Search in sources :

Example 46 with FakeExtractorOutput

use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.

the class PsExtractorSeekTest method handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame() throws IOException {
    PsExtractor extractor = new PsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    readInputFileOnce(extractor, extractorOutput);
    SeekMap seekMap = extractorOutput.seekMap;
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(VIDEO_TRACK_ID);
    long numSeek = 100;
    for (long i = 0; i < numSeek; i++) {
        long targetSeekTimeUs = random.nextInt(DURATION_US + 1);
        int extractedFrameIndex = seekToTimeUs(extractor, seekMap, targetSeekTimeUs, trackOutput);
        assertThat(extractedFrameIndex).isNotEqualTo(-1);
        assertFirstFrameAfterSeekContainsTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
    }
}
Also used : FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput) SeekMap(com.google.android.exoplayer2.extractor.SeekMap) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 47 with FakeExtractorOutput

use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.

the class PsExtractorSeekTest method extractSeekMapAndTracks.

private SeekMap extractSeekMapAndTracks(PsExtractor extractor, FakeExtractorOutput output) throws IOException {
    ExtractorInput input = getExtractorInputFromPosition(0);
    extractor.init(output);
    int readResult = Extractor.RESULT_CONTINUE;
    while (true) {
        try {
            // Keep reading until we can get the seek map
            while (readResult == Extractor.RESULT_CONTINUE && (output.seekMap == null || !output.tracksEnded)) {
                readResult = extractor.read(input, positionHolder);
            }
        } finally {
            DataSourceUtil.closeQuietly(dataSource);
        }
        if (readResult == Extractor.RESULT_SEEK) {
            input = getExtractorInputFromPosition(positionHolder.position);
            readResult = Extractor.RESULT_CONTINUE;
        } else if (readResult == Extractor.RESULT_END_OF_INPUT) {
            throw new IOException("EOF encountered without seekmap");
        }
        if (output.seekMap != null) {
            return output.seekMap;
        }
    }
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) IOException(java.io.IOException)

Example 48 with FakeExtractorOutput

use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.

the class TsExtractorSeekTest method handlePendingSeek_handlesSeekingForward_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingForward_extractsCorrectFrame() throws IOException {
    TsExtractor extractor = new TsExtractor();
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(AUDIO_TRACK_ID);
    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(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
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 49 with FakeExtractorOutput

use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.

the class TsExtractorSeekTest method handlePendingSeek_handlesSeekToEoF_extractsLastFrame.

@Test
public void handlePendingSeek_handlesSeekToEoF_extractsLastFrame() throws IOException {
    TsExtractor extractor = new TsExtractor();
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(AUDIO_TRACK_ID);
    long targetSeekTimeUs = seekMap.getDurationUs();
    int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
    assertThat(extractedFrameIndex).isNotEqualTo(-1);
    assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
}
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 50 with FakeExtractorOutput

use of com.google.android.exoplayer2.testutil.FakeExtractorOutput in project ExoPlayer by google.

the class TsExtractorSeekTest method handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesRandomSeeksAfterReadingFileOnce_extractsCorrectFrame() throws IOException {
    TsExtractor extractor = new TsExtractor();
    Uri fileUri = TestUtil.buildAssetUri(TEST_FILE);
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    readInputFileOnce(extractor, extractorOutput, fileUri);
    SeekMap seekMap = extractorOutput.seekMap;
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(AUDIO_TRACK_ID);
    long numSeek = 100;
    for (long i = 0; i < numSeek; i++) {
        long targetSeekTimeUs = random.nextInt(DURATION_US + 1);
        int extractedFrameIndex = TestUtil.seekToTimeUs(extractor, seekMap, targetSeekTimeUs, dataSource, trackOutput, fileUri);
        assertThat(extractedFrameIndex).isNotEqualTo(-1);
        assertFirstFrameAfterSeekContainTargetSeekTime(trackOutput, targetSeekTimeUs, extractedFrameIndex);
    }
}
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)

Aggregations

FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)52 Test (org.junit.Test)43 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)35 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)32 Uri (android.net.Uri)25 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)11 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)10 WebvttDecoder (com.google.android.exoplayer2.text.webvtt.WebvttDecoder)6 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)6 Before (org.junit.Before)6 Format (com.google.android.exoplayer2.Format)4 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)4 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)3 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)2 SimulatedIOException (com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException)2 IOException (java.io.IOException)2 TrackIdGenerator (com.google.android.exoplayer2.extractor.ts.TsPayloadReader.TrackIdGenerator)1 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1