Handle output size changes inside DefaultVideoSink

PiperOrigin-RevId: 686507112
This commit is contained in:
kimvde 2024-10-16 07:56:23 -07:00 committed by Copybara-Service
parent 6afebf4c7d
commit 363f71357b
3 changed files with 12 additions and 8 deletions

View file

@ -33,11 +33,14 @@ import java.util.concurrent.Executor;
private final VideoFrameReleaseControl videoFrameReleaseControl;
private final VideoFrameRenderControl videoFrameRenderControl;
private Format inputFormat;
public DefaultVideoSink(
VideoFrameReleaseControl videoFrameReleaseControl,
VideoFrameRenderControl videoFrameRenderControl) {
this.videoFrameReleaseControl = videoFrameReleaseControl;
this.videoFrameRenderControl = videoFrameRenderControl;
inputFormat = new Format.Builder().build();
}
@Override
@ -149,7 +152,10 @@ import java.util.concurrent.Executor;
@Override
public void onInputStreamChanged(@InputType int inputType, Format format) {
throw new UnsupportedOperationException();
if (format.width != inputFormat.width || format.height != inputFormat.height) {
videoFrameRenderControl.onOutputSizeChanged(format.width, format.height);
}
inputFormat = format;
}
@Override

View file

@ -18,6 +18,7 @@ package androidx.media3.exoplayer.video;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import static androidx.media3.exoplayer.video.VideoSink.INPUT_TYPE_SURFACE;
import static java.lang.annotation.ElementType.TYPE_USE;
import android.content.Context;
@ -334,8 +335,9 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
@Override
public void onOutputSizeChanged(int width, int height) {
// We forward output size changes to render control even if we are still flushing.
videoFrameRenderControl.onOutputSizeChanged(width, height);
// We forward output size changes to the sink even if we are still flushing.
Format format = new Format.Builder().setWidth(width).setHeight(height).build();
defaultVideoSink.onInputStreamChanged(INPUT_TYPE_SURFACE, format);
}
@Override

View file

@ -25,7 +25,6 @@ import androidx.media3.common.VideoFrameProcessor;
import androidx.media3.common.VideoSize;
import androidx.media3.common.util.LongArrayQueue;
import androidx.media3.common.util.TimedValueQueue;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.ExoPlaybackException;
/** Controls rendering of video frames. */
@ -181,10 +180,7 @@ import androidx.media3.exoplayer.ExoPlaybackException;
/** Called when the size of the available frames has changed. */
public void onOutputSizeChanged(int width, int height) {
VideoSize newVideoSize = new VideoSize(width, height);
if (!Util.areEqual(pendingOutputVideoSize, newVideoSize)) {
pendingOutputVideoSize = newVideoSize;
}
pendingOutputVideoSize = new VideoSize(width, height);
}
/**