ec-aac ASC: a PCE no longer ends the config parse, so the trailing SBR sync extension is read (al_sbr_cm_48_5.1 is HE-AAC per ffprobe; it parsed as no-SBR before)
Browse files at this commitb150de91be885dff7e55f1ff460933b617f49445Parent: be888451 changed file +12 -18
- crates/ec-aac/src/config.rs +12 -18
crates/ec-aac/src/config.rsmodified+12 -18
| @@ -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 { |
| @@ -127,16 +117,20 @@ pub fn parse_audio_specific_config(data: &[u8]) -> Result<AudioSpecificConfig> { | ||
| 127 | 117 | if 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 |