Add missing switch case

Before this change, calling read after reaching the end of input in an Ogg file
would cause an IllegalStateException.

PiperOrigin-RevId: 364758873
This commit is contained in:
aquilescanta 2021-03-24 09:52:46 +00:00 committed by Ian Baker
parent bffb68b23b
commit 273d68accd
2 changed files with 19 additions and 0 deletions

View File

@ -119,6 +119,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
case STATE_READ_PAYLOAD:
castNonNull(oggSeeker);
return readPayload(input, seekPosition);
case STATE_END_OF_INPUT:
return C.RESULT_END_OF_INPUT;
default:
// Never happens.
throw new IllegalStateException();

View File

@ -16,11 +16,15 @@
package com.google.android.exoplayer2.extractor.ogg;
import static com.google.android.exoplayer2.testutil.TestUtil.getByteArray;
import static com.google.common.truth.Truth.assertThat;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.PositionHolder;
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeExtractorOutput;
import java.io.IOException;
import org.junit.Test;
import org.junit.runner.RunWith;
@ -34,6 +38,19 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public final class OggExtractorNonParameterizedTest {
@Test
public void read_afterEndOfInput_doesNotThrowIllegalState() throws Exception {
byte[] data =
getByteArray(ApplicationProvider.getApplicationContext(), "media/ogg/bear_flac.ogg");
FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
OggExtractor oggExtractor = new OggExtractor();
oggExtractor.init(new FakeExtractorOutput());
// We feed data to the extractor until the end of input is reached.
while (oggExtractor.read(input, new PositionHolder()) != C.RESULT_END_OF_INPUT) {}
// We call read again to check that it does not throw an IllegalStateException.
assertThat(oggExtractor.read(input, new PositionHolder())).isEqualTo(C.RESULT_END_OF_INPUT);
}
@Test
public void sniffVorbis() throws Exception {
byte[] data =