Commit 4d518806 by christosts Committed by Ian Baker

Remove experimental flag for AsynchronousMediaCodecAdapter

The AsyncronousMediaCodecAdapter should call MediaCodec.start()
on the same thread it calls MediaCodec.flush(), i.e. the playback
thread. This change removes the experimental flag that allowed
calling MediaCodec.start() from the callback thread.

The flag was flipped to true already.

PiperOrigin-RevId: 430689665
parent 8416f465
...@@ -170,25 +170,6 @@ public class DefaultRenderersFactory implements RenderersFactory { ...@@ -170,25 +170,6 @@ public class DefaultRenderersFactory implements RenderersFactory {
} }
/** /**
* Enable calling {@link MediaCodec#start} immediately after {@link MediaCodec#flush} on the
* playback thread, when operating the codec in asynchronous mode. If disabled, {@link
* MediaCodec#start} will be called by the callback thread after pending callbacks are handled.
*
* <p>By default, this feature is disabled.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param enabled Whether {@link MediaCodec#start} will be called on the playback thread
* immediately after {@link MediaCodec#flush}.
* @return This factory, for convenience.
*/
public DefaultRenderersFactory experimentalSetImmediateCodecStartAfterFlushEnabled(
boolean enabled) {
codecAdapterFactory.experimentalSetImmediateCodecStartAfterFlushEnabled(enabled);
return this;
}
/**
* Sets whether to enable fallback to lower-priority decoders if decoder initialization fails. * Sets whether to enable fallback to lower-priority decoders if decoder initialization fails.
* This may result in using a decoder that is less efficient or slower than the primary decoder. * This may result in using a decoder that is less efficient or slower than the primary decoder.
* *
......
...@@ -54,7 +54,6 @@ import java.nio.ByteBuffer; ...@@ -54,7 +54,6 @@ import java.nio.ByteBuffer;
private final Supplier<HandlerThread> callbackThreadSupplier; private final Supplier<HandlerThread> callbackThreadSupplier;
private final Supplier<HandlerThread> queueingThreadSupplier; private final Supplier<HandlerThread> queueingThreadSupplier;
private final boolean synchronizeCodecInteractionsWithQueueing; private final boolean synchronizeCodecInteractionsWithQueueing;
private final boolean enableImmediateCodecStartAfterFlush;
/** /**
* Creates an factory for {@link AsynchronousMediaCodecAdapter} instances. * Creates an factory for {@link AsynchronousMediaCodecAdapter} instances.
...@@ -66,29 +65,23 @@ import java.nio.ByteBuffer; ...@@ -66,29 +65,23 @@ import java.nio.ByteBuffer;
* interactions will wait until all input buffers pending queueing wil be submitted to the * interactions will wait until all input buffers pending queueing wil be submitted to the
* {@link MediaCodec}. * {@link MediaCodec}.
*/ */
public Factory( public Factory(@C.TrackType int trackType, boolean synchronizeCodecInteractionsWithQueueing) {
@C.TrackType int trackType,
boolean synchronizeCodecInteractionsWithQueueing,
boolean enableImmediateCodecStartAfterFlush) {
this( this(
/* callbackThreadSupplier= */ () -> /* callbackThreadSupplier= */ () ->
new HandlerThread(createCallbackThreadLabel(trackType)), new HandlerThread(createCallbackThreadLabel(trackType)),
/* queueingThreadSupplier= */ () -> /* queueingThreadSupplier= */ () ->
new HandlerThread(createQueueingThreadLabel(trackType)), new HandlerThread(createQueueingThreadLabel(trackType)),
synchronizeCodecInteractionsWithQueueing, synchronizeCodecInteractionsWithQueueing);
enableImmediateCodecStartAfterFlush);
} }
@VisibleForTesting @VisibleForTesting
/* package */ Factory( /* package */ Factory(
Supplier<HandlerThread> callbackThreadSupplier, Supplier<HandlerThread> callbackThreadSupplier,
Supplier<HandlerThread> queueingThreadSupplier, Supplier<HandlerThread> queueingThreadSupplier,
boolean synchronizeCodecInteractionsWithQueueing, boolean synchronizeCodecInteractionsWithQueueing) {
boolean enableImmediateCodecStartAfterFlush) {
this.callbackThreadSupplier = callbackThreadSupplier; this.callbackThreadSupplier = callbackThreadSupplier;
this.queueingThreadSupplier = queueingThreadSupplier; this.queueingThreadSupplier = queueingThreadSupplier;
this.synchronizeCodecInteractionsWithQueueing = synchronizeCodecInteractionsWithQueueing; this.synchronizeCodecInteractionsWithQueueing = synchronizeCodecInteractionsWithQueueing;
this.enableImmediateCodecStartAfterFlush = enableImmediateCodecStartAfterFlush;
} }
@Override @Override
...@@ -105,8 +98,7 @@ import java.nio.ByteBuffer; ...@@ -105,8 +98,7 @@ import java.nio.ByteBuffer;
codec, codec,
callbackThreadSupplier.get(), callbackThreadSupplier.get(),
queueingThreadSupplier.get(), queueingThreadSupplier.get(),
synchronizeCodecInteractionsWithQueueing, synchronizeCodecInteractionsWithQueueing);
enableImmediateCodecStartAfterFlush);
TraceUtil.endSection(); TraceUtil.endSection();
codecAdapter.initialize( codecAdapter.initialize(
configuration.mediaFormat, configuration.mediaFormat,
...@@ -139,7 +131,6 @@ import java.nio.ByteBuffer; ...@@ -139,7 +131,6 @@ import java.nio.ByteBuffer;
private final AsynchronousMediaCodecCallback asynchronousMediaCodecCallback; private final AsynchronousMediaCodecCallback asynchronousMediaCodecCallback;
private final AsynchronousMediaCodecBufferEnqueuer bufferEnqueuer; private final AsynchronousMediaCodecBufferEnqueuer bufferEnqueuer;
private final boolean synchronizeCodecInteractionsWithQueueing; private final boolean synchronizeCodecInteractionsWithQueueing;
private final boolean enableImmediateCodecStartAfterFlush;
private boolean codecReleased; private boolean codecReleased;
private @State int state; private @State int state;
...@@ -147,13 +138,11 @@ import java.nio.ByteBuffer; ...@@ -147,13 +138,11 @@ import java.nio.ByteBuffer;
MediaCodec codec, MediaCodec codec,
HandlerThread callbackThread, HandlerThread callbackThread,
HandlerThread enqueueingThread, HandlerThread enqueueingThread,
boolean synchronizeCodecInteractionsWithQueueing, boolean synchronizeCodecInteractionsWithQueueing) {
boolean enableImmediateCodecStartAfterFlush) {
this.codec = codec; this.codec = codec;
this.asynchronousMediaCodecCallback = new AsynchronousMediaCodecCallback(callbackThread); this.asynchronousMediaCodecCallback = new AsynchronousMediaCodecCallback(callbackThread);
this.bufferEnqueuer = new AsynchronousMediaCodecBufferEnqueuer(codec, enqueueingThread); this.bufferEnqueuer = new AsynchronousMediaCodecBufferEnqueuer(codec, enqueueingThread);
this.synchronizeCodecInteractionsWithQueueing = synchronizeCodecInteractionsWithQueueing; this.synchronizeCodecInteractionsWithQueueing = synchronizeCodecInteractionsWithQueueing;
this.enableImmediateCodecStartAfterFlush = enableImmediateCodecStartAfterFlush;
this.state = STATE_CREATED; this.state = STATE_CREATED;
} }
...@@ -232,18 +221,13 @@ import java.nio.ByteBuffer; ...@@ -232,18 +221,13 @@ import java.nio.ByteBuffer;
// The order of calls is important: // The order of calls is important:
// 1. Flush the bufferEnqueuer to stop queueing input buffers. // 1. Flush the bufferEnqueuer to stop queueing input buffers.
// 2. Flush the codec to stop producing available input/output buffers. // 2. Flush the codec to stop producing available input/output buffers.
// 3. Flush the callback after flushing the codec so that in-flight callbacks are discarded. // 3. Flush the callback so that in-flight callbacks are discarded.
// 4. Start the codec. The asynchronous callback will drop pending callbacks and we can start
// the codec now.
bufferEnqueuer.flush(); bufferEnqueuer.flush();
codec.flush(); codec.flush();
if (enableImmediateCodecStartAfterFlush) { asynchronousMediaCodecCallback.flush();
// The asynchronous callback will drop pending callbacks but we can start the codec now.
asynchronousMediaCodecCallback.flush(/* codec= */ null);
codec.start(); codec.start();
} else {
// Let the asynchronous callback start the codec in the callback thread after pending
// callbacks are handled.
asynchronousMediaCodecCallback.flush(codec);
}
} }
@Override @Override
......
...@@ -191,14 +191,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -191,14 +191,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
/** /**
* Initiates a flush asynchronously, which will be completed on the callback thread. When the * Initiates a flush asynchronously, which will be completed on the callback thread. When the
* flush is complete, it will trigger {@code onFlushCompleted} from the callback thread. * flush is complete, it will trigger {@code onFlushCompleted} from the callback thread.
*
* @param codec A {@link MediaCodec} to {@link MediaCodec#start start} after all pending callbacks
* are handled, or {@code null} if starting the {@link MediaCodec} is performed elsewhere.
*/ */
public void flush(@Nullable MediaCodec codec) { public void flush() {
synchronized (lock) { synchronized (lock) {
++pendingFlushCount; ++pendingFlushCount;
Util.castNonNull(handler).post(() -> this.onFlushCompleted(codec)); Util.castNonNull(handler).post(this::onFlushCompleted);
} }
} }
...@@ -238,7 +235,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -238,7 +235,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
} }
private void onFlushCompleted(@Nullable MediaCodec codec) { private void onFlushCompleted() {
synchronized (lock) { synchronized (lock) {
if (shutDown) { if (shutDown) {
return; return;
...@@ -254,15 +251,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ...@@ -254,15 +251,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
return; return;
} }
flushInternal(); flushInternal();
if (codec != null) {
try {
codec.start();
} catch (IllegalStateException e) {
setInternalException(e);
} catch (Exception e) {
setInternalException(new IllegalStateException(e));
}
}
} }
} }
......
...@@ -17,7 +17,6 @@ package com.google.android.exoplayer2.mediacodec; ...@@ -17,7 +17,6 @@ package com.google.android.exoplayer2.mediacodec;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
import android.media.MediaCodec;
import androidx.annotation.IntDef; import androidx.annotation.IntDef;
import com.google.android.exoplayer2.util.Log; import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
...@@ -53,11 +52,9 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter. ...@@ -53,11 +52,9 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter.
private @Mode int asynchronousMode; private @Mode int asynchronousMode;
private boolean enableSynchronizeCodecInteractionsWithQueueing; private boolean enableSynchronizeCodecInteractionsWithQueueing;
private boolean enableImmediateCodecStartAfterFlush;
public DefaultMediaCodecAdapterFactory() { public DefaultMediaCodecAdapterFactory() {
asynchronousMode = MODE_DEFAULT; asynchronousMode = MODE_DEFAULT;
enableImmediateCodecStartAfterFlush = true;
} }
/** /**
...@@ -94,22 +91,6 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter. ...@@ -94,22 +91,6 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter.
enableSynchronizeCodecInteractionsWithQueueing = enabled; enableSynchronizeCodecInteractionsWithQueueing = enabled;
} }
/**
* Enable calling {@link MediaCodec#start} immediately after {@link MediaCodec#flush} on the
* playback thread, when operating the codec in asynchronous mode. If disabled, {@link
* MediaCodec#start} will be called by the callback thread after pending callbacks are handled.
*
* <p>By default, this feature is enabled.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param enabled Whether {@link MediaCodec#start()} will be called on the playback thread
* immediately after {@link MediaCodec#flush}.
*/
public void experimentalSetImmediateCodecStartAfterFlushEnabled(boolean enabled) {
enableImmediateCodecStartAfterFlush = enabled;
}
@Override @Override
public MediaCodecAdapter createAdapter(MediaCodecAdapter.Configuration configuration) public MediaCodecAdapter createAdapter(MediaCodecAdapter.Configuration configuration)
throws IOException { throws IOException {
...@@ -122,9 +103,7 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter. ...@@ -122,9 +103,7 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter.
+ Util.getTrackTypeString(trackType)); + Util.getTrackTypeString(trackType));
AsynchronousMediaCodecAdapter.Factory factory = AsynchronousMediaCodecAdapter.Factory factory =
new AsynchronousMediaCodecAdapter.Factory( new AsynchronousMediaCodecAdapter.Factory(
trackType, trackType, enableSynchronizeCodecInteractionsWithQueueing);
enableSynchronizeCodecInteractionsWithQueueing,
enableImmediateCodecStartAfterFlush);
return factory.createAdapter(configuration); return factory.createAdapter(configuration);
} }
return new SynchronousMediaCodecAdapter.Factory().createAdapter(configuration); return new SynchronousMediaCodecAdapter.Factory().createAdapter(configuration);
......
...@@ -54,8 +54,7 @@ public class AsynchronousMediaCodecAdapterTest { ...@@ -54,8 +54,7 @@ public class AsynchronousMediaCodecAdapterTest {
new AsynchronousMediaCodecAdapter.Factory( new AsynchronousMediaCodecAdapter.Factory(
/* callbackThreadSupplier= */ () -> callbackThread, /* callbackThreadSupplier= */ () -> callbackThread,
/* queueingThreadSupplier= */ () -> queueingThread, /* queueingThreadSupplier= */ () -> queueingThread,
/* synchronizeCodecInteractionsWithQueueing= */ false, /* synchronizeCodecInteractionsWithQueueing= */ false)
/* enableImmediateCodecStartAfterFlush= */ false)
.createAdapter(configuration); .createAdapter(configuration);
bufferInfo = new MediaCodec.BufferInfo(); bufferInfo = new MediaCodec.BufferInfo();
// After starting the MediaCodec, the ShadowMediaCodec offers input buffer 0. We advance the // After starting the MediaCodec, the ShadowMediaCodec offers input buffer 0. We advance the
......
...@@ -94,7 +94,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -94,7 +94,7 @@ public class AsynchronousMediaCodecCallbackTest {
asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 0); asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 0);
asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 1); asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 1);
callbackHandler.post(() -> beforeFlushCompletes.set(true)); callbackHandler.post(() -> beforeFlushCompletes.set(true));
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
callbackHandler.post(() -> flushCompleted.set(true)); callbackHandler.post(() -> flushCompleted.set(true));
while (!beforeFlushCompletes.get()) { while (!beforeFlushCompletes.get()) {
shadowCallbackLooper.runOneTask(); shadowCallbackLooper.runOneTask();
...@@ -113,7 +113,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -113,7 +113,7 @@ public class AsynchronousMediaCodecCallbackTest {
// Send two input buffers to the callback and then flush(). // Send two input buffers to the callback and then flush().
asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 0); asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 0);
asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 1); asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 1);
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the callback thread so that flush() completes. // Progress the callback thread so that flush() completes.
shadowOf(callbackThreadLooper).idle(); shadowOf(callbackThreadLooper).idle();
...@@ -132,7 +132,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -132,7 +132,7 @@ public class AsynchronousMediaCodecCallbackTest {
// another input buffer. // another input buffer.
asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 0); asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 0);
asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 1); asynchronousMediaCodecCallback.onInputBufferAvailable(codec, 1);
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the callback thread to complete flush. // Progress the callback thread to complete flush.
shadowOf(callbackThread.getLooper()).idle(); shadowOf(callbackThread.getLooper()).idle();
...@@ -207,7 +207,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -207,7 +207,7 @@ public class AsynchronousMediaCodecCallbackTest {
asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 0, bufferInfo); asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 0, bufferInfo);
asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 1, bufferInfo); asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 1, bufferInfo);
callbackHandler.post(() -> beforeFlushCompletes.set(true)); callbackHandler.post(() -> beforeFlushCompletes.set(true));
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
callbackHandler.post(() -> flushCompleted.set(true)); callbackHandler.post(() -> flushCompleted.set(true));
while (beforeFlushCompletes.get()) { while (beforeFlushCompletes.get()) {
shadowCallbackLooper.runOneTask(); shadowCallbackLooper.runOneTask();
...@@ -227,7 +227,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -227,7 +227,7 @@ public class AsynchronousMediaCodecCallbackTest {
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo(); MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 0, bufferInfo); asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 0, bufferInfo);
asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 1, bufferInfo); asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 1, bufferInfo);
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the callback looper so that flush() completes. // Progress the callback looper so that flush() completes.
shadowOf(callbackThreadLooper).idle(); shadowOf(callbackThreadLooper).idle();
...@@ -248,7 +248,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -248,7 +248,7 @@ public class AsynchronousMediaCodecCallbackTest {
asynchronousMediaCodecCallback.onOutputFormatChanged(codec, createMediaFormat("format0")); asynchronousMediaCodecCallback.onOutputFormatChanged(codec, createMediaFormat("format0"));
asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 0, bufferInfo); asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 0, bufferInfo);
asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 1, bufferInfo); asynchronousMediaCodecCallback.onOutputBufferAvailable(codec, 1, bufferInfo);
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the callback looper so that flush() completes. // Progress the callback looper so that flush() completes.
shadowOf(callbackThreadLooper).idle(); shadowOf(callbackThreadLooper).idle();
...@@ -275,7 +275,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -275,7 +275,7 @@ public class AsynchronousMediaCodecCallbackTest {
MediaFormat pendingMediaFormat = new MediaFormat(); MediaFormat pendingMediaFormat = new MediaFormat();
asynchronousMediaCodecCallback.onOutputFormatChanged(codec, pendingMediaFormat); asynchronousMediaCodecCallback.onOutputFormatChanged(codec, pendingMediaFormat);
// flush() should not discard the last format. // flush() should not discard the last format.
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the callback looper so that flush() completes. // Progress the callback looper so that flush() completes.
shadowOf(callbackThreadLooper).idle(); shadowOf(callbackThreadLooper).idle();
...@@ -302,7 +302,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -302,7 +302,7 @@ public class AsynchronousMediaCodecCallbackTest {
MediaFormat pendingMediaFormat = new MediaFormat(); MediaFormat pendingMediaFormat = new MediaFormat();
asynchronousMediaCodecCallback.onOutputFormatChanged(codec, pendingMediaFormat); asynchronousMediaCodecCallback.onOutputFormatChanged(codec, pendingMediaFormat);
// flush() should not discard the last format. // flush() should not discard the last format.
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the callback looper so that flush() completes. // Progress the callback looper so that flush() completes.
shadowOf(callbackThreadLooper).idle(); shadowOf(callbackThreadLooper).idle();
...@@ -367,7 +367,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -367,7 +367,7 @@ public class AsynchronousMediaCodecCallbackTest {
asynchronousMediaCodecCallback.onOutputFormatChanged(codec, format); asynchronousMediaCodecCallback.onOutputFormatChanged(codec, format);
asynchronousMediaCodecCallback.dequeueOutputBufferIndex(new MediaCodec.BufferInfo()); asynchronousMediaCodecCallback.dequeueOutputBufferIndex(new MediaCodec.BufferInfo());
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the callback looper so that flush() completes. // Progress the callback looper so that flush() completes.
shadowOf(callbackThreadLooper).idle(); shadowOf(callbackThreadLooper).idle();
...@@ -390,7 +390,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -390,7 +390,7 @@ public class AsynchronousMediaCodecCallbackTest {
asynchronousMediaCodecCallback.onOutputFormatChanged(codec, createMediaFormat("format1")); asynchronousMediaCodecCallback.onOutputFormatChanged(codec, createMediaFormat("format1"));
asynchronousMediaCodecCallback.onOutputBufferAvailable( asynchronousMediaCodecCallback.onOutputBufferAvailable(
codec, /* index= */ 1, new MediaCodec.BufferInfo()); codec, /* index= */ 1, new MediaCodec.BufferInfo());
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true)); new Handler(callbackThreadLooper).post(() -> flushCompleted.set(true));
// Progress the looper so that flush is completed // Progress the looper so that flush is completed
shadowCallbackLooper.idle(); shadowCallbackLooper.idle();
...@@ -419,11 +419,11 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -419,11 +419,11 @@ public class AsynchronousMediaCodecCallbackTest {
asynchronousMediaCodecCallback.onOutputBufferAvailable( asynchronousMediaCodecCallback.onOutputBufferAvailable(
codec, /* index= */ 0, new MediaCodec.BufferInfo()); codec, /* index= */ 0, new MediaCodec.BufferInfo());
// Flush and progress the looper so that flush is completed. // Flush and progress the looper so that flush is completed.
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
callbackThreadHandler.post(flushCompleted::incrementAndGet); callbackThreadHandler.post(flushCompleted::incrementAndGet);
shadowCallbackLooper.idle(); shadowCallbackLooper.idle();
// Flush again, the pending format from the first flush should remain as pending. // Flush again, the pending format from the first flush should remain as pending.
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
callbackThreadHandler.post(flushCompleted::incrementAndGet); callbackThreadHandler.post(flushCompleted::incrementAndGet);
shadowCallbackLooper.idle(); shadowCallbackLooper.idle();
asynchronousMediaCodecCallback.onOutputBufferAvailable( asynchronousMediaCodecCallback.onOutputBufferAvailable(
...@@ -441,7 +441,7 @@ public class AsynchronousMediaCodecCallbackTest { ...@@ -441,7 +441,7 @@ public class AsynchronousMediaCodecCallbackTest {
public void flush_withPendingError_resetsError() throws Exception { public void flush_withPendingError_resetsError() throws Exception {
asynchronousMediaCodecCallback.onError(codec, createCodecException()); asynchronousMediaCodecCallback.onError(codec, createCodecException());
// Calling flush should clear any pending error. // Calling flush should clear any pending error.
asynchronousMediaCodecCallback.flush(/* codec= */ null); asynchronousMediaCodecCallback.flush();
assertThat(asynchronousMediaCodecCallback.dequeueInputBufferIndex()) assertThat(asynchronousMediaCodecCallback.dequeueInputBufferIndex())
.isEqualTo(MediaCodec.INFO_TRY_AGAIN_LATER); .isEqualTo(MediaCodec.INFO_TRY_AGAIN_LATER);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment