From b7f0071e8c02e4b19d920ecdd67b4d0429102fa0 Mon Sep 17 00:00:00 2001 From: kimvde Date: Wed, 24 Nov 2021 18:52:55 +0000 Subject: [PATCH] Rename decoderInputFormat in transformer renderers - This format is passed to the PassthroughPipeline, which doesn't use any decoder. - In most other cases where it is used, it is not relevant that this format will be or has been passed to the decoder. What's relevant is that it is the format of the input. PiperOrigin-RevId: 412093371 --- .../transformer/AudioSamplePipeline.java | 23 +++++++------- .../transformer/TransformerAudioRenderer.java | 8 ++--- .../transformer/TransformerVideoRenderer.java | 13 ++++---- .../transformer/VideoSamplePipeline.java | 31 +++++++++---------- 4 files changed, 35 insertions(+), 40 deletions(-) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/AudioSamplePipeline.java b/libraries/transformer/src/main/java/androidx/media3/transformer/AudioSamplePipeline.java index d4510d4df6..76f7d51955 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/AudioSamplePipeline.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/AudioSamplePipeline.java @@ -47,8 +47,11 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; private static final String TAG = "AudioSamplePipeline"; private static final int DEFAULT_ENCODER_BITRATE = 128 * 1024; + private final Format inputFormat; + private final Transformation transformation; + private final int rendererIndex; + private final MediaCodecAdapterWrapper decoder; - private final Format decoderInputFormat; private final DecoderInputBuffer decoderInputBuffer; private final SonicAudioProcessor sonicAudioProcessor; @@ -57,9 +60,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; private final DecoderInputBuffer encoderInputBuffer; private final DecoderInputBuffer encoderOutputBuffer; - private final Transformation transformation; - private final int rendererIndex; - private @MonotonicNonNull AudioFormat encoderInputAudioFormat; private @MonotonicNonNull MediaCodecAdapterWrapper encoder; private long nextEncoderInputBufferTimeUs; @@ -69,10 +69,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; private boolean drainingSonicForSpeedChange; private float currentSpeed; - public AudioSamplePipeline( - Format decoderInputFormat, Transformation transformation, int rendererIndex) + public AudioSamplePipeline(Format inputFormat, Transformation transformation, int rendererIndex) throws ExoPlaybackException { - this.decoderInputFormat = decoderInputFormat; + this.inputFormat = inputFormat; this.transformation = transformation; this.rendererIndex = rendererIndex; decoderInputBuffer = @@ -83,17 +82,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); sonicAudioProcessor = new SonicAudioProcessor(); sonicOutputBuffer = AudioProcessor.EMPTY_BUFFER; - speedProvider = new SegmentSpeedProvider(decoderInputFormat); + speedProvider = new SegmentSpeedProvider(inputFormat); currentSpeed = speedProvider.getSpeed(0); try { - this.decoder = MediaCodecAdapterWrapper.createForAudioDecoding(decoderInputFormat); + this.decoder = MediaCodecAdapterWrapper.createForAudioDecoding(inputFormat); } catch (IOException e) { // TODO(internal b/192864511): Assign a specific error code. throw ExoPlaybackException.createForRenderer( e, TAG, rendererIndex, - decoderInputFormat, + inputFormat, /* rendererFormatSupport= */ C.FORMAT_HANDLED, /* isRecoverable= */ false, PlaybackException.ERROR_CODE_UNSPECIFIED); @@ -319,7 +318,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; } String audioMimeType = transformation.audioMimeType == null - ? decoderInputFormat.sampleMimeType + ? inputFormat.sampleMimeType : transformation.audioMimeType; try { encoder = @@ -359,7 +358,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; cause, TAG, rendererIndex, - decoderInputFormat, + inputFormat, /* rendererFormatSupport= */ C.FORMAT_HANDLED, /* isRecoverable= */ false, errorCode); diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerAudioRenderer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerAudioRenderer.java index 74110ed1be..e91c70433d 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerAudioRenderer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerAudioRenderer.java @@ -58,13 +58,13 @@ import androidx.media3.exoplayer.source.SampleStream.ReadDataResult; if (result != C.RESULT_FORMAT_READ) { return false; } - Format decoderInputFormat = checkNotNull(formatHolder.format); + Format inputFormat = checkNotNull(formatHolder.format); if ((transformation.audioMimeType != null - && !transformation.audioMimeType.equals(decoderInputFormat.sampleMimeType)) + && !transformation.audioMimeType.equals(inputFormat.sampleMimeType)) || transformation.flattenForSlowMotion) { - samplePipeline = new AudioSamplePipeline(decoderInputFormat, transformation, getIndex()); + samplePipeline = new AudioSamplePipeline(inputFormat, transformation, getIndex()); } else { - samplePipeline = new PassthroughSamplePipeline(decoderInputFormat); + samplePipeline = new PassthroughSamplePipeline(inputFormat); } return true; } diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerVideoRenderer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerVideoRenderer.java index 8f215c23ad..8006e99291 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerVideoRenderer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerVideoRenderer.java @@ -69,18 +69,17 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; if (result != C.RESULT_FORMAT_READ) { return false; } - Format decoderInputFormat = checkNotNull(formatHolder.format); + Format inputFormat = checkNotNull(formatHolder.format); if ((transformation.videoMimeType != null - && !transformation.videoMimeType.equals(decoderInputFormat.sampleMimeType)) + && !transformation.videoMimeType.equals(inputFormat.sampleMimeType)) || (transformation.outputHeight != Transformation.NO_VALUE - && transformation.outputHeight != decoderInputFormat.height)) { - samplePipeline = - new VideoSamplePipeline(context, decoderInputFormat, transformation, getIndex()); + && transformation.outputHeight != inputFormat.height)) { + samplePipeline = new VideoSamplePipeline(context, inputFormat, transformation, getIndex()); } else { - samplePipeline = new PassthroughSamplePipeline(decoderInputFormat); + samplePipeline = new PassthroughSamplePipeline(inputFormat); } if (transformation.flattenForSlowMotion) { - sefSlowMotionFlattener = new SefSlowMotionFlattener(decoderInputFormat); + sefSlowMotionFlattener = new SefSlowMotionFlattener(inputFormat); } return true; } diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoSamplePipeline.java b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoSamplePipeline.java index 91862a63a4..61be19995a 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/VideoSamplePipeline.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/VideoSamplePipeline.java @@ -38,32 +38,29 @@ import java.io.IOException; private static final String TAG = "VideoSamplePipeline"; - private final MediaCodecAdapterWrapper encoder; - private final DecoderInputBuffer encoderOutputBuffer; - private final DecoderInputBuffer decoderInputBuffer; private final MediaCodecAdapterWrapper decoder; private final FrameEditor frameEditor; + private final MediaCodecAdapterWrapper encoder; + private final DecoderInputBuffer encoderOutputBuffer; + private boolean waitingForPopulatedDecoderSurface; public VideoSamplePipeline( - Context context, Format decoderInputFormat, Transformation transformation, int rendererIndex) + Context context, Format inputFormat, Transformation transformation, int rendererIndex) throws ExoPlaybackException { - decoderInputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); - encoderOutputBuffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_DISABLED); - int outputWidth = decoderInputFormat.width; - int outputHeight = decoderInputFormat.height; + int outputWidth = inputFormat.width; + int outputHeight = inputFormat.height; if (transformation.outputHeight != Transformation.NO_VALUE - && transformation.outputHeight != decoderInputFormat.height) { - outputWidth = - decoderInputFormat.width * transformation.outputHeight / decoderInputFormat.height; + && transformation.outputHeight != inputFormat.height) { + outputWidth = inputFormat.width * transformation.outputHeight / inputFormat.height; outputHeight = transformation.outputHeight; } @@ -76,13 +73,13 @@ import java.io.IOException; .setSampleMimeType( transformation.videoMimeType != null ? transformation.videoMimeType - : decoderInputFormat.sampleMimeType) + : inputFormat.sampleMimeType) .build(), ImmutableMap.of()); } catch (IOException e) { // TODO(internal b/192864511): Assign a specific error code. throw createRendererException( - e, rendererIndex, decoderInputFormat, PlaybackException.ERROR_CODE_UNSPECIFIED); + e, rendererIndex, inputFormat, PlaybackException.ERROR_CODE_UNSPECIFIED); } frameEditor = FrameEditor.create( @@ -93,10 +90,10 @@ import java.io.IOException; try { decoder = MediaCodecAdapterWrapper.createForVideoDecoding( - decoderInputFormat, frameEditor.getInputSurface()); + inputFormat, frameEditor.getInputSurface()); } catch (IOException e) { throw createRendererException( - e, rendererIndex, decoderInputFormat, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED); + e, rendererIndex, inputFormat, PlaybackException.ERROR_CODE_DECODER_INIT_FAILED); } } @@ -172,12 +169,12 @@ import java.io.IOException; } private static ExoPlaybackException createRendererException( - Throwable cause, int rendererIndex, Format decoderInputFormat, int errorCode) { + Throwable cause, int rendererIndex, Format inputFormat, int errorCode) { return ExoPlaybackException.createForRenderer( cause, TAG, rendererIndex, - decoderInputFormat, + inputFormat, /* rendererFormatSupport= */ C.FORMAT_HANDLED, /* isRecoverable= */ false, errorCode);