Search in sources :

Example 11 with FakeExtractorInput

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

the class OggPacketTest method testParseRealFile.

public void testParseRealFile() throws IOException, InterruptedException {
    byte[] data = TestUtil.getByteArray(getInstrumentation(), TEST_FILE);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(data).build();
    int packetCounter = 0;
    while (readPacket(input)) {
        packetCounter++;
    }
    assertEquals(277, packetCounter);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 12 with FakeExtractorInput

use of com.google.android.exoplayer2.testutil.FakeExtractorInput 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 13 with FakeExtractorInput

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

the class OggPageHeaderTest method testPopulatePageHeaderQuiteOnExceptionLessThan27Bytes.

public void testPopulatePageHeaderQuiteOnExceptionLessThan27Bytes() throws IOException, InterruptedException {
    FakeExtractorInput input = TestData.createInput(TestUtil.createByteArray(2, 2), false);
    OggPageHeader header = new OggPageHeader();
    assertFalse(populatePageHeader(input, header, true));
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput)

Example 14 with FakeExtractorInput

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

the class TestUtil method consumeTestData.

private static void consumeTestData(Extractor extractor, FakeExtractorInput input, long timeUs, FakeExtractorOutput output, boolean retryFromStartIfLive) throws IOException, InterruptedException {
    extractor.seek(input.getPosition(), timeUs);
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        try {
            // Extractor.read should not read seekPositionHolder.position. Set it to a value that's
            // likely to cause test failure if a read does occur.
            seekPositionHolder.position = Long.MIN_VALUE;
            readResult = extractor.read(input, seekPositionHolder);
            if (readResult == Extractor.RESULT_SEEK) {
                long seekPosition = seekPositionHolder.position;
                Assertions.checkState(0 <= seekPosition && seekPosition <= Integer.MAX_VALUE);
                input.setPosition((int) seekPosition);
            }
        } catch (SimulatedIOException e) {
            if (!retryFromStartIfLive) {
                continue;
            }
            boolean isOnDemand = input.getLength() != C.LENGTH_UNSET || (output.seekMap != null && output.seekMap.getDurationUs() != C.TIME_UNSET);
            if (isOnDemand) {
                continue;
            }
            input.setPosition(0);
            for (int i = 0; i < output.numberOfTracks; i++) {
                output.trackOutputs.valueAt(i).clear();
            }
            extractor.seek(0, 0);
        }
    }
}
Also used : SimulatedIOException(com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException) PositionHolder(com.google.android.exoplayer2.extractor.PositionHolder)

Example 15 with FakeExtractorInput

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

the class TestUtil method assertOutput.

/**
   * Asserts that {@code extractor} consumes {@code sampleFile} successfully and its output equals
   * to a prerecorded output dump file with the name {@code sampleFile} + "{@value
   * #DUMP_EXTENSION}". If {@code simulateUnknownLength} is true and {@code sampleFile} + "{@value
   * #UNKNOWN_LENGTH_EXTENSION}" exists, it's preferred.
   *
   * @param extractor The {@link Extractor} to be tested.
   * @param sampleFile The path to the input sample.
   * @param fileData Content of the input file.
   * @param instrumentation To be used to load the sample file.
   * @param simulateIOErrors If true simulates IOErrors.
   * @param simulateUnknownLength If true simulates unknown input length.
   * @param simulatePartialReads If true simulates partial reads.
   * @return The {@link FakeExtractorOutput} used in the test.
   * @throws IOException If reading from the input fails.
   * @throws InterruptedException If interrupted while reading from the input.
   */
public static FakeExtractorOutput assertOutput(Extractor extractor, String sampleFile, byte[] fileData, Instrumentation instrumentation, boolean simulateIOErrors, boolean simulateUnknownLength, boolean simulatePartialReads) throws IOException, InterruptedException {
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(fileData).setSimulateIOErrors(simulateIOErrors).setSimulateUnknownLength(simulateUnknownLength).setSimulatePartialReads(simulatePartialReads).build();
    Assert.assertTrue(sniffTestData(extractor, input));
    input.resetPeekPosition();
    FakeExtractorOutput extractorOutput = consumeTestData(extractor, input, 0, true);
    if (simulateUnknownLength && assetExists(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION)) {
        extractorOutput.assertOutput(instrumentation, sampleFile + UNKNOWN_LENGTH_EXTENSION);
    } else {
        extractorOutput.assertOutput(instrumentation, sampleFile + ".0" + DUMP_EXTENSION);
    }
    SeekMap seekMap = extractorOutput.seekMap;
    if (seekMap.isSeekable()) {
        long durationUs = seekMap.getDurationUs();
        for (int j = 0; j < 4; j++) {
            long timeUs = (durationUs * j) / 3;
            long position = seekMap.getPosition(timeUs);
            input.setPosition((int) position);
            for (int i = 0; i < extractorOutput.numberOfTracks; i++) {
                extractorOutput.trackOutputs.valueAt(i).clear();
            }
            consumeTestData(extractor, input, timeUs, extractorOutput, false);
            extractorOutput.assertOutput(instrumentation, sampleFile + '.' + j + DUMP_EXTENSION);
        }
    }
    return extractorOutput;
}
Also used : SeekMap(com.google.android.exoplayer2.extractor.SeekMap)

Aggregations

FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)24 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)3 FakeExtractorOutput (com.google.android.exoplayer2.testutil.FakeExtractorOutput)2 TimestampAdjuster (com.google.android.exoplayer2.util.TimestampAdjuster)2 EOFException (java.io.EOFException)2 SeekMap (com.google.android.exoplayer2.extractor.SeekMap)1 TrackOutput (com.google.android.exoplayer2.extractor.TrackOutput)1 SimulatedIOException (com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException)1 FakeTrackOutput (com.google.android.exoplayer2.testutil.FakeTrackOutput)1 ParsableByteArray (com.google.android.exoplayer2.util.ParsableByteArray)1