Block until FrameProcessorChain is released.

This is safer because it will prevent any future problems with
creating a new FrameProcessorChain before the previous one has
completed its async release.

From [eglDestroyContext documentation](https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglDestroyContext.xhtml):
"If the EGL rendering context is not current to any thread,
eglDestroyContext destroys it immediately."
The context isn't current to any thread here because GlUtil calls
eglMakeCurrent with EGL_NO_CONTEXT before calling eglDestroyContext.
So everthing should be released once the FrameProcessorChain's
release task terminates.

PiperOrigin-RevId: 442807484
This commit is contained in:
hschlueter 2022-04-19 15:33:13 +01:00 committed by Ian Baker
parent 570769ac9a
commit ba5d570aca

View file

@ -20,6 +20,7 @@ import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import static com.google.android.exoplayer2.util.Assertions.checkState;
import static com.google.android.exoplayer2.util.Assertions.checkStateNotNull;
import static com.google.common.collect.Iterables.getLast;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import android.content.Context;
import android.graphics.SurfaceTexture;
@ -36,6 +37,7 @@ import androidx.annotation.Nullable;
import androidx.annotation.WorkerThread;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.util.GlUtil;
import com.google.android.exoplayer2.util.Log;
import com.google.android.exoplayer2.util.Util;
import com.google.common.collect.ImmutableList;
import java.io.IOException;
@ -183,7 +185,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
enableExperimentalHdrEditing);
}
private static final String TAG = "FrameProcessorChain";
private static final String THREAD_NAME = "Transformer:FrameProcessorChain";
private static final long RELEASE_WAIT_TIME_MS = 100;
private final boolean enableExperimentalHdrEditing;
private final EGLDisplay eglDisplay;
@ -373,6 +377,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* <p>If the frame processor chain is released before it has {@linkplain #isEnded() ended}, it
* will attempt to cancel processing any input frames that have already become available. Input
* frames that become available after release are ignored.
*
* <p>This method blocks until all OpenGL resources are released or releasing times out.
*/
public void release() {
releaseRequested = true;
@ -394,6 +400,13 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
inputSurface.release();
}
singleThreadExecutorService.shutdown();
try {
if (!singleThreadExecutorService.awaitTermination(RELEASE_WAIT_TIME_MS, MILLISECONDS)) {
Log.d(TAG, "Failed to release FrameProcessorChain");
}
} catch (InterruptedException e) {
Log.d(TAG, "FrameProcessorChain release was interrupted", e);
}
}
/**