Detect invalid frames early in passthrough/offload

Without checking if getFramesPerEncodedSample fails,
the frame count becomes negative which leads to
hard to debug errors.

PiperOrigin-RevId: 319247618
This commit is contained in:
krocard 2020-07-01 18:13:07 +01:00 committed by Oliver Woodman
parent 541568386b
commit 513b268558

View file

@ -1402,7 +1402,11 @@ public final class DefaultAudioSink implements AudioSink {
switch (encoding) {
case C.ENCODING_MP3:
int headerDataInBigEndian = Util.getBigEndianInt(buffer, buffer.position());
return MpegAudioUtil.parseMpegAudioFrameSampleCount(headerDataInBigEndian);
int frameCount = MpegAudioUtil.parseMpegAudioFrameSampleCount(headerDataInBigEndian);
if (frameCount == C.LENGTH_UNSET) {
throw new IllegalArgumentException();
}
return frameCount;
case C.ENCODING_AAC_LC:
return AacUtil.AAC_LC_AUDIO_SAMPLE_COUNT;
case C.ENCODING_AAC_HE_V1: