isobmff/boxes/metadata_media.rs
1use scuffle_bytes_util::BytesCow;
2use scuffle_bytes_util::zero_copy::{Deserialize, Serialize};
3
4use super::{BitRateBox, SampleEntry};
5use crate::{FullBoxHeader, IsoBox, IsoSized, UnknownBox, Utf8List, Utf8String};
6
7/// Metadata sample entry
8///
9/// ISO/IEC 14496-12 - 12.3.3
10///
11/// Sub boxes:
12/// - [`btrt`](super::BitRateBox)
13/// - Any other boxes
14#[derive(Debug, PartialEq, Eq)]
15pub struct MetaDataSampleEntry {
16 /// The sample entry that this box inherits from.
17 pub sample_entry: SampleEntry,
18}
19
20impl<'a> Deserialize<'a> for MetaDataSampleEntry {
21 fn deserialize<R>(reader: R) -> std::io::Result<Self>
22 where
23 R: scuffle_bytes_util::zero_copy::ZeroCopyReader<'a>,
24 {
25 Ok(Self {
26 sample_entry: SampleEntry::deserialize(reader)?,
27 })
28 }
29}
30
31impl Serialize for MetaDataSampleEntry {
32 fn serialize<W>(&self, writer: W) -> std::io::Result<()>
33 where
34 W: std::io::Write,
35 {
36 self.sample_entry.serialize(writer)
37 }
38}
39
40impl IsoSized for MetaDataSampleEntry {
41 fn size(&self) -> usize {
42 self.sample_entry.size()
43 }
44}
45
46/// XML metadata sample entry
47///
48/// ISO/IEC 14496-12 - 12.3.3
49#[derive(IsoBox, Debug, PartialEq, Eq)]
50#[iso_box(box_type = b"metx", crate_path = crate)]
51pub struct XMLMetaDataSampleEntry<'a> {
52 /// The sample entry that this box inherits from.
53 pub sample_entry: MetaDataSampleEntry,
54 /// A MIME type which identifies the content encoding of the timed metadata.
55 /// It is defined in the same way as for an [`ItemInfoEntry`](super::ItemInfoEntry) in this document.
56 /// If not present (an empty string is supplied) the timed metadata is not encoded.
57 /// An example for this field is 'application/zip'.
58 /// Note that no MIME types for BiM [ISO/IEC 23001-1] and TeM [ISO/IEC 15938-1] currently exist.
59 /// Thus, the experimental MIME types 'application/x-BiM' and 'text/x-TeM' shall be used to identify
60 /// these encoding mechanisms.
61 pub content_encoding: Utf8String,
62 /// One or more XML namespaces to which the sample documents conform. When
63 /// used for metadata, this is needed for identifying its type, e.g. gBSD or AQoS [MPEG-21-7] and for
64 /// decoding using XML aware encoding mechanisms such as BiM.
65 pub namespace: Utf8List,
66 /// Zero or more URLs for XML schema(s) to which the sample document
67 /// conforms. If there is one namespace and one schema, then this field shall be the URL of the one
68 /// schema. If there is more than one namespace, then the syntax of this field shall adhere to that
69 /// for xsi:​schemaLocation attribute as defined by XML. When used for metadata, this is needed for
70 /// decoding of the timed metadata by XML aware encoding mechanisms such as BiM.
71 pub schema_location: Utf8List,
72 /// The contained [`BitRateBox`]. (optional)
73 #[iso_box(nested_box(collect))]
74 pub btrt: Option<BitRateBox>,
75 /// A list of unknown boxes that were not recognized during deserialization.
76 #[iso_box(nested_box(collect_unknown))]
77 pub unknown_boxes: Vec<UnknownBox<'a>>,
78}
79
80/// Text config box
81///
82/// ISO/IEC 14496-12 - 12.3.3
83#[derive(IsoBox, Debug, PartialEq, Eq)]
84#[iso_box(box_type = b"txtC", crate_path = crate)]
85pub struct TextConfigBox {
86 /// The full box header.
87 pub full_header: FullBoxHeader,
88 /// The initial text of each document which is prepended before the contents of each sync sample.
89 pub text_config: Utf8String,
90}
91
92/// Text metadata sample entry
93///
94/// ISO/IEC 14496-12 - 12.3.3
95#[derive(IsoBox, Debug, PartialEq, Eq)]
96#[iso_box(box_type = b"mett", crate_path = crate)]
97pub struct TextMetaDataSampleEntry<'a> {
98 /// The sample entry that this box inherits from.
99 pub sample_entry: MetaDataSampleEntry,
100 /// A MIME type which identifies the content encoding of the timed metadata.
101 /// It is defined in the same way as for an [`ItemInfoEntry`](super::ItemInfoEntry) in this document.
102 /// If not present (an empty string is supplied) the timed metadata is not encoded.
103 /// An example for this field is 'application/zip'.
104 /// Note that no MIME types for BiM [ISO/IEC 23001-1] and TeM [ISO/IEC 15938-1] currently exist.
105 /// Thus, the experimental MIME types 'application/x-BiM' and 'text/x-TeM' shall be used to identify
106 /// these encoding mechanisms.
107 pub content_encoding: Utf8String,
108 /// A MIME type which identifies the content format of the samples.
109 /// Examples for this field include 'text/html' and 'text/plain'.
110 pub mime_format: Utf8String,
111 /// The contained [`BitRateBox`]. (optional)
112 #[iso_box(nested_box(collect))]
113 pub btrt: Option<BitRateBox>,
114 /// The contained [`TextConfigBox`]. (optional)
115 #[iso_box(nested_box(collect))]
116 pub txtc: Option<TextConfigBox>,
117 /// A list of unknown boxes that were not recognized during deserialization.
118 #[iso_box(nested_box(collect_unknown))]
119 pub unknown_boxes: Vec<UnknownBox<'a>>,
120}
121
122/// MIME box
123///
124/// ISO/IEC 14496-12 - 12.3.3
125#[derive(IsoBox, Debug, PartialEq, Eq)]
126#[iso_box(box_type = b"mime", crate_path = crate)]
127pub struct MIMEBox {
128 /// The full box header.
129 pub full_header: FullBoxHeader,
130 /// A string corresponding to the MIME type each XML document carried in the stream
131 /// would have if it were delivered on its own, possibly including sub-parameters.
132 pub content_type: Utf8String,
133}
134
135/// URI box
136///
137/// ISO/IEC 14496-12 - 12.3.3
138#[derive(IsoBox, Debug, PartialEq, Eq)]
139#[iso_box(box_type = b"uri ", crate_path = crate)]
140pub struct URIBox {
141 /// The full box header.
142 pub full_header: FullBoxHeader,
143 /// A URI formatted according to the rules in 6.3.3.
144 pub the_uri: Utf8String,
145}
146
147/// URI init box
148///
149/// ISO/IEC 14496-12 - 12.3.3
150#[derive(IsoBox, Debug, PartialEq, Eq)]
151#[iso_box(box_type = b"uriI", crate_path = crate)]
152pub struct URIInitBox<'a> {
153 /// The full box header.
154 pub full_header: FullBoxHeader,
155 /// Opaque data whose form is defined in the documentation of the URI form.
156 pub uri_initialization_data: BytesCow<'a>,
157}
158
159/// URI meta sample entry
160///
161/// ISO/IEC 14496-12 - 12.3.3
162#[derive(IsoBox, Debug, PartialEq, Eq)]
163#[iso_box(box_type = b"urim", crate_path = crate)]
164pub struct URIMetaSampleEntry<'a> {
165 /// The sample entry that this box inherits from.
166 pub sample_entry: MetaDataSampleEntry,
167 /// The contained [`BitRateBox`]. (optional)
168 #[iso_box(nested_box(collect))]
169 pub btrt: Option<BitRateBox>,
170 /// The contained [`MIMEBox`]. (mandatory)
171 #[iso_box(nested_box)]
172 pub the_label: URIBox,
173 /// The contained [`URIInitBox`]. (optional)
174 #[iso_box(nested_box(collect))]
175 pub init: Option<URIInitBox<'a>>,
176 /// A list of unknown boxes that were not recognized during deserialization.
177 #[iso_box(nested_box(collect_unknown))]
178 pub unknown_boxes: Vec<UnknownBox<'a>>,
179}