Previewing: Allow inputColorInfo to change, from SDR to HDR.

This also fixes issue introduced by frames being released from a prior version of a
GlShaderProgram

Tested by seeking within a playlist with one SDR then one HDR video.

PiperOrigin-RevId: 599475959
This commit is contained in:
huangdarwin 2024-01-18 05:17:48 -08:00 committed by Copybara-Service
parent 0e66197419
commit 616cb943f0
7 changed files with 19 additions and 14 deletions

View File

@ -165,6 +165,14 @@ public abstract class BaseGlShaderProgram implements GlShaderProgram {
@Override
public void releaseOutputFrame(GlTextureInfo outputTexture) {
if (!outputTexturePool.isUsingTexture(outputTexture)) {
// This allows us to ignore outputTexture instances not associated with this
// BaseGlShaderProgram instance. This may happen if a BaseGlShaderProgram is introduced into
// the GlShaderProgram chain after frames already exist in the pipeline.
// TODO - b/320481157: Consider removing this if condition and disallowing disconnecting a
// GlShaderProgram while it still has in-use frames.
return;
}
outputTexturePool.freeTexture(outputTexture);
inputListener.onReadyToAcceptInputFrame();
}

View File

@ -76,6 +76,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override
public void setSamplingGlShaderProgram(GlShaderProgram samplingGlShaderProgram) {
downstreamShaderProgramCapacity = 0;
this.shaderProgram = samplingGlShaderProgram;
}

View File

@ -447,12 +447,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
* <p>If either {@link FrameInfo#colorInfo} or {@code outputColorInfo} {@linkplain
* ColorInfo#isTransferHdr} are HDR}, color transfers must {@linkplain
* Factory.Builder#setEnableColorTransfers be enabled}.
*
* <p>The {@link FrameInfo}'s {@link ColorInfo} must not change between different calls to this
* method.
*/
// TODO: b/307952514: After updating frameInfo.colorInfo works with flushing, remove relevant
// javadoc.
@Override
public void registerInputStream(
@InputType int inputType, List<Effect> effects, FrameInfo frameInfo) {

View File

@ -140,6 +140,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override
public void setSamplingGlShaderProgram(GlShaderProgram samplingGlShaderProgram) {
checkState(samplingGlShaderProgram instanceof ExternalShaderProgram);
externalShaderProgramInputCapacity.set(0);
this.externalShaderProgram = (ExternalShaderProgram) samplingGlShaderProgram;
}

View File

@ -69,8 +69,6 @@ import androidx.media3.common.util.TimestampIterator;
*
* <p>Must be called before any method that queues input or {@link
* #signalEndOfCurrentInputStream()}.
*
* <p>This must only be called once.
*/
public abstract void setSamplingGlShaderProgram(GlShaderProgram samplingGlShaderProgram);

View File

@ -105,6 +105,11 @@ import java.util.Queue;
freeTextures.add(textureInfo);
}
/** Returns whether the texture represented by {@code textureInfo} is in use. */
public boolean isUsingTexture(GlTextureInfo textureInfo) {
return inUseTextures.contains(textureInfo);
}
/**
* Frees the oldest in-use texture.
*

View File

@ -560,7 +560,6 @@ public final class CompositingVideoSinkProvider
@Nullable private Effect rotationEffect;
@Nullable private Format inputFormat;
private @MonotonicNonNull ColorInfo firstInputColorInfo;
private @InputType int inputType;
private long inputStreamOffsetUs;
private boolean pendingInputStreamOffsetChange;
@ -778,15 +777,13 @@ public final class CompositingVideoSinkProvider
}
effects.addAll(videoEffects);
Format inputFormat = checkNotNull(this.inputFormat);
if (firstInputColorInfo == null) {
// TODO: b/307952514 - Get inputColorInfo from inputFormat for each stream, after this value
// can change per-stream.
firstInputColorInfo = getAdjustedInputColorInfo(inputFormat.colorInfo);
}
videoFrameProcessor.registerInputStream(
inputType,
effects,
new FrameInfo.Builder(firstInputColorInfo, inputFormat.width, inputFormat.height)
new FrameInfo.Builder(
getAdjustedInputColorInfo(inputFormat.colorInfo),
inputFormat.width,
inputFormat.height)
.setPixelWidthHeightRatio(inputFormat.pixelWidthHeightRatio)
.build());
}