Make VideoGraph and VideoFrameProcessor listener methods optional

PiperOrigin-RevId: 686833280
This commit is contained in:
kimvde 2024-10-17 02:35:21 -07:00 committed by Copybara-Service
parent d2ccace75c
commit 38c27d45f1
6 changed files with 10 additions and 57 deletions

View File

@ -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<Effect> effects, FrameInfo frameInfo);
default void onInputStreamRegistered(
@InputType int inputType, List<Effect> effects, FrameInfo frameInfo) {}
/**
* Called when the output size changes.
@ -155,7 +155,7 @@ public interface VideoFrameProcessor {
* <p>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 {
* <p>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() {}
}
/**

View File

@ -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 {
* <p>If this is called, the calling {@link VideoGraph} must immediately be {@linkplain
* #release() released}.
*/
void onError(VideoFrameProcessingException exception);
default void onError(VideoFrameProcessingException exception) {}
}
/**

View File

@ -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();

View File

@ -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);

View File

@ -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<Effect> effects,
FrameInfo frameInfo) {}
@Override
public void onOutputSizeChanged(int width, int height) {}
@Override
public void onOutputFrameAvailableForRendering(long presentationTimeUs) {}
@Override
public void onError(VideoFrameProcessingException exception) {

View File

@ -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<Effect> effects,
FrameInfo frameInfo) {}
@Override
public void onOutputSizeChanged(int width, int height) {
listenerExecutor.execute(() -> listener.onOutputSizeChanged(width, height));