Commit 273d68ac by aquilescanta Committed by Ian Baker

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
parent bffb68b2
...@@ -119,6 +119,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -119,6 +119,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
case STATE_READ_PAYLOAD: case STATE_READ_PAYLOAD:
castNonNull(oggSeeker); castNonNull(oggSeeker);
return readPayload(input, seekPosition); return readPayload(input, seekPosition);
case STATE_END_OF_INPUT:
return C.RESULT_END_OF_INPUT;
default: default:
// Never happens. // Never happens.
throw new IllegalStateException(); throw new IllegalStateException();
......
...@@ -16,11 +16,15 @@ ...@@ -16,11 +16,15 @@
package com.google.android.exoplayer2.extractor.ogg; package com.google.android.exoplayer2.extractor.ogg;
import static com.google.android.exoplayer2.testutil.TestUtil.getByteArray; 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.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4; 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.ExtractorAsserts;
import com.google.android.exoplayer2.testutil.FakeExtractorInput; import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeExtractorOutput;
import java.io.IOException; import java.io.IOException;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
...@@ -35,6 +39,19 @@ import org.junit.runner.RunWith; ...@@ -35,6 +39,19 @@ import org.junit.runner.RunWith;
public final class OggExtractorNonParameterizedTest { public final class OggExtractorNonParameterizedTest {
@Test @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 { public void sniffVorbis() throws Exception {
byte[] data = byte[] data =
getByteArray(ApplicationProvider.getApplicationContext(), "media/ogg/vorbis_header"); getByteArray(ApplicationProvider.getApplicationContext(), "media/ogg/vorbis_header");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment