Remove experimental synchronization on async buffer queuing

PiperOrigin-RevId: 591273508
This commit is contained in:
tonihei 2023-12-15 09:12:17 -08:00 committed by Copybara-Service
parent 29d7dd1ec9
commit f47c4e33ec
4 changed files with 8 additions and 73 deletions

View File

@ -163,22 +163,6 @@ public class DefaultRenderersFactory implements RenderersFactory {
return this;
}
/**
* Enable synchronizing codec interactions with asynchronous buffer queueing.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param enabled Whether codec interactions will be synchronized with asynchronous buffer
* queueing.
* @return This factory, for convenience.
*/
@CanIgnoreReturnValue
public DefaultRenderersFactory experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled(
boolean enabled) {
codecAdapterFactory.experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled(enabled);
return this;
}
/**
* 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.

View File

@ -53,35 +53,27 @@ import java.nio.ByteBuffer;
public static final class Factory implements MediaCodecAdapter.Factory {
private final Supplier<HandlerThread> callbackThreadSupplier;
private final Supplier<HandlerThread> queueingThreadSupplier;
private final boolean synchronizeCodecInteractionsWithQueueing;
/**
* Creates an factory for {@link AsynchronousMediaCodecAdapter} instances.
*
* @param trackType One of {@link C#TRACK_TYPE_AUDIO} or {@link C#TRACK_TYPE_VIDEO}. Used for
* labelling the internal thread accordingly.
* @param synchronizeCodecInteractionsWithQueueing Whether the adapter should synchronize {@link
* MediaCodec} interactions with asynchronous buffer queueing. When {@code true}, codec
* interactions will wait until all input buffers pending queueing wil be submitted to the
* {@link MediaCodec}.
*/
public Factory(@C.TrackType int trackType, boolean synchronizeCodecInteractionsWithQueueing) {
public Factory(@C.TrackType int trackType) {
this(
/* callbackThreadSupplier= */ () ->
new HandlerThread(createCallbackThreadLabel(trackType)),
/* queueingThreadSupplier= */ () ->
new HandlerThread(createQueueingThreadLabel(trackType)),
synchronizeCodecInteractionsWithQueueing);
new HandlerThread(createQueueingThreadLabel(trackType)));
}
@VisibleForTesting
/* package */ Factory(
Supplier<HandlerThread> callbackThreadSupplier,
Supplier<HandlerThread> queueingThreadSupplier,
boolean synchronizeCodecInteractionsWithQueueing) {
Supplier<HandlerThread> queueingThreadSupplier) {
this.callbackThreadSupplier = callbackThreadSupplier;
this.queueingThreadSupplier = queueingThreadSupplier;
this.synchronizeCodecInteractionsWithQueueing = synchronizeCodecInteractionsWithQueueing;
}
@Override
@ -95,10 +87,7 @@ import java.nio.ByteBuffer;
codec = MediaCodec.createByCodecName(codecName);
codecAdapter =
new AsynchronousMediaCodecAdapter(
codec,
callbackThreadSupplier.get(),
queueingThreadSupplier.get(),
synchronizeCodecInteractionsWithQueueing);
codec, callbackThreadSupplier.get(), queueingThreadSupplier.get());
TraceUtil.endSection();
codecAdapter.initialize(
configuration.mediaFormat,
@ -130,19 +119,14 @@ import java.nio.ByteBuffer;
private final MediaCodec codec;
private final AsynchronousMediaCodecCallback asynchronousMediaCodecCallback;
private final AsynchronousMediaCodecBufferEnqueuer bufferEnqueuer;
private final boolean synchronizeCodecInteractionsWithQueueing;
private boolean codecReleased;
private @State int state;
private AsynchronousMediaCodecAdapter(
MediaCodec codec,
HandlerThread callbackThread,
HandlerThread enqueueingThread,
boolean synchronizeCodecInteractionsWithQueueing) {
MediaCodec codec, HandlerThread callbackThread, HandlerThread enqueueingThread) {
this.codec = codec;
this.asynchronousMediaCodecCallback = new AsynchronousMediaCodecCallback(callbackThread);
this.bufferEnqueuer = new AsynchronousMediaCodecBufferEnqueuer(codec, enqueueingThread);
this.synchronizeCodecInteractionsWithQueueing = synchronizeCodecInteractionsWithQueueing;
this.state = STATE_CREATED;
}
@ -250,7 +234,6 @@ import java.nio.ByteBuffer;
@Override
public void setOnFrameRenderedListener(OnFrameRenderedListener listener, Handler handler) {
maybeBlockOnQueueing();
codec.setOnFrameRenderedListener(
(codec, presentationTimeUs, nanoTime) ->
listener.onFrameRendered(
@ -260,26 +243,22 @@ import java.nio.ByteBuffer;
@Override
public void setOutputSurface(Surface surface) {
maybeBlockOnQueueing();
codec.setOutputSurface(surface);
}
@Override
public void setParameters(Bundle params) {
maybeBlockOnQueueing();
codec.setParameters(params);
}
@Override
public void setVideoScalingMode(@C.VideoScalingMode int scalingMode) {
maybeBlockOnQueueing();
codec.setVideoScalingMode(scalingMode);
}
@Override
@RequiresApi(26)
public PersistableBundle getMetrics() {
maybeBlockOnQueueing();
return codec.getMetrics();
}
@ -293,19 +272,6 @@ import java.nio.ByteBuffer;
asynchronousMediaCodecCallback.onOutputFormatChanged(codec, format);
}
private void maybeBlockOnQueueing() {
if (synchronizeCodecInteractionsWithQueueing) {
try {
bufferEnqueuer.waitUntilQueueingComplete();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
// The playback thread should not be interrupted. Raising this as an
// IllegalStateException.
throw new IllegalStateException(e);
}
}
}
private static String createCallbackThreadLabel(@C.TrackType int trackType) {
return createThreadLabel(trackType, /* prefix= */ "ExoPlayer:MediaCodecAsyncAdapter:");
}

View File

@ -54,7 +54,6 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter.
private static final String TAG = "DMCodecAdapterFactory";
private @Mode int asynchronousMode;
private boolean enableSynchronizeCodecInteractionsWithQueueing;
public DefaultMediaCodecAdapterFactory() {
asynchronousMode = MODE_DEFAULT;
@ -84,18 +83,6 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter.
return this;
}
/**
* Enable synchronizing codec interactions with asynchronous buffer queueing.
*
* <p>This method is experimental, and will be renamed or removed in a future release.
*
* @param enabled Whether codec interactions will be synchronized with asynchronous buffer
* queueing.
*/
public void experimentalSetSynchronizeCodecInteractionsWithQueueingEnabled(boolean enabled) {
enableSynchronizeCodecInteractionsWithQueueing = enabled;
}
@Override
public MediaCodecAdapter createAdapter(MediaCodecAdapter.Configuration configuration)
throws IOException {
@ -108,8 +95,7 @@ public final class DefaultMediaCodecAdapterFactory implements MediaCodecAdapter.
"Creating an asynchronous MediaCodec adapter for track type "
+ Util.getTrackTypeString(trackType));
AsynchronousMediaCodecAdapter.Factory factory =
new AsynchronousMediaCodecAdapter.Factory(
trackType, enableSynchronizeCodecInteractionsWithQueueing);
new AsynchronousMediaCodecAdapter.Factory(trackType);
return factory.createAdapter(configuration);
}
return new SynchronousMediaCodecAdapter.Factory().createAdapter(configuration);

View File

@ -53,8 +53,7 @@ public class AsynchronousMediaCodecAdapterTest {
adapter =
new AsynchronousMediaCodecAdapter.Factory(
/* callbackThreadSupplier= */ () -> callbackThread,
/* queueingThreadSupplier= */ () -> queueingThread,
/* synchronizeCodecInteractionsWithQueueing= */ false)
/* queueingThreadSupplier= */ () -> queueingThread)
.createAdapter(configuration);
bufferInfo = new MediaCodec.BufferInfo();
// After starting the MediaCodec, the ShadowMediaCodec offers input buffer 0. We advance the
@ -222,6 +221,6 @@ public class AsynchronousMediaCodecAdapterTest {
Integer.TYPE, Integer.TYPE, String.class);
constructor.setAccessible(true);
return constructor.newInstance(
/* errorCode= */ 0, /* actionCode= */ 0, /* detailMessage= */ "error from codec");
/* errorCode */ 0, /* actionCode */ 0, /* detailMessage */ "error from codec");
}
}