Use SKIPPED ad status when a playing ad period has been removed

PiperOrigin-RevId: 521476767
This commit is contained in:
bachinger 2023-04-03 17:15:15 +01:00 committed by Marc Baechinger
parent 7babcf28dc
commit e6b9bde1dd
3 changed files with 18 additions and 15 deletions

View File

@ -1435,7 +1435,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
Timeline timeline = player.getCurrentTimeline();
Timeline.Window window = new Timeline.Window();
Timeline.Period adPeriod = new Timeline.Period();
// In case all periods are in the live window, we need the correct ad group duration when
// In case all periods are in the live window, we need to correct the ad group duration when
// inserting the first ad. Try calculate ad group duration from media structure.
long totalAdDurationUs =
getAdGroupDurationUsForLiveAdPeriodIndex(

View File

@ -737,7 +737,7 @@ import java.util.Set;
return adPlaybackState;
}
if (state == AD_STATE_AVAILABLE || state == AD_STATE_UNAVAILABLE) {
adPlaybackState = adPlaybackState.withPlayedAd(adGroupIndex, /* adIndexInAdGroup= */ i);
adPlaybackState = adPlaybackState.withSkippedAd(adGroupIndex, /* adIndexInAdGroup= */ i);
}
adGroupDurationUs += adGroup.durationsUs[i];
}
@ -751,7 +751,11 @@ import java.util.Set;
long[] newDurationsUs = new long[adGroup.durationsUs.length];
for (int adIndex = 0; adIndex < newDurationsUs.length; adIndex++) {
newDurationsUs[adIndex] = preserveDurations ? adGroup.durationsUs[adIndex] : 0;
adPlaybackState = adPlaybackState.withPlayedAd(adGroupIndex, /* adIndexInAdGroup= */ adIndex);
if (adGroup.states[adIndex] == AD_STATE_AVAILABLE
|| adGroup.states[adIndex] == AD_STATE_UNAVAILABLE) {
adPlaybackState =
adPlaybackState.withSkippedAd(adGroupIndex, /* adIndexInAdGroup= */ adIndex);
}
}
return adPlaybackState
.withAdDurationsUs(adGroupIndex, newDurationsUs)

View File

@ -1663,7 +1663,6 @@ public class ImaUtilTest {
/* totalAdDurationUs= */ 3 * AD_PERIOD_DURATION_US,
/* totalAdsInAdPod= */ 3,
adPlaybackState);
AdPlaybackState finalAdPlaybackState = adPlaybackState;
assertThat(
getAdGroupAndIndexInLiveMultiPeriodTimeline(
@ -2040,7 +2039,7 @@ public class ImaUtilTest {
.asList()
.containsExactly(
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_SKIPPED,
AD_STATE_UNAVAILABLE,
AD_STATE_UNAVAILABLE,
AD_STATE_UNAVAILABLE,
@ -2059,11 +2058,11 @@ public class ImaUtilTest {
.asList()
.containsExactly(
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED)
AD_STATE_SKIPPED,
AD_STATE_SKIPPED,
AD_STATE_SKIPPED,
AD_STATE_SKIPPED,
AD_STATE_SKIPPED)
.inOrder();
assertThat(adPlaybackState5.getAdGroup(/* adGroupIndex= */ 0).durationsUs)
.asList()
@ -2085,11 +2084,11 @@ public class ImaUtilTest {
.asList()
.containsExactly(
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED,
AD_STATE_PLAYED)
AD_STATE_SKIPPED,
AD_STATE_SKIPPED,
AD_STATE_SKIPPED,
AD_STATE_SKIPPED,
AD_STATE_SKIPPED)
.inOrder();
assertThat(adPlaybackState6.getAdGroup(/* adGroupIndex= */ 0).durationsUs)
.asList()