@blockcast/mmt-base 2.2.0-main.73af0eedcbc8 → 2.2.0-main.79fd2df1f6a3

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 (40) hide show
  1. package/dist/datagram-leg-size.d.ts +30 -0
  2. package/dist/datagram-leg-size.d.ts.map +1 -0
  3. package/dist/datagram-leg-size.js +42 -0
  4. package/dist/datagram-leg-size.js.map +1 -0
  5. package/dist/event-timeline-catalog.d.ts +21 -0
  6. package/dist/event-timeline-catalog.d.ts.map +1 -0
  7. package/dist/event-timeline-catalog.js +40 -0
  8. package/dist/event-timeline-catalog.js.map +1 -0
  9. package/dist/fec-bindings.d.ts +13 -1
  10. package/dist/fec-bindings.d.ts.map +1 -1
  11. package/dist/fec-bindings.js +29 -6
  12. package/dist/fec-bindings.js.map +1 -1
  13. package/dist/fec-catalog.d.ts +4 -1
  14. package/dist/fec-catalog.d.ts.map +1 -1
  15. package/dist/fec-catalog.js.map +1 -1
  16. package/dist/index.d.ts +3 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.js +3 -0
  19. package/dist/index.js.map +1 -1
  20. package/dist/mmtp-siblings.d.ts +50 -0
  21. package/dist/mmtp-siblings.d.ts.map +1 -0
  22. package/dist/mmtp-siblings.js +142 -0
  23. package/dist/mmtp-siblings.js.map +1 -0
  24. package/dist/mmtp.d.ts +0 -13
  25. package/dist/mmtp.d.ts.map +1 -1
  26. package/dist/mmtp.js +13 -21
  27. package/dist/mmtp.js.map +1 -1
  28. package/dist/multicast-catalog.d.ts +20 -0
  29. package/dist/multicast-catalog.d.ts.map +1 -1
  30. package/dist/multicast-catalog.js +38 -2
  31. package/dist/multicast-catalog.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/datagram-leg-size.ts +46 -0
  34. package/src/event-timeline-catalog.ts +55 -0
  35. package/src/fec-bindings.ts +43 -7
  36. package/src/fec-catalog.ts +4 -1
  37. package/src/index.ts +3 -0
  38. package/src/mmtp-siblings.ts +161 -0
  39. package/src/mmtp.ts +15 -37
  40. package/src/multicast-catalog.ts +46 -1
@@ -0,0 +1,55 @@
1
+ // The Event Timeline tracks of an MSF catalog (draft-ietf-moq-msf-01 8.2), read once for every
2
+ // consumer: the container's ad-creative receiver, the transport's join selection, the players.
3
+ // Track-level, like mmtpTrackIssues: a bad entry costs that track, never the catalog.
4
+
5
+ export interface EventTimelineTrack {
6
+ readonly name: string
7
+ readonly namespace?: string
8
+ readonly eventType: string
9
+ /** Media tracks whose timeline the records index (riedl 3, R3). */
10
+ readonly depends: readonly string[]
11
+ }
12
+ export type EventTimelineTrackIssueCode = 'track_event_type' | 'track_event_mime_type' | 'track_event_depends'
13
+ export interface EventTimelineTrackIssue {
14
+ readonly code: EventTimelineTrackIssueCode
15
+ readonly path: string
16
+ readonly name: string
17
+ readonly index: number
18
+ }
19
+
20
+ const isObject = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v)
21
+
22
+ /** Tracks of packaging "eventtimeline", only those of `eventTypes` when given. `issues` names every
23
+ * eventtimeline track a consumer must skip, whatever its eventType. */
24
+ export function catalogEventTimelineTracks(catalog: unknown, eventTypes?: readonly string[]): {
25
+ tracks: EventTimelineTrack[]
26
+ issues: EventTimelineTrackIssue[]
27
+ } {
28
+ const tracks: EventTimelineTrack[] = []
29
+ const issues: EventTimelineTrackIssue[] = []
30
+ const list: unknown[] = isObject(catalog) && Array.isArray(catalog['tracks']) ? catalog['tracks'] : []
31
+ // msf-01 5.2.14: a depends name resolves in the namespace of the track that declares it.
32
+ const named = new Set(list.filter(isObject).map((t) => `${String(t['namespace'] ?? '')}\u0000${String(t['name'])}`))
33
+ list.forEach((t, index) => {
34
+ if (!isObject(t) || t['packaging'] !== 'eventtimeline' || typeof t['name'] !== 'string') return
35
+ const name = t['name']
36
+ const issue = (code: EventTimelineTrackIssueCode, field: string): void => {
37
+ issues.push({ code, path: `$.tracks[${index}].${field}`, name, index })
38
+ }
39
+ const eventType = t['eventType']
40
+ if (typeof eventType !== 'string' || eventType.length === 0) return issue('track_event_type', 'eventType')
41
+ // msf-01 8.2 requires application/json; the MSF editor's copy dropped the field, so only another value rejects.
42
+ if (t['mimeType'] !== undefined && t['mimeType'] !== 'application/json') return issue('track_event_mime_type', 'mimeType')
43
+ const depends = t['depends']
44
+ const namespace = String(t['namespace'] ?? '')
45
+ // riedl 3 (R3): depends names the media track(s) whose timeline the index uses; the timeline needs that clock.
46
+ if (!Array.isArray(depends) || depends.length === 0 ||
47
+ !depends.every((d) => typeof d === 'string' && d !== name && named.has(`${namespace}\u0000${d}`))) {
48
+ return issue('track_event_depends', 'depends')
49
+ }
50
+ if (eventTypes !== undefined && !eventTypes.includes(eventType)) return
51
+ const ns = t['namespace']
52
+ tracks.push({ name, ...(typeof ns === 'string' ? { namespace: ns } : {}), eventType, depends: depends as string[] })
53
+ })
54
+ return { tracks, issues }
55
+ }
@@ -21,7 +21,13 @@
21
21
  * track anything. A draft-01 object `fec` is `fec_member` at that track's
22
22
  * `fec`: the track plays without FEC.
23
23
  */
24
- import { validateFecCatalog, type FecCatalogCode, type FecCatalogReceiver } from './fec-catalog.js'
24
+ import {
25
+ validateFecCatalog,
26
+ type FecCatalogCode,
27
+ type FecCatalogIssue,
28
+ type FecCatalogReceiver,
29
+ type FecCatalogReport,
30
+ } from './fec-catalog.js'
25
31
 
26
32
  /** The receiver this runtime is: it decodes `iso-ssbg1-v1` only. */
27
33
  export const RUNTIME_FEC_RECEIVER: FecCatalogReceiver = Object.freeze({
@@ -163,6 +169,41 @@ export function fecCatalogTracks(catalog: unknown): { tracks: unknown[]; pointer
163
169
  return { tracks, pointers }
164
170
  }
165
171
 
172
+ function runtimeView(catalog: unknown, receiver: FecCatalogReceiver) {
173
+ const { tracks, pointers } = fecCatalogTracks(catalog)
174
+ const report = validateFecCatalog({ tracks }, receiver)
175
+ const at = (path: string) => {
176
+ const m = /^\/tracks\/(\d+)(.*)$/.exec(path)
177
+ return m ? pointers[Number(m[1])] + m[2] : path
178
+ }
179
+ return { tracks, pointers, report, at }
180
+ }
181
+
182
+ /**
183
+ * The `validateFecCatalog` report `resolveFecBindings` acts on (BLO-55242):
184
+ * the same `tracks[]` view and the same receiver, so a host publishing it
185
+ * cannot disagree with what the runtime does. Paths are JSON Pointers into
186
+ * the original catalog (a hang path starts `/video`, `/audio` or `/repair`).
187
+ * One kind does not resolve: a hang layer 0 repair track with no
188
+ * `repair.renditions` entry stands at the `repairTrack` string that names it
189
+ * (`.../fec/<j>/repairTrack`), so a path below that track names nothing in
190
+ * the catalog. The track indices (`trackIndex`, `repairTrack`,
191
+ * `boundRepairTracks`, `symbolTrack`) index `fecCatalogTracks(catalog).tracks`.
192
+ */
193
+ export function runtimeFecCatalogReport(
194
+ catalog: unknown,
195
+ receiver: FecCatalogReceiver = RUNTIME_FEC_RECEIVER,
196
+ ): FecCatalogReport {
197
+ const { report, at } = runtimeView(catalog, receiver)
198
+ const issue = (i: FecCatalogIssue) => Object.freeze({ code: i.code, path: at(i.path) })
199
+ return Object.freeze({
200
+ instances: Object.freeze(
201
+ report.instances.map((i) => Object.freeze({ ...i, path: at(i.path), issues: Object.freeze(i.issues.map(issue)) })),
202
+ ),
203
+ issues: Object.freeze(report.issues.map(issue)),
204
+ })
205
+ }
206
+
166
207
  /**
167
208
  * Every source track's runtime FEC binding, by track name. A track with no
168
209
  * `fec`, or an empty `fec` array, declares no FEC and has no entry.
@@ -171,12 +212,7 @@ export function resolveFecBindings(
171
212
  catalog: unknown,
172
213
  receiver: FecCatalogReceiver = RUNTIME_FEC_RECEIVER,
173
214
  ): ReadonlyMap<string, FecSourceBinding> {
174
- const { tracks, pointers } = fecCatalogTracks(catalog)
175
- const report = validateFecCatalog({ tracks }, receiver)
176
- const at = (path: string) => {
177
- const m = /^\/tracks\/(\d+)(.*)$/.exec(path)
178
- return m ? pointers[Number(m[1])] + m[2] : path
179
- }
215
+ const { tracks, pointers, report, at } = runtimeView(catalog, receiver)
180
216
  const trackAt = (i: number) => recordOf(tracks[i]) ?? {}
181
217
  const nameAt = (i: number | null) => (i === null ? undefined : (trackAt(i)['name'] as string))
182
218
  const why = (i: { outcome: string; issues: readonly { code: FecCatalogCode; path: string }[]; path: string }) =>
@@ -51,7 +51,10 @@ export interface FecCatalogIssue {
51
51
  }
52
52
 
53
53
  export interface FecCatalogInstance {
54
- /** JSON Pointer of the instance object, `/tracks/<i>/fec/<j>`. */
54
+ /** JSON Pointer of the instance object. `validateFecCatalog` gives
55
+ * `/tracks/<i>/fec/<j>`; `runtimeFecCatalogReport` gives the pointer in the
56
+ * original catalog, which for hang is `/video/renditions/<name>/fec/<j>`
57
+ * (or under `/audio`). Read the track from `trackIndex`, not from the path. */
55
58
  readonly path: string;
56
59
  readonly track: string | null;
57
60
  /** Resolved Instance ID; null when `instanceId` is malformed. */
package/src/index.ts CHANGED
@@ -8,3 +8,6 @@ export * from './ip-address.js'
8
8
  export * from './multicast-catalog.js'
9
9
  export * from './fec-catalog.js'
10
10
  export * from './fec-bindings.js'
11
+ export * from './mmtp-siblings.js'
12
+ export * from './datagram-leg-size.js'
13
+ export * from './event-timeline-catalog.js'
@@ -0,0 +1,161 @@
1
+ // The mmtp track modes of draft-ramadan-moq-mmt-02 13.1 and the pairing of
2
+ // an "mfu-datagram" track with the "mfu" track it mirrors (4.3.1).
3
+ //
4
+ // A publisher MUST NOT publish an "mfu-datagram" track without an "mfu" track
5
+ // of the same namespace whose objects are identical in Group ID, Object ID
6
+ // and payload. The catalog carries no sibling pointer, so the pair is read
7
+ // from what the two entries state: they are siblings when their whole
8
+ // identity set is equal, field by field or absent on both. The identity set
9
+ // is the hard set (what the Group and Object IDs are derived from) and the
10
+ // rendition fields of mmt-02 13.1 (one payload has one codec, size, bitrate
11
+ // and language; the rungs of a ladder share the hard set, so nothing else
12
+ // tells them apart). A datagram track with no sibling, or more than one, is
13
+ // rejected and the player plays "mfu". The soft set is reported, never a
14
+ // fault. Names, roles and labels are not read: fec-catalog-00 makes names
15
+ // non-normative. Known limit: two "mfu" tracks with one description cannot
16
+ // carry datagram siblings until the draft defines a pointer.
17
+ //
18
+ // The rule is a per-pair predicate: it answers the same over the whole
19
+ // catalog and over any subset of it a consumer kept.
20
+
21
+ /** Every mmtpMode this library accepts (mmt-02 13.1). Anything else rejects the track. */
22
+ export const MMTP_MODES = Object.freeze(['mfu', 'mfu-datagram'] as const)
23
+
24
+ export type MmtpMode = (typeof MMTP_MODES)[number]
25
+
26
+ export function isMmtpMode(value: unknown): value is MmtpMode {
27
+ return typeof value === 'string' && (MMTP_MODES as readonly string[]).includes(value)
28
+ }
29
+
30
+ /**
31
+ * Fields the Group and Object IDs of an mmtp track are derived from: two
32
+ * tracks whose values differ cannot carry identical ids (mmt-02 4.4.2, 4.6).
33
+ * Compared equal-or-both-absent, group duration as resolved ticks.
34
+ */
35
+ export const MMTP_SIBLING_HARD_FIELDS = Object.freeze([
36
+ 'namespace',
37
+ 'timescale',
38
+ 'presentationAnchorTicks',
39
+ 'groupDuration',
40
+ ] as const)
41
+
42
+ /**
43
+ * Fields that describe the media a track carries. The pair carries one
44
+ * payload (mmt-02 4.3.1), so it has one description: an "mfu" track whose
45
+ * description differs is another rendition. The rungs of a ladder share the
46
+ * hard set and nothing else in the catalog tells them apart. Compared
47
+ * equal-or-both-absent, like the hard set.
48
+ */
49
+ export const MMTP_SIBLING_RENDITION_FIELDS = Object.freeze([
50
+ 'codec',
51
+ 'width',
52
+ 'height',
53
+ 'framerate',
54
+ 'bitrate',
55
+ 'samplerate',
56
+ 'channelConfig',
57
+ 'lang',
58
+ ] as const)
59
+
60
+ /**
61
+ * Fields the pair SHOULD share; a mismatch is reported, not a fault. A soft
62
+ * field is read from the entry of the track subscribed, never borrowed from
63
+ * its sibling: a leg takes the keyframe interval its "mfu-datagram" entry
64
+ * states, and none when that entry states none (mmt-02 4.4.3).
65
+ */
66
+ export const MMTP_SIBLING_SOFT_FIELDS = Object.freeze([
67
+ 'initRef',
68
+ 'keyframeIntervalMs',
69
+ 'keyframeIntervalTicks',
70
+ 'isLive',
71
+ 'altGroup',
72
+ ] as const)
73
+
74
+ export interface MmtpSiblingPair<T> {
75
+ /** The "mfu" track. */
76
+ readonly stream: T
77
+ /** Its "mfu-datagram" sibling, when the catalog carries exactly one. */
78
+ readonly datagram?: T
79
+ /** Soft-set fields on which the two differ (empty without a datagram sibling). */
80
+ readonly softMismatches: readonly string[]
81
+ }
82
+
83
+ type Fields = Record<string, unknown>
84
+
85
+ function fields(track: object): Fields {
86
+ return track as Fields
87
+ }
88
+
89
+ function groupDurationTicks(track: Fields): bigint | undefined {
90
+ const ticks = track['groupDurationTicks']
91
+ if (Number.isSafeInteger(ticks)) return BigInt(ticks as number)
92
+ const ms = track['groupDurationMs']
93
+ const timescale = track['timescale']
94
+ if (!Number.isSafeInteger(ms) || !Number.isSafeInteger(timescale)) return undefined
95
+ return (BigInt(ms as number) * BigInt(timescale as number)) / 1000n
96
+ }
97
+
98
+ function identityEqual(a: Fields, b: Fields): boolean {
99
+ return (
100
+ a['namespace'] === b['namespace'] &&
101
+ a['timescale'] === b['timescale'] &&
102
+ a['presentationAnchorTicks'] === b['presentationAnchorTicks'] &&
103
+ groupDurationTicks(a) === groupDurationTicks(b) &&
104
+ MMTP_SIBLING_RENDITION_FIELDS.every((field) => a[field] === b[field])
105
+ )
106
+ }
107
+
108
+ function isMmtpTrack(track: unknown, mode: MmtpMode): track is object {
109
+ return (
110
+ typeof track === 'object' && track !== null && !Array.isArray(track) &&
111
+ fields(track)['packaging'] === 'mmtp' && fields(track)['mmtpMode'] === mode
112
+ )
113
+ }
114
+
115
+ /**
116
+ * The "mfu" tracks of `tracks` an "mfu-datagram" track could be the sibling
117
+ * of: the ones whose identity set (hard set and rendition fields) equals its own. Exactly one
118
+ * pairs it; zero or more than one rejects the datagram track (mmt-02 4.3.1).
119
+ */
120
+ export function mmtpSiblingCandidates<T extends object>(tracks: readonly T[], datagram: T): T[] {
121
+ const own = fields(datagram)
122
+ return tracks.filter((track) => isMmtpTrack(track, 'mfu') && identityEqual(fields(track), own))
123
+ }
124
+
125
+ /**
126
+ * Every "mfu" track of `tracks` by name, each with its "mfu-datagram" sibling
127
+ * when exactly one matches its identity set. A datagram track that matches no
128
+ * "mfu" track or more than one pairs with none, and two datagram tracks that
129
+ * match the same "mfu" track pair with neither (each is rejected by
130
+ * `mmtpTrackIssues` in the container validator, which first sets aside a
131
+ * track it rejects for its delivery mode); the "mfu" tracks are listed
132
+ * whatever happens to their siblings. Never throws.
133
+ */
134
+ export function pairMmtpSiblings<T extends object>(tracks: readonly T[]): ReadonlyMap<string, MmtpSiblingPair<T>> {
135
+ const pairs = new Map<string, MmtpSiblingPair<T>>()
136
+ for (const track of tracks) {
137
+ if (!isMmtpTrack(track, 'mfu')) continue
138
+ const name = fields(track)['name']
139
+ if (typeof name === 'string' && !pairs.has(name)) pairs.set(name, { stream: track, softMismatches: [] })
140
+ }
141
+ // Two datagram tracks matching one "mfu" track pair with neither: the
142
+ // catalog says nothing about which mirrors it.
143
+ const datagrams = new Map<string, T[]>()
144
+ for (const datagram of tracks) {
145
+ if (!isMmtpTrack(datagram, 'mfu-datagram')) continue
146
+ const candidates = mmtpSiblingCandidates(tracks, datagram)
147
+ if (candidates.length !== 1) continue
148
+ const name = fields(candidates[0]!)['name']
149
+ if (typeof name !== 'string' || pairs.get(name)?.stream !== candidates[0]) continue
150
+ datagrams.set(name, [...(datagrams.get(name) ?? []), datagram])
151
+ }
152
+ for (const [name, matched] of datagrams) {
153
+ if (matched.length !== 1) continue
154
+ const { stream } = pairs.get(name)!
155
+ const a = fields(stream)
156
+ const b = fields(matched[0]!)
157
+ const softMismatches = MMTP_SIBLING_SOFT_FIELDS.filter((field) => a[field] !== b[field])
158
+ pairs.set(name, { stream, datagram: matched[0]!, softMismatches })
159
+ }
160
+ return pairs
161
+ }
package/src/mmtp.ts CHANGED
@@ -374,7 +374,6 @@ function isEmptyOrExactLegacyTrailer(payload: Uint8Array, start: number, end: nu
374
374
 
375
375
  interface DeclaredTrailerLayout {
376
376
  hasFecId: boolean
377
- hasOverlayFecId: boolean
378
377
  }
379
378
 
380
379
  /** Options for extractMFUPayload and explainMFURejection. */
@@ -385,15 +384,6 @@ export interface MFUExtractOptions {
385
384
  * was already stripped before WASM decoding.
386
385
  */
387
386
  skipFecId?: boolean
388
- /**
389
- * The catalog declares a keyframe overlay (`scope: "keyframe"` repair track)
390
- * for this packet's source. A RAP packet then carries two Source FEC Payload
391
- * IDs, base first and overlay last (BLO-32719 Clarification 7). This is a
392
- * catalog fact, never inferred: the header has no overlay bit, and a payload
393
- * four bytes shorter is byte-identical to a missing overlay. Mirrors
394
- * mmt-core `split_payload_and_source_fec_trailers(overlay_declared)`.
395
- */
396
- overlayDeclared?: boolean
397
387
  }
398
388
 
399
389
  function resolveDeclaredTrailers(
@@ -401,38 +391,31 @@ function resolveDeclaredTrailers(
401
391
  declaredEnd: number,
402
392
  fecType: number,
403
393
  options?: MFUExtractOptions,
404
- rapFlag = false,
405
394
  ): DeclaredTrailerLayout | null {
406
395
  if (declaredEnd > payload.length) return null
407
396
 
408
397
  if (options?.skipFecId) {
409
398
  return isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length)
410
- ? { hasFecId: false, hasOverlayFecId: false }
399
+ ? { hasFecId: false }
411
400
  : null
412
401
  }
413
402
 
414
- const overlay = options?.overlayDeclared === true && rapFlag
415
403
  if (fecType === 1) {
416
- const fecStart = payload.length - sourceFecTrailerSize(overlay)
404
+ const fecStart = payload.length - SOURCE_FEC_PAYLOAD_ID_SIZE
417
405
  if (fecStart < declaredEnd || !isEmptyOrExactLegacyTrailer(payload, declaredEnd, fecStart)) {
418
406
  return null
419
407
  }
420
- return { hasFecId: true, hasOverlayFecId: overlay }
408
+ return { hasFecId: true }
421
409
  }
422
- // An overlay ID rides behind a base ID the header says is absent.
423
- if (fecType !== 0 || overlay) return null
410
+ if (fecType !== 0) return null
424
411
 
425
412
  if (isEmptyOrExactLegacyTrailer(payload, declaredEnd, payload.length)) {
426
- return { hasFecId: false, hasOverlayFecId: false }
413
+ return { hasFecId: false }
427
414
  }
428
415
 
429
416
  return null
430
417
  }
431
418
 
432
- function sourceFecTrailerSize(overlay: boolean): number {
433
- return overlay ? 2 * SOURCE_FEC_PAYLOAD_ID_SIZE : SOURCE_FEC_PAYLOAD_ID_SIZE
434
- }
435
-
436
419
  /**
437
420
  * Extract NAL unit payload from MMTP packet
438
421
  */
@@ -458,8 +441,6 @@ export interface MFUExtraction {
458
441
  itemId: number | null
459
442
  /** Source FEC Payload ID if present (`FEC_type == 1`), or null */
460
443
  fecPayloadId: { ssId: number } | null
461
- /** Keyframe-overlay Source FEC Payload ID: RAP packets with `overlayDeclared` only. */
462
- overlayFecPayloadId: { ssId: number } | null
463
444
  }
464
445
 
465
446
  /**
@@ -481,8 +462,6 @@ export interface MFUExtraction {
481
462
  * FEC-recovered symbols where the FEC PID was already stripped before WASM decoding
482
463
  * but the fecType bits in byte 0 still reflect the original packet (FEC Type=1 per
483
464
  * draft-ramadan-moq-mmt-01 §3.1).
484
- * @param options.overlayDeclared The catalog declares a keyframe overlay for this
485
- * source, so a RAP packet carries an 8-byte trailer (see MFUExtractOptions).
486
465
  * @returns Extracted MFU data + metadata, or null if packet is too small
487
466
  */
488
467
  interface MfuPlan {
@@ -568,7 +547,6 @@ function planMfuExtraction(
568
547
  layout.dataEnd,
569
548
  header.fecType,
570
549
  options,
571
- header.rapFlag,
572
550
  )
573
551
  if (!trailerLayout) {
574
552
  // The most common cause is a producer whose Source FEC Payload ID width
@@ -576,7 +554,7 @@ function planMfuExtraction(
576
554
  // leaving operators to infer it from a generic trailer error.
577
555
  if (!options?.skipFecId && header.fecType === 1) {
578
556
  const observed = payload.length - layout.dataEnd
579
- const expected = sourceFecTrailerSize(options?.overlayDeclared === true && header.rapFlag)
557
+ const expected = SOURCE_FEC_PAYLOAD_ID_SIZE
580
558
  if (observed !== expected) {
581
559
  return {
582
560
  rejection: {
@@ -664,17 +642,17 @@ function extractPlannedMfu(
664
642
 
665
643
  const data = payload.subarray(mfuOffset, dataEnd)
666
644
 
667
- const trailerStart =
668
- mmtpPacket.length - sourceFecTrailerSize(trailerLayout.hasOverlayFecId)
669
- const ssIdAt = (offset: number) => ({
670
- ssId: new DataView(mmtpPacket.buffer, mmtpPacket.byteOffset + offset, 4).getUint32(0, false),
671
- })
672
- const fecPayloadId = trailerLayout.hasFecId ? ssIdAt(trailerStart) : null
673
- const overlayFecPayloadId = trailerLayout.hasOverlayFecId
674
- ? ssIdAt(trailerStart + SOURCE_FEC_PAYLOAD_ID_SIZE)
645
+ const fecPayloadId = trailerLayout.hasFecId
646
+ ? {
647
+ ssId: new DataView(
648
+ mmtpPacket.buffer,
649
+ mmtpPacket.byteOffset + mmtpPacket.length - SOURCE_FEC_PAYLOAD_ID_SIZE,
650
+ 4,
651
+ ).getUint32(0, false),
652
+ }
675
653
  : null
676
654
 
677
- return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId, overlayFecPayloadId }
655
+ return { header, mpu, fragmentType, data, mfuDuHeader, itemId, fecPayloadId }
678
656
  }
679
657
 
680
658
  /**
@@ -255,8 +255,11 @@ export function multicastCatalogIssues(
255
255
 
256
256
  const tracks = Array.isArray(catalog["tracks"]) ? catalog["tracks"] : [];
257
257
  const namespaceOf = new Map<string, unknown>();
258
+ const modeOf = new Map<string, unknown>();
258
259
  for (const track of tracks) {
259
- if (isObject(track) && typeof track["name"] === "string") namespaceOf.set(track["name"], track["namespace"]);
260
+ if (!isObject(track) || typeof track["name"] !== "string") continue;
261
+ namespaceOf.set(track["name"], track["namespace"]);
262
+ modeOf.set(track["name"], track["mmtpMode"]);
260
263
  }
261
264
  const tagged = (catalog as { [CATALOG_NAMESPACE]?: unknown })[CATALOG_NAMESPACE];
262
265
  let referenceNamespace = options.catalogNamespace ?? (typeof tagged === "string" ? tagged : undefined);
@@ -337,6 +340,12 @@ export function multicastCatalogIssues(
337
340
  const ref = refs[refIndex];
338
341
  const name = isObject(ref) ? ref["name"] : ref;
339
342
  if (typeof name !== "string") continue;
343
+ // mmt-02 4.3.1: the "mfu" and "mfu-datagram" tracks carry the same
344
+ // MMTP sub-flow, so an endpoint lists the "mfu" track and never the
345
+ // datagram one; a receiver ignores an endpoint that does.
346
+ if (modeOf.get(name) === "mfu-datagram") {
347
+ fail("multicast_track", `${at}.tracks[${refIndex}].name`, `track ${JSON.stringify(name)} is an "mfu-datagram" track, which rides no multicast endpoint; list its "mfu" sibling (draft-ramadan-moq-mmt-02 4.3.1)`);
348
+ }
340
349
  const namespace = namespaceOf.get(name);
341
350
  if (typeof namespace !== "string") continue;
342
351
  referenceNamespace ??= namespace;
@@ -387,3 +396,39 @@ export function admittedMulticastEndpoints(
387
396
  const ignored = new Set(issues.map(issue => issue.endpointIndex));
388
397
  return new Set(endpoints.map((_, index) => index).filter(index => !ignored.has(index)));
389
398
  }
399
+
400
+ /** Resolved ATSC 3.0 tuning (draft -01 4.2.2/4.2.3). Only `frequency` is REQUIRED. */
401
+ export type Atsc3NetworkSource = {
402
+ /** RF centre frequency in kHz. */
403
+ frequency: number;
404
+ plpId?: number;
405
+ serviceId?: number;
406
+ /** SLS of the MMTP service; libmmt does not fetch it. */
407
+ slsUri?: string;
408
+ };
409
+
410
+ /**
411
+ * Resolve ATSC 3.0 tuning from a catalog `networkSource` (array or bare-object
412
+ * form): the first `type: "atsc3"` entry with a positive integer `frequency`
413
+ * (kHz). Optional fields are carried only when in range; an entry with no
414
+ * usable frequency is skipped, since it names nothing a tuner can lock to.
415
+ * Draft -01 3 puts the tuner first, so callers prefer this over AMT.
416
+ *
417
+ * Lives here, not in `@blockcast/mmt-container`, so the transport's
418
+ * `endpointToMulticastConfig` and the container read the field one way.
419
+ */
420
+ export function catalogAtsc3NetworkSource(networkSource: unknown): Atsc3NetworkSource | undefined {
421
+ const entries = Array.isArray(networkSource) ? networkSource : networkSource ? [networkSource] : [];
422
+ for (const ns of entries) {
423
+ if (!isObject(ns)) continue;
424
+ if (ns.type !== "atsc3" || !isIntegerIn(ns.frequency, 1, Number.MAX_SAFE_INTEGER)) continue;
425
+ const slsUri = typeof ns.slsUri === "string" ? ns.slsUri.trim() : "";
426
+ return {
427
+ frequency: ns.frequency,
428
+ ...(isIntegerIn(ns.plpId, 0, 63) ? { plpId: ns.plpId } : {}),
429
+ ...(isIntegerIn(ns.serviceId, 0, 65535) ? { serviceId: ns.serviceId } : {}),
430
+ ...(slsUri ? { slsUri } : {}),
431
+ };
432
+ }
433
+ return undefined;
434
+ }