TextureInput: Advise client to delete syncObject after use

PiperOrigin-RevId: 544670927
This commit is contained in:
tofunmi 2023-06-30 16:04:49 +00:00 committed by microkatz
parent 58180a0f2a
commit 6f9731ce7e
4 changed files with 10 additions and 14 deletions

View File

@ -27,7 +27,8 @@ public interface OnInputFrameProcessedListener {
* @param textureId The identifier of the processed texture. * @param textureId The identifier of the processed texture.
* @param syncObject A GL sync object that has been inserted into the GL command stream after the * @param syncObject A GL sync object that has been inserted into the GL command stream after the
* last write of texture. Value is 0 if and only if the {@code GLES30#glFenceSync} failed or * last write of texture. Value is 0 if and only if the {@code GLES30#glFenceSync} failed or
* the EGL context version is less than openGL 3.0. * the EGL context version is less than openGL 3.0. The sync object must be {@link
* androidx.media3.common.util.GlUtil#deleteSyncObject deleted} after use.
*/ */
void onInputFrameProcessed(int textureId, long syncObject) throws VideoFrameProcessingException; void onInputFrameProcessed(int textureId, long syncObject) throws VideoFrameProcessingException;
} }

View File

@ -40,7 +40,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
private @MonotonicNonNull OnInputFrameProcessedListener frameProcessedListener; private @MonotonicNonNull OnInputFrameProcessedListener frameProcessedListener;
private @MonotonicNonNull FrameInfo inputFrameInfo; private @MonotonicNonNull FrameInfo inputFrameInfo;
private long glSyncObject;
/** /**
* Creates a new instance. * Creates a new instance.
@ -68,11 +67,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override @Override
public void onInputFrameProcessed(GlTextureInfo inputTexture) { public void onInputFrameProcessed(GlTextureInfo inputTexture) {
videoFrameProcessingTaskExecutor.submit( videoFrameProcessingTaskExecutor.submit(
() -> { () ->
glSyncObject = GlUtil.createGlSyncFence(); checkNotNull(frameProcessedListener)
checkNotNull(frameProcessedListener) .onInputFrameProcessed(inputTexture.getTexId(), GlUtil.createGlSyncFence()));
.onInputFrameProcessed(inputTexture.getTexId(), glSyncObject);
});
} }
@Override @Override
@ -128,10 +125,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
@Override @Override
public void release() throws VideoFrameProcessingException { public void release() throws VideoFrameProcessingException {
try { // Do nothing.
GlUtil.deleteSyncObject(glSyncObject);
} catch (GlUtil.GlException e) {
throw new VideoFrameProcessingException(e);
}
} }
} }

View File

@ -354,9 +354,10 @@ public final class VideoFrameProcessorTestRunner {
.setPixelWidthHeightRatio(pixelWidthHeightRatio) .setPixelWidthHeightRatio(pixelWidthHeightRatio)
.build()); .build());
videoFrameProcessor.setOnInputFrameProcessedListener( videoFrameProcessor.setOnInputFrameProcessedListener(
(texId, unused) -> { (texId, syncObject) -> {
try { try {
GlUtil.deleteTexture(texId); GlUtil.deleteTexture(texId);
GlUtil.deleteSyncObject(syncObject);
} catch (GlUtil.GlException e) { } catch (GlUtil.GlException e) {
throw new VideoFrameProcessingException(e); throw new VideoFrameProcessingException(e);
} }

View File

@ -503,9 +503,10 @@ public class TransformerEndToEndTest {
EditedMediaItem editedMediaItem, Looper looper, AssetLoader.Listener listener) { EditedMediaItem editedMediaItem, Looper looper, AssetLoader.Listener listener) {
Format format = new Format.Builder().setWidth(width).setHeight(height).build(); Format format = new Format.Builder().setWidth(width).setHeight(height).build();
OnInputFrameProcessedListener frameProcessedListener = OnInputFrameProcessedListener frameProcessedListener =
(texId, unused) -> { (texId, syncObject) -> {
try { try {
GlUtil.deleteTexture(texId); GlUtil.deleteTexture(texId);
GlUtil.deleteSyncObject(syncObject);
} catch (GlUtil.GlException e) { } catch (GlUtil.GlException e) {
throw new VideoFrameProcessingException(e); throw new VideoFrameProcessingException(e);
} }