Skip to main content

wedeo_core/
frame_side_data.rs

1/// Frame side data types, matching FFmpeg's `AVFrameSideDataType` from `libavutil/frame.h`.
2#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3#[repr(u32)]
4pub enum FrameSideDataType {
5    /// The data is the AVPanScan struct defined in libavcodec.
6    Panscan = 0,
7    /// ATSC A53 Part 4 Closed Captions.
8    /// A53 CC bitstream is stored as uint8_t in data.
9    A53Cc = 1,
10    /// Stereoscopic 3d metadata.
11    Stereo3d = 2,
12    /// The data is the AVMatrixEncoding enum.
13    MatrixEncoding = 3,
14    /// Metadata relevant to a downmix procedure.
15    DownmixInfo = 4,
16    /// ReplayGain information.
17    ReplayGain = 5,
18    /// 3x3 transformation matrix describing an affine transformation
19    /// for correct presentation.
20    DisplayMatrix = 6,
21    /// Active Format Description data consisting of a single byte.
22    Afd = 7,
23    /// Motion vectors exported by some codecs.
24    MotionVectors = 8,
25    /// Recommends skipping the specified number of samples.
26    SkipSamples = 9,
27    /// Audio service type.
28    AudioServiceType = 10,
29    /// Mastering display metadata associated with a video frame.
30    MasteringDisplayMetadata = 11,
31    /// The GOP timecode in 25 bit timecode format.
32    GopTimecode = 12,
33    /// Spherical mapping metadata.
34    Spherical = 13,
35    /// Content light level (based on CTA-861.3).
36    ContentLightLevel = 14,
37    /// ICC profile as an opaque octet buffer following ISO 15076-1.
38    IccProfile = 15,
39    /// SMPTE ST 12-1 timecode.
40    S12mTimecode = 16,
41    /// HDR dynamic metadata (SMPTE 2094-40:2016).
42    DynamicHdrPlus = 17,
43    /// Regions Of Interest.
44    RegionsOfInterest = 18,
45    /// Encoding parameters for a video frame.
46    VideoEncParams = 19,
47    /// User data unregistered metadata (H.26[45] UDU SEI message).
48    SeiUnregistered = 20,
49    /// Film grain parameters for a frame.
50    FilmGrainParams = 21,
51    /// Bounding boxes for object detection and classification.
52    DetectionBboxes = 22,
53    /// Dolby Vision RPU raw data, suitable for passing to x265 or other libraries.
54    DoviRpuBuffer = 23,
55    /// Parsed Dolby Vision metadata.
56    DoviMetadata = 24,
57    /// HDR Vivid dynamic metadata (CUVA 005.1-2021).
58    DynamicHdrVivid = 25,
59    /// Ambient viewing environment metadata (H.274).
60    AmbientViewingEnvironment = 26,
61    /// Encoder-specific hinting information about changed/unchanged portions of a frame.
62    VideoHint = 27,
63    /// Raw LCEVC payload data.
64    Lcevc = 28,
65    /// View ID for multi-view video streams (e.g. stereoscopic 3D content).
66    ViewId = 29,
67    /// 3D reference displays information.
68    ThreeDReferenceDisplays = 30,
69    /// Extensible image file format metadata (EXIF).
70    Exif = 31,
71}
72
73/// Side data associated with a frame, matching FFmpeg's `AVFrameSideData`.
74#[derive(Debug, Clone)]
75pub struct FrameSideData {
76    pub data_type: FrameSideDataType,
77    pub data: Vec<u8>,
78}
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83
84    #[test]
85    fn test_side_data_type_discriminants() {
86        // Verify key discriminant values match FFmpeg's enum.
87        assert_eq!(FrameSideDataType::Panscan as u32, 0);
88        assert_eq!(FrameSideDataType::A53Cc as u32, 1);
89        assert_eq!(FrameSideDataType::DisplayMatrix as u32, 6);
90        assert_eq!(FrameSideDataType::MasteringDisplayMetadata as u32, 11);
91        assert_eq!(FrameSideDataType::ContentLightLevel as u32, 14);
92        assert_eq!(FrameSideDataType::FilmGrainParams as u32, 21);
93        assert_eq!(FrameSideDataType::DoviRpuBuffer as u32, 23);
94        assert_eq!(FrameSideDataType::DoviMetadata as u32, 24);
95        assert_eq!(FrameSideDataType::DynamicHdrVivid as u32, 25);
96        assert_eq!(FrameSideDataType::AmbientViewingEnvironment as u32, 26);
97        assert_eq!(FrameSideDataType::VideoHint as u32, 27);
98        assert_eq!(FrameSideDataType::Lcevc as u32, 28);
99        assert_eq!(FrameSideDataType::ViewId as u32, 29);
100        assert_eq!(FrameSideDataType::ThreeDReferenceDisplays as u32, 30);
101        assert_eq!(FrameSideDataType::Exif as u32, 31);
102    }
103
104    #[test]
105    fn test_frame_side_data_creation() {
106        let sd = FrameSideData {
107            data_type: FrameSideDataType::A53Cc,
108            data: vec![0x01, 0x02, 0x03],
109        };
110        assert_eq!(sd.data_type, FrameSideDataType::A53Cc);
111        assert_eq!(sd.data.len(), 3);
112    }
113
114    #[test]
115    fn test_frame_side_data_clone() {
116        let sd = FrameSideData {
117            data_type: FrameSideDataType::IccProfile,
118            data: vec![0xFF; 100],
119        };
120        let sd2 = sd.clone();
121        assert_eq!(sd2.data_type, FrameSideDataType::IccProfile);
122        assert_eq!(sd2.data.len(), 100);
123    }
124}