Search in sources :

Example 11 with SeekMap

use of androidx.media3.extractor.SeekMap in project ExoPlayer by google.

the class AdtsExtractorSeekTest method seeking_handlesRandomSeeks_extractsCorrectSamples.

@Test
public void seeking_handlesRandomSeeks_extractsCorrectSamples() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long numSeek = 100;
    for (long i = 0; i < numSeek; i++) {
        long targetSeekTimeUs = random.nextInt(FILE_DURATION_US + 1);
        int extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
        assertThat(extractedSampleIndex).isNotEqualTo(-1);
        assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
    }
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 12 with SeekMap

use of androidx.media3.extractor.SeekMap in project ExoPlayer by google.

the class AdtsExtractorSeekTest method seeking_handlesSeekingToPositionInFile_extractsCorrectSample.

@Test
public void seeking_handlesSeekingToPositionInFile_extractsCorrectSample() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = 980_000;
    int extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedSampleIndex).isNotEqualTo(-1);
    assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 13 with SeekMap

use of androidx.media3.extractor.SeekMap in project ExoPlayer by google.

the class AdtsExtractorSeekTest method seeking_handlesSeekToEoF_extractsLastSample.

@Test
public void seeking_handlesSeekToEoF_extractsLastSample() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = seekMap.getDurationUs();
    int extractedSampleIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedSampleIndex).isNotEqualTo(-1);
    assertFirstSampleAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedSampleIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 14 with SeekMap

use of androidx.media3.extractor.SeekMap in project ExoPlayer by google.

the class ConstantBitrateSeekerTest method seeking_handlesSeekingForward.

@Test
public void seeking_handlesSeekingForward() throws IOException {
    String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 987_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 1_234_000;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekIsExactFrame(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Example 15 with SeekMap

use of androidx.media3.extractor.SeekMap in project ExoPlayer by google.

the class ConstantBitrateSeekerTest method seeking_handlesSeekToZero.

@Test
public void seeking_handlesSeekToZero() throws IOException {
    String fileName = CONSTANT_FRAME_SIZE_TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long targetSeekTimeUs = 0;
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(C.INDEX_UNSET);
    assertFirstFrameAfterSeekIsExactFrame(fileName, trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)142 Uri (android.net.Uri)126 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)85 SeekMap (androidx.media3.extractor.SeekMap)76 FakeTrackOutput (androidx.media3.test.utils.FakeTrackOutput)56 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)56 FakeExtractorOutput (androidx.media3.test.utils.FakeExtractorOutput)33 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)33 Nullable (androidx.annotation.Nullable)6 DefaultExtractorInput (androidx.media3.extractor.DefaultExtractorInput)4 ExtractorInput (androidx.media3.extractor.ExtractorInput)4 PositionHolder (androidx.media3.extractor.PositionHolder)3 IOException (java.io.IOException)3 FakeExtractorInput (androidx.media3.test.utils.FakeExtractorInput)2 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)2 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)2 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)2 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)2 Format (androidx.media3.common.Format)1 Metadata (androidx.media3.common.Metadata)1