Fix delayed discontinuity for failed ad insertions.
We have logic to not immediately interrupt playback when an ad group
fails to load and instead let the current content play and transition
at the point where the ad group should have been.
This logic was broken by dcbdbe5341
because of one of the conditions
used MediaPeriodId.adGroupIndex, which is always -1 for content ids.
It still worked for the last ad group because the next ad group index
was C.INDEX_UNSET.
Fix the issue and amend the test that was meant to catch this to test
the ad failures for the last ad and previous ads.
Also fix the PositionInfo reported in such a case, which was also wrong.
Issue: google/ExoPlayer#9929
#minor-release
PiperOrigin-RevId: 427143223
This commit is contained in:
parent
2e34f9d552
commit
80cdfd0cf0
@ -97,6 +97,9 @@
|
|||||||
* Add support for
|
* Add support for
|
||||||
[IMA Dynamic Ad Insertion (DAI)](https://support.google.com/admanager/answer/6147120)
|
[IMA Dynamic Ad Insertion (DAI)](https://support.google.com/admanager/answer/6147120)
|
||||||
([#8213](https://github.com/google/ExoPlayer/issues/8213)).
|
([#8213](https://github.com/google/ExoPlayer/issues/8213)).
|
||||||
|
* Fix issue where an ad group that failed to load caused an immediate
|
||||||
|
playback reset
|
||||||
|
([#9929](https://github.com/google/ExoPlayer/issues/9929)).
|
||||||
* DASH:
|
* DASH:
|
||||||
* Support the `forced-subtitle` track role
|
* Support the `forced-subtitle` track role
|
||||||
([#9727](https://github.com/google/ExoPlayer/issues/9727)).
|
([#9727](https://github.com/google/ExoPlayer/issues/9727)).
|
||||||
|
@ -1927,8 +1927,6 @@ import java.util.concurrent.TimeoutException;
|
|||||||
long oldPositionUs;
|
long oldPositionUs;
|
||||||
long oldContentPositionUs;
|
long oldContentPositionUs;
|
||||||
if (positionDiscontinuityReason == DISCONTINUITY_REASON_AUTO_TRANSITION) {
|
if (positionDiscontinuityReason == DISCONTINUITY_REASON_AUTO_TRANSITION) {
|
||||||
oldPositionUs = oldPeriod.positionInWindowUs + oldPeriod.durationUs;
|
|
||||||
oldContentPositionUs = oldPositionUs;
|
|
||||||
if (oldPlaybackInfo.periodId.isAd()) {
|
if (oldPlaybackInfo.periodId.isAd()) {
|
||||||
// The old position is the end of the previous ad.
|
// The old position is the end of the previous ad.
|
||||||
oldPositionUs =
|
oldPositionUs =
|
||||||
@ -1936,12 +1934,15 @@ import java.util.concurrent.TimeoutException;
|
|||||||
oldPlaybackInfo.periodId.adGroupIndex, oldPlaybackInfo.periodId.adIndexInAdGroup);
|
oldPlaybackInfo.periodId.adGroupIndex, oldPlaybackInfo.periodId.adIndexInAdGroup);
|
||||||
// The ad cue point is stored in the old requested content position.
|
// The ad cue point is stored in the old requested content position.
|
||||||
oldContentPositionUs = getRequestedContentPositionUs(oldPlaybackInfo);
|
oldContentPositionUs = getRequestedContentPositionUs(oldPlaybackInfo);
|
||||||
} else if (oldPlaybackInfo.periodId.nextAdGroupIndex != C.INDEX_UNSET
|
} else if (oldPlaybackInfo.periodId.nextAdGroupIndex != C.INDEX_UNSET) {
|
||||||
&& playbackInfo.periodId.isAd()) {
|
// The old position is the end of a clipped content before an ad group. Use the exact ad
|
||||||
// If it's a transition from content to an ad in the same window, the old position is the
|
// cue point as the transition position.
|
||||||
// ad cue point that is the same as current content position.
|
|
||||||
oldPositionUs = getRequestedContentPositionUs(playbackInfo);
|
oldPositionUs = getRequestedContentPositionUs(playbackInfo);
|
||||||
oldContentPositionUs = oldPositionUs;
|
oldContentPositionUs = oldPositionUs;
|
||||||
|
} else {
|
||||||
|
// The old position is the end of a Timeline period. Use the exact duration.
|
||||||
|
oldPositionUs = oldPeriod.positionInWindowUs + oldPeriod.durationUs;
|
||||||
|
oldContentPositionUs = oldPositionUs;
|
||||||
}
|
}
|
||||||
} else if (oldPlaybackInfo.periodId.isAd()) {
|
} else if (oldPlaybackInfo.periodId.isAd()) {
|
||||||
oldPositionUs = oldPlaybackInfo.positionUs;
|
oldPositionUs = oldPlaybackInfo.positionUs;
|
||||||
|
@ -2664,7 +2664,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
boolean earliestCuePointIsUnchangedOrLater =
|
boolean earliestCuePointIsUnchangedOrLater =
|
||||||
periodIdWithAds.nextAdGroupIndex == C.INDEX_UNSET
|
periodIdWithAds.nextAdGroupIndex == C.INDEX_UNSET
|
||||||
|| (oldPeriodId.nextAdGroupIndex != C.INDEX_UNSET
|
|| (oldPeriodId.nextAdGroupIndex != C.INDEX_UNSET
|
||||||
&& periodIdWithAds.adGroupIndex >= oldPeriodId.nextAdGroupIndex);
|
&& periodIdWithAds.nextAdGroupIndex >= oldPeriodId.nextAdGroupIndex);
|
||||||
// Drop update if we keep playing the same content (MediaPeriod.periodUid are identical) and
|
// Drop update if we keep playing the same content (MediaPeriod.periodUid are identical) and
|
||||||
// the only change is that MediaPeriodId.nextAdGroupIndex increased. This postpones a potential
|
// the only change is that MediaPeriodId.nextAdGroupIndex increased. This postpones a potential
|
||||||
// discontinuity until we reach the former next ad group position.
|
// discontinuity until we reach the former next ad group position.
|
||||||
|
@ -720,7 +720,7 @@ public final class ExoPlayerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void adGroupWithLoadErrorIsSkipped() throws Exception {
|
public void adGroupWithLoadError_noFurtherAdGroup_isSkipped() throws Exception {
|
||||||
AdPlaybackState initialAdPlaybackState =
|
AdPlaybackState initialAdPlaybackState =
|
||||||
FakeTimeline.createAdPlaybackState(
|
FakeTimeline.createAdPlaybackState(
|
||||||
/* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */
|
/* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */
|
||||||
@ -735,11 +735,12 @@ public final class ExoPlayerTest {
|
|||||||
/* isDynamic= */ false,
|
/* isDynamic= */ false,
|
||||||
/* isLive= */ false,
|
/* isLive= */ false,
|
||||||
/* isPlaceholder= */ false,
|
/* isPlaceholder= */ false,
|
||||||
/* durationUs= */ C.MICROS_PER_SECOND,
|
/* durationUs= */ 10 * C.MICROS_PER_SECOND,
|
||||||
/* defaultPositionUs= */ 0,
|
/* defaultPositionUs= */ 0,
|
||||||
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US,
|
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US,
|
||||||
initialAdPlaybackState));
|
initialAdPlaybackState));
|
||||||
AdPlaybackState errorAdPlaybackState = initialAdPlaybackState.withAdLoadError(0, 0);
|
AdPlaybackState errorAdPlaybackState =
|
||||||
|
initialAdPlaybackState.withAdLoadError(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
||||||
final Timeline adErrorTimeline =
|
final Timeline adErrorTimeline =
|
||||||
new FakeTimeline(
|
new FakeTimeline(
|
||||||
new TimelineWindowDefinition(
|
new TimelineWindowDefinition(
|
||||||
@ -749,30 +750,166 @@ public final class ExoPlayerTest {
|
|||||||
/* isDynamic= */ false,
|
/* isDynamic= */ false,
|
||||||
/* isLive= */ false,
|
/* isLive= */ false,
|
||||||
/* isPlaceholder= */ false,
|
/* isPlaceholder= */ false,
|
||||||
/* durationUs= */ C.MICROS_PER_SECOND,
|
/* durationUs= */ 10 * C.MICROS_PER_SECOND,
|
||||||
/* defaultPositionUs= */ 0,
|
/* defaultPositionUs= */ 0,
|
||||||
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US,
|
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US,
|
||||||
errorAdPlaybackState));
|
errorAdPlaybackState));
|
||||||
final FakeMediaSource fakeMediaSource =
|
final FakeMediaSource fakeMediaSource =
|
||||||
new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
|
new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
|
||||||
ActionSchedule actionSchedule =
|
ExoPlayer player = new TestExoPlayerBuilder(context).build();
|
||||||
new ActionSchedule.Builder(TAG)
|
Player.Listener mockListener = mock(Player.Listener.class);
|
||||||
.pause()
|
player.addListener(mockListener);
|
||||||
.waitForPlaybackState(Player.STATE_READY)
|
|
||||||
.executeRunnable(() -> fakeMediaSource.setNewSourceInfo(adErrorTimeline))
|
player.setMediaSource(fakeMediaSource);
|
||||||
.waitForTimelineChanged(
|
player.prepare();
|
||||||
adErrorTimeline, /* expectedReason */ Player.TIMELINE_CHANGE_REASON_SOURCE_UPDATE)
|
runUntilPlaybackState(player, Player.STATE_READY);
|
||||||
.play()
|
fakeMediaSource.setNewSourceInfo(adErrorTimeline);
|
||||||
.build();
|
player.play();
|
||||||
ExoPlayerTestRunner testRunner =
|
runUntilPlaybackState(player, Player.STATE_ENDED);
|
||||||
new ExoPlayerTestRunner.Builder(context)
|
Timeline.Window window =
|
||||||
.setMediaSources(fakeMediaSource)
|
player.getCurrentTimeline().getWindow(/* windowIndex= */ 0, new Timeline.Window());
|
||||||
.setActionSchedule(actionSchedule)
|
Timeline.Period period =
|
||||||
.build()
|
player
|
||||||
.start()
|
.getCurrentTimeline()
|
||||||
.blockUntilEnded(TIMEOUT_MS);
|
.getPeriod(/* periodIndex= */ 0, new Timeline.Period(), /* setIds= */ true);
|
||||||
|
player.release();
|
||||||
|
|
||||||
// There is still one discontinuity from content to content for the failed ad insertion.
|
// There is still one discontinuity from content to content for the failed ad insertion.
|
||||||
testRunner.assertPositionDiscontinuityReasonsEqual(Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
|
PositionInfo positionInfo =
|
||||||
|
new PositionInfo(
|
||||||
|
window.uid,
|
||||||
|
/* mediaItemIndex= */ 0,
|
||||||
|
window.mediaItem,
|
||||||
|
period.uid,
|
||||||
|
/* periodIndex= */ 0,
|
||||||
|
/* positionMs= */ 5_000,
|
||||||
|
/* contentPositionMs= */ 5_000,
|
||||||
|
/* adGroupIndex= */ C.INDEX_UNSET,
|
||||||
|
/* adIndexInAdGroup= */ C.INDEX_UNSET);
|
||||||
|
verify(mockListener)
|
||||||
|
.onPositionDiscontinuity(
|
||||||
|
positionInfo, positionInfo, Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void adGroupWithLoadError_withFurtherAdGroup_isSkipped() throws Exception {
|
||||||
|
AdPlaybackState initialAdPlaybackState =
|
||||||
|
FakeTimeline.createAdPlaybackState(
|
||||||
|
/* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */
|
||||||
|
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
|
||||||
|
+ 5 * C.MICROS_PER_SECOND,
|
||||||
|
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
|
||||||
|
+ 8 * C.MICROS_PER_SECOND);
|
||||||
|
Timeline fakeTimeline =
|
||||||
|
new FakeTimeline(
|
||||||
|
new TimelineWindowDefinition(
|
||||||
|
/* periodCount= */ 1,
|
||||||
|
/* id= */ 0,
|
||||||
|
/* isSeekable= */ true,
|
||||||
|
/* isDynamic= */ false,
|
||||||
|
/* isLive= */ false,
|
||||||
|
/* isPlaceholder= */ false,
|
||||||
|
/* durationUs= */ 10 * C.MICROS_PER_SECOND,
|
||||||
|
/* defaultPositionUs= */ 0,
|
||||||
|
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US,
|
||||||
|
initialAdPlaybackState));
|
||||||
|
AdPlaybackState errorAdPlaybackState =
|
||||||
|
initialAdPlaybackState.withAdLoadError(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
||||||
|
final Timeline adErrorTimeline =
|
||||||
|
new FakeTimeline(
|
||||||
|
new TimelineWindowDefinition(
|
||||||
|
/* periodCount= */ 1,
|
||||||
|
/* id= */ 0,
|
||||||
|
/* isSeekable= */ true,
|
||||||
|
/* isDynamic= */ false,
|
||||||
|
/* isLive= */ false,
|
||||||
|
/* isPlaceholder= */ false,
|
||||||
|
/* durationUs= */ 10 * C.MICROS_PER_SECOND,
|
||||||
|
/* defaultPositionUs= */ 0,
|
||||||
|
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US,
|
||||||
|
errorAdPlaybackState));
|
||||||
|
final FakeMediaSource fakeMediaSource =
|
||||||
|
new FakeMediaSource(fakeTimeline, ExoPlayerTestRunner.VIDEO_FORMAT);
|
||||||
|
ExoPlayer player = new TestExoPlayerBuilder(context).build();
|
||||||
|
Player.Listener mockListener = mock(Player.Listener.class);
|
||||||
|
player.addListener(mockListener);
|
||||||
|
|
||||||
|
player.setMediaSource(fakeMediaSource);
|
||||||
|
player.prepare();
|
||||||
|
runUntilPlaybackState(player, Player.STATE_READY);
|
||||||
|
fakeMediaSource.setNewSourceInfo(adErrorTimeline);
|
||||||
|
player.play();
|
||||||
|
runUntilPlaybackState(player, Player.STATE_ENDED);
|
||||||
|
Timeline.Window window =
|
||||||
|
player.getCurrentTimeline().getWindow(/* windowIndex= */ 0, new Timeline.Window());
|
||||||
|
Timeline.Period period =
|
||||||
|
player
|
||||||
|
.getCurrentTimeline()
|
||||||
|
.getPeriod(/* periodIndex= */ 0, new Timeline.Period(), /* setIds= */ true);
|
||||||
|
player.release();
|
||||||
|
|
||||||
|
// There is still one discontinuity from content to content for the failed ad insertion and the
|
||||||
|
// normal ad transition for the successful ad insertion.
|
||||||
|
PositionInfo positionInfoFailedAd =
|
||||||
|
new PositionInfo(
|
||||||
|
window.uid,
|
||||||
|
/* mediaItemIndex= */ 0,
|
||||||
|
window.mediaItem,
|
||||||
|
period.uid,
|
||||||
|
/* periodIndex= */ 0,
|
||||||
|
/* positionMs= */ 5_000,
|
||||||
|
/* contentPositionMs= */ 5_000,
|
||||||
|
/* adGroupIndex= */ C.INDEX_UNSET,
|
||||||
|
/* adIndexInAdGroup= */ C.INDEX_UNSET);
|
||||||
|
verify(mockListener)
|
||||||
|
.onPositionDiscontinuity(
|
||||||
|
positionInfoFailedAd,
|
||||||
|
positionInfoFailedAd,
|
||||||
|
Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
|
||||||
|
PositionInfo positionInfoContentAtSuccessfulAd =
|
||||||
|
new PositionInfo(
|
||||||
|
window.uid,
|
||||||
|
/* mediaItemIndex= */ 0,
|
||||||
|
window.mediaItem,
|
||||||
|
period.uid,
|
||||||
|
/* periodIndex= */ 0,
|
||||||
|
/* positionMs= */ 8_000,
|
||||||
|
/* contentPositionMs= */ 8_000,
|
||||||
|
/* adGroupIndex= */ C.INDEX_UNSET,
|
||||||
|
/* adIndexInAdGroup= */ C.INDEX_UNSET);
|
||||||
|
PositionInfo positionInfoSuccessfulAdStart =
|
||||||
|
new PositionInfo(
|
||||||
|
window.uid,
|
||||||
|
/* mediaItemIndex= */ 0,
|
||||||
|
window.mediaItem,
|
||||||
|
period.uid,
|
||||||
|
/* periodIndex= */ 0,
|
||||||
|
/* positionMs= */ 0,
|
||||||
|
/* contentPositionMs= */ 8_000,
|
||||||
|
/* adGroupIndex= */ 1,
|
||||||
|
/* adIndexInAdGroup= */ 0);
|
||||||
|
PositionInfo positionInfoSuccessfulAdEnd =
|
||||||
|
new PositionInfo(
|
||||||
|
window.uid,
|
||||||
|
/* mediaItemIndex= */ 0,
|
||||||
|
window.mediaItem,
|
||||||
|
period.uid,
|
||||||
|
/* periodIndex= */ 0,
|
||||||
|
/* positionMs= */ Util.usToMs(
|
||||||
|
period.getAdDurationUs(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0)),
|
||||||
|
/* contentPositionMs= */ 8_000,
|
||||||
|
/* adGroupIndex= */ 1,
|
||||||
|
/* adIndexInAdGroup= */ 0);
|
||||||
|
verify(mockListener)
|
||||||
|
.onPositionDiscontinuity(
|
||||||
|
positionInfoContentAtSuccessfulAd,
|
||||||
|
positionInfoSuccessfulAdStart,
|
||||||
|
Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
|
||||||
|
verify(mockListener)
|
||||||
|
.onPositionDiscontinuity(
|
||||||
|
positionInfoSuccessfulAdEnd,
|
||||||
|
positionInfoContentAtSuccessfulAd,
|
||||||
|
Player.DISCONTINUITY_REASON_AUTO_TRANSITION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user