moq_karp/audio/
aac.rs

1use super::Error;
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
5pub struct AAC {
6	pub profile: u8,
7	// freq_index
8	// chan_conf
9}
10
11impl std::fmt::Display for AAC {
12	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
13		write!(f, "mp4a.40.{}", self.profile)
14	}
15}
16
17impl std::str::FromStr for AAC {
18	type Err = Error;
19
20	fn from_str(s: &str) -> Result<Self, Self::Err> {
21		let remain = s.strip_prefix("mp4a.40.").ok_or(Error::InvalidCodec)?;
22		Ok(Self {
23			profile: u8::from_str(remain)?,
24		})
25	}
26}
27
28#[cfg(test)]
29mod test {
30	use std::str::FromStr;
31
32	use super::*;
33
34	#[test]
35	fn test_aac() {
36		let encoded = "mp4a.40.2";
37		let decoded = AAC { profile: 2 };
38
39		let output = AAC::from_str(encoded).expect("failed to parse AAC string");
40		assert_eq!(output, decoded);
41
42		let output = decoded.to_string();
43		assert_eq!(output, encoded);
44	}
45}