From 77cc25242bdc5ec049a8c5bd525a5c30ce5fa9d2 Mon Sep 17 00:00:00 2001 From: claincly Date: Wed, 1 Feb 2023 15:29:32 +0000 Subject: [PATCH] Report flushing completed after all pending frames are decoded. With the current ExtTexMgr, it can happen that - `x` frames are registered, but haven't arrived yet - flush - need to drop `x` frames when they arrive on SurfaceTexture - status is reset to 0 pending, 0 available, drop `x` when frames arrive - register one frame - status is set to 1 pending, 0 available, drop `x` when frames arrive - flush - now the number of frame to drop is reset to `pending - available = 1` - but it should be `x+1` This CL solves the issue by reporting (by running the afterFlushTask) flush completes only after all the pending frames before calling flush are accounted for. PiperOrigin-RevId: 506310671 --- .../exoplayer2/effect/ExternalTextureManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java b/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java index 4dc0fb22f4..2cbfc330e2 100644 --- a/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java +++ b/library/effect/src/main/java/com/google/android/exoplayer2/effect/ExternalTextureManager.java @@ -58,6 +58,7 @@ import java.util.concurrent.atomic.AtomicInteger; // Set to null on any thread. Read and set to non-null on the GL thread only. @Nullable private volatile FrameInfo currentFrame; + // TODO(b/238302341) Remove the use of after flush task, block the calling thread instead. @Nullable private volatile FrameProcessingTask onFlushCompleteTask; private long previousStreamOffsetUs; @@ -97,6 +98,7 @@ import java.util.concurrent.atomic.AtomicInteger; if (numberOfFramesToDropOnBecomingAvailable > 0) { numberOfFramesToDropOnBecomingAvailable--; surfaceTexture.updateTexImage(); + maybeExecuteAfterFlushTask(); } else { availableFrameCount++; maybeQueueFrameToExternalTextureProcessor(); @@ -184,10 +186,14 @@ import java.util.concurrent.atomic.AtomicInteger; externalTextureProcessorInputCapacity.set(0); currentFrame = null; pendingFrames.clear(); + maybeExecuteAfterFlushTask(); + } - if (onFlushCompleteTask != null) { - frameProcessingTaskExecutor.submitWithHighPriority(onFlushCompleteTask); + private void maybeExecuteAfterFlushTask() { + if (onFlushCompleteTask == null || numberOfFramesToDropOnBecomingAvailable > 0) { + return; } + frameProcessingTaskExecutor.submitWithHighPriority(onFlushCompleteTask); } @WorkerThread