Merge branch 'lane-corr3': AAC decoder reports how many access units used PNS
Browse files at this commit3 changed files +40 -4
- crates/ec-aac/src/decode.rs +23 -3
- crates/ec-aac/src/lib.rs +5 -0
- crates/ec-aac/tests/oracle.rs +12 -1
crates/ec-aac/src/decode.rsmodified+23 -3
| @@ -500,6 +500,7 @@ pub struct BlockDecoder { | ||
| 500 | 500 | noise: Noise, |
| 501 | 501 | sf_index: u8, |
| 502 | 502 | sbr: Option<crate::sbr_chain::SbrChain>, |
| 503 | + pns_aus: usize, | |
| 503 | 504 | } |
| 504 | 505 | |
| 505 | 506 | impl BlockDecoder { |
| @@ -511,9 +512,13 @@ impl BlockDecoder { | ||
| 511 | 512 | noise: Noise(0x1f2e_3d4c), |
| 512 | 513 | sf_index, |
| 513 | 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 | 522 | pub fn set_sf_index(&mut self, sf_index: u8) { |
| 518 | 523 | self.sf_index = sf_index; |
| 519 | 524 | } |
| @@ -747,7 +752,12 @@ impl BlockDecoder { | ||
| 747 | 752 | // directly follows the element it decorates. |
| 748 | 753 | let mut pending: Option<(u8, usize, usize, bool)> = None; |
| 749 | 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 | 761 | loop { |
| 752 | 762 | if r.bits_remaining() < 3 { |
| 753 | 763 | break; |
| @@ -761,6 +771,7 @@ impl BlockDecoder { | ||
| 761 | 771 | let tag = r.read_bits(4)? as u8; |
| 762 | 772 | let start = out.len(); |
| 763 | 773 | let mut ch = [self.channel_stream(r, None)?]; |
| 774 | + pns |= has_pns(&ch[0]); | |
| 764 | 775 | if dump_tools { |
| 765 | 776 | log_tool_sideinfo(tool_row(au, tag, false, &ch[0], None)); |
| 766 | 777 | } |
| @@ -806,6 +817,7 @@ impl BlockDecoder { | ||
| 806 | 817 | self.channel_stream(r, shared.as_ref())?, |
| 807 | 818 | self.channel_stream(r, shared.as_ref())?, |
| 808 | 819 | ]; |
| 820 | + pns |= pair.iter().any(has_pns); | |
| 809 | 821 | if dump_tools { |
| 810 | 822 | log_tool_sideinfo(tool_row(au, tag, true, &pair[0], Some(&mask))); |
| 811 | 823 | } |
| @@ -881,8 +893,7 @@ impl BlockDecoder { | ||
| 881 | 893 | // a non-SBR one) -- same "unavailable frame" case as the |
| 882 | 894 | // no-fresh-payload branch in id 6 above, so fall back to |
| 883 | 895 | // 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) | |
| 886 | 897 | { |
| 887 | 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 | 907 | r.align_to_byte(); |
| 894 | 908 | Ok(out) |
| 895 | 909 | } |
| @@ -1025,6 +1039,12 @@ fn apply_ms(left: &mut Ics, right: &mut Ics, mask: &MsMask) { | ||
| 1025 | 1039 | /// Builds one `EC_AAC_TOOL_SIDEINFO_DEBUG` row from an already-decoded `Ics` |
| 1026 | 1040 | /// (any channel of a CPE, since PNS/IS/TNS presence is per-channel but the |
| 1027 | 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 | 1048 | fn tool_row(au: usize, tag: u8, is_cpe: bool, ch: &Ics, mask: Option<&MsMask>) -> ToolSideInfoRow { |
| 1029 | 1049 | let mut ms_bands = 0; |
| 1030 | 1050 | let mut pns_bands = 0; |
crates/ec-aac/src/lib.rsmodified+5 -0
| @@ -153,6 +153,11 @@ impl AacDecoder { | ||
| 153 | 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 | 161 | /// The configuration this decoder was built with, if any. |
| 157 | 162 | pub fn config(&self) -> Option<&AudioSpecificConfig> { |
| 158 | 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 | 53 | /// Our decode of an ADTS file, as planar-by-channel `f32`. |
| 54 | 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 | 60 | let data = std::fs::read(path).expect("fixture readable"); |
| 56 | 61 | let mut decoder = AacDecoder::new(); |
| 57 | 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 | 77 | at = end; |
| 73 | 78 | } |
| 74 | - (planes, rate) | |
| 79 | + (planes, rate, decoder.pns_aus()) | |
| 75 | 80 | } |
| 76 | 81 | |
| 77 | 82 | /// Pearson correlation over the overlap of two channels. |
| @@ -218,6 +223,12 @@ fn aac_coding_tools_match_ffmpeg_in_isolation() { | ||
| 218 | 223 | .expect("ffmpeg runs"); |
| 219 | 224 | assert!(out.status.success(), "remux failed for {name}"); |
| 220 | 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 | 232 | println!("{name}: {corr:?}"); |
| 222 | 233 | for (ch, c) in corr.iter().enumerate() { |
| 223 | 234 | assert!( |