Debian Codegraph @

debian/missing-sources/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 MP4AudioSampleEntry 0x6d70_3461, // "mp4a"
150 MP4VideoSampleEntry 0x6d70_3476, // "mp4v"
151 #[cfg(feature = "3gpp")]
152 AMRNBSampleEntry 0x7361_6d72, // "samr" - AMR narrow-band
153 #[cfg(feature = "3gpp")]
154 AMRWBSampleEntry 0x7361_7762, // "sawb" - AMR wide-band
155 #[cfg(feature = "3gpp")]
156 AMRSpecificBox 0x6461_6d72, // "damr"
157 ESDBox 0x6573_6473, // "esds"
158 VP8SampleEntry 0x7670_3038, // "vp08"
159 VP9SampleEntry 0x7670_3039, // "vp09"
160 VPCodecConfigurationBox 0x7670_6343, // "vpcC"
161 AV1SampleEntry 0x6176_3031, // "av01"
162 AV1CodecConfigurationBox 0x6176_3143, // "av1C"
163 FLACSampleEntry 0x664c_6143, // "fLaC"
164 FLACSpecificBox 0x6466_4c61, // "dfLa"
165 OpusSampleEntry 0x4f70_7573, // "Opus"
166 OpusSpecificBox 0x644f_7073, // "dOps"
167 ProtectedVisualSampleEntry 0x656e_6376, // "encv" - Need to check official name in spec.
168 ProtectedAudioSampleEntry 0x656e_6361, // "enca" - Need to check official name in spec.
169 MovieExtendsBox 0x6d76_6578, // "mvex"
170 MovieExtendsHeaderBox 0x6d65_6864, // "mehd"
171 QTWaveAtom 0x7761_7665, // "wave" - quicktime atom
172 ProtectionSystemSpecificHeaderBox 0x7073_7368, // "pssh"
173 SchemeInformationBox 0x7363_6869, // "schi"
174 TrackEncryptionBox 0x7465_6e63, // "tenc"
175 ProtectionSchemeInfoBox 0x7369_6e66, // "sinf"
176 OriginalFormatBox 0x6672_6d61, // "frma"
177 SchemeTypeBox 0x7363_686d, // "schm"
178 MP3AudioSampleEntry 0x2e6d_7033, // ".mp3" - from F4V.
179 CompositionOffsetBox 0x6374_7473, // "ctts"
180 LPCMAudioSampleEntry 0x6c70_636d, // "lpcm" - quicktime atom
181 ALACSpecificBox 0x616c_6163, // "alac" - Also used by ALACSampleEntry
182 UuidBox 0x7575_6964, // "uuid"
183 MetadataBox 0x6d65_7461, // "meta"
184 MetadataHeaderBox 0x6d68_6472, // "mhdr"
185 MetadataItemKeysBox 0x6b65_7973, // "keys"
186 MetadataItemListEntry 0x696c_7374, // "ilst"
187 MetadataItemDataEntry 0x6461_7461, // "data"
188 MetadataItemNameBox 0x6e61_6d65, // "name"
189 #[cfg(feature = "meta-xml")]
190 MetadataXMLBox 0x786d_6c20, // "xml "
191 #[cfg(feature = "meta-xml")]
192 MetadataBXMLBox 0x6278_6d6c, // "bxml"
193 UserdataBox 0x7564_7461, // "udta"
194 AlbumEntry 0xa961_6c62, // "©alb"
195 ArtistEntry 0xa941_5254, // "©ART"
196 ArtistLowercaseEntry 0xa961_7274, // "©art"
197 AlbumArtistEntry 0x6141_5254, // "aART"
198 CommentEntry 0xa963_6d74, // "©cmt"
199 DateEntry 0xa964_6179, // "©day"
200 TitleEntry 0xa96e_616d, // "©nam"
201 CustomGenreEntry 0xa967_656e, // "©gen"
202 StandardGenreEntry 0x676e_7265, // "gnre"
203 TrackNumberEntry 0x7472_6b6e, // "trkn"
204 DiskNumberEntry 0x6469_736b, // "disk"
205 ComposerEntry 0xa977_7274, // "©wrt"
206 EncoderEntry 0xa974_6f6f, // "©too"
207 EncodedByEntry 0xa965_6e63, // "©enc"
208 TempoEntry 0x746d_706f, // "tmpo"
209 CopyrightEntry 0x6370_7274, // "cprt"
210 CompilationEntry 0x6370_696c, // "cpil"
211 CoverArtEntry 0x636f_7672, // "covr"
212 AdvisoryEntry 0x7274_6e67, // "rtng"
213 RatingEntry 0x7261_7465, // "rate"
214 GroupingEntry 0xa967_7270, // "©grp"
215 MediaTypeEntry 0x7374_696b, // "stik"
216 PodcastEntry 0x7063_7374, // "pcst"
217 CategoryEntry 0x6361_7467, // "catg"
218 KeywordEntry 0x6b65_7977, // "keyw"
219 PodcastUrlEntry 0x7075_726c, // "purl"
220 PodcastGuidEntry 0x6567_6964, // "egid"
221 DescriptionEntry 0x6465_7363, // "desc"
222 LongDescriptionEntry 0x6c64_6573, // "ldes"
223 LyricsEntry 0xa96c_7972, // "©lyr"
224 TVNetworkNameEntry 0x7476_6e6e, // "tvnn"
225 TVShowNameEntry 0x7476_7368, // "tvsh"
226 TVEpisodeNameEntry 0x7476_656e, // "tven"
227 TVSeasonNumberEntry 0x7476_736e, // "tvsn"
228 TVEpisodeNumberEntry 0x7476_6573, // "tves"
229 PurchaseDateEntry 0x7075_7264, // "purd"
230 GaplessPlaybackEntry 0x7067_6170, // "pgap"
231 OwnerEntry 0x6f77_6e72, // "ownr"
232 HDVideoEntry 0x6864_7664, // "hdvd"
233 SortNameEntry 0x736f_6e6d, // "sonm"
234 SortAlbumEntry 0x736f_616c, // "soal"
235 SortArtistEntry 0x736f_6172, // "soar"
236 SortAlbumArtistEntry 0x736f_6161, // "soaa"
237 SortComposerEntry 0x736f_636f, // "soco"
238 );