Skip to main content

display_types/cea861/
misc.rs

1#[cfg(any(feature = "alloc", feature = "std"))]
2use crate::prelude::Vec;
3
4/// Well-known InfoFrame type codes from the InfoFrame Data Block (extended tag `0x20`).
5///
6/// These correspond to the InfoFrame types defined in HDMI and CTA-861.
7pub mod infoframe_type {
8    /// Vendor-Specific InfoFrame (VSI). The associated OUI identifies the vendor.
9    pub const VENDOR_SPECIFIC: u8 = 0x01;
10    /// AVI InfoFrame — active video format, colorimetry, aspect ratio.
11    pub const AVI: u8 = 0x02;
12    /// Source Product Descriptor InfoFrame.
13    pub const SOURCE_PRODUCT_DESCRIPTOR: u8 = 0x03;
14    /// Audio InfoFrame.
15    pub const AUDIO: u8 = 0x04;
16    /// MPEG Source InfoFrame.
17    pub const MPEG_SOURCE: u8 = 0x05;
18    /// NTSC VBI InfoFrame.
19    pub const NTSC_VBI: u8 = 0x06;
20    /// Dynamic Range and Mastering InfoFrame (HDR10 static metadata).
21    pub const DYNAMIC_RANGE_MASTERING: u8 = 0x07;
22}
23
24/// One entry from an InfoFrame Data Block (extended tag `0x20`).
25///
26/// Each descriptor identifies an InfoFrame type that the sink is capable of
27/// receiving. For Vendor-Specific InfoFrames (`type_code == 0x01`) the IEEE OUI
28/// of the vendor is also present.
29#[non_exhaustive]
30#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub struct InfoFrameDescriptor {
33    /// InfoFrame type code (bits 4:0 of the SID byte).
34    ///
35    /// See the constants in [`infoframe_type`] for the well-known values.
36    pub type_code: u8,
37    /// IEEE OUI for Vendor-Specific InfoFrames (`type_code == 0x01`).
38    ///
39    /// Stored as `(byte0 << 16) | (byte1 << 8) | byte2` following the byte
40    /// order used in CTA-861.  `None` for all other types.
41    pub vendor_oui: Option<u32>,
42}
43
44impl InfoFrameDescriptor {
45    /// Constructs an `InfoFrameDescriptor`.
46    pub fn new(type_code: u8, vendor_oui: Option<u32>) -> Self {
47        Self {
48            type_code,
49            vendor_oui,
50        }
51    }
52}
53
54/// A decoded Vendor-Specific Video Data Block (VSVDB, extended tag `0x01`) or
55/// Vendor-Specific Audio Data Block (VSADB, extended tag `0x11`).
56///
57/// Both block types share the same structure: a 3-byte IEEE OUI followed by an
58/// opaque vendor-defined payload (CTA-861 Tables 56–57). The payload is stored
59/// verbatim for consumers that recognise the OUI.
60///
61/// Well-known video OUIs include Dolby Vision (`0x00D046`) and HDR10+ (`0x90848B`).
62#[non_exhaustive]
63#[cfg(any(feature = "alloc", feature = "std"))]
64#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
65#[derive(Debug, Clone, PartialEq, Eq)]
66pub struct VendorSpecificBlock {
67    /// 24-bit IEEE OUI in canonical (MSB-first) form.
68    ///
69    /// Assembled from the three OUI bytes as `(byte2 << 16) | (byte1 << 8) | byte0`,
70    /// where byte0 is the least-significant byte as stored on the wire.
71    pub oui: u32,
72    /// Vendor-defined payload bytes following the OUI.
73    pub payload: Vec<u8>,
74}
75
76#[cfg(any(feature = "alloc", feature = "std"))]
77impl VendorSpecificBlock {
78    /// Constructs a `VendorSpecificBlock`.
79    pub fn new(oui: u32, payload: Vec<u8>) -> Self {
80        Self { oui, payload }
81    }
82}