forge
Explore
Log in

Don't you dare go Hollow

Report pns access units

Browse files at this commit

0138acd214ea1af676093ac153e32652988021ccAhmet Kaan GümüşParent: eca8b3d
  • feat
    • report pns access units
Show full message
feat(aac): report pns access units
crates/ec-aac/src/decode.rsmodified+23 -3
@@ -500,6 +500,7 @@ pub struct BlockDecoder {
500 noise: Noise,500 noise: Noise,
501 sf_index: u8,501 sf_index: u8,
502 sbr: Option<crate::sbr_chain::SbrChain>,502 sbr: Option<crate::sbr_chain::SbrChain>,
503+ pns_aus: usize,
503 }504 }
504 505
505 impl BlockDecoder {506 impl BlockDecoder {
@@ -511,9 +512,13 @@ impl BlockDecoder {
511 noise: Noise(0x1f2e_3d4c),512 noise: Noise(0x1f2e_3d4c),
512 sf_index,513 sf_index,
513 sbr: None,514 sbr: None,
515+ pns_aus: 0,
514 }516 }
515 }517 }
516 518
519+ pub fn pns_aus(&self) -> usize {
520+ self.pns_aus
521+ }
517 pub fn set_sf_index(&mut self, sf_index: u8) {522 pub fn set_sf_index(&mut self, sf_index: u8) {
518 self.sf_index = sf_index;523 self.sf_index = sf_index;
519 }524 }
@@ -747,7 +752,12 @@ impl BlockDecoder {
747 // directly follows the element it decorates.752 // directly follows the element it decorates.
748 let mut pending: Option<(u8, usize, usize, bool)> = None;753 let mut pending: Option<(u8, usize, usize, bool)> = None;
749 let dump_tools = tool_sideinfo_enabled();754 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;
751 loop {761 loop {
752 if r.bits_remaining() < 3 {762 if r.bits_remaining() < 3 {
753 break;763 break;
@@ -761,6 +771,7 @@ impl BlockDecoder {
761 let tag = r.read_bits(4)? as u8;771 let tag = r.read_bits(4)? as u8;
762 let start = out.len();772 let start = out.len();
763 let mut ch = [self.channel_stream(r, None)?];773 let mut ch = [self.channel_stream(r, None)?];
774+ pns |= has_pns(&ch[0]);
764 if dump_tools {775 if dump_tools {
765 log_tool_sideinfo(tool_row(au, tag, false, &ch[0], None));776 log_tool_sideinfo(tool_row(au, tag, false, &ch[0], None));
766 }777 }
@@ -806,6 +817,7 @@ impl BlockDecoder {
806 self.channel_stream(r, shared.as_ref())?,817 self.channel_stream(r, shared.as_ref())?,
807 self.channel_stream(r, shared.as_ref())?,818 self.channel_stream(r, shared.as_ref())?,
808 ];819 ];
820+ pns |= pair.iter().any(has_pns);
809 if dump_tools {821 if dump_tools {
810 log_tool_sideinfo(tool_row(au, tag, true, &pair[0], Some(&mask)));822 log_tool_sideinfo(tool_row(au, tag, true, &pair[0], Some(&mask)));
811 }823 }
@@ -881,8 +893,7 @@ impl BlockDecoder {
881 // a non-SBR one) -- same "unavailable frame" case as the893 // a non-SBR one) -- same "unavailable frame" case as the
882 // no-fresh-payload branch in id 6 above, so fall back to894 // no-fresh-payload branch in id 6 above, so fall back to
883 // the last known SBR data the same way.895 // the last known SBR data the same way.
884- if let (Some(sbr), Some((tag, start, n, is_cpe))) =896+ if let (Some(sbr), Some((tag, start, n, is_cpe))) = (self.sbr.as_mut(), pending)
885- (self.sbr.as_mut(), pending)
886 {897 {
887 sbr.apply_last(tag, is_cpe, &mut out[start..start + n]);898 sbr.apply_last(tag, is_cpe, &mut out[start..start + n]);
888 }899 }
@@ -890,6 +901,9 @@ impl BlockDecoder {
890 }901 }
891 }902 }
892 }903 }
904+ if pns {
905+ self.pns_aus += 1;
906+ }
893 r.align_to_byte();907 r.align_to_byte();
894 Ok(out)908 Ok(out)
895 }909 }
@@ -1025,6 +1039,12 @@ fn apply_ms(left: &mut Ics, right: &mut Ics, mask: &MsMask) {
1025 /// Builds one `EC_AAC_TOOL_SIDEINFO_DEBUG` row from an already-decoded `Ics`1039 /// Builds one `EC_AAC_TOOL_SIDEINFO_DEBUG` row from an already-decoded `Ics`
1026 /// (any channel of a CPE, since PNS/IS/TNS presence is per-channel but the1040 /// (any channel of a CPE, since PNS/IS/TNS presence is per-channel but the
1027 /// dump only needs whether the element used the tool at all).1041 /// 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+
1028 fn tool_row(au: usize, tag: u8, is_cpe: bool, ch: &Ics, mask: Option<&MsMask>) -> ToolSideInfoRow {1048 fn tool_row(au: usize, tag: u8, is_cpe: bool, ch: &Ics, mask: Option<&MsMask>) -> ToolSideInfoRow {
1029 let mut ms_bands = 0;1049 let mut ms_bands = 0;
1030 let mut pns_bands = 0;1050 let mut pns_bands = 0;
crates/ec-aac/src/lib.rsmodified+5 -0
@@ -153,6 +153,11 @@ impl AacDecoder {
153 Ok(AacDecoder::with_config(parse_audio_specific_config(data)?))153 Ok(AacDecoder::with_config(parse_audio_specific_config(data)?))
154 }154 }
155 155
156+ /// Successful access units that used perceptual noise substitution.
157+ pub fn pns_aus(&self) -> usize {
158+ self.block.pns_aus()
159+ }
160+
156 /// The configuration this decoder was built with, if any.161 /// The configuration this decoder was built with, if any.
157 pub fn config(&self) -> Option<&AudioSpecificConfig> {162 pub fn config(&self) -> Option<&AudioSpecificConfig> {
158 self.config.as_ref()163 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>> {
52 52
53 /// Our decode of an ADTS file, as planar-by-channel `f32`.53 /// Our decode of an ADTS file, as planar-by-channel `f32`.
54 fn our_decode(path: &Path) -> (Vec<Vec<f32>>, u32) {54 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) {
55 let data = std::fs::read(path).expect("fixture readable");60 let data = std::fs::read(path).expect("fixture readable");
56 let mut decoder = AacDecoder::new();61 let mut decoder = AacDecoder::new();
57 let mut planes: Vec<Vec<f32>> = Vec::new();62 let mut planes: Vec<Vec<f32>> = Vec::new();
@@ -71,7 +76,7 @@ fn our_decode(path: &Path) -> (Vec<Vec<f32>>, u32) {
71 }76 }
72 at = end;77 at = end;
73 }78 }
74- (planes, rate)79+ (planes, rate, decoder.pns_aus())
75 }80 }
76 81
77 /// Pearson correlation over the overlap of two channels.82 /// Pearson correlation over the overlap of two channels.
@@ -218,6 +223,12 @@ fn aac_coding_tools_match_ffmpeg_in_isolation() {
218 .expect("ffmpeg runs");223 .expect("ffmpeg runs");
219 assert!(out.status.success(), "remux failed for {name}");224 assert!(out.status.success(), "remux failed for {name}");
220 let corr = compare(&adts);225 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+ );
221 println!("{name}: {corr:?}");232 println!("{name}: {corr:?}");
222 for (ch, c) in corr.iter().enumerate() {233 for (ch, c) in corr.iter().enumerate() {
223 assert!(234 assert!(