isobmff/boxes/subtitle_media.rs
1use scuffle_bytes_util::zero_copy::{Deserialize, Serialize, ZeroCopyReader};
2
3use super::{BitRateBox, SampleEntry, TextConfigBox};
4use crate::{FullBoxHeader, IsoBox, IsoSized, UnknownBox, Utf8List, Utf8String};
5
6/// Subtitle media header box
7///
8/// ISO/IEC 14496-12 - 12.6.2
9#[derive(IsoBox, Debug, PartialEq, Eq)]
10#[iso_box(box_type = b"sthd", crate_path = crate)]
11pub struct SubtitleMediaHeaderBox {
12 /// The full box header.
13 pub full_header: FullBoxHeader,
14 // empty
15}
16
17/// Subtitle sample entry
18///
19/// ISO/IEC 14496-12 - 12.6.3
20///
21/// Sub boxes:
22/// - [`btrt`](super::BitRateBox)
23/// - Any other boxes
24#[derive(Debug, PartialEq, Eq)]
25pub struct SubtitleSampleEntry {
26 /// The sample entry that this box inherits from.
27 pub sample_entry: SampleEntry,
28}
29
30impl<'a> Deserialize<'a> for SubtitleSampleEntry {
31 fn deserialize<R: ZeroCopyReader<'a>>(reader: R) -> std::io::Result<Self> {
32 Ok(Self {
33 sample_entry: SampleEntry::deserialize(reader)?,
34 })
35 }
36}
37
38impl Serialize for SubtitleSampleEntry {
39 fn serialize<W>(&self, writer: W) -> std::io::Result<()>
40 where
41 W: std::io::Write,
42 {
43 self.sample_entry.serialize(writer)
44 }
45}
46
47impl IsoSized for SubtitleSampleEntry {
48 fn size(&self) -> usize {
49 self.sample_entry.size()
50 }
51}
52
53/// XML subtitle sample entry
54///
55/// ISO/IEC 14496-12 - 12.6.3
56#[derive(IsoBox, Debug, PartialEq, Eq)]
57#[iso_box(box_type = b"stpp", crate_path = crate)]
58pub struct XMLSubtitleSampleEntry<'a> {
59 /// The sample entry that this box inherits from.
60 pub sample_entry: SubtitleSampleEntry,
61 /// One or more XML namespaces to which the sample documents conform. When used for
62 /// metadata, this is needed for identifying its type, e.g. gBSD or AQoS [MPEG-21-7] and for decoding
63 /// using XML aware encoding mechanisms such as BiM.
64 pub namespace: Utf8List,
65 /// Zero or more URLs for XML schema(s) to which the sample document conforms. If
66 /// there is one namespace and one schema, then this field shall be the URL of the one schema. If there is
67 /// more than one namespace, then the syntax of this field shall adhere to that for xsi:​schemaLocation
68 /// attribute as defined by XML. When used for metadata, this is needed for decoding of the timed
69 /// metadata by XML aware encoding mechanisms such as BiM.
70 pub schema_location: Utf8List,
71 /// The media type of all auxiliary resources, such as images and fonts, if present, stored as subtitle sub-samples.
72 pub auxiliary_mime_types: Utf8List,
73 /// The contained [`BitRateBox`]. (optional)
74 #[iso_box(nested_box(collect))]
75 pub btrt: Option<BitRateBox>,
76 /// A list of unknown boxes that were not recognized during deserialization.
77 #[iso_box(nested_box(collect_unknown))]
78 pub unknown_boxes: Vec<UnknownBox<'a>>,
79}
80
81/// Text subtitle sample entry
82///
83/// ISO/IEC 14496-12 - 12.6.3
84#[derive(IsoBox, Debug, PartialEq, Eq)]
85#[iso_box(box_type = b"sbtt", crate_path = crate)]
86pub struct TextSubtitleSampleEntry<'a> {
87 /// The sample entry that this box inherits from.
88 pub sample_entry: SubtitleSampleEntry,
89 /// A MIME type which identifies the content encoding of the subtitles. It is
90 /// defined in the same way as for an ItemInfoEntry in this document. If not present (an empty string
91 /// is supplied) the subtitle samples are not encoded. An example for this field is 'application/zip'.
92 pub content_encoding: Utf8String,
93 /// A MIME type which identifies the content format of the samples. Examples for
94 /// this field include 'text/html' and 'text/plain'.
95 pub mime_format: Utf8String,
96 /// The contained [`BitRateBox`]. (optional)
97 #[iso_box(nested_box(collect))]
98 pub btrt: Option<BitRateBox>,
99 /// The contained [`TextConfigBox`]. (optional)
100 #[iso_box(nested_box(collect))]
101 pub txtc: Option<TextConfigBox>,
102 /// A list of unknown boxes that were not recognized during deserialization.
103 #[iso_box(nested_box(collect_unknown))]
104 pub unknown_boxes: Vec<UnknownBox<'a>>,
105}