Commit 67d15ec5 by kimvde Committed by tonihei

Fix threading issueis in SequenceAssetLoaderListener

Callbacks onTrackCount and onTrackAdded can be called simultaneously
from different threads.

Before this fix, it was possible for the MuxerWrapper and
FallbackListener track count to never be set, or to be set
with incorrect values.

PiperOrigin-RevId: 514779719
parent 62c03524
......@@ -440,8 +440,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
ERROR_CODE_FAILED_RUNTIME_CHECK));
return;
}
trackCountsToReport.decrementAndGet();
tracksToAdd.addAndGet(trackCount);
trackCountsToReport.decrementAndGet();
}
@Override
......@@ -465,12 +465,11 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} else {
outputHasVideo.set(true);
}
if (trackCountsToReport.get() == 0 && tracksToAdd.get() == 1) {
if (trackCountsToReport.get() == 0 && tracksToAdd.decrementAndGet() == 0) {
int outputTrackCount = (outputHasAudio.get() ? 1 : 0) + (outputHasVideo.get() ? 1 : 0);
muxerWrapper.setTrackCount(outputTrackCount);
fallbackListener.setTrackCount(outputTrackCount);
}
tracksToAdd.decrementAndGet();
return trackInfo.shouldTranscode;
}
......
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