forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-corr3': AAC decoder reports how many access units used PNS

Browse files at this commit

09e998b37ccfd8bd5052d060dc68c24921e9edf3Ahmet Kaan GümüşParent: eca8b3d0138acd
crates/ec-aac/src/decode.rsmodified+23 -3
@@ -500,6 +500,7 @@ pub struct BlockDecoder {
500500 noise: Noise,
501501 sf_index: u8,
502502 sbr: Option<crate::sbr_chain::SbrChain>,
503+ pns_aus: usize,
503504 }
504505
505506 impl BlockDecoder {
@@ -511,9 +512,13 @@ impl BlockDecoder {
511512 noise: Noise(0x1f2e_3d4c),
512513 sf_index,
513514 sbr: None,
515+ pns_aus: 0,
514516 }
515517 }
516518
519+ pub fn pns_aus(&self) -> usize {
520+ self.pns_aus
521+ }
517522 pub fn set_sf_index(&mut self, sf_index: u8) {
518523 self.sf_index = sf_index;
519524 }
@@ -747,7 +752,12 @@ impl BlockDecoder {
747752 // directly follows the element it decorates.
748753 let mut pending: Option<(u8, usize, usize, bool)> = None;
749754 let dump_tools = tool_sideinfo_enabled();
750- let au = if dump_tools { next_tool_sideinfo_au() } else { 0 };
755+ let au = if dump_tools {
756+ next_tool_sideinfo_au()
757+ } else {
758+ 0
759+ };
760+ let mut pns = false;
751761 loop {
752762 if r.bits_remaining() < 3 {
753763 break;
@@ -761,6 +771,7 @@ impl BlockDecoder {
761771 let tag = r.read_bits(4)? as u8;
762772 let start = out.len();
763773 let mut ch = [self.channel_stream(r, None)?];
774+ pns |= has_pns(&ch[0]);
764775 if dump_tools {
765776 log_tool_sideinfo(tool_row(au, tag, false, &ch[0], None));
766777 }
@@ -806,6 +817,7 @@ impl BlockDecoder {
806817 self.channel_stream(r, shared.as_ref())?,
807818 self.channel_stream(r, shared.as_ref())?,
808819 ];
820+ pns |= pair.iter().any(has_pns);
809821 if dump_tools {
810822 log_tool_sideinfo(tool_row(au, tag, true, &pair[0], Some(&mask)));
811823 }
@@ -881,8 +893,7 @@ impl BlockDecoder {
881893 // a non-SBR one) -- same "unavailable frame" case as the
882894 // no-fresh-payload branch in id 6 above, so fall back to
883895 // the last known SBR data the same way.
884- if let (Some(sbr), Some((tag, start, n, is_cpe))) =
885- (self.sbr.as_mut(), pending)
896+ if let (Some(sbr), Some((tag, start, n, is_cpe))) = (self.sbr.as_mut(), pending)
886897 {
887898 sbr.apply_last(tag, is_cpe, &mut out[start..start + n]);
888899 }
@@ -890,6 +901,9 @@ impl BlockDecoder {
890901 }
891902 }
892903 }
904+ if pns {
905+ self.pns_aus += 1;
906+ }
893907 r.align_to_byte();
894908 Ok(out)
895909 }
@@ -1025,6 +1039,12 @@ fn apply_ms(left: &mut Ics, right: &mut Ics, mask: &MsMask) {
10251039 /// Builds one `EC_AAC_TOOL_SIDEINFO_DEBUG` row from an already-decoded `Ics`
10261040 /// (any channel of a CPE, since PNS/IS/TNS presence is per-channel but the
10271041 /// dump only needs whether the element used the tool at all).
1042+fn has_pns(ch: &Ics) -> bool {
1043+ ch.cb
1044+ .iter()
1045+ .any(|group| group.iter().any(|&codebook| codebook == NOISE_HCB))
1046+}
1047+
10281048 fn tool_row(au: usize, tag: u8, is_cpe: bool, ch: &Ics, mask: Option<&MsMask>) -> ToolSideInfoRow {
10291049 let mut ms_bands = 0;
10301050 let mut pns_bands = 0;
crates/ec-aac/src/lib.rsmodified+5 -0
@@ -153,6 +153,11 @@ impl AacDecoder {
153153 Ok(AacDecoder::with_config(parse_audio_specific_config(data)?))
154154 }
155155
156+ /// Successful access units that used perceptual noise substitution.
157+ pub fn pns_aus(&self) -> usize {
158+ self.block.pns_aus()
159+ }
160+
156161 /// The configuration this decoder was built with, if any.
157162 pub fn config(&self) -> Option<&AudioSpecificConfig> {
158163 self.config.as_ref()
crates/ec-aac/tests/oracle.rsmodified+12 -1
@@ -52,6 +52,11 @@ fn deinterleave(samples: &[f32], channels: usize) -> Vec<Vec<f32>> {
5252
5353 /// Our decode of an ADTS file, as planar-by-channel `f32`.
5454 fn our_decode(path: &Path) -> (Vec<Vec<f32>>, u32) {
55+ let (planes, rate, _) = our_decode_with_pns(path);
56+ (planes, rate)
57+}
58+
59+fn our_decode_with_pns(path: &Path) -> (Vec<Vec<f32>>, u32, usize) {
5560 let data = std::fs::read(path).expect("fixture readable");
5661 let mut decoder = AacDecoder::new();
5762 let mut planes: Vec<Vec<f32>> = Vec::new();
@@ -71,7 +76,7 @@ fn our_decode(path: &Path) -> (Vec<Vec<f32>>, u32) {
7176 }
7277 at = end;
7378 }
74- (planes, rate)
79+ (planes, rate, decoder.pns_aus())
7580 }
7681
7782 /// Pearson correlation over the overlap of two channels.
@@ -218,6 +223,12 @@ fn aac_coding_tools_match_ffmpeg_in_isolation() {
218223 .expect("ffmpeg runs");
219224 assert!(out.status.success(), "remux failed for {name}");
220225 let corr = compare(&adts);
226+ let pns = our_decode_with_pns(&adts).2;
227+ assert_eq!(
228+ pns > 0,
229+ matches!(tool, "pns" | "all"),
230+ "{name}: pns_aus={pns}"
231+ );
221232 println!("{name}: {corr:?}");
222233 for (ch, c) in corr.iter().enumerate() {
223234 assert!(