Search in sources :

Example 6 with ReadDataResult

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

the class TransformerVideoRenderer method ensureConfigured.

/**
 * Attempts to read the input format and to initialize the {@link SamplePipeline}.
 */
@Override
protected boolean ensureConfigured() throws TransformationException {
    if (samplePipeline != null) {
        return true;
    }
    FormatHolder formatHolder = getFormatHolder();
    @ReadDataResult int result = readSource(formatHolder, decoderInputBuffer, /* readFlags= */
    FLAG_REQUIRE_FORMAT);
    if (result != C.RESULT_FORMAT_READ) {
        return false;
    }
    Format inputFormat = checkNotNull(formatHolder.format);
    if (shouldPassthrough(inputFormat)) {
        samplePipeline = new PassthroughSamplePipeline(inputFormat, transformationRequest, fallbackListener);
    } else {
        samplePipeline = new VideoTranscodingSamplePipeline(context, inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener, debugViewProvider);
    }
    if (transformationRequest.flattenForSlowMotion) {
        sefSlowMotionFlattener = new SefSlowMotionFlattener(inputFormat);
    }
    return true;
}
Also used : Format(com.google.android.exoplayer2.Format) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Example 7 with ReadDataResult

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

the class FakeRenderer method render.

@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
    if (isEnded) {
        return;
    }
    playbackPositionUs = positionUs;
    while (true) {
        if (!hasPendingBuffer) {
            FormatHolder formatHolder = getFormatHolder();
            buffer.clear();
            @ReadDataResult int result = readSource(formatHolder, buffer, /* readFlags= */
            0);
            if (result == C.RESULT_FORMAT_READ) {
                DrmSession.replaceSession(currentDrmSession, formatHolder.drmSession);
                currentDrmSession = formatHolder.drmSession;
                Format format = Assertions.checkNotNull(formatHolder.format);
                if (MimeTypes.getTrackType(format.sampleMimeType) != getTrackType()) {
                    throw ExoPlaybackException.createForRenderer(new IllegalStateException(Util.formatInvariant("Format track type (%s) doesn't match renderer track type (%s).", MimeTypes.getTrackType(format.sampleMimeType), getTrackType())), getName(), getIndex(), format, C.FORMAT_UNSUPPORTED_TYPE, /* isRecoverable= */
                    false, PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED);
                }
                formatsRead.add(format);
                onFormatChanged(format);
            } else if (result == C.RESULT_BUFFER_READ) {
                if (buffer.isEndOfStream()) {
                    isEnded = true;
                    return;
                }
                hasPendingBuffer = true;
            } else {
                Assertions.checkState(result == C.RESULT_NOTHING_READ);
                return;
            }
        }
        if (hasPendingBuffer) {
            if (!shouldProcessBuffer(buffer.timeUs, positionUs)) {
                return;
            }
            lastSamplePositionUs = buffer.timeUs;
            sampleBufferReadCount++;
            hasPendingBuffer = false;
        }
    }
}
Also used : Format(com.google.android.exoplayer2.Format) ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Example 8 with ReadDataResult

use of com.google.android.exoplayer2.source.SampleStream.ReadDataResult 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 9 with ReadDataResult

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

the class TransformerBaseRenderer method feedPipelineFromInput.

/**
 * Attempts to read input data and pass the input data to the sample pipeline.
 *
 * @return Whether it may be possible to read more data immediately by calling this method again.
 * @throws TransformationException If a {@link SamplePipeline} problem occurs.
 */
@RequiresNonNull("samplePipeline")
private boolean feedPipelineFromInput() throws TransformationException {
    @Nullable DecoderInputBuffer samplePipelineInputBuffer = samplePipeline.dequeueInputBuffer();
    if (samplePipelineInputBuffer == null) {
        return false;
    }
    @ReadDataResult int result = readSource(getFormatHolder(), samplePipelineInputBuffer, /* readFlags= */
    0);
    switch(result) {
        case C.RESULT_BUFFER_READ:
            samplePipelineInputBuffer.flip();
            if (samplePipelineInputBuffer.isEndOfStream()) {
                samplePipeline.queueInputBuffer();
                return false;
            }
            mediaClock.updateTimeForTrackType(getTrackType(), samplePipelineInputBuffer.timeUs);
            samplePipelineInputBuffer.timeUs -= streamOffsetUs;
            checkStateNotNull(samplePipelineInputBuffer.data);
            maybeQueueSampleToPipeline(samplePipelineInputBuffer);
            return true;
        case C.RESULT_FORMAT_READ:
            throw new IllegalStateException("Format changes are not supported.");
        case C.RESULT_NOTHING_READ:
        default:
            return false;
    }
}
Also used : ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) DecoderInputBuffer(com.google.android.exoplayer2.decoder.DecoderInputBuffer) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 10 with ReadDataResult

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

the class MediaCodecRenderer method bypassRead.

private void bypassRead() throws ExoPlaybackException {
    checkState(!inputStreamEnded);
    FormatHolder formatHolder = getFormatHolder();
    bypassSampleBuffer.clear();
    while (true) {
        bypassSampleBuffer.clear();
        @ReadDataResult int result = readSource(formatHolder, bypassSampleBuffer, /* readFlags= */
        0);
        switch(result) {
            case C.RESULT_FORMAT_READ:
                onInputFormatChanged(formatHolder);
                return;
            case C.RESULT_NOTHING_READ:
                return;
            case C.RESULT_BUFFER_READ:
                if (bypassSampleBuffer.isEndOfStream()) {
                    inputStreamEnded = true;
                    return;
                }
                if (waitingForFirstSampleInFormat) {
                    // This is the first buffer in a new format, the output format must be updated.
                    outputFormat = checkNotNull(inputFormat);
                    onOutputFormatChanged(outputFormat, /* mediaFormat= */
                    null);
                    waitingForFirstSampleInFormat = false;
                }
                // Try to append the buffer to the batch buffer.
                bypassSampleBuffer.flip();
                if (!bypassBatchBuffer.append(bypassSampleBuffer)) {
                    bypassSampleBufferPending = true;
                    return;
                }
                break;
            default:
                throw new IllegalStateException();
        }
    }
}
Also used : ReadDataResult(com.google.android.exoplayer2.source.SampleStream.ReadDataResult) FormatHolder(com.google.android.exoplayer2.FormatHolder)

Aggregations

ReadDataResult (com.google.android.exoplayer2.source.SampleStream.ReadDataResult)11 FormatHolder (com.google.android.exoplayer2.FormatHolder)9 Nullable (androidx.annotation.Nullable)4 Format (com.google.android.exoplayer2.Format)4 DecoderException (com.google.android.exoplayer2.decoder.DecoderException)2 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)1 ArrayList (java.util.ArrayList)1 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)1