From e99e1debc171436a05807f35c608bea5849edf1a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 27 Oct 2026 23:37:47 -0700 Subject: [PATCH 1/8] chore(quest): claim quest/m1/cut-audit/catalog-parity.md Quest-Claim: 9df0f61d1e0684a5 From 8dc8ba4f7374b38acb84847d77286ed27eb7b0b2 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 00:07:58 -0700 Subject: [PATCH 2/8] fix(hang)!: Rust and JS accept the same catalogs Both languages now validate codec strings, dimension and rate ranges, and containers the same way, and skip a malformed audio or video rendition while keeping the rest of the catalog. JS drops the legacy array video and {track, config} audio forms, and Rust drops the displayRatio* alias. A shared fixture corpus both test suites load fails CI on any future divergence. Co-Authored-By: Claude Opus 5.5 --- drafts/draft-lcurley-moq-hang.md | 23 +- js/hang/api/catalog.api.md | 869 +----- js/hang/src/catalog/audio.ts | 45 +- js/hang/src/catalog/clock.test.ts | 2 +- js/hang/src/catalog/container.test.ts | 2 +- js/hang/src/catalog/parity.test.ts | 32 + js/hang/src/catalog/root.test.ts | 14 +- js/hang/src/catalog/section.ts | 45 + js/hang/src/catalog/video.test.ts | 25 +- js/hang/src/catalog/video.ts | 109 +- rs/hang/Cargo.toml | 2 +- rs/hang/fixtures/catalog-parity.json | 3981 ++++++++++++++++++++++++ rs/hang/src/catalog/audio/aac.rs | 2 +- rs/hang/src/catalog/audio/mod.rs | 25 +- rs/hang/src/catalog/container.rs | 24 +- rs/hang/src/catalog/hex.rs | 12 +- rs/hang/src/catalog/millis.rs | 15 +- rs/hang/src/catalog/mod.rs | 63 + rs/hang/src/catalog/root.rs | 96 +- rs/hang/src/catalog/video/av1.rs | 12 +- rs/hang/src/catalog/video/h264.rs | 13 +- rs/hang/src/catalog/video/h265.rs | 39 +- rs/hang/src/catalog/video/mod.rs | 48 +- rs/hang/src/catalog/video/vp9.rs | 8 +- rs/hang/src/error.rs | 4 + rs/hang/src/snapshot.rs | 4 +- rs/moq-mux/src/catalog/producer.rs | 28 +- rs/moq-mux/src/container/flv/export.rs | 2 +- rs/moq-mux/src/container/ts/export.rs | 2 +- rs/moq-mux/src/error.rs | 2 +- 30 files changed, 4469 insertions(+), 1079 deletions(-) create mode 100644 js/hang/src/catalog/parity.test.ts create mode 100644 rs/hang/fixtures/catalog-parity.json diff --git a/drafts/draft-lcurley-moq-hang.md b/drafts/draft-lcurley-moq-hang.md index d8992f76fab..23eba577102 100644 --- a/drafts/draft-lcurley-moq-hang.md +++ b/drafts/draft-lcurley-moq-hang.md @@ -227,6 +227,22 @@ A rendition MAY keep its ID and name the new track with `track` ({{field-track}} A track name removed from the catalog MUST NOT return with a different identity. A consumer MAY configure a decoder once per track from the catalog. +## Malformed Renditions {#malformed} +A consumer MUST ignore a malformed audio or video rendition and keep the rest of the catalog, while a `renditions` value that is not an object refuses the catalog. +A rendition is malformed when it is not an object or a field it carries has the wrong type or is out of range. + +`codedWidth`, `codedHeight`, `displayAspectWidth`, `displayAspectHeight`, `sampleRate`, and `numberOfChannels` are integers from 1 to 2^32 - 1, and `bitrate`, `jitter`, `warmup`, and `delay` are integers from 0 to 2^53 - 1. + +A `codec` naming a codec below without its parameters in this form is malformed; any other string is a codec the consumer may not recognize, never a malformed one: + +- `avc1.` or `avc3.`, then exactly six hexadecimal digits. +- `hvc1.` or `hev1.`, then the ISO/IEC 14496-15 fields: an optional profile space `A` to `C` with a decimal profile, hexadecimal compatibility flags of at most 32 bits, `L` or `H` with a decimal level, and up to six hexadecimal constraint bytes. One empty trailing field is tolerated. +- `vp09.`, then three or eight two-digit decimal fields. +- `av01.`, then the AV1 codecs parameter: profile 0 to 2, a two-digit level with tier `M` or `H`, a two-digit bit depth, and optionally every one of the monochrome, chroma, colour, and range fields. +- `mp4a.40.`, then a decimal object type from 0 to 255. + +Each decimal or hexadecimal field is one or more digits, without a sign. + ## Video A video track contains the necessary information to decode a video stream. @@ -336,7 +352,7 @@ Its `fov` is the degrees of longitude the picture spans, centred straight ahead: `mono`, the default when absent, shows the whole frame to both eyes. `left-right` carries the left eye's view in the left half and the right eye's in the right half, and `top-bottom` carries the left eye's view in the top half and the right eye's in the bottom half. -A consumer MUST treat an unrecognized `projection` kind or `stereo` value as absent, and MUST reject a recognized `projection` kind with a malformed field, such as a `fov` out of range. +A consumer MUST treat an unrecognized `projection` kind or `stereo` value as absent, and a recognized `projection` kind with a malformed field, such as a `fov` out of range, makes the rendition malformed ({{malformed}}). Neither field is part of the track's identity. `interlaced` is true when each decoded picture weaves two fields, as an H.264 stream with `frame_mbs_only_flag` 0 decodes. @@ -430,7 +446,7 @@ type AudioDecoderConfigExtensions = { `layout` says what the decoded channels carry; when absent, they follow the codec's own channel order. `ambisonic` is full-sphere ambisonics in the AmbiX convention: ACN channel order with SN3D normalization, of the order N for which `numberOfChannels` is (N+1)^2. -A consumer MUST reject `ambisonic` with fewer than 4 channels or a count that is not a square, and MUST treat an unrecognized `layout` as absent. +`ambisonic` with fewer than 4 channels or a count that is not a square makes the rendition malformed ({{malformed}}), and a consumer MUST treat an unrecognized `layout` as absent. `layout` is not part of the track's identity. An Opus frame timestamp counts the samples the OpusHead pre-skip trims: a consumer presents each decoded sample the pre-skip, at 48 kHz, earlier than its frame timestamp places it, so the first sample kept plays at the first decoded frame's timestamp. @@ -438,7 +454,6 @@ An Opus frame timestamp counts the samples the OpusHead pre-skip trims: a consum ### PCM {#audio-pcm} Hang defines the `"pcm"` audio codec for uncompressed samples. -The `sampleRate` and `numberOfChannels` fields MUST be present and greater than zero. The `description` field MUST NOT be present. If `bitrate` is present, it MUST equal `sampleRate * numberOfChannels * 32`. @@ -881,6 +896,7 @@ type Container = ~~~ The `kind` field selects the framing; a consumer MUST ignore a rendition whose `kind` it does not recognize. +A container without a string `kind`, or with a recognized `kind` missing its fields, makes the rendition malformed ({{malformed}}). Every container shares the same group rules: A video group MUST start at a random access point: a keyframe unless the rendition declares `warmup` ({{field-warmup}}), in which case it MAY start at a picture from which decoding converges within that duration. @@ -1146,6 +1162,7 @@ This document has no IANA actions. - Replaced the root `archive` section and its per-track timelines with an optional, per-rendition `hls` field on video and audio ({{hls}}). Each record is a segment's first `group` and `pts` in milliseconds, with an optional `duration` where zero marks a stop; frame positions, `end`, `keyframe`, `timescale`, `replay`, `replayEpoch`, `store`, and `version` are gone. Each rendition numbers its own segments, and an edge maps a rendition's record `n` to its segment `n`. The record track is named `.hls` and is not compressed. - A reader refuses a JSON frame in which an object repeats a member name. +- A consumer ignores a malformed audio or video rendition ({{malformed}}) and keeps the rest of the catalog: a known codec string without valid parameters, a zero or out-of-range dimension, sample rate, or channel count, a bitrate or duration above 2^53 - 1, or a container without a string `kind`. - Added the root `version` ({{catalog-version}}): the oldest draft that reads the catalog, which a consumer refuses when above its own. A `track` other than the entry's ID or a video `warmup` needs 4. Consumers MUST ignore unknown fields. - A data track marks a discontinuity with a group of one object with no bytes, since its empty payload is data. An object with no bytes on an audio or video track, or sharing its group, is malformed. - Removed the Recording section: the store layout is a moq-archive format, documented with that crate, not part of this draft. diff --git a/js/hang/api/catalog.api.md b/js/hang/api/catalog.api.md index 199413a77a8..a480d9b1c98 100644 --- a/js/hang/api/catalog.api.md +++ b/js/hang/api/catalog.api.md @@ -7,7 +7,6 @@ import { $brand } from "@zod/mini"; import { $loose } from "zod/v4/core"; import { $strip } from "zod/v4/core"; import { Net } from "@moq/hang"; -import { ZodMiniArray } from "@zod/mini"; import { ZodMiniBase64 } from "@zod/mini"; import { ZodMiniBoolean } from "@zod/mini"; import { ZodMiniCatch } from "@zod/mini"; @@ -70,128 +69,8 @@ export namespace Audio { track: ZodMiniOptional>; warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; }, $strip>; - export const AudioSchema: ZodMiniUnion, ZodMiniObject<{ - bitrate: ZodMiniOptional<$ZodBranded, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - layout: ZodMiniOptional>; - numberOfChannels: $ZodBranded, "u53", "out">; - sampleRate: $ZodBranded, "u53", "out">; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>>; - }, $strip>, ZodMiniPipe, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - layout: ZodMiniOptional>; - numberOfChannels: $ZodBranded, "u53", "out">; - sampleRate: $ZodBranded, "u53", "out">; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>; - track: ZodMiniObject<{ - name: ZodMiniString; - }, $strip>; - }, $strip>, ZodMiniTransform<{ - renditions: { - [x: string]: { - bitrate?: number & $brand<"u53"> | undefined; - broadcast?: RelativeBroadcast | undefined; - codec: string; - container: { - kind: "legacy"; - } | { - init: string; - kind: "cmaf"; - } | { - kind: "loc"; - } | { - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }; - delay?: number & $brand<"u53"> | undefined; - description?: string | undefined; - enabled?: boolean | undefined; - epoch?: ReferenceEpoch | undefined; - hls?: { - duration: number & $brand<"u53">; - track: string; - } | undefined; - jitter?: number & $brand<"u53"> | undefined; - label?: string | undefined; - layout?: string | undefined; - numberOfChannels: number & $brand<"u53">; - sampleRate: number & $brand<"u53">; - track?: string | undefined; - warmup?: number & $brand<"u53"> | undefined; - }; - }; - }, { - config: { + export const AudioSchema: ZodMiniObject<{ + renditions: ZodMiniPipe, Record>, ZodMiniTransform | undefined; broadcast?: RelativeBroadcast | undefined; codec: string; @@ -224,11 +103,8 @@ export namespace Audio { sampleRate: number & $brand<"u53">; track?: string | undefined; warmup?: number & $brand<"u53"> | undefined; - }; - track: { - name: string; - }; - }>>]>; + }>, Record>>; + }, $strip>; export function ranked(renditions: Record): [string, Audio.AudioConfig][]; } @@ -413,128 +289,8 @@ export const RelativeBroadcastSchema: ZodMiniType; export type Root = infer; export const RootSchema: ZodMiniObject<{ - audio: ZodMiniOptional, ZodMiniObject<{ - bitrate: ZodMiniOptional<$ZodBranded, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - layout: ZodMiniOptional>; - numberOfChannels: $ZodBranded, "u53", "out">; - sampleRate: $ZodBranded, "u53", "out">; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>>; - }, $strip>, ZodMiniPipe, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - layout: ZodMiniOptional>; - numberOfChannels: $ZodBranded, "u53", "out">; - sampleRate: $ZodBranded, "u53", "out">; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>; - track: ZodMiniObject<{ - name: ZodMiniString; - }, $strip>; - }, $strip>, ZodMiniTransform<{ - renditions: { - [x: string]: { - bitrate?: number & $brand<"u53"> | undefined; - broadcast?: RelativeBroadcast | undefined; - codec: string; - container: { - kind: "legacy"; - } | { - init: string; - kind: "cmaf"; - } | { - kind: "loc"; - } | { - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }; - delay?: number & $brand<"u53"> | undefined; - description?: string | undefined; - enabled?: boolean | undefined; - epoch?: ReferenceEpoch | undefined; - hls?: { - duration: number & $brand<"u53">; - track: string; - } | undefined; - jitter?: number & $brand<"u53"> | undefined; - label?: string | undefined; - layout?: string | undefined; - numberOfChannels: number & $brand<"u53">; - sampleRate: number & $brand<"u53">; - track?: string | undefined; - warmup?: number & $brand<"u53"> | undefined; - }; - }; - }, { - config: { + audio: ZodMiniOptional, Record>, ZodMiniTransform | undefined; broadcast?: RelativeBroadcast | undefined; codec: string; @@ -567,11 +323,8 @@ export const RootSchema: ZodMiniObject<{ sampleRate: number & $brand<"u53">; track?: string | undefined; warmup?: number & $brand<"u53"> | undefined; - }; - track: { - name: string; - }; - }>>]>>; + }>, Record>>; + }, $strip>>; binary: ZodMiniOptional, ZodMiniObject<{ bitrate: ZodMiniOptional<$ZodBranded, "u53", "out">>; @@ -641,303 +394,13 @@ export const RootSchema: ZodMiniObject<{ }, $strip>>; }, $strip>, ZodMiniPipe, ZodMiniTransform>]>>; version: ZodMiniOptional>; - video: ZodMiniOptional, "u53", "out">; width: $ZodBranded, "u53", "out">; }, $strip>>; flip: ZodMiniOptional>; - renditions: ZodMiniRecord, ZodMiniObject<{ - bitrate: ZodMiniOptional<$ZodBranded, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - codedHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - codedWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - color: ZodMiniOptional; - maxFall: ZodMiniNumber; - }, $strip>>; - mastering: ZodMiniOptional; - y: ZodMiniNumber; - }, $strip>; - green: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - maxLuminance: ZodMiniNumber; - minLuminance: ZodMiniNumber; - red: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - white: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - }, $strip>>; - matrix: ZodMiniOptional<$ZodBranded, "u8", "out">>; - primaries: ZodMiniOptional<$ZodBranded, "u8", "out">>; - range: ZodMiniOptional>; - transfer: ZodMiniOptional<$ZodBranded, "u8", "out">>; - }, $strip>>; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - displayAspectHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - displayAspectWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - framerate: ZodMiniOptional>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - interlaced: ZodMiniOptional>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - optimizeForLatency: ZodMiniOptional>; - preference: ZodMiniOptional; - projection: ZodMiniOptional; - }, $strip>, ZodMiniObject<{ - fov: ZodMiniOptional>; - kind: ZodMiniLiteral<"equirectangular">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - reorder: ZodMiniOptional<$ZodBranded, "u8", "out">>; - stereo: ZodMiniOptional>; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>>; - rotation: ZodMiniOptional>; - }, $strip>, ZodMiniPipe, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - codedHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - codedWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - color: ZodMiniOptional; - maxFall: ZodMiniNumber; - }, $strip>>; - mastering: ZodMiniOptional; - y: ZodMiniNumber; - }, $strip>; - green: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - maxLuminance: ZodMiniNumber; - minLuminance: ZodMiniNumber; - red: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - white: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - }, $strip>>; - matrix: ZodMiniOptional<$ZodBranded, "u8", "out">>; - primaries: ZodMiniOptional<$ZodBranded, "u8", "out">>; - range: ZodMiniOptional>; - transfer: ZodMiniOptional<$ZodBranded, "u8", "out">>; - }, $strip>>; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - displayAspectHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - displayAspectWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - framerate: ZodMiniOptional>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - interlaced: ZodMiniOptional>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - optimizeForLatency: ZodMiniOptional>; - preference: ZodMiniOptional; - projection: ZodMiniOptional; - }, $strip>, ZodMiniObject<{ - fov: ZodMiniOptional>; - kind: ZodMiniLiteral<"equirectangular">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - reorder: ZodMiniOptional<$ZodBranded, "u8", "out">>; - stereo: ZodMiniOptional>; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>; - track: ZodMiniObject<{ - name: ZodMiniString; - }, $strip>; - }, $strip>>, ZodMiniTransform<{ - display: { - height: number & $brand<"u53">; - width: number & $brand<"u53">; - } | undefined; - flip: undefined; - renditions: { - [k: string]: { - bitrate?: number & $brand<"u53"> | undefined; - broadcast?: RelativeBroadcast | undefined; - codec: string; - codedHeight?: number & $brand<"u53"> | undefined; - codedWidth?: number & $brand<"u53"> | undefined; - color?: { - contentLight?: { - maxCll: number; - maxFall: number; - } | undefined; - mastering?: { - blue: { - x: number; - y: number; - }; - green: { - x: number; - y: number; - }; - maxLuminance: number; - minLuminance: number; - red: { - x: number; - y: number; - }; - white: { - x: number; - y: number; - }; - } | undefined; - matrix?: number & $brand<"u8"> | undefined; - primaries?: number & $brand<"u8"> | undefined; - range?: "full" | "limited" | undefined; - transfer?: number & $brand<"u8"> | undefined; - } | undefined; - container: { - kind: "legacy"; - } | { - init: string; - kind: "cmaf"; - } | { - kind: "loc"; - } | { - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }; - delay?: number & $brand<"u53"> | undefined; - description?: string | undefined; - displayAspectHeight?: number & $brand<"u53"> | undefined; - displayAspectWidth?: number & $brand<"u53"> | undefined; - enabled?: boolean | undefined; - epoch?: ReferenceEpoch | undefined; - framerate?: number | undefined; - hls?: { - duration: number & $brand<"u53">; - track: string; - } | undefined; - interlaced?: boolean | undefined; - jitter?: number & $brand<"u53"> | undefined; - label?: string | undefined; - optimizeForLatency?: boolean | undefined; - preference?: number | undefined; - projection?: { - kind: "rectilinear"; - } | { - fov?: number | undefined; - kind: "equirectangular"; - } | { - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - } | undefined; - reorder?: number & $brand<"u8"> | undefined; - stereo?: string | undefined; - track?: string | undefined; - warmup?: number & $brand<"u53"> | undefined; - }; - }; - rotation: undefined; - }, { - config: { + renditions: ZodMiniPipe, Record>, ZodMiniTransform | undefined; broadcast?: RelativeBroadcast | undefined; codec: string; @@ -1019,11 +482,9 @@ export const RootSchema: ZodMiniObject<{ stereo?: string | undefined; track?: string | undefined; warmup?: number & $brand<"u53"> | undefined; - }; - track: { - name: string; - }; - }[]>>]>>; + }>, Record>>; + rotation: ZodMiniOptional>; + }, $strip>>; }, $loose>; export type Stats = infer; @@ -1291,303 +752,13 @@ export namespace Video { track: ZodMiniOptional>; warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; }, $strip>; - export const VideoSchema: ZodMiniUnion, "u53", "out">; width: $ZodBranded, "u53", "out">; }, $strip>>; flip: ZodMiniOptional>; - renditions: ZodMiniRecord, ZodMiniObject<{ - bitrate: ZodMiniOptional<$ZodBranded, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - codedHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - codedWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - color: ZodMiniOptional; - maxFall: ZodMiniNumber; - }, $strip>>; - mastering: ZodMiniOptional; - y: ZodMiniNumber; - }, $strip>; - green: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - maxLuminance: ZodMiniNumber; - minLuminance: ZodMiniNumber; - red: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - white: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - }, $strip>>; - matrix: ZodMiniOptional<$ZodBranded, "u8", "out">>; - primaries: ZodMiniOptional<$ZodBranded, "u8", "out">>; - range: ZodMiniOptional>; - transfer: ZodMiniOptional<$ZodBranded, "u8", "out">>; - }, $strip>>; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - displayAspectHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - displayAspectWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - framerate: ZodMiniOptional>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - interlaced: ZodMiniOptional>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - optimizeForLatency: ZodMiniOptional>; - preference: ZodMiniOptional; - projection: ZodMiniOptional; - }, $strip>, ZodMiniObject<{ - fov: ZodMiniOptional>; - kind: ZodMiniLiteral<"equirectangular">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - reorder: ZodMiniOptional<$ZodBranded, "u8", "out">>; - stereo: ZodMiniOptional>; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>>; - rotation: ZodMiniOptional>; - }, $strip>, ZodMiniPipe, "u53", "out">>; - broadcast: ZodMiniOptional>>; - codec: ZodMiniString; - codedHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - codedWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - color: ZodMiniOptional; - maxFall: ZodMiniNumber; - }, $strip>>; - mastering: ZodMiniOptional; - y: ZodMiniNumber; - }, $strip>; - green: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - maxLuminance: ZodMiniNumber; - minLuminance: ZodMiniNumber; - red: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - white: ZodMiniObject<{ - x: ZodMiniNumber; - y: ZodMiniNumber; - }, $strip>; - }, $strip>>; - matrix: ZodMiniOptional<$ZodBranded, "u8", "out">>; - primaries: ZodMiniOptional<$ZodBranded, "u8", "out">>; - range: ZodMiniOptional>; - transfer: ZodMiniOptional<$ZodBranded, "u8", "out">>; - }, $strip>>; - container: ZodMiniDefault; - }, $strip>, ZodMiniObject<{ - init: ZodMiniBase64; - kind: ZodMiniLiteral<"cmaf">; - }, $strip>, ZodMiniObject<{ - kind: ZodMiniLiteral<"loc">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - delay: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - description: ZodMiniOptional>; - displayAspectHeight: ZodMiniOptional<$ZodBranded, "u53", "out">>; - displayAspectWidth: ZodMiniOptional<$ZodBranded, "u53", "out">>; - enabled: ZodMiniOptional>; - epoch: ZodMiniOptional>>; - framerate: ZodMiniOptional>; - hls: ZodMiniCatch, "u53", "out">; - track: ZodMiniString; - }, $strip>>>; - interlaced: ZodMiniOptional>; - jitter: ZodMiniOptional, "u53", "out">, ZodMiniTransform | undefined, number & $brand<"u53">>>>; - label: ZodMiniOptional>; - optimizeForLatency: ZodMiniOptional>; - preference: ZodMiniOptional; - projection: ZodMiniOptional; - }, $strip>, ZodMiniObject<{ - fov: ZodMiniOptional>; - kind: ZodMiniLiteral<"equirectangular">; - }, $strip>], "kind">, ZodMiniPipe; - }, $loose>, ZodMiniTransform<{ - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }, { - [x: string]: unknown; - kind: string; - }>>]>>; - reorder: ZodMiniOptional<$ZodBranded, "u8", "out">>; - stereo: ZodMiniOptional>; - track: ZodMiniOptional>; - warmup: ZodMiniOptional<$ZodBranded, "u53", "out">>; - }, $strip>; - track: ZodMiniObject<{ - name: ZodMiniString; - }, $strip>; - }, $strip>>, ZodMiniTransform<{ - display: { - height: number & $brand<"u53">; - width: number & $brand<"u53">; - } | undefined; - flip: undefined; - renditions: { - [k: string]: { - bitrate?: number & $brand<"u53"> | undefined; - broadcast?: RelativeBroadcast | undefined; - codec: string; - codedHeight?: number & $brand<"u53"> | undefined; - codedWidth?: number & $brand<"u53"> | undefined; - color?: { - contentLight?: { - maxCll: number; - maxFall: number; - } | undefined; - mastering?: { - blue: { - x: number; - y: number; - }; - green: { - x: number; - y: number; - }; - maxLuminance: number; - minLuminance: number; - red: { - x: number; - y: number; - }; - white: { - x: number; - y: number; - }; - } | undefined; - matrix?: number & $brand<"u8"> | undefined; - primaries?: number & $brand<"u8"> | undefined; - range?: "full" | "limited" | undefined; - transfer?: number & $brand<"u8"> | undefined; - } | undefined; - container: { - kind: "legacy"; - } | { - init: string; - kind: "cmaf"; - } | { - kind: "loc"; - } | { - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - }; - delay?: number & $brand<"u53"> | undefined; - description?: string | undefined; - displayAspectHeight?: number & $brand<"u53"> | undefined; - displayAspectWidth?: number & $brand<"u53"> | undefined; - enabled?: boolean | undefined; - epoch?: ReferenceEpoch | undefined; - framerate?: number | undefined; - hls?: { - duration: number & $brand<"u53">; - track: string; - } | undefined; - interlaced?: boolean | undefined; - jitter?: number & $brand<"u53"> | undefined; - label?: string | undefined; - optimizeForLatency?: boolean | undefined; - preference?: number | undefined; - projection?: { - kind: "rectilinear"; - } | { - fov?: number | undefined; - kind: "equirectangular"; - } | { - kind: "unknown"; - raw: { - [x: string]: unknown; - kind: string; - }; - } | undefined; - reorder?: number & $brand<"u8"> | undefined; - stereo?: string | undefined; - track?: string | undefined; - warmup?: number & $brand<"u53"> | undefined; - }; - }; - rotation: undefined; - }, { - config: { + renditions: ZodMiniPipe, Record>, ZodMiniTransform | undefined; broadcast?: RelativeBroadcast | undefined; codec: string; @@ -1669,11 +840,9 @@ export namespace Video { stereo?: string | undefined; track?: string | undefined; warmup?: number & $brand<"u53"> | undefined; - }; - track: { - name: string; - }; - }[]>>]>; + }>, Record>>; + rotation: ZodMiniOptional>; + }, $strip>; export function ranked(renditions: Record): [string, Video.VideoConfig][]; } @@ -1693,6 +862,8 @@ export function compressionSupported(compression: Compression): compression is " export function containerSupported(container: Container): boolean; +export const countSchema: $ZodBranded, "u53", "out">; + export function detectFormat(name: string): Format | undefined; export function encode(root: Root): Root; diff --git a/js/hang/src/catalog/audio.ts b/js/hang/src/catalog/audio.ts index 4ab198b21e5..1e44798b618 100644 --- a/js/hang/src/catalog/audio.ts +++ b/js/hang/src/catalog/audio.ts @@ -5,11 +5,16 @@ import { hexSchema } from "./hex"; import { HlsFieldSchema } from "./hls"; import { u53Schema } from "./integers"; import { EpochSchema, RelativeBroadcastSchema } from "./path"; +import { codecNumber, countSchema, renditions } from "./section"; -// Backwards compatibility: old track schema -const TrackSchema = z.object({ - name: z.string(), -}); +/** + * Whether `codec` parses: an AAC string names its object type, while any other string is carried + * as a codec this build may not decode. Mirrors the Rust `AudioCodec` parser. + */ +function codecValid(codec: string): boolean { + if (codec.startsWith("mp4a.40.")) return codecNumber(codec.slice("mp4a.40.".length), 10, 0xff); + return true; +} const AudioConfigFields = z.object({ // Optional reference to another broadcast that publishes this track, expressed @@ -30,7 +35,7 @@ const AudioConfigFields = z.object({ // Registered WebCodecs codec string, or Hang's "pcm" extension for // interleaved little-endian IEEE-754 binary32 samples. - codec: z.string(), + codec: z.string().check(z.refine(codecValid, "malformed codec string")), // The container format, used to decode the timestamp and more. container: ContainerSchema, @@ -40,11 +45,11 @@ const AudioConfigFields = z.object({ // Otherwise, the initialization information is in-band. description: z.optional(hexSchema), - // The sample rate of the audio in Hz - sampleRate: u53Schema, + // The sample rate of the audio in Hz, never zero. + sampleRate: countSchema, - // The number of channels in the audio - numberOfChannels: u53Schema, + // The number of channels in the audio, never zero. + numberOfChannels: countSchema, // What the decoded channels carry. Absent means the codec's own channel order. "ambisonic" is // full-sphere AmbiX (ACN order, SN3D normalization) whose order follows from numberOfChannels, @@ -113,23 +118,11 @@ function isAmbisonic(channels: number): boolean { } /** Schema for the catalog audio section: a map of track name to rendition config. */ -export const AudioSchema = z.union([ - z.object({ - // A map of track name to rendition configuration. - // This is not an array so it will work with JSON Merge Patch. - renditions: z.record(z.string(), AudioConfigSchema), - }), - // Backwards compatibility: transform old {track, config} format to new object format - z.pipe( - z.object({ - track: TrackSchema, - config: AudioConfigSchema, - }), - z.transform((old) => ({ - renditions: { [old.track.name]: old.config }, - })), - ), -]); +export const AudioSchema = z.object({ + // A map of track name to rendition configuration, skipping a malformed rendition. + // This is not an array so it will work with JSON Merge Patch. + renditions: renditions(AudioConfigSchema), +}); /** The catalog audio section: renditions keyed by track name. */ export type Audio = z.infer; diff --git a/js/hang/src/catalog/clock.test.ts b/js/hang/src/catalog/clock.test.ts index b0533a214c4..15ed8435f65 100644 --- a/js/hang/src/catalog/clock.test.ts +++ b/js/hang/src/catalog/clock.test.ts @@ -90,7 +90,7 @@ test("wallClockTime refuses bad inputs", () => { test("the packaged shape maps HLS record timestamps through the root clock", () => { const catalog = RootSchema.parse(FIXTURE); if (!catalog.clock) throw new Error("fixture lost its clock"); - const video = catalog.video && "renditions" in catalog.video ? catalog.video.renditions.video : undefined; + const video = catalog.video?.renditions.video; expect(video?.hls).toEqual({ track: "video.hls", duration: u53(2000) }); // Record PTS 2000 (ms) lands 2s after the wall epoch. diff --git a/js/hang/src/catalog/container.test.ts b/js/hang/src/catalog/container.test.ts index c3973b7e0e9..18442130275 100644 --- a/js/hang/src/catalog/container.test.ts +++ b/js/hang/src/catalog/container.test.ts @@ -38,7 +38,7 @@ test("catalog with an unknown container keeps its other renditions", () => { }; const parsed = RootSchema.parse(catalog); - if (!parsed.video || !("renditions" in parsed.video)) throw new Error("missing video section"); + if (!parsed.video) throw new Error("missing video section"); const known = parsed.video.renditions.legacy; expect(known?.container.kind).toBe("legacy"); diff --git a/js/hang/src/catalog/parity.test.ts b/js/hang/src/catalog/parity.test.ts new file mode 100644 index 00000000000..8b712eb51a5 --- /dev/null +++ b/js/hang/src/catalog/parity.test.ts @@ -0,0 +1,32 @@ +import { expect, test } from "bun:test"; +import { checkRenditions, RootSchema } from "./root.ts"; + +interface Case { + name: string; + catalog: unknown; + refused?: boolean; + video?: string[]; + audio?: string[]; +} + +// The corpus rs/hang also loads: both languages accept the same catalogs and keep the same +// renditions, so a divergence fails CI on whichever side drifts. +const cases = (await Bun.file( + new URL("../../../../rs/hang/fixtures/catalog-parity.json", import.meta.url), +).json()) as Case[]; + +// Rust's BTreeMap order, so the lists compare as recorded. +const ids = (renditions: Record | undefined) => Object.keys(renditions ?? {}).sort(); + +for (const c of cases) { + test(`shared parity fixture: ${c.name}`, () => { + const parse = () => checkRenditions(RootSchema.parse(c.catalog)); + if (c.refused) { + expect(parse).toThrow(); + return; + } + const root = parse(); + expect(ids(root.video?.renditions)).toEqual(c.video ?? []); + expect(ids(root.audio?.renditions)).toEqual(c.audio ?? []); + }); +} diff --git a/js/hang/src/catalog/root.test.ts b/js/hang/src/catalog/root.test.ts index 73237758936..7b714270bcb 100644 --- a/js/hang/src/catalog/root.test.ts +++ b/js/hang/src/catalog/root.test.ts @@ -39,7 +39,7 @@ test("rendition broadcast reference is parsed and normalized", () => { }, }; const parsed = RootSchema.parse(catalog); - if (!parsed.video || !("renditions" in parsed.video)) throw new Error("missing video section"); + if (!parsed.video) throw new Error("missing video section"); // Normalized like Rust path::Relative: redundant `.` and empty segments are dropped. expect(parsed.video.renditions.video?.broadcast).toBe("source" as RelativeBroadcast); }); @@ -71,8 +71,8 @@ test("every reference-bearing section carries an optional epoch", () => { }); const parsed = RootSchema.parse(catalog(EPOCH)); - if (!parsed.video || !("renditions" in parsed.video)) throw new Error("missing video section"); - if (!parsed.audio || !("renditions" in parsed.audio)) throw new Error("missing audio section"); + if (!parsed.video) throw new Error("missing video section"); + if (!parsed.audio) throw new Error("missing audio section"); expect(parsed.video.renditions.v?.epoch).toBe(EPOCH); expect(parsed.audio.renditions.a?.epoch).toBe(EPOCH); expect(parsed.text?.renditions.t?.epoch).toBe(EPOCH); @@ -98,7 +98,7 @@ test("rendition parent broadcast reference stays distinct from empty", () => { }, }; const parsed = RootSchema.parse(catalog); - if (!parsed.video || !("renditions" in parsed.video)) throw new Error("missing video section"); + if (!parsed.video) throw new Error("missing video section"); expect(parsed.video.renditions.video?.broadcast).toBe("." as RelativeBroadcast); }); @@ -111,7 +111,7 @@ test("rendition without broadcast reference stays undefined", () => { }, }; const parsed = RootSchema.parse(catalog); - if (!parsed.video || !("renditions" in parsed.video)) throw new Error("missing video section"); + if (!parsed.video) throw new Error("missing video section"); expect(parsed.video.renditions.video?.broadcast).toBeUndefined(); }); @@ -180,7 +180,7 @@ test("a rendition's hls field round-trips", () => { const parsed = RootSchema.parse({ video: { renditions: { video: { codec: "avc1.64001f", container: { kind: "legacy" }, hls } } }, }); - if (!parsed.video || !("renditions" in parsed.video)) throw new Error("missing video section"); + if (!parsed.video) throw new Error("missing video section"); expect(parsed.video.renditions.video?.hls).toEqual({ track: hls.track, duration: u53(hls.duration) }); expect(JSON.stringify(parsed)).toContain('"hls":{"track":"video.hls","duration":2000}'); }); @@ -189,7 +189,7 @@ test("a malformed hls field leaves the rendition playable", () => { const config = { codec: "avc1.64001f", container: { kind: "legacy" } }; for (const hls of [{ track: "video.hls" }, { duration: 2000 }, { track: 42, duration: 2000 }, "video.hls", null]) { const parsed = RootSchema.parse({ video: { renditions: { video: { ...config, hls } } } }); - if (!parsed.video || !("renditions" in parsed.video)) throw new Error("missing video section"); + if (!parsed.video) throw new Error("missing video section"); expect(parsed.video.renditions.video?.hls).toBeUndefined(); expect(parsed.video.renditions.video?.codec).toBe(config.codec); } diff --git a/js/hang/src/catalog/section.ts b/js/hang/src/catalog/section.ts index 1aa0b26aca5..a4078d1193d 100644 --- a/js/hang/src/catalog/section.ts +++ b/js/hang/src/catalog/section.ts @@ -1,4 +1,5 @@ import * as z from "zod/mini"; +import { u53Schema } from "./integers"; /** * Wrap a catalog section so a value that isn't one decodes as absent rather than failing the @@ -33,6 +34,50 @@ export function section(schema: T, map: string) { ); } +/** + * A media section's renditions, skipping each malformed one instead of refusing the catalog. + * + * A rendition this build cannot read can't be played anyway, so dropping it keeps its siblings + * playable, the same as a rendition with an unknown container. The map itself must be an object, + * so a section that isn't one is still refused. Mirrors the Rust `deserialize_renditions`. + * + * @param schema - one rendition's schema. + */ +export function renditions(schema: T) { + return z.pipe( + // Not `z.record`, which would drop an ID like `__proto__` that JSON.parse keeps as its own. + z.custom>( + (value) => typeof value === "object" && value !== null && !Array.isArray(value), + ), + z.transform((raw) => { + const kept: [string, z.infer][] = []; + for (const [id, value] of Object.entries(raw)) { + const result = schema.safeParse(value); + if (result.success) kept.push([id, result.data]); + else console.warn(`skipping malformed rendition ${id}: ${result.error.message}`); + } + // fromEntries defines each key as its own property, so `__proto__` stays an ID. + return Object.fromEntries(kept) as Record>; + }), + ); +} + +/** + * A nonzero count that fits in 32 bits, such as a picture dimension or sample rate. Branded `u53` + * like the wider counts, since every value fits there too. + */ +export const countSchema = u53Schema.check(z.positive(), z.lte(0xffff_ffff)); + +/** + * Whether a codec string field is digits in `radix`, at most `max`. Refuses the empty field and + * the sign or whitespace `parseInt` alone would take. Mirrors the Rust `codec_number`. + */ +export function codecNumber(field: string | undefined, radix: 10 | 16, max: number): boolean { + if (field === undefined) return false; + const digits = radix === 10 ? /^[0-9]+$/ : /^[0-9a-fA-F]+$/; + return digits.test(field) && Number.parseInt(field, radix) <= max; +} + /** * Like {@link section}, for a section identified by one string field (`stats.track`, `echo.path`) * rather than a map. Mirrors the Rust `deserialize_named`. diff --git a/js/hang/src/catalog/video.test.ts b/js/hang/src/catalog/video.test.ts index 975ba2d4b48..145b20d783d 100644 --- a/js/hang/src/catalog/video.test.ts +++ b/js/hang/src/catalog/video.test.ts @@ -1,6 +1,6 @@ import { expect, test } from "bun:test"; import * as Catalog from "./index.ts"; -import { ranked, VideoConfigSchema, VideoSchema } from "./video.ts"; +import { ranked, VideoConfigSchema } from "./video.ts"; test("ranked puts enabled video before a larger disabled picture", () => { const renditions = { @@ -118,29 +118,6 @@ test("video config ignores a legacy stalled flag", () => { expect(parsed.enabled).toBeUndefined(); }); -test("legacy video arrays derive display size from display aspect fields", () => { - const parsed = VideoSchema.parse([ - { - track: { name: "video" }, - config: { - codec: "avc1.64001f", - container: { kind: "legacy" }, - displayAspectWidth: 16, - displayAspectHeight: 9, - }, - }, - ]); - - expect( - parsed.display && { - width: Number(parsed.display.width), - height: Number(parsed.display.height), - }, - ).toEqual({ width: 16, height: 9 }); - expect(Number(parsed.renditions.video?.displayAspectWidth)).toBe(16); - expect(Number(parsed.renditions.video?.displayAspectHeight)).toBe(9); -}); - test("video warmup round trips as optional integer milliseconds", () => { const base = { codec: "vp8", container: { kind: "legacy" } }; expect(VideoConfigSchema.parse(base).warmup).toBeUndefined(); diff --git a/js/hang/src/catalog/video.ts b/js/hang/src/catalog/video.ts index e75ccc5ad0a..11736e2afa1 100644 --- a/js/hang/src/catalog/video.ts +++ b/js/hang/src/catalog/video.ts @@ -5,11 +5,39 @@ import { hexSchema } from "./hex"; import { HlsFieldSchema } from "./hls"; import { u8Schema, u53Schema } from "./integers"; import { EpochSchema, RelativeBroadcastSchema } from "./path"; +import { codecNumber, countSchema, renditions } from "./section"; + +// av01..., optionally followed by every one of . +// ...... +const AV1 = /^av01\.[0-2]\.[0-9]{2}[MH]\.[0-9]{2}(\.[01]\.[01]{2}[0-3]\.[0-9]{2}\.[0-9]{2}\.[0-9]{2}\.[01])?$/; + +// vp09..., optionally followed by all five color fields, each two digits. +const VP9 = /^vp09(\.[0-9]{2}){3}((\.[0-9]{2}){5})?$/; + +// hvc1/hev1...[.]{0,6} +function hevcValid(codec: string): boolean { + const [, profile, compatibility, level, ...constraints] = codec.split("."); + if (profile === undefined || level === undefined) return false; + // general_profile_space is two bits, and 0 has no letter. + const idc = /^[A-C]/.test(profile) ? profile.slice(1) : profile; + if (!codecNumber(idc, 10, 0xff) || !codecNumber(compatibility, 16, 0xffff_ffff)) return false; + if (!/^[HL]/.test(level) || !codecNumber(level.slice(1), 10, 0xff)) return false; + // Tolerate one empty trailing field (a dangling '.') emitted by older encoders and muxers. + if (constraints.at(-1) === "") constraints.pop(); + return constraints.length <= 6 && constraints.every((constraint) => codecNumber(constraint, 16, 0xff)); +} -// Backwards compatibility: old track schema -const TrackSchema = z.object({ - name: z.string(), -}); +/** + * Whether `codec` parses: a known codec's string must carry its parameters, while any other string + * is carried as a codec this build may not decode. Mirrors the Rust `VideoCodec` parser. + */ +function codecValid(codec: string): boolean { + if (codec.startsWith("avc1.") || codec.startsWith("avc3.")) return /^avc[13]\.[0-9a-fA-F]{6}$/.test(codec); + if (codec.startsWith("hvc1.") || codec.startsWith("hev1.")) return hevcValid(codec); + if (codec.startsWith("vp09.")) return VP9.test(codec); + if (codec.startsWith("av01.")) return AV1.test(codec); + return true; +} // A CIE 1931 xy chromaticity coordinate. const ChromaticitySchema = z.object({ x: z.number(), y: z.number() }); @@ -103,7 +131,7 @@ export const VideoConfigSchema = z.object({ label: z.optional(z.string()), // See: https://w3c.github.io/webcodecs/codec_registry.html - codec: z.string(), + codec: z.string().check(z.refine(codecValid, "malformed codec string")), // The container format, used to decode the timestamp and more. container: ContainerSchema, @@ -115,13 +143,13 @@ export const VideoConfigSchema = z.object({ // The largest width and height the track carries in pixels, fixed for its name. The picture // resizes in band at a keyframe below these ceilings, unless the description pins it. - codedWidth: z.optional(u53Schema), - codedHeight: z.optional(u53Schema), + codedWidth: z.optional(countSchema), + codedHeight: z.optional(countSchema), // The aspect ratio the whole picture is displayed at, as WebCodecs' VideoDecoderConfig // displayAspectWidth/displayAspectHeight. Absent means the decoded picture's own shape. - displayAspectWidth: z.optional(u53Schema), - displayAspectHeight: z.optional(u53Schema), + displayAspectWidth: z.optional(countSchema), + displayAspectHeight: z.optional(countSchema), // The colour the decoded pixels carry, so a renderer need not guess or reparse the bitstream. color: z.optional(ColorSchema), @@ -205,51 +233,28 @@ export const VideoConfigSchema = z.object({ * Schema for the catalog video section: renditions plus display size, rotation, and flip. * Renditions mirror WebCodecs VideoDecoderConfig (https://w3c.github.io/webcodecs/#video-decoder-config). */ -export const VideoSchema = z.union([ - z.object({ - // A map of track name to rendition configuration. - // This is not an array in order for it to work with JSON Merge Patch. - renditions: z.record(z.string(), VideoConfigSchema), - - // Render the video at this size in pixels. - // This is separate from the display aspect ratio because it does not require reinitialization. - display: z.optional( - z.object({ - width: u53Schema, - height: u53Schema, - }), - ), - - // The rotation of the video in degrees. - // Default: 0 - rotation: z.optional(z.number()), - - // If true, the decoder will flip the video horizontally - // Default: false - flip: z.optional(z.boolean()), - }), - // Backwards compatibility: transform old array of {track, config} to new object format - z.pipe( - z.array( - z.object({ - track: TrackSchema, - config: VideoConfigSchema, - }), - ), - z.transform((arr) => { - const config = arr[0]?.config; - return { - renditions: Object.fromEntries(arr.map((item) => [item.track.name, item.config])), - display: - config?.displayAspectWidth !== undefined && config?.displayAspectHeight !== undefined - ? { width: config.displayAspectWidth, height: config.displayAspectHeight } - : undefined, - rotation: undefined, - flip: undefined, - }; +export const VideoSchema = z.object({ + // A map of track name to rendition configuration, skipping a malformed rendition. + // This is not an array in order for it to work with JSON Merge Patch. + renditions: renditions(VideoConfigSchema), + + // Render the video at this size in pixels. + // This is separate from the display aspect ratio because it does not require reinitialization. + display: z.optional( + z.object({ + width: u53Schema.check(z.lte(0xffff_ffff)), + height: u53Schema.check(z.lte(0xffff_ffff)), }), ), -]); + + // The rotation of the video in degrees. + // Default: 0 + rotation: z.optional(z.number()), + + // If true, the decoder will flip the video horizontally + // Default: false + flip: z.optional(z.boolean()), +}); /** The catalog video section: renditions keyed by track name plus display options. */ export type Video = z.infer; diff --git a/rs/hang/Cargo.toml b/rs/hang/Cargo.toml index 3c59a1a0ddb..258c8c01a69 100644 --- a/rs/hang/Cargo.toml +++ b/rs/hang/Cargo.toml @@ -24,6 +24,7 @@ serde = { workspace = true } serde_json = { workspace = true } serde_with = { workspace = true, features = ["base64"] } thiserror = { workspace = true } +tracing = { workspace = true } url = { workspace = true, features = ["serde"] } [dependencies.derive_more] @@ -35,7 +36,6 @@ anyhow = { workspace = true } moq-mux = { path = "../moq-mux" } moq-tokio = { path = "../moq-tokio", default-features = false, features = ["quic", "aws-lc-rs", "websocket"] } tokio = { workspace = true, features = ["macros", "fs"] } -tracing = { workspace = true } url = { workspace = true } [lints] diff --git a/rs/hang/fixtures/catalog-parity.json b/rs/hang/fixtures/catalog-parity.json new file mode 100644 index 00000000000..702179474a0 --- /dev/null +++ b/rs/hang/fixtures/catalog-parity.json @@ -0,0 +1,3981 @@ +[ + { + "name": "video codec 'avc1.64001f'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'avc3.64001F'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc3.64001F" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'avc1.6400'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.6400" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'avc1.64001g'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001g" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'avc1.64001f.00'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f.00" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'avc1.'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1." + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'avc1'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'AVC1.64001f'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "AVC1.64001f" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'hvc1.1.6.L93.B0'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93.B0" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'hev1.1.6.L93.90'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hev1.1.6.L93.90" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'hvc1.1.6.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'hvc1.A1.6.L93.B0'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.A1.6.L93.B0" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'hvc1.2.4.H120.B0.0.0.0.0.0'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.2.4.H120.B0.0.0.0.0.0" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'hvc1.1.6.L93.B0.'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93.B0." + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'hvc1.D1.6.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.D1.6.L93" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.1.6.X93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.X93" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.1.6'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.x.6.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.x.6.L93" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.+1.6.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.+1.6.L93" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.1.6.L93..B0'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93..B0" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.1.6.L93.B0.0.0.0.0.0.0'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93.B0.0.0.0.0.0.0" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.1.6.L256'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L256" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.1.123456789.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.123456789.L93" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'hvc1.1.6.L93.100'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93.100" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'vp8'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp8" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'vp09.00.10.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.00.10.08" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'vp09.02.10.10.01.09.16.09.01'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.02.10.10.01.09.16.09.01" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'vp09.0.10.8'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.0.10.8" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'vp09.00.10'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.00.10" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'vp09.00.10.08.01'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.00.10.08.01" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'vp09.00.10.08.01.09.16.09.01.00'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.00.10.08.01.09.16.09.01.00" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'vp09.+0.10.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.+0.10.08" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'av01.0.04M.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.04M.08" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'av01.0.04M.10.0.110.01.01.01.0'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.04M.10.0.110.01.01.01.0" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec 'av01.3.04M.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.3.04M.08" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'av01.0.4M.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.4M.08" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'av01.0.04X.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.04X.08" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'av01.0.04M.08.0.110'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.04M.08.0.110" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codec 'future'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "future" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec ''", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'mp4a.40.2'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.2", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'mp4a.40.02'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.02", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'mp4a.40.29'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.29", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'mp4a.40.'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio codec 'mp4a.40.x'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.x", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio codec 'mp4a.40.256'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.256", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio codec 'mp4a.40.+2'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.+2", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio codec 'mp4a.40.2.1'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.40.2.1", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio codec 'mp4a.67'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp4a.67", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'opus'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'pcm'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "pcm", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'flac'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "flac", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'mp3'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp3", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'mp2'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "mp2", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'ac-3'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "ac-3", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'ec-3'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "ec-3", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio codec 'future'", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "future", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video codedWidth 1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 1 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codedWidth 4294967295", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 4294967295 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codedWidth 4294967296", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 4294967296 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedWidth 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 5000000000 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedWidth 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 0 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedWidth -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedWidth 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedWidth '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": "1280" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedHeight 1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 1 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codedHeight 4294967295", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 4294967295 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codedHeight 4294967296", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 4294967296 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedHeight 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 5000000000 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedHeight 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 0 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedHeight -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedHeight 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video codedHeight '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": "1280" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectWidth 1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 1 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video displayAspectWidth 4294967295", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 4294967295 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video displayAspectWidth 4294967296", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 4294967296 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectWidth 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 5000000000 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectWidth 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 0 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectWidth -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectWidth 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectWidth '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": "1280" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectHeight 1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 1 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video displayAspectHeight 4294967295", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 4294967295 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video displayAspectHeight 4294967296", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 4294967296 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectHeight 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 5000000000 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectHeight 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 0 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectHeight -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectHeight 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video displayAspectHeight '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": "1280" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio sampleRate 1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 1, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio sampleRate 4294967295", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 4294967295, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio sampleRate 4294967296", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 4294967296, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio sampleRate 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 0, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio sampleRate -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": -1, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio sampleRate 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 1.5, + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio numberOfChannels 1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 1 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio numberOfChannels 4294967295", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 4294967295 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio numberOfChannels 4294967296", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 4294967296 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio numberOfChannels 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 0 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio numberOfChannels -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": -1 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio numberOfChannels 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 1.5 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video bitrate 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "bitrate": 0 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio bitrate 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "bitrate": 0 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video bitrate 9007199254740991", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "bitrate": 9007199254740991 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio bitrate 9007199254740991", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "bitrate": 9007199254740991 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video bitrate 9007199254740992", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "bitrate": 9007199254740992 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio bitrate 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "bitrate": 9007199254740992 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video bitrate -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "bitrate": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio bitrate -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "bitrate": -1 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video bitrate 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "bitrate": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio bitrate 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "bitrate": 1.5 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video jitter 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "jitter": 0 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio jitter 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "jitter": 0 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video jitter 9007199254740991", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "jitter": 9007199254740991 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio jitter 9007199254740991", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "jitter": 9007199254740991 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video jitter 9007199254740992", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "jitter": 9007199254740992 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio jitter 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "jitter": 9007199254740992 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video jitter -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "jitter": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio jitter -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "jitter": -1 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video jitter 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "jitter": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio jitter 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "jitter": 1.5 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video warmup 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "warmup": 0 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio warmup 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "warmup": 0 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video warmup 9007199254740991", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "warmup": 9007199254740991 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio warmup 9007199254740991", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "warmup": 9007199254740991 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video warmup 9007199254740992", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "warmup": 9007199254740992 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio warmup 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "warmup": 9007199254740992 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video warmup -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "warmup": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio warmup -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "warmup": -1 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video warmup 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "warmup": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio warmup 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "warmup": 1.5 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video delay 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "delay": 0 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio delay 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "delay": 0 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video delay 9007199254740991", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "delay": 9007199254740991 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio delay 9007199254740991", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "delay": 9007199254740991 + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video delay 9007199254740992", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "delay": 9007199254740992 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio delay 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "delay": 9007199254740992 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video delay -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "delay": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio delay -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "delay": -1 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video delay 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "delay": 1.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio delay 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "delay": 1.5 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video reorder 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "reorder": 0 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video reorder 255", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "reorder": 255 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video reorder 256", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "reorder": 256 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video reorder -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "reorder": -1 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video preference -2147483648", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "preference": -2147483648 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video preference 2147483647", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "preference": 2147483647 + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video preference 2147483648", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "preference": 2147483648 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video preference -2147483649", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "preference": -2147483649 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video preference 0.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "preference": 0.5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video container {\"kind\": \"legacy\"}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": "legacy" + } + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio container {\"kind\": \"legacy\"}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": { + "kind": "legacy" + } + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video container {\"kind\": \"loc\"}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": "loc" + } + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio container {\"kind\": \"loc\"}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": { + "kind": "loc" + } + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video container {\"kind\": \"cmaf\", \"init\": \"AAEC\"}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": "cmaf", + "init": "AAEC" + } + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio container {\"kind\": \"cmaf\", \"init\": \"AAEC\"}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": { + "kind": "cmaf", + "init": "AAEC" + } + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video container {\"kind\": \"future\", \"magic\": 7}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": "future", + "magic": 7 + } + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio container {\"kind\": \"future\", \"magic\": 7}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": { + "kind": "future", + "magic": 7 + } + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video container {\"kind\": \"cmaf\"}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": "cmaf" + } + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio container {\"kind\": \"cmaf\"}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": { + "kind": "cmaf" + } + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video container {}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": {} + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio container {}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": {} + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video container {\"kind\": 5}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": 5 + } + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio container {\"kind\": 5}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": { + "kind": 5 + } + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video container {\"kind\": null}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": null + } + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio container {\"kind\": null}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": { + "kind": null + } + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video container \"legacy\"", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": "legacy" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio container \"legacy\"", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": "legacy" + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video description odd hex", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "description": "abc" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video description base64", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "description": "AUIAKv/h" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video description uppercase hex", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "description": "ABCD" + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video codec not a string", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": 5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video label not a string", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "label": 5 + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video enabled not a boolean", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "enabled": "yes" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video malformed epoch", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "epoch": "not-a-uuid" + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video projection fov out of range", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "projection": { + "kind": "equirectangular", + "fov": 400 + } + } + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "video projection unknown kind", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "projection": { + "kind": "cubemap" + } + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "video undecodable hls", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "hls": { + "track": "video.hls" + } + } + } + } + }, + "video": [ + "ok", + "probe" + ] + }, + { + "name": "audio ambisonic with 6 channels", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 6, + "layout": "ambisonic" + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "audio ambisonic with 4 channels", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 4, + "layout": "ambisonic" + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "audio unknown layout", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "layout": "5.1" + } + } + } + }, + "audio": [ + "ok", + "probe" + ] + }, + { + "name": "video rendition not an object", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": 5 + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio rendition not an object", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": [] + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "video rendition missing codec", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": {} + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "audio rendition missing sampleRate", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "numberOfChannels": 2 + } + } + } + }, + "audio": [ + "ok" + ] + }, + { + "name": "every rendition malformed leaves empty sections", + "catalog": { + "video": { + "renditions": { + "bad": { + "codec": "avc1.6400" + } + } + }, + "audio": { + "renditions": { + "bad": { + "codec": "opus", + "sampleRate": 0, + "numberOfChannels": 2 + } + } + } + } + }, + { + "name": "rendition IDs are any string", + "catalog": { + "video": { + "renditions": { + "": { + "codec": "avc1.64001f" + }, + "__proto__": { + "codec": "avc1.64001f" + } + } + } + }, + "video": [ + "", + "__proto__" + ] + }, + { + "name": "empty catalog", + "catalog": {} + }, + { + "name": "video display at u32", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + } + }, + "display": { + "width": 4294967295, + "height": 1 + } + } + }, + "video": [ + "ok" + ] + }, + { + "name": "legacy video array", + "catalog": { + "video": [ + { + "track": { + "name": "video" + }, + "config": { + "codec": "avc1.64001f" + } + } + ] + }, + "refused": true + }, + { + "name": "legacy audio track and config", + "catalog": { + "audio": { + "track": { + "name": "audio" + }, + "config": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + }, + "refused": true + }, + { + "name": "video renditions not an object", + "catalog": { + "video": { + "renditions": [ + { + "codec": "avc1.64001f" + } + ] + } + }, + "refused": true + }, + { + "name": "audio renditions missing", + "catalog": { + "audio": {} + }, + "refused": true + }, + { + "name": "video display width beyond u32", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + } + }, + "display": { + "width": 4294967296, + "height": 1 + } + } + }, + "refused": true + }, + { + "name": "video rotation not a number", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + } + }, + "rotation": "90" + } + }, + "refused": true + }, + { + "name": "one ID for video and audio", + "catalog": { + "video": { + "renditions": { + "main": { + "codec": "avc1.64001f" + } + } + }, + "audio": { + "renditions": { + "main": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + } + } + } + }, + "refused": true + }, + { + "name": "a newer version", + "catalog": { + "version": 5, + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + } + } + } + }, + "refused": true + } +] diff --git a/rs/hang/src/catalog/audio/aac.rs b/rs/hang/src/catalog/audio/aac.rs index 38223e540e3..c755db32860 100644 --- a/rs/hang/src/catalog/audio/aac.rs +++ b/rs/hang/src/catalog/audio/aac.rs @@ -27,7 +27,7 @@ impl std::str::FromStr for AAC { fn from_str(s: &str) -> Result { let remain = s.strip_prefix("mp4a.40.").ok_or(Error::InvalidCodec)?; Ok(Self { - profile: u8::from_str(remain)?, + profile: crate::catalog::codec_number(remain, 10)?, }) } } diff --git a/rs/hang/src/catalog/audio/mod.rs b/rs/hang/src/catalog/audio/mod.rs index 0c13373888d..336377b215c 100644 --- a/rs/hang/src/catalog/audio/mod.rs +++ b/rs/hang/src/catalog/audio/mod.rs @@ -34,6 +34,9 @@ pub struct Audio { /// A map of track name to rendition configuration. /// This is not an array so it will work with JSON Merge Patch. /// We use a BTreeMap so keys are sorted alphabetically for *some* deterministic behavior. + /// + /// A malformed rendition is skipped when decoding rather than refusing the catalog. + #[serde(deserialize_with = "crate::catalog::deserialize_renditions")] pub renditions: BTreeMap, } @@ -132,10 +135,10 @@ pub struct AudioConfig { #[serde_as(as = "DisplayFromStr")] pub codec: AudioCodec, - /// The sample rate of the audio in Hz. + /// The sample rate of the audio in Hz, never zero. pub sample_rate: u32, - /// The number of channels in the audio. + /// The number of channels in the audio, never zero. #[serde(rename = "numberOfChannels")] pub channel_count: u32, @@ -146,8 +149,9 @@ pub struct AudioConfig { #[serde_as(as = "Option")] pub layout: Option, - /// The maximum bitrate of the audio track in bits per second. + /// The maximum bitrate of the audio track in bits per second, at most 2^53 - 1. #[serde(default)] + #[serde_as(as = "Option")] pub bitrate: Option, /// Whether this rendition may be selected. When false, no frames are coming and a consumer @@ -237,6 +241,21 @@ impl AudioConfig { } } +impl crate::catalog::Rendition for AudioConfig { + fn check(&self) -> crate::Result<()> { + if self.sample_rate == 0 { + return Err(crate::Error::Zero("sampleRate")); + } + if self.channel_count == 0 { + return Err(crate::Error::Zero("numberOfChannels")); + } + if let Some(layout) = &self.layout { + layout.check(self.channel_count)?; + } + Ok(()) + } +} + #[cfg(test)] mod test { use super::*; diff --git a/rs/hang/src/catalog/container.rs b/rs/hang/src/catalog/container.rs index 2466f3dbd2e..fa35b5d3ec6 100644 --- a/rs/hang/src/catalog/container.rs +++ b/rs/hang/src/catalog/container.rs @@ -12,7 +12,7 @@ use serde_with::{base64::Base64, serde_as}; /// /// An unrecognized `kind` decodes to [`Container::Unknown`] instead of failing, so one /// rendition using a future container does not take down the rest of the catalog. Such a -/// rendition must be ignored by consumers. +/// rendition must be ignored by consumers. A `kind` that is absent or not a string is malformed. #[derive(Debug, Clone, PartialEq, Default)] pub enum Container { /// A QUIC varint timestamp prefix followed by the raw codec payload. @@ -42,9 +42,13 @@ pub enum Container { pub struct UnknownContainer(serde_json::Map); impl UnknownContainer { - /// The `kind` as it appeared on the wire, or `None` if it was absent or not a string. - pub fn kind(&self) -> Option<&str> { - self.0.get("kind").and_then(serde_json::Value::as_str) + /// The `kind` as it appeared on the wire. + pub fn kind(&self) -> &str { + // Deserialize refuses a container without a string kind, so this is never empty. + self.0 + .get("kind") + .and_then(serde_json::Value::as_str) + .unwrap_or_default() } /// The full JSON object, including `kind`. @@ -99,7 +103,8 @@ impl<'de> Deserialize<'de> for Container { Known::Loc => Self::Loc, }) } - _ => Ok(Self::Unknown(UnknownContainer(object))), + Some(_) => Ok(Self::Unknown(UnknownContainer(object))), + None => Err(de::Error::custom("container `kind` must be a string")), } } } @@ -146,7 +151,7 @@ mod tests { let Container::Unknown(unknown) = &parsed else { panic!("expected unknown: {parsed:?}"); }; - assert_eq!(unknown.kind(), Some("future")); + assert_eq!(unknown.kind(), "future"); assert_eq!(unknown.fields().len(), 3); assert_eq!(serde_json::to_string(&parsed).unwrap(), json); @@ -157,4 +162,11 @@ mod tests { // cmaf without init is not a valid cmaf container and must not degrade to Unknown. serde_json::from_str::(r#"{"kind":"cmaf"}"#).unwrap_err(); } + + #[test] + fn kindless_container_errors() { + for json in [r#"{}"#, r#"{"kind":5}"#, r#"{"kind":null}"#] { + serde_json::from_str::(json).unwrap_err(); + } + } } diff --git a/rs/hang/src/catalog/hex.rs b/rs/hang/src/catalog/hex.rs index 51cc950e197..2938fad6bf5 100644 --- a/rs/hang/src/catalog/hex.rs +++ b/rs/hang/src/catalog/hex.rs @@ -39,14 +39,14 @@ mod test { fn base64_description() { let json = r#"{"video":{"renditions":{"video/0":{"codec":"avc1.42e02a","container":{"kind":"legacy"},"description":"AUIAKv/hABtnQgAq"}}}}"#; - let err = Catalog::<()>::from_str(json).unwrap_err().to_string(); - assert!(err.contains("expected hex"), "{err}"); + // The malformed rendition is skipped, with a warning naming the encoding it expected. + assert!(Catalog::<()>::from_str(json).unwrap().video.renditions.is_empty()); - // Also from an already-parsed Value, which is what a consumer deserializes: moq-json - // reconstructs one from the frames. That carries no line or column, so this message is - // all a consumer gets (moq-json prefixes the field path on its own side). let value: serde_json::Value = serde_json::from_str(json).unwrap(); - let err = serde_json::from_value::(value).unwrap_err().to_string(); + let rendition = value["video"]["renditions"]["video/0"].clone(); + let err = serde_json::from_value::(rendition) + .unwrap_err() + .to_string(); assert!(err.contains("expected hex"), "{err}"); } diff --git a/rs/hang/src/catalog/millis.rs b/rs/hang/src/catalog/millis.rs index 3b0f2cd6f12..c053d80eb9d 100644 --- a/rs/hang/src/catalog/millis.rs +++ b/rs/hang/src/catalog/millis.rs @@ -2,9 +2,9 @@ use std::time::Duration; +use serde::Serializer; use serde::de::Deserializer; use serde::ser::Error as _; -use serde::{Deserialize, Serialize, Serializer}; use serde_with::{DeserializeAs, SerializeAs}; /// A [`serde_with`] adapter encoding a [`Duration`] as whole milliseconds, rounded up. @@ -21,15 +21,15 @@ pub(crate) struct MillisCeil; impl SerializeAs for MillisCeil { fn serialize_as(source: &Duration, serializer: S) -> Result { let millis = source.as_nanos().div_ceil(1_000_000); - u64::try_from(millis) - .map_err(|_| S::Error::custom("a duration too long to express in milliseconds"))? - .serialize(serializer) + let millis = + u64::try_from(millis).map_err(|_| S::Error::custom("a duration too long to express in milliseconds"))?; + crate::snapshot::Number::serialize_as(&millis, serializer) } } impl<'de> DeserializeAs<'de, Duration> for MillisCeil { fn deserialize_as>(deserializer: D) -> Result { - u64::deserialize(deserializer).map(Duration::from_millis) + crate::snapshot::Number::deserialize_as(deserializer).map(Duration::from_millis) } } @@ -51,9 +51,8 @@ impl SerializeAs> for MillisCeil { impl<'de> DeserializeAs<'de, Option> for MillisCeil { fn deserialize_as>(deserializer: D) -> Result, D::Error> { - Ok(Option::::deserialize(deserializer)? - .filter(|millis| *millis != 0) - .map(Duration::from_millis)) + let millis: Option = Option::::deserialize_as(deserializer)?; + Ok(millis.filter(|millis| *millis != 0).map(Duration::from_millis)) } } diff --git a/rs/hang/src/catalog/mod.rs b/rs/hang/src/catalog/mod.rs index 8be1512795f..cf32f589058 100644 --- a/rs/hang/src/catalog/mod.rs +++ b/rs/hang/src/catalog/mod.rs @@ -65,6 +65,69 @@ where Ok(value) } +/// Parse a codec string field of digits in `radix`, refusing the empty field, sign, and whitespace +/// `from_str_radix` alone would take. +pub(crate) fn codec_number>(field: &str, radix: u32) -> Result { + if field.is_empty() || !field.chars().all(|c| c.is_digit(radix)) { + return Err(crate::Error::InvalidCodec); + } + let value = u32::from_str_radix(field, radix).map_err(|_| crate::Error::InvalidCodec)?; + T::try_from(value).map_err(|_| crate::Error::InvalidCodec) +} + +/// Decode a struct only from a JSON object. +/// +/// serde also reads a struct from an array of its fields in order, which would let an array section +/// such as the retired `video: [{track, config}]` form decode as something else entirely. +pub(crate) fn deserialize_object<'de, D, T>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, + T: serde::de::DeserializeOwned, +{ + use serde::Deserialize; + let object = serde_json::Map::deserialize(deserializer)?; + serde_json::from_value(serde_json::Value::Object(object)).map_err(serde::de::Error::custom) +} + +/// A media rendition config, decoded on its own so a malformed one costs only itself. +pub(crate) trait Rendition: serde::de::DeserializeOwned { + /// Refuse a field out of the range its type allows. + fn check(&self) -> crate::Result<()>; +} + +/// Decode a media section's renditions, skipping each malformed one instead of refusing the catalog. +/// +/// A rendition this build cannot read can't be played anyway, so dropping it keeps its siblings +/// playable, the same as a rendition with an unknown container. The map itself must decode, so a +/// section that isn't one is still refused. +pub(crate) fn deserialize_renditions<'de, D, T>( + deserializer: D, +) -> Result, D::Error> +where + D: serde::Deserializer<'de>, + T: Rendition, +{ + use serde::Deserialize; + let renditions = std::collections::BTreeMap::::deserialize(deserializer)?; + + let decode = |value: serde_json::Value| -> crate::Result { + let config: T = deserialize_object(value)?; + config.check()?; + Ok(config) + }; + + Ok(renditions + .into_iter() + .filter_map(|(id, value)| match decode(value) { + Ok(config) => Some((id, config)), + Err(err) => { + tracing::warn!(%id, %err, "skipping malformed rendition"); + None + } + }) + .collect()) +} + /// A catalog section: a map of track name to config, published under one well-known root key. /// /// The associated [`MAP`](Self::MAP) is what tells a real section apart from an application's own diff --git a/rs/hang/src/catalog/root.rs b/rs/hang/src/catalog/root.rs index 0c90a55b35a..a6113c005d5 100644 --- a/rs/hang/src/catalog/root.rs +++ b/rs/hang/src/catalog/root.rs @@ -109,10 +109,18 @@ struct Wire { #[serde(default, getter = "Catalog::min_version", deserialize_with = "deserialize_version")] version: Option, - #[serde(default, skip_serializing_if = "Video::is_empty")] + #[serde( + default, + skip_serializing_if = "Video::is_empty", + deserialize_with = "crate::catalog::deserialize_object" + )] video: Video, - #[serde(default, skip_serializing_if = "Audio::is_empty")] + #[serde( + default, + skip_serializing_if = "Audio::is_empty", + deserialize_with = "crate::catalog::deserialize_object" + )] audio: Audio, #[serde(default)] @@ -253,8 +261,12 @@ impl Catalog<()> { impl Catalog { /// Refuse a catalog with an ID naming both a video and an audio rendition, or with a - /// projection or audio layout out of range. + /// rendition field out of range, such as a zero sample rate or a projection out of bounds. + /// + /// Decoding already skips an out-of-range rendition, so this catches a catalog built by hand. pub fn check_renditions(&self) -> Result<()> { + use crate::catalog::Rendition; + if let Some(id) = self .video .renditions @@ -264,14 +276,10 @@ impl Catalog { return Err(crate::Error::DuplicateRendition(id.clone())); } for config in self.video.renditions.values() { - if let Some(projection) = &config.projection { - projection.check()?; - } + config.check()?; } for config in self.audio.renditions.values() { - if let Some(layout) = &config.layout { - layout.check(config.channel_count)?; - } + config.check()?; } Ok(()) } @@ -411,6 +419,45 @@ mod test { use super::*; + #[derive(Deserialize)] + struct ParityCase { + name: String, + catalog: serde_json::Value, + #[serde(default)] + refused: bool, + #[serde(default)] + video: Vec, + #[serde(default)] + audio: Vec, + } + + /// The corpus `js/hang` also loads: both languages accept the same catalogs and keep the same + /// renditions, so a divergence fails CI on whichever side drifts. + #[test] + fn shared_parity_fixtures() { + let cases: Vec = serde_json::from_str(include_str!("../../fixtures/catalog-parity.json")).unwrap(); + let mut failures = Vec::new(); + for case in cases { + let parsed = Catalog::<()>::from_str(&case.catalog.to_string()).and_then(|catalog| { + catalog.check_renditions()?; + Ok(catalog) + }); + match (parsed, case.refused) { + (Err(_), true) => {} + (Ok(catalog), true) => failures.push(format!("{}: accepted {catalog:?}", case.name)), + (Err(err), false) => failures.push(format!("{}: refused: {err}", case.name)), + (Ok(catalog), false) => { + let video: Vec<_> = catalog.video.renditions.keys().cloned().collect(); + let audio: Vec<_> = catalog.audio.renditions.keys().cloned().collect(); + if (&video, &audio) != (&case.video, &case.audio) { + failures.push(format!("{}: kept video {video:?} audio {audio:?}", case.name)); + } + } + } + } + assert!(failures.is_empty(), "{}", failures.join("\n")); + } + /// The rendition count is the publisher's to choose: a catalog listing many is accepted. #[test] fn many_renditions_are_accepted() { @@ -518,23 +565,38 @@ mod test { )); } + /// A publisher building the catalog by hand is caught before it writes a value every reader skips. #[test] - fn spatial_fields_out_of_range_are_refused() { + fn fields_out_of_range_are_refused() { use crate::catalog::{AudioLayout, Projection, VideoCodec, VideoConfig}; - let mut catalog = Catalog::<()>::from_str( - r#"{"audio": {"renditions": {"amb": {"codec": "opus", "sampleRate": 48000, "numberOfChannels": 6, "layout": "ambisonic", "container": {"kind": "legacy"}}}}}"#, - ) - .unwrap(); + let mut catalog = Catalog::<()>::default(); + let mut amb = AudioConfig::new(Opus, 48_000, 6); + amb.layout = Some(AudioLayout::Ambisonic); + catalog.audio.insert("amb", amb).unwrap(); assert!(matches!( catalog.check_renditions(), Err(crate::Error::InvalidAmbisonicChannels(6)) )); catalog.audio.renditions.get_mut("amb").unwrap().channel_count = 4; - assert_eq!(catalog.audio.renditions["amb"].layout, Some(AudioLayout::Ambisonic)); catalog.check_renditions().unwrap(); - // A publisher building the catalog by hand is caught before it writes the bad value. + catalog.audio.renditions.get_mut("amb").unwrap().sample_rate = 0; + assert!(matches!( + catalog.check_renditions(), + Err(crate::Error::Zero("sampleRate")) + )); + catalog.audio.renditions.get_mut("amb").unwrap().sample_rate = 48_000; + + let mut config = VideoConfig::new(VideoCodec::VP8); + config.coded_width = Some(0); + catalog.video.insert("empty", config).unwrap(); + assert!(matches!( + catalog.check_renditions(), + Err(crate::Error::Zero("codedWidth")) + )); + catalog.video.remove("empty"); + let mut config = VideoConfig::new(VideoCodec::VP8); config.projection = Some(Projection::Equirectangular { fov: Some(400.0) }); catalog.video.insert("vr", config).unwrap(); @@ -852,7 +914,7 @@ mod test { let Container::Unknown(unknown) = &future.container else { panic!("expected unknown container: {:?}", future.container); }; - assert_eq!(unknown.kind(), Some("future")); + assert_eq!(unknown.kind(), "future"); // The unknown rendition survives a republish intact. let output = parsed.to_json().expect("failed to encode"); diff --git a/rs/hang/src/catalog/video/av1.rs b/rs/hang/src/catalog/video/av1.rs index d3713bc322b..8f030e485ea 100644 --- a/rs/hang/src/catalog/video/av1.rs +++ b/rs/hang/src/catalog/video/av1.rs @@ -84,14 +84,14 @@ static AV1_REGEX: std::sync::LazyLock = std::sync::LazyLock::new(| &r" ^av01 \.(?[0-2]) - \.(?\d{2})(?\w) - \.(?\d{2}) + \.(?[0-9]{2})(?[MH]) + \.(?[0-9]{2}) (? - \.(?\d) + \.(?[01]) \.(?[01])(?[01])(?[0-3]) - \.(?\d{2}) - \.(?\d{2}) - \.(?\d{2}) + \.(?[0-9]{2}) + \.(?[0-9]{2}) + \.(?[0-9]{2}) \.(?[01]) )? $" diff --git a/rs/hang/src/catalog/video/h264.rs b/rs/hang/src/catalog/video/h264.rs index 86ea0d94eae..3f6095eb774 100644 --- a/rs/hang/src/catalog/video/h264.rs +++ b/rs/hang/src/catalog/video/h264.rs @@ -47,7 +47,7 @@ impl FromStr for H264 { }; let part = parts.next().ok_or(Error::InvalidCodec)?; - if part.len() != 6 || !part.bytes().all(|byte| byte.is_ascii_hexdigit()) { + if part.len() != 6 || !part.bytes().all(|byte| byte.is_ascii_hexdigit()) || parts.next().is_some() { return Err(Error::InvalidCodec); } @@ -71,7 +71,16 @@ mod tests { #[test] fn malformed_hex_fields_are_invalid() { for prefix in ["avc1", "avc3"] { - for part in ["aé123", "12aé3", "123aé", "+12345", "12+345", "1234+5", "12gg56"] { + for part in [ + "aé123", + "12aé3", + "123aé", + "+12345", + "12+345", + "1234+5", + "12gg56", + "64001f.00", + ] { let encoded = format!("{prefix}.{part}"); assert!( matches!(VideoCodec::from_str(&encoded), Err(Error::InvalidCodec)), diff --git a/rs/hang/src/catalog/video/h265.rs b/rs/hang/src/catalog/video/h265.rs index 7c3d0d419fc..38aaf105f95 100644 --- a/rs/hang/src/catalog/video/h265.rs +++ b/rs/hang/src/catalog/video/h265.rs @@ -104,14 +104,17 @@ impl FromStr for H265 { }; let profile = parts.next().ok_or(Error::InvalidCodec)?; - let profile_space = match profile.as_bytes().first().ok_or(Error::InvalidCodec)? { - b'A'..=b'Z' => 1 + profile.as_bytes()[0] - b'A', - _ => 0, + let (profile_space, profile_idc) = match profile.as_bytes().first().ok_or(Error::InvalidCodec)? { + // general_profile_space is two bits, and 0 has no letter. + space @ b'A'..=b'C' => (1 + space - b'A', &profile[1..]), + _ => (0, profile), }; - let profile_idc = (if profile_space > 0 { &profile[1..] } else { profile }).parse::()?; + let profile_idc = crate::catalog::codec_number(profile_idc, 10)?; let compatibility = parts.next().ok_or(Error::InvalidCodec)?; - let profile_compatibility_flags = u32::from_str_radix(compatibility, 16)?.reverse_bits().to_be_bytes(); + let profile_compatibility_flags = crate::catalog::codec_number::(compatibility, 16)? + .reverse_bits() + .to_be_bytes(); let level = parts.next().ok_or(Error::InvalidCodec)?; @@ -121,22 +124,20 @@ impl FromStr for H265 { _ => return Err(Error::InvalidCodec), }; - let level_idc = level[1..].parse::()?; + let level_idc = crate::catalog::codec_number(&level[1..], 10)?; - let mut constraint_flags = [0u8; 6]; + let mut constraints: Vec<&str> = parts.collect(); + // Tolerate one empty trailing field (a dangling '.') emitted by older encoders/muxers. + if constraints.last() == Some(&"") { + constraints.pop(); + } + if constraints.len() > 6 { + return Err(Error::InvalidCodec); + } - let parts = parts.enumerate(); - for (i, constraint) in parts { - // Tolerate an empty trailing field (a dangling '.') emitted by older - // encoders/muxers so we still parse their streams once this is fixed. - if constraint.is_empty() { - continue; - } - if i >= 6 { - return Err(Error::InvalidCodec); - } - - constraint_flags[i] = u8::from_str_radix(constraint, 16)?; + let mut constraint_flags = [0u8; 6]; + for (flags, constraint) in constraint_flags.iter_mut().zip(constraints) { + *flags = crate::catalog::codec_number(constraint, 16)?; } Ok(Self { diff --git a/rs/hang/src/catalog/video/mod.rs b/rs/hang/src/catalog/video/mod.rs index 758a8d2bff7..0b55916114d 100644 --- a/rs/hang/src/catalog/video/mod.rs +++ b/rs/hang/src/catalog/video/mod.rs @@ -44,6 +44,9 @@ pub struct Video { /// A map of track name to rendition configuration. /// This is not an array in order for it to work with JSON Merge Patch. /// We use a BTreeMap so keys are sorted alphabetically for *some* deterministic behavior. + /// + /// A malformed rendition is skipped when decoding rather than refusing the catalog. + #[serde(deserialize_with = "crate::catalog::deserialize_renditions")] pub renditions: BTreeMap, /// Render the video at this size in pixels. @@ -227,7 +230,7 @@ pub struct VideoConfig { #[serde_as(as = "Option")] pub description: Option, - /// The largest encoded width/height the track carries, fixed for its name. + /// The largest encoded width/height the track carries, fixed for its name, never zero. /// /// The picture resizes in band at a keyframe below these ceilings, unless the /// `description` pins it. Absent means unknown; a publisher may fill it once. @@ -236,17 +239,12 @@ pub struct VideoConfig { pub coded_height: Option, /// The aspect ratio the whole picture is displayed at, as WebCodecs' - /// `VideoDecoderConfig.displayAspectWidth` / `displayAspectHeight`. + /// `VideoDecoderConfig.displayAspectWidth` / `displayAspectHeight`, never zero. /// /// Absent means the decoded picture's own shape. A publisher with non-square /// samples sets the picture's aspect here, never the sample aspect. - /// - /// The `displayRatio*` aliases decode catalogs from publishers predating the - /// rename to `displayAspect*`; the current name is what we emit. - #[serde(alias = "displayRatioWidth")] pub display_aspect_width: Option, /// The height counterpart of `display_aspect_width`. - #[serde(alias = "displayRatioHeight")] pub display_aspect_height: Option, /// The colour the decoded pixels carry, so a renderer need not guess or reparse the bitstream. @@ -274,8 +272,9 @@ pub struct VideoConfig { #[serde(default, skip_serializing_if = "std::ops::Not::not")] pub interlaced: bool, - /// The maximum bitrate of the video track, if known. + /// The maximum bitrate of the video track, if known, at most 2^53 - 1. #[serde(default)] + #[serde_as(as = "Option")] pub bitrate: Option, /// Whether this rendition may be selected. When false, no frames are coming and a consumer @@ -396,6 +395,25 @@ impl VideoConfig { } } +impl crate::catalog::Rendition for VideoConfig { + fn check(&self) -> crate::Result<()> { + for (field, value) in [ + ("codedWidth", self.coded_width), + ("codedHeight", self.coded_height), + ("displayAspectWidth", self.display_aspect_width), + ("displayAspectHeight", self.display_aspect_height), + ] { + if value == Some(0) { + return Err(crate::Error::Zero(field)); + } + } + if let Some(projection) = &self.projection { + projection.check()?; + } + Ok(()) + } +} + fn is_zero(value: &i32) -> bool { *value == 0 } @@ -512,20 +530,6 @@ mod test { assert!(encoded.get("displayRatioHeight").is_none()); } - #[test] - fn decodes_legacy_display_ratio_keys() { - // A catalog serialized by a pre-0.20 publisher used displayRatio*; the - // alias keeps the aspect ratio from being silently dropped. - let json = serde_json::json!({ - "codec": "avc1.640028", - "displayRatioWidth": 16, - "displayRatioHeight": 9, - }); - let config: VideoConfig = serde_json::from_value(json).expect("failed to decode legacy keys"); - assert_eq!(config.display_aspect_width, Some(16)); - assert_eq!(config.display_aspect_height, Some(9)); - } - #[test] fn enabled_is_written_only_when_false() { let mut config = VideoConfig::new(VideoCodec::VP8); diff --git a/rs/hang/src/catalog/video/vp9.rs b/rs/hang/src/catalog/video/vp9.rs index ec255dd412b..e4321f38aba 100644 --- a/rs/hang/src/catalog/video/vp9.rs +++ b/rs/hang/src/catalog/video/vp9.rs @@ -59,12 +59,16 @@ impl std::str::FromStr for VP9 { type Err = Error; fn from_str(s: &str) -> Result { + // Every field is two decimal digits. let parts = s .strip_prefix("vp09.") .ok_or(Error::InvalidCodec)? .split('.') - .map(u8::from_str) - .collect::, _>>()?; + .map(|field| match field.len() { + 2 => crate::catalog::codec_number(field, 10), + _ => Err(Error::InvalidCodec), + }) + .collect::, _>>()?; if parts.len() < 3 { return Err(Error::InvalidCodec); diff --git a/rs/hang/src/error.rs b/rs/hang/src/error.rs index 199afcddf06..ce4a66b5a2e 100644 --- a/rs/hang/src/error.rs +++ b/rs/hang/src/error.rs @@ -84,6 +84,10 @@ pub enum Error { /// An ambisonic audio rendition's channel count is not a square of at least 4. #[error("ambisonic audio needs a square channel count of at least 4, not {0}")] InvalidAmbisonicChannels(u32), + + /// A catalog field that counts something is zero, such as a picture dimension or sample rate. + #[error("catalog {0} must not be zero")] + Zero(&'static str), } /// A Result type alias for hang operations. diff --git a/rs/hang/src/snapshot.rs b/rs/hang/src/snapshot.rs index 9f9ba99637f..a2fed15284b 100644 --- a/rs/hang/src/snapshot.rs +++ b/rs/hang/src/snapshot.rs @@ -10,7 +10,7 @@ pub(crate) struct Number; impl SerializeAs for Number { fn serialize_as(value: &u64, serializer: S) -> Result { if *value > crate::catalog::MAX_SAFE_INTEGER { - return Err(serde::ser::Error::custom("snapshot integer exceeds JSON safe range")); + return Err(serde::ser::Error::custom("integer exceeds the JSON safe range")); } value.serialize(serializer) } @@ -19,7 +19,7 @@ impl<'de> DeserializeAs<'de, u64> for Number { fn deserialize_as>(deserializer: D) -> Result { let value = u64::deserialize(deserializer)?; if value > crate::catalog::MAX_SAFE_INTEGER { - return Err(serde::de::Error::custom("snapshot integer exceeds JSON safe range")); + return Err(serde::de::Error::custom("integer exceeds the JSON safe range")); } Ok(value) } diff --git a/rs/moq-mux/src/catalog/producer.rs b/rs/moq-mux/src/catalog/producer.rs index 5df43ad42b5..f7cbb57bfb4 100644 --- a/rs/moq-mux/src/catalog/producer.rs +++ b/rs/moq-mux/src/catalog/producer.rs @@ -1252,19 +1252,17 @@ fn video_sap_type(codec: &hang::catalog::VideoCodec) -> Option { } } -/// The MSF packaging that announces `container`, or `None` to leave the rendition out of the catalog. +/// The MSF packaging that announces `container`. /// /// Exhaustive on purpose: a catch-all is what announced LOC as legacy, and it would do the same to the /// next container added. hang says an unrecognized one must be ignored, so it keeps its wire kind (no -/// MSF consumer claims one it does not know) and is dropped when it does not even name one. -fn packaging_of(container: &hang::catalog::Container) -> Option { +/// MSF consumer claims one it does not know). +fn packaging_of(container: &hang::catalog::Container) -> moq_msf::Packaging { match container { - hang::catalog::Container::Cmaf { .. } => Some(moq_msf::Packaging::Cmaf), - hang::catalog::Container::Loc => Some(moq_msf::Packaging::Loc), - hang::catalog::Container::Legacy => Some(moq_msf::Packaging::Legacy), - hang::catalog::Container::Unknown(unknown) => { - unknown.kind().map(|kind| moq_msf::Packaging::Unknown(kind.to_string())) - } + hang::catalog::Container::Cmaf { .. } => moq_msf::Packaging::Cmaf, + hang::catalog::Container::Loc => moq_msf::Packaging::Loc, + hang::catalog::Container::Legacy => moq_msf::Packaging::Legacy, + hang::catalog::Container::Unknown(unknown) => moq_msf::Packaging::Unknown(unknown.kind().to_string()), } } @@ -1312,9 +1310,7 @@ fn to_msf_media(catalog: &hang::Catalog, base: &moq_net::Path) -> let has_multiple_video = catalog.video.renditions.len() > 1; for (name, config) in &catalog.video.renditions { - let Some(packaging) = packaging_of(&config.container) else { - continue; - }; + let packaging = packaging_of(&config.container); let init_data = match &config.container { hang::catalog::Container::Cmaf { init, .. } => Some(base64::engine::general_purpose::STANDARD.encode(init)), @@ -1349,9 +1345,7 @@ fn to_msf_media(catalog: &hang::Catalog, base: &moq_net::Path) -> let has_multiple_audio = catalog.audio.renditions.len() > 1; for (name, config) in &catalog.audio.renditions { - let Some(packaging) = packaging_of(&config.container) else { - continue; - }; + let packaging = packaging_of(&config.container); let init_data = match &config.container { hang::catalog::Container::Cmaf { init, .. } => Some(base64::engine::general_purpose::STANDARD.encode(init)), @@ -1383,9 +1377,7 @@ fn to_msf_media(catalog: &hang::Catalog, base: &moq_net::Path) -> } for (name, config) in &catalog.text.renditions { - let Some(packaging) = packaging_of(&config.container) else { - continue; - }; + let packaging = packaging_of(&config.container); let Some((wire, namespace)) = reference(name, config) else { continue; }; diff --git a/rs/moq-mux/src/container/flv/export.rs b/rs/moq-mux/src/container/flv/export.rs index ac707f3eca7..b6cfa676ea0 100644 --- a/rs/moq-mux/src/container/flv/export.rs +++ b/rs/moq-mux/src/container/flv/export.rs @@ -967,7 +967,7 @@ fn ensure_legacy(container: &Container, kind: &str, name: &str) -> anyhow::Resul Container::Cmaf { .. } => anyhow::bail!("FLV export does not support CMAF {kind} track '{name}'"), Container::Unknown(unknown) => anyhow::bail!( "FLV export does not support container '{}' on {kind} track '{name}'", - unknown.kind().unwrap_or("") + unknown.kind() ), } } diff --git a/rs/moq-mux/src/container/ts/export.rs b/rs/moq-mux/src/container/ts/export.rs index 7d7360e73d7..26db1a1169b 100644 --- a/rs/moq-mux/src/container/ts/export.rs +++ b/rs/moq-mux/src/container/ts/export.rs @@ -4485,7 +4485,7 @@ fn ensure_raw(container: &Container, kind: &str, name: &str) -> anyhow::Result<( Container::Cmaf { .. } => anyhow::bail!("TS export does not support CMAF {kind} track '{name}'"), Container::Unknown(unknown) => anyhow::bail!( "TS export does not support container '{}' on {kind} track '{name}'", - unknown.kind().unwrap_or("") + unknown.kind() ), } } diff --git a/rs/moq-mux/src/error.rs b/rs/moq-mux/src/error.rs index aeaba4c0537..6beab44f339 100644 --- a/rs/moq-mux/src/error.rs +++ b/rs/moq-mux/src/error.rs @@ -323,7 +323,7 @@ pub enum Error { impl Error { /// The error for a rendition whose container this build does not recognize. pub(crate) fn unsupported_container(container: &hang::catalog::UnknownContainer) -> Self { - Self::UnsupportedContainer(container.kind().unwrap_or("").to_string()) + Self::UnsupportedContainer(container.kind().to_string()) } /// The reason a track this error aborts gives its subscribers. Only a transport error has a From c1f722f5aae018732e6d77081326fca98922849c Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 01:06:04 -0700 Subject: [PATCH 3/8] docs(quest): leave the backlog skip measurement as the remaining work Co-Authored-By: Claude Opus 5.5 --- quest/m1/cut-audit/README.md | 2 +- quest/m1/cut-audit/catalog-parity.md | 60 ++++++++++++---------------- 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/quest/m1/cut-audit/README.md b/quest/m1/cut-audit/README.md index c50273fb477..c8f4bf22e9d 100644 --- a/quest/m1/cut-audit/README.md +++ b/quest/m1/cut-audit/README.md @@ -62,7 +62,7 @@ leaving JS-only redesigns of `js/net` to [rs2ts](/quest/m2/rs2ts/README.md). - [The export jitter buffer admits only frames due within its window](/quest/m1/cut-audit/jitter-admission.md) - a fast track is backpressured, not buffered without bound - [Peer-driven receive loops yield on a per-message budget](/quest/m1/cut-audit/peer-loop-budget.md) - small-message floods cannot monopolize a session driver - [Removing a stale front is O(1)](/quest/m1/cut-audit/weak-cache-remove.md) - a restart wave is linear under the origin lock -- [Rust and JS accept the same catalogs](/quest/m1/cut-audit/catalog-parity.md) - one strictness, per rendition, with a shared fixture corpus +- [Rust and JS skip a backlog by the same measure](/quest/m1/cut-audit/catalog-parity.md) - a backlog join starts at the same group in every player - [Every relay runtime honors or refuses each listen setting](/quest/m1/cut-audit/uring-listen-config.md) - io_uring stops ignoring preferred addresses - [Lite's version gates, refusals, and draft text agree](/quest/m1/cut-audit/lite-wire-nits.md) - small wire and draft mismatches fixed diff --git a/quest/m1/cut-audit/catalog-parity.md b/quest/m1/cut-audit/catalog-parity.md index 6657975057b..25e876e7a81 100644 --- a/quest/m1/cut-audit/catalog-parity.md +++ b/quest/m1/cut-audit/catalog-parity.md @@ -1,41 +1,31 @@ -# [M] Rust and JS accept the same catalogs +# [S] Rust and JS skip a backlog by the same measure ## Goal -A catalog that one language accepts, the other accepts, and a malformed -known-codec rendition is refused per rendition in both, so a browser never -plays what moq-cli, moqsrc, and HLS refuse, or the reverse. +A player joining a backlog starts at the same group in moq-cli, moqsrc, and +the browser. If they start at different groups, align the two container +consumers' skip measurements, with a test in each. ## Plan -Found by the 2026-10-24 pre-cut audit at 151a529670. Reproduced with probes -in both languages, inherited. - -| Input | JS | Rust | -|---|---|---| -| `codec:"avc1.6400"` | accepts | refuses | -| `codedWidth:5000000000` | accepts | refuses (u32) | -| legacy `video:[{track,config}]` | accepts | refuses | -| `container:{}` | refuses | accepts as Unknown | - -`sampleRate:0` and `numberOfChannels:0` pass both and fail later in -`Timescale::new`. Rust: `rs/hang/src/catalog/video/codec.rs:62`, -`video/mod.rs:192`, `audio/mod.rs:136`, `container.rs:88`. JS: -`js/hang/src/catalog/video.ts:129,146,229`, `audio.ts:110`, -`container.ts:15`. - -Decided 2026-10-25 (maintainer): strict and per rendition. Both languages -validate codec strings and dimension ranges the same way, refuse zero rates -and channel counts, and skip a malformed rendition while keeping the rest of -the catalog. Strict means JS drops the legacy `video:[{track,config}]` array -form, as Rust already refuses it. Add a shared fixture corpus both test -suites load, so a future divergence fails CI. - -Also check the container consumer's skip measurement: Rust measures newest -content minus the next group's start (`rs/moq-mux/src/container/consumer.rs:576`), -JS from the oldest unread frame (`js/hang/src/container/consumer.ts:401`). -They may diverge on a backlog join (unverified); align them if a test shows -it. - -Public API: stricter catalog acceptance in one or both languages. Wire: a -stricter catalog contract, stated in `drafts/draft-lcurley-moq-hang.md`. +Found by the 2026-10-24 pre-cut audit at 151a529670. The catalog half of +this quest (Rust and JS accept the same catalogs) landed separately. + +Rust measures newest content minus the next group's start +(`rs/moq-mux/src/container/consumer.rs`, the `should_skip` check in the +blocking-group path). JS measures from the oldest unread frame +(`js/hang/src/container/consumer.ts`, `#checkMaxDelay`). The Rust comment +argues for its measure: a group's own first frame is no bound, since a group +longer than the budget would be cut short whenever it blocks behind a newer +one, as a join's backlog does. + +They diverge, reproduced by a throwaway probe in each consumer: five +finished one-second groups of ten frames plus a one-frame sixth group, all +landing before the first read, with a 1500 ms budget. JS starts at the 4.0 s +group, while Rust starts at 0 and plays the whole backlog, whether the sixth +group is open or finished. Rust's skip only runs while the current group +blocks, so a fully buffered backlog never triggers it. + +Decide which start is right (likely JS's, which keeps the join within the +budget), align the other consumer, and keep the scenario as a paired test in +both. From 08ebe250e118c0d40052b09579006330c0c48a4d Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 01:38:19 -0700 Subject: [PATCH 4/8] fix(hang): refresh API reports and drop the unreachable zero-channel export case Co-Authored-By: Claude Opus 5.5 --- js/hang/api/catalog.api.md | 2 -- js/publish/api/element.api.md | 2 +- rs/moq-mux/src/container/ts/export_test.rs | 4 ++-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/js/hang/api/catalog.api.md b/js/hang/api/catalog.api.md index a480d9b1c98..5c43b8d3b65 100644 --- a/js/hang/api/catalog.api.md +++ b/js/hang/api/catalog.api.md @@ -862,8 +862,6 @@ export function compressionSupported(compression: Compression): compression is " export function containerSupported(container: Container): boolean; -export const countSchema: $ZodBranded, "u53", "out">; - export function detectFormat(name: string): Format | undefined; export function encode(root: Root): Root; diff --git a/js/publish/api/element.api.md b/js/publish/api/element.api.md index cb2cb264eda..54490b28255 100644 --- a/js/publish/api/element.api.md +++ b/js/publish/api/element.api.md @@ -17,7 +17,7 @@ export default class extends HTMLElement { constructor(); get announce(): AnnounceMode | undefined; set announce(value: AnnounceMode); - attributeChangedCallback(name: "source" | "url" | "name" | "announce" | "backend" | "versions" | "muted" | "invisible" | "preview", oldValue: string | null, newValue: string | null): void; + attributeChangedCallback(name: "source" | "url" | "announce" | "name" | "backend" | "versions" | "muted" | "invisible" | "preview", oldValue: string | null, newValue: string | null): void; audio: Audio.Encoder; get backend(): Preview.Backend; set backend(value: Preview.Backend); diff --git a/rs/moq-mux/src/container/ts/export_test.rs b/rs/moq-mux/src/container/ts/export_test.rs index 63a4e9c03e6..4fd78bcf2ac 100644 --- a/rs/moq-mux/src/container/ts/export_test.rs +++ b/rs/moq-mux/src/container/ts/export_test.rs @@ -5308,8 +5308,8 @@ async fn opus_export_refuses_a_head_it_cannot_label() { let family_255 = opus_mapping(255, 2, 0, &[0, 1]); let wide = opus_mapping(255, 9, 0, &[0, 1, 2, 3, 4, 5, 6, 7, 8]); - let refused: [(u32, Option, &str); 9] = [ - (0, None, "no OpusHead"), + // A zero channel count never reaches the exporter: the catalog refuses it. + let refused: [(u32, Option, &str); 8] = [ (6, None, "no OpusHead"), (9, None, "no OpusHead"), (6, Some(opus_head(6, Some(swapped))), "not the Vorbis layout"), From 8be23a26fc15dfea9b8bba5517534e4a0bbf2ee3 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 29 Oct 2026 08:59:40 -0700 Subject: [PATCH 5/8] quest: plan the per-entry skip for text and data catalog sections Co-Authored-By: Claude Opus 5.5 --- quest/m1/cut-audit/README.md | 1 + quest/m1/cut-audit/catalog-section-skip.md | 28 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 quest/m1/cut-audit/catalog-section-skip.md diff --git a/quest/m1/cut-audit/README.md b/quest/m1/cut-audit/README.md index c8f4bf22e9d..9b0a93966f9 100644 --- a/quest/m1/cut-audit/README.md +++ b/quest/m1/cut-audit/README.md @@ -63,6 +63,7 @@ leaving JS-only redesigns of `js/net` to [rs2ts](/quest/m2/rs2ts/README.md). - [Peer-driven receive loops yield on a per-message budget](/quest/m1/cut-audit/peer-loop-budget.md) - small-message floods cannot monopolize a session driver - [Removing a stale front is O(1)](/quest/m1/cut-audit/weak-cache-remove.md) - a restart wave is linear under the origin lock - [Rust and JS skip a backlog by the same measure](/quest/m1/cut-audit/catalog-parity.md) - a backlog join starts at the same group in every player +- [Every catalog section skips a malformed entry](/quest/m1/cut-audit/catalog-section-skip.md) - text and data entries follow the video and audio skip rule, `__proto__` included - [Every relay runtime honors or refuses each listen setting](/quest/m1/cut-audit/uring-listen-config.md) - io_uring stops ignoring preferred addresses - [Lite's version gates, refusals, and draft text agree](/quest/m1/cut-audit/lite-wire-nits.md) - small wire and draft mismatches fixed diff --git a/quest/m1/cut-audit/catalog-section-skip.md b/quest/m1/cut-audit/catalog-section-skip.md new file mode 100644 index 00000000000..9490d33ceb1 --- /dev/null +++ b/quest/m1/cut-audit/catalog-section-skip.md @@ -0,0 +1,28 @@ +# [S] Every catalog section skips a malformed entry + +## Goal + +A malformed text rendition or json/binary data track is skipped with a +warning in both Rust and JS, keeping the rest of the catalog, the way video +and audio renditions already are. A text or data entry whose ID is +`__proto__` is kept by both languages. The shared parity corpus covers each +section. + +## Plan + +Follow-up of [moq-dev/moq#7035](https://github.com/moq-dev/moq/pull/7035), +which applied per-rendition skipping to video and audio only. The maintainer +picked one rule everywhere when settling that PR's decisions. + +Today a malformed text, json, or binary entry refuses the whole catalog +(`a_malformed_text_section_still_fails` and +`a_malformed_data_section_still_fails` in `rs/hang/src/catalog/root.rs`). +In JS, `text.ts`, `json.ts`, and `binary.ts` parse their maps with +`z.record`, which drops a `__proto__` ID that Rust keeps. + +Reuse what video and audio use: `deserialize_renditions` in +`rs/hang/src/catalog/mod.rs` and `renditions()` in +`js/hang/src/catalog/section.ts`. Flip the two Rust tests to expect a skip, +add text and data cases (including `__proto__`) to +`rs/hang/fixtures/catalog-parity.json`, and extend the draft's "Malformed +Renditions" section to name every section. From 6005ce07bef0ddfd9cb508dabf41325086a19d00 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 07:57:19 -0700 Subject: [PATCH 6/8] fix(hang): a misspelled broadcast reference skips its rendition Main's strict path rule (#7037) refused the catalog for a misspelled rendition `broadcast`, while this branch skips each malformed rendition. Both decoders already skip it after the merge; align the draft and pin it with a test on each side. Co-Authored-By: Claude Opus 5.5 --- drafts/draft-lcurley-moq-hang.md | 4 ++-- js/hang/src/catalog/root.test.ts | 5 +++-- rs/hang/src/catalog/root.rs | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/drafts/draft-lcurley-moq-hang.md b/drafts/draft-lcurley-moq-hang.md index 9681fc4c4d4..05165655e14 100644 --- a/drafts/draft-lcurley-moq-hang.md +++ b/drafts/draft-lcurley-moq-hang.md @@ -685,7 +685,7 @@ By default a rendition's track lives in the same broadcast that served the catal The `broadcast` field overrides that, naming a different broadcast that publishes the track. The value is a relative path, resolved against the path of the broadcast that served the catalog. -It is spelled like a path {{moql}}, so a consumer MUST reject a catalog whose reference has a leading, trailing, or doubled `/`, or a `\` before anything but `\` or `/`. +It is spelled like a path {{moql}}, so a reference with a leading, trailing, or doubled `/`, or a `\` before anything but `\` or `/`, makes the rendition malformed ({{malformed}}). It uses relative reference resolution ({{!RFC3986, Section 5.2}}): a non-empty reference replaces the catalog broadcast's last path segment before applying `.` and `..` segments. For example, `./source` in a catalog served by `room/transcode` resolves to `room/source`, while `.` resolves to `room`. An empty reference resolves to the catalog broadcast itself. @@ -1143,7 +1143,7 @@ This document has no IANA actions. ## moq-hang-04 {:numbered="false"} -- A `broadcast` reference and an echo `path` are spelled like a path: one with an empty segment or a lone `\` refuses the catalog instead of collapsing. +- A `broadcast` reference and an echo `path` are spelled like a path instead of collapsing: a reference with an empty segment or a lone `\` makes its rendition malformed ({{malformed}}), and such an echo `path` refuses the catalog. - Removed `catalog.json.z` and the data track `compression` field: compression is a track property the transport carries ({{compression}}), so each compressed track is one name, and the catalog, `stats` and `echo` snapshots, HLS record tracks, and JSON data tracks SHOULD be compressed. - Replaced the root `archive` section and its per-track timelines with an optional, per-rendition `hls` field on video and audio ({{hls}}). Each record is a segment's first `group` and `pts` in milliseconds, with an optional `duration` where zero marks a stop; frame positions, `end`, `keyframe`, `timescale`, `replay`, `replayEpoch`, `store`, and `version` are gone. Each rendition numbers its own segments, and an edge maps a rendition's record `n` to its segment `n`. The record track is named `.hls` and is compressed ({{compression}}). - A reader refuses a JSON frame in which an object repeats a member name. diff --git a/js/hang/src/catalog/root.test.ts b/js/hang/src/catalog/root.test.ts index ccb48366eee..eeb206d2cdd 100644 --- a/js/hang/src/catalog/root.test.ts +++ b/js/hang/src/catalog/root.test.ts @@ -43,10 +43,11 @@ test("rendition broadcast reference is parsed and normalized", () => { // Normalized like Rust path::Relative: redundant `.` segments are dropped. expect(parsed.video.renditions.video?.broadcast).toBe("source" as RelativeBroadcast); - // Spelled like a path, so an empty segment or a lone backslash refuses the catalog. + // Spelled like a path, so an empty segment or a lone backslash makes the rendition malformed. for (const broadcast of ["./source/", "/source", "a//b", "a\\b"]) { const video = { broadcast, codec: "avc1.64001f", container: { kind: "legacy" } }; - expect(RootSchema.safeParse({ video: { renditions: { video } } }).success).toBe(false); + const skipped = RootSchema.parse({ video: { renditions: { video } } }); + expect(skipped.video?.renditions).toEqual({}); } }); diff --git a/rs/hang/src/catalog/root.rs b/rs/hang/src/catalog/root.rs index 87cf154e284..095fc7732f9 100644 --- a/rs/hang/src/catalog/root.rs +++ b/rs/hang/src/catalog/root.rs @@ -855,6 +855,25 @@ mod test { ); } + #[test] + fn rendition_with_misspelled_broadcast_is_skipped() { + // Spelled like a path, so an empty segment or a lone backslash makes the rendition + // malformed. Mirrors the JS `rendition broadcast reference is parsed and normalized`. + for broadcast in ["./source/", "/source", "a//b", r"a\b"] { + let encoded = serde_json::json!({ + "video": {"renditions": {"video": { + "broadcast": broadcast, + "codec": "avc1.64001f", + "container": {"kind": "legacy"} + }}} + }) + .to_string(); + + let parsed = Catalog::<()>::from_str(&encoded).expect("failed to decode"); + assert!(parsed.video.renditions.is_empty(), "{broadcast:?} should be skipped"); + } + } + #[test] fn rendition_with_parent_broadcast_stays_distinct_from_empty() { let encoded = r#"{ From 85679d6ea69b6033ff81181b7cdbc76a495b36ee Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 08:23:18 -0700 Subject: [PATCH 7/8] docs(hang): only defined fields make a rendition malformed Co-Authored-By: Claude Opus 5.5 --- drafts/draft-lcurley-moq-hang.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drafts/draft-lcurley-moq-hang.md b/drafts/draft-lcurley-moq-hang.md index 05165655e14..0efab5970bc 100644 --- a/drafts/draft-lcurley-moq-hang.md +++ b/drafts/draft-lcurley-moq-hang.md @@ -228,7 +228,7 @@ A consumer MAY configure a decoder once per track from the catalog. ## Malformed Renditions {#malformed} A consumer MUST ignore a malformed audio or video rendition and keep the rest of the catalog, while a `renditions` value that is not an object refuses the catalog. -A rendition is malformed when it is not an object or a field it carries has the wrong type or is out of range. +A rendition is malformed when it is not an object or a field this document defines has the wrong type or is out of range. `codedWidth`, `codedHeight`, `displayAspectWidth`, `displayAspectHeight`, `sampleRate`, and `numberOfChannels` are integers from 1 to 2^32 - 1, and `bitrate`, `jitter`, `warmup`, and `delay` are integers from 0 to 2^53 - 1. From 3d8a9f97d789582d2d5bc73a6b695d73f385fa9f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Fri, 30 Oct 2026 08:39:06 -0700 Subject: [PATCH 8/8] fix(hang)!: a malformed rendition refuses the whole catalog Per the maintainer's 2026-10-30 decision, any malformed audio or video rendition refuses the catalog in both Rust and JS, instead of being skipped while the rest is kept. That covers a misspelled `broadcast` reference, a projection `fov` out of range, and every other field the draft defines; unknown extension fields still never make a rendition malformed. The shared corpus now expects every formerly skipped case to be refused, the draft says "refuse", and the follow-up quest shrinks to the `__proto__` ID gap in text and data sections. Co-Authored-By: Claude Opus 5.5 --- drafts/draft-lcurley-moq-hang.md | 9 +- js/hang/src/catalog/audio.ts | 2 +- js/hang/src/catalog/root.test.ts | 5 +- js/hang/src/catalog/section.ts | 17 +- js/hang/src/catalog/video.ts | 2 +- quest/m1/cut-audit/README.md | 2 +- quest/m1/cut-audit/catalog-parity.md | 5 +- quest/m1/cut-audit/catalog-proto-ids.md | 23 ++ quest/m1/cut-audit/catalog-section-skip.md | 28 -- rs/hang/Cargo.toml | 2 +- rs/hang/fixtures/catalog-parity.json | 449 ++++++--------------- rs/hang/src/catalog/audio/mod.rs | 2 +- rs/hang/src/catalog/hex.rs | 12 +- rs/hang/src/catalog/mod.rs | 22 +- rs/hang/src/catalog/root.rs | 13 +- rs/hang/src/catalog/video/mod.rs | 2 +- 16 files changed, 186 insertions(+), 409 deletions(-) create mode 100644 quest/m1/cut-audit/catalog-proto-ids.md delete mode 100644 quest/m1/cut-audit/catalog-section-skip.md diff --git a/drafts/draft-lcurley-moq-hang.md b/drafts/draft-lcurley-moq-hang.md index 0efab5970bc..e1ca9e40476 100644 --- a/drafts/draft-lcurley-moq-hang.md +++ b/drafts/draft-lcurley-moq-hang.md @@ -227,8 +227,9 @@ A track name removed from the catalog MUST NOT return with a different identity. A consumer MAY configure a decoder once per track from the catalog. ## Malformed Renditions {#malformed} -A consumer MUST ignore a malformed audio or video rendition and keep the rest of the catalog, while a `renditions` value that is not an object refuses the catalog. -A rendition is malformed when it is not an object or a field this document defines has the wrong type or is out of range. +A consumer MUST refuse a catalog with a malformed audio or video rendition, or with a `renditions` value that is not an object, rather than play the rest of it. +A rendition is malformed when it is not an object or a field this document defines has the wrong type or is out of range, unless this document says to treat that field as absent, as it does for `hls` ({{hls}}). +An unknown field never makes a rendition malformed. `codedWidth`, `codedHeight`, `displayAspectWidth`, `displayAspectHeight`, `sampleRate`, and `numberOfChannels` are integers from 1 to 2^32 - 1, and `bitrate`, `jitter`, `warmup`, and `delay` are integers from 0 to 2^53 - 1. @@ -1143,11 +1144,11 @@ This document has no IANA actions. ## moq-hang-04 {:numbered="false"} -- A `broadcast` reference and an echo `path` are spelled like a path instead of collapsing: a reference with an empty segment or a lone `\` makes its rendition malformed ({{malformed}}), and such an echo `path` refuses the catalog. +- A `broadcast` reference and an echo `path` are spelled like a path: one with an empty segment or a lone `\` refuses the catalog instead of collapsing. - Removed `catalog.json.z` and the data track `compression` field: compression is a track property the transport carries ({{compression}}), so each compressed track is one name, and the catalog, `stats` and `echo` snapshots, HLS record tracks, and JSON data tracks SHOULD be compressed. - Replaced the root `archive` section and its per-track timelines with an optional, per-rendition `hls` field on video and audio ({{hls}}). Each record is a segment's first `group` and `pts` in milliseconds, with an optional `duration` where zero marks a stop; frame positions, `end`, `keyframe`, `timescale`, `replay`, `replayEpoch`, `store`, and `version` are gone. Each rendition numbers its own segments, and an edge maps a rendition's record `n` to its segment `n`. The record track is named `.hls` and is compressed ({{compression}}). - A reader refuses a JSON frame in which an object repeats a member name. -- A consumer ignores a malformed audio or video rendition ({{malformed}}) and keeps the rest of the catalog: a known codec string without valid parameters, a zero or out-of-range dimension, sample rate, or channel count, a bitrate or duration above 2^53 - 1, or a container without a string `kind`. +- A malformed audio or video rendition ({{malformed}}) refuses the catalog: a known codec string without valid parameters, a zero or out-of-range dimension, sample rate, or channel count, a bitrate or duration above 2^53 - 1, or a container without a string `kind`. - Added the root `version` ({{catalog-version}}): the oldest draft that reads the catalog, which a consumer refuses when above its own. A `track` other than the entry's ID or a video `warmup` needs 4. Consumers MUST ignore unknown fields. - A data track marks a discontinuity with a group of one object with no bytes, since its empty payload is data. An object with no bytes on an audio or video track, or sharing its group, is malformed. - Removed the Recording section: the store layout is a moq-archive format, documented with that crate, not part of this draft. diff --git a/js/hang/src/catalog/audio.ts b/js/hang/src/catalog/audio.ts index 03acb0acec9..6e65c05e9d3 100644 --- a/js/hang/src/catalog/audio.ts +++ b/js/hang/src/catalog/audio.ts @@ -120,7 +120,7 @@ function isAmbisonic(channels: number): boolean { /** Schema for the catalog audio section: a map of track name to rendition config. */ export const AudioSchema = z.object({ - // A map of track name to rendition configuration, skipping a malformed rendition. + // A map of track name to rendition configuration; a malformed rendition refuses the catalog. // This is not an array so it will work with JSON Merge Patch. renditions: renditions(AudioConfigSchema), }); diff --git a/js/hang/src/catalog/root.test.ts b/js/hang/src/catalog/root.test.ts index eeb206d2cdd..ccb48366eee 100644 --- a/js/hang/src/catalog/root.test.ts +++ b/js/hang/src/catalog/root.test.ts @@ -43,11 +43,10 @@ test("rendition broadcast reference is parsed and normalized", () => { // Normalized like Rust path::Relative: redundant `.` segments are dropped. expect(parsed.video.renditions.video?.broadcast).toBe("source" as RelativeBroadcast); - // Spelled like a path, so an empty segment or a lone backslash makes the rendition malformed. + // Spelled like a path, so an empty segment or a lone backslash refuses the catalog. for (const broadcast of ["./source/", "/source", "a//b", "a\\b"]) { const video = { broadcast, codec: "avc1.64001f", container: { kind: "legacy" } }; - const skipped = RootSchema.parse({ video: { renditions: { video } } }); - expect(skipped.video?.renditions).toEqual({}); + expect(RootSchema.safeParse({ video: { renditions: { video } } }).success).toBe(false); } }); diff --git a/js/hang/src/catalog/section.ts b/js/hang/src/catalog/section.ts index a4078d1193d..90cca8003d1 100644 --- a/js/hang/src/catalog/section.ts +++ b/js/hang/src/catalog/section.ts @@ -35,11 +35,11 @@ export function section(schema: T, map: string) { } /** - * A media section's renditions, skipping each malformed one instead of refusing the catalog. + * A media section's renditions, refusing the catalog if any one is malformed. * - * A rendition this build cannot read can't be played anyway, so dropping it keeps its siblings - * playable, the same as a rendition with an unknown container. The map itself must be an object, - * so a section that isn't one is still refused. Mirrors the Rust `deserialize_renditions`. + * Each rendition must parse with `schema`; the issue names the rendition. An unknown container + * or extension field is not malformed, so it never refuses the catalog. Mirrors the Rust + * `deserialize_renditions`. * * @param schema - one rendition's schema. */ @@ -49,12 +49,17 @@ export function renditions(schema: T) { z.custom>( (value) => typeof value === "object" && value !== null && !Array.isArray(value), ), - z.transform((raw) => { + z.transform((raw, ctx) => { const kept: [string, z.infer][] = []; for (const [id, value] of Object.entries(raw)) { const result = schema.safeParse(value); if (result.success) kept.push([id, result.data]); - else console.warn(`skipping malformed rendition ${id}: ${result.error.message}`); + else + ctx.issues.push({ + code: "custom", + message: `malformed rendition ${id}: ${result.error.message}`, + input: value, + }); } // fromEntries defines each key as its own property, so `__proto__` stays an ID. return Object.fromEntries(kept) as Record>; diff --git a/js/hang/src/catalog/video.ts b/js/hang/src/catalog/video.ts index 631aad38ea6..748bc2cfe98 100644 --- a/js/hang/src/catalog/video.ts +++ b/js/hang/src/catalog/video.ts @@ -235,7 +235,7 @@ export const VideoConfigSchema = z.object({ * Renditions mirror WebCodecs VideoDecoderConfig (https://w3c.github.io/webcodecs/#video-decoder-config). */ export const VideoSchema = z.object({ - // A map of track name to rendition configuration, skipping a malformed rendition. + // A map of track name to rendition configuration; a malformed rendition refuses the catalog. // This is not an array in order for it to work with JSON Merge Patch. renditions: renditions(VideoConfigSchema), diff --git a/quest/m1/cut-audit/README.md b/quest/m1/cut-audit/README.md index c642acffd3f..96d43df46c7 100644 --- a/quest/m1/cut-audit/README.md +++ b/quest/m1/cut-audit/README.md @@ -60,7 +60,7 @@ leaving JS-only redesigns of `js/net` to [rs2ts](/quest/m2/rs2ts/README.md). - [The export clock keeps only the rules admission still needs](/quest/m1/cut-audit/jitter-admission.md) - the clock rules the time and byte admission bound made redundant are measured and removed - [Stream-accept loops yield on a per-poll budget](/quest/m1/cut-audit/accept-budget.md) - a peer opening many streams cannot monopolize a session driver - [Rust and JS skip a backlog by the same measure](/quest/m1/cut-audit/catalog-parity.md) - a backlog join starts at the same group in every player -- [Every catalog section skips a malformed entry](/quest/m1/cut-audit/catalog-section-skip.md) - text and data entries follow the video and audio skip rule, `__proto__` included +- [Text and data sections keep a prototype-named ID](/quest/m1/cut-audit/catalog-proto-ids.md) - text and data entries keep the ID JS's `z.record` drops - [Every relay runtime honors or refuses each listen setting](/quest/m1/cut-audit/uring-listen-config.md) - io_uring stops ignoring preferred addresses ## Related diff --git a/quest/m1/cut-audit/catalog-parity.md b/quest/m1/cut-audit/catalog-parity.md index 25e876e7a81..d78e3a4ea54 100644 --- a/quest/m1/cut-audit/catalog-parity.md +++ b/quest/m1/cut-audit/catalog-parity.md @@ -9,7 +9,10 @@ consumers' skip measurements, with a test in each. ## Plan Found by the 2026-10-24 pre-cut audit at 151a529670. The catalog half of -this quest (Rust and JS accept the same catalogs) landed separately. +this quest (Rust and JS accept the same catalogs) landed separately in +[moq-dev/moq#7035](https://github.com/moq-dev/moq/pull/7035): any malformed +rendition refuses the whole catalog in both languages (maintainer, +2026-10-30). Rust measures newest content minus the next group's start (`rs/moq-mux/src/container/consumer.rs`, the `should_skip` check in the diff --git a/quest/m1/cut-audit/catalog-proto-ids.md b/quest/m1/cut-audit/catalog-proto-ids.md new file mode 100644 index 00000000000..231966596ba --- /dev/null +++ b/quest/m1/cut-audit/catalog-proto-ids.md @@ -0,0 +1,23 @@ +# [XS] Text and data sections keep a prototype-named ID + +## Goal + +A text rendition or json/binary data track whose ID is `__proto__` is kept +by both Rust and JS, the way video and audio renditions already are. The +shared parity corpus covers each section. + +## Plan + +Follow-up of [moq-dev/moq#7035](https://github.com/moq-dev/moq/pull/7035), +which fixed it for video and audio only. + +A malformed entry in any section refuses the whole catalog in both +languages (maintainer, 2026-10-30), which text and data sections already do +(`a_malformed_text_section_still_fails` and +`a_malformed_data_section_still_fails` in `rs/hang/src/catalog/root.rs`). +What remains is the ID: `text.ts`, `json.ts`, and `binary.ts` parse their +maps with `z.record`, which drops a `__proto__` ID that Rust keeps. + +Reuse `renditions()` in `js/hang/src/catalog/section.ts`, which video and +audio use, and add text and data cases (including `__proto__`) to +`rs/hang/fixtures/catalog-parity.json`. diff --git a/quest/m1/cut-audit/catalog-section-skip.md b/quest/m1/cut-audit/catalog-section-skip.md deleted file mode 100644 index 9490d33ceb1..00000000000 --- a/quest/m1/cut-audit/catalog-section-skip.md +++ /dev/null @@ -1,28 +0,0 @@ -# [S] Every catalog section skips a malformed entry - -## Goal - -A malformed text rendition or json/binary data track is skipped with a -warning in both Rust and JS, keeping the rest of the catalog, the way video -and audio renditions already are. A text or data entry whose ID is -`__proto__` is kept by both languages. The shared parity corpus covers each -section. - -## Plan - -Follow-up of [moq-dev/moq#7035](https://github.com/moq-dev/moq/pull/7035), -which applied per-rendition skipping to video and audio only. The maintainer -picked one rule everywhere when settling that PR's decisions. - -Today a malformed text, json, or binary entry refuses the whole catalog -(`a_malformed_text_section_still_fails` and -`a_malformed_data_section_still_fails` in `rs/hang/src/catalog/root.rs`). -In JS, `text.ts`, `json.ts`, and `binary.ts` parse their maps with -`z.record`, which drops a `__proto__` ID that Rust keeps. - -Reuse what video and audio use: `deserialize_renditions` in -`rs/hang/src/catalog/mod.rs` and `renditions()` in -`js/hang/src/catalog/section.ts`. Flip the two Rust tests to expect a skip, -add text and data cases (including `__proto__`) to -`rs/hang/fixtures/catalog-parity.json`, and extend the draft's "Malformed -Renditions" section to name every section. diff --git a/rs/hang/Cargo.toml b/rs/hang/Cargo.toml index 258c8c01a69..3c59a1a0ddb 100644 --- a/rs/hang/Cargo.toml +++ b/rs/hang/Cargo.toml @@ -24,7 +24,6 @@ serde = { workspace = true } serde_json = { workspace = true } serde_with = { workspace = true, features = ["base64"] } thiserror = { workspace = true } -tracing = { workspace = true } url = { workspace = true, features = ["serde"] } [dependencies.derive_more] @@ -36,6 +35,7 @@ anyhow = { workspace = true } moq-mux = { path = "../moq-mux" } moq-tokio = { path = "../moq-tokio", default-features = false, features = ["quic", "aws-lc-rs", "websocket"] } tokio = { workspace = true, features = ["macros", "fs"] } +tracing = { workspace = true } url = { workspace = true } [lints] diff --git a/rs/hang/fixtures/catalog-parity.json b/rs/hang/fixtures/catalog-parity.json index 702179474a0..aba0e90a48f 100644 --- a/rs/hang/fixtures/catalog-parity.json +++ b/rs/hang/fixtures/catalog-parity.json @@ -51,9 +51,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'avc1.64001g'", @@ -69,9 +67,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'avc1.64001f.00'", @@ -87,9 +83,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'avc1.'", @@ -105,9 +99,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'avc1'", @@ -275,9 +267,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.1.6.X93'", @@ -293,9 +283,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.1.6'", @@ -311,9 +299,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.x.6.L93'", @@ -329,9 +315,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.+1.6.L93'", @@ -347,9 +331,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.1.6.L93..B0'", @@ -365,9 +347,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.1.6.L93.B0.0.0.0.0.0.0'", @@ -383,9 +363,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.1.6.L256'", @@ -401,9 +379,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.1.123456789.L93'", @@ -419,9 +395,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'hvc1.1.6.L93.100'", @@ -437,9 +411,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'vp8'", @@ -512,9 +484,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'vp09.00.10'", @@ -530,9 +500,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'vp09.00.10.08.01'", @@ -548,9 +516,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'vp09.00.10.08.01.09.16.09.01.00'", @@ -566,9 +532,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'vp09.+0.10.08'", @@ -584,9 +548,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'av01.0.04M.08'", @@ -640,9 +602,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'av01.0.4M.08'", @@ -658,9 +618,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'av01.0.04X.08'", @@ -676,9 +634,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'av01.0.04M.08.0.110'", @@ -694,9 +650,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codec 'future'", @@ -823,9 +777,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio codec 'mp4a.40.x'", @@ -845,9 +797,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio codec 'mp4a.40.256'", @@ -867,9 +817,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio codec 'mp4a.40.+2'", @@ -889,9 +837,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio codec 'mp4a.40.2.1'", @@ -911,9 +857,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio codec 'mp4a.67'", @@ -1177,9 +1121,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedWidth 5000000000", @@ -1196,9 +1138,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedWidth 0", @@ -1215,9 +1155,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedWidth -1", @@ -1234,9 +1172,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedWidth 1.5", @@ -1253,9 +1189,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedWidth '1280'", @@ -1272,9 +1206,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedHeight 1", @@ -1331,9 +1263,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedHeight 5000000000", @@ -1350,9 +1280,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedHeight 0", @@ -1369,9 +1297,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedHeight -1", @@ -1388,9 +1314,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedHeight 1.5", @@ -1407,9 +1331,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video codedHeight '1280'", @@ -1426,9 +1348,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectWidth 1", @@ -1485,9 +1405,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectWidth 5000000000", @@ -1504,9 +1422,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectWidth 0", @@ -1523,9 +1439,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectWidth -1", @@ -1542,9 +1456,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectWidth 1.5", @@ -1561,9 +1473,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectWidth '1280'", @@ -1580,9 +1490,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectHeight 1", @@ -1639,9 +1547,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectHeight 5000000000", @@ -1658,9 +1564,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectHeight 0", @@ -1677,9 +1581,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectHeight -1", @@ -1696,9 +1598,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectHeight 1.5", @@ -1715,9 +1615,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video displayAspectHeight '1280'", @@ -1734,9 +1632,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio sampleRate 1", @@ -1802,9 +1698,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio sampleRate 0", @@ -1824,9 +1718,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio sampleRate -1", @@ -1846,9 +1738,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio sampleRate 1.5", @@ -1868,9 +1758,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio numberOfChannels 1", @@ -1936,9 +1824,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio numberOfChannels 0", @@ -1958,9 +1844,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio numberOfChannels -1", @@ -1980,9 +1864,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio numberOfChannels 1.5", @@ -2002,9 +1884,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video bitrate 0", @@ -2109,9 +1989,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio bitrate 9007199254740992", @@ -2132,9 +2010,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video bitrate -1", @@ -2151,9 +2027,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio bitrate -1", @@ -2174,9 +2048,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video bitrate 1.5", @@ -2193,9 +2065,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio bitrate 1.5", @@ -2216,9 +2086,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video jitter 0", @@ -2323,9 +2191,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio jitter 9007199254740992", @@ -2346,9 +2212,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video jitter -1", @@ -2365,9 +2229,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio jitter -1", @@ -2388,9 +2250,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video jitter 1.5", @@ -2407,9 +2267,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio jitter 1.5", @@ -2430,9 +2288,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video warmup 0", @@ -2537,9 +2393,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio warmup 9007199254740992", @@ -2560,9 +2414,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video warmup -1", @@ -2579,9 +2431,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio warmup -1", @@ -2602,9 +2452,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video warmup 1.5", @@ -2621,9 +2469,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio warmup 1.5", @@ -2644,9 +2490,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video delay 0", @@ -2751,9 +2595,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio delay 9007199254740992", @@ -2774,9 +2616,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video delay -1", @@ -2793,9 +2633,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio delay -1", @@ -2816,9 +2654,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video delay 1.5", @@ -2835,9 +2671,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio delay 1.5", @@ -2858,9 +2692,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video reorder 0", @@ -2917,9 +2749,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video reorder -1", @@ -2936,9 +2766,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video preference -2147483648", @@ -2995,9 +2823,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video preference -2147483649", @@ -3014,9 +2840,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video preference 0.5", @@ -3033,9 +2857,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video container {\"kind\": \"legacy\"}", @@ -3250,9 +3072,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio container {\"kind\": \"cmaf\"}", @@ -3275,9 +3095,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video container {}", @@ -3294,9 +3112,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio container {}", @@ -3317,9 +3133,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video container {\"kind\": 5}", @@ -3338,9 +3152,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio container {\"kind\": 5}", @@ -3363,9 +3175,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video container {\"kind\": null}", @@ -3384,9 +3194,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio container {\"kind\": null}", @@ -3409,9 +3217,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video container \"legacy\"", @@ -3428,9 +3234,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio container \"legacy\"", @@ -3451,9 +3255,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video description odd hex", @@ -3470,9 +3272,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video description base64", @@ -3489,9 +3289,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video description uppercase hex", @@ -3527,9 +3325,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video label not a string", @@ -3546,9 +3342,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video enabled not a boolean", @@ -3565,9 +3359,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video malformed epoch", @@ -3584,9 +3376,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video projection fov out of range", @@ -3606,9 +3396,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "video projection unknown kind", @@ -3673,9 +3461,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "audio ambisonic with 4 channels", @@ -3737,9 +3523,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio rendition not an object", @@ -3755,9 +3539,7 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { "name": "video rendition missing codec", @@ -3771,9 +3553,7 @@ } } }, - "video": [ - "ok" - ] + "refused": true }, { "name": "audio rendition missing sampleRate", @@ -3792,12 +3572,10 @@ } } }, - "audio": [ - "ok" - ] + "refused": true }, { - "name": "every rendition malformed leaves empty sections", + "name": "every rendition malformed refuses the catalog", "catalog": { "video": { "renditions": { @@ -3815,7 +3593,8 @@ } } } - } + }, + "refused": true }, { "name": "rendition IDs are any string", diff --git a/rs/hang/src/catalog/audio/mod.rs b/rs/hang/src/catalog/audio/mod.rs index 9fbc16c2086..684c233fa19 100644 --- a/rs/hang/src/catalog/audio/mod.rs +++ b/rs/hang/src/catalog/audio/mod.rs @@ -35,7 +35,7 @@ pub struct Audio { /// This is not an array so it will work with JSON Merge Patch. /// We use a BTreeMap so keys are sorted alphabetically for *some* deterministic behavior. /// - /// A malformed rendition is skipped when decoding rather than refusing the catalog. + /// A malformed rendition refuses the whole catalog when decoding. #[serde(deserialize_with = "crate::catalog::deserialize_renditions")] pub renditions: BTreeMap, } diff --git a/rs/hang/src/catalog/hex.rs b/rs/hang/src/catalog/hex.rs index 2938fad6bf5..51cc950e197 100644 --- a/rs/hang/src/catalog/hex.rs +++ b/rs/hang/src/catalog/hex.rs @@ -39,14 +39,14 @@ mod test { fn base64_description() { let json = r#"{"video":{"renditions":{"video/0":{"codec":"avc1.42e02a","container":{"kind":"legacy"},"description":"AUIAKv/hABtnQgAq"}}}}"#; - // The malformed rendition is skipped, with a warning naming the encoding it expected. - assert!(Catalog::<()>::from_str(json).unwrap().video.renditions.is_empty()); + let err = Catalog::<()>::from_str(json).unwrap_err().to_string(); + assert!(err.contains("expected hex"), "{err}"); + // Also from an already-parsed Value, which is what a consumer deserializes: moq-json + // reconstructs one from the frames. That carries no line or column, so this message is + // all a consumer gets (moq-json prefixes the field path on its own side). let value: serde_json::Value = serde_json::from_str(json).unwrap(); - let rendition = value["video"]["renditions"]["video/0"].clone(); - let err = serde_json::from_value::(rendition) - .unwrap_err() - .to_string(); + let err = serde_json::from_value::(value).unwrap_err().to_string(); assert!(err.contains("expected hex"), "{err}"); } diff --git a/rs/hang/src/catalog/mod.rs b/rs/hang/src/catalog/mod.rs index 72a44f25d93..8ab1e1570aa 100644 --- a/rs/hang/src/catalog/mod.rs +++ b/rs/hang/src/catalog/mod.rs @@ -87,17 +87,16 @@ where serde_json::from_value(serde_json::Value::Object(object)).map_err(serde::de::Error::custom) } -/// A media rendition config, decoded on its own so a malformed one costs only itself. +/// A media rendition config, checked as it decodes. pub(crate) trait Rendition: serde::de::DeserializeOwned { /// Refuse a field out of the range its type allows. fn check(&self) -> crate::Result<()>; } -/// Decode a media section's renditions, skipping each malformed one instead of refusing the catalog. +/// Decode a media section's renditions, refusing the catalog if any one is malformed. /// -/// A rendition this build cannot read can't be played anyway, so dropping it keeps its siblings -/// playable, the same as a rendition with an unknown container. The map itself must decode, so a -/// section that isn't one is still refused. +/// Each rendition must be an object whose fields are in range; the error names the rendition. +/// An unknown container or extension field is not malformed, so it never refuses the catalog. pub(crate) fn deserialize_renditions<'de, D, T>( deserializer: D, ) -> Result, D::Error> @@ -114,16 +113,13 @@ where Ok(config) }; - Ok(renditions + renditions .into_iter() - .filter_map(|(id, value)| match decode(value) { - Ok(config) => Some((id, config)), - Err(err) => { - tracing::warn!(%id, %err, "skipping malformed rendition"); - None - } + .map(|(id, value)| match decode(value) { + Ok(config) => Ok((id, config)), + Err(err) => Err(serde::de::Error::custom(format!("malformed rendition {id}: {err}"))), }) - .collect()) + .collect() } /// A catalog section: a map of track name to config, published under one well-known root key. diff --git a/rs/hang/src/catalog/root.rs b/rs/hang/src/catalog/root.rs index 095fc7732f9..cb0264ef81d 100644 --- a/rs/hang/src/catalog/root.rs +++ b/rs/hang/src/catalog/root.rs @@ -259,7 +259,7 @@ impl Catalog { /// Refuse a catalog with an ID naming both a video and an audio rendition, or with a /// rendition field out of range, such as a zero sample rate or a projection out of bounds. /// - /// Decoding already skips an out-of-range rendition, so this catches a catalog built by hand. + /// Decoding already refuses an out-of-range rendition, so this catches a catalog built by hand. pub fn check_renditions(&self) -> Result<()> { use crate::catalog::Rendition; @@ -559,7 +559,7 @@ mod test { )); } - /// A publisher building the catalog by hand is caught before it writes a value every reader skips. + /// A publisher building the catalog by hand is caught before it writes a value every reader refuses. #[test] fn fields_out_of_range_are_refused() { use crate::catalog::{AudioLayout, Projection, VideoCodec, VideoConfig}; @@ -856,9 +856,9 @@ mod test { } #[test] - fn rendition_with_misspelled_broadcast_is_skipped() { - // Spelled like a path, so an empty segment or a lone backslash makes the rendition - // malformed. Mirrors the JS `rendition broadcast reference is parsed and normalized`. + fn rendition_with_misspelled_broadcast_is_refused() { + // Spelled like a path, so an empty segment or a lone backslash makes the rendition malformed, + // which refuses the catalog. Mirrors the JS `rendition broadcast reference is parsed and normalized`. for broadcast in ["./source/", "/source", "a//b", r"a\b"] { let encoded = serde_json::json!({ "video": {"renditions": {"video": { @@ -869,8 +869,7 @@ mod test { }) .to_string(); - let parsed = Catalog::<()>::from_str(&encoded).expect("failed to decode"); - assert!(parsed.video.renditions.is_empty(), "{broadcast:?} should be skipped"); + Catalog::<()>::from_str(&encoded).expect_err(&format!("{broadcast:?} should be refused")); } } diff --git a/rs/hang/src/catalog/video/mod.rs b/rs/hang/src/catalog/video/mod.rs index 8a8f4df8251..695c4dd52e9 100644 --- a/rs/hang/src/catalog/video/mod.rs +++ b/rs/hang/src/catalog/video/mod.rs @@ -45,7 +45,7 @@ pub struct Video { /// This is not an array in order for it to work with JSON Merge Patch. /// We use a BTreeMap so keys are sorted alphabetically for *some* deterministic behavior. /// - /// A malformed rendition is skipped when decoding rather than refusing the catalog. + /// A malformed rendition refuses the whole catalog when decoding. #[serde(deserialize_with = "crate::catalog::deserialize_renditions")] pub renditions: BTreeMap,