mirror of
https://github.com/androidx/media.git
synced 2025-05-18 13:09:56 +08:00
Allow to specify the number of removed ad groups in AdPlaybackState.
This helps to remove old ad groups (e.g. those that fell out of the live window) to keep the data size of AdPlaybackState small. Also added this case to some existing unit tests to ensure it's covered. PiperOrigin-RevId: 376170653
This commit is contained in:
parent
0d0ccadc83
commit
2938d40bf4
@ -699,6 +699,14 @@ public abstract class Timeline implements Bundleable {
|
|||||||
return adPlaybackState.adGroupCount;
|
return adPlaybackState.adGroupCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of removed ad groups in the period. Ad groups with indices between {@code
|
||||||
|
* 0} (inclusive) and {@code removedAdGroupCount} (exclusive) will be empty.
|
||||||
|
*/
|
||||||
|
public int getRemovedAdGroupCount() {
|
||||||
|
return adPlaybackState.adGroupCount;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the time of the ad group at index {@code adGroupIndex} in the period, in
|
* Returns the time of the ad group at index {@code adGroupIndex} in the period, in
|
||||||
* microseconds.
|
* microseconds.
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package com.google.android.exoplayer2.source.ads;
|
package com.google.android.exoplayer2.source.ads;
|
||||||
|
|
||||||
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
||||||
import static java.lang.Math.max;
|
import static java.lang.Math.max;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -417,7 +418,10 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
/* adsId= */ null,
|
/* adsId= */ null,
|
||||||
/* adGroups= */ new AdGroup[0],
|
/* adGroups= */ new AdGroup[0],
|
||||||
/* adResumePositionUs= */ 0L,
|
/* adResumePositionUs= */ 0L,
|
||||||
/* contentDurationUs= */ C.TIME_UNSET);
|
/* contentDurationUs= */ C.TIME_UNSET,
|
||||||
|
/* removedAdGroupCount= */ 0);
|
||||||
|
|
||||||
|
private static final AdGroup REMOVED_AD_GROUP = new AdGroup(/* timeUs= */ 0).withAdCount(0);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The opaque identifier for ads with which this instance is associated, or {@code null} if unset.
|
* The opaque identifier for ads with which this instance is associated, or {@code null} if unset.
|
||||||
@ -432,6 +436,12 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
* The duration of the content period in microseconds, if known. {@link C#TIME_UNSET} otherwise.
|
* The duration of the content period in microseconds, if known. {@link C#TIME_UNSET} otherwise.
|
||||||
*/
|
*/
|
||||||
public final long contentDurationUs;
|
public final long contentDurationUs;
|
||||||
|
/**
|
||||||
|
* The number of ad groups the have been removed. Ad groups with indices between {@code 0}
|
||||||
|
* (inclusive) and {@code removedAdGroupCount} (exclusive) will be empty and must not be modified
|
||||||
|
* by any of the {@code with*} methods.
|
||||||
|
*/
|
||||||
|
public final int removedAdGroupCount;
|
||||||
|
|
||||||
private final AdGroup[] adGroups;
|
private final AdGroup[] adGroups;
|
||||||
|
|
||||||
@ -448,21 +458,29 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
adsId,
|
adsId,
|
||||||
createEmptyAdGroups(adGroupTimesUs),
|
createEmptyAdGroups(adGroupTimesUs),
|
||||||
/* adResumePositionUs= */ 0,
|
/* adResumePositionUs= */ 0,
|
||||||
/* contentDurationUs= */ C.TIME_UNSET);
|
/* contentDurationUs= */ C.TIME_UNSET,
|
||||||
|
/* removedAdGroupCount= */ 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private AdPlaybackState(
|
private AdPlaybackState(
|
||||||
@Nullable Object adsId, AdGroup[] adGroups, long adResumePositionUs, long contentDurationUs) {
|
@Nullable Object adsId,
|
||||||
|
AdGroup[] adGroups,
|
||||||
|
long adResumePositionUs,
|
||||||
|
long contentDurationUs,
|
||||||
|
int removedAdGroupCount) {
|
||||||
this.adsId = adsId;
|
this.adsId = adsId;
|
||||||
this.adResumePositionUs = adResumePositionUs;
|
this.adResumePositionUs = adResumePositionUs;
|
||||||
this.contentDurationUs = contentDurationUs;
|
this.contentDurationUs = contentDurationUs;
|
||||||
adGroupCount = adGroups.length;
|
adGroupCount = adGroups.length + removedAdGroupCount;
|
||||||
this.adGroups = adGroups;
|
this.adGroups = adGroups;
|
||||||
|
this.removedAdGroupCount = removedAdGroupCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns the specified {@link AdGroup}. */
|
/** Returns the specified {@link AdGroup}. */
|
||||||
public AdGroup getAdGroup(int adGroupIndex) {
|
public AdGroup getAdGroup(int adGroupIndex) {
|
||||||
return adGroups[adGroupIndex];
|
return adGroupIndex < removedAdGroupCount
|
||||||
|
? REMOVED_AD_GROUP
|
||||||
|
: adGroups[adGroupIndex - removedAdGroupCount];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -480,11 +498,11 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
public int getAdGroupIndexForPositionUs(long positionUs, long periodDurationUs) {
|
public int getAdGroupIndexForPositionUs(long positionUs, long periodDurationUs) {
|
||||||
// Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
|
// Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
|
||||||
// In practice we expect there to be few ad groups so the search shouldn't be expensive.
|
// In practice we expect there to be few ad groups so the search shouldn't be expensive.
|
||||||
int index = adGroups.length - 1;
|
int index = adGroupCount - 1;
|
||||||
while (index >= 0 && isPositionBeforeAdGroup(positionUs, periodDurationUs, index)) {
|
while (index >= 0 && isPositionBeforeAdGroup(positionUs, periodDurationUs, index)) {
|
||||||
index--;
|
index--;
|
||||||
}
|
}
|
||||||
return index >= 0 && adGroups[index].hasUnplayedAds() ? index : C.INDEX_UNSET;
|
return index >= 0 && getAdGroup(index).hasUnplayedAds() ? index : C.INDEX_UNSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -505,21 +523,22 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
}
|
}
|
||||||
// Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
|
// Use a linear search as the array elements may not be increasing due to TIME_END_OF_SOURCE.
|
||||||
// In practice we expect there to be few ad groups so the search shouldn't be expensive.
|
// In practice we expect there to be few ad groups so the search shouldn't be expensive.
|
||||||
int index = 0;
|
int index = removedAdGroupCount;
|
||||||
while (index < adGroups.length
|
while (index < adGroupCount
|
||||||
&& ((adGroups[index].timeUs != C.TIME_END_OF_SOURCE && adGroups[index].timeUs <= positionUs)
|
&& ((getAdGroup(index).timeUs != C.TIME_END_OF_SOURCE
|
||||||
|| !adGroups[index].shouldPlayAdGroup())) {
|
&& getAdGroup(index).timeUs <= positionUs)
|
||||||
|
|| !getAdGroup(index).shouldPlayAdGroup())) {
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
return index < adGroups.length ? index : C.INDEX_UNSET;
|
return index < adGroupCount ? 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}. */
|
||||||
public boolean isAdInErrorState(int adGroupIndex, int adIndexInAdGroup) {
|
public boolean isAdInErrorState(int adGroupIndex, int adIndexInAdGroup) {
|
||||||
if (adGroupIndex >= adGroups.length) {
|
if (adGroupIndex >= adGroupCount) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
AdGroup adGroup = adGroups[adGroupIndex];
|
AdGroup adGroup = getAdGroup(adGroupIndex);
|
||||||
if (adGroup.count == C.LENGTH_UNSET || adIndexInAdGroup >= adGroup.count) {
|
if (adGroup.count == C.LENGTH_UNSET || adIndexInAdGroup >= adGroup.count) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -536,9 +555,11 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
*/
|
*/
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withAdGroupTimeUs(int adGroupIndex, long adGroupTimeUs) {
|
public AdPlaybackState withAdGroupTimeUs(int adGroupIndex, long adGroupTimeUs) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
||||||
adGroups[adGroupIndex] = this.adGroups[adGroupIndex].withTimeUs(adGroupTimeUs);
|
adGroups[adjustedIndex] = this.adGroups[adjustedIndex].withTimeUs(adGroupTimeUs);
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -551,16 +572,18 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
*/
|
*/
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withNewAdGroup(int adGroupIndex, long adGroupTimeUs) {
|
public AdPlaybackState withNewAdGroup(int adGroupIndex, long adGroupTimeUs) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
AdGroup newAdGroup = new AdGroup(adGroupTimeUs);
|
AdGroup newAdGroup = new AdGroup(adGroupTimeUs);
|
||||||
AdGroup[] adGroups = Util.nullSafeArrayAppend(this.adGroups, newAdGroup);
|
AdGroup[] adGroups = Util.nullSafeArrayAppend(this.adGroups, newAdGroup);
|
||||||
System.arraycopy(
|
System.arraycopy(
|
||||||
/* src= */ adGroups,
|
/* src= */ adGroups,
|
||||||
/* srcPos= */ adGroupIndex,
|
/* srcPos= */ adjustedIndex,
|
||||||
/* dest= */ adGroups,
|
/* dest= */ adGroups,
|
||||||
/* destPos= */ adGroupIndex + 1,
|
/* destPos= */ adjustedIndex + 1,
|
||||||
/* length= */ adGroupCount - adGroupIndex);
|
/* length= */ this.adGroups.length - adjustedIndex);
|
||||||
adGroups[adGroupIndex] = newAdGroup;
|
adGroups[adjustedIndex] = newAdGroup;
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -570,44 +593,56 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withAdCount(int adGroupIndex, int adCount) {
|
public AdPlaybackState withAdCount(int adGroupIndex, int adCount) {
|
||||||
checkArgument(adCount > 0);
|
checkArgument(adCount > 0);
|
||||||
if (adGroups[adGroupIndex].count == adCount) {
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
|
if (adGroups[adjustedIndex].count == adCount) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
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[adjustedIndex] = this.adGroups[adjustedIndex].withAdCount(adCount);
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an instance with the specified ad URI. */
|
/** Returns an instance with the specified ad URI. */
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri) {
|
public AdPlaybackState withAdUri(int adGroupIndex, int adIndexInAdGroup, Uri uri) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
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[adjustedIndex] = adGroups[adjustedIndex].withAdUri(uri, adIndexInAdGroup);
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an instance with the specified ad marked as played. */
|
/** Returns an instance with the specified ad marked as played. */
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) {
|
public AdPlaybackState withPlayedAd(int adGroupIndex, int adIndexInAdGroup) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
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[adjustedIndex] =
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
adGroups[adjustedIndex].withAdState(AD_STATE_PLAYED, adIndexInAdGroup);
|
||||||
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an instance with the specified ad marked as skipped. */
|
/** Returns an instance with the specified ad marked as skipped. */
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) {
|
public AdPlaybackState withSkippedAd(int adGroupIndex, int adIndexInAdGroup) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
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[adjustedIndex] =
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
adGroups[adjustedIndex].withAdState(AD_STATE_SKIPPED, adIndexInAdGroup);
|
||||||
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 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. */
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withAdLoadError(int adGroupIndex, int adIndexInAdGroup) {
|
public AdPlaybackState withAdLoadError(int adGroupIndex, int adIndexInAdGroup) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
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[adjustedIndex] = adGroups[adjustedIndex].withAdState(AD_STATE_ERROR, adIndexInAdGroup);
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -616,19 +651,27 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
*/
|
*/
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withSkippedAdGroup(int adGroupIndex) {
|
public AdPlaybackState withSkippedAdGroup(int adGroupIndex) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
||||||
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAllAdsSkipped();
|
adGroups[adjustedIndex] = adGroups[adjustedIndex].withAllAdsSkipped();
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns an instance with the specified ad durations, in microseconds. */
|
/**
|
||||||
|
* Returns an instance with the specified ad durations, in microseconds.
|
||||||
|
*
|
||||||
|
* <p>Must only be used if {@link #removedAdGroupCount} is 0.
|
||||||
|
*/
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withAdDurationsUs(long[][] adDurationUs) {
|
public AdPlaybackState withAdDurationsUs(long[][] adDurationUs) {
|
||||||
|
checkState(removedAdGroupCount == 0);
|
||||||
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
||||||
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(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -637,9 +680,11 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
*/
|
*/
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withAdDurationsUs(int adGroupIndex, long... adDurationsUs) {
|
public AdPlaybackState withAdDurationsUs(int adGroupIndex, long... adDurationsUs) {
|
||||||
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
||||||
adGroups[adGroupIndex] = adGroups[adGroupIndex].withAdDurationsUs(adDurationsUs);
|
adGroups[adjustedIndex] = adGroups[adjustedIndex].withAdDurationsUs(adDurationsUs);
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -651,7 +696,8 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
if (this.adResumePositionUs == adResumePositionUs) {
|
if (this.adResumePositionUs == adResumePositionUs) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,7 +707,33 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
if (this.contentDurationUs == contentDurationUs) {
|
if (this.contentDurationUs == contentDurationUs) {
|
||||||
return this;
|
return this;
|
||||||
} else {
|
} else {
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an instance with the specified number of {@link #removedAdGroupCount removed ad
|
||||||
|
* groups}.
|
||||||
|
*
|
||||||
|
* <p>Ad groups with indices between {@code 0} (inclusive) and {@code removedAdGroupCount}
|
||||||
|
* (exclusive) will be empty and must not be modified by any of the {@code with*} methods.
|
||||||
|
*/
|
||||||
|
@CheckResult
|
||||||
|
public AdPlaybackState withRemovedAdGroupCount(int removedAdGroupCount) {
|
||||||
|
if (this.removedAdGroupCount == removedAdGroupCount) {
|
||||||
|
return this;
|
||||||
|
} else {
|
||||||
|
checkArgument(removedAdGroupCount > this.removedAdGroupCount);
|
||||||
|
AdGroup[] adGroups = new AdGroup[adGroupCount - removedAdGroupCount];
|
||||||
|
System.arraycopy(
|
||||||
|
/* src= */ this.adGroups,
|
||||||
|
/* srcPos= */ removedAdGroupCount - this.removedAdGroupCount,
|
||||||
|
/* dest= */ adGroups,
|
||||||
|
/* destPos= */ 0,
|
||||||
|
/* length= */ adGroups.length);
|
||||||
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,13 +743,15 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
*/
|
*/
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withContentResumeOffsetUs(int adGroupIndex, long contentResumeOffsetUs) {
|
public AdPlaybackState withContentResumeOffsetUs(int adGroupIndex, long contentResumeOffsetUs) {
|
||||||
if (adGroups[adGroupIndex].contentResumeOffsetUs == contentResumeOffsetUs) {
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
|
if (adGroups[adjustedIndex].contentResumeOffsetUs == contentResumeOffsetUs) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
||||||
adGroups[adGroupIndex] =
|
adGroups[adjustedIndex] =
|
||||||
adGroups[adGroupIndex].withContentResumeOffsetUs(contentResumeOffsetUs);
|
adGroups[adjustedIndex].withContentResumeOffsetUs(contentResumeOffsetUs);
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -686,12 +760,15 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
*/
|
*/
|
||||||
@CheckResult
|
@CheckResult
|
||||||
public AdPlaybackState withIsServerSideInserted(int adGroupIndex, boolean isServerSideInserted) {
|
public AdPlaybackState withIsServerSideInserted(int adGroupIndex, boolean isServerSideInserted) {
|
||||||
if (adGroups[adGroupIndex].isServerSideInserted == isServerSideInserted) {
|
int adjustedIndex = adGroupIndex - removedAdGroupCount;
|
||||||
|
if (adGroups[adjustedIndex].isServerSideInserted == isServerSideInserted) {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
AdGroup[] adGroups = Util.nullSafeArrayCopy(this.adGroups, this.adGroups.length);
|
||||||
adGroups[adGroupIndex] = adGroups[adGroupIndex].withIsServerSideInserted(isServerSideInserted);
|
adGroups[adjustedIndex] =
|
||||||
return new AdPlaybackState(adsId, adGroups, adResumePositionUs, contentDurationUs);
|
adGroups[adjustedIndex].withIsServerSideInserted(isServerSideInserted);
|
||||||
|
return new AdPlaybackState(
|
||||||
|
adsId, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -707,6 +784,7 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
&& adGroupCount == that.adGroupCount
|
&& adGroupCount == that.adGroupCount
|
||||||
&& adResumePositionUs == that.adResumePositionUs
|
&& adResumePositionUs == that.adResumePositionUs
|
||||||
&& contentDurationUs == that.contentDurationUs
|
&& contentDurationUs == that.contentDurationUs
|
||||||
|
&& removedAdGroupCount == that.removedAdGroupCount
|
||||||
&& Arrays.equals(adGroups, that.adGroups);
|
&& Arrays.equals(adGroups, that.adGroups);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,6 +794,7 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
result = 31 * result + (adsId == null ? 0 : adsId.hashCode());
|
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 + removedAdGroupCount;
|
||||||
result = 31 * result + Arrays.hashCode(adGroups);
|
result = 31 * result + Arrays.hashCode(adGroups);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -776,7 +855,7 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
// The end of the content is at (but not before) any postroll ad, and after any other ads.
|
// The end of the content is at (but not before) any postroll ad, and after any other ads.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
long adGroupPositionUs = adGroups[adGroupIndex].timeUs;
|
long adGroupPositionUs = getAdGroup(adGroupIndex).timeUs;
|
||||||
if (adGroupPositionUs == C.TIME_END_OF_SOURCE) {
|
if (adGroupPositionUs == C.TIME_END_OF_SOURCE) {
|
||||||
return periodDurationUs == C.TIME_UNSET || positionUs < periodDurationUs;
|
return periodDurationUs == C.TIME_UNSET || positionUs < periodDurationUs;
|
||||||
} else {
|
} else {
|
||||||
@ -788,12 +867,18 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
|
|
||||||
@Documented
|
@Documented
|
||||||
@Retention(RetentionPolicy.SOURCE)
|
@Retention(RetentionPolicy.SOURCE)
|
||||||
@IntDef({FIELD_AD_GROUPS, FIELD_AD_RESUME_POSITION_US, FIELD_CONTENT_DURATION_US})
|
@IntDef({
|
||||||
|
FIELD_AD_GROUPS,
|
||||||
|
FIELD_AD_RESUME_POSITION_US,
|
||||||
|
FIELD_CONTENT_DURATION_US,
|
||||||
|
FIELD_REMOVED_AD_GROUP_COUNT
|
||||||
|
})
|
||||||
private @interface FieldNumber {}
|
private @interface FieldNumber {}
|
||||||
|
|
||||||
private static final int FIELD_AD_GROUPS = 1;
|
private static final int FIELD_AD_GROUPS = 1;
|
||||||
private static final int FIELD_AD_RESUME_POSITION_US = 2;
|
private static final int FIELD_AD_RESUME_POSITION_US = 2;
|
||||||
private static final int FIELD_CONTENT_DURATION_US = 3;
|
private static final int FIELD_CONTENT_DURATION_US = 3;
|
||||||
|
private static final int FIELD_REMOVED_AD_GROUP_COUNT = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
@ -812,6 +897,7 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
bundle.putParcelableArrayList(keyForField(FIELD_AD_GROUPS), adGroupBundleList);
|
bundle.putParcelableArrayList(keyForField(FIELD_AD_GROUPS), adGroupBundleList);
|
||||||
bundle.putLong(keyForField(FIELD_AD_RESUME_POSITION_US), adResumePositionUs);
|
bundle.putLong(keyForField(FIELD_AD_RESUME_POSITION_US), adResumePositionUs);
|
||||||
bundle.putLong(keyForField(FIELD_CONTENT_DURATION_US), contentDurationUs);
|
bundle.putLong(keyForField(FIELD_CONTENT_DURATION_US), contentDurationUs);
|
||||||
|
bundle.putInt(keyForField(FIELD_REMOVED_AD_GROUP_COUNT), removedAdGroupCount);
|
||||||
return bundle;
|
return bundle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -839,7 +925,9 @@ public final class AdPlaybackState implements Bundleable {
|
|||||||
bundle.getLong(keyForField(FIELD_AD_RESUME_POSITION_US), /* defaultValue= */ 0);
|
bundle.getLong(keyForField(FIELD_AD_RESUME_POSITION_US), /* defaultValue= */ 0);
|
||||||
long contentDurationUs =
|
long contentDurationUs =
|
||||||
bundle.getLong(keyForField(FIELD_CONTENT_DURATION_US), /* defaultValue= */ C.TIME_UNSET);
|
bundle.getLong(keyForField(FIELD_CONTENT_DURATION_US), /* defaultValue= */ C.TIME_UNSET);
|
||||||
return new AdPlaybackState(/* adsId= */ null, adGroups, adResumePositionUs, contentDurationUs);
|
int removedAdGroupCount = bundle.getInt(keyForField(FIELD_REMOVED_AD_GROUP_COUNT));
|
||||||
|
return new AdPlaybackState(
|
||||||
|
/* adsId= */ null, adGroups, adResumePositionUs, contentDurationUs, removedAdGroupCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String keyForField(@FieldNumber int field) {
|
private static String keyForField(@FieldNumber int field) {
|
||||||
|
@ -23,7 +23,6 @@ import static org.junit.Assert.fail;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
@ -31,84 +30,90 @@ import org.junit.runner.RunWith;
|
|||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class AdPlaybackStateTest {
|
public 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_TIMES_US = new long[] {0, 5_000_000, 10_000_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 static final Object TEST_ADS_ID = new Object();
|
||||||
|
|
||||||
private AdPlaybackState state;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
state = new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TMES_US);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAdCount() {
|
public void setAdCount() {
|
||||||
assertThat(state.getAdGroup(0).count).isEqualTo(C.LENGTH_UNSET);
|
AdPlaybackState state =
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
assertThat(state.getAdGroup(0).count).isEqualTo(1);
|
|
||||||
|
assertThat(state.getAdGroup(1).count).isEqualTo(C.LENGTH_UNSET);
|
||||||
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1);
|
||||||
|
|
||||||
|
assertThat(state.getAdGroup(1).count).isEqualTo(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAdUriBeforeAdCount() {
|
public void setAdUriBeforeAdCount() {
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, TEST_URI);
|
AdPlaybackState state =
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).uris[0]).isNull();
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI);
|
||||||
assertThat(state.getAdGroup(0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2);
|
||||||
assertThat(state.getAdGroup(0).uris[1]).isSameInstanceAs(TEST_URI);
|
|
||||||
assertThat(state.getAdGroup(0).states[1]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
assertThat(state.getAdGroup(1).uris[0]).isNull();
|
||||||
|
assertThat(state.getAdGroup(1).states[0]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
||||||
|
assertThat(state.getAdGroup(1).uris[1]).isSameInstanceAs(TEST_URI);
|
||||||
|
assertThat(state.getAdGroup(1).states[1]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAdErrorBeforeAdCount() {
|
public void setAdErrorBeforeAdCount() {
|
||||||
state = state.withAdLoadError(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
AdPlaybackState state =
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).uris[0]).isNull();
|
state = state.withAdLoadError(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0);
|
||||||
assertThat(state.getAdGroup(0).states[0]).isEqualTo(AdPlaybackState.AD_STATE_ERROR);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2);
|
||||||
assertThat(state.isAdInErrorState(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0)).isTrue();
|
|
||||||
assertThat(state.getAdGroup(0).states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
assertThat(state.getAdGroup(1).uris[0]).isNull();
|
||||||
assertThat(state.isAdInErrorState(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1)).isFalse();
|
assertThat(state.getAdGroup(1).states[0]).isEqualTo(AdPlaybackState.AD_STATE_ERROR);
|
||||||
|
assertThat(state.isAdInErrorState(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0)).isTrue();
|
||||||
|
assertThat(state.getAdGroup(1).states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
||||||
|
assertThat(state.isAdInErrorState(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1)).isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withAdGroupTimeUs_updatesAdGroupTimeUs() {
|
public void withAdGroupTimeUs_updatesAdGroupTimeUs() {
|
||||||
AdPlaybackState state = new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0, 10_000);
|
AdPlaybackState state =
|
||||||
|
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0, 5_000, 10_000)
|
||||||
|
.withRemovedAdGroupCount(1);
|
||||||
|
|
||||||
state =
|
state =
|
||||||
state
|
state
|
||||||
.withAdGroupTimeUs(/* adGroupIndex= */ 0, 3_000)
|
.withAdGroupTimeUs(/* adGroupIndex= */ 1, 3_000)
|
||||||
.withAdGroupTimeUs(/* adGroupIndex= */ 1, 6_000);
|
.withAdGroupTimeUs(/* adGroupIndex= */ 2, 6_000);
|
||||||
|
|
||||||
assertThat(state.adGroupCount).isEqualTo(2);
|
assertThat(state.adGroupCount).isEqualTo(3);
|
||||||
assertThat(state.getAdGroup(0).timeUs).isEqualTo(3_000);
|
assertThat(state.getAdGroup(1).timeUs).isEqualTo(3_000);
|
||||||
assertThat(state.getAdGroup(1).timeUs).isEqualTo(6_000);
|
assertThat(state.getAdGroup(2).timeUs).isEqualTo(6_000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void withNewAdGroup_addsGroupAndKeepsExistingGroups() {
|
public void withNewAdGroup_addsGroupAndKeepsExistingGroups() {
|
||||||
AdPlaybackState state =
|
AdPlaybackState state =
|
||||||
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 3_000, 6_000)
|
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0, 3_000, 6_000)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)
|
.withRemovedAdGroupCount(1)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2)
|
||||||
.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, TEST_URI)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
|
||||||
.withSkippedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0);
|
.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI)
|
||||||
|
.withSkippedAd(/* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0);
|
||||||
|
|
||||||
state =
|
state =
|
||||||
state
|
state
|
||||||
.withNewAdGroup(/* adGroupIndex= */ 0, /* adGroupTimeUs= */ 1_000)
|
.withNewAdGroup(/* adGroupIndex= */ 1, /* adGroupTimeUs= */ 1_000)
|
||||||
.withNewAdGroup(/* adGroupIndex= */ 2, /* adGroupTimeUs= */ 5_000)
|
.withNewAdGroup(/* adGroupIndex= */ 3, /* adGroupTimeUs= */ 5_000)
|
||||||
.withNewAdGroup(/* adGroupIndex= */ 4, /* adGroupTimeUs= */ 8_000);
|
.withNewAdGroup(/* adGroupIndex= */ 5, /* adGroupTimeUs= */ 8_000);
|
||||||
|
|
||||||
assertThat(state.adGroupCount).isEqualTo(5);
|
assertThat(state.adGroupCount).isEqualTo(6);
|
||||||
assertThat(state.getAdGroup(0).count).isEqualTo(C.INDEX_UNSET);
|
assertThat(state.getAdGroup(1).count).isEqualTo(C.INDEX_UNSET);
|
||||||
assertThat(state.getAdGroup(1).count).isEqualTo(2);
|
assertThat(state.getAdGroup(2).count).isEqualTo(2);
|
||||||
assertThat(state.getAdGroup(1).uris[1]).isSameInstanceAs(TEST_URI);
|
assertThat(state.getAdGroup(2).uris[1]).isSameInstanceAs(TEST_URI);
|
||||||
assertThat(state.getAdGroup(2).count).isEqualTo(C.INDEX_UNSET);
|
assertThat(state.getAdGroup(3).count).isEqualTo(C.INDEX_UNSET);
|
||||||
assertThat(state.getAdGroup(3).count).isEqualTo(1);
|
assertThat(state.getAdGroup(4).count).isEqualTo(1);
|
||||||
assertThat(state.getAdGroup(3).states[0]).isEqualTo(AdPlaybackState.AD_STATE_SKIPPED);
|
assertThat(state.getAdGroup(4).states[0]).isEqualTo(AdPlaybackState.AD_STATE_SKIPPED);
|
||||||
assertThat(state.getAdGroup(4).count).isEqualTo(C.INDEX_UNSET);
|
assertThat(state.getAdGroup(5).count).isEqualTo(C.INDEX_UNSET);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -129,92 +134,107 @@ public class AdPlaybackStateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFirstAdIndexToPlayIsZero() {
|
public void getFirstAdIndexToPlayIsZero() {
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
AdPlaybackState state =
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2, TEST_URI);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 3);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).getFirstAdIndexToPlay()).isEqualTo(0);
|
assertThat(state.getAdGroup(1).getFirstAdIndexToPlay()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFirstAdIndexToPlaySkipsPlayedAd() {
|
public void getFirstAdIndexToPlaySkipsPlayedAd() {
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
AdPlaybackState state =
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2, TEST_URI);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 3);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI);
|
||||||
|
|
||||||
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
state = state.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).getFirstAdIndexToPlay()).isEqualTo(1);
|
assertThat(state.getAdGroup(1).getFirstAdIndexToPlay()).isEqualTo(1);
|
||||||
assertThat(state.getAdGroup(0).states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
assertThat(state.getAdGroup(1).states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
||||||
assertThat(state.getAdGroup(0).states[2]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
assertThat(state.getAdGroup(1).states[2]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFirstAdIndexToPlaySkipsSkippedAd() {
|
public void getFirstAdIndexToPlaySkipsSkippedAd() {
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
AdPlaybackState state =
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2, TEST_URI);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 3);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI);
|
||||||
|
|
||||||
state = state.withSkippedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
state = state.withSkippedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).getFirstAdIndexToPlay()).isEqualTo(1);
|
assertThat(state.getAdGroup(1).getFirstAdIndexToPlay()).isEqualTo(1);
|
||||||
assertThat(state.getAdGroup(0).states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
assertThat(state.getAdGroup(1).states[1]).isEqualTo(AdPlaybackState.AD_STATE_UNAVAILABLE);
|
||||||
assertThat(state.getAdGroup(0).states[2]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
assertThat(state.getAdGroup(1).states[2]).isEqualTo(AdPlaybackState.AD_STATE_AVAILABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFirstAdIndexToPlaySkipsErrorAds() {
|
public void getFirstAdIndexToPlaySkipsErrorAds() {
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
AdPlaybackState state =
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2, TEST_URI);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 3);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI);
|
||||||
|
|
||||||
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
state = state.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0);
|
||||||
state = state.withAdLoadError(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1);
|
state = state.withAdLoadError(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).getFirstAdIndexToPlay()).isEqualTo(2);
|
assertThat(state.getAdGroup(1).getFirstAdIndexToPlay()).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNextAdIndexToPlaySkipsErrorAds() {
|
public void getNextAdIndexToPlaySkipsErrorAds() {
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
AdPlaybackState state =
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, TEST_URI);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 3);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI);
|
||||||
|
|
||||||
state = state.withAdLoadError(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1);
|
state = state.withAdLoadError(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).getNextAdIndexToPlay(0)).isEqualTo(2);
|
assertThat(state.getAdGroup(1).getNextAdIndexToPlay(0)).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getFirstAdIndexToPlay_withPlayedServerSideInsertedAds_returnsFirstIndex() {
|
public void getFirstAdIndexToPlay_withPlayedServerSideInsertedAds_returnsFirstIndex() {
|
||||||
state = state.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true);
|
AdPlaybackState state =
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI);
|
state = state.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, TEST_URI);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 3);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2, TEST_URI);
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI);
|
||||||
|
|
||||||
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
state = state.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).getFirstAdIndexToPlay()).isEqualTo(0);
|
assertThat(state.getAdGroup(1).getFirstAdIndexToPlay()).isEqualTo(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getNextAdIndexToPlay_withPlayedServerSideInsertedAds_returnsNextIndex() {
|
public void getNextAdIndexToPlay_withPlayedServerSideInsertedAds_returnsNextIndex() {
|
||||||
state = state.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true);
|
AdPlaybackState state =
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3);
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US).withRemovedAdGroupCount(1);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI);
|
state = state.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, TEST_URI);
|
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 3);
|
||||||
state = state.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2, TEST_URI);
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI);
|
||||||
|
state = state.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI);
|
||||||
|
|
||||||
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
state = state.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0);
|
||||||
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1);
|
state = state.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1);
|
||||||
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 2);
|
state = state.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2);
|
||||||
|
|
||||||
assertThat(state.getAdGroup(0).getNextAdIndexToPlay(/* lastPlayedAdIndex= */ 0)).isEqualTo(1);
|
assertThat(state.getAdGroup(1).getNextAdIndexToPlay(/* lastPlayedAdIndex= */ 0)).isEqualTo(1);
|
||||||
assertThat(state.getAdGroup(0).getNextAdIndexToPlay(/* lastPlayedAdIndex= */ 1)).isEqualTo(2);
|
assertThat(state.getAdGroup(1).getNextAdIndexToPlay(/* lastPlayedAdIndex= */ 1)).isEqualTo(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setAdStateTwiceThrows() {
|
public void setAdStateTwiceThrows() {
|
||||||
|
AdPlaybackState state = new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US);
|
||||||
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1);
|
state = state.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1);
|
||||||
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
state = state.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
|
||||||
try {
|
try {
|
||||||
@ -227,6 +247,7 @@ public class AdPlaybackStateTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void skipAllWithoutAdCount() {
|
public void skipAllWithoutAdCount() {
|
||||||
|
AdPlaybackState state = new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US);
|
||||||
state = state.withSkippedAdGroup(0);
|
state = state.withSkippedAdGroup(0);
|
||||||
state = state.withSkippedAdGroup(1);
|
state = state.withSkippedAdGroup(1);
|
||||||
assertThat(state.getAdGroup(0).count).isEqualTo(0);
|
assertThat(state.getAdGroup(0).count).isEqualTo(0);
|
||||||
@ -236,20 +257,22 @@ public class AdPlaybackStateTest {
|
|||||||
@Test
|
@Test
|
||||||
public void roundTripViaBundle_yieldsEqualFieldsExceptAdsId() {
|
public void roundTripViaBundle_yieldsEqualFieldsExceptAdsId() {
|
||||||
AdPlaybackState originalState =
|
AdPlaybackState originalState =
|
||||||
state
|
new AdPlaybackState(TEST_ADS_ID, TEST_AD_GROUP_TIMES_US)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
|
.withRemovedAdGroupCount(1)
|
||||||
.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0)
|
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
||||||
.withAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI)
|
.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2)
|
|
||||||
.withSkippedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0)
|
|
||||||
.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1)
|
|
||||||
.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI)
|
.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, TEST_URI)
|
||||||
.withAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 4444)
|
.withSkippedAd(/* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 3333)
|
.withPlayedAd(/* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
|
.withAdUri(/* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, TEST_URI)
|
||||||
|
.withAdUri(/* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, TEST_URI)
|
||||||
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 4444)
|
||||||
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 3333)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
|
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
|
||||||
.withAdDurationsUs(new long[][] {{12}, {34, 56}})
|
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
|
||||||
|
.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs...= */ 12)
|
||||||
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 34, 56)
|
||||||
.withAdResumePositionUs(123)
|
.withAdResumePositionUs(123)
|
||||||
.withContentDurationUs(456);
|
.withContentDurationUs(456);
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ public final class ServerSideInsertedAdsMediaSource extends BaseMediaSource
|
|||||||
*/
|
*/
|
||||||
public void setAdPlaybackState(AdPlaybackState adPlaybackState) {
|
public void setAdPlaybackState(AdPlaybackState adPlaybackState) {
|
||||||
checkArgument(adPlaybackState.adGroupCount >= this.adPlaybackState.adGroupCount);
|
checkArgument(adPlaybackState.adGroupCount >= this.adPlaybackState.adGroupCount);
|
||||||
for (int i = 0; i < adPlaybackState.adGroupCount; i++) {
|
for (int i = adPlaybackState.removedAdGroupCount; i < adPlaybackState.adGroupCount; i++) {
|
||||||
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
||||||
checkArgument(adGroup.isServerSideInserted);
|
checkArgument(adGroup.isServerSideInserted);
|
||||||
if (i < this.adPlaybackState.adGroupCount) {
|
if (i < this.adPlaybackState.adGroupCount) {
|
||||||
|
@ -53,7 +53,7 @@ public final class ServerSideInsertedAdsUtil {
|
|||||||
long adGroupInsertionPositionUs =
|
long adGroupInsertionPositionUs =
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
fromPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, adPlaybackState);
|
fromPositionUs, /* nextAdGroupIndex= */ C.INDEX_UNSET, adPlaybackState);
|
||||||
int insertionIndex = 0;
|
int insertionIndex = adPlaybackState.removedAdGroupCount;
|
||||||
while (insertionIndex < adPlaybackState.adGroupCount
|
while (insertionIndex < adPlaybackState.adGroupCount
|
||||||
&& adPlaybackState.getAdGroup(insertionIndex).timeUs != C.TIME_END_OF_SOURCE
|
&& adPlaybackState.getAdGroup(insertionIndex).timeUs != C.TIME_END_OF_SOURCE
|
||||||
&& adPlaybackState.getAdGroup(insertionIndex).timeUs <= adGroupInsertionPositionUs) {
|
&& adPlaybackState.getAdGroup(insertionIndex).timeUs <= adGroupInsertionPositionUs) {
|
||||||
@ -184,7 +184,7 @@ public final class ServerSideInsertedAdsUtil {
|
|||||||
long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState) {
|
long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState) {
|
||||||
AdPlaybackState.AdGroup currentAdGroup = adPlaybackState.getAdGroup(adGroupIndex);
|
AdPlaybackState.AdGroup currentAdGroup = adPlaybackState.getAdGroup(adGroupIndex);
|
||||||
positionUs += currentAdGroup.timeUs;
|
positionUs += currentAdGroup.timeUs;
|
||||||
for (int i = 0; i < adGroupIndex; i++) {
|
for (int i = adPlaybackState.removedAdGroupCount; i < adGroupIndex; i++) {
|
||||||
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
||||||
for (int j = 0; j < getAdCountInGroup(adPlaybackState, /* adGroupIndex= */ i); j++) {
|
for (int j = 0; j < getAdCountInGroup(adPlaybackState, /* adGroupIndex= */ i); j++) {
|
||||||
positionUs += adGroup.durationsUs[j];
|
positionUs += adGroup.durationsUs[j];
|
||||||
@ -214,7 +214,7 @@ public final class ServerSideInsertedAdsUtil {
|
|||||||
long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState) {
|
long positionUs, int adGroupIndex, int adIndexInAdGroup, AdPlaybackState adPlaybackState) {
|
||||||
AdPlaybackState.AdGroup currentAdGroup = adPlaybackState.getAdGroup(adGroupIndex);
|
AdPlaybackState.AdGroup currentAdGroup = adPlaybackState.getAdGroup(adGroupIndex);
|
||||||
positionUs -= currentAdGroup.timeUs;
|
positionUs -= currentAdGroup.timeUs;
|
||||||
for (int i = 0; i < adGroupIndex; i++) {
|
for (int i = adPlaybackState.removedAdGroupCount; i < adGroupIndex; i++) {
|
||||||
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
||||||
for (int j = 0; j < getAdCountInGroup(adPlaybackState, /* adGroupIndex= */ i); j++) {
|
for (int j = 0; j < getAdCountInGroup(adPlaybackState, /* adGroupIndex= */ i); j++) {
|
||||||
positionUs -= adGroup.durationsUs[j];
|
positionUs -= adGroup.durationsUs[j];
|
||||||
@ -246,7 +246,7 @@ public final class ServerSideInsertedAdsUtil {
|
|||||||
if (nextAdGroupIndex == C.INDEX_UNSET) {
|
if (nextAdGroupIndex == C.INDEX_UNSET) {
|
||||||
nextAdGroupIndex = adPlaybackState.adGroupCount;
|
nextAdGroupIndex = adPlaybackState.adGroupCount;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nextAdGroupIndex; i++) {
|
for (int i = adPlaybackState.removedAdGroupCount; i < nextAdGroupIndex; i++) {
|
||||||
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
||||||
if (adGroup.timeUs == C.TIME_END_OF_SOURCE || adGroup.timeUs > positionUs) {
|
if (adGroup.timeUs == C.TIME_END_OF_SOURCE || adGroup.timeUs > positionUs) {
|
||||||
break;
|
break;
|
||||||
@ -283,7 +283,7 @@ public final class ServerSideInsertedAdsUtil {
|
|||||||
if (nextAdGroupIndex == C.INDEX_UNSET) {
|
if (nextAdGroupIndex == C.INDEX_UNSET) {
|
||||||
nextAdGroupIndex = adPlaybackState.adGroupCount;
|
nextAdGroupIndex = adPlaybackState.adGroupCount;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < nextAdGroupIndex; i++) {
|
for (int i = adPlaybackState.removedAdGroupCount; i < nextAdGroupIndex; i++) {
|
||||||
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
AdPlaybackState.AdGroup adGroup = adPlaybackState.getAdGroup(i);
|
||||||
if (adGroup.timeUs == C.TIME_END_OF_SOURCE
|
if (adGroup.timeUs == C.TIME_END_OF_SOURCE
|
||||||
|| adGroup.timeUs > positionUs - totalAdDurationBeforePositionUs) {
|
|| adGroup.timeUs > positionUs - totalAdDurationBeforePositionUs) {
|
||||||
|
@ -37,7 +37,8 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
@Test
|
@Test
|
||||||
public void addAdGroupToAdPlaybackState_insertsCorrectAdGroupData() {
|
public void addAdGroupToAdPlaybackState_insertsCorrectAdGroupData() {
|
||||||
AdPlaybackState state =
|
AdPlaybackState state =
|
||||||
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ C.TIME_END_OF_SOURCE);
|
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 1, C.TIME_END_OF_SOURCE)
|
||||||
|
.withRemovedAdGroupCount(2);
|
||||||
|
|
||||||
// stream: 0-- content --4300-- ad1 --4500-- content
|
// stream: 0-- content --4300-- ad1 --4500-- content
|
||||||
// content timeline: 0-4300 - [ad1] - 4700-end
|
// content timeline: 0-4300 - [ad1] - 4700-end
|
||||||
@ -50,11 +51,12 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(state)
|
assertThat(state)
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 4300, C.TIME_END_OF_SOURCE)
|
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 4300, C.TIME_END_OF_SOURCE)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
|
.withRemovedAdGroupCount(2)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 400)
|
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
|
||||||
.withAdDurationsUs(new long[][] {new long[] {200}, new long[0]}));
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
|
||||||
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 200));
|
||||||
|
|
||||||
// stream: 0-- content --2100-- ad1 --2400-- content --4300-- ad2 --4500-- content
|
// stream: 0-- content --2100-- ad1 --2400-- content --4300-- ad2 --4500-- content
|
||||||
// content timeline: 0-2100 - [ad1] - 2100-4000 - [ad2] - 4400-end
|
// content timeline: 0-2100 - [ad1] - 2100-4000 - [ad2] - 4400-end
|
||||||
@ -67,13 +69,16 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(state)
|
assertThat(state)
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 2100, 4000, C.TIME_END_OF_SOURCE)
|
new AdPlaybackState(
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
|
ADS_ID, /* adGroupTimesUs...= */ 0, 0, 2100, 4000, C.TIME_END_OF_SOURCE)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
.withRemovedAdGroupCount(2)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
|
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 400)
|
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
|
||||||
.withAdDurationsUs(new long[][] {new long[] {300}, new long[] {200}, new long[0]}));
|
.withIsServerSideInserted(/* adGroupIndex= */ 3, /* isServerSideInserted= */ true)
|
||||||
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 400)
|
||||||
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 300)
|
||||||
|
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200));
|
||||||
|
|
||||||
// stream: 0-- ad1 --100-- content --2100-- ad2 --2400-- content --4300-- ad3 --4500-- content
|
// stream: 0-- ad1 --100-- content --2100-- ad2 --2400-- content --4300-- ad3 --4500-- content
|
||||||
// content timeline: 0 - [ad1] - 50-2050 -[ad2] - 2050-3950 - [ad3] - 4350-end
|
// content timeline: 0 - [ad1] - 50-2050 -[ad2] - 2050-3950 - [ad3] - 4350-end
|
||||||
@ -87,19 +92,19 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
assertThat(state)
|
assertThat(state)
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
new AdPlaybackState(
|
new AdPlaybackState(
|
||||||
ADS_ID, /* adGroupTimesUs...= */ 0, 2050, 3950, C.TIME_END_OF_SOURCE)
|
ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2050, 3950, C.TIME_END_OF_SOURCE)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
|
.withRemovedAdGroupCount(2)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
|
||||||
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
|
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
|
.withAdCount(/* adGroupIndex= */ 4, /* adCount= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
|
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 50)
|
.withIsServerSideInserted(/* adGroupIndex= */ 3, /* isServerSideInserted= */ true)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
|
.withIsServerSideInserted(/* adGroupIndex= */ 4, /* isServerSideInserted= */ true)
|
||||||
.withAdDurationsUs(
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 50)
|
||||||
new long[][] {
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
|
||||||
new long[] {100}, new long[] {300}, new long[] {200}, new long[0]
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 100)
|
||||||
}));
|
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 300)
|
||||||
|
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 200));
|
||||||
|
|
||||||
// stream: 0-- ad1 --100-- c --2100-- ad2 --2400-- c --4300-- ad3 --4500-- c --5000-- ad4 --6000
|
// stream: 0-- ad1 --100-- c --2100-- ad2 --2400-- c --4300-- ad3 --4500-- c --5000-- ad4 --6000
|
||||||
// content timeline: 0 - [ad1] - 50-2050 -[ad2] - 2050-3950 - [ad3] - 4350-4850 - [ad4] - 4850
|
// content timeline: 0 - [ad1] - 50-2050 -[ad2] - 2050-3950 - [ad3] - 4350-4850 - [ad4] - 4850
|
||||||
@ -113,25 +118,29 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
assertThat(state)
|
assertThat(state)
|
||||||
.isEqualTo(
|
.isEqualTo(
|
||||||
new AdPlaybackState(
|
new AdPlaybackState(
|
||||||
ADS_ID, /* adGroupTimesUs...= */ 0, 2050, 3950, 4850, C.TIME_END_OF_SOURCE)
|
ADS_ID, /* adGroupTimesUs...= */
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
|
0,
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
0,
|
||||||
|
0,
|
||||||
|
2050,
|
||||||
|
3950,
|
||||||
|
4850,
|
||||||
|
C.TIME_END_OF_SOURCE)
|
||||||
|
.withRemovedAdGroupCount(2)
|
||||||
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
|
||||||
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
|
.withAdCount(/* adGroupIndex= */ 4, /* adCount= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
|
.withAdCount(/* adGroupIndex= */ 5, /* adCount= */ 1)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
|
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
|
||||||
.withIsServerSideInserted(/* adGroupIndex= */ 3, /* isServerSideInserted= */ true)
|
.withIsServerSideInserted(/* adGroupIndex= */ 3, /* isServerSideInserted= */ true)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 50)
|
.withIsServerSideInserted(/* adGroupIndex= */ 4, /* isServerSideInserted= */ true)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
|
.withIsServerSideInserted(/* adGroupIndex= */ 5, /* isServerSideInserted= */ true)
|
||||||
.withAdDurationsUs(
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 50)
|
||||||
new long[][] {
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
|
||||||
new long[] {100},
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 100)
|
||||||
new long[] {300},
|
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 300)
|
||||||
new long[] {200},
|
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 200)
|
||||||
new long[] {1000},
|
.withAdDurationsUs(/* adGroupIndex= */ 5, /* adDurationsUs...= */ 1000));
|
||||||
new long[0]
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -139,100 +148,98 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
||||||
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
||||||
AdPlaybackState state =
|
AdPlaybackState state =
|
||||||
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 2000, 4000)
|
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)
|
.withRemovedAdGroupCount(2)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
|
||||||
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 3)
|
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100)
|
.withAdCount(/* adGroupIndex= */ 4, /* adCount= */ 3)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 0)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
|
||||||
.withAdDurationsUs(
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
|
||||||
new long[][] {
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
|
||||||
new long[] {150, 50},
|
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
|
||||||
new long[] {200},
|
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
|
||||||
new long[] {50, 50, 100}
|
|
||||||
});
|
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 0, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 0, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 100, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 100, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 200, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 200, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(200);
|
.isEqualTo(200);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ -50, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ -50, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 0, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 0, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(150);
|
.isEqualTo(150);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 100, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 100, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(250);
|
.isEqualTo(250);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ -50, /* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ -50, /* adGroupIndex= */ 3, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(2050);
|
.isEqualTo(2050);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 0, /* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 0, /* adGroupIndex= */ 3, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(2100);
|
.isEqualTo(2100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 200, /* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 200, /* adGroupIndex= */ 3, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(2300);
|
.isEqualTo(2300);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 300, /* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 300, /* adGroupIndex= */ 3, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(2400);
|
.isEqualTo(2400);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ -50, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ -50, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(4250);
|
.isEqualTo(4250);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 0, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 0, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(4300);
|
.isEqualTo(4300);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 100, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 100, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(4400);
|
.isEqualTo(4400);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ -50, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ -50, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(4300);
|
.isEqualTo(4300);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 0, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 0, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(4350);
|
.isEqualTo(4350);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 100, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 100, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(4450);
|
.isEqualTo(4450);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ -50, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 2, state))
|
/* positionUs= */ -50, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 2, state))
|
||||||
.isEqualTo(4350);
|
.isEqualTo(4350);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 50, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 2, state))
|
/* positionUs= */ 50, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 2, state))
|
||||||
.isEqualTo(4450);
|
.isEqualTo(4450);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForAd(
|
getStreamPositionUsForAd(
|
||||||
/* positionUs= */ 150, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 2, state))
|
/* positionUs= */ 150, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 2, state))
|
||||||
.isEqualTo(4550);
|
.isEqualTo(4550);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,105 +248,103 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
||||||
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
||||||
AdPlaybackState state =
|
AdPlaybackState state =
|
||||||
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 2000, 4000)
|
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)
|
.withRemovedAdGroupCount(2)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
|
||||||
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 3)
|
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100)
|
.withAdCount(/* adGroupIndex= */ 4, /* adCount= */ 3)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 0)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
|
||||||
.withAdDurationsUs(
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
|
||||||
new long[][] {
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
|
||||||
new long[] {150, 50},
|
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
|
||||||
new long[] {200},
|
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
|
||||||
new long[] {50, 50, 100}
|
|
||||||
});
|
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 0, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 0, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 100, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 100, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 100, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 100, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(-50);
|
.isEqualTo(-50);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 200, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 200, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(200);
|
.isEqualTo(200);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 200, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 200, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(50);
|
.isEqualTo(50);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 300, /* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 300, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(150);
|
.isEqualTo(150);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 2000, /* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 2000, /* adGroupIndex= */ 3, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(-100);
|
.isEqualTo(-100);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 2100, /* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 2100, /* adGroupIndex= */ 3, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 2300, /* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 2300, /* adGroupIndex= */ 3, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(200);
|
.isEqualTo(200);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4300, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 4300, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4300, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 4300, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(-50);
|
.isEqualTo(-50);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4300, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 2, state))
|
/* positionUs= */ 4300, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 2, state))
|
||||||
.isEqualTo(-100);
|
.isEqualTo(-100);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4400, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 0, state))
|
/* positionUs= */ 4400, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 0, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4400, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 4400, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(50);
|
.isEqualTo(50);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4400, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 2, state))
|
/* positionUs= */ 4400, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 2, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4500, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 4500, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(150);
|
.isEqualTo(150);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4500, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 2, state))
|
/* positionUs= */ 4500, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 2, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4700, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 1, state))
|
/* positionUs= */ 4700, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 1, state))
|
||||||
.isEqualTo(350);
|
.isEqualTo(350);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForAd(
|
getMediaPeriodPositionUsForAd(
|
||||||
/* positionUs= */ 4700, /* adGroupIndex= */ 2, /* adIndexInAdGroup= */ 2, state))
|
/* positionUs= */ 4700, /* adGroupIndex= */ 4, /* adIndexInAdGroup= */ 2, state))
|
||||||
.isEqualTo(300);
|
.isEqualTo(300);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,23 +353,21 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
||||||
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
||||||
AdPlaybackState state =
|
AdPlaybackState state =
|
||||||
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 2000, 4000)
|
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)
|
.withRemovedAdGroupCount(2)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
|
||||||
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 3)
|
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100)
|
.withAdCount(/* adGroupIndex= */ 4, /* adCount= */ 3)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 0)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
|
||||||
.withAdDurationsUs(
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
|
||||||
new long[][] {
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
|
||||||
new long[] {150, 50},
|
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
|
||||||
new long[] {200},
|
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
|
||||||
new long[] {50, 50, 100}
|
|
||||||
});
|
|
||||||
|
|
||||||
assertThat(getStreamPositionUsForContent(/* positionUs= */ 0, /* nextAdGroupIndex= */ 0, state))
|
assertThat(getStreamPositionUsForContent(/* positionUs= */ 0, /* nextAdGroupIndex= */ 2, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
assertThat(getStreamPositionUsForContent(/* positionUs= */ 0, /* nextAdGroupIndex= */ 1, state))
|
assertThat(getStreamPositionUsForContent(/* positionUs= */ 0, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(
|
getStreamPositionUsForContent(
|
||||||
@ -372,10 +375,10 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 50, /* nextAdGroupIndex= */ 0, state))
|
getStreamPositionUsForContent(/* positionUs= */ 50, /* nextAdGroupIndex= */ 2, state))
|
||||||
.isEqualTo(50);
|
.isEqualTo(50);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 50, /* nextAdGroupIndex= */ 1, state))
|
getStreamPositionUsForContent(/* positionUs= */ 50, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(150);
|
.isEqualTo(150);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(
|
getStreamPositionUsForContent(
|
||||||
@ -383,7 +386,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
.isEqualTo(150);
|
.isEqualTo(150);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 100, /* nextAdGroupIndex= */ 1, state))
|
getStreamPositionUsForContent(/* positionUs= */ 100, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(200);
|
.isEqualTo(200);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(
|
getStreamPositionUsForContent(
|
||||||
@ -391,7 +394,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
.isEqualTo(200);
|
.isEqualTo(200);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 1999, /* nextAdGroupIndex= */ 1, state))
|
getStreamPositionUsForContent(/* positionUs= */ 1999, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(2099);
|
.isEqualTo(2099);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(
|
getStreamPositionUsForContent(
|
||||||
@ -399,10 +402,10 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
.isEqualTo(2099);
|
.isEqualTo(2099);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 2000, /* nextAdGroupIndex= */ 1, state))
|
getStreamPositionUsForContent(/* positionUs= */ 2000, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(2100);
|
.isEqualTo(2100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 2000, /* nextAdGroupIndex= */ 2, state))
|
getStreamPositionUsForContent(/* positionUs= */ 2000, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(2300);
|
.isEqualTo(2300);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(
|
getStreamPositionUsForContent(
|
||||||
@ -410,7 +413,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
.isEqualTo(2300);
|
.isEqualTo(2300);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 3999, /* nextAdGroupIndex= */ 2, state))
|
getStreamPositionUsForContent(/* positionUs= */ 3999, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(4299);
|
.isEqualTo(4299);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(
|
getStreamPositionUsForContent(
|
||||||
@ -418,7 +421,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
.isEqualTo(4299);
|
.isEqualTo(4299);
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(/* positionUs= */ 4000, /* nextAdGroupIndex= */ 2, state))
|
getStreamPositionUsForContent(/* positionUs= */ 4000, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(4300);
|
.isEqualTo(4300);
|
||||||
assertThat(
|
assertThat(
|
||||||
getStreamPositionUsForContent(
|
getStreamPositionUsForContent(
|
||||||
@ -446,27 +449,25 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
// stream: 0-- ad1 --200-- content --2100-- ad2 --2300-- content --4300-- ad3 --4500-- content
|
||||||
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
// content timeline: 0 - [ad1] - 100-2000 -[ad2] - 2000-4000 - [ad3] - 4400-end
|
||||||
AdPlaybackState state =
|
AdPlaybackState state =
|
||||||
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 2000, 4000)
|
new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
|
||||||
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)
|
.withRemovedAdGroupCount(2)
|
||||||
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 1)
|
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
|
||||||
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 3)
|
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100)
|
.withAdCount(/* adGroupIndex= */ 4, /* adCount= */ 3)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 0)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
|
||||||
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
|
||||||
.withAdDurationsUs(
|
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
|
||||||
new long[][] {
|
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
|
||||||
new long[] {150, 50},
|
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
|
||||||
new long[] {200},
|
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
|
||||||
new long[] {50, 50, 100}
|
|
||||||
});
|
|
||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 0, /* nextAdGroupIndex= */ 0, state))
|
/* positionUs= */ 0, /* nextAdGroupIndex= */ 2, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 0, /* nextAdGroupIndex= */ 1, state))
|
/* positionUs= */ 0, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -475,11 +476,11 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 100, /* nextAdGroupIndex= */ 0, state))
|
/* positionUs= */ 100, /* nextAdGroupIndex= */ 2, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 100, /* nextAdGroupIndex= */ 1, state))
|
/* positionUs= */ 100, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(0);
|
.isEqualTo(0);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -488,7 +489,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 200, /* nextAdGroupIndex= */ 1, state))
|
/* positionUs= */ 200, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(100);
|
.isEqualTo(100);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -497,7 +498,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 2099, /* nextAdGroupIndex= */ 1, state))
|
/* positionUs= */ 2099, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(1999);
|
.isEqualTo(1999);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -506,11 +507,11 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 2100, /* nextAdGroupIndex= */ 1, state))
|
/* positionUs= */ 2100, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(2000);
|
.isEqualTo(2000);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 2100, /* nextAdGroupIndex= */ 2, state))
|
/* positionUs= */ 2100, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(2000);
|
.isEqualTo(2000);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -519,11 +520,11 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 2300, /* nextAdGroupIndex= */ 1, state))
|
/* positionUs= */ 2300, /* nextAdGroupIndex= */ 3, state))
|
||||||
.isEqualTo(2200);
|
.isEqualTo(2200);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 2300, /* nextAdGroupIndex= */ 2, state))
|
/* positionUs= */ 2300, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(2000);
|
.isEqualTo(2000);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -532,7 +533,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 4299, /* nextAdGroupIndex= */ 2, state))
|
/* positionUs= */ 4299, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(3999);
|
.isEqualTo(3999);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -541,7 +542,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 4300, /* nextAdGroupIndex= */ 2, state))
|
/* positionUs= */ 4300, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(4000);
|
.isEqualTo(4000);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
@ -550,7 +551,7 @@ public final class ServerSideInsertedAdsUtilTest {
|
|||||||
|
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
/* positionUs= */ 4500, /* nextAdGroupIndex= */ 2, state))
|
/* positionUs= */ 4500, /* nextAdGroupIndex= */ 4, state))
|
||||||
.isEqualTo(4200);
|
.isEqualTo(4200);
|
||||||
assertThat(
|
assertThat(
|
||||||
getMediaPeriodPositionUsForContent(
|
getMediaPeriodPositionUsForContent(
|
||||||
|
@ -982,8 +982,9 @@ public class PlayerControlView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
for (int j = window.firstPeriodIndex; j <= window.lastPeriodIndex; j++) {
|
for (int j = window.firstPeriodIndex; j <= window.lastPeriodIndex; j++) {
|
||||||
timeline.getPeriod(j, period);
|
timeline.getPeriod(j, period);
|
||||||
int periodAdGroupCount = period.getAdGroupCount();
|
int removedGroups = period.getRemovedAdGroupCount();
|
||||||
for (int adGroupIndex = 0; adGroupIndex < periodAdGroupCount; adGroupIndex++) {
|
int totalGroups = period.getAdGroupCount();
|
||||||
|
for (int adGroupIndex = removedGroups; adGroupIndex < totalGroups; adGroupIndex++) {
|
||||||
long adGroupTimeInPeriodUs = period.getAdGroupTimeUs(adGroupIndex);
|
long adGroupTimeInPeriodUs = period.getAdGroupTimeUs(adGroupIndex);
|
||||||
if (adGroupTimeInPeriodUs == C.TIME_END_OF_SOURCE) {
|
if (adGroupTimeInPeriodUs == C.TIME_END_OF_SOURCE) {
|
||||||
if (period.durationUs == C.TIME_UNSET) {
|
if (period.durationUs == C.TIME_UNSET) {
|
||||||
|
@ -1345,8 +1345,9 @@ public class StyledPlayerControlView extends FrameLayout {
|
|||||||
}
|
}
|
||||||
for (int j = window.firstPeriodIndex; j <= window.lastPeriodIndex; j++) {
|
for (int j = window.firstPeriodIndex; j <= window.lastPeriodIndex; j++) {
|
||||||
timeline.getPeriod(j, period);
|
timeline.getPeriod(j, period);
|
||||||
int periodAdGroupCount = period.getAdGroupCount();
|
int removedGroups = period.getRemovedAdGroupCount();
|
||||||
for (int adGroupIndex = 0; adGroupIndex < periodAdGroupCount; adGroupIndex++) {
|
int totalGroups = period.getAdGroupCount();
|
||||||
|
for (int adGroupIndex = removedGroups; adGroupIndex < totalGroups; adGroupIndex++) {
|
||||||
long adGroupTimeInPeriodUs = period.getAdGroupTimeUs(adGroupIndex);
|
long adGroupTimeInPeriodUs = period.getAdGroupTimeUs(adGroupIndex);
|
||||||
if (adGroupTimeInPeriodUs == C.TIME_END_OF_SOURCE) {
|
if (adGroupTimeInPeriodUs == C.TIME_END_OF_SOURCE) {
|
||||||
if (period.durationUs == C.TIME_UNSET) {
|
if (period.durationUs == C.TIME_UNSET) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user