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
This commit is contained in:
kimvde 2023-03-07 18:48:31 +00:00 committed by tonihei
parent fe710871aa
commit 87d1c3e624

View file

@ -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;
}