Debian Codegraph @

third_party/rust/mp4parse/src/boxes.rs

raw
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at https://mozilla.org/MPL/2.0/.
4 use std::fmt;
5
6 // To ensure we don't use stdlib allocating types by accident
7 #[allow(dead_code)]
8 struct Vec;
9 #[allow(dead_code)]
10 struct Box;
11 #[allow(dead_code)]
12 struct HashMap;
13 #[allow(dead_code)]
14 struct String;
15
16 macro_rules! box_database {
17 ($($(#[$attr:meta])* $boxenum:ident $boxtype:expr),*,) => {
18 #[derive(Clone, Copy, PartialEq, Eq)]
19 pub enum BoxType {
20 $($(#[$attr])* $boxenum),*,
21 UnknownBox(u32),
22 }
23
24 impl From<u32> for BoxType {
25 fn from(t: u32) -> BoxType {
26 use self::BoxType::*;
27 match t {
28 $($(#[$attr])* $boxtype => $boxenum),*,
29 _ => UnknownBox(t),
30 }
31 }
32 }
33
34 impl From<BoxType> for u32 {
35 fn from(b: BoxType) -> u32 {
36 use self::BoxType::*;
37 match b {
38 $($(#[$attr])* $boxenum => $boxtype),*,
39 UnknownBox(t) => t,
40 }
41 }
42 }
43
44 }
45 }
46
47 impl fmt::Debug for BoxType {
48 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
49 let fourcc: FourCC = From::from(*self);
50 fourcc.fmt(f)
51 }
52 }
53
54 #[derive(Default, Eq, Hash, PartialEq, Clone)]
55 pub struct FourCC {
56 pub value: [u8; 4],
57 }
58
59 impl From<u32> for FourCC {
60 fn from(number: u32) -> FourCC {
61 FourCC {
62 value: number.to_be_bytes(),
63 }
64 }
65 }
66
67 impl From<BoxType> for FourCC {
68 fn from(t: BoxType) -> FourCC {
69 let box_num: u32 = Into::into(t);
70 From::from(box_num)
71 }
72 }
73
74 impl From<[u8; 4]> for FourCC {
75 fn from(v: [u8; 4]) -> FourCC {
76 FourCC { value: v }
77 }
78 }
79
80 impl fmt::Debug for FourCC {
81 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
82 match std::str::from_utf8(&self.value) {
83 Ok(s) => f.write_str(s),
84 Err(_) => self.value.fmt(f),
85 }
86 }
87 }
88
89 impl fmt::Display for FourCC {
90 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
91 f.write_str(std::str::from_utf8(&self.value).unwrap_or("null"))
92 }
93 }
94
95 impl PartialEq<&[u8; 4]> for FourCC {
96 fn eq(&self, other: &&[u8; 4]) -> bool {
97 self.value.eq(*other)
98 }
99 }
100
101 box_database!(
102 FileTypeBox 0x6674_7970, // "ftyp"
103 MediaDataBox 0x6d64_6174, // "mdat"
104 PrimaryItemBox 0x7069_746d, // "pitm"
105 ItemDataBox 0x6964_6174, // "idat"
106 ItemInfoBox 0x6969_6e66, // "iinf"
107 ItemInfoEntry 0x696e_6665, // "infe"
108 ItemLocationBox 0x696c_6f63, // "iloc"
109 MovieBox 0x6d6f_6f76, // "moov"
110 MovieHeaderBox 0x6d76_6864, // "mvhd"
111 TrackBox 0x7472_616b, // "trak"
112 TrackHeaderBox 0x746b_6864, // "tkhd"
113 TrackReferenceBox 0x7472_6566, // "tref"
114 AuxiliaryBox 0x6175_786C, // "auxl"
115 EditBox 0x6564_7473, // "edts"
116 MediaBox 0x6d64_6961, // "mdia"
117 EditListBox 0x656c_7374, // "elst"
118 MediaHeaderBox 0x6d64_6864, // "mdhd"
119 HandlerBox 0x6864_6c72, // "hdlr"
120 MediaInformationBox 0x6d69_6e66, // "minf"
121 ItemReferenceBox 0x6972_6566, // "iref"
122 ItemPropertiesBox 0x6970_7270, // "iprp"
123 ItemPropertyContainerBox 0x6970_636f, // "ipco"
124 ItemPropertyAssociationBox 0x6970_6d61, // "ipma"
125 ColourInformationBox 0x636f_6c72, // "colr"
126 ImageSpatialExtentsProperty 0x6973_7065, // "ispe"
127 PixelAspectRatioBox 0x7061_7370, // "pasp"
128 PixelInformationBox 0x7069_7869, // "pixi"
129 AuxiliaryTypeProperty 0x6175_7843, // "auxC"
130 CleanApertureBox 0x636c_6170, // "clap"
131 ImageRotation 0x6972_6f74, // "irot"
132 ImageMirror 0x696d_6972, // "imir"
133 OperatingPointSelectorProperty 0x6131_6f70, // "a1op"
134 AV1LayeredImageIndexingProperty 0x6131_6c78, // "a1lx"
135 LayerSelectorProperty 0x6c73_656c, // "lsel"
136 SampleTableBox 0x7374_626c, // "stbl"
137 SampleDescriptionBox 0x7374_7364, // "stsd"
138 TimeToSampleBox 0x7374_7473, // "stts"
139 SampleToChunkBox 0x7374_7363, // "stsc"
140 SampleSizeBox 0x7374_737a, // "stsz"
141 ChunkOffsetBox 0x7374_636f, // "stco"
142 ChunkLargeOffsetBox 0x636f_3634, // "co64"
143 SyncSampleBox 0x7374_7373, // "stss"
144 AVCSampleEntry 0x6176_6331, // "avc1"
145 AVC3SampleEntry 0x6176_6333, // "avc3" - Need to check official name in spec.
146 AVCConfigurationBox 0x6176_6343, // "avcC"
147 H263SampleEntry 0x7332_3633, // "s263"
148 H263SpecificBox 0x6432_3633, // "d263"
149 HEV1SampleEntry 0x6865_7631, // "hev1"
150 HVC1SampleEntry 0x6876_6331, // "hvc1"
151 HEVCConfigurationBox 0x6876_6343, // "hvcC"
152 MP4AudioSampleEntry 0x6d70_3461, // "mp4a"
153 MP4VideoSampleEntry 0x6d70_3476, // "mp4v"
154 #[cfg(feature = "3gpp")]
155 AMRNBSampleEntry 0x7361_6d72, // "samr" - AMR narrow-band
156 #[cfg(feature = "3gpp")]
157 AMRWBSampleEntry 0x7361_7762, // "sawb" - AMR wide-band
158 #[cfg(feature = "3gpp")]
159 AMRSpecificBox 0x6461_6d72, // "damr"
160 ESDBox 0x6573_6473, // "esds"
161 VP8SampleEntry 0x7670_3038, // "vp08"
162 VP9SampleEntry 0x7670_3039, // "vp09"
163 VPCodecConfigurationBox 0x7670_6343, // "vpcC"
164 AV1SampleEntry 0x6176_3031, // "av01"
165 AV1CodecConfigurationBox 0x6176_3143, // "av1C"
166 FLACSampleEntry 0x664c_6143, // "fLaC"
167 FLACSpecificBox 0x6466_4c61, // "dfLa"
168 OpusSampleEntry 0x4f70_7573, // "Opus"
169 OpusSpecificBox 0x644f_7073, // "dOps"
170 ProtectedVisualSampleEntry 0x656e_6376, // "encv" - Need to check official name in spec.
171 ProtectedAudioSampleEntry 0x656e_6361, // "enca" - Need to check official name in spec.
172 MovieExtendsBox 0x6d76_6578, // "mvex"
173 MovieExtendsHeaderBox 0x6d65_6864, // "mehd"
174 QTWaveAtom 0x7761_7665, // "wave" - quicktime atom
175 ProtectionSystemSpecificHeaderBox 0x7073_7368, // "pssh"
176 SchemeInformationBox 0x7363_6869, // "schi"
177 TrackEncryptionBox 0x7465_6e63, // "tenc"
178 ProtectionSchemeInfoBox 0x7369_6e66, // "sinf"
179 OriginalFormatBox 0x6672_6d61, // "frma"
180 SchemeTypeBox 0x7363_686d, // "schm"
181 MP3AudioSampleEntry 0x2e6d_7033, // ".mp3" - from F4V.
182 CompositionOffsetBox 0x6374_7473, // "ctts"
183 LPCMAudioSampleEntry 0x6c70_636d, // "lpcm" - quicktime atom
184 ALACSpecificBox 0x616c_6163, // "alac" - Also used by ALACSampleEntry
185 UuidBox 0x7575_6964, // "uuid"
186 MetadataBox 0x6d65_7461, // "meta"
187 MetadataHeaderBox 0x6d68_6472, // "mhdr"
188 MetadataItemKeysBox 0x6b65_7973, // "keys"
189 MetadataItemListEntry 0x696c_7374, // "ilst"
190 MetadataItemDataEntry 0x6461_7461, // "data"
191 MetadataItemNameBox 0x6e61_6d65, // "name"
192 #[cfg(feature = "meta-xml")]
193 MetadataXMLBox 0x786d_6c20, // "xml "
194 #[cfg(feature = "meta-xml")]
195 MetadataBXMLBox 0x6278_6d6c, // "bxml"
196 UserdataBox 0x7564_7461, // "udta"
197 AlbumEntry 0xa961_6c62, // "©alb"
198 ArtistEntry 0xa941_5254, // "©ART"
199 ArtistLowercaseEntry 0xa961_7274, // "©art"
200 AlbumArtistEntry 0x6141_5254, // "aART"
201 CommentEntry 0xa963_6d74, // "©cmt"
202 DateEntry 0xa964_6179, // "©day"
203 TitleEntry 0xa96e_616d, // "©nam"
204 CustomGenreEntry 0xa967_656e, // "©gen"
205 StandardGenreEntry 0x676e_7265, // "gnre"
206 TrackNumberEntry 0x7472_6b6e, // "trkn"
207 DiskNumberEntry 0x6469_736b, // "disk"
208 ComposerEntry 0xa977_7274, // "©wrt"
209 EncoderEntry 0xa974_6f6f, // "©too"
210 EncodedByEntry 0xa965_6e63, // "©enc"
211 TempoEntry 0x746d_706f, // "tmpo"
212 CopyrightEntry 0x6370_7274, // "cprt"
213 CompilationEntry 0x6370_696c, // "cpil"
214 CoverArtEntry 0x636f_7672, // "covr"
215 AdvisoryEntry 0x7274_6e67, // "rtng"
216 RatingEntry 0x7261_7465, // "rate"
217 GroupingEntry 0xa967_7270, // "©grp"
218 MediaTypeEntry 0x7374_696b, // "stik"
219 PodcastEntry 0x7063_7374, // "pcst"
220 CategoryEntry 0x6361_7467, // "catg"
221 KeywordEntry 0x6b65_7977, // "keyw"
222 PodcastUrlEntry 0x7075_726c, // "purl"
223 PodcastGuidEntry 0x6567_6964, // "egid"
224 DescriptionEntry 0x6465_7363, // "desc"
225 LongDescriptionEntry 0x6c64_6573, // "ldes"
226 LyricsEntry 0xa96c_7972, // "©lyr"
227 TVNetworkNameEntry 0x7476_6e6e, // "tvnn"
228 TVShowNameEntry 0x7476_7368, // "tvsh"
229 TVEpisodeNameEntry 0x7476_656e, // "tven"
230 TVSeasonNumberEntry 0x7476_736e, // "tvsn"
231 TVEpisodeNumberEntry 0x7476_6573, // "tves"
232 PurchaseDateEntry 0x7075_7264, // "purd"
233 GaplessPlaybackEntry 0x7067_6170, // "pgap"
234 OwnerEntry 0x6f77_6e72, // "ownr"
235 HDVideoEntry 0x6864_7664, // "hdvd"
236 SortNameEntry 0x736f_6e6d, // "sonm"
237 SortAlbumEntry 0x736f_616c, // "soal"
238 SortArtistEntry 0x736f_6172, // "soar"
239 SortAlbumArtistEntry 0x736f_6161, // "soaa"
240 SortComposerEntry 0x736f_636f, // "soco"
241 );