Search in sources :

Example 41 with FakeExtractorOutput

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

the class TestUtil method extractSeekMap.

/**
 * Reads from the given input using the given {@link Extractor}, until it can produce the {@link
 * SeekMap} and all of the track formats have been identified, or until the extractor encounters
 * EOF.
 *
 * @param extractor The {@link Extractor} to extractor from input.
 * @param output The {@link FakeTrackOutput} to store the extracted {@link SeekMap} and track.
 * @param dataSource The {@link DataSource} that will be used to read from the input.
 * @param uri The Uri of the input.
 * @return The extracted {@link SeekMap}.
 * @throws IOException If an error occurred reading from the input, or if the extractor finishes
 *     reading from input without extracting any {@link SeekMap}.
 */
public static SeekMap extractSeekMap(Extractor extractor, FakeExtractorOutput output, DataSource dataSource, Uri uri) throws IOException {
    ExtractorInput input = getExtractorInputFromPosition(dataSource, /* position= */
    0, uri);
    extractor.init(output);
    PositionHolder positionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (true) {
        try {
            // Keep reading until we get the seek map and the track information.
            while (readResult == Extractor.RESULT_CONTINUE && (output.seekMap == null || !output.tracksEnded)) {
                readResult = extractor.read(input, positionHolder);
            }
            for (int i = 0; i < output.trackOutputs.size(); i++) {
                int trackId = output.trackOutputs.keyAt(i);
                while (readResult == Extractor.RESULT_CONTINUE && output.trackOutputs.get(trackId).lastFormat == null) {
                    readResult = extractor.read(input, positionHolder);
                }
            }
        } finally {
            DataSourceUtil.closeQuietly(dataSource);
        }
        if (readResult == Extractor.RESULT_SEEK) {
            input = getExtractorInputFromPosition(dataSource, positionHolder.position, uri);
            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) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) IOException(java.io.IOException)

Example 42 with FakeExtractorOutput

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

the class PsExtractorSeekTest method handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingBackward_extractsCorrectFrame() throws IOException {
    PsExtractor extractor = new PsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = extractSeekMapAndTracks(extractor, extractorOutput);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(VIDEO_TRACK_ID);
    long firstSeekTimeUs = 987_000;
    seekToTimeUs(extractor, seekMap, firstSeekTimeUs, trackOutput);
    long targetSeekTimeUs = 0;
    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 43 with FakeExtractorOutput

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

the class PsExtractorSeekTest method readInputFileOnce.

private void readInputFileOnce(PsExtractor extractor, FakeExtractorOutput extractorOutput) throws IOException {
    extractor.init(extractorOutput);
    int readResult = Extractor.RESULT_CONTINUE;
    ExtractorInput input = getExtractorInputFromPosition(0);
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        try {
            while (readResult == Extractor.RESULT_CONTINUE) {
                readResult = extractor.read(input, positionHolder);
            }
        } finally {
            DataSourceUtil.closeQuietly(dataSource);
        }
        if (readResult == Extractor.RESULT_SEEK) {
            input = getExtractorInputFromPosition(positionHolder.position);
            readResult = Extractor.RESULT_CONTINUE;
        }
    }
}
Also used : ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) DefaultExtractorInput(com.google.android.exoplayer2.extractor.DefaultExtractorInput)

Example 44 with FakeExtractorOutput

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

the class PsExtractorSeekTest method psExtractorReads_nonSeekTableFile_returnSeekableSeekMap.

@Test
public void psExtractorReads_nonSeekTableFile_returnSeekableSeekMap() throws IOException {
    PsExtractor extractor = new PsExtractor();
    SeekMap seekMap = extractSeekMapAndTracks(extractor, new FakeExtractorOutput());
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 45 with FakeExtractorOutput

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

the class PsExtractorSeekTest method handlePendingSeek_handlesSeekToEoF.

@Test
public void handlePendingSeek_handlesSeekToEoF() throws IOException, InterruptedException {
    PsExtractor extractor = new PsExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = extractSeekMapAndTracks(extractor, extractorOutput);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(VIDEO_TRACK_ID);
    long targetSeekTimeUs = seekMap.getDurationUs();
    int extractedFrameIndex = seekToTimeUs(extractor, seekMap, targetSeekTimeUs, trackOutput);
    // Assert that this seek will return a position at end of stream, without any frame.
    assertThat(extractedFrameIndex).isEqualTo(-1);
}
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)

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