Effects: Have VFP texture output disable surface output.

Also, document that texture output disables manual frame release.

In the past, texture output would lead to surface output methods throwing. Now,
they're simply no-ops instead.

PiperOrigin-RevId: 534894168
(cherry picked from commit abf649cdfa367976517ee07f83ea805b60ed88a5)
This commit is contained in:
huangdarwin 2023-05-24 18:27:00 +01:00 committed by Tofunmi Adigun-Hameed
parent f59dac9d7d
commit 74a032d462
2 changed files with 19 additions and 14 deletions

View File

@ -136,10 +136,10 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
* regain capacity, output textures must be released using {@link * regain capacity, output textures must be released using {@link
* ReleaseOutputTextureCallback}. * ReleaseOutputTextureCallback}.
* *
* <p>If not set, there will be no texture output. * <p>If set, {@linkplain #setOutputSurfaceInfo} and {@link #renderOutputFrame} will be
* no-ops, and {@code renderFramesAutomatically} will behave as if it is set to {@code true}.
* *
* <p>This must not be set if the {@linkplain #setOutputSurfaceInfo output surface info} is * <p>If not set, there will be no texture output.
* also set.
* *
* @param textureOutputListener The {@link TextureOutputListener}. * @param textureOutputListener The {@link TextureOutputListener}.
* @param textureOutputCapacity The amount of output textures that may be allocated at a time * @param textureOutputCapacity The amount of output textures that may be allocated at a time
@ -211,6 +211,10 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
* *
* <p>If invoking the {@code listener} on {@link DefaultVideoFrameProcessor}'s internal thread * <p>If invoking the {@code listener} on {@link DefaultVideoFrameProcessor}'s internal thread
* is desired, pass a {@link MoreExecutors#directExecutor() direct listenerExecutor}. * is desired, pass a {@link MoreExecutors#directExecutor() direct listenerExecutor}.
*
* <p>If {@linkplain Factory.Builder#setTextureOutput texture output} is set, {@linkplain
* #setOutputSurfaceInfo} and {@link #renderOutputFrame} will be no-ops, and {@code
* renderFramesAutomatically} will behave as if it is set to {@code true}.
*/ */
@Override @Override
public DefaultVideoFrameProcessor create( public DefaultVideoFrameProcessor create(
@ -235,7 +239,7 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
if (inputColorInfo.colorSpace != outputColorInfo.colorSpace if (inputColorInfo.colorSpace != outputColorInfo.colorSpace
|| ColorInfo.isTransferHdr(inputColorInfo) != ColorInfo.isTransferHdr(outputColorInfo)) { || ColorInfo.isTransferHdr(inputColorInfo) != ColorInfo.isTransferHdr(outputColorInfo)) {
// GL Tone mapping is only implemented for BT2020 to BT709 and HDR to SDR (Gamma 2.2). // OpenGL tone mapping is only implemented for BT2020 to BT709 and HDR to SDR (Gamma 2.2).
// Gamma 2.2 is used instead of SMPTE 170M for SDR, despite MediaFormat's // Gamma 2.2 is used instead of SMPTE 170M for SDR, despite MediaFormat's
// COLOR_TRANSFER_SDR_VIDEO being defined as SMPTE 170M. This is to match // COLOR_TRANSFER_SDR_VIDEO being defined as SMPTE 170M. This is to match
// other known tone-mapping behavior within the Android ecosystem. // other known tone-mapping behavior within the Android ecosystem.
@ -444,8 +448,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* <p>This must not be set on an instance where {@linkplain Factory.Builder#setTextureOutput * <p>If {@linkplain Factory.Builder#setTextureOutput texture output} is set, calling this method
* texture output} is set. * will be a no-op.
*/ */
@Override @Override
public void setOutputSurfaceInfo(@Nullable SurfaceInfo outputSurfaceInfo) { public void setOutputSurfaceInfo(@Nullable SurfaceInfo outputSurfaceInfo) {
@ -455,8 +459,8 @@ public final class DefaultVideoFrameProcessor implements VideoFrameProcessor {
/** /**
* {@inheritDoc} * {@inheritDoc}
* *
* <p>This may also be used for rendering from an output texture, if a {@link * <p>If {@linkplain Factory.Builder#setTextureOutput texture output} is set, calling this method
* TextureOutputListener} {@linkplain Factory.Builder#setTextureOutput is set} * will be a no-op.
*/ */
@Override @Override
public void renderOutputFrame(long renderTimeNs) { public void renderOutputFrame(long renderTimeNs) {

View File

@ -266,6 +266,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
public void renderOutputFrame(long renderTimeNs) { public void renderOutputFrame(long renderTimeNs) {
if (textureOutputListener != null) {
return;
}
frameProcessingStarted = true; frameProcessingStarted = true;
checkState(!renderFramesAutomatically); checkState(!renderFramesAutomatically);
Pair<GlTextureInfo, Long> oldestAvailableFrame = availableFrames.remove(); Pair<GlTextureInfo, Long> oldestAvailableFrame = availableFrames.remove();
@ -275,13 +278,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
renderTimeNs); renderTimeNs);
} }
/** /** See {@link DefaultVideoFrameProcessor#setOutputSurfaceInfo} */
* Sets the output {@link SurfaceInfo}.
*
* @see VideoFrameProcessor#setOutputSurfaceInfo(SurfaceInfo)
*/
public synchronized void setOutputSurfaceInfo(@Nullable SurfaceInfo outputSurfaceInfo) { public synchronized void setOutputSurfaceInfo(@Nullable SurfaceInfo outputSurfaceInfo) {
checkState(textureOutputListener == null); if (textureOutputListener != null) {
return;
}
if (Util.areEqual(this.outputSurfaceInfo, outputSurfaceInfo)) { if (Util.areEqual(this.outputSurfaceInfo, outputSurfaceInfo)) {
return; return;
} }