Skip to main content

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

1use crate::coding::{Decode, Encode};
2use crate::{Buf, BufMut, Result};
3
4#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5#[derive(Debug, Clone, PartialEq, Eq)]
6/// Plain text sample entry.
7///
8/// Used for timed text. Its essentially just the standard sample entry body.
9///
10/// See ISO/IEC 14496-12:2022 Section 12.5.3.
11pub struct PlainText {
12    pub data_reference_index: u16,
13}
14
15impl Encode for PlainText {
16    fn encode<B: BufMut>(&self, buf: &mut B) -> Result<()> {
17        0u32.encode(buf)?; // reserved
18        0u16.encode(buf)?; // reserved
19        self.data_reference_index.encode(buf)?;
20        Ok(())
21    }
22}
23impl Decode for PlainText {
24    fn decode<B: Buf>(buf: &mut B) -> Result<Self> {
25        u32::decode(buf)?; // reserved
26        u16::decode(buf)?; // reserved
27        let data_reference_index = u16::decode(buf)?;
28
29        Ok(Self {
30            data_reference_index,
31        })
32    }
33}