Search in sources :

Example 26 with FakeExtractorOutput

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

the class ExtractorAsserts method consumeTestData.

private static void consumeTestData(Extractor extractor, FakeExtractorInput input, long timeUs, FakeExtractorOutput output, boolean retryFromStartIfLive) throws IOException {
    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;
                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 27 with FakeExtractorOutput

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

use of com.google.android.exoplayer2.testutil.FakeExtractorOutput 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)

Example 29 with FakeExtractorOutput

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

the class TsExtractorTest method testCustomPesReader.

public void testCustomPesReader() throws Exception {
    CustomTsPayloadReaderFactory factory = new CustomTsPayloadReaderFactory(true, false);
    TsExtractor tsExtractor = new TsExtractor(TsExtractor.MODE_NORMAL, new TimestampAdjuster(0), factory);
    FakeExtractorInput input = new FakeExtractorInput.Builder().setData(TestUtil.getByteArray(getInstrumentation(), "ts/sample.ts")).setSimulateIOErrors(false).setSimulateUnknownLength(false).setSimulatePartialReads(false).build();
    FakeExtractorOutput output = new FakeExtractorOutput();
    tsExtractor.init(output);
    PositionHolder seekPositionHolder = new PositionHolder();
    int readResult = Extractor.RESULT_CONTINUE;
    while (readResult != Extractor.RESULT_END_OF_INPUT) {
        readResult = tsExtractor.read(input, seekPositionHolder);
    }
    CustomEsReader reader = factory.esReader;
    assertEquals(2, reader.packetsRead);
    TrackOutput trackOutput = reader.getTrackOutput();
    assertTrue(trackOutput == output.trackOutputs.get(257));
    assertEquals(Format.createTextSampleFormat("1/257", "mime", null, 0, 0, "und", null, 0), ((FakeTrackOutput) trackOutput).format);
}
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) TrackOutput(com.google.android.exoplayer2.extractor.TrackOutput) FakeTrackOutput(com.google.android.exoplayer2.testutil.FakeTrackOutput)

Example 30 with FakeExtractorOutput

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

the class FlvExtractorSeekTest method setUp.

@Before
public void setUp() throws Exception {
    extractor = new FlvExtractor();
    extractorOutput = new FakeExtractorOutput();
    dataSource = new DefaultDataSource.Factory(ApplicationProvider.getApplicationContext()).createDataSource();
}
Also used : 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