Fix a bug that video effects are added twice

The tests passed because of an issue in chaining. The chaining listener allows
self-looping, i.e. the producer and the consumer of a frame could be the same
instance. Like an effect chain of `a -> a -> b` This didn't fail any test
before, because the chaining is rectified when connecting a to b, but it should
have failed when connecting a to a.

PiperOrigin-RevId: 742215700
This commit is contained in:
claincly 2025-03-31 04:20:45 -07:00 committed by Copybara-Service
parent 73fa820828
commit ff6537d69b
2 changed files with 7 additions and 19 deletions

View File

@ -15,6 +15,8 @@
*/
package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkArgument;
import androidx.media3.common.GlObjectsProvider;
import androidx.media3.common.GlTextureInfo;
import androidx.media3.effect.GlShaderProgram.InputListener;
@ -51,6 +53,9 @@ import androidx.media3.effect.GlShaderProgram.OutputListener;
GlShaderProgram producingGlShaderProgram,
GlShaderProgram consumingGlShaderProgram,
VideoFrameProcessingTaskExecutor videoFrameProcessingTaskExecutor) {
checkArgument(
producingGlShaderProgram != consumingGlShaderProgram,
"Creating a self loop in the chain: " + producingGlShaderProgram);
this.producingGlShaderProgram = producingGlShaderProgram;
frameConsumptionManager =
new FrameConsumptionManager(

View File

@ -782,7 +782,7 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
@FirstFrameReleaseInstruction int firstFrameReleaseInstruction,
List<Effect> videoEffects) {
checkState(isInitialized());
setPendingVideoEffects(videoEffects);
this.videoEffects = ImmutableList.copyOf(videoEffects);
this.inputType = inputType;
this.inputFormat = format;
finalBufferPresentationTimeUs = C.TIME_UNSET;
@ -863,7 +863,7 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
if (this.videoEffects.equals(videoEffects)) {
return;
}
setPendingVideoEffects(videoEffects);
this.videoEffects = ImmutableList.copyOf(videoEffects);
if (inputFormat != null) {
registerInputStream(inputFormat);
}
@ -999,23 +999,6 @@ public final class PlaybackVideoGraphWrapper implements VideoSinkProvider, Video
// Private methods
/**
* Sets the pending video effects.
*
* <p>Effects are pending until a new input stream is registered.
*/
private void setPendingVideoEffects(List<Effect> newVideoEffects) {
if (videoGraphFactory.supportsMultipleInputs()) {
this.videoEffects = ImmutableList.copyOf(newVideoEffects);
} else {
this.videoEffects =
new ImmutableList.Builder<Effect>()
.addAll(newVideoEffects)
.addAll(compositionEffects)
.build();
}
}
private void registerInputStream(Format inputFormat) {
Format adjustedInputFormat =
inputFormat