Skip to main content

mp4_atom/moov/trak/mdia/minf/stbl/stsd/
camm.rs

1use crate::*;
2
3/// CameraMotionMetadataSampleEntry ('camm'), used for camera motion metadata tracks
4/// (e.g. gyroscope/accelerometer samples).
5///
6/// See [Google's "Camera Motion Metadata Track Design" specification](https://developers.google.com/streetview/publish/camm-spec).
7#[derive(Debug, Clone, PartialEq, Eq)]
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9pub struct Camm {
10    pub metadata: MetaData,
11}
12
13impl Atom for Camm {
14    const KIND: FourCC = FourCC::new(b"camm");
15
16    fn decode_body<B: Buf>(buf: &mut B) -> Result<Self> {
17        Ok(Self {
18            metadata: MetaData::decode(buf)?,
19        })
20    }
21
22    fn encode_body<B: BufMut>(&self, buf: &mut B) -> Result<()> {
23        self.metadata.encode(buf)?;
24        Ok(())
25    }
26}
27
28#[cfg(test)]
29mod tests {
30    use super::*;
31
32    #[test]
33    fn test_camm_roundtrip() {
34        let camm = Camm {
35            metadata: MetaData {
36                data_reference_index: 1,
37            },
38        };
39
40        let mut buf = Vec::new();
41        camm.encode(&mut buf).unwrap();
42
43        let decoded = Camm::decode(&mut buf.as_slice()).expect("failed to decode camm");
44        assert_eq!(decoded, camm);
45    }
46}