1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//! MP4 specific items
//!
//! ## File notes
//!
//! The only supported tag format is [`Ilst`].
mod atom_info;
pub(crate) mod ilst;
mod moov;
mod properties;
mod read;

use lofty_attr::LoftyFile;

// Exports

/// This module contains the codes for all of the [Well-known data types]
///
/// [Well-known data types]: https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/Metadata/Metadata.html#//apple_ref/doc/uid/TP40000939-CH1-SW34
pub mod constants {
	pub use super::ilst::constants::*;
}

pub use crate::mp4::properties::{AudioObjectType, Mp4Codec, Mp4Properties};
pub use atom_info::AtomIdent;
pub use ilst::atom::{AdvisoryRating, Atom, AtomData};
pub use ilst::Ilst;

pub(crate) use properties::SAMPLE_RATES;

/// An MP4 file
#[derive(LoftyFile)]
#[lofty(read_fn = "read::read_from")]
pub struct Mp4File {
	/// The file format from ftyp's "major brand" (Ex. "M4A ")
	pub(crate) ftyp: String,
	#[lofty(tag_type = "Mp4Ilst")]
	/// The parsed `ilst` (metadata) atom, if it exists
	pub(crate) ilst_tag: Option<Ilst>,
	/// The file's audio properties
	pub(crate) properties: Mp4Properties,
}

impl Mp4File {
	/// Returns the file format from ftyp's "major brand" (Ex. "M4A ")
	///
	/// # Examples
	///
	/// ```rust,no_run
	/// use lofty::mp4::Mp4File;
	/// use lofty::{AudioFile, ParseOptions};
	///
	/// # fn main() -> lofty::Result<()> {
	/// # let mut m4a_reader = std::io::Cursor::new(&[]);
	/// let m4a_file = Mp4File::read_from(&mut m4a_reader, ParseOptions::new())?;
	///
	/// assert_eq!(m4a_file.ftyp(), "M4A ");
	/// # Ok(()) }
	/// ```
	pub fn ftyp(&self) -> &str {
		self.ftyp.as_ref()
	}
}