Commit 51b2a0f7 by andrewlewis Committed by Andrew Lewis

Add support for timing out ad preloading

Detect stuck buffering cases in ImaAdsLoader, and discard the ad group after
a timeout. This is intended to make the IMA extension more robust in the case
where an ad group unexpectedly doesn't load.

The timing out behavior is enabled by default but apps can choose to retain
the old behavior by setting an unset timeout on ImaAdsLoader.Builder.

PiperOrigin-RevId: 311729798
parent e8c74055
...@@ -52,8 +52,12 @@ ...@@ -52,8 +52,12 @@
([#7234](https://github.com/google/ExoPlayer/issues/7234)). ([#7234](https://github.com/google/ExoPlayer/issues/7234)).
* AV1 extension: Add a heuristic to determine the default number of threads * AV1 extension: Add a heuristic to determine the default number of threads
used for AV1 playback using the extension. used for AV1 playback using the extension.
* IMA extension: Upgrade to IMA SDK version 3.19.0, and migrate to new * IMA extension:
preloading APIs ([#6429](https://github.com/google/ExoPlayer/issues/6429)). * Upgrade to IMA SDK version 3.19.0, and migrate to new
preloading APIs
([#6429](https://github.com/google/ExoPlayer/issues/6429)).
* Add support for timing out ad preloading, to avoid playback getting
stuck if an ad group unexpectedly fails to load.
### 2.11.4 (2020-04-08) ### ### 2.11.4 (2020-04-08) ###
......
...@@ -360,6 +360,18 @@ public final class AdPlaybackState { ...@@ -360,6 +360,18 @@ public final class AdPlaybackState {
return index < adGroupTimesUs.length ? index : C.INDEX_UNSET; return index < adGroupTimesUs.length ? index : C.INDEX_UNSET;
} }
/** Returns whether the specified ad has been marked as in {@link #AD_STATE_ERROR}. */
public boolean isAdInErrorState(int adGroupIndex, int adIndexInAdGroup) {
if (adGroupIndex >= adGroups.length) {
return false;
}
AdGroup adGroup = adGroups[adGroupIndex];
if (adGroup.count == C.LENGTH_UNSET || adIndexInAdGroup >= adGroup.count) {
return false;
}
return adGroup.states[adIndexInAdGroup] == AdPlaybackState.AD_STATE_ERROR;
}
/** /**
* Returns an instance with the number of ads in {@code adGroupIndex} resolved to {@code adCount}. * Returns an instance with the number of ads in {@code adGroupIndex} resolved to {@code adCount}.
* The ad count must be greater than zero. * The ad count must be greater than zero.
......
...@@ -64,7 +64,9 @@ public final class AdPlaybackStateTest { ...@@ -64,7 +64,9 @@ public final class AdPlaybackStateTest {
assertThat(state.adGroups[0].uris[0]).isNull(); assertThat(state.adGroups[0].uris[0]).isNull();
assertThat(state.adGroups[0].states[0]).isEqualTo(AdPlaybackState.AD_STATE_ERROR); assertThat(state.adGroups[0].states[0]).isEqualTo(AdPlaybackState.AD_STATE_ERROR);
assertThat(state.isAdInErrorState(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0)).isTrue();
assertThat(state.adGroups[0].states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE); assertThat(state.adGroups[0].states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
assertThat(state.isAdInErrorState(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1)).isFalse();
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment