Skip to main content

ebml_webm/
ids.rs

1//! `WebM` element IDs used by the v1 demux subset.
2//!
3//! See facade `ADR-0001` / this crate's `adr/0001`. Values are the raw EBML
4//! element ID (marker bits included, per RFC 8794) — see
5//! `docs/standards/registry.toml` (`rfc-8794-ebml`, `webm-container-guidelines`).
6
7#![forbid(unsafe_code)]
8
9/// `EBML` header — skipped whole in v1 demux (no `DocType` validation); the
10/// mux side writes a minimal, spec-valid one (`adr/0003`).
11pub const EBML_HEADER: u32 = 0x1A45_DFA3;
12/// `EBML\EBMLVersion` (mux only — always `1`).
13pub const EBML_VERSION: u32 = 0x4286;
14/// `EBML\EBMLReadVersion` (mux only — always `1`).
15pub const EBML_READ_VERSION: u32 = 0x42F7;
16/// `EBML\EBMLMaxIDLength` (mux only — always `4`, matching [`decode_id`](crate::vint::decode_id)'s limit).
17pub const EBML_MAX_ID_LENGTH: u32 = 0x42F2;
18/// `EBML\EBMLMaxSizeLength` (mux only — always `8`).
19pub const EBML_MAX_SIZE_LENGTH: u32 = 0x42F3;
20/// `EBML\DocType` (mux only — ASCII `"webm"`).
21pub const DOC_TYPE: u32 = 0x4282;
22/// `EBML\DocTypeVersion` (mux only).
23pub const DOC_TYPE_VERSION: u32 = 0x4287;
24/// `EBML\DocTypeReadVersion` (mux only).
25pub const DOC_TYPE_READ_VERSION: u32 = 0x4285;
26/// `Segment` — top-level container; may be indefinite size.
27pub const SEGMENT: u32 = 0x1853_8067;
28/// `Segment\Info`.
29pub const SEGMENT_INFO: u32 = 0x1549_A966;
30/// `Segment\Info\TimecodeScale` (ns per tick; default `1_000_000`).
31pub const TIMECODE_SCALE: u32 = 0x2A_D7B1;
32/// `Segment\Tracks`.
33pub const TRACKS: u32 = 0x1654_AE6B;
34/// `Segment\Tracks\TrackEntry`.
35pub const TRACK_ENTRY: u32 = 0xAE;
36/// `TrackEntry\TrackNumber`.
37pub const TRACK_NUMBER: u32 = 0xD7;
38/// `TrackEntry\TrackType` (1 = video, 2 = audio, …).
39pub const TRACK_TYPE: u32 = 0x83;
40/// `TrackEntry\CodecID` (ASCII, e.g. `"V_VP9"`).
41pub const CODEC_ID: u32 = 0x86;
42/// `TrackEntry\Video`.
43pub const VIDEO: u32 = 0xE0;
44/// `Video\PixelWidth`.
45pub const PIXEL_WIDTH: u32 = 0xB0;
46/// `Video\PixelHeight`.
47pub const PIXEL_HEIGHT: u32 = 0xBA;
48/// `Segment\Cluster` — may be indefinite size.
49pub const CLUSTER: u32 = 0x1F43_B675;
50/// `Cluster\Timecode` (in `TimecodeScale` ticks, relative to `Segment` start).
51pub const TIMECODE: u32 = 0xE7;
52/// `Cluster\SimpleBlock`.
53pub const SIMPLE_BLOCK: u32 = 0xA3;
54/// `TrackEntry\Audio`.
55pub const AUDIO: u32 = 0xE1;
56/// `Audio\SamplingFrequency` (EBML Float; default `8000.0` Hz).
57pub const SAMPLING_FREQUENCY: u32 = 0xB5;
58/// `Audio\Channels` (default `1`).
59pub const CHANNELS: u32 = 0x9F;
60/// `Cluster\BlockGroup`.
61pub const BLOCK_GROUP: u32 = 0xA0;
62/// `BlockGroup\Block` — same wire format as `SimpleBlock`, but the keyframe
63/// flag bit is reserved here; keyframe-ness is instead the *absence* of a
64/// sibling `ReferenceBlock`.
65pub const BLOCK: u32 = 0xA1;
66/// `BlockGroup\BlockDuration` (in `TimecodeScale` ticks).
67pub const BLOCK_DURATION: u32 = 0x9B;
68/// `BlockGroup\ReferenceBlock` — presence (value is unused) marks the block as
69/// not a keyframe.
70pub const REFERENCE_BLOCK: u32 = 0xFB;
71/// `Segment\Cues` — seek index; informational only (this crate does no
72/// seeking itself, per sans-io — see crate-local ADR-0002).
73pub const CUES: u32 = 0x1C53_BB6B;
74/// `Cues\CuePoint`.
75pub const CUE_POINT: u32 = 0xBB;
76/// `CuePoint\CueTime`.
77pub const CUE_TIME: u32 = 0xB3;
78/// `CuePoint\CueTrackPositions`.
79pub const CUE_TRACK_POSITIONS: u32 = 0xB7;
80/// `CueTrackPositions\CueTrack`.
81pub const CUE_TRACK: u32 = 0xF7;
82/// `CueTrackPositions\CueClusterPosition` (byte offset from `Segment`'s data start).
83pub const CUE_CLUSTER_POSITION: u32 = 0xF1;
84/// `Segment\SeekHead` — informational only (see [`CUES`]).
85pub const SEEK_HEAD: u32 = 0x114D_9B74;
86/// `SeekHead\Seek`.
87pub const SEEK: u32 = 0x4DBB;
88/// `Seek\SeekID` (the referenced element's raw ID bytes).
89pub const SEEK_ID: u32 = 0x53AB;
90/// `Seek\SeekPosition` (byte offset from `Segment`'s data start).
91pub const SEEK_POSITION: u32 = 0x53AC;
92
93/// Master elements the walker descends into. Every other element ID
94/// (recognized leaf or not) is treated as opaque and skipped by its own
95/// element size.
96#[must_use]
97pub const fn is_descend_master(id: u32) -> bool {
98    matches!(
99        id,
100        SEGMENT
101            | SEGMENT_INFO
102            | TRACKS
103            | TRACK_ENTRY
104            | VIDEO
105            | AUDIO
106            | CLUSTER
107            | BLOCK_GROUP
108            | CUES
109            | CUE_POINT
110            | CUE_TRACK_POSITIONS
111            | SEEK_HEAD
112            | SEEK
113    )
114}