Remove need to call setVideoEffects before initialize in sink provider
PiperOrigin-RevId: 624869759
This commit is contained in:
parent
fa0fb38ca6
commit
df3c245250
@ -201,6 +201,7 @@ public final class CompositingVideoSinkProvider
|
|||||||
private final CopyOnWriteArraySet<CompositingVideoSinkProvider.Listener> listeners;
|
private final CopyOnWriteArraySet<CompositingVideoSinkProvider.Listener> listeners;
|
||||||
|
|
||||||
private Clock clock;
|
private Clock clock;
|
||||||
|
private List<Effect> videoEffects;
|
||||||
private @MonotonicNonNull VideoFrameReleaseControl videoFrameReleaseControl;
|
private @MonotonicNonNull VideoFrameReleaseControl videoFrameReleaseControl;
|
||||||
private @MonotonicNonNull VideoFrameRenderControl videoFrameRenderControl;
|
private @MonotonicNonNull VideoFrameRenderControl videoFrameRenderControl;
|
||||||
private @MonotonicNonNull Format outputFormat;
|
private @MonotonicNonNull Format outputFormat;
|
||||||
@ -208,15 +209,15 @@ public final class CompositingVideoSinkProvider
|
|||||||
private @MonotonicNonNull HandlerWrapper handler;
|
private @MonotonicNonNull HandlerWrapper handler;
|
||||||
private @MonotonicNonNull PreviewingVideoGraph videoGraph;
|
private @MonotonicNonNull PreviewingVideoGraph videoGraph;
|
||||||
private @MonotonicNonNull VideoSinkImpl videoSinkImpl;
|
private @MonotonicNonNull VideoSinkImpl videoSinkImpl;
|
||||||
private @MonotonicNonNull List<Effect> videoEffects;
|
|
||||||
@Nullable private Pair<Surface, Size> currentSurfaceAndSize;
|
@Nullable private Pair<Surface, Size> currentSurfaceAndSize;
|
||||||
private int pendingFlushCount;
|
private int pendingFlushCount;
|
||||||
private @State int state;
|
private @State int state;
|
||||||
|
|
||||||
private CompositingVideoSinkProvider(Builder builder) {
|
private CompositingVideoSinkProvider(Builder builder) {
|
||||||
this.context = builder.context;
|
this.context = builder.context;
|
||||||
this.previewingVideoGraphFactory = checkStateNotNull(builder.previewingVideoGraphFactory);
|
videoEffects = ImmutableList.of();
|
||||||
this.listeners = new CopyOnWriteArraySet<>();
|
previewingVideoGraphFactory = checkStateNotNull(builder.previewingVideoGraphFactory);
|
||||||
|
listeners = new CopyOnWriteArraySet<>();
|
||||||
clock = Clock.DEFAULT;
|
clock = Clock.DEFAULT;
|
||||||
state = STATE_CREATED;
|
state = STATE_CREATED;
|
||||||
}
|
}
|
||||||
@ -280,7 +281,6 @@ public final class CompositingVideoSinkProvider
|
|||||||
@Override
|
@Override
|
||||||
public void initialize(Format sourceFormat) throws VideoSink.VideoSinkException {
|
public void initialize(Format sourceFormat) throws VideoSink.VideoSinkException {
|
||||||
checkState(state == STATE_CREATED);
|
checkState(state == STATE_CREATED);
|
||||||
checkStateNotNull(videoEffects);
|
|
||||||
checkState(videoFrameRenderControl != null && videoFrameReleaseControl != null);
|
checkState(videoFrameRenderControl != null && videoFrameReleaseControl != null);
|
||||||
|
|
||||||
// Lazily initialize the handler here so it's initialized on the playback looper.
|
// Lazily initialize the handler here so it's initialized on the playback looper.
|
||||||
@ -317,7 +317,9 @@ public final class CompositingVideoSinkProvider
|
|||||||
} catch (VideoFrameProcessingException e) {
|
} catch (VideoFrameProcessingException e) {
|
||||||
throw new VideoSink.VideoSinkException(e, sourceFormat);
|
throw new VideoSink.VideoSinkException(e, sourceFormat);
|
||||||
}
|
}
|
||||||
videoSinkImpl.setVideoEffects(checkNotNull(videoEffects));
|
if (!videoEffects.isEmpty()) {
|
||||||
|
videoSinkImpl.setVideoEffects(videoEffects);
|
||||||
|
}
|
||||||
addListener(videoSinkImpl);
|
addListener(videoSinkImpl);
|
||||||
state = STATE_INITIALIZED;
|
state = STATE_INITIALIZED;
|
||||||
}
|
}
|
||||||
|
@ -63,8 +63,7 @@ public interface VideoSinkProvider {
|
|||||||
void setPendingVideoEffects(List<Effect> videoEffects);
|
void setPendingVideoEffects(List<Effect> videoEffects);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the provider for video frame processing. Can be called up to one time and only
|
* Initializes the provider for video frame processing. Can be called up to one time.
|
||||||
* after video effects are {@linkplain #setVideoEffects(List) set}.
|
|
||||||
*
|
*
|
||||||
* @param sourceFormat The format of the compressed video.
|
* @param sourceFormat The format of the compressed video.
|
||||||
* @throws VideoSink.VideoSinkException If enabling the provider failed.
|
* @throws VideoSink.VideoSinkException If enabling the provider failed.
|
||||||
|
@ -30,7 +30,6 @@ import androidx.media3.common.VideoFrameProcessor;
|
|||||||
import androidx.media3.common.VideoGraph;
|
import androidx.media3.common.VideoGraph;
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -54,26 +53,15 @@ public final class CompositingVideoSinkProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void initialize() throws VideoSink.VideoSinkException {
|
public void initialize() throws VideoSink.VideoSinkException {
|
||||||
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
||||||
provider.setVideoEffects(ImmutableList.of());
|
|
||||||
|
|
||||||
provider.initialize(new Format.Builder().build());
|
provider.initialize(new Format.Builder().build());
|
||||||
|
|
||||||
assertThat(provider.isInitialized()).isTrue();
|
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
|
@Test
|
||||||
public void initialize_calledTwice_throws() throws VideoSink.VideoSinkException {
|
public void initialize_calledTwice_throws() throws VideoSink.VideoSinkException {
|
||||||
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
||||||
provider.setVideoEffects(ImmutableList.of());
|
|
||||||
provider.initialize(new Format.Builder().build());
|
provider.initialize(new Format.Builder().build());
|
||||||
|
|
||||||
assertThrows(
|
assertThrows(
|
||||||
@ -83,7 +71,6 @@ public final class CompositingVideoSinkProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void isInitialized_afterRelease_returnsFalse() throws VideoSink.VideoSinkException {
|
public void isInitialized_afterRelease_returnsFalse() throws VideoSink.VideoSinkException {
|
||||||
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
||||||
provider.setVideoEffects(ImmutableList.of());
|
|
||||||
provider.initialize(new Format.Builder().build());
|
provider.initialize(new Format.Builder().build());
|
||||||
|
|
||||||
provider.release();
|
provider.release();
|
||||||
@ -94,7 +81,6 @@ public final class CompositingVideoSinkProviderTest {
|
|||||||
@Test
|
@Test
|
||||||
public void initialize_afterRelease_throws() throws VideoSink.VideoSinkException {
|
public void initialize_afterRelease_throws() throws VideoSink.VideoSinkException {
|
||||||
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
||||||
provider.setVideoEffects(ImmutableList.of());
|
|
||||||
Format format = new Format.Builder().build();
|
Format format = new Format.Builder().build();
|
||||||
|
|
||||||
provider.initialize(format);
|
provider.initialize(format);
|
||||||
@ -107,7 +93,6 @@ public final class CompositingVideoSinkProviderTest {
|
|||||||
public void setOutputStreamOffsetUs_frameReleaseTimesAreAdjusted()
|
public void setOutputStreamOffsetUs_frameReleaseTimesAreAdjusted()
|
||||||
throws VideoSink.VideoSinkException {
|
throws VideoSink.VideoSinkException {
|
||||||
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
CompositingVideoSinkProvider provider = createCompositingVideoSinkProvider();
|
||||||
provider.setVideoEffects(ImmutableList.of());
|
|
||||||
provider.initialize(new Format.Builder().build());
|
provider.initialize(new Format.Builder().build());
|
||||||
VideoSink videoSink = provider.getSink();
|
VideoSink videoSink = provider.getSink();
|
||||||
videoSink.registerInputStream(
|
videoSink.registerInputStream(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user