Effect: Only allow setExecutorService with @NonNull values.

PiperOrigin-RevId: 546828814
This commit is contained in:
huangdarwin 2023-07-10 12:15:26 +01:00 committed by Rohit Singh
parent d6f20455ac
commit 7c9e6ad2ea
2 changed files with 11 additions and 10 deletions

View file

@ -105,7 +105,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
public static final class Builder {
private boolean enableColorTransfers;
private @MonotonicNonNull GlObjectsProvider glObjectsProvider;
@Nullable private ExecutorService executorService;
private @MonotonicNonNull ExecutorService executorService;
private @MonotonicNonNull TextureOutputListener textureOutputListener;
private int textureOutputCapacity;
@ -139,8 +139,9 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
/**
* Sets the {@link Util#newSingleThreadScheduledExecutor} to execute GL commands from.
*
* <p>If set and non-null, the {@link ExecutorService} must be {@link
* ExecutorService#shutdown} by the caller.
* <p>If set, the {@link ExecutorService} must be {@linkplain ExecutorService#shutdown shut
* down} by the caller after all {@linkplain VideoFrameProcessor VideoFrameProcessors} using
* it have been {@linkplain #release released}.
*
* <p>The default value is a new {@link Util#newSingleThreadScheduledExecutor}, owned and
* {@link ExecutorService#shutdown} by the created {@link DefaultVideoFrameProcessor}.
@ -149,7 +150,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
*/
@CanIgnoreReturnValue
@VisibleForTesting(otherwise = PACKAGE_PRIVATE)
public Builder setExecutorService(@Nullable ExecutorService executorService) {
public Builder setExecutorService(ExecutorService executorService) {
this.executorService = executorService;
return this;
}

View file

@ -32,7 +32,6 @@ import androidx.media3.common.Effect;
import androidx.media3.common.GlObjectsProvider;
import androidx.media3.common.GlTextureInfo;
import androidx.media3.common.VideoFrameProcessingException;
import androidx.media3.common.VideoFrameProcessor;
import androidx.media3.common.util.GlUtil;
import androidx.media3.common.util.Util;
import androidx.media3.effect.DefaultGlObjectsProvider;
@ -212,7 +211,7 @@ public final class VideoCompositorPixelTest {
@Nullable ExecutorService executorService,
GlObjectsProvider glObjectsProvider) {
int inputId = videoCompositor.registerInputSource();
VideoFrameProcessor.Factory defaultVideoFrameProcessorFactory =
DefaultVideoFrameProcessor.Factory.Builder defaultVideoFrameProcessorFactoryBuilder =
new DefaultVideoFrameProcessor.Factory.Builder()
.setGlObjectsProvider(glObjectsProvider)
.setTextureOutput(
@ -226,12 +225,13 @@ public final class VideoCompositorPixelTest {
videoCompositor.queueInputTexture(
inputId, outputTexture, presentationTimeUs, releaseOutputTextureCallback);
},
/* textureOutputCapacity= */ 1)
.setExecutorService(executorService)
.build();
/* textureOutputCapacity= */ 1);
if (executorService != null) {
defaultVideoFrameProcessorFactoryBuilder.setExecutorService(executorService);
}
return new VideoFrameProcessorTestRunner.Builder()
.setTestId(testId)
.setVideoFrameProcessorFactory(defaultVideoFrameProcessorFactory)
.setVideoFrameProcessorFactory(defaultVideoFrameProcessorFactoryBuilder.build())
.setInputType(INPUT_TYPE_BITMAP)
.setInputColorInfo(ColorInfo.SRGB_BT709_FULL)
.setBitmapReader(textureBitmapReader);