Search in sources :

Example 1 with FakeExtractorOutput

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

the class TsExtractorTest method testCustomInitialSectionReader.

public void testCustomInitialSectionReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(false, true);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_NORMAL, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample_with_sdt.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    tsExtractor.init(new FakeExtractorOutput());
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
    }
    assertEquals(1, factory.sdtReader.consumedSdts);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) TimestampAdjuster(com.google.android.exoplayer2.util.TimestampAdjuster) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput)

Example 2 with FakeExtractorOutput

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

the class PsExtractorSeekTest method handlePendingSeek_handlesSeekingForward_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingForward_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 = 1_234_000;
    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 3 with FakeExtractorOutput

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

the class PsExtractorSeekTest method handlePendingSeek_handlesRandomSeeks_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesRandomSeeks_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 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 4 with FakeExtractorOutput

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

the class PsExtractorSeekTest method handlePendingSeek_handlesSeekingToPositionInFile_extractsCorrectFrame.

@Test
public void handlePendingSeek_handlesSeekingToPositionInFile_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 targetSeekTimeUs = 987_000;
    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 5 with FakeExtractorOutput

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

the class PsExtractorSeekTest method setUp.

@Before
public void setUp() throws IOException {
    expectedOutput = new FakeExtractorOutput();
    positionHolder = new PositionHolder();
    extractAllSamplesFromFileToExpectedOutput(ApplicationProvider.getApplicationContext(), PS_FILE_PATH);
    expectedTrackOutput = expectedOutput.trackOutputs.get(VIDEO_TRACK_ID);
    dataSource = new DefaultDataSource.Factory(ApplicationProvider.getApplicationContext()).createDataSource();
    totalInputLength = readInputLength();
}
Also used : PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Before(org.junit.Before)

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