From c4fb7552839e4225e3736513f0b17c6abe999ea2 Mon Sep 17 00:00:00 2001 From: samrobinson Date: Fri, 15 Sep 2023 10:47:16 -0700 Subject: [PATCH] Open progress conditionVariable when quitting internal thread. If getProgress is blocking whilst the internal thread calls endInternal (for error or success), the condition is never opened. Related to this, onCompleted and onError are therefore never surfaced to the app. progressState is accessed from application and internal threads, so should be marked volatile to prevent a thread caching the value. PiperOrigin-RevId: 565720184 --- .../androidx/media3/transformer/TransformerInternal.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java index e08ab843a8..5bb443d11c 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformerInternal.java @@ -366,8 +366,12 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; internalHandler.post(internalHandlerThread::quitSafely); } + // Update progress before opening variable to avoid getProgress returning an invalid combination + // of state and progress. + progressState = PROGRESS_STATE_NOT_STARTED; + transformerConditionVariable.open(); + if (forCancellation) { - transformerConditionVariable.open(); return; }