isobmff/boxes/
text_media.rs

1use scuffle_bytes_util::zero_copy::{Deserialize, Serialize, ZeroCopyReader};
2
3use super::{BitRateBox, SampleEntry, TextConfigBox};
4use crate::{IsoBox, IsoSized, UnknownBox, Utf8String};
5
6/// Plain Text sample entry
7///
8/// ISO/IEC 14496-12 - 12.5.3
9///
10/// Sub boxes:
11/// - [`btrt`](super::BitRateBox)
12/// - Any other boxes
13#[derive(Debug, PartialEq, Eq)]
14pub struct PlainTextSampleEntry {
15    /// The sample entry that this box inherits from.
16    pub sample_entry: SampleEntry,
17}
18
19impl<'a> Deserialize<'a> for PlainTextSampleEntry {
20    fn deserialize<R: ZeroCopyReader<'a>>(reader: R) -> std::io::Result<Self> {
21        Ok(Self {
22            sample_entry: SampleEntry::deserialize(reader)?,
23        })
24    }
25}
26
27impl Serialize for PlainTextSampleEntry {
28    fn serialize<W>(&self, writer: W) -> std::io::Result<()>
29    where
30        W: std::io::Write,
31    {
32        self.sample_entry.serialize(writer)
33    }
34}
35
36impl IsoSized for PlainTextSampleEntry {
37    fn size(&self) -> usize {
38        self.sample_entry.size()
39    }
40}
41
42/// Simple text sample entry
43///
44/// ISO/IEC 14496-12 - 12.5.3
45#[derive(IsoBox, Debug, PartialEq, Eq)]
46#[iso_box(box_type = b"stxt", crate_path = crate)]
47pub struct SimpleTextSampleEntry<'a> {
48    /// The sample entry that this box inherits from.
49    pub sample_entry: PlainTextSampleEntry,
50    /// A MIME type which identifies the content encoding of the timed text. It is
51    /// defined in the same way as for an [`ItemInfoEntry`](super::ItemInfoEntry) in this document.
52    /// If not present (an empty string is supplied) the timed text is not encoded.
53    /// An example for this field is 'application/zip'.
54    pub content_encoding: Utf8String,
55    /// A MIME type which identifies the content format of the samples. Examples for
56    /// this field include 'text/html' and 'text/plain'.
57    pub mime_format: Utf8String,
58    /// The contained [`BitRateBox`]. (optional)
59    #[iso_box(nested_box(collect))]
60    pub btrt: Option<BitRateBox>,
61    /// The contained [`TextConfigBox`]. (optional)
62    #[iso_box(nested_box(collect))]
63    pub txtc: Option<TextConfigBox>,
64    /// A list of unknown boxes that were not recognized during deserialization.
65    #[iso_box(nested_box(collect_unknown))]
66    pub unknown_boxes: Vec<UnknownBox<'a>>,
67}