caf/
enums.rs

1// CAF container decoder written in Rust
2//
3// Copyright (c) 2017 est31 <MTest31@outlook.com>
4// and contributors. All rights reserved.
5// Licensed under MIT license, or Apache 2 license,
6// at your option. Please see the LICENSE file
7// attached to this source distribution for details.
8
9/*!
10Module with some (sparse) enums
11
12In muliple places, the spec provides lists of IDs, saying
13that the list is non exhaustive.
14*/
15
16/// Module containing the different specified chunk types
17///
18/// Beware, the spec explicitly says that its list is non exhaustive.
19mod chunk_types {
20	// The order is not random, its how it appears in the spec, bear this in mind.
21	// The spec says that this list is not exhaustive, so we can't use an enum here.
22	// Especially, users may add their own custom chunk types provided those are
23	// outside of the reserved space of identifiers.
24
25	pub const AUDIO_DESCRIPTION :u32 = 0x64_65_73_63; // "desc"
26	pub const AUDIO_DATA :u32 = 0x64_61_74_61; // "data"
27	pub const PACKET_TABLE :u32 = 0x70_61_6b_74; // "pakt"
28	pub const CHANNEL_LAYOUT :u32 = 0x63_68_61_6e; // "chan"
29	pub const MAGIC_COOKIE :u32 = 0x6b_75_6b_69; // "kuki"
30	pub const STRINGS :u32 = 0x73_74_42_67; // "strg"
31	pub const MARKER :u32 = 0x6d_61_72_6b; // "mark"
32	pub const REGION :u32 = 0x72_65_67_6e; // "regn"
33	pub const INSTRUMENT :u32 = 0x69_6e_73_74; // "inst"
34	pub const MIDI :u32 = 0x6d_69_64_69; // "midi"
35	pub const OVERVIEW :u32 = 0x6f_76_76_77; // "ovvw"
36	pub const PEAK :u32 = 0x70_65_61_6b; // "peak"
37	pub const EDIT_COMMENTS :u32 = 0x65_64_63_74; // "edct"
38	pub const INFO :u32 = 0x69_6e_66_6f; // "info"
39	pub const UNIQUE_MATERIAL_IDENTIFIER :u32 = 0x75_6d_69_64; // "umid"
40	pub const USER_DEFINED :u32 = 0x75_75_69_64; // "uuid"
41	pub const FREE :u32 = 0x66_72_65_65; // "free"
42}
43
44/// Possible chunk types defined by the spec
45///
46/// The chunks in a CAF file after the CAF File Header form the
47/// uppermost layer of granularity.
48///
49/// The spec explicitly says that the list is not exhaustive
50/// and that users may add their own unofficial chunk types
51/// from outside of the reserved range of chunks.
52/// Those chunk types are represented by the `Other` variant.
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
54pub enum ChunkType {
55	/// mChunkType for the "Audio Description" chunk
56	AudioDescription,
57	/// mChunkType for the "Audio Data" chunk
58	AudioData,
59	/// mChunkType for the "Packet Table" chunk
60	PacketTable,
61	/// mChunkType for the "Channel Layout" chunk
62	ChannelLayout,
63	/// mChunkType for the "Magic Cookie" chunk
64	MagicCookie,
65	/// mChunkType for the "Strings" chunk
66	Strings,
67	/// mChunkType for the "Marker" chunk
68	Marker,
69	/// mChunkType for the "Region" chunk
70	Region,
71	/// mChunkType for the "Instrument" chunk
72	Instrument,
73	/// mChunkType for the "MIDI" chunk
74	Midi,
75	/// mChunkType for the "Overview" chunk
76	Overview,
77	/// mChunkType for the "Peak" chunk
78	Peak,
79	/// mChunkType for the "Edit Comments" chunk
80	EditComments,
81	/// mChunkType for the "Information" chunk
82	Info,
83	/// mChunkType for the "Unique Material Identifier" chunk
84	UniqueMaterialIdentifier,
85	/// mChunkType for the "User-Defined" chunk
86	UserDefined,
87	/// mChunkType for the "Free" chunk
88	Free,
89	/// Variant for all chunks that were not mentioned in this list.
90	///
91	/// This includes both chunk types from the range of reserved
92	/// chunk types that weren't mentioned, and those from outside
93	/// the range of reserved ones.
94	Other(u32),
95}
96
97impl From<u32> for ChunkType {
98	fn from(v :u32) -> Self {
99		use self::chunk_types::*;
100		use self::ChunkType::*;
101		match v {
102			AUDIO_DESCRIPTION => AudioDescription,
103			AUDIO_DATA => AudioData,
104			PACKET_TABLE => PacketTable,
105			CHANNEL_LAYOUT => ChannelLayout,
106			MAGIC_COOKIE => MagicCookie,
107			STRINGS => Strings,
108			MARKER => Marker,
109			REGION => Region,
110			INSTRUMENT => Instrument,
111			MIDI => Midi,
112			OVERVIEW => Overview,
113			PEAK => Peak,
114			EDIT_COMMENTS => EditComments,
115			INFO => Info,
116			UNIQUE_MATERIAL_IDENTIFIER => UniqueMaterialIdentifier,
117			USER_DEFINED => UserDefined,
118			FREE => Free,
119			_ => Other(v),
120		}
121	}
122}
123
124/// Module containing the different specified chunk types
125///
126/// Beware, the spec explicitly says that its list is non exhaustive.
127mod format_types {
128	// The order is not random, its how it appears in the spec, bear this in mind.
129	// The spec says that this list is not exhaustive, so we can't use an enum here.
130
131
132	pub const LINEAR_PCM :u32 = 0x6c_70_63_6d; // "lpcm"
133	pub const APPLE_IMA4 :u32 = 0x69_6d_61_34; // "ima4"
134	pub const MPEG4_AAC :u32 = 0x61_61_63_20; // "aac "
135	pub const MACE3 :u32 = 0x4d_41_43_33; // "MAC3"
136	pub const MACE6 :u32 = 0x4d_41_43_36; // "MAC6"
137	pub const U_LAW :u32 = 0x75_6c_61_77; // "ulaw"
138	pub const A_LAW :u32 = 0x61_6c_61_77; // "alaw"
139	pub const MPEG_LAYER_1 :u32 = 0x2e_6d_70_31; // ".mp1"
140	pub const MPEG_LAYER_2 :u32 = 0x2e_6d_70_32; // ".mp2"
141	pub const MPEG_LAYER_3 :u32 = 0x2e_6d_70_33; // ".mp3"
142	pub const AAPL_LOSSLESS :u32 = 0x61_6c_61_63; // "alac"
143}
144
145/// Payload format types defined by the spec
146///
147/// Enum for all the possible `mFormatID` field contents
148/// defined by the spec.
149///
150/// The spec explicitly says that the list is not exhaustive.
151#[derive(Debug, Clone, PartialEq, Eq)]
152pub enum FormatType {
153	/// mFormatID for Linear PCM
154	LinearPcm,
155	/// mFormatID for IMA 4:1 ADPCM
156	AppleIma4,
157	/// mFormatID for MPEG-4 AAC
158	Mpeg4Aac,
159	/// mFormatID for MACE 3:1
160	Mace3,
161	/// mFormatID for MACE 6:1
162	Mace6,
163	/// mFormatID for uLaw 2:1
164	Ulaw,
165	/// mFormatID for aLaw 2:1
166	Alaw,
167	/// mFormatID for MPEG-1
168	MpegLayer1,
169	/// mFormatID for MPEG-{1,2}
170	MpegLayer2,
171	/// mFormatID for MPEG-{1,2,3}
172	MpegLayer3,
173	/// mFormatID for Apple Lossless
174	AppleLossless,
175	/// Variant for all formats that were not mentioned in this list.
176	Other(u32),
177}
178
179impl From<u32> for FormatType {
180	fn from(v :u32) -> Self {
181		use self::format_types::*;
182		use self::FormatType::*;
183		match v {
184			LINEAR_PCM => LinearPcm,
185			APPLE_IMA4 => AppleIma4,
186			MPEG4_AAC => Mpeg4Aac,
187			MACE3 => Mace3,
188			MACE6 => Mace6,
189			U_LAW => Ulaw,
190			A_LAW => Alaw,
191			MPEG_LAYER_1 => MpegLayer1,
192			MPEG_LAYER_2 => MpegLayer2,
193			MPEG_LAYER_3 => MpegLayer3,
194			AAPL_LOSSLESS => AppleLossless,
195			_ => Other(v),
196		}
197	}
198}