From 38c27d45f14bd9a9df9bbcea7161a6a9d9b8005b Mon Sep 17 00:00:00 2001 From: kimvde Date: Thu, 17 Oct 2024 02:35:21 -0700 Subject: [PATCH] Make VideoGraph and VideoFrameProcessor listener methods optional PiperOrigin-RevId: 686833280 --- .../media3/common/VideoFrameProcessor.java | 12 +++++----- .../androidx/media3/common/VideoGraph.java | 8 +++---- .../DefaultVideoFrameProcessorTest.java | 24 ------------------- .../media3/effect/EffectsTestUtil.java | 3 --- .../effect/MultipleInputVideoGraph.java | 11 --------- .../media3/effect/SingleInputVideoGraph.java | 9 ------- 6 files changed, 10 insertions(+), 57 deletions(-) diff --git a/libraries/common/src/main/java/androidx/media3/common/VideoFrameProcessor.java b/libraries/common/src/main/java/androidx/media3/common/VideoFrameProcessor.java index 2fb1c9a17b..c5bcc6ab02 100644 --- a/libraries/common/src/main/java/androidx/media3/common/VideoFrameProcessor.java +++ b/libraries/common/src/main/java/androidx/media3/common/VideoFrameProcessor.java @@ -143,8 +143,8 @@ public interface VideoFrameProcessor { * @param effects The list of {@link Effect effects} to apply to the new input stream. * @param frameInfo The {@link FrameInfo} of the new input stream. */ - void onInputStreamRegistered( - @InputType int inputType, List effects, FrameInfo frameInfo); + default void onInputStreamRegistered( + @InputType int inputType, List effects, FrameInfo frameInfo) {} /** * Called when the output size changes. @@ -155,7 +155,7 @@ public interface VideoFrameProcessor { *

The output size may differ from the size specified using {@link * #setOutputSurfaceInfo(SurfaceInfo)}. */ - void onOutputSizeChanged(int width, int height); + default void onOutputSizeChanged(int width, int height) {} /** * Called when an output frame with the given {@code presentationTimeUs} becomes available for @@ -163,7 +163,7 @@ public interface VideoFrameProcessor { * * @param presentationTimeUs The presentation time of the frame, in microseconds. */ - void onOutputFrameAvailableForRendering(long presentationTimeUs); + default void onOutputFrameAvailableForRendering(long presentationTimeUs) {} /** * Called when an exception occurs during asynchronous video frame processing. @@ -171,10 +171,10 @@ public interface VideoFrameProcessor { *

If this is called, the calling {@link VideoFrameProcessor} must immediately be {@linkplain * VideoFrameProcessor#release() released}. */ - void onError(VideoFrameProcessingException exception); + default void onError(VideoFrameProcessingException exception) {} /** Called after the {@link VideoFrameProcessor} has rendered its final output frame. */ - void onEnded(); + default void onEnded() {} } /** diff --git a/libraries/common/src/main/java/androidx/media3/common/VideoGraph.java b/libraries/common/src/main/java/androidx/media3/common/VideoGraph.java index 8b82433736..52d2a2c2b1 100644 --- a/libraries/common/src/main/java/androidx/media3/common/VideoGraph.java +++ b/libraries/common/src/main/java/androidx/media3/common/VideoGraph.java @@ -33,7 +33,7 @@ public interface VideoGraph { * @param width The new output width in pixels. * @param height The new output width in pixels. */ - void onOutputSizeChanged(int width, int height); + default void onOutputSizeChanged(int width, int height) {} /** * Called when an output frame with the given {@code framePresentationTimeUs} becomes available @@ -41,14 +41,14 @@ public interface VideoGraph { * * @param framePresentationTimeUs The presentation time of the frame, in microseconds. */ - void onOutputFrameAvailableForRendering(long framePresentationTimeUs); + default void onOutputFrameAvailableForRendering(long framePresentationTimeUs) {} /** * Called after the {@link VideoGraph} has rendered its final output frame. * * @param finalFramePresentationTimeUs The timestamp of the last output frame, in microseconds. */ - void onEnded(long finalFramePresentationTimeUs); + default void onEnded(long finalFramePresentationTimeUs) {} /** * Called when an exception occurs during video frame processing. @@ -56,7 +56,7 @@ public interface VideoGraph { *

If this is called, the calling {@link VideoGraph} must immediately be {@linkplain * #release() released}. */ - void onError(VideoFrameProcessingException exception); + default void onError(VideoFrameProcessingException exception) {} } /** diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorTest.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorTest.java index 7d5bf63de5..0eb11fc4d4 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorTest.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/DefaultVideoFrameProcessorTest.java @@ -95,19 +95,10 @@ public class DefaultVideoFrameProcessorTest { inputStreamRegisteredCountDownLatch.countDown(); } - @Override - public void onOutputSizeChanged(int width, int height) {} - - @Override - public void onOutputFrameAvailableForRendering(long presentationTimeUs) {} - @Override public void onError(VideoFrameProcessingException exception) { videoFrameProcessingException.set(exception); } - - @Override - public void onEnded() {} }); CountDownLatch videoFrameProcessorConfigurationCountDownLatch = new CountDownLatch(1); @@ -157,19 +148,10 @@ public class DefaultVideoFrameProcessorTest { countDownLatch.countDown(); } - @Override - public void onOutputSizeChanged(int width, int height) {} - - @Override - public void onOutputFrameAvailableForRendering(long presentationTimeUs) {} - @Override public void onError(VideoFrameProcessingException exception) { videoFrameProcessingException.set(exception); } - - @Override - public void onEnded() {} }); InputStreamInfo stream1 = @@ -230,9 +212,6 @@ public class DefaultVideoFrameProcessorTest { inputStreamRegisteredCondition.open(); } - @Override - public void onOutputSizeChanged(int width, int height) {} - @Override public void onOutputFrameAvailableForRendering(long presentationTimeUs) { outputFrameCount++; @@ -313,9 +292,6 @@ public class DefaultVideoFrameProcessorTest { inputStreamRegisteredCountDownLatch.countDown(); } - @Override - public void onOutputSizeChanged(int width, int height) {} - @Override public void onOutputFrameAvailableForRendering(long presentationTimeUs) { outputFrameCount.incrementAndGet(); diff --git a/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectsTestUtil.java b/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectsTestUtil.java index 4acf111f22..644a85e78e 100644 --- a/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectsTestUtil.java +++ b/libraries/effect/src/androidTest/java/androidx/media3/effect/EffectsTestUtil.java @@ -138,9 +138,6 @@ import java.util.concurrent.atomic.AtomicReference; videoFrameProcessorReadyCountDownLatch.countDown(); } - @Override - public void onOutputSizeChanged(int width, int height) {} - @Override public void onOutputFrameAvailableForRendering(long presentationTimeUs) { actualPresentationTimesUs.add(presentationTimeUs); diff --git a/libraries/effect/src/main/java/androidx/media3/effect/MultipleInputVideoGraph.java b/libraries/effect/src/main/java/androidx/media3/effect/MultipleInputVideoGraph.java index 4a6fa05dec..8d4b696dc9 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/MultipleInputVideoGraph.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/MultipleInputVideoGraph.java @@ -249,17 +249,6 @@ public abstract class MultipleInputVideoGraph implements VideoGraph { listenerExecutor, new VideoFrameProcessor.Listener() { // All of this listener's methods are called on the sharedExecutorService. - @Override - public void onInputStreamRegistered( - @VideoFrameProcessor.InputType int inputType, - List effects, - FrameInfo frameInfo) {} - - @Override - public void onOutputSizeChanged(int width, int height) {} - - @Override - public void onOutputFrameAvailableForRendering(long presentationTimeUs) {} @Override public void onError(VideoFrameProcessingException exception) { diff --git a/libraries/effect/src/main/java/androidx/media3/effect/SingleInputVideoGraph.java b/libraries/effect/src/main/java/androidx/media3/effect/SingleInputVideoGraph.java index 16fbefd815..f3a80cf25a 100644 --- a/libraries/effect/src/main/java/androidx/media3/effect/SingleInputVideoGraph.java +++ b/libraries/effect/src/main/java/androidx/media3/effect/SingleInputVideoGraph.java @@ -25,15 +25,12 @@ import androidx.annotation.Nullable; import androidx.media3.common.C; import androidx.media3.common.ColorInfo; import androidx.media3.common.DebugViewProvider; -import androidx.media3.common.Effect; -import androidx.media3.common.FrameInfo; import androidx.media3.common.SurfaceInfo; import androidx.media3.common.VideoFrameProcessingException; import androidx.media3.common.VideoFrameProcessor; import androidx.media3.common.VideoGraph; import androidx.media3.common.util.UnstableApi; import com.google.common.util.concurrent.MoreExecutors; -import java.util.List; import java.util.concurrent.Executor; /** A {@link VideoGraph} that handles one input stream. */ @@ -112,12 +109,6 @@ public abstract class SingleInputVideoGraph implements VideoGraph { new VideoFrameProcessor.Listener() { private long lastProcessedFramePresentationTimeUs; - @Override - public void onInputStreamRegistered( - @VideoFrameProcessor.InputType int inputType, - List effects, - FrameInfo frameInfo) {} - @Override public void onOutputSizeChanged(int width, int height) { listenerExecutor.execute(() -> listener.onOutputSizeChanged(width, height));