diff --git a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacBinarySearchSeekerTest.java b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacBinarySearchSeekerTest.java index a3770afc78..025fdfd209 100644 --- a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacBinarySearchSeekerTest.java +++ b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacBinarySearchSeekerTest.java @@ -25,6 +25,7 @@ import com.google.android.exoplayer2.testutil.FakeExtractorInput; import com.google.android.exoplayer2.testutil.TestUtil; import java.io.IOException; import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; /** Unit test for {@link FlacBinarySearchSeeker}. */ @@ -41,6 +42,7 @@ public final class FlacBinarySearchSeekerTest { } } + @Test public void testGetSeekMap_returnsSeekMapWithCorrectDuration() throws IOException, FlacDecoderException, InterruptedException { byte[] data = @@ -63,6 +65,7 @@ public final class FlacBinarySearchSeekerTest { assertThat(seekMap.isSeekable()).isTrue(); } + @Test public void testSetSeekTargetUs_returnsSeekPending() throws IOException, FlacDecoderException, InterruptedException { byte[] data = diff --git a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorSeekTest.java b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorSeekTest.java index 3beb4d0103..a64a52b411 100644 --- a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorSeekTest.java +++ b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorSeekTest.java @@ -41,6 +41,7 @@ import java.io.IOException; import java.util.List; import java.util.Random; import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; /** Seeking tests for {@link FlacExtractor} when the FLAC stream does not have a SEEKTABLE. */ @@ -76,6 +77,7 @@ public final class FlacExtractorSeekTest { positionHolder = new PositionHolder(); } + @Test public void testFlacExtractorReads_nonSeekTableFile_returnSeekableSeekMap() throws IOException, InterruptedException { FlacExtractor extractor = new FlacExtractor(); @@ -87,6 +89,7 @@ public final class FlacExtractorSeekTest { assertThat(seekMap.isSeekable()).isTrue(); } + @Test public void testHandlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame() throws IOException, InterruptedException { FlacExtractor extractor = new FlacExtractor(); @@ -103,6 +106,7 @@ public final class FlacExtractorSeekTest { trackOutput, targetSeekTimeUs, extractedFrameIndex); } + @Test public void testHandlePendingSeek_handlesSeekToEoF_extractsLastFrame() throws IOException, InterruptedException { FlacExtractor extractor = new FlacExtractor(); @@ -120,6 +124,7 @@ public final class FlacExtractorSeekTest { trackOutput, targetSeekTimeUs, extractedFrameIndex); } + @Test public void testHandlePendingSeek_handlesSeekingBackward_extractsCorrectFrame() throws IOException, InterruptedException { FlacExtractor extractor = new FlacExtractor(); @@ -139,6 +144,7 @@ public final class FlacExtractorSeekTest { trackOutput, targetSeekTimeUs, extractedFrameIndex); } + @Test public void testHandlePendingSeek_handlesSeekingForward_extractsCorrectFrame() throws IOException, InterruptedException { FlacExtractor extractor = new FlacExtractor(); @@ -158,6 +164,7 @@ public final class FlacExtractorSeekTest { trackOutput, targetSeekTimeUs, extractedFrameIndex); } + @Test public void testHandlePendingSeek_handlesRandomSeeks_extractsCorrectFrame() throws IOException, InterruptedException { FlacExtractor extractor = new FlacExtractor(); diff --git a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java index 97f152cea4..c8033e04d3 100644 --- a/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java +++ b/extensions/flac/src/androidTest/java/com/google/android/exoplayer2/ext/flac/FlacExtractorTest.java @@ -21,6 +21,7 @@ import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import com.google.android.exoplayer2.testutil.ExtractorAsserts; import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; /** Unit test for {@link FlacExtractor}. */ @@ -34,11 +35,13 @@ public class FlacExtractorTest { } } + @Test public void testExtractFlacSample() throws Exception { ExtractorAsserts.assertBehavior( FlacExtractor::new, "bear.flac", ApplicationProvider.getApplicationContext()); } + @Test public void testExtractFlacSampleWithId3Header() throws Exception { ExtractorAsserts.assertBehavior( FlacExtractor::new, "bear_with_id3.flac", ApplicationProvider.getApplicationContext()); diff --git a/extensions/flac/src/main/jni/flac_parser.cc b/extensions/flac/src/main/jni/flac_parser.cc index 0ddb93dbe6..b920560f3a 100644 --- a/extensions/flac/src/main/jni/flac_parser.cc +++ b/extensions/flac/src/main/jni/flac_parser.cc @@ -456,6 +456,9 @@ bool FLACParser::getSeekPositions(int64_t timeUs, for (unsigned i = length; i != 0; i--) { int64_t sampleNumber = points[i - 1].sample_number; + if (sampleNumber == -1) { // placeholder + continue; + } if (sampleNumber <= targetSampleNumber) { result[0] = (sampleNumber * 1000000LL) / sampleRate; result[1] = firstFrameOffset + points[i - 1].stream_offset;