diff --git a/drafts/draft-lcurley-moq-hang.md b/drafts/draft-lcurley-moq-hang.md index 901dff18db8..e1ca9e40476 100644 --- a/drafts/draft-lcurley-moq-hang.md +++ b/drafts/draft-lcurley-moq-hang.md @@ -226,6 +226,23 @@ 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 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. + +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. @@ -335,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. @@ -429,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. @@ -437,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`. @@ -670,7 +686,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. @@ -867,6 +883,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. @@ -1131,6 +1148,7 @@ This document has no IANA actions. - 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 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/api/catalog.api.md b/js/hang/api/catalog.api.md index 3495a30b7d0..34e78b06887 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][]; } @@ -403,128 +279,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; @@ -557,11 +313,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">>; @@ -629,303 +382,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; @@ -1007,11 +470,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; @@ -1277,303 +738,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; @@ -1655,11 +826,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][]; } diff --git a/js/hang/src/catalog/audio.ts b/js/hang/src/catalog/audio.ts index 8f743f66b5a..6e65c05e9d3 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, @@ -114,23 +119,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; a malformed rendition refuses the catalog. + // 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 b02e125593b..ccb48366eee 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 `.` segments are dropped. expect(parsed.video.renditions.video?.broadcast).toBe("source" as RelativeBroadcast); @@ -77,8 +77,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); @@ -104,7 +104,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); }); @@ -117,7 +117,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(); }); @@ -186,7 +186,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}'); }); @@ -195,7 +195,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..90cca8003d1 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,55 @@ export function section(schema: T, map: string) { ); } +/** + * A media section's renditions, refusing the catalog if any one is malformed. + * + * 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. + */ +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, 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 + 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>; + }), + ); +} + +/** + * 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 520ae5473bc..748bc2cfe98 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), @@ -206,51 +234,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; a malformed rendition refuses the catalog. + // 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/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/quest/m1/cut-audit/README.md b/quest/m1/cut-audit/README.md index abc1d660664..6a7f33247e6 100644 --- a/quest/m1/cut-audit/README.md +++ b/quest/m1/cut-audit/README.md @@ -57,7 +57,8 @@ leaving JS-only redesigns of `js/net` to [rs2ts](/quest/m2/rs2ts-js.md). - [A reserved group survives a route returning](/quest/m1/cut-audit/reserved-route-return.md) - a route flip A to B to A no longer panics a peeked reader - [A description-less AAC rendition means one thing](/quest/m1/cut-audit/aac-description-less.md) - every player and exporter agrees on the frame format - [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 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 +- [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 ## Related diff --git a/quest/m1/cut-audit/catalog-parity.md b/quest/m1/cut-audit/catalog-parity.md index 6657975057b..d78e3a4ea54 100644 --- a/quest/m1/cut-audit/catalog-parity.md +++ b/quest/m1/cut-audit/catalog-parity.md @@ -1,41 +1,34 @@ -# [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 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 +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. 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/rs/hang/fixtures/catalog-parity.json b/rs/hang/fixtures/catalog-parity.json new file mode 100644 index 00000000000..aba0e90a48f --- /dev/null +++ b/rs/hang/fixtures/catalog-parity.json @@ -0,0 +1,3760 @@ +[ + { + "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" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'avc1.64001g'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001g" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'avc1.64001f.00'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f.00" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'avc1.'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1." + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.1.6.X93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.X93" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.1.6'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.x.6.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.x.6.L93" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.+1.6.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.+1.6.L93" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.1.6.L93..B0'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93..B0" + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.1.6.L256'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L256" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.1.123456789.L93'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.123456789.L93" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'hvc1.1.6.L93.100'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "hvc1.1.6.L93.100" + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'vp09.00.10'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.00.10" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'vp09.00.10.08.01'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.00.10.08.01" + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'vp09.+0.10.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "vp09.+0.10.08" + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'av01.0.4M.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.4M.08" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'av01.0.04X.08'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.04X.08" + } + } + } + }, + "refused": true + }, + { + "name": "video codec 'av01.0.04M.08.0.110'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "av01.0.04M.08.0.110" + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "video codedWidth 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 5000000000 + } + } + } + }, + "refused": true + }, + { + "name": "video codedWidth 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 0 + } + } + } + }, + "refused": true + }, + { + "name": "video codedWidth -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video codedWidth 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": 1.5 + } + } + } + }, + "refused": true + }, + { + "name": "video codedWidth '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedWidth": "1280" + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "video codedHeight 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 5000000000 + } + } + } + }, + "refused": true + }, + { + "name": "video codedHeight 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 0 + } + } + } + }, + "refused": true + }, + { + "name": "video codedHeight -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video codedHeight 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": 1.5 + } + } + } + }, + "refused": true + }, + { + "name": "video codedHeight '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "codedHeight": "1280" + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectWidth 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 5000000000 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectWidth 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 0 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectWidth -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectWidth 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": 1.5 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectWidth '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectWidth": "1280" + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectHeight 5000000000", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 5000000000 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectHeight 0", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 0 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectHeight -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectHeight 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": 1.5 + } + } + } + }, + "refused": true + }, + { + "name": "video displayAspectHeight '1280'", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "displayAspectHeight": "1280" + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "audio sampleRate 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 0, + "numberOfChannels": 2 + } + } + } + }, + "refused": true + }, + { + "name": "audio sampleRate -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": -1, + "numberOfChannels": 2 + } + } + } + }, + "refused": true + }, + { + "name": "audio sampleRate 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 1.5, + "numberOfChannels": 2 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "audio numberOfChannels 0", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 0 + } + } + } + }, + "refused": true + }, + { + "name": "audio numberOfChannels -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": -1 + } + } + } + }, + "refused": true + }, + { + "name": "audio numberOfChannels 1.5", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 1.5 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "audio bitrate 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "bitrate": 9007199254740992 + } + } + } + }, + "refused": true + }, + { + "name": "video bitrate -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "bitrate": -1 + } + } + } + }, + "refused": true + }, + { + "name": "audio bitrate -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "bitrate": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video bitrate 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "bitrate": 1.5 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "audio jitter 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "jitter": 9007199254740992 + } + } + } + }, + "refused": true + }, + { + "name": "video jitter -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "jitter": -1 + } + } + } + }, + "refused": true + }, + { + "name": "audio jitter -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "jitter": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video jitter 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "jitter": 1.5 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "audio warmup 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "warmup": 9007199254740992 + } + } + } + }, + "refused": true + }, + { + "name": "video warmup -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "warmup": -1 + } + } + } + }, + "refused": true + }, + { + "name": "audio warmup -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "warmup": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video warmup 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "warmup": 1.5 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "audio delay 9007199254740992", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "delay": 9007199254740992 + } + } + } + }, + "refused": true + }, + { + "name": "video delay -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "delay": -1 + } + } + } + }, + "refused": true + }, + { + "name": "audio delay -1", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "delay": -1 + } + } + } + }, + "refused": true + }, + { + "name": "video delay 1.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "delay": 1.5 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "video reorder -1", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "reorder": -1 + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "video preference -2147483649", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "preference": -2147483649 + } + } + } + }, + "refused": true + }, + { + "name": "video preference 0.5", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "preference": 0.5 + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + } + }, + "refused": true + }, + { + "name": "video container {}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": {} + } + } + } + }, + "refused": true + }, + { + "name": "audio container {}", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": {} + } + } + } + }, + "refused": true + }, + { + "name": "video container {\"kind\": 5}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": 5 + } + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + } + }, + "refused": true + }, + { + "name": "video container {\"kind\": null}", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": { + "kind": null + } + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + } + }, + "refused": true + }, + { + "name": "video container \"legacy\"", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "container": "legacy" + } + } + } + }, + "refused": true + }, + { + "name": "audio container \"legacy\"", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2, + "container": "legacy" + } + } + } + }, + "refused": true + }, + { + "name": "video description odd hex", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "description": "abc" + } + } + } + }, + "refused": true + }, + { + "name": "video description base64", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "description": "AUIAKv/h" + } + } + } + }, + "refused": true + }, + { + "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 + } + } + } + }, + "refused": true + }, + { + "name": "video label not a string", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "label": 5 + } + } + } + }, + "refused": true + }, + { + "name": "video enabled not a boolean", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "enabled": "yes" + } + } + } + }, + "refused": true + }, + { + "name": "video malformed epoch", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "epoch": "not-a-uuid" + } + } + } + }, + "refused": true + }, + { + "name": "video projection fov out of range", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": { + "codec": "avc1.64001f", + "projection": { + "kind": "equirectangular", + "fov": 400 + } + } + } + } + }, + "refused": true + }, + { + "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" + } + } + } + }, + "refused": true + }, + { + "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 + } + } + }, + "refused": true + }, + { + "name": "audio rendition not an object", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": [] + } + } + }, + "refused": true + }, + { + "name": "video rendition missing codec", + "catalog": { + "video": { + "renditions": { + "ok": { + "codec": "avc1.64001f" + }, + "probe": {} + } + } + }, + "refused": true + }, + { + "name": "audio rendition missing sampleRate", + "catalog": { + "audio": { + "renditions": { + "ok": { + "codec": "opus", + "sampleRate": 48000, + "numberOfChannels": 2 + }, + "probe": { + "codec": "opus", + "numberOfChannels": 2 + } + } + } + }, + "refused": true + }, + { + "name": "every rendition malformed refuses the catalog", + "catalog": { + "video": { + "renditions": { + "bad": { + "codec": "avc1.6400" + } + } + }, + "audio": { + "renditions": { + "bad": { + "codec": "opus", + "sampleRate": 0, + "numberOfChannels": 2 + } + } + } + }, + "refused": true + }, + { + "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 fe1e336918b..684c233fa19 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 refuses the whole catalog when decoding. + #[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 @@ -253,6 +257,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/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 72c7812bbe6..8ab1e1570aa 100644 --- a/rs/hang/src/catalog/mod.rs +++ b/rs/hang/src/catalog/mod.rs @@ -63,6 +63,65 @@ 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, 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, refusing the catalog if any one is malformed. +/// +/// 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> +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) + }; + + renditions + .into_iter() + .map(|(id, value)| match decode(value) { + Ok(config) => Ok((id, config)), + Err(err) => Err(serde::de::Error::custom(format!("malformed rendition {id}: {err}"))), + }) + .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 8fd98c304b3..cb0264ef81d 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)] @@ -249,8 +257,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 refuses 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 @@ -260,14 +272,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(()) } @@ -405,6 +413,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() { @@ -512,23 +559,38 @@ mod test { )); } + /// A publisher building the catalog by hand is caught before it writes a value every reader refuses. #[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(); @@ -793,6 +855,24 @@ mod test { ); } + #[test] + 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": { + "broadcast": broadcast, + "codec": "avc1.64001f", + "container": {"kind": "legacy"} + }}} + }) + .to_string(); + + Catalog::<()>::from_str(&encoded).expect_err(&format!("{broadcast:?} should be refused")); + } + } + #[test] fn rendition_with_parent_broadcast_stays_distinct_from_empty() { let encoded = r#"{ @@ -846,7 +926,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 a52a474a005..695c4dd52e9 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 refuses the whole catalog when decoding. + #[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 @@ -413,6 +412,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 } @@ -529,20 +547,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 96439aa5fe1..9164dd30f72 100644 --- a/rs/moq-mux/src/catalog/producer.rs +++ b/rs/moq-mux/src/catalog/producer.rs @@ -1363,19 +1363,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()), } } @@ -1423,9 +1421,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)), @@ -1460,9 +1456,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)), @@ -1494,9 +1488,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 6eb0bd94244..668ce16d331 100644 --- a/rs/moq-mux/src/container/flv/export.rs +++ b/rs/moq-mux/src/container/flv/export.rs @@ -965,7 +965,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 d5ae4b3d752..4c94790fb08 100644 --- a/rs/moq-mux/src/container/ts/export.rs +++ b/rs/moq-mux/src/container/ts/export.rs @@ -4862,7 +4862,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/container/ts/export_test.rs b/rs/moq-mux/src/container/ts/export_test.rs index 72d91533751..d30b77a9183 100644 --- a/rs/moq-mux/src/container/ts/export_test.rs +++ b/rs/moq-mux/src/container/ts/export_test.rs @@ -5549,8 +5549,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"), diff --git a/rs/moq-mux/src/error.rs b/rs/moq-mux/src/error.rs index b8afabbe7c3..e18e1a21ba9 100644 --- a/rs/moq-mux/src/error.rs +++ b/rs/moq-mux/src/error.rs @@ -318,7 +318,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