Search in sources :

Example 1 with SimulatedIOException

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

the class VarintReaderTest method testReadVarintFlaky.

private static void testReadVarintFlaky(VarintReader reader, boolean removeMask, byte[] data, int expectedLength, long expectedValue) throws IOException, InterruptedException {
    ExtractorInput input = new FakeExtractorInput.Builder().setData(data).setSimulateUnknownLength(true).setSimulateIOErrors(true).setSimulatePartialReads(true).build();
    long result = -1;
    while (result == -1) {
        try {
            result = reader.readUnsignedVarint(input, false, removeMask, 8);
            if (result == C.RESULT_END_OF_INPUT || result == C.RESULT_MAX_LENGTH_EXCEEDED) {
                // Unexpected.
                fail();
            }
        } catch (SimulatedIOException e) {
        // Expected.
        }
    }
    assertEquals(expectedLength, input.getPosition());
    assertEquals(expectedValue, result);
}
Also used : FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) ExtractorInput(com.google.android.exoplayer2.extractor.ExtractorInput) FakeExtractorInput(com.google.android.exoplayer2.testutil.FakeExtractorInput) SimulatedIOException(com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException)

Example 2 with SimulatedIOException

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

Aggregations

SimulatedIOException (com.google.android.exoplayer2.testutil.FakeExtractorInput.SimulatedIOException)2 ExtractorInput (com.google.android.exoplayer2.extractor.ExtractorInput)1 PositionHolder (com.google.android.exoplayer2.extractor.PositionHolder)1 FakeExtractorInput (com.google.android.exoplayer2.testutil.FakeExtractorInput)1