mirror of
https://github.com/androidx/media.git
synced 2025-05-14 02:59:52 +08:00
Throw ParserException if AAC config is invalid
Issue:#8295 PiperOrigin-RevId: 346064966
This commit is contained in:
parent
0501d47144
commit
dd782ef9b4
@ -18,7 +18,6 @@ package com.google.android.exoplayer2.audio;
|
|||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.ParserException;
|
import com.google.android.exoplayer2.ParserException;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.ParsableBitArray;
|
import com.google.android.exoplayer2.util.ParsableBitArray;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
@ -173,7 +172,8 @@ public final class AacUtil {
|
|||||||
*
|
*
|
||||||
* @param audioSpecificConfig A byte array containing the AudioSpecificConfig to parse.
|
* @param audioSpecificConfig A byte array containing the AudioSpecificConfig to parse.
|
||||||
* @return The parsed configuration.
|
* @return The parsed configuration.
|
||||||
* @throws ParserException If the AudioSpecificConfig cannot be parsed as it's not supported.
|
* @throws ParserException If the AudioSpecificConfig cannot be parsed because it is invalid or
|
||||||
|
* unsupported.
|
||||||
*/
|
*/
|
||||||
public static Config parseAudioSpecificConfig(byte[] audioSpecificConfig) throws ParserException {
|
public static Config parseAudioSpecificConfig(byte[] audioSpecificConfig) throws ParserException {
|
||||||
return parseAudioSpecificConfig(
|
return parseAudioSpecificConfig(
|
||||||
@ -188,7 +188,8 @@ public final class AacUtil {
|
|||||||
* @param forceReadToEnd Whether the entire AudioSpecificConfig should be read. Required for
|
* @param forceReadToEnd Whether the entire AudioSpecificConfig should be read. Required for
|
||||||
* knowing the length of the configuration payload.
|
* knowing the length of the configuration payload.
|
||||||
* @return The parsed configuration.
|
* @return The parsed configuration.
|
||||||
* @throws ParserException If the AudioSpecificConfig cannot be parsed as it's not supported.
|
* @throws ParserException If the AudioSpecificConfig cannot be parsed because it is invalid or
|
||||||
|
* unsupported.
|
||||||
*/
|
*/
|
||||||
public static Config parseAudioSpecificConfig(ParsableBitArray bitArray, boolean forceReadToEnd)
|
public static Config parseAudioSpecificConfig(ParsableBitArray bitArray, boolean forceReadToEnd)
|
||||||
throws ParserException {
|
throws ParserException {
|
||||||
@ -248,7 +249,9 @@ public final class AacUtil {
|
|||||||
}
|
}
|
||||||
// For supported containers, bits_to_decode() is always 0.
|
// For supported containers, bits_to_decode() is always 0.
|
||||||
int channelCount = AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE[channelConfiguration];
|
int channelCount = AUDIO_SPECIFIC_CONFIG_CHANNEL_COUNT_TABLE[channelConfiguration];
|
||||||
Assertions.checkArgument(channelCount != AUDIO_SPECIFIC_CONFIG_CHANNEL_CONFIGURATION_INVALID);
|
if (channelCount == AUDIO_SPECIFIC_CONFIG_CHANNEL_CONFIGURATION_INVALID) {
|
||||||
|
throw new ParserException();
|
||||||
|
}
|
||||||
return new Config(sampleRateHz, channelCount, codecs);
|
return new Config(sampleRateHz, channelCount, codecs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,15 +339,17 @@ public final class AacUtil {
|
|||||||
*
|
*
|
||||||
* @param bitArray The bit array containing the audio specific configuration.
|
* @param bitArray The bit array containing the audio specific configuration.
|
||||||
* @return The sampling frequency.
|
* @return The sampling frequency.
|
||||||
|
* @throws ParserException If the audio specific configuration is invalid.
|
||||||
*/
|
*/
|
||||||
private static int getSamplingFrequency(ParsableBitArray bitArray) {
|
private static int getSamplingFrequency(ParsableBitArray bitArray) throws ParserException {
|
||||||
int samplingFrequency;
|
int samplingFrequency;
|
||||||
int frequencyIndex = bitArray.readBits(4);
|
int frequencyIndex = bitArray.readBits(4);
|
||||||
if (frequencyIndex == AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY) {
|
if (frequencyIndex == AUDIO_SPECIFIC_CONFIG_FREQUENCY_INDEX_ARBITRARY) {
|
||||||
samplingFrequency = bitArray.readBits(24);
|
samplingFrequency = bitArray.readBits(24);
|
||||||
} else {
|
} else if (frequencyIndex < 13) {
|
||||||
Assertions.checkArgument(frequencyIndex < 13);
|
|
||||||
samplingFrequency = AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[frequencyIndex];
|
samplingFrequency = AUDIO_SPECIFIC_CONFIG_SAMPLING_RATE_TABLE[frequencyIndex];
|
||||||
|
} else {
|
||||||
|
throw new ParserException();
|
||||||
}
|
}
|
||||||
return samplingFrequency;
|
return samplingFrequency;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user