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

View file

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