Search in sources :

Example 21 with DecoderInputBuffer

use of androidx.media3.decoder.DecoderInputBuffer in project media by androidx.

the class SampleQueueTest method setUp.

@Before
public void setUp() {
    allocator = new DefaultAllocator(false, ALLOCATION_SIZE);
    mockDrmSession = Mockito.mock(DrmSession.class);
    mockDrmSessionManager = new MockDrmSessionManager(mockDrmSession);
    eventDispatcher = new DrmSessionEventListener.EventDispatcher();
    sampleQueue = new SampleQueue(allocator, mockDrmSessionManager, eventDispatcher);
    formatHolder = new FormatHolder();
    inputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
}
Also used : DrmSession(androidx.media3.exoplayer.drm.DrmSession) DecoderInputBuffer(androidx.media3.decoder.DecoderInputBuffer) FormatHolder(androidx.media3.exoplayer.FormatHolder) DefaultAllocator(androidx.media3.exoplayer.upstream.DefaultAllocator) DrmSessionEventListener(androidx.media3.exoplayer.drm.DrmSessionEventListener) Before(org.junit.Before)

Example 22 with DecoderInputBuffer

use of androidx.media3.decoder.DecoderInputBuffer in project media by androidx.

the class TransformerAudioRenderer 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 AudioTranscodingSamplePipeline(inputFormat, transformationRequest, decoderFactory, encoderFactory, muxerWrapper.getSupportedSampleMimeTypes(getTrackType()), fallbackListener);
    }
    return true;
}
Also used : Format(androidx.media3.common.Format) ReadDataResult(androidx.media3.exoplayer.source.SampleStream.ReadDataResult) FormatHolder(androidx.media3.exoplayer.FormatHolder)

Example 23 with DecoderInputBuffer

use of androidx.media3.decoder.DecoderInputBuffer in project media by androidx.

the class TransformerBaseRenderer method feedMuxerFromPipeline.

/**
 * Attempts to write sample pipeline output data to the muxer.
 *
 * @return Whether it may be possible to write more data immediately by calling this method again.
 * @throws Muxer.MuxerException If a muxing problem occurs.
 * @throws TransformationException If a {@link SamplePipeline} problem occurs.
 */
@RequiresNonNull("samplePipeline")
private boolean feedMuxerFromPipeline() throws Muxer.MuxerException, TransformationException {
    if (!muxerWrapperTrackAdded) {
        @Nullable Format samplePipelineOutputFormat = samplePipeline.getOutputFormat();
        if (samplePipelineOutputFormat == null) {
            return false;
        }
        muxerWrapperTrackAdded = true;
        muxerWrapper.addTrackFormat(samplePipelineOutputFormat);
    }
    if (samplePipeline.isEnded()) {
        muxerWrapper.endTrack(getTrackType());
        muxerWrapperTrackEnded = true;
        return false;
    }
    @Nullable DecoderInputBuffer samplePipelineOutputBuffer = samplePipeline.getOutputBuffer();
    if (samplePipelineOutputBuffer == null) {
        return false;
    }
    if (!muxerWrapper.writeSample(getTrackType(), checkStateNotNull(samplePipelineOutputBuffer.data), samplePipelineOutputBuffer.isKeyFrame(), samplePipelineOutputBuffer.timeUs)) {
        return false;
    }
    samplePipeline.releaseOutputBuffer();
    return true;
}
Also used : Format(androidx.media3.common.Format) DecoderInputBuffer(androidx.media3.decoder.DecoderInputBuffer) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 24 with DecoderInputBuffer

use of androidx.media3.decoder.DecoderInputBuffer in project media by androidx.

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(androidx.media3.exoplayer.source.SampleStream.ReadDataResult) DecoderInputBuffer(androidx.media3.decoder.DecoderInputBuffer) Nullable(androidx.annotation.Nullable) RequiresNonNull(org.checkerframework.checker.nullness.qual.RequiresNonNull)

Example 25 with DecoderInputBuffer

use of androidx.media3.decoder.DecoderInputBuffer in project media by androidx.

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(androidx.media3.common.Format) ReadDataResult(androidx.media3.exoplayer.source.SampleStream.ReadDataResult) FormatHolder(androidx.media3.exoplayer.FormatHolder)

Aggregations

Test (org.junit.Test)13 Nullable (androidx.annotation.Nullable)10 EventStream (androidx.media3.exoplayer.dash.manifest.EventStream)9 DecoderInputBuffer (androidx.media3.decoder.DecoderInputBuffer)8 EventMessage (androidx.media3.extractor.metadata.emsg.EventMessage)8 DecoderInputBuffer (com.google.android.exoplayer2.decoder.DecoderInputBuffer)8 Format (androidx.media3.common.Format)6 Before (org.junit.Before)6 FormatHolder (androidx.media3.exoplayer.FormatHolder)5 RequiresNonNull (org.checkerframework.checker.nullness.qual.RequiresNonNull)4 CryptoInfo (androidx.media3.decoder.CryptoInfo)3 ReadDataResult (androidx.media3.exoplayer.source.SampleStream.ReadDataResult)3 FormatHolder (com.google.android.exoplayer2.FormatHolder)3 ByteBuffer (java.nio.ByteBuffer)3 SurfaceTexture (android.graphics.SurfaceTexture)2 Handler (android.os.Handler)2 Surface (android.view.Surface)2 CryptoException (androidx.media3.decoder.CryptoException)2 ExoTrackSelection (androidx.media3.exoplayer.trackselection.ExoTrackSelection)2 FixedTrackSelection (androidx.media3.exoplayer.trackselection.FixedTrackSelection)2