From 94ef005b179557b85219d19234e18b1259d42c81 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/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AudioSamplePipeline.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AudioSamplePipeline.java index b53da51eb3..042cb8e990 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/AudioSamplePipeline.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/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/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java index e57150c996..8f71a54ba3 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java @@ -58,13 +58,13 @@ import com.google.android.exoplayer2.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/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerVideoRenderer.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerVideoRenderer.java index 1541dc7fe6..f4ccefc26f 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerVideoRenderer.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/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/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java index 9cb698efcd..46c0ef23d1 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/VideoSamplePipeline.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/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);