Skip to main content

mp4_atom/
emeb.rs

1use crate::*;
2
3/// `EventMessageEmptyBox` ('emeb'), a sample carried by an Event Message
4/// track (the [`Evte`](crate::Evte) sample entry) to signal that no event is
5/// active for the enclosing sample's duration.
6///
7/// See ISO/IEC 23001-18:2022 Section 6.2.
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
9#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
10pub struct Emeb;
11
12impl Atom for Emeb {
13    const KIND: FourCC = FourCC::new(b"emeb");
14
15    fn decode_body<B: Buf>(_buf: &mut B) -> Result<Self> {
16        Ok(Self)
17    }
18
19    fn encode_body<B: BufMut>(&self, _buf: &mut B) -> Result<()> {
20        Ok(())
21    }
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27
28    #[test]
29    fn test_emeb_roundtrip() {
30        // A real `emeb` sample: header only, no body.
31        const ENCODED_EMEB: &[u8] = &[0x00, 0x00, 0x00, 0x08, 0x65, 0x6d, 0x65, 0x62];
32
33        let emeb =
34            Emeb::decode(&mut std::io::Cursor::new(ENCODED_EMEB)).expect("failed to decode emeb");
35        assert_eq!(emeb, Emeb);
36
37        let mut buf = Vec::new();
38        emeb.encode(&mut buf).unwrap();
39        assert_eq!(buf.as_slice(), ENCODED_EMEB);
40    }
41}