Search in sources :

Example 36 with FakeExtractorOutput

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

the class AmrExtractorSeekTest method seeking_handlesSeekingForward_extractsCorrectFrames_forNarrowBandAmr.

@Test
public void seeking_handlesSeekingForward_extractsCorrectFrames_forNarrowBandAmr() throws IOException {
    String fileName = NARROW_BAND_AMR_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAmrExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AmrExtractor extractor = createAmrExtractor();
    FakeExtractorOutput extractorOutput = new FakeExtractorOutput();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, extractorOutput, dataSource, fileUri);
    FakeTrackOutput trackOutput = extractorOutput.trackOutputs.get(0);
    long firstSeekTimeUs = 980_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 1_200_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 37 with FakeExtractorOutput

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

the class OggExtractorNonParameterizedTest method read_afterEndOfInput_doesNotThrowIllegalState.

@Test
public void read_afterEndOfInput_doesNotThrowIllegalState() throws Exception {
    byte[] data = getByteArray(ApplicationProvider.getApplicationContext(), "media/ogg/bear_flac.ogg");
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
    OggExtractor oggExtractor = new OggExtractor();
    oggExtractor.init(new FakeExtractorOutput());
    // We feed data to the extractor until the end of input is reached.
    while (oggExtractor.read(input, new PositionHolder()) != C.RESULT_END_OF_INPUT) {
    }
    // We call read again to check that it does not throw an IllegalStateException.
    assertThat(oggExtractor.read(input, new PositionHolder())).isEqualTo(C.RESULT_END_OF_INPUT);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 38 with FakeExtractorOutput

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

the class AdtsExtractorSeekTest method seeking_handlesSeekingBackward_extractsCorrectSamples.

@Test
public void seeking_handlesSeekingBackward_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 firstSeekTimeUs = 980_000;
    TestUtil.seekToTimeUs(extractor, seekMap, firstSeekTimeUs, dataSource, trackOutput, fileUri);
    long targetSeekTimeUs = 0;
    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 39 with FakeExtractorOutput

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

the class AdtsExtractorSeekTest method adtsExtractorReads_returnSeekableSeekMap.

@Test
public void adtsExtractorReads_returnSeekableSeekMap() throws IOException {
    String fileName = TEST_FILE;
    Uri fileUri = TestUtil.buildAssetUri(fileName);
    expectedTrackOutput = TestUtil.extractAllSamplesFromFile(createAdtsExtractor(), ApplicationProvider.getApplicationContext(), fileName).trackOutputs.get(0);
    AdtsExtractor extractor = createAdtsExtractor();
    SeekMap seekMap = TestUtil.extractSeekMap(extractor, new FakeExtractorOutput(), dataSource, fileUri);
    assertThat(seekMap).isNotNull();
    assertThat(seekMap.getDurationUs()).isEqualTo(FILE_DURATION_US);
    assertThat(seekMap.isSeekable()).isTrue();
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap) Uri(android.net.Uri) FakeExtractorOutput(com.google.android.exoplayer2.testutil.FakeExtractorOutput) Test(org.junit.Test)

Example 40 with FakeExtractorOutput

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

the class ExtractorAsserts method assertOutput.

/**
 * Asserts that an extractor consumes valid input data successfully under the specified
 * conditions.
 *
 * @param extractor The {@link Extractor} to be tested.
 * @param dumpFilesPrefix The dump files prefix prepended to the dump files path.
 * @param data Content of the input file.
 * @param context To be used to load the sample file.
 * @param sniffFirst Whether to sniff the data by calling {@link Extractor#sniff(ExtractorInput)}
 *     prior to consuming it.
 * @param simulateIOErrors Whether to simulate IO errors.
 * @param simulateUnknownLength Whether to simulate unknown input length.
 * @param simulatePartialReads Whether to simulate partial reads.
 * @throws IOException If reading from the input fails.
 */
private static void assertOutput(Extractor extractor, String dumpFilesPrefix, byte[] data, Context context, boolean deduplicateConsecutiveFormats, boolean sniffFirst, boolean simulateIOErrors, boolean simulateUnknownLength, boolean simulatePartialReads) throws IOException {
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).setSimulateIOErrors(simulateIOErrors).setSimulateUnknownLength(simulateUnknownLength).setSimulatePartialReads(simulatePartialReads).build();
    if (sniffFirst) {
        assertSniff(extractor, input, /* expectedResult= */
        true);
        input.resetPeekPosition();
    }
    FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, 0, true, deduplicateConsecutiveFormats);
    if (simulateUnknownLength) {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
    } else {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + ".0" + DUMP_EXTENSION);
    }
    // Seeking to (timeUs=0, position=0) should always work, and cause the same data to be output.
    extractorOutput.clearTrackOutputs();
    input.reset();
    consumeTestData(extractor, input, /* timeUs= */
    0, extractorOutput, false);
    if (simulateUnknownLength) {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
    } else {
        DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + ".0" + DUMP_EXTENSION);
    }
    SeekMap seekMap = Assertions.checkNotNull(extractorOutput.seekMap);
    long durationUs = seekMap.getDurationUs();
    // Only seek to the timeUs=0 if the SeekMap is unseekable or the duration is unknown.
    int numberSeekTests = seekMap.isSeekable() && durationUs != C.TIME_UNSET ? 4 : 1;
    for (int j = 0; j < numberSeekTests; j++) {
        long timeUs = durationUs * j / 3;
        long position = seekMap.getSeekPoints(timeUs).first.position;
        if (timeUs == 0 && position == 0) {
            // Already tested.
            continue;
        }
        input.reset();
        input.setPosition((int) position);
        extractorOutput.clearTrackOutputs();
        consumeTestData(extractor, input, timeUs, extractorOutput, false);
        if (simulateUnknownLength && timeUs == 0) {
            DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + UNKNOWN_LENGTH_EXTENSION);
        } else {
            DumpFileAsserts.assertOutput(context, extractorOutput, dumpFilesPrefix + '.' + j + DUMP_EXTENSION);
        }
    }
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap)

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