Fix availableFrameCount semantic

`availableFrameCount` tracks the number of frames that is avilable on the
`SurfaceTexture`, but haven't been used (by `updateTexImage()`) yet. Thus
semantically this counter should only be decremented after calling
`updateTexImage()`, not before it.

Also reworded `getPendingFrameCount()` javadoc, "external texture" is an
internal state that is not publicised anywhere.

PiperOrigin-RevId: 488765174
This commit is contained in:
claincly 2022-11-15 22:48:54 +00:00 committed by microkatz
parent 53cff556bf
commit b4efd20843

View File

@ -15,7 +15,7 @@
*/
package androidx.media3.effect;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkStateNotNull;
import android.graphics.SurfaceTexture;
import androidx.annotation.Nullable;
@ -118,7 +118,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* Returns the number of {@linkplain #registerInputFrame(FrameInfo) registered} frames that have
* not been rendered to the external texture yet.
* not been sent to the downstream {@link ExternalTextureProcessor} yet.
*
* <p>Can be called on any thread.
*/
@ -151,11 +151,11 @@ import java.util.concurrent.atomic.AtomicInteger;
return;
}
availableFrameCount.getAndDecrement();
surfaceTexture.updateTexImage();
this.currentFrame = pendingFrames.remove();
availableFrameCount.getAndDecrement();
this.currentFrame = pendingFrames.peek();
FrameInfo currentFrame = checkNotNull(this.currentFrame);
FrameInfo currentFrame = checkStateNotNull(this.currentFrame);
externalTextureProcessorInputCapacity.getAndDecrement();
surfaceTexture.getTransformMatrix(textureTransformMatrix);
externalTextureProcessor.setTextureTransformMatrix(textureTransformMatrix);
@ -173,6 +173,7 @@ import java.util.concurrent.atomic.AtomicInteger;
new TextureInfo(
externalTexId, /* fboId= */ C.INDEX_UNSET, currentFrame.width, currentFrame.height),
presentationTimeUs);
checkStateNotNull(pendingFrames.remove());
if (inputStreamEnded && pendingFrames.isEmpty()) {
externalTextureProcessor.signalEndOfCurrentInputStream();