Remove need to call setVideoEffects before initialize in sink provider

PiperOrigin-RevId: 624869759
This commit is contained in:
kimvde 2024-04-15 01:24:06 -07:00 committed by Copybara-Service
parent fa0fb38ca6
commit df3c245250
3 changed files with 8 additions and 22 deletions

View File

@ -201,6 +201,7 @@ public final class CompositingVideoSinkProvider
private final CopyOnWriteArraySet<CompositingVideoSinkProvider.Listener> listeners;
private Clock clock;
private List<Effect> videoEffects;
private @MonotonicNonNull VideoFrameReleaseControl videoFrameReleaseControl;
private @MonotonicNonNull VideoFrameRenderControl videoFrameRenderControl;
private @MonotonicNonNull Format outputFormat;
@ -208,15 +209,15 @@ public final class CompositingVideoSinkProvider
private @MonotonicNonNull HandlerWrapper handler;
private @MonotonicNonNull PreviewingVideoGraph videoGraph;
private @MonotonicNonNull VideoSinkImpl videoSinkImpl;
private @MonotonicNonNull List<Effect> videoEffects;
@Nullable private Pair<Surface, Size> currentSurfaceAndSize;
private int pendingFlushCount;
private @State int state;
private CompositingVideoSinkProvider(Builder builder) {
this.context = builder.context;
this.previewingVideoGraphFactory = checkStateNotNull(builder.previewingVideoGraphFactory);
this.listeners = new CopyOnWriteArraySet<>();
videoEffects = ImmutableList.of();
previewingVideoGraphFactory = checkStateNotNull(builder.previewingVideoGraphFactory);
listeners = new CopyOnWriteArraySet<>();
clock = Clock.DEFAULT;
state = STATE_CREATED;
}
@ -280,7 +281,6 @@ public final class CompositingVideoSinkProvider
@Override
public void initialize(Format sourceFormat) throws VideoSink.VideoSinkException {
checkState(state == STATE_CREATED);
checkStateNotNull(videoEffects);
checkState(videoFrameRenderControl != null && videoFrameReleaseControl != null);
// Lazily initialize the handler here so it's initialized on the playback looper.
@ -317,7 +317,9 @@ public final class CompositingVideoSinkProvider
} catch (VideoFrameProcessingException e) {
throw new VideoSink.VideoSinkException(e, sourceFormat);
}
videoSinkImpl.setVideoEffects(checkNotNull(videoEffects));
if (!videoEffects.isEmpty()) {
videoSinkImpl.setVideoEffects(videoEffects);
}
addListener(videoSinkImpl);
state = STATE_INITIALIZED;
}

View File

@ -63,8 +63,7 @@ public interface VideoSinkProvider {
void setPendingVideoEffects(List<Effect> videoEffects);
/**
* Initializes the provider for video frame processing. Can be called up to one time and only
* after video effects are {@linkplain #setVideoEffects(List) set}.
* Initializes the provider for video frame processing. Can be called up to one time.
*
* @param sourceFormat The format of the compressed video.
* @throws VideoSink.VideoSinkException If enabling the provider failed.

View File

@ -30,7 +30,6 @@ import androidx.media3.common.VideoFrameProcessor;
import androidx.media3.common.VideoGraph;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList;
import java.util.List;
import java.util.concurrent.Executor;
import org.junit.Test;
@ -54,26 +53,15 @@ public final class CompositingVideoSinkProviderTest {
@Test
public void initialize() throws VideoSink.VideoSinkException {
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
provider.setVideoEffects(ImmutableList.of());
provider.initialize(new Format.Builder().build());
assertThat(provider.isInitialized()).isTrue();
}
@Test
public void initialize_withoutEffects_throws() {
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
assertThrows(
IllegalStateException.class,
() -> provider.initialize(new Format.Builder().setWidth(640).setHeight(480).build()));
}
@Test
public void initialize_calledTwice_throws() throws VideoSink.VideoSinkException {
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
provider.setVideoEffects(ImmutableList.of());
provider.initialize(new Format.Builder().build());
assertThrows(
@ -83,7 +71,6 @@ public final class CompositingVideoSinkProviderTest {
@Test
public void isInitialized_afterRelease_returnsFalse() throws VideoSink.VideoSinkException {
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
provider.setVideoEffects(ImmutableList.of());
provider.initialize(new Format.Builder().build());
provider.release();
@ -94,7 +81,6 @@ public final class CompositingVideoSinkProviderTest {
@Test
public void initialize_afterRelease_throws() throws VideoSink.VideoSinkException {
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
provider.setVideoEffects(ImmutableList.of());
Format format = new Format.Builder().build();
provider.initialize(format);
@ -107,7 +93,6 @@ public final class CompositingVideoSinkProviderTest {
public void setOutputStreamOffsetUs_frameReleaseTimesAreAdjusted()
throws VideoSink.VideoSinkException {
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
provider.setVideoEffects(ImmutableList.of());
provider.initialize(new Format.Builder().build());
VideoSink videoSink = provider.getSink();
videoSink.registerInputStream(