Use final reference to content timeline inside handler message

The content timeline field may be updated when the live timeline
is refreshed in the looper event preceding the runnable that is
posted to the player thread. Hence a new timeline may contain a
new period uid that is not present in the ad playback state map.

Using a final reference makes sure period and ad playback state
match when asserted.

PiperOrigin-RevId: 518228165
This commit is contained in:
bachinger 2023-03-21 10:55:44 +00:00 committed by microkatz
parent 0a2a20d4fb
commit 0bae410f7d

View file

@ -188,6 +188,7 @@ public final class ServerSideAdInsertionMediaSource extends BaseMediaSource
if (playbackHandler == null) {
this.adPlaybackStates = adPlaybackStates;
} else {
Timeline finalContentTimeline = contentTimeline;
playbackHandler.post(
() -> {
for (SharedMediaPeriod mediaPeriod : mediaPeriods.values()) {
@ -206,9 +207,9 @@ public final class ServerSideAdInsertionMediaSource extends BaseMediaSource
}
}
this.adPlaybackStates = adPlaybackStates;
if (contentTimeline != null) {
if (finalContentTimeline != null) {
refreshSourceInfo(
new ServerSideAdInsertionTimeline(contentTimeline, adPlaybackStates));
new ServerSideAdInsertionTimeline(finalContentTimeline, adPlaybackStates));
}
});
}