From 755df46a6b7ce312de15eb712c61a2f4636cefe2 Mon Sep 17 00:00:00 2001 From: hschlueter Date: Thu, 13 Jan 2022 10:43:52 +0000 Subject: [PATCH] Remove Transformer-specific things from MediaCodecAdapter. PiperOrigin-RevId: 421514944 --- .../AsynchronousMediaCodecAdapter.java | 25 +----- .../mediacodec/MediaCodecAdapter.java | 90 +------------------ .../SynchronousMediaCodecAdapter.java | 51 +---------- .../testutil/CapturingRenderersFactory.java | 12 --- 4 files changed, 8 insertions(+), 170 deletions(-) diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapter.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapter.java index c49bdb4035..449833bc7d 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapter.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapter.java @@ -109,8 +109,7 @@ import java.nio.ByteBuffer; configuration.mediaFormat, configuration.surface, configuration.crypto, - configuration.flags, - configuration.createInputSurface); + configuration.flags); return codecAdapter; } catch (Exception e) { if (codecAdapter != null) { @@ -139,7 +138,6 @@ import java.nio.ByteBuffer; private final boolean enableImmediateCodecStartAfterFlush; private boolean codecReleased; @State private int state; - @Nullable private Surface inputSurface; private AsynchronousMediaCodecAdapter( MediaCodec codec, @@ -159,15 +157,11 @@ import java.nio.ByteBuffer; @Nullable MediaFormat mediaFormat, @Nullable Surface surface, @Nullable MediaCrypto crypto, - int flags, - boolean createInputSurface) { + int flags) { asynchronousMediaCodecCallback.initialize(codec); TraceUtil.beginSection("configureCodec"); codec.configure(mediaFormat, surface, crypto, flags); TraceUtil.endSection(); - if (createInputSurface) { - inputSurface = codec.createInputSurface(); - } bufferEnqueuer.start(); TraceUtil.beginSection("startCodec"); codec.start(); @@ -223,12 +217,6 @@ import java.nio.ByteBuffer; return codec.getInputBuffer(index); } - @Override - @Nullable - public Surface getInputSurface() { - return inputSurface; - } - @Override @Nullable public ByteBuffer getOutputBuffer(int index) { @@ -263,9 +251,6 @@ import java.nio.ByteBuffer; } state = STATE_SHUT_DOWN; } finally { - if (inputSurface != null) { - inputSurface.release(); - } if (!codecReleased) { codec.release(); codecReleased = true; @@ -301,12 +286,6 @@ import java.nio.ByteBuffer; codec.setVideoScalingMode(scalingMode); } - @Override - public void signalEndOfInputStream() { - maybeBlockOnQueueing(); - codec.signalEndOfInputStream(); - } - @Override @RequiresApi(26) public PersistableBundle getMetrics() { diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecAdapter.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecAdapter.java index 3636cf26ed..69acb3b844 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecAdapter.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecAdapter.java @@ -55,13 +55,7 @@ public interface MediaCodecAdapter { Format format, @Nullable MediaCrypto crypto) { return new Configuration( - codecInfo, - mediaFormat, - format, - /* surface= */ null, - crypto, - /* flags= */ 0, - /* createInputSurface= */ false); + codecInfo, mediaFormat, format, /* surface= */ null, crypto, /* flags= */ 0); } /** @@ -80,55 +74,7 @@ public interface MediaCodecAdapter { Format format, @Nullable Surface surface, @Nullable MediaCrypto crypto) { - return new Configuration( - codecInfo, - mediaFormat, - format, - surface, - crypto, - /* flags= */ 0, - /* createInputSurface= */ false); - } - - /** - * Creates a configuration for audio encoding. - * - * @param codecInfo See {@link #codecInfo}. - * @param mediaFormat See {@link #mediaFormat}. - * @param format See {@link #format}. - * @return The created instance. - */ - public static Configuration createForAudioEncoding( - MediaCodecInfo codecInfo, MediaFormat mediaFormat, Format format) { - return new Configuration( - codecInfo, - mediaFormat, - format, - /* surface= */ null, - /* crypto= */ null, - MediaCodec.CONFIGURE_FLAG_ENCODE, - /* createInputSurface= */ false); - } - - /** - * Creates a configuration for video encoding. - * - * @param codecInfo See {@link #codecInfo}. - * @param mediaFormat See {@link #mediaFormat}. - * @param format See {@link #format}. - * @return The created instance. - */ - @RequiresApi(18) - public static Configuration createForVideoEncoding( - MediaCodecInfo codecInfo, MediaFormat mediaFormat, Format format) { - return new Configuration( - codecInfo, - mediaFormat, - format, - /* surface= */ null, - /* crypto= */ null, - MediaCodec.CONFIGURE_FLAG_ENCODE, - /* createInputSurface= */ true); + return new Configuration(codecInfo, mediaFormat, format, surface, crypto, /* flags= */ 0); } /** Information about the {@link MediaCodec} being configured. */ @@ -145,17 +91,8 @@ public interface MediaCodecAdapter { @Nullable public final Surface surface; /** For DRM protected playbacks, a {@link MediaCrypto} to use for decryption. */ @Nullable public final MediaCrypto crypto; - /** - * Specify CONFIGURE_FLAG_ENCODE to configure the component as an encoder. - * - * @see MediaCodec#configure - */ + /** See {@link MediaCodec#configure}. */ public final int flags; - /** - * Whether to request a {@link Surface} and use it as to the input to an encoder. This can only - * be set to {@code true} on API 18+. - */ - public final boolean createInputSurface; private Configuration( MediaCodecInfo codecInfo, @@ -163,15 +100,13 @@ public interface MediaCodecAdapter { Format format, @Nullable Surface surface, @Nullable MediaCrypto crypto, - int flags, - boolean createInputSurface) { + int flags) { this.codecInfo = codecInfo; this.mediaFormat = mediaFormat; this.format = format; this.surface = surface; this.crypto = crypto; this.flags = flags; - this.createInputSurface = createInputSurface; } } @@ -229,14 +164,6 @@ public interface MediaCodecAdapter { @Nullable ByteBuffer getInputBuffer(int index); - /** - * Returns the input {@link Surface}, or null if the input is not a surface. - * - * @see MediaCodec#createInputSurface() - */ - @Nullable - Surface getInputSurface(); - /** * Returns a read-only ByteBuffer for a dequeued output buffer index. * @@ -329,15 +256,6 @@ public interface MediaCodecAdapter { /** Whether the adapter needs to be reconfigured before it is used. */ boolean needsReconfiguration(); - /** - * Signals the encoder of end-of-stream on input. The call can only be used when the encoder - * receives its input from a {@link Surface surface}. - * - * @see MediaCodec#signalEndOfInputStream() - */ - @RequiresApi(18) - void signalEndOfInputStream(); - /** * Returns metrics data about the current codec instance. * diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/SynchronousMediaCodecAdapter.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/SynchronousMediaCodecAdapter.java index cfe3c4e875..ff6ce38bda 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/SynchronousMediaCodecAdapter.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/SynchronousMediaCodecAdapter.java @@ -25,7 +25,6 @@ import android.os.Bundle; import android.os.Handler; import android.os.PersistableBundle; import android.view.Surface; -import androidx.annotation.DoNotInline; import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; import com.google.android.exoplayer2.C; @@ -46,7 +45,6 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter { @Override public MediaCodecAdapter createAdapter(Configuration configuration) throws IOException { @Nullable MediaCodec codec = null; - @Nullable Surface inputSurface = null; try { codec = createCodec(configuration); TraceUtil.beginSection("configureCodec"); @@ -56,24 +54,11 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter { configuration.crypto, configuration.flags); TraceUtil.endSection(); - - if (configuration.createInputSurface) { - if (Util.SDK_INT >= 18) { - inputSurface = Api18.createCodecInputSurface(codec); - } else { - throw new IllegalStateException( - "Encoding from a surface is only supported on API 18 and up."); - } - } - TraceUtil.beginSection("startCodec"); codec.start(); TraceUtil.endSection(); - return new SynchronousMediaCodecAdapter(codec, inputSurface); + return new SynchronousMediaCodecAdapter(codec); } catch (IOException | RuntimeException e) { - if (inputSurface != null) { - inputSurface.release(); - } if (codec != null) { codec.release(); } @@ -93,13 +78,11 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter { } private final MediaCodec codec; - @Nullable private final Surface inputSurface; @Nullable private ByteBuffer[] inputByteBuffers; @Nullable private ByteBuffer[] outputByteBuffers; - private SynchronousMediaCodecAdapter(MediaCodec mediaCodec, @Nullable Surface inputSurface) { + private SynchronousMediaCodecAdapter(MediaCodec mediaCodec) { this.codec = mediaCodec; - this.inputSurface = inputSurface; if (Util.SDK_INT < 21) { inputByteBuffers = codec.getInputBuffers(); outputByteBuffers = codec.getOutputBuffers(); @@ -144,12 +127,6 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter { } } - @Override - @Nullable - public Surface getInputSurface() { - return inputSurface; - } - @Override @Nullable public ByteBuffer getOutputBuffer(int index) { @@ -193,18 +170,9 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter { public void release() { inputByteBuffers = null; outputByteBuffers = null; - if (inputSurface != null) { - inputSurface.release(); - } codec.release(); } - @Override - @RequiresApi(18) - public void signalEndOfInputStream() { - Api18.signalEndOfInputStream(codec); - } - @Override @RequiresApi(23) public void setOnFrameRenderedListener(OnFrameRenderedListener listener, Handler handler) { @@ -237,19 +205,4 @@ public final class SynchronousMediaCodecAdapter implements MediaCodecAdapter { public PersistableBundle getMetrics() { return codec.getMetrics(); } - - @RequiresApi(18) - private static final class Api18 { - private Api18() {} - - @DoNotInline - public static Surface createCodecInputSurface(MediaCodec codec) { - return codec.createInputSurface(); - } - - @DoNotInline - public static void signalEndOfInputStream(MediaCodec codec) { - codec.signalEndOfInputStream(); - } - } } diff --git a/testutils/src/main/java/com/google/android/exoplayer2/testutil/CapturingRenderersFactory.java b/testutils/src/main/java/com/google/android/exoplayer2/testutil/CapturingRenderersFactory.java index 1823dac443..fd9ee80234 100644 --- a/testutils/src/main/java/com/google/android/exoplayer2/testutil/CapturingRenderersFactory.java +++ b/testutils/src/main/java/com/google/android/exoplayer2/testutil/CapturingRenderersFactory.java @@ -195,12 +195,6 @@ public class CapturingRenderersFactory implements RenderersFactory, Dumper.Dumpa return inputBuffer; } - @Nullable - @Override - public Surface getInputSurface() { - return delegate.getInputSurface(); - } - @Nullable @Override public ByteBuffer getOutputBuffer(int index) { @@ -270,12 +264,6 @@ public class CapturingRenderersFactory implements RenderersFactory, Dumper.Dumpa delegate.setVideoScalingMode(scalingMode); } - @RequiresApi(18) - @Override - public void signalEndOfInputStream() { - delegate.signalEndOfInputStream(); - } - @RequiresApi(26) @Override public PersistableBundle getMetrics() {