Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1520,9 +1520,13 @@ private boolean putAndNotifyAdPlaybackStateUpdate(Object adsId, AdPlaybackState
private void notifyAssetResolutionFailed(Object adsId, int adGroupIndex, int adIndexInAdGroup) {
HlsAdSession session = adsMediaSourceSessionManager.getSession(adsId);
if (session != null) {
AdPlaybackState adPlaybackState =
session.adPlaybackState.withAdLoadError(adGroupIndex, adIndexInAdGroup);
putAndNotifyAdPlaybackStateUpdate(adsId, adPlaybackState);
AdPlaybackState adPlaybackState = session.adPlaybackState;
AdGroup adGroup = adPlaybackState.getAdGroup(adGroupIndex);
// Only mark unresolved ads as failed, preserving manual changes made while loading.
if (adGroup.states[adIndexInAdGroup] == AD_STATE_UNAVAILABLE) {
putAndNotifyAdPlaybackStateUpdate(
adsId, adPlaybackState.withAdLoadError(adGroupIndex, adIndexInAdGroup));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONObject;
Expand Down Expand Up @@ -6656,6 +6658,79 @@ public void setWithSkippedAdGroup_whenAdToSkipIsPlaying_adGroupSkippedAndEventLi
});
}

@Test
public void setWithSkippedAdGroup_assetListLoadFailsAfterSkip_preservesSkippedState()
throws Exception {
CountDownLatch loadStarted = new CountDownLatch(1);
CountDownLatch failLoad = new CountDownLatch(1);
adsLoader.release();
adsLoader =
new HlsInterstitialsAdsLoader(
() ->
new ByteArrayDataSource(
uri -> {
loadStarted.countDown();
try {
if (!failLoad.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
throw new IOException("Timed out waiting for the ad group to be skipped");
}
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException(e);
}
throw new IOException("Injected asset list failure after skip");
}));
adsLoader.addListener(mockAdsLoaderListener);
adsLoader.addListener(assetListLoadingListener);
adsMediaSource =
(AdsMediaSource)
new HlsInterstitialsAdsLoader.AdsMediaSourceFactory(
adsLoader,
mockAdViewProvider,
(Context) ApplicationProvider.getApplicationContext())
.createMediaSource(contentMediaItem);
String playlistString =
"#EXTM3U\n"
+ "#EXT-X-TARGETDURATION:9\n"
+ "#EXT-X-PROGRAM-DATE-TIME:2020-01-02T21:00:00.000Z\n"
+ "#EXTINF:9,\n"
+ "main0.ts\n"
+ "#EXTINF:51,\n"
+ "main1.ts\n"
+ "#EXT-X-ENDLIST\n"
+ "#EXT-X-DATERANGE:ID=\"ad0-0\",CLASS=\"com.apple.hls.interstitial\","
+ "START-DATE=\"2020-01-02T22:00:00.000Z\",CUE=\"PRE\","
+ "X-ASSET-LIST=\"http://example.com/assetlist.json\"\n";
when(mockPlayer.getContentPosition()).thenReturn(0L);
try {
AdPlaybackState initialState =
callHandleContentTimelineChangedAndCaptureAdPlaybackState(
playlistString,
adsLoader,
/* windowIndex= */ 0,
/* windowPositionInPeriodUs= */ 0,
/* windowEndPositionInPeriodUs= */ C.TIME_END_OF_SOURCE);
assertThat(loadStarted.await(TIMEOUT_MS, TimeUnit.MILLISECONDS)).isTrue();
assertThat(initialState.getAdGroup(0).states).asList().containsExactly(AD_STATE_UNAVAILABLE);

// Model a live-edge join skipping the group while its asset-list request is still pending.
adsLoader.setWithSkippedAdGroup(/* adGroupIndex= */ 0);
failLoad.countDown();

// A late IOException must not attempt the invalid SKIPPED -> ERROR state transition.
runMainLooperUntil(assetListLoadingListener::failed, TIMEOUT_MS, Clock.DEFAULT);
ArgumentCaptor<AdPlaybackState> stateCaptor = ArgumentCaptor.forClass(AdPlaybackState.class);
verify(mockEventListener, atLeast(1)).onAdPlaybackState(stateCaptor.capture());
assertThat(stateCaptor.getValue().getAdGroup(0).states)
.asList()
.containsExactly(AD_STATE_SKIPPED);
assertThat(assetListLoadingListener.assetListLoadCompletedCounter.get()).isEqualTo(0);
} finally {
failLoad.countDown();
adsLoader.release();
}
}

@Test
public void setWithSkippedAd_skipsAdDuringLoading_assetListLoadingCancelledToPreferManualChange()
throws IOException, TimeoutException {
Expand Down