Search in sources :

Example 11 with PsExtractor

use of com.google.android.exoplayer2.extractor.ts.PsExtractor 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 12 with PsExtractor

use of com.google.android.exoplayer2.extractor.ts.PsExtractor 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)

Aggregations

SeekMap (com.google.android.exoplayer2.extractor.SeekMap)8 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)7 Test (org.junit.Test)7 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)6 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)4 DefaultExtractorInput (com.google.android.exoplayer2.extractor.DefaultExtractorInput)3 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)3 Nullable (androidx.annotation.Nullable)1 AmrExtractor (com.google.android.exoplayer2.extractor.amr.AmrExtractor)1 FlacExtractor (com.google.android.exoplayer2.extractor.flac.FlacExtractor)1 FlvExtractor (com.google.android.exoplayer2.extractor.flv.FlvExtractor)1 JpegExtractor (com.google.android.exoplayer2.extractor.jpeg.JpegExtractor)1 MatroskaExtractor (com.google.android.exoplayer2.extractor.mkv.MatroskaExtractor)1 Mp3Extractor (com.google.android.exoplayer2.extractor.mp3.Mp3Extractor)1 FragmentedMp4Extractor (com.google.android.exoplayer2.extractor.mp4.FragmentedMp4Extractor)1 Mp4Extractor (com.google.android.exoplayer2.extractor.mp4.Mp4Extractor)1 OggExtractor (com.google.android.exoplayer2.extractor.ogg.OggExtractor)1 Ac3Extractor (com.google.android.exoplayer2.extractor.ts.Ac3Extractor)1 Ac4Extractor (com.google.android.exoplayer2.extractor.ts.Ac4Extractor)1 AdtsExtractor (com.google.android.exoplayer2.extractor.ts.AdtsExtractor)1