Don't enqueue ad periods that start after the end of the period

Issue: androidx/media#2215
PiperOrigin-RevId: 747376615
This commit is contained in:
bachinger 2025-04-14 05:39:40 -07:00 committed by Copybara-Service
parent 3205811f23
commit ed56ed22fb
4 changed files with 13 additions and 2 deletions

View File

@ -2981,6 +2981,10 @@ This release corresponds to the
* Ad playback / IMA: * Ad playback / IMA:
* Decrease ad polling rate from every 100ms to every 200ms, to line up * Decrease ad polling rate from every 100ms to every 200ms, to line up
with Media Rating Council (MRC) recommendations. with Media Rating Council (MRC) recommendations.
* Fix bug where ad groups after the end of a VOD window stalled playback.
Ads groups with a start time after the window are not enqueued into the
`MediaPeriodQueue` anymore
([#2215](https://github.com/androidx/media/issues/2215)).
* FFmpeg extension: * FFmpeg extension:
* Update CMake version to `3.21.0+` to avoid a CMake bug causing * Update CMake version to `3.21.0+` to avoid a CMake bug causing
AndroidStudio's gradle sync to fail AndroidStudio's gradle sync to fail

View File

@ -865,7 +865,10 @@ public final class AdPlaybackState {
|| !getAdGroup(index).shouldPlayAdGroup())) { || !getAdGroup(index).shouldPlayAdGroup())) {
index++; index++;
} }
return index < adGroupCount ? index : C.INDEX_UNSET; return index < adGroupCount
&& (periodDurationUs == C.TIME_UNSET || getAdGroup(index).timeUs <= periodDurationUs)
? index
: C.INDEX_UNSET;
} }
/** Returns whether the specified ad has been marked as in {@link #AD_STATE_ERROR}. */ /** Returns whether the specified ad has been marked as in {@link #AD_STATE_ERROR}. */

View File

@ -856,6 +856,10 @@ public class AdPlaybackStateTest {
state.getAdGroupIndexAfterPositionUs( state.getAdGroupIndexAfterPositionUs(
/* positionUs= */ C.TIME_END_OF_SOURCE, /* periodDurationUs= */ 5000)) /* positionUs= */ C.TIME_END_OF_SOURCE, /* periodDurationUs= */ 5000))
.isEqualTo(C.INDEX_UNSET); .isEqualTo(C.INDEX_UNSET);
assertThat(
state.getAdGroupIndexAfterPositionUs(
/* positionUs= */ 1001, /* periodDurationUs= */ 1002))
.isEqualTo(C.INDEX_UNSET);
} }
@Test @Test

View File

@ -868,7 +868,7 @@ import java.util.Objects;
} }
if (imaAdState == IMA_AD_STATE_NONE if (imaAdState == IMA_AD_STATE_NONE
&& playbackState == Player.STATE_BUFFERING && (playbackState == Player.STATE_BUFFERING || playbackState == Player.STATE_ENDED)
&& playWhenReady) { && playWhenReady) {
ensureSentContentCompleteIfAtEndOfStream(); ensureSentContentCompleteIfAtEndOfStream();
} else if (imaAdState != IMA_AD_STATE_NONE && playbackState == Player.STATE_ENDED) { } else if (imaAdState != IMA_AD_STATE_NONE && playbackState == Player.STATE_ENDED) {