Effect: Minimize calls to configure in default impl.
In case BaseShaderProgram implementations have an expensive configure() call, we can only call configure() when absolutely necessary, aka when the input size changes. To reduce scope, this doesn't reduce the amount of configure() calls that may be made outside this class, in DefaultFrameDroppingShaderProgram and FinalShaderProgramWrapper. PiperOrigin-RevId: 558754314
This commit is contained in:
parent
153740386a
commit
59744fe788
@ -16,6 +16,7 @@
|
|||||||
package androidx.media3.effect;
|
package androidx.media3.effect;
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.GlObjectsProvider;
|
import androidx.media3.common.GlObjectsProvider;
|
||||||
import androidx.media3.common.GlTextureInfo;
|
import androidx.media3.common.GlTextureInfo;
|
||||||
import androidx.media3.common.VideoFrameProcessingException;
|
import androidx.media3.common.VideoFrameProcessingException;
|
||||||
@ -46,6 +47,8 @@ public abstract class BaseGlShaderProgram implements GlShaderProgram {
|
|||||||
private OutputListener outputListener;
|
private OutputListener outputListener;
|
||||||
private ErrorListener errorListener;
|
private ErrorListener errorListener;
|
||||||
private Executor errorListenerExecutor;
|
private Executor errorListenerExecutor;
|
||||||
|
private int inputWidth;
|
||||||
|
private int inputHeight;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@code BaseGlShaderProgram} instance.
|
* Creates a {@code BaseGlShaderProgram} instance.
|
||||||
@ -61,6 +64,8 @@ public abstract class BaseGlShaderProgram implements GlShaderProgram {
|
|||||||
outputListener = new OutputListener() {};
|
outputListener = new OutputListener() {};
|
||||||
errorListener = (frameProcessingException) -> {};
|
errorListener = (frameProcessingException) -> {};
|
||||||
errorListenerExecutor = MoreExecutors.directExecutor();
|
errorListenerExecutor = MoreExecutors.directExecutor();
|
||||||
|
inputWidth = C.LENGTH_UNSET;
|
||||||
|
inputHeight = C.LENGTH_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -125,9 +130,15 @@ public abstract class BaseGlShaderProgram implements GlShaderProgram {
|
|||||||
public void queueInputFrame(
|
public void queueInputFrame(
|
||||||
GlObjectsProvider glObjectsProvider, GlTextureInfo inputTexture, long presentationTimeUs) {
|
GlObjectsProvider glObjectsProvider, GlTextureInfo inputTexture, long presentationTimeUs) {
|
||||||
try {
|
try {
|
||||||
Size outputTextureSize = configure(inputTexture.width, inputTexture.height);
|
if (inputWidth != inputTexture.width
|
||||||
outputTexturePool.ensureConfigured(
|
|| inputHeight != inputTexture.height
|
||||||
glObjectsProvider, outputTextureSize.getWidth(), outputTextureSize.getHeight());
|
|| !outputTexturePool.isConfigured()) {
|
||||||
|
inputWidth = inputTexture.width;
|
||||||
|
inputHeight = inputTexture.height;
|
||||||
|
Size outputTextureSize = configure(inputTexture.width, inputTexture.height);
|
||||||
|
outputTexturePool.ensureConfigured(
|
||||||
|
glObjectsProvider, outputTextureSize.getWidth(), outputTextureSize.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
// Focus on the next free buffer.
|
// Focus on the next free buffer.
|
||||||
GlTextureInfo outputTexture = outputTexturePool.useTexture();
|
GlTextureInfo outputTexture = outputTexturePool.useTexture();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user