codec_bitstream/
av1.rs

1use std::mem;
2
3/// Extract sequence header obu from mkv CodecPrivate
4pub fn extract_seq_hdr_from_mkv_codec_private(codec_private: &[u8]) -> &[u8] {
5    &codec_private[4..]
6}
7
8#[derive(Debug, Copy, Clone)]
9pub struct ColorCharacteristics {
10    pub cp: ColourPrimaries,
11    pub mc: MatrixCoefficients,
12    pub tc: TransferCharacteristic,
13}
14
15impl ColorCharacteristics {
16    pub fn or(self, other: Self) -> Self {
17        Self {
18            cp: if matches!(self.cp, ColourPrimaries::Unspecified) {
19                other.cp
20            } else {
21                self.cp
22            },
23            mc: if matches!(self.mc, MatrixCoefficients::Unspecified) {
24                other.mc
25            } else {
26                self.mc
27            },
28            tc: if matches!(self.tc, TransferCharacteristic::Unspecified) {
29                other.tc
30            } else {
31                self.tc
32            },
33        }
34    }
35}
36
37/// defined by the “Color primaries” section of ISO/IEC 23091-4/ITU-T H.273
38#[derive(Debug, Copy, Clone)]
39#[repr(u8)]
40pub enum ColourPrimaries {
41    BT709 = 1,
42    Unspecified = 2,
43    BT601 = 6,
44    // TODO complete colour primaries
45}
46
47impl ColourPrimaries {
48    pub fn from_byte(byte: u8) -> Self {
49        assert!(byte <= ColourPrimaries::BT601 as u8);
50        unsafe { mem::transmute::<u8, _>(byte) }
51    }
52}
53
54/// defined by the “Transfer characteristics” section of ISO/IEC 23091-4/ITU-T H.273
55#[derive(Debug, Copy, Clone)]
56#[repr(u8)]
57pub enum TransferCharacteristic {
58    Reserved = 0,
59    BT709 = 1,
60    Unspecified = 2,
61    Reserved2 = 3,
62    BT601 = 6,
63    // TODO complete transfer characteristic
64}
65
66impl TransferCharacteristic {
67    pub fn from_byte(byte: u8) -> Self {
68        assert!(byte <= TransferCharacteristic::BT601 as u8);
69        unsafe { mem::transmute::<u8, _>(byte) }
70    }
71}
72
73/// defined by the “Matrix coefficients” section of ISO/IEC 23091-4/ITU-T H.273
74#[derive(Debug, Copy, Clone)]
75#[repr(u8)]
76pub enum MatrixCoefficients {
77    Identity = 0,
78    BT709 = 1,
79    Unspecified = 2,
80    Reserved = 3,
81    FCC = 4,
82    BT601 = 6,
83    // TODO complete matrix coefficients
84}
85
86impl MatrixCoefficients {
87    pub fn from_byte(byte: u8) -> Self {
88        assert!(byte <= MatrixCoefficients::BT601 as u8);
89        unsafe { mem::transmute::<u8, _>(byte) }
90    }
91}