Search in sources :

Example 6 with FLAG_REQUIRE_FORMAT

use of com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT in project ExoPlayer by google.

the class DecoderVideoRenderer method render.

// BaseRenderer implementation.
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
    if (outputStreamEnded) {
        return;
    }
    if (inputFormat == null) {
        // We don't have a format yet, so try and read one.
        FormatHolder formatHolder = getFormatHolder();
        flagsOnlyBuffer.clear();
        @ReadDataResult int result = readSource(formatHolder, flagsOnlyBuffer, FLAG_REQUIRE_FORMAT);
        if (result == C.RESULT_FORMAT_READ) {
            onInputFormatChanged(formatHolder);
        } else if (result == C.RESULT_BUFFER_READ) {
            // End of stream read having not read a format.
            Assertions.checkState(flagsOnlyBuffer.isEndOfStream());
            inputStreamEnded = true;
            outputStreamEnded = true;
            return;
        } else {
            // We still don't have a format and can't make progress without one.
            return;
        }
    }
    // If we don't have a decoder yet, we need to instantiate one.
    maybeInitDecoder();
    if (decoder != null) {
        try {
            // Rendering loop.
            TraceUtil.beginSection("drainAndFeed");
            while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {
            }
            while (feedInputBuffer()) {
            }
            TraceUtil.endSection();
        } catch (DecoderException e) {
            Log.e(TAG, "Video codec error", e);
            eventDispatcher.videoCodecError(e);
            throw createRendererException(e, inputFormat, PlaybackException.ERROR_CODE_DECODING_FAILED);
        }
        decoderCounters.ensureUpdated();
    }
}
Also used : DecoderException(com.google.android.exoplayer2.decoder.DecoderException) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Example 7 with FLAG_REQUIRE_FORMAT

use of com.google.android.exoplayer2.source.SampleStream.FLAG_REQUIRE_FORMAT in project ExoPlayer by google.

the class MediaCodecRenderer method render.

@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
    if (pendingOutputEndOfStream) {
        pendingOutputEndOfStream = false;
        processEndOfStream();
    }
    if (pendingPlaybackException != null) {
        ExoPlaybackException playbackException = pendingPlaybackException;
        pendingPlaybackException = null;
        throw playbackException;
    }
    try {
        if (outputStreamEnded) {
            renderToEndOfStream();
            return;
        }
        if (inputFormat == null && !readSourceOmittingSampleData(FLAG_REQUIRE_FORMAT)) {
            // We still don't have a format and can't make progress without one.
            return;
        }
        // We have a format.
        maybeInitCodecOrBypass();
        if (bypassEnabled) {
            TraceUtil.beginSection("bypassRender");
            while (bypassRender(positionUs, elapsedRealtimeUs)) {
            }
            TraceUtil.endSection();
        } else if (codec != null) {
            long renderStartTimeMs = SystemClock.elapsedRealtime();
            TraceUtil.beginSection("drainAndFeed");
            while (drainOutputBuffer(positionUs, elapsedRealtimeUs) && shouldContinueRendering(renderStartTimeMs)) {
            }
            while (feedInputBuffer() && shouldContinueRendering(renderStartTimeMs)) {
            }
            TraceUtil.endSection();
        } else {
            decoderCounters.skippedInputBufferCount += skipSource(positionUs);
            // We need to read any format changes despite not having a codec so that drmSession can be
            // updated, and so that we have the most recent format should the codec be initialized. We
            // may also reach the end of the stream. FLAG_PEEK is used because we don't want to advance
            // the source further than skipSource has already done.
            readSourceOmittingSampleData(FLAG_PEEK);
        }
        decoderCounters.ensureUpdated();
    } catch (IllegalStateException e) {
        if (isMediaCodecException(e)) {
            onCodecError(e);
            boolean isRecoverable = Util.SDK_INT >= 21 && isRecoverableMediaCodecExceptionV21(e);
            if (isRecoverable) {
                releaseCodec();
            }
            throw createRendererException(createDecoderException(e, getCodecInfo()), inputFormat, isRecoverable, PlaybackException.ERROR_CODE_DECODING_FAILED);
        }
        throw e;
    }
}
Also used : ExoPlaybackException(com.google.android.exoplayer2.ExoPlaybackException)

Aggregations

FormatHolder (com.google.android.exoplayer2.FormatHolder)6 ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)4 Format (com.google.android.exoplayer2.Format)2 DecoderException (com.google.android.exoplayer2.decoder.DecoderException)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)2 ExoTrackSelection (com.google.android.exoplayer2.trackselection.ExoTrackSelection)2 FixedTrackSelection (com.google.android.exoplayer2.trackselection.FixedTrackSelection)2 Test (org.junit.Test)2 ExoPlaybackException (com.google.android.exoplayer2.ExoPlaybackException)1