mirror of
https://github.com/androidx/media.git
synced 2025-05-17 12:39:52 +08:00
Fix FLAC extension tests
- Add @Test annotations. - Fix seeking to ignore potential placeholders (see https://xiph.org/flac/format.html#metadata_block_seektable). PiperOrigin-RevId: 279074092
This commit is contained in:
parent
6f9baffa0c
commit
29d110b7eb
@ -25,6 +25,7 @@ import com.google.android.exoplayer2.testutil.FakeExtractorInput;
|
|||||||
import com.google.android.exoplayer2.testutil.TestUtil;
|
import com.google.android.exoplayer2.testutil.TestUtil;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
/** Unit test for {@link FlacBinarySearchSeeker}. */
|
/** Unit test for {@link FlacBinarySearchSeeker}. */
|
||||||
@ -41,6 +42,7 @@ public final class FlacBinarySearchSeekerTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetSeekMap_returnsSeekMapWithCorrectDuration()
|
public void testGetSeekMap_returnsSeekMapWithCorrectDuration()
|
||||||
throws IOException, FlacDecoderException, InterruptedException {
|
throws IOException, FlacDecoderException, InterruptedException {
|
||||||
byte[] data =
|
byte[] data =
|
||||||
@ -63,6 +65,7 @@ public final class FlacBinarySearchSeekerTest {
|
|||||||
assertThat(seekMap.isSeekable()).isTrue();
|
assertThat(seekMap.isSeekable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testSetSeekTargetUs_returnsSeekPending()
|
public void testSetSeekTargetUs_returnsSeekPending()
|
||||||
throws IOException, FlacDecoderException, InterruptedException {
|
throws IOException, FlacDecoderException, InterruptedException {
|
||||||
byte[] data =
|
byte[] data =
|
||||||
|
@ -41,6 +41,7 @@ import java.io.IOException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
/** Seeking tests for {@link FlacExtractor} when the FLAC stream does not have a SEEKTABLE. */
|
/** 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();
|
positionHolder = new PositionHolder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testFlacExtractorReads_nonSeekTableFile_returnSeekableSeekMap()
|
public void testFlacExtractorReads_nonSeekTableFile_returnSeekableSeekMap()
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
FlacExtractor extractor = new FlacExtractor();
|
FlacExtractor extractor = new FlacExtractor();
|
||||||
@ -87,6 +89,7 @@ public final class FlacExtractorSeekTest {
|
|||||||
assertThat(seekMap.isSeekable()).isTrue();
|
assertThat(seekMap.isSeekable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame()
|
public void testHandlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame()
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
FlacExtractor extractor = new FlacExtractor();
|
FlacExtractor extractor = new FlacExtractor();
|
||||||
@ -103,6 +106,7 @@ public final class FlacExtractorSeekTest {
|
|||||||
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandlePendingSeek_handlesSeekToEoF_extractsLastFrame()
|
public void testHandlePendingSeek_handlesSeekToEoF_extractsLastFrame()
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
FlacExtractor extractor = new FlacExtractor();
|
FlacExtractor extractor = new FlacExtractor();
|
||||||
@ -120,6 +124,7 @@ public final class FlacExtractorSeekTest {
|
|||||||
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandlePendingSeek_handlesSeekingBackward_extractsCorrectFrame()
|
public void testHandlePendingSeek_handlesSeekingBackward_extractsCorrectFrame()
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
FlacExtractor extractor = new FlacExtractor();
|
FlacExtractor extractor = new FlacExtractor();
|
||||||
@ -139,6 +144,7 @@ public final class FlacExtractorSeekTest {
|
|||||||
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandlePendingSeek_handlesSeekingForward_extractsCorrectFrame()
|
public void testHandlePendingSeek_handlesSeekingForward_extractsCorrectFrame()
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
FlacExtractor extractor = new FlacExtractor();
|
FlacExtractor extractor = new FlacExtractor();
|
||||||
@ -158,6 +164,7 @@ public final class FlacExtractorSeekTest {
|
|||||||
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
trackOutput, targetSeekTimeUs, extractedFrameIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testHandlePendingSeek_handlesRandomSeeks_extractsCorrectFrame()
|
public void testHandlePendingSeek_handlesRandomSeeks_extractsCorrectFrame()
|
||||||
throws IOException, InterruptedException {
|
throws IOException, InterruptedException {
|
||||||
FlacExtractor extractor = new FlacExtractor();
|
FlacExtractor extractor = new FlacExtractor();
|
||||||
|
@ -21,6 +21,7 @@ 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.testutil.ExtractorAsserts;
|
import com.google.android.exoplayer2.testutil.ExtractorAsserts;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
/** Unit test for {@link FlacExtractor}. */
|
/** Unit test for {@link FlacExtractor}. */
|
||||||
@ -34,11 +35,13 @@ public class FlacExtractorTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExtractFlacSample() throws Exception {
|
public void testExtractFlacSample() throws Exception {
|
||||||
ExtractorAsserts.assertBehavior(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new, "bear.flac", ApplicationProvider.getApplicationContext());
|
FlacExtractor::new, "bear.flac", ApplicationProvider.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testExtractFlacSampleWithId3Header() throws Exception {
|
public void testExtractFlacSampleWithId3Header() throws Exception {
|
||||||
ExtractorAsserts.assertBehavior(
|
ExtractorAsserts.assertBehavior(
|
||||||
FlacExtractor::new, "bear_with_id3.flac", ApplicationProvider.getApplicationContext());
|
FlacExtractor::new, "bear_with_id3.flac", ApplicationProvider.getApplicationContext());
|
||||||
|
@ -456,6 +456,9 @@ bool FLACParser::getSeekPositions(int64_t timeUs,
|
|||||||
|
|
||||||
for (unsigned i = length; i != 0; i--) {
|
for (unsigned i = length; i != 0; i--) {
|
||||||
int64_t sampleNumber = points[i - 1].sample_number;
|
int64_t sampleNumber = points[i - 1].sample_number;
|
||||||
|
if (sampleNumber == -1) { // placeholder
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (sampleNumber <= targetSampleNumber) {
|
if (sampleNumber <= targetSampleNumber) {
|
||||||
result[0] = (sampleNumber * 1000000LL) / sampleRate;
|
result[0] = (sampleNumber * 1000000LL) / sampleRate;
|
||||||
result[1] = firstFrameOffset + points[i - 1].stream_offset;
|
result[1] = firstFrameOffset + points[i - 1].stream_offset;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user