Commit 891ec223 by aquilescanta Committed by Andrew Lewis

Rearrange condition blocking to ensure Handler thread loops

Without this change, any prepare() operation that requires posting to
the DummyMainThread's handler cannot complete preparation.

PiperOrigin-RevId: 233050367
parent fd979790
......@@ -53,7 +53,7 @@ public final class DummyMainThread {
* Runs the provided {@link Runnable} on the main thread, blocking until execution completes or
* until timeout milliseconds have passed.
*
* @param timeoutMs the maximum time to wait in milliseconds.
* @param timeoutMs The maximum time to wait in milliseconds.
* @param runnable The {@link Runnable} to run.
*/
public void runOnMainThread(int timeoutMs, final Runnable runnable) {
......
......@@ -187,13 +187,14 @@ public final class MediaPeriodAsserts {
private static TrackGroupArray getTrackGroups(MediaPeriod mediaPeriod) {
AtomicReference<TrackGroupArray> trackGroupArray = new AtomicReference<>(null);
DummyMainThread dummyMainThread = new DummyMainThread();
ConditionVariable preparedCondition = new ConditionVariable();
dummyMainThread.runOnMainThread(
() -> {
ConditionVariable preparedCondition = new ConditionVariable();
mediaPeriod.prepare(
new Callback() {
@Override
public void onPrepared(MediaPeriod mediaPeriod) {
trackGroupArray.set(mediaPeriod.getTrackGroups());
preparedCondition.open();
}
......@@ -203,13 +204,12 @@ public final class MediaPeriodAsserts {
}
},
/* positionUs= */ 0);
try {
preparedCondition.block();
} catch (InterruptedException e) {
// Ignore.
}
trackGroupArray.set(mediaPeriod.getTrackGroups());
});
try {
preparedCondition.block();
} catch (InterruptedException e) {
// Ignore.
}
dummyMainThread.release();
return trackGroupArray.get();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment