Merge branch 'simplify/w0t-aac' into simplify/w0
Browse files at this commit3 changed files +31 -20
- crates/ec-aac/src/config.rs +13 -19
- crates/ec-aac/tests/it/multichannel_parity.rs +7 -0
- scripts/fixtures.d/audio.sh +11 -1
crates/ec-aac/src/config.rsmodified+13 -19
| @@ -77,10 +77,11 @@ pub fn parse_audio_specific_config(data: &[u8]) -> Result<AudioSpecificConfig> { | ||
| 77 | 77 | let mut r = BitReader::new(data); |
| 78 | 78 | let mut object = object_type(&mut r)?; |
| 79 | 79 | let (mut sf_index, mut rate) = sampling_frequency(&mut r)?; |
| 80 | - let mut channel_config = r.read_bits(4)? as u8; | |
| 80 | + let channel_config = r.read_bits(4)? as u8; | |
| 81 | 81 | let mut sbr = false; |
| 82 | 82 | let mut ps = false; |
| 83 | 83 | let mut ext_rate = None; |
| 84 | + let mut program = None; | |
| 84 | 85 | if object == AOT_SBR || object == AOT_PS { |
| 85 | 86 | sbr = true; |
| 86 | 87 | ps = object == AOT_PS; |
| @@ -98,21 +99,10 @@ pub fn parse_audio_specific_config(data: &[u8]) -> Result<AudioSpecificConfig> { | ||
| 98 | 99 | } |
| 99 | 100 | let _extension_flag = r.read_bit()?; |
| 100 | 101 | if channel_config == 0 { |
| 101 | - let pce = parse_program_config(&mut r)?; | |
| 102 | - channel_config = 0; | |
| 103 | - sf_index = pce.sf_index; | |
| 104 | - rate = sample_rate_for_index(pce.sf_index); | |
| 105 | - return Ok(AudioSpecificConfig { | |
| 106 | - object_type: object, | |
| 107 | - sample_rate: rate, | |
| 108 | - sf_index, | |
| 109 | - channels: pce.channels, | |
| 110 | - channel_config, | |
| 111 | - sbr_present: false, | |
| 112 | - ps_present: false, | |
| 113 | - extension_sample_rate: None, | |
| 114 | - pce: pce.elements, | |
| 115 | - }); | |
| 102 | + let parsed = parse_program_config(&mut r)?; | |
| 103 | + sf_index = parsed.sf_index; | |
| 104 | + rate = sample_rate_for_index(parsed.sf_index); | |
| 105 | + program = Some(parsed); | |
| 116 | 106 | } |
| 117 | 107 | // A backward-compatible SBR signal rides in a sync extension at the end. |
| 118 | 108 | if r.bits_remaining() >= 16 && r.read_bits(11)? == 0x2B7 { |
| @@ -124,19 +114,23 @@ pub fn parse_audio_specific_config(data: &[u8]) -> Result<AudioSpecificConfig> { | ||
| 124 | 114 | } |
| 125 | 115 | } |
| 126 | 116 | } |
| 127 | - if rate == 0 { | |
| 117 | + if program.is_none() && rate == 0 { | |
| 128 | 118 | return Err(Error::corrupt("aac: reserved samplingFrequencyIndex")); |
| 129 | 119 | } |
| 120 | + let (channels, pce) = match program { | |
| 121 | + Some(parsed) => (parsed.channels, parsed.elements), | |
| 122 | + None => (channels_for_config(channel_config), Vec::new()), | |
| 123 | + }; | |
| 130 | 124 | Ok(AudioSpecificConfig { |
| 131 | 125 | object_type: object, |
| 132 | 126 | sample_rate: rate, |
| 133 | 127 | sf_index, |
| 134 | - channels: channels_for_config(channel_config), | |
| 128 | + channels, | |
| 135 | 129 | channel_config, |
| 136 | 130 | sbr_present: sbr, |
| 137 | 131 | ps_present: ps, |
| 138 | 132 | extension_sample_rate: ext_rate, |
| 139 | - pce: Vec::new(), | |
| 133 | + pce, | |
| 140 | 134 | }) |
| 141 | 135 | } |
| 142 | 136 |
crates/ec-aac/tests/it/multichannel_parity.rsmodified+7 -0
| @@ -278,6 +278,10 @@ fn matrix(ours: &[Vec<f32>], theirs: &[Vec<f32>], lag: i64) -> Vec<Vec<f64>> { | ||
| 278 | 278 | .collect() |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | +fn adts_refused(encoder: &str, channels: usize, container: Container) -> bool { | |
| 282 | + matches!(container, Container::Adts) && encoder == "aac" && channels > 7 | |
| 283 | +} | |
| 284 | + | |
| 281 | 285 | fn check_case(layout: &Layout, encoder: &str, container: Container, failures: &mut Vec<String>) { |
| 282 | 286 | let label = format!("{:<6} {:<5} {:<10}", layout.name, container.label(), encoder); |
| 283 | 287 | let path = encode(layout, encoder, container); |
| @@ -340,6 +344,9 @@ fn multichannel_matches_ffmpeg_per_channel() { | ||
| 340 | 344 | for encoder in ENCODERS { |
| 341 | 345 | for layout in LAYOUTS { |
| 342 | 346 | for container in [Container::Adts, Container::Mp4] { |
| 347 | + if adts_refused(encoder, layout.channels, container) { | |
| 348 | + continue; | |
| 349 | + } | |
| 343 | 350 | check_case(layout, encoder, container, &mut failures); |
| 344 | 351 | } |
| 345 | 352 | } |
scripts/fixtures.d/audio.shmodified+11 -1
| @@ -1,4 +1,4 @@ | ||
| 1 | -FREQS=(220 440 660 55 880 1320) | |
| 1 | +FREQS=(220 440 660 55 880 1320 990 1100) | |
| 2 | 2 | LAYOUTS=("mono|1" "stereo|2" "5.1|6") |
| 3 | 3 | RATES=(44100 48000) |
| 4 | 4 | AUDIO_CODECS=( |
| @@ -28,7 +28,11 @@ build_audio_in() { | ||
| 28 | 28 | case $nch in |
| 29 | 29 | 1) layout=mono ;; |
| 30 | 30 | 2) layout=stereo ;; |
| 31 | + 3) layout=3.0 ;; | |
| 32 | + 4) layout=4.0 ;; | |
| 33 | + 5) layout=5.0 ;; | |
| 31 | 34 | 6) layout=5.1 ;; |
| 35 | + 8) layout=7.1 ;; | |
| 32 | 36 | esac |
| 33 | 37 | for ((i = 0; i < nch; i++)); do expr+="0.125*sin(2*PI*${FREQS[i]}*t)|"; done |
| 34 | 38 | AIN=(-f lavfi -i "aevalsrc=${expr%|}:s=${rate}:d=3:c=${layout}") |
| @@ -68,6 +72,12 @@ fam_audio() { | ||
| 68 | 72 | mk audio/alac24-mp4-${lname}-48000.m4a "${AIN[@]}" "${AMAP[@]}" -c:a alac -sample_fmt s32p $T1 -ar 48000 |
| 69 | 73 | done |
| 70 | 74 | |
| 75 | + for lspec in "3.0|3" "4.0|4" "5.0|5" "7.1|8"; do | |
| 76 | + IFS='|' read -r lname nch <<<"$lspec" | |
| 77 | + build_audio_in "$nch" 48000 | |
| 78 | + mk audio/flac-${lname}-48000.flac "${AIN[@]}" "${AMAP[@]}" -c:a flac $T1 -ar 48000 | |
| 79 | + done | |
| 80 | + | |
| 71 | 81 | for spec in "${AAC_TOOL_VARIANTS[@]}"; do |
| 72 | 82 | IFS='|' read -r vname vargs <<<"$spec" |
| 73 | 83 | read -r -a VARGS <<<"$vargs" |