Commit 764e5e81 by andrewlewis Committed by Andrew Lewis

Expose the ads identifier in the Timeline period

Issue: #3750
PiperOrigin-RevId: 341021084
parent 0c301fef
...@@ -128,6 +128,7 @@ import java.util.Map; ...@@ -128,6 +128,7 @@ import java.util.Map;
private final ImaUtil.ImaFactory imaFactory; private final ImaUtil.ImaFactory imaFactory;
private final List<String> supportedMimeTypes; private final List<String> supportedMimeTypes;
private final DataSpec adTagDataSpec; private final DataSpec adTagDataSpec;
private final Object adsId;
private final Timeline.Period period; private final Timeline.Period period;
private final Handler handler; private final Handler handler;
private final ComponentListener componentListener; private final ComponentListener componentListener;
...@@ -146,7 +147,6 @@ import java.util.Map; ...@@ -146,7 +147,6 @@ import java.util.Map;
@Nullable private AdsManager adsManager; @Nullable private AdsManager adsManager;
private boolean isAdsManagerInitialized; private boolean isAdsManagerInitialized;
private boolean hasAdPlaybackState;
@Nullable private AdLoadException pendingAdLoadError; @Nullable private AdLoadException pendingAdLoadError;
private Timeline timeline; private Timeline timeline;
private long contentDurationMs; private long contentDurationMs;
...@@ -214,6 +214,7 @@ import java.util.Map; ...@@ -214,6 +214,7 @@ import java.util.Map;
ImaUtil.ImaFactory imaFactory, ImaUtil.ImaFactory imaFactory,
List<String> supportedMimeTypes, List<String> supportedMimeTypes,
DataSpec adTagDataSpec, DataSpec adTagDataSpec,
Object adsId,
@Nullable ViewGroup adViewGroup) { @Nullable ViewGroup adViewGroup) {
this.configuration = configuration; this.configuration = configuration;
this.imaFactory = imaFactory; this.imaFactory = imaFactory;
...@@ -228,6 +229,7 @@ import java.util.Map; ...@@ -228,6 +229,7 @@ import java.util.Map;
imaSdkSettings.setPlayerVersion(IMA_SDK_SETTINGS_PLAYER_VERSION); imaSdkSettings.setPlayerVersion(IMA_SDK_SETTINGS_PLAYER_VERSION);
this.supportedMimeTypes = supportedMimeTypes; this.supportedMimeTypes = supportedMimeTypes;
this.adTagDataSpec = adTagDataSpec; this.adTagDataSpec = adTagDataSpec;
this.adsId = adsId;
period = new Timeline.Period(); period = new Timeline.Period();
handler = Util.createHandler(getImaLooper(), /* callback= */ null); handler = Util.createHandler(getImaLooper(), /* callback= */ null);
componentListener = new ComponentListener(); componentListener = new ComponentListener();
...@@ -286,14 +288,16 @@ import java.util.Map; ...@@ -286,14 +288,16 @@ import java.util.Map;
lastAdProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY; lastAdProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
lastContentProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY; lastContentProgress = VideoProgressUpdate.VIDEO_TIME_NOT_READY;
maybeNotifyPendingAdLoadError(); maybeNotifyPendingAdLoadError();
if (hasAdPlaybackState) { if (!AdPlaybackState.NONE.equals(adPlaybackState)) {
// Pass the ad playback state to the player, and resume ads if necessary. // Pass the ad playback state to the player, and resume ads if necessary.
eventListener.onAdPlaybackState(adPlaybackState); eventListener.onAdPlaybackState(adPlaybackState);
if (adsManager != null && imaPausedContent && playWhenReady) { if (adsManager != null && imaPausedContent && playWhenReady) {
adsManager.resume(); adsManager.resume();
} }
} else if (adsManager != null) { } else if (adsManager != null) {
adPlaybackState = ImaUtil.getInitialAdPlaybackStateForCuePoints(adsManager.getAdCuePoints()); adPlaybackState =
new AdPlaybackState(
adsId, ImaUtil.getAdGroupTimesUsForCuePoints(adsManager.getAdCuePoints()));
updateAdPlaybackState(); updateAdPlaybackState();
} }
if (adDisplayContainer != null) { if (adDisplayContainer != null) {
...@@ -348,8 +352,7 @@ import java.util.Map; ...@@ -348,8 +352,7 @@ import java.util.Map;
stopUpdatingAdProgress(); stopUpdatingAdProgress();
imaAdInfo = null; imaAdInfo = null;
pendingAdLoadError = null; pendingAdLoadError = null;
adPlaybackState = AdPlaybackState.NONE; adPlaybackState = new AdPlaybackState(adsId);
hasAdPlaybackState = true;
updateAdPlaybackState(); updateAdPlaybackState();
} }
...@@ -496,7 +499,7 @@ import java.util.Map; ...@@ -496,7 +499,7 @@ import java.util.Map;
try { try {
request = ImaUtil.getAdsRequestForAdTagDataSpec(imaFactory, adTagDataSpec); request = ImaUtil.getAdsRequestForAdTagDataSpec(imaFactory, adTagDataSpec);
} catch (IOException e) { } catch (IOException e) {
hasAdPlaybackState = true; adPlaybackState = new AdPlaybackState(adsId);
updateAdPlaybackState(); updateAdPlaybackState();
pendingAdLoadError = AdLoadException.createForAllAds(e); pendingAdLoadError = AdLoadException.createForAllAds(e);
maybeNotifyPendingAdLoadError(); maybeNotifyPendingAdLoadError();
...@@ -1215,8 +1218,8 @@ import java.util.Map; ...@@ -1215,8 +1218,8 @@ import java.util.Map;
// If a player is attached already, start playback immediately. // If a player is attached already, start playback immediately.
try { try {
adPlaybackState = adPlaybackState =
ImaUtil.getInitialAdPlaybackStateForCuePoints(adsManager.getAdCuePoints()); new AdPlaybackState(
hasAdPlaybackState = true; adsId, ImaUtil.getAdGroupTimesUsForCuePoints(adsManager.getAdCuePoints()));
updateAdPlaybackState(); updateAdPlaybackState();
} catch (RuntimeException e) { } catch (RuntimeException e) {
maybeNotifyInternalError("onAdsManagerLoaded", e); maybeNotifyInternalError("onAdsManagerLoaded", e);
...@@ -1276,8 +1279,7 @@ import java.util.Map; ...@@ -1276,8 +1279,7 @@ import java.util.Map;
if (adsManager == null) { if (adsManager == null) {
// No ads were loaded, so allow playback to start without any ads. // No ads were loaded, so allow playback to start without any ads.
pendingAdRequestContext = null; pendingAdRequestContext = null;
adPlaybackState = AdPlaybackState.NONE; adPlaybackState = new AdPlaybackState(adsId);
hasAdPlaybackState = true;
updateAdPlaybackState(); updateAdPlaybackState();
} else if (ImaUtil.isAdGroupLoadError(error)) { } else if (ImaUtil.isAdGroupLoadError(error)) {
try { try {
......
...@@ -417,14 +417,21 @@ public final class ImaAdsLoader ...@@ -417,14 +417,21 @@ public final class ImaAdsLoader
* *
* @param adTagDataSpec The data specification of the ad tag to load. See class javadoc for * @param adTagDataSpec The data specification of the ad tag to load. See class javadoc for
* information about compatible ad tag formats. * information about compatible ad tag formats.
* @param adsId A opaque identifier for the ad playback state across start/stop calls.
* @param adViewGroup A {@link ViewGroup} on top of the player that will show any ad UI, or {@code * @param adViewGroup A {@link ViewGroup} on top of the player that will show any ad UI, or {@code
* null} if playing audio-only ads. * null} if playing audio-only ads.
*/ */
public void requestAds(DataSpec adTagDataSpec, @Nullable ViewGroup adViewGroup) { public void requestAds(DataSpec adTagDataSpec, Object adsId, @Nullable ViewGroup adViewGroup) {
if (adTagLoader == null) { if (adTagLoader == null) {
adTagLoader = adTagLoader =
new AdTagLoader( new AdTagLoader(
context, configuration, imaFactory, supportedMimeTypes, adTagDataSpec, adViewGroup); context,
configuration,
imaFactory,
supportedMimeTypes,
adTagDataSpec,
adsId,
adViewGroup);
} }
} }
...@@ -488,7 +495,7 @@ public final class ImaAdsLoader ...@@ -488,7 +495,7 @@ public final class ImaAdsLoader
return; return;
} }
if (adTagLoader == null) { if (adTagLoader == null) {
requestAds(adTagDataSpec, adViewProvider.getAdViewGroup()); requestAds(adTagDataSpec, adsId, adViewProvider.getAdViewGroup());
} }
checkNotNull(adTagLoader).start(player, adViewProvider, eventListener); checkNotNull(adTagLoader).start(player, adViewProvider, eventListener);
} }
......
...@@ -36,7 +36,6 @@ import com.google.ads.interactivemedia.v3.api.UiElement; ...@@ -36,7 +36,6 @@ import com.google.ads.interactivemedia.v3.api.UiElement;
import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer; import com.google.ads.interactivemedia.v3.api.player.VideoAdPlayer;
import com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate; import com.google.ads.interactivemedia.v3.api.player.VideoProgressUpdate;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.ads.AdPlaybackState;
import com.google.android.exoplayer2.source.ads.AdsLoader.OverlayInfo; import com.google.android.exoplayer2.source.ads.AdsLoader.OverlayInfo;
import com.google.android.exoplayer2.upstream.DataSchemeDataSource; import com.google.android.exoplayer2.upstream.DataSchemeDataSource;
import com.google.android.exoplayer2.upstream.DataSpec; import com.google.android.exoplayer2.upstream.DataSpec;
...@@ -154,15 +153,14 @@ import java.util.Set; ...@@ -154,15 +153,14 @@ import java.util.Set;
} }
/** /**
* Returns an initial {@link AdPlaybackState} with ad groups at the provided {@code cuePoints}. * Returns the microsecond ad group timestamps corresponding to the specified cue points.
* *
* @param cuePoints The cue points of the ads in seconds. * @param cuePoints The cue points of the ads in seconds, provided by the IMA SDK.
* @return The {@link AdPlaybackState}. * @return The corresponding microsecond ad group timestamps.
*/ */
public static AdPlaybackState getInitialAdPlaybackStateForCuePoints(List<Float> cuePoints) { public static long[] getAdGroupTimesUsForCuePoints(List<Float> cuePoints) {
if (cuePoints.isEmpty()) { if (cuePoints.isEmpty()) {
// If no cue points are specified, there is a preroll ad. return new long[] {0L};
return new AdPlaybackState(/* adGroupTimesUs...= */ 0);
} }
int count = cuePoints.size(); int count = cuePoints.size();
...@@ -178,7 +176,7 @@ import java.util.Set; ...@@ -178,7 +176,7 @@ import java.util.Set;
} }
// Cue points may be out of order, so sort them. // Cue points may be out of order, so sort them.
Arrays.sort(adGroupTimesUs, 0, adGroupIndex); Arrays.sort(adGroupTimesUs, 0, adGroupIndex);
return new AdPlaybackState(adGroupTimesUs); return adGroupTimesUs;
} }
/** Returns an {@link AdsRequest} based on the specified ad tag {@link DataSpec}. */ /** Returns an {@link AdsRequest} based on the specified ad tag {@link DataSpec}. */
......
...@@ -519,9 +519,13 @@ public abstract class Timeline { ...@@ -519,9 +519,13 @@ public abstract class Timeline {
return positionInWindowUs; return positionInWindowUs;
} }
/** /** Returns the opaque identifier for ads played with this period, or {@code null} if unset. */
* Returns the number of ad groups in the period. @Nullable
*/ public Object getAdsId() {
return adPlaybackState.adsId;
}
/** Returns the number of ad groups in the period. */
public int getAdGroupCount() { public int getAdGroupCount() {
return adPlaybackState.adGroupCount; return adPlaybackState.adGroupCount;
} }
......
...@@ -258,7 +258,18 @@ public final class AdPlaybackState { ...@@ -258,7 +258,18 @@ public final class AdPlaybackState {
public static final int AD_STATE_ERROR = 4; public static final int AD_STATE_ERROR = 4;
/** Ad playback state with no ads. */ /** Ad playback state with no ads. */
public static final AdPlaybackState NONE = new AdPlaybackState(); public static final AdPlaybackState NONE =
new AdPlaybackState(
/* adsId= */ null,
/* adGroupTimesUs= */ new long[0],
/* adGroups= */ null,
/* adResumePositionUs= */ 0L,
/* contentDurationUs= */ C.TIME_UNSET);
/**
* The opaque identifier for ads with which this instance is associated, or {@code null} if unset.
*/
@Nullable public final Object adsId;
/** The number of ad groups. */ /** The number of ad groups. */
public final int adGroupCount; public final int adGroupCount;
...@@ -280,29 +291,38 @@ public final class AdPlaybackState { ...@@ -280,29 +291,38 @@ public final class AdPlaybackState {
/** /**
* Creates a new ad playback state with the specified ad group times. * Creates a new ad playback state with the specified ad group times.
* *
* @param adsId The opaque identifier for ads with which this instance is associated.
* @param adGroupTimesUs The times of ad groups in microseconds, relative to the start of the * @param adGroupTimesUs The times of ad groups in microseconds, relative to the start of the
* {@link com.google.android.exoplayer2.Timeline.Period} they belong to. A final element with * {@link com.google.android.exoplayer2.Timeline.Period} they belong to. A final element with
* the value {@link C#TIME_END_OF_SOURCE} indicates that there is a postroll ad. * the value {@link C#TIME_END_OF_SOURCE} indicates that there is a postroll ad.
*/ */
public AdPlaybackState(long... adGroupTimesUs) { public AdPlaybackState(Object adsId, long... adGroupTimesUs) {
int count = adGroupTimesUs.length; this(
adGroupCount = count; adsId,
this.adGroupTimesUs = Arrays.copyOf(adGroupTimesUs, count); adGroupTimesUs,
this.adGroups = new AdGroup[count]; /* adGroups= */ null,
for (int i = 0; i < count; i++) { /* adResumePositionUs= */ 0,
adGroups[i] = new AdGroup(); /* contentDurationUs= */ C.TIME_UNSET);
}
adResumePositionUs = 0;
contentDurationUs = C.TIME_UNSET;
} }
private AdPlaybackState( private AdPlaybackState(
long[] adGroupTimesUs, AdGroup[] adGroups, long adResumePositionUs, long contentDurationUs) { @Nullable Object adsId,
adGroupCount = adGroups.length; long[] adGroupTimesUs,
@Nullable AdGroup[] adGroups,
long adResumePositionUs,
long contentDurationUs) {
this.adsId = adsId;
this.adGroupTimesUs = adGroupTimesUs; this.adGroupTimesUs = adGroupTimesUs;
this.adGroups = adGroups;
this.adResumePositionUs = adResumePositionUs; this.adResumePositionUs = adResumePositionUs;
this.contentDurationUs = contentDurationUs; this.contentDurationUs = contentDurationUs;
adGroupCount = adGroupTimesUs.length;
if (adGroups == null) {
adGroups = new AdGroup[adGroupCount];
for (int i = 0; i < adGroupCount; i++) {
adGroups[i] = new AdGroup();
}
}
this.adGroups = adGroups;
} }
/** /**
...@@ -378,7 +398,8 @@ public final class AdPlaybackState { ...@@ -378,7 +398,8 @@ public final class AdPlaybackState {
} }
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length); AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = this.adGroups[adGroupIndex].withAdCount(adCount); adGroups[adGroupIndex] = this.adGroups[adGroupIndex].withAdCount(adCount);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
/** Returns an instance with the specified ad URI. */ /** Returns an instance with the specified ad URI. */
...@@ -386,7 +407,8 @@ public final class AdPlaybackState { ...@@ -386,7 +407,8 @@ public final class AdPlaybackState {
public AdPlaybackState withAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri) { public AdPlaybackState withAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri) {
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length); AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdUri(uri, adIndexInAdGroup); adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdUri(uri, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
/** Returns an instance with the specified ad marked as played. */ /** Returns an instance with the specified ad marked as played. */
...@@ -394,7 +416,8 @@ public final class AdPlaybackState { ...@@ -394,7 +416,8 @@ public final class AdPlaybackState {
public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) { public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length); AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_PLAYED, adIndexInAdGroup); adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_PLAYED, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
/** Returns an instance with the specified ad marked as skipped. */ /** Returns an instance with the specified ad marked as skipped. */
...@@ -402,7 +425,8 @@ public final class AdPlaybackState { ...@@ -402,7 +425,8 @@ public final class AdPlaybackState {
public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) { public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length); AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_SKIPPED, adIndexInAdGroup); adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_SKIPPED, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
/** Returns an instance with the specified ad marked as having a load error. */ /** Returns an instance with the specified ad marked as having a load error. */
...@@ -410,7 +434,8 @@ public final class AdPlaybackState { ...@@ -410,7 +434,8 @@ public final class AdPlaybackState {
public AdPlaybackState withAdLoadError(int adGroupIndex, int adIndexInAdGroup) { public AdPlaybackState withAdLoadError(int adGroupIndex, int adIndexInAdGroup) {
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length); AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_ERROR, adIndexInAdGroup); adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdState(AD_STATE_ERROR, adIndexInAdGroup);
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
/** /**
...@@ -421,7 +446,8 @@ public final class AdPlaybackState { ...@@ -421,7 +446,8 @@ public final class AdPlaybackState {
public AdPlaybackState withSkippedAdGroup(int adGroupIndex) { public AdPlaybackState withSkippedAdGroup(int adGroupIndex) {
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length); AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAllAdsSkipped(); adGroups[adGroupIndex] = adGroups[adGroupIndex].withAllAdsSkipped();
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
/** Returns an instance with the specified ad durations, in microseconds. */ /** Returns an instance with the specified ad durations, in microseconds. */
...@@ -431,7 +457,8 @@ public final class AdPlaybackState { ...@@ -431,7 +457,8 @@ public final class AdPlaybackState {
for (int adGroupIndex = 0; adGroupIndex < adGroupCount; adGroupIndex++) { for (int adGroupIndex = 0; adGroupIndex < adGroupCount; adGroupIndex++) {
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdDurationsUs(adDurationUs[adGroupIndex]); adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdDurationsUs(adDurationUs[adGroupIndex]);
} }
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
/** /**
...@@ -443,7 +470,8 @@ public final class AdPlaybackState { ...@@ -443,7 +470,8 @@ public final class AdPlaybackState {
if (this.adResumePositionUs == adResumePositionUs) { if (this.adResumePositionUs == adResumePositionUs) {
return this; return this;
} else { } else {
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
} }
...@@ -453,7 +481,8 @@ public final class AdPlaybackState { ...@@ -453,7 +481,8 @@ public final class AdPlaybackState {
if (this.contentDurationUs == contentDurationUs) { if (this.contentDurationUs == contentDurationUs) {
return this; return this;
} else { } else {
return new AdPlaybackState(adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs); return new AdPlaybackState(
adsId, adGroupTimesUs, adGroups, adResumePositionUs, contentDurationUs);
} }
} }
...@@ -466,7 +495,8 @@ public final class AdPlaybackState { ...@@ -466,7 +495,8 @@ public final class AdPlaybackState {
return false; return false;
} }
AdPlaybackState that = (AdPlaybackState) o; AdPlaybackState that = (AdPlaybackState) o;
return adGroupCount == that.adGroupCount return Util.areEqual(adsId, that.adsId)
&& adGroupCount == that.adGroupCount
&& adResumePositionUs == that.adResumePositionUs && adResumePositionUs == that.adResumePositionUs
&& contentDurationUs == that.contentDurationUs && contentDurationUs == that.contentDurationUs
&& Arrays.equals(adGroupTimesUs, that.adGroupTimesUs) && Arrays.equals(adGroupTimesUs, that.adGroupTimesUs)
...@@ -476,6 +506,7 @@ public final class AdPlaybackState { ...@@ -476,6 +506,7 @@ public final class AdPlaybackState {
@Override @Override
public int hashCode() { public int hashCode() {
int result = adGroupCount; int result = adGroupCount;
result = 31 * result + (adsId == null ? 0 : adsId.hashCode());
result = 31 * result + (int) adResumePositionUs; result = 31 * result + (int) adResumePositionUs;
result = 31 * result + (int) contentDurationUs; result = 31 * result + (int) contentDurationUs;
result = 31 * result + Arrays.hashCode(adGroupTimesUs); result = 31 * result + Arrays.hashCode(adGroupTimesUs);
...@@ -486,7 +517,9 @@ public final class AdPlaybackState { ...@@ -486,7 +517,9 @@ public final class AdPlaybackState {
@Override @Override
public String toString() { public String toString() {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("AdPlaybackState(adResumePositionUs="); sb.append("AdPlaybackState(adsId=");
sb.append(adsId);
sb.append(", adResumePositionUs=");
sb.append(adResumePositionUs); sb.append(adResumePositionUs);
sb.append(", adGroups=["); sb.append(", adGroups=[");
for (int i = 0; i < adGroups.length; i++) { for (int i = 0; i < adGroups.length; i++) {
......
...@@ -4349,7 +4349,8 @@ public final class ExoPlayerTest { ...@@ -4349,7 +4349,8 @@ public final class ExoPlayerTest {
public void addMediaSource_whilePlayingAd_correctMasking() throws Exception { public void addMediaSource_whilePlayingAd_correctMasking() throws Exception {
long contentDurationMs = 10_000; long contentDurationMs = 10_000;
long adDurationMs = 100_000; long adDurationMs = 100_000;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adGroupTimesUs...= */ 0); AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0);
adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1); adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1);
adPlaybackState = adPlaybackState =
adPlaybackState.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, Uri.EMPTY); adPlaybackState.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, Uri.EMPTY);
...@@ -4455,7 +4456,8 @@ public final class ExoPlayerTest { ...@@ -4455,7 +4456,8 @@ public final class ExoPlayerTest {
public void seekTo_whilePlayingAd_correctMasking() throws Exception { public void seekTo_whilePlayingAd_correctMasking() throws Exception {
long contentDurationMs = 10_000; long contentDurationMs = 10_000;
long adDurationMs = 4_000; long adDurationMs = 4_000;
AdPlaybackState adPlaybackState = new AdPlaybackState(/* adGroupTimesUs...= */ 0); AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0);
adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1); adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1);
adPlaybackState = adPlaybackState =
adPlaybackState.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, Uri.EMPTY); adPlaybackState.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, Uri.EMPTY);
......
...@@ -404,7 +404,8 @@ public final class MediaPeriodQueueTest { ...@@ -404,7 +404,8 @@ public final class MediaPeriodQueueTest {
private void setupAdTimeline(long... adGroupTimesUs) { private void setupAdTimeline(long... adGroupTimesUs) {
adPlaybackState = adPlaybackState =
new AdPlaybackState(adGroupTimesUs).withContentDurationUs(CONTENT_DURATION_US); new AdPlaybackState(/* adsId= */ new Object(), adGroupTimesUs)
.withContentDurationUs(CONTENT_DURATION_US);
SinglePeriodAdTimeline adTimeline = SinglePeriodAdTimeline adTimeline =
new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState); new SinglePeriodAdTimeline(CONTENT_TIMELINE, adPlaybackState);
setupTimeline(adTimeline); setupTimeline(adTimeline);
...@@ -498,7 +499,8 @@ public final class MediaPeriodQueueTest { ...@@ -498,7 +499,8 @@ public final class MediaPeriodQueueTest {
private void updateAdPlaybackStateAndTimeline(long... adGroupTimesUs) { private void updateAdPlaybackStateAndTimeline(long... adGroupTimesUs) {
adPlaybackState = adPlaybackState =
new AdPlaybackState(adGroupTimesUs).withContentDurationUs(CONTENT_DURATION_US); new AdPlaybackState(/* adsId= */ new Object(), adGroupTimesUs)
.withContentDurationUs(CONTENT_DURATION_US);
updateTimeline(); updateTimeline();
} }
......
...@@ -419,7 +419,9 @@ public final class DefaultPlaybackSessionManagerTest { ...@@ -419,7 +419,9 @@ public final class DefaultPlaybackSessionManagerTest {
/* isDynamic= */ false, /* isDynamic= */ false,
/* durationUs =*/ 10 * C.MICROS_PER_SECOND, /* durationUs =*/ 10 * C.MICROS_PER_SECOND,
new AdPlaybackState( new AdPlaybackState(
/* adGroupTimesUs=... */ 2 * C.MICROS_PER_SECOND, 5 * C.MICROS_PER_SECOND) /* adsId= */ new Object(),
/* adGroupTimesUs=... */ 2 * C.MICROS_PER_SECOND,
5 * C.MICROS_PER_SECOND)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1))); .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)));
EventTime adEventTime1 = EventTime adEventTime1 =
...@@ -701,7 +703,8 @@ public final class DefaultPlaybackSessionManagerTest { ...@@ -701,7 +703,8 @@ public final class DefaultPlaybackSessionManagerTest {
/* isSeekable= */ true, /* isSeekable= */ true,
/* isDynamic= */ false, /* isDynamic= */ false,
/* durationUs =*/ 10 * C.MICROS_PER_SECOND, /* durationUs =*/ 10 * C.MICROS_PER_SECOND,
new AdPlaybackState(/* adGroupTimesUs=... */ C.TIME_END_OF_SOURCE) new AdPlaybackState(
/* adsId= */ new Object(), /* adGroupTimesUs=... */ C.TIME_END_OF_SOURCE)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1))); .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)));
EventTime adEventTime = EventTime adEventTime =
createEventTime( createEventTime(
...@@ -903,7 +906,10 @@ public final class DefaultPlaybackSessionManagerTest { ...@@ -903,7 +906,10 @@ public final class DefaultPlaybackSessionManagerTest {
/* isSeekable= */ true, /* isSeekable= */ true,
/* isDynamic= */ false, /* isDynamic= */ false,
/* durationUs =*/ 10 * C.MICROS_PER_SECOND, /* durationUs =*/ 10 * C.MICROS_PER_SECOND,
new AdPlaybackState(/* adGroupTimesUs=... */ 0, 5 * C.MICROS_PER_SECOND) new AdPlaybackState(
/* adsId= */ new Object(), /* adGroupTimesUs=... */
0,
5 * C.MICROS_PER_SECOND)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1))); .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)));
EventTime adEventTime1 = EventTime adEventTime1 =
...@@ -983,7 +989,9 @@ public final class DefaultPlaybackSessionManagerTest { ...@@ -983,7 +989,9 @@ public final class DefaultPlaybackSessionManagerTest {
/* isDynamic= */ false, /* isDynamic= */ false,
/* durationUs =*/ 10 * C.MICROS_PER_SECOND, /* durationUs =*/ 10 * C.MICROS_PER_SECOND,
new AdPlaybackState( new AdPlaybackState(
/* adGroupTimesUs=... */ 2 * C.MICROS_PER_SECOND, 5 * C.MICROS_PER_SECOND) /* adsId= */ new Object(), /* adGroupTimesUs=... */
2 * C.MICROS_PER_SECOND,
5 * C.MICROS_PER_SECOND)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1))); .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)));
EventTime adEventTime1 = EventTime adEventTime1 =
...@@ -1032,7 +1040,10 @@ public final class DefaultPlaybackSessionManagerTest { ...@@ -1032,7 +1040,10 @@ public final class DefaultPlaybackSessionManagerTest {
/* isSeekable= */ true, /* isSeekable= */ true,
/* isDynamic= */ false, /* isDynamic= */ false,
/* durationUs =*/ 10 * C.MICROS_PER_SECOND, /* durationUs =*/ 10 * C.MICROS_PER_SECOND,
new AdPlaybackState(/* adGroupTimesUs=... */ 0, 5 * C.MICROS_PER_SECOND) new AdPlaybackState(
/* adsId= */ new Object(), /* adGroupTimesUs=... */
0,
5 * C.MICROS_PER_SECOND)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1))); .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)));
EventTime adEventTime1 = EventTime adEventTime1 =
......
...@@ -31,12 +31,13 @@ public final class AdPlaybackStateTest { ...@@ -31,12 +31,13 @@ public final class AdPlaybackStateTest {
private static final long[] TEST_AD_GROUP_TMES_US = new long[] {0, C.msToUs(10_000)}; private static final long[] TEST_AD_GROUP_TMES_US = new long[] {0, C.msToUs(10_000)};
private static final Uri TEST_URI = Uri.EMPTY; private static final Uri TEST_URI = Uri.EMPTY;
private static final Object TEST_ADS_ID = new Object();
private AdPlaybackState state; private AdPlaybackState state;
@Before @Before
public void setUp() { public void setUp() {
state = new AdPlaybackState(TEST_AD_GROUP_TMES_US); state = new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TMES_US);
} }
@Test @Test
......
...@@ -77,7 +77,7 @@ public final class AdsMediaSourceTest { ...@@ -77,7 +77,7 @@ public final class AdsMediaSourceTest {
CONTENT_TIMELINE.getUidOfPeriod(/* periodIndex= */ 0); CONTENT_TIMELINE.getUidOfPeriod(/* periodIndex= */ 0);
private static final AdPlaybackState AD_PLAYBACK_STATE = private static final AdPlaybackState AD_PLAYBACK_STATE =
new AdPlaybackState(/* adGroupTimesUs...= */ 0) new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0)
.withContentDurationUs(CONTENT_DURATION_US) .withContentDurationUs(CONTENT_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, Uri.EMPTY) .withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, Uri.EMPTY)
......
...@@ -246,7 +246,8 @@ public final class FakeTimeline extends Timeline { ...@@ -246,7 +246,8 @@ public final class FakeTimeline extends Timeline {
*/ */
public static AdPlaybackState createAdPlaybackState(int adsPerAdGroup, long... adGroupTimesUs) { public static AdPlaybackState createAdPlaybackState(int adsPerAdGroup, long... adGroupTimesUs) {
int adGroupCount = adGroupTimesUs.length; int adGroupCount = adGroupTimesUs.length;
AdPlaybackState adPlaybackState = new AdPlaybackState(adGroupTimesUs); AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), adGroupTimesUs);
long[][] adDurationsUs = new long[adGroupCount][]; long[][] adDurationsUs = new long[adGroupCount][];
for (int i = 0; i < adGroupCount; i++) { for (int i = 0; i < adGroupCount; i++) {
adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ i, adsPerAdGroup); adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ i, adsPerAdGroup);
......
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