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 1135bf7df4..dffdef4280 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 @@ -114,16 +114,11 @@ import java.nio.ByteBuffer; forceQueueingSynchronizationWorkaround, synchronizeCodecInteractionsWithQueueing); TraceUtil.endSection(); - TraceUtil.beginSection("configureCodec"); - codecAdapter.configure( + codecAdapter.initialize( configuration.mediaFormat, configuration.surface, configuration.crypto, configuration.flags); - TraceUtil.endSection(); - TraceUtil.beginSection("startCodec"); - codecAdapter.start(); - TraceUtil.endSection(); return codecAdapter; } catch (Exception e) { if (codecAdapter != null) { @@ -138,13 +133,12 @@ import java.nio.ByteBuffer; @Documented @Retention(RetentionPolicy.SOURCE) - @IntDef({STATE_CREATED, STATE_CONFIGURED, STATE_STARTED, STATE_SHUT_DOWN}) + @IntDef({STATE_CREATED, STATE_INITIALIZED, STATE_SHUT_DOWN}) private @interface State {} private static final int STATE_CREATED = 0; - private static final int STATE_CONFIGURED = 1; - private static final int STATE_STARTED = 2; - private static final int STATE_SHUT_DOWN = 3; + private static final int STATE_INITIALIZED = 1; + private static final int STATE_SHUT_DOWN = 2; private final MediaCodec codec; private final AsynchronousMediaCodecCallback asynchronousMediaCodecCallback; @@ -168,20 +162,20 @@ import java.nio.ByteBuffer; this.state = STATE_CREATED; } - private void configure( + private void initialize( @Nullable MediaFormat mediaFormat, @Nullable Surface surface, @Nullable MediaCrypto crypto, int flags) { asynchronousMediaCodecCallback.initialize(codec); + TraceUtil.beginSection("configureCodec"); codec.configure(mediaFormat, surface, crypto, flags); - state = STATE_CONFIGURED; - } - - private void start() { + TraceUtil.endSection(); bufferEnqueuer.start(); + TraceUtil.beginSection("startCodec"); codec.start(); - state = STATE_STARTED; + TraceUtil.endSection(); + state = STATE_INITIALIZED; } @Override @@ -253,10 +247,8 @@ import java.nio.ByteBuffer; @Override public void release() { try { - if (state == STATE_STARTED) { + if (state == STATE_INITIALIZED) { bufferEnqueuer.shutdown(); - } - if (state == STATE_CONFIGURED || state == STATE_STARTED) { asynchronousMediaCodecCallback.shutdown(); } state = STATE_SHUT_DOWN; diff --git a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java index bec1a7bf4b..5dfeb04ff1 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/mediacodec/AsynchronousMediaCodecAdapterTest.java @@ -30,9 +30,11 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.robolectric.annotation.internal.DoNotInstrument; /** Unit tests for {@link AsynchronousMediaCodecAdapter}. */ @RunWith(AndroidJUnit4.class) +@DoNotInstrument public class AsynchronousMediaCodecAdapterTest { private AsynchronousMediaCodecAdapter adapter; private HandlerThread callbackThread; @@ -60,8 +62,8 @@ public class AsynchronousMediaCodecAdapterTest { /* synchronizeCodecInteractionsWithQueueing= */ false) .createAdapter(configuration); bufferInfo = new MediaCodec.BufferInfo(); - // After start(), the ShadowMediaCodec offers input buffer 0. We advance the looper to make sure - // and messages have been propagated to the adapter. + // After starting the MediaCodec, the ShadowMediaCodec offers input buffer 0. We advance the + // looper to make sure any messages have been propagated to the adapter. shadowOf(callbackThread.getLooper()).idle(); }