Refactor transformation completion

PiperOrigin-RevId: 488929446
This commit is contained in:
kimvde 2022-11-16 14:56:33 +00:00 committed by microkatz
parent e1eb8b6dd8
commit 1ee185cb10
23 changed files with 400 additions and 387 deletions

View File

@ -80,7 +80,7 @@ public class AdPlaybackStateTest {
@Test @Test
public void withAdGroupTimeUs_updatesAdGroupTimeUs() { public void withAdGroupTimeUs_updatesAdGroupTimeUs() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0, 5_000, 10_000) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0, 5_000, 10_000)
.withRemovedAdGroupCount(1); .withRemovedAdGroupCount(1);
state = state =
@ -96,7 +96,7 @@ public class AdPlaybackStateTest {
@Test @Test
public void withNewAdGroup_addsGroupAndKeepsExistingGroups() { public void withNewAdGroup_addsGroupAndKeepsExistingGroups() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0, 3_000, 6_000) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0, 3_000, 6_000)
.withRemovedAdGroupCount(1) .withRemovedAdGroupCount(1)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
@ -122,12 +122,12 @@ public class AdPlaybackStateTest {
@Test @Test
public void withAdDurationsUs_updatesAdDurations() { public void withAdDurationsUs_updatesAdDurations() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0, 10_000) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0, 10_000)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2)
.withAdDurationsUs(new long[][] {new long[] {5_000, 6_000}, new long[] {7_000, 8_000}}); .withAdDurationsUs(new long[][] {new long[] {5_000, 6_000}, new long[] {7_000, 8_000}});
state = state.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs= */ 1_000, 2_000); state = state.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs...= */ 1_000, 2_000);
assertThat(state.getAdGroup(0).durationsUs[0]).isEqualTo(5_000); assertThat(state.getAdGroup(0).durationsUs[0]).isEqualTo(5_000);
assertThat(state.getAdGroup(0).durationsUs[1]).isEqualTo(6_000); assertThat(state.getAdGroup(0).durationsUs[1]).isEqualTo(6_000);
@ -314,7 +314,7 @@ public class AdPlaybackStateTest {
@Test @Test
public void withOriginalAdCount() { public void withOriginalAdCount() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 5_000_000) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 5_000_000)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2); .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2);
state = state.withOriginalAdCount(/* adGroupIndex= */ 0, /* originalAdCount= */ 3); state = state.withOriginalAdCount(/* adGroupIndex= */ 0, /* originalAdCount= */ 3);
@ -326,7 +326,7 @@ public class AdPlaybackStateTest {
@Test @Test
public void withOriginalAdCount_unsetValue_defaultsToIndexUnset() { public void withOriginalAdCount_unsetValue_defaultsToIndexUnset() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 5_000_000) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 5_000_000)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2); .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 2);
assertThat(state.getAdGroup(0).count).isEqualTo(2); assertThat(state.getAdGroup(0).count).isEqualTo(2);
@ -335,7 +335,7 @@ public class AdPlaybackStateTest {
@Test @Test
public void withLastAdGroupRemoved() { public void withLastAdGroupRemoved() {
AdPlaybackState state = new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 5_000_000); AdPlaybackState state = new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 5_000_000);
state = state =
state state
.withAdCount(/* adGroupIndex= */ 0, 3) .withAdCount(/* adGroupIndex= */ 0, 3)
@ -362,7 +362,7 @@ public class AdPlaybackStateTest {
state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 5); state = state.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 5);
state = state =
state.withAdDurationsUs( state.withAdDurationsUs(
/* adGroupIndex= */ 1, /* adDurationsUs= */ 1_000L, 2_000L, 3_000L, 4_000L, 5_000L); /* adGroupIndex= */ 1, /* adDurationsUs...= */ 1_000L, 2_000L, 3_000L, 4_000L, 5_000L);
state = state.withAvailableAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI); state = state.withAvailableAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 1, TEST_URI);
state = state.withAvailableAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI); state = state.withAvailableAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 2, TEST_URI);
state = state.withAvailableAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 3, TEST_URI); state = state.withAvailableAdUri(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 3, TEST_URI);
@ -418,8 +418,8 @@ public class AdPlaybackStateTest {
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 3333) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 3333)
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs= */ 12) .withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs...= */ 12)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 34, 56) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 34, 56)
.withAdResumePositionUs(123) .withAdResumePositionUs(123)
.withContentDurationUs(456); .withContentDurationUs(456);
@ -456,7 +456,7 @@ public class AdPlaybackStateTest {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState( new AdPlaybackState(
/* adsId= */ new Object(), /* adsId= */ new Object(),
/* adGroupTimesUs= */ 0, /* adGroupTimesUs...= */ 0,
1000, 1000,
2000, 2000,
3000, 3000,
@ -539,7 +539,7 @@ public class AdPlaybackStateTest {
@Test @Test
public void getAdGroupIndexAfterPositionUs_withServerSideInsertedAds_returnsNextAdGroup() { public void getAdGroupIndexAfterPositionUs_withServerSideInsertedAds_returnsNextAdGroup() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 0, 1000, 2000) new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0, 1000, 2000)
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)

View File

@ -80,7 +80,7 @@ public final class FlagSetTest {
public void containsAny_withoutAdd_returnsFalseForAllValues() { public void containsAny_withoutAdd_returnsFalseForAllValues() {
FlagSet flags = new FlagSet.Builder().build(); FlagSet flags = new FlagSet.Builder().build();
assertThat(flags.containsAny(/* flags= */ -1234, 0, 2, Integer.MAX_VALUE)).isFalse(); assertThat(flags.containsAny(/* flags...= */ -1234, 0, 2, Integer.MAX_VALUE)).isFalse();
} }
@Test @Test
@ -95,9 +95,9 @@ public final class FlagSetTest {
assertThat( assertThat(
flags.containsAny( flags.containsAny(
/* flags= */ -1235, -1234, 0, 1, 2, Integer.MAX_VALUE - 1, Integer.MAX_VALUE)) /* flags...= */ -1235, -1234, 0, 1, 2, Integer.MAX_VALUE - 1, Integer.MAX_VALUE))
.isTrue(); .isTrue();
assertThat(flags.containsAny(/* flags= */ -1235, 1, Integer.MAX_VALUE - 1)).isFalse(); assertThat(flags.containsAny(/* flags...= */ -1235, 1, Integer.MAX_VALUE - 1)).isFalse();
} }
@Test @Test

View File

@ -756,7 +756,7 @@ public final class ExoPlayerTest {
public void adGroupWithLoadError_noFurtherAdGroup_isSkipped() throws Exception { public void adGroupWithLoadError_noFurtherAdGroup_isSkipped() throws Exception {
AdPlaybackState initialAdPlaybackState = AdPlaybackState initialAdPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adGroupTimesUs= */ /* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+ 5 * C.MICROS_PER_SECOND); + 5 * C.MICROS_PER_SECOND);
Timeline fakeTimeline = Timeline fakeTimeline =
@ -809,7 +809,7 @@ public final class ExoPlayerTest {
public void adGroupWithLoadError_withFurtherAdGroup_isSkipped() throws Exception { public void adGroupWithLoadError_withFurtherAdGroup_isSkipped() throws Exception {
AdPlaybackState initialAdPlaybackState = AdPlaybackState initialAdPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adGroupTimesUs= */ /* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+ 5 * C.MICROS_PER_SECOND, + 5 * C.MICROS_PER_SECOND,
TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
@ -2938,7 +2938,8 @@ public final class ExoPlayerTest {
AdPlaybackState adPlaybackStateWithMidroll = AdPlaybackState adPlaybackStateWithMidroll =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adsPerAdGroup= */ 1,
/* adGroupTimesUs= */ TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US /* adGroupTimesUs...= */ TimelineWindowDefinition
.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+ 5 * C.MICROS_PER_SECOND); + 5 * C.MICROS_PER_SECOND);
Timeline timeline2 = Timeline timeline2 =
new FakeTimeline( new FakeTimeline(
@ -2989,7 +2990,8 @@ public final class ExoPlayerTest {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adsPerAdGroup= */ 1,
/* adGroupTimesUs= */ TimelineWindowDefinition.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US /* adGroupTimesUs...= */ TimelineWindowDefinition
.DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+ Util.msToUs(adGroupWindowTimeMs)); + Util.msToUs(adGroupWindowTimeMs));
Timeline timeline = Timeline timeline =
new FakeTimeline( new FakeTimeline(
@ -3622,7 +3624,7 @@ public final class ExoPlayerTest {
@Test @Test
public void contentWithInitialSeekPositionAfterPrerollAdStartsAtSeekPosition() throws Exception { public void contentWithInitialSeekPositionAfterPrerollAdStartsAtSeekPosition() throws Exception {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 3, /* adGroupTimesUs= */ 0); FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 3, /* adGroupTimesUs...= */ 0);
Timeline fakeTimeline = Timeline fakeTimeline =
new FakeTimeline( new FakeTimeline(
new TimelineWindowDefinition( new TimelineWindowDefinition(
@ -3671,7 +3673,7 @@ public final class ExoPlayerTest {
@Test @Test
public void contentWithoutInitialSeekStartsAtDefaultPositionAfterPrerollAd() throws Exception { public void contentWithoutInitialSeekStartsAtDefaultPositionAfterPrerollAd() throws Exception {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 3, /* adGroupTimesUs= */ 0); FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 3, /* adGroupTimesUs...= */ 0);
Timeline fakeTimeline = Timeline fakeTimeline =
new FakeTimeline( new FakeTimeline(
new TimelineWindowDefinition( new TimelineWindowDefinition(
@ -3725,7 +3727,7 @@ public final class ExoPlayerTest {
ExoPlayer player = new TestExoPlayerBuilder(context).build(); ExoPlayer player = new TestExoPlayerBuilder(context).build();
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adGroupTimesUs= */ 42_000_004_000_000L); /* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */ 42_000_004_000_000L);
Timeline liveTimeline1 = Timeline liveTimeline1 =
new FakeTimeline( new FakeTimeline(
new TimelineWindowDefinition( new TimelineWindowDefinition(
@ -4730,7 +4732,7 @@ public final class ExoPlayerTest {
long contentDurationMs = 10_000; long contentDurationMs = 10_000;
long adDurationMs = 100_000; long adDurationMs = 100_000;
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 0); new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0);
adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1); adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1);
adPlaybackState = adPlaybackState =
adPlaybackState.withAvailableAdUri( adPlaybackState.withAvailableAdUri(
@ -4832,7 +4834,7 @@ public final class ExoPlayerTest {
long contentDurationMs = 10_000; long contentDurationMs = 10_000;
long adDurationMs = 4_000; long adDurationMs = 4_000;
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 0); new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0);
adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1); adPlaybackState = adPlaybackState.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1);
adPlaybackState = adPlaybackState =
adPlaybackState.withAvailableAdUri( adPlaybackState.withAvailableAdUri(
@ -4915,7 +4917,7 @@ public final class ExoPlayerTest {
long contentDurationMs = 10_000; long contentDurationMs = 10_000;
long adDurationMs = 4_000; long adDurationMs = 4_000;
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 0) new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri( .withAvailableAdUri(
/* adGroupIndex= */ 0, /* adGroupIndex= */ 0,
@ -4960,7 +4962,7 @@ public final class ExoPlayerTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
"windowId", "windowId",
/* numberOfPlayedAds= */ 0, /* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
true, true,
true, true,
false); false);
@ -5051,7 +5053,7 @@ public final class ExoPlayerTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
"windowId", "windowId",
/* numberOfPlayedAds= */ 0, /* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
true, true,
false, false,
false); false);
@ -5113,7 +5115,7 @@ public final class ExoPlayerTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
"windowId", "windowId",
/* numberOfPlayedAds= */ 0, /* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
true, true,
true, true,
false); false);
@ -5180,7 +5182,7 @@ public final class ExoPlayerTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
"windowId", "windowId",
/* numberOfPlayedAds= */ 0, /* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
true, true,
true, true,
false); false);
@ -5261,7 +5263,7 @@ public final class ExoPlayerTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
"windowId", "windowId",
/* numberOfPlayedAds= */ 2, /* numberOfPlayedAds= */ 2,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
true, true,
true, true,
false); false);
@ -5316,7 +5318,7 @@ public final class ExoPlayerTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
"windowId", "windowId",
/* numberOfPlayedAds= */ Integer.MAX_VALUE, /* numberOfPlayedAds= */ Integer.MAX_VALUE,
/* isAdPeriodFlags= */ true, /* isAdPeriodFlags...= */ true,
false, false,
true, true,
true, true,
@ -5384,28 +5386,28 @@ public final class ExoPlayerTest {
new AdPlaybackState("adsId"), new AdPlaybackState("adsId"),
/* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US, /* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ C.MICROS_PER_SECOND); /* adDurationsUs...= */ C.MICROS_PER_SECOND);
adPlaybackState = adPlaybackState =
addAdGroupToAdPlaybackState( addAdGroupToAdPlaybackState(
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US /* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+ (3 * C.MICROS_PER_SECOND), + (3 * C.MICROS_PER_SECOND),
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ C.MICROS_PER_SECOND); /* adDurationsUs...= */ C.MICROS_PER_SECOND);
adPlaybackState = adPlaybackState =
addAdGroupToAdPlaybackState( addAdGroupToAdPlaybackState(
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US /* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+ (5 * C.MICROS_PER_SECOND), + (5 * C.MICROS_PER_SECOND),
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ C.MICROS_PER_SECOND); /* adDurationsUs...= */ C.MICROS_PER_SECOND);
adPlaybackState = adPlaybackState =
addAdGroupToAdPlaybackState( addAdGroupToAdPlaybackState(
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US /* fromPositionUs= */ DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+ (9 * C.MICROS_PER_SECOND), + (9 * C.MICROS_PER_SECOND),
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ C.MICROS_PER_SECOND); /* adDurationsUs...= */ C.MICROS_PER_SECOND);
adPlaybackState = adPlaybackState =
adPlaybackState.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup+ */ 0); adPlaybackState.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup+ */ 0);
adPlaybackState = adPlaybackState =
@ -5651,7 +5653,7 @@ public final class ExoPlayerTest {
@Test @Test
public void shortAdFollowedByUnpreparedAd_playbackDoesNotGetStuck() throws Exception { public void shortAdFollowedByUnpreparedAd_playbackDoesNotGetStuck() throws Exception {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 2, /* adGroupTimesUs= */ 0); FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 2, /* adGroupTimesUs...= */ 0);
long shortAdDurationMs = 1_000; long shortAdDurationMs = 1_000;
adPlaybackState = adPlaybackState =
adPlaybackState.withAdDurationsUs(new long[][] {{shortAdDurationMs, shortAdDurationMs}}); adPlaybackState.withAdDurationsUs(new long[][] {{shortAdDurationMs, shortAdDurationMs}});
@ -9063,7 +9065,7 @@ public final class ExoPlayerTest {
@Test @Test
public void isCommandAvailable_duringAd_isFalseForSeekCommands() throws Exception { public void isCommandAvailable_duringAd_isFalseForSeekCommands() throws Exception {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 0) new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri( .withAvailableAdUri(
/* adGroupIndex= */ 0, /* adGroupIndex= */ 0,
@ -10034,7 +10036,7 @@ public final class ExoPlayerTest {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adsPerAdGroup= */ 1,
/* adGroupTimesUs= */ 0, /* adGroupTimesUs...= */ 0,
7 * C.MICROS_PER_SECOND, 7 * C.MICROS_PER_SECOND,
C.TIME_END_OF_SOURCE); C.TIME_END_OF_SOURCE);
TimelineWindowDefinition adTimelineDefinition = TimelineWindowDefinition adTimelineDefinition =
@ -10623,7 +10625,7 @@ public final class ExoPlayerTest {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 2, /* adsPerAdGroup= */ 2,
/* adGroupTimesUs= */ 0, /* adGroupTimesUs...= */ 0,
7 * C.MICROS_PER_SECOND, 7 * C.MICROS_PER_SECOND,
C.TIME_END_OF_SOURCE); C.TIME_END_OF_SOURCE);
TimelineWindowDefinition adTimeline = TimelineWindowDefinition adTimeline =
@ -10760,7 +10762,7 @@ public final class ExoPlayerTest {
player.addListener(listener); player.addListener(listener);
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adGroupTimesUs= */ 2 * C.MICROS_PER_SECOND); /* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */ 2 * C.MICROS_PER_SECOND);
TimelineWindowDefinition adTimeline = TimelineWindowDefinition adTimeline =
new TimelineWindowDefinition( new TimelineWindowDefinition(
/* periodCount= */ 1, /* periodCount= */ 1,
@ -10849,7 +10851,7 @@ public final class ExoPlayerTest {
player.addListener(listener); player.addListener(listener);
AdPlaybackState postRollAdPlaybackState = AdPlaybackState postRollAdPlaybackState =
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adGroupTimesUs= */ C.TIME_END_OF_SOURCE); /* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */ C.TIME_END_OF_SOURCE);
TimelineWindowDefinition postRollWindow = TimelineWindowDefinition postRollWindow =
new TimelineWindowDefinition( new TimelineWindowDefinition(
/* periodCount= */ 1, /* periodCount= */ 1,
@ -10863,7 +10865,7 @@ public final class ExoPlayerTest {
/* windowOffsetInFirstPeriodUs= */ 0, /* windowOffsetInFirstPeriodUs= */ 0,
postRollAdPlaybackState); postRollAdPlaybackState);
AdPlaybackState preRollAdPlaybackState = AdPlaybackState preRollAdPlaybackState =
FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 1, /* adGroupTimesUs= */ 0); FakeTimeline.createAdPlaybackState(/* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */ 0);
TimelineWindowDefinition preRollWindow = TimelineWindowDefinition preRollWindow =
new TimelineWindowDefinition( new TimelineWindowDefinition(
/* periodCount= */ 1, /* periodCount= */ 1,
@ -11901,7 +11903,8 @@ public final class ExoPlayerTest {
.build(); .build();
// Live stream timeline with unassigned next ad group. // Live stream timeline with unassigned next ad group.
AdPlaybackState initialAdPlaybackState = AdPlaybackState initialAdPlaybackState =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ C.TIME_END_OF_SOURCE) new AdPlaybackState(
/* adsId= */ new Object(), /* adGroupTimesUs...= */ C.TIME_END_OF_SOURCE)
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdDurationsUs(new long[][] {new long[] {10 * C.MICROS_PER_SECOND}}); .withAdDurationsUs(new long[][] {new long[] {10 * C.MICROS_PER_SECOND}});

View File

@ -127,7 +127,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void getNextMediaPeriodInfo_withPrerollAd_returnsCorrectMediaPeriodInfos() { public void getNextMediaPeriodInfo_withPrerollAd_returnsCorrectMediaPeriodInfos() {
setupAdTimeline(/* adGroupTimesUs= */ 0); setupAdTimeline(/* adGroupTimesUs...= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
assertNextMediaPeriodInfoIsAd( assertNextMediaPeriodInfoIsAd(
/* adGroupIndex= */ 0, /* adGroupIndex= */ 0,
@ -149,7 +149,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void getNextMediaPeriodInfo_withMidrollAds_returnsCorrectMediaPeriodInfos() { public void getNextMediaPeriodInfo_withMidrollAds_returnsCorrectMediaPeriodInfos() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US);
assertGetNextMediaPeriodInfoReturnsContentMediaPeriod( assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(
/* periodUid= */ firstPeriodUid, /* periodUid= */ firstPeriodUid,
/* startPositionUs= */ 0, /* startPositionUs= */ 0,
@ -205,7 +205,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void getNextMediaPeriodInfo_withMidrollAndPostroll_returnsCorrectMediaPeriodInfos() { public void getNextMediaPeriodInfo_withMidrollAndPostroll_returnsCorrectMediaPeriodInfos() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, C.TIME_END_OF_SOURCE); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, C.TIME_END_OF_SOURCE);
assertGetNextMediaPeriodInfoReturnsContentMediaPeriod( assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(
/* periodUid= */ firstPeriodUid, /* periodUid= */ firstPeriodUid,
/* startPositionUs= */ 0, /* startPositionUs= */ 0,
@ -259,7 +259,7 @@ public final class MediaPeriodQueueTest {
adPlaybackState = adPlaybackState =
new AdPlaybackState( new AdPlaybackState(
/* adsId= */ new Object(), /* adsId= */ new Object(),
/* adGroupTimesUs= */ 0, /* adGroupTimesUs...= */ 0,
FIRST_AD_START_TIME_US, FIRST_AD_START_TIME_US,
C.TIME_END_OF_SOURCE) C.TIME_END_OF_SOURCE)
.withContentDurationUs(CONTENT_DURATION_US) .withContentDurationUs(CONTENT_DURATION_US)
@ -330,7 +330,7 @@ public final class MediaPeriodQueueTest {
adPlaybackState = adPlaybackState =
new AdPlaybackState( new AdPlaybackState(
/* adsId= */ new Object(), /* adsId= */ new Object(),
/* adGroupTimesUs= */ 0, /* adGroupTimesUs...= */ 0,
FIRST_AD_START_TIME_US, FIRST_AD_START_TIME_US,
SECOND_AD_START_TIME_US) SECOND_AD_START_TIME_US)
.withContentDurationUs(CONTENT_DURATION_US) .withContentDurationUs(CONTENT_DURATION_US)
@ -398,7 +398,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void getNextMediaPeriodInfo_withPostrollLoadError_returnsEmptyFinalMediaPeriodInfo() { public void getNextMediaPeriodInfo_withPostrollLoadError_returnsEmptyFinalMediaPeriodInfo() {
setupAdTimeline(/* adGroupTimesUs= */ C.TIME_END_OF_SOURCE); setupAdTimeline(/* adGroupTimesUs...= */ C.TIME_END_OF_SOURCE);
assertGetNextMediaPeriodInfoReturnsContentMediaPeriod( assertGetNextMediaPeriodInfoReturnsContentMediaPeriod(
/* periodUid= */ firstPeriodUid, /* periodUid= */ firstPeriodUid,
/* startPositionUs= */ 0, /* startPositionUs= */ 0,
@ -425,7 +425,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void getNextMediaPeriodInfo_withPlayedAdGroups_returnsCorrectMediaPeriodInfos() { public void getNextMediaPeriodInfo_withPlayedAdGroups_returnsCorrectMediaPeriodInfos() {
setupAdTimeline(/* adGroupTimesUs= */ 0, FIRST_AD_START_TIME_US, C.TIME_END_OF_SOURCE); setupAdTimeline(/* adGroupTimesUs...= */ 0, FIRST_AD_START_TIME_US, C.TIME_END_OF_SOURCE);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
setAdGroupLoaded(/* adGroupIndex= */ 2); setAdGroupLoaded(/* adGroupIndex= */ 2);
@ -509,14 +509,14 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void public void
updateQueuedPeriods_withDurationChangeInPlayingContent_handlesChangeAndRemovesPeriodsAfterChangedPeriod() { updateQueuedPeriods_withDurationChangeInPlayingContent_handlesChangeAndRemovesPeriodsAfterChangedPeriod() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
enqueueNext(); // Content before ad. enqueueNext(); // Content before ad.
enqueueNext(); // Ad. enqueueNext(); // Ad.
enqueueNext(); // Content after ad. enqueueNext(); // Content after ad.
// Change position of first ad (= change duration of playing content before first ad). // Change position of first ad (= change duration of playing content before first ad).
updateAdPlaybackStateAndTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US - 2000); updateAdPlaybackStateAndTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US - 2000);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
long maxRendererReadPositionUs = long maxRendererReadPositionUs =
MediaPeriodQueue.INITIAL_RENDERER_POSITION_OFFSET_US + FIRST_AD_START_TIME_US - 3000; MediaPeriodQueue.INITIAL_RENDERER_POSITION_OFFSET_US + FIRST_AD_START_TIME_US - 3000;
@ -537,14 +537,14 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void public void
updateQueuedPeriods_withDurationChangeInPlayingContentAfterReadingPosition_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() { updateQueuedPeriods_withDurationChangeInPlayingContentAfterReadingPosition_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
enqueueNext(); // Content before ad. enqueueNext(); // Content before ad.
enqueueNext(); // Ad. enqueueNext(); // Ad.
enqueueNext(); // Content after ad. enqueueNext(); // Content after ad.
// Change position of first ad (= change duration of playing content before first ad). // Change position of first ad (= change duration of playing content before first ad).
updateAdPlaybackStateAndTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US - 2000); updateAdPlaybackStateAndTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US - 2000);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
long maxRendererReadPositionUs = long maxRendererReadPositionUs =
MediaPeriodQueue.INITIAL_RENDERER_POSITION_OFFSET_US + FIRST_AD_START_TIME_US - 1000; MediaPeriodQueue.INITIAL_RENDERER_POSITION_OFFSET_US + FIRST_AD_START_TIME_US - 1000;
@ -579,7 +579,7 @@ public final class MediaPeriodQueueTest {
// Change position of first ad (= change duration of playing content before first ad). // Change position of first ad (= change duration of playing content before first ad).
adPlaybackState = adPlaybackState =
new AdPlaybackState( new AdPlaybackState(
/* adsId= */ new Object(), /* adGroupTimesUs= */ FIRST_AD_START_TIME_US - 2000) /* adsId= */ new Object(), /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US - 2000)
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true); .withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true);
updateTimeline(); updateTimeline();
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
@ -602,7 +602,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void public void
updateQueuedPeriods_withDurationChangeAfterReadingPeriod_handlesChangeAndRemovesPeriodsAfterChangedPeriod() { updateQueuedPeriods_withDurationChangeAfterReadingPeriod_handlesChangeAndRemovesPeriodsAfterChangedPeriod() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
enqueueNext(); // Content before first ad. enqueueNext(); // Content before first ad.
@ -612,7 +612,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads). // Change position of second ad (= change duration of content between ads).
updateAdPlaybackStateAndTimeline( updateAdPlaybackStateAndTimeline(
/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000); /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
boolean changeHandled = boolean changeHandled =
@ -628,7 +628,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void public void
updateQueuedPeriods_withDurationChangeBeforeReadingPeriod_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() { updateQueuedPeriods_withDurationChangeBeforeReadingPeriod_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
enqueueNext(); // Content before first ad. enqueueNext(); // Content before first ad.
@ -641,7 +641,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads). // Change position of second ad (= change duration of content between ads).
updateAdPlaybackStateAndTimeline( updateAdPlaybackStateAndTimeline(
/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000); /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
long maxRendererReadPositionUs = long maxRendererReadPositionUs =
@ -659,7 +659,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void public void
updateQueuedPeriods_withDurationChangeInReadingPeriodAfterReadingPosition_handlesChangeAndRemovesPeriodsAfterChangedPeriod() { updateQueuedPeriods_withDurationChangeInReadingPeriodAfterReadingPosition_handlesChangeAndRemovesPeriodsAfterChangedPeriod() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
enqueueNext(); // Content before first ad. enqueueNext(); // Content before first ad.
@ -671,7 +671,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads). // Change position of second ad (= change duration of content between ads).
updateAdPlaybackStateAndTimeline( updateAdPlaybackStateAndTimeline(
/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000); /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
long readingPositionAtStartOfContentBetweenAds = long readingPositionAtStartOfContentBetweenAds =
@ -691,7 +691,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void public void
updateQueuedPeriods_withDurationChangeInReadingPeriodBeforeReadingPosition_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() { updateQueuedPeriods_withDurationChangeInReadingPeriodBeforeReadingPosition_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
enqueueNext(); // Content before first ad. enqueueNext(); // Content before first ad.
@ -703,7 +703,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads). // Change position of second ad (= change duration of content between ads).
updateAdPlaybackStateAndTimeline( updateAdPlaybackStateAndTimeline(
/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000); /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
long readingPositionAtEndOfContentBetweenAds = long readingPositionAtEndOfContentBetweenAds =
@ -723,7 +723,7 @@ public final class MediaPeriodQueueTest {
@Test @Test
public void public void
updateQueuedPeriods_withDurationChangeInReadingPeriodReadToEnd_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() { updateQueuedPeriods_withDurationChangeInReadingPeriodReadToEnd_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod() {
setupAdTimeline(/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US); setupAdTimeline(/* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
enqueueNext(); // Content before first ad. enqueueNext(); // Content before first ad.
@ -735,7 +735,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads). // Change position of second ad (= change duration of content between ads).
updateAdPlaybackStateAndTimeline( updateAdPlaybackStateAndTimeline(
/* adGroupTimesUs= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000); /* adGroupTimesUs...= */ FIRST_AD_START_TIME_US, SECOND_AD_START_TIME_US - 1000);
setAdGroupLoaded(/* adGroupIndex= */ 0); setAdGroupLoaded(/* adGroupIndex= */ 0);
setAdGroupLoaded(/* adGroupIndex= */ 1); setAdGroupLoaded(/* adGroupIndex= */ 1);
boolean changeHandled = boolean changeHandled =
@ -838,7 +838,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, windowId,
/* numberOfPlayedAds= */ 0, /* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags= */ true, /* isAdPeriodFlags...= */ true,
false, false,
true, true,
true, true,
@ -873,7 +873,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, windowId,
/* numberOfPlayedAds= */ 4, /* numberOfPlayedAds= */ 4,
/* isAdPeriodFlags= */ true, /* isAdPeriodFlags...= */ true,
false, false,
true, true,
true, true,
@ -908,7 +908,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, windowId,
/* numberOfPlayedAds= */ 2, /* numberOfPlayedAds= */ 2,
/* isAdPeriodFlags= */ true, /* isAdPeriodFlags...= */ true,
false, false,
true, true,
true, true,
@ -932,7 +932,7 @@ public final class MediaPeriodQueueTest {
Object windowId = new Object(); Object windowId = new Object();
Timeline timeline = Timeline timeline =
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, /* numberOfPlayedAds= */ 0, /* isAdPeriodFlags= */ false, true); windowId, /* numberOfPlayedAds= */ 0, /* isAdPeriodFlags...= */ false, true);
MediaPeriodId mediaPeriodId = MediaPeriodId mediaPeriodId =
mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange( mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(
@ -951,7 +951,7 @@ public final class MediaPeriodQueueTest {
Object windowId = new Object(); Object windowId = new Object();
Timeline timeline = Timeline timeline =
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, /* numberOfPlayedAds= */ 0, /* isAdPeriodFlags= */ false, true, false); windowId, /* numberOfPlayedAds= */ 0, /* isAdPeriodFlags...= */ false, true, false);
MediaPeriodId mediaPeriodId = MediaPeriodId mediaPeriodId =
mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange( mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(
@ -970,7 +970,7 @@ public final class MediaPeriodQueueTest {
Object windowId = new Object(); Object windowId = new Object();
Timeline timeline = Timeline timeline =
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, /* numberOfPlayedAds= */ 1, /* isAdPeriodFlags= */ false, true, false); windowId, /* numberOfPlayedAds= */ 1, /* isAdPeriodFlags...= */ false, true, false);
MediaPeriodId mediaPeriodId = MediaPeriodId mediaPeriodId =
mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange( mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(
@ -989,7 +989,7 @@ public final class MediaPeriodQueueTest {
Object windowId = new Object(); Object windowId = new Object();
Timeline timeline = Timeline timeline =
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, /* numberOfPlayedAds= */ 2, /* isAdPeriodFlags= */ true, true, false); windowId, /* numberOfPlayedAds= */ 2, /* isAdPeriodFlags...= */ true, true, false);
MediaPeriodId mediaPeriodId = MediaPeriodId mediaPeriodId =
mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange( mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(
timeline, new Pair<>(windowId, 0), /* positionUs= */ 0); timeline, new Pair<>(windowId, 0), /* positionUs= */ 0);
@ -1009,7 +1009,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, windowId,
/* numberOfPlayedAds= */ 4, /* numberOfPlayedAds= */ 4,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
true, true,
true, true,
true, true,
@ -1032,7 +1032,12 @@ public final class MediaPeriodQueueTest {
Object windowId = new Object(); Object windowId = new Object();
Timeline timeline = Timeline timeline =
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, /* numberOfPlayedAds= */ 0, /* isAdPeriodFlags= */ true, false, false, false); windowId,
/* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags...= */ true,
false,
false,
false);
MediaPeriodId mediaPeriodId = MediaPeriodId mediaPeriodId =
mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange( mediaPeriodQueue.resolveMediaPeriodIdForAdsAfterPeriodPositionChange(
@ -1053,7 +1058,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline( createMultiPeriodServerSideInsertedTimeline(
windowId, windowId,
/* numberOfPlayedAds= */ 0, /* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
false, false,
false, false,
false); false);

View File

@ -1027,7 +1027,7 @@ public final class DefaultAnalyticsCollectorTest {
new AtomicReference<>( new AtomicReference<>(
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adsPerAdGroup= */ 1,
/* adGroupTimesUs= */ windowOffsetInFirstPeriodUs, /* adGroupTimesUs...= */ windowOffsetInFirstPeriodUs,
windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND, windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND,
C.TIME_END_OF_SOURCE)); C.TIME_END_OF_SOURCE));
AtomicInteger playedAdCount = new AtomicInteger(0); AtomicInteger playedAdCount = new AtomicInteger(0);
@ -1300,7 +1300,7 @@ public final class DefaultAnalyticsCollectorTest {
/* isDynamic= */ false, /* isDynamic= */ false,
10 * C.MICROS_PER_SECOND, 10 * C.MICROS_PER_SECOND,
FakeTimeline.createAdPlaybackState( FakeTimeline.createAdPlaybackState(
/* adsPerAdGroup= */ 1, /* adGroupTimesUs= */ /* adsPerAdGroup= */ 1, /* adGroupTimesUs...= */
windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND))); windowOffsetInFirstPeriodUs + 5 * C.MICROS_PER_SECOND)));
FakeMediaSource fakeMediaSource = FakeMediaSource fakeMediaSource =
new FakeMediaSource( new FakeMediaSource(

View File

@ -289,10 +289,11 @@ public final class SilenceSkippingAudioProcessorTest {
Pcm16BitAudioBuilder audioBuilder = new Pcm16BitAudioBuilder(channelCount, totalFrameCount); Pcm16BitAudioBuilder audioBuilder = new Pcm16BitAudioBuilder(channelCount, totalFrameCount);
while (!audioBuilder.isFull()) { while (!audioBuilder.isFull()) {
int silenceDurationFrames = (silenceDurationMs * sampleRate) / 1000; int silenceDurationFrames = (silenceDurationMs * sampleRate) / 1000;
audioBuilder.appendFrames(/* count= */ silenceDurationFrames, /* channelLevels= */ (short) 0); audioBuilder.appendFrames(
/* count= */ silenceDurationFrames, /* channelLevels...= */ (short) 0);
int noiseDurationFrames = (noiseDurationMs * sampleRate) / 1000; int noiseDurationFrames = (noiseDurationMs * sampleRate) / 1000;
audioBuilder.appendFrames( audioBuilder.appendFrames(
/* count= */ noiseDurationFrames, /* channelLevels= */ Short.MAX_VALUE); /* count= */ noiseDurationFrames, /* channelLevels...= */ Short.MAX_VALUE);
} }
return new InputBufferProvider(audioBuilder.build()); return new InputBufferProvider(audioBuilder.build());
} }

View File

@ -79,7 +79,7 @@ public final class AdsMediaSourceTest {
CONTENT_TIMELINE.getUidOfPeriod(/* periodIndex= */ 0); CONTENT_TIMELINE.getUidOfPeriod(/* periodIndex= */ 0);
private static final AdPlaybackState AD_PLAYBACK_STATE = private static final AdPlaybackState AD_PLAYBACK_STATE =
new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs= */ 0) new AdPlaybackState(/* adsId= */ new Object(), /* adGroupTimesUs...= */ 0)
.withContentDurationUs(CONTENT_DURATION_US) .withContentDurationUs(CONTENT_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri( .withAvailableAdUri(

View File

@ -93,16 +93,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
// Test with one ad group before the window, and the window starting within the second ad group. // Test with one ad group before the window, and the window starting within the second ad group.
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState( new AdPlaybackState(
/* adsId= */ new Object(), /* adGroupTimesUs= */ 15_000_000, 41_500_000, 42_200_000) /* adsId= */ new Object(), /* adGroupTimesUs...= */
15_000_000,
41_500_000,
42_200_000)
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs= */ 500_000) .withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs...= */ 500_000)
.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs= */ 300_000, 100_000) .withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs...= */ 300_000, 100_000)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 400_000) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 400_000)
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100_000) .withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100_000)
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 400_000) .withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 400_000)
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 200_000); .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 200_000);
@ -166,16 +169,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
// Test with one ad group before the window, and the window starting within the second ad group. // Test with one ad group before the window, and the window starting within the second ad group.
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState( new AdPlaybackState(
/* adsId= */ new Object(), /* adGroupTimesUs= */ 15_000_000, 41_500_000, 42_200_000) /* adsId= */ new Object(), /* adGroupTimesUs...= */
15_000_000,
41_500_000,
42_200_000)
.withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 0, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 1, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs= */ 500_000) .withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs...= */ 500_000)
.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs= */ 300_000, 100_000) .withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs...= */ 300_000, 100_000)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 400_000) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 400_000)
.withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100_000) .withContentResumeOffsetUs(/* adGroupIndex= */ 0, /* contentResumeOffsetUs= */ 100_000)
.withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 400_000) .withContentResumeOffsetUs(/* adGroupIndex= */ 1, /* contentResumeOffsetUs= */ 400_000)
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 200_000); .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 200_000);
@ -260,19 +266,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 200_000); /* adDurationsUs...= */ 200_000);
adPlaybackState = adPlaybackState =
addAdGroupToAdPlaybackState( addAdGroupToAdPlaybackState(
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ 400_000, /* fromPositionUs= */ 400_000,
/* contentResumeOffsetUs= */ 1_000_000, /* contentResumeOffsetUs= */ 1_000_000,
/* adDurationsUs= */ 300_000); /* adDurationsUs...= */ 300_000);
AdPlaybackState firstAdPlaybackState = AdPlaybackState firstAdPlaybackState =
addAdGroupToAdPlaybackState( addAdGroupToAdPlaybackState(
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ 900_000, /* fromPositionUs= */ 900_000,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 100_000); /* adDurationsUs...= */ 100_000);
AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>(); AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
mediaSourceRef.set( mediaSourceRef.set(
@ -330,7 +336,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
new AdPlaybackState(/* adsId= */ new Object()), new AdPlaybackState(/* adsId= */ new Object()),
/* fromPositionUs= */ 900_000, /* fromPositionUs= */ 900_000,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 100_000); /* adDurationsUs...= */ 100_000);
AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>(); AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
mediaSourceRef.set( mediaSourceRef.set(
new ServerSideAdInsertionMediaSource( new ServerSideAdInsertionMediaSource(
@ -358,7 +364,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
firstAdPlaybackState, firstAdPlaybackState,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 500_000); /* adDurationsUs...= */ 500_000);
mediaSourceRef mediaSourceRef
.get() .get()
.setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState)); .setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState));
@ -401,7 +407,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
new AdPlaybackState(/* adsId= */ new Object()), new AdPlaybackState(/* adsId= */ new Object()),
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 500_000); /* adDurationsUs...= */ 500_000);
AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>(); AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
mediaSourceRef.set( mediaSourceRef.set(
new ServerSideAdInsertionMediaSource( new ServerSideAdInsertionMediaSource(
@ -431,7 +437,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
firstAdPlaybackState firstAdPlaybackState
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 3)
.withAdDurationsUs( .withAdDurationsUs(
/* adGroupIndex= */ 0, /* adDurationsUs= */ 50_000, 250_000, 200_000); /* adGroupIndex= */ 0, /* adDurationsUs...= */ 50_000, 250_000, 200_000);
mediaSourceRef mediaSourceRef
.get() .get()
.setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState)); .setAdPlaybackStates(ImmutableMap.of(periodUid.get(), secondAdPlaybackState));
@ -469,19 +475,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 100_000); /* adDurationsUs...= */ 100_000);
adPlaybackState = adPlaybackState =
addAdGroupToAdPlaybackState( addAdGroupToAdPlaybackState(
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ 600_000, /* fromPositionUs= */ 600_000,
/* contentResumeOffsetUs= */ 1_000_000, /* contentResumeOffsetUs= */ 1_000_000,
/* adDurationsUs= */ 100_000); /* adDurationsUs...= */ 100_000);
AdPlaybackState firstAdPlaybackState = AdPlaybackState firstAdPlaybackState =
addAdGroupToAdPlaybackState( addAdGroupToAdPlaybackState(
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ 900_000, /* fromPositionUs= */ 900_000,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 100_000); /* adDurationsUs...= */ 100_000);
AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>(); AtomicReference<ServerSideAdInsertionMediaSource> mediaSourceRef = new AtomicReference<>();
mediaSourceRef.set( mediaSourceRef.set(

View File

@ -39,7 +39,7 @@ public final class ServerSideAdInsertionUtilTest {
@Test @Test
public void addAdGroupToAdPlaybackState_insertsCorrectAdGroupData() { public void addAdGroupToAdPlaybackState_insertsCorrectAdGroupData() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(ADS_ID, /* adGroupTimesUs= */ 0, 1, C.TIME_END_OF_SOURCE) new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 1, C.TIME_END_OF_SOURCE)
.withRemovedAdGroupCount(2); .withRemovedAdGroupCount(2);
// stream: 0-- content --4300-- ad1 --4500-- content // stream: 0-- content --4300-- ad1 --4500-- content
@ -49,16 +49,16 @@ public final class ServerSideAdInsertionUtilTest {
state, state,
/* fromPositionUs= */ 4300, /* fromPositionUs= */ 4300,
/* contentResumeOffsetUs= */ 400, /* contentResumeOffsetUs= */ 400,
/* adDurationsUs= */ 200); /* adDurationsUs...= */ 200);
assertThat(state) assertThat(state)
.isEqualTo( .isEqualTo(
new AdPlaybackState(ADS_ID, /* adGroupTimesUs= */ 0, 0, 4300, C.TIME_END_OF_SOURCE) new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 4300, C.TIME_END_OF_SOURCE)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 200)); .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,20 +67,20 @@ public final class ServerSideAdInsertionUtilTest {
state, state,
/* fromPositionUs= */ 2100, /* fromPositionUs= */ 2100,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 300); /* adDurationsUs...= */ 300);
assertThat(state) assertThat(state)
.isEqualTo( .isEqualTo(
new AdPlaybackState( new AdPlaybackState(
ADS_ID, /* adGroupTimesUs= */ 0, 0, 2100, 4000, C.TIME_END_OF_SOURCE) ADS_ID, /* adGroupTimesUs...= */ 0, 0, 2100, 4000, C.TIME_END_OF_SOURCE)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
.withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 2, /* isServerSideInserted= */ true)
.withIsServerSideInserted(/* adGroupIndex= */ 3, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 3, /* isServerSideInserted= */ true)
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 300) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 300)
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs= */ 200)); .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
@ -89,12 +89,12 @@ public final class ServerSideAdInsertionUtilTest {
state, state,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 50, /* contentResumeOffsetUs= */ 50,
/* adDurationsUs= */ 100); /* adDurationsUs...= */ 100);
assertThat(state) assertThat(state)
.isEqualTo( .isEqualTo(
new AdPlaybackState( new AdPlaybackState(
ADS_ID, /* adGroupTimesUs= */ 0, 0, 0, 2050, 3950, C.TIME_END_OF_SOURCE) ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2050, 3950, C.TIME_END_OF_SOURCE)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
@ -104,9 +104,9 @@ public final class ServerSideAdInsertionUtilTest {
.withIsServerSideInserted(/* adGroupIndex= */ 4, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 4, /* isServerSideInserted= */ true)
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 50) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 50)
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 100) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 100)
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs= */ 300) .withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 300)
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs= */ 200)); .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
@ -115,12 +115,19 @@ public final class ServerSideAdInsertionUtilTest {
state, state,
/* fromPositionUs= */ 5000, /* fromPositionUs= */ 5000,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 1000); /* adDurationsUs...= */ 1000);
assertThat(state) assertThat(state)
.isEqualTo( .isEqualTo(
new AdPlaybackState( new AdPlaybackState(
ADS_ID, /* adGroupTimesUs= */ 0, 0, 0, 2050, 3950, 4850, C.TIME_END_OF_SOURCE) ADS_ID, /* adGroupTimesUs...= */
0,
0,
0,
2050,
3950,
4850,
C.TIME_END_OF_SOURCE)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 1)
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
@ -132,10 +139,10 @@ public final class ServerSideAdInsertionUtilTest {
.withIsServerSideInserted(/* adGroupIndex= */ 5, /* isServerSideInserted= */ true) .withIsServerSideInserted(/* adGroupIndex= */ 5, /* isServerSideInserted= */ true)
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 50) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 50)
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 100) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 100)
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs= */ 300) .withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 300)
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs= */ 200) .withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 200)
.withAdDurationsUs(/* adGroupIndex= */ 5, /* adDurationsUs= */ 1000)); .withAdDurationsUs(/* adGroupIndex= */ 5, /* adDurationsUs...= */ 1000));
} }
@Test @Test
@ -147,7 +154,7 @@ public final class ServerSideAdInsertionUtilTest {
state, state,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 50_000, /* contentResumeOffsetUs= */ 50_000,
/* adDurationsUs= */ 0, /* adDurationsUs...= */ 0,
0, 0,
10_000, 10_000,
40_000, 40_000,
@ -170,7 +177,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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, 0, 0, 2000, 4000) new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
@ -178,9 +185,9 @@ public final class ServerSideAdInsertionUtilTest {
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0) .withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 150, 50) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs= */ 200) .withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs= */ 50, 50, 100); .withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
assertThat( assertThat(
getStreamPositionUsForAd( getStreamPositionUsForAd(
@ -270,7 +277,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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, 0, 0, 2000, 4000) new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
@ -278,9 +285,9 @@ public final class ServerSideAdInsertionUtilTest {
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0) .withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 150, 50) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs= */ 200) .withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs= */ 50, 50, 100); .withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
assertThat( assertThat(
getMediaPeriodPositionUsForAd( getMediaPeriodPositionUsForAd(
@ -375,7 +382,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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, 0, 0, 2000, 4000) new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
@ -383,9 +390,9 @@ public final class ServerSideAdInsertionUtilTest {
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0) .withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 150, 50) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs= */ 200) .withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs= */ 50, 50, 100); .withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
assertThat(getStreamPositionUsForContent(/* positionUs= */ 0, /* nextAdGroupIndex= */ 2, state)) assertThat(getStreamPositionUsForContent(/* positionUs= */ 0, /* nextAdGroupIndex= */ 2, state))
.isEqualTo(0); .isEqualTo(0);
@ -471,7 +478,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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, 0, 0, 2000, 4000) new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 0, 0, 2000, 4000)
.withRemovedAdGroupCount(2) .withRemovedAdGroupCount(2)
.withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2) .withAdCount(/* adGroupIndex= */ 2, /* adCount= */ 2)
.withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 3, /* adCount= */ 1)
@ -479,9 +486,9 @@ public final class ServerSideAdInsertionUtilTest {
.withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100) .withContentResumeOffsetUs(/* adGroupIndex= */ 2, /* contentResumeOffsetUs= */ 100)
.withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0) .withContentResumeOffsetUs(/* adGroupIndex= */ 3, /* contentResumeOffsetUs= */ 0)
.withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400) .withContentResumeOffsetUs(/* adGroupIndex= */ 4, /* contentResumeOffsetUs= */ 400)
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ 150, 50) .withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs...= */ 150, 50)
.withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs= */ 200) .withAdDurationsUs(/* adGroupIndex= */ 3, /* adDurationsUs...= */ 200)
.withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs= */ 50, 50, 100); .withAdDurationsUs(/* adGroupIndex= */ 4, /* adDurationsUs...= */ 50, 50, 100);
assertThat( assertThat(
getMediaPeriodPositionUsForContent( getMediaPeriodPositionUsForContent(
@ -588,7 +595,7 @@ public final class ServerSideAdInsertionUtilTest {
@Test @Test
public void getAdCountInGroup_withUnsetCount_returnsZero() { public void getAdCountInGroup_withUnsetCount_returnsZero() {
AdPlaybackState state = new AdPlaybackState(ADS_ID, /* adGroupTimesUs= */ 0, 2000); AdPlaybackState state = new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 2000);
assertThat(getAdCountInGroup(state, /* adGroupIndex= */ 0)).isEqualTo(0); assertThat(getAdCountInGroup(state, /* adGroupIndex= */ 0)).isEqualTo(0);
assertThat(getAdCountInGroup(state, /* adGroupIndex= */ 1)).isEqualTo(0); assertThat(getAdCountInGroup(state, /* adGroupIndex= */ 1)).isEqualTo(0);
@ -597,7 +604,7 @@ public final class ServerSideAdInsertionUtilTest {
@Test @Test
public void getAdCountInGroup_withSetCount_returnsCount() { public void getAdCountInGroup_withSetCount_returnsCount() {
AdPlaybackState state = AdPlaybackState state =
new AdPlaybackState(ADS_ID, /* adGroupTimesUs= */ 0, 2000) new AdPlaybackState(ADS_ID, /* adGroupTimesUs...= */ 0, 2000)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 4) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 4)
.withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 6); .withAdCount(/* adGroupIndex= */ 1, /* adCount= */ 6);

View File

@ -570,9 +570,9 @@ public final class AdaptiveTrackSelectionTest {
TrackGroup trackGroupMultipleFixed = new TrackGroup(formatFixed1, formatFixed2); TrackGroup trackGroupMultipleFixed = new TrackGroup(formatFixed1, formatFixed2);
TrackGroup trackGroupAdaptive = TrackGroup trackGroupAdaptive =
new TrackGroup(formatAdaptive1, formatAdaptive2, formatAdaptive3, formatAdaptive4); new TrackGroup(formatAdaptive1, formatAdaptive2, formatAdaptive3, formatAdaptive4);
Definition definitionFixed1 = new Definition(trackGroupMultipleFixed, /* tracks= */ 0); Definition definitionFixed1 = new Definition(trackGroupMultipleFixed, /* tracks...= */ 0);
Definition definitionFixed2 = new Definition(trackGroupMultipleFixed, /* tracks= */ 1); Definition definitionFixed2 = new Definition(trackGroupMultipleFixed, /* tracks...= */ 1);
Definition definitionAdaptive = new Definition(trackGroupAdaptive, /* tracks= */ 1, 2, 3); Definition definitionAdaptive = new Definition(trackGroupAdaptive, /* tracks...= */ 1, 2, 3);
List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>(); List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
AdaptiveTrackSelection.Factory factory = AdaptiveTrackSelection.Factory factory =
new AdaptiveTrackSelection.Factory() { new AdaptiveTrackSelection.Factory() {
@ -621,9 +621,9 @@ public final class AdaptiveTrackSelectionTest {
TrackGroup trackGroup2 = TrackGroup trackGroup2 =
new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat); new TrackGroup(group2Format1, group2Format2, group2Format3, group2UnusedFormat);
TrackGroup fixedGroup = new TrackGroup(fixedFormat); TrackGroup fixedGroup = new TrackGroup(fixedFormat);
Definition definition1 = new Definition(trackGroup1, /* tracks= */ 0, 1); Definition definition1 = new Definition(trackGroup1, /* tracks...= */ 0, 1);
Definition definition2 = new Definition(trackGroup2, /* tracks= */ 0, 1, 2); Definition definition2 = new Definition(trackGroup2, /* tracks...= */ 0, 1, 2);
Definition fixedDefinition = new Definition(fixedGroup, /* tracks= */ 0); Definition fixedDefinition = new Definition(fixedGroup, /* tracks...= */ 0);
List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>(); List<List<AdaptationCheckpoint>> checkPoints = new ArrayList<>();
AdaptiveTrackSelection.Factory factory = AdaptiveTrackSelection.Factory factory =
new AdaptiveTrackSelection.Factory() { new AdaptiveTrackSelection.Factory() {

View File

@ -2173,8 +2173,10 @@ public final class DefaultTrackSelectorTest {
TIMELINE); TIMELINE);
assertThat(result.length).isEqualTo(2); assertThat(result.length).isEqualTo(2);
assertAdaptiveSelection(result.selections[0], trackGroups.get(0), /* expectedTracks= */ 1, 0); assertAdaptiveSelection(
assertAdaptiveSelection(result.selections[1], trackGroups.get(1), /* expectedTracks= */ 1, 0); result.selections[0], trackGroups.get(0), /* expectedTracks...= */ 1, 0);
assertAdaptiveSelection(
result.selections[1], trackGroups.get(1), /* expectedTracks...= */ 1, 0);
// Multiple adaptive selection disallowed. // Multiple adaptive selection disallowed.
trackSelector.setParameters( trackSelector.setParameters(
@ -2187,7 +2189,8 @@ public final class DefaultTrackSelectorTest {
TIMELINE); TIMELINE);
assertThat(result.length).isEqualTo(2); assertThat(result.length).isEqualTo(2);
assertAdaptiveSelection(result.selections[0], trackGroups.get(0), /* expectedTracks= */ 1, 0); assertAdaptiveSelection(
result.selections[0], trackGroups.get(0), /* expectedTracks...= */ 1, 0);
assertFixedSelection(result.selections[1], trackGroups.get(1), /* expectedTrack= */ 1); assertFixedSelection(result.selections[1], trackGroups.get(1), /* expectedTrack= */ 1);
} }
@ -2231,7 +2234,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections[0], adaptiveGroup, /* expectedTracks= */ 1, 0); assertAdaptiveSelection(result.selections[0], adaptiveGroup, /* expectedTracks...= */ 1, 0);
// Select default (=most tracks) if no preference is specified. // Select default (=most tracks) if no preference is specified.
trackSelector.setParameters(defaultParameters.buildUpon().setPreferredVideoMimeType(null)); trackSelector.setParameters(defaultParameters.buildUpon().setPreferredVideoMimeType(null));
@ -2239,7 +2242,7 @@ public final class DefaultTrackSelectorTest {
trackSelector.selectTracks( trackSelector.selectTracks(
new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE); new RendererCapabilities[] {VIDEO_CAPABILITIES}, trackGroups, periodId, TIMELINE);
assertThat(result.length).isEqualTo(1); assertThat(result.length).isEqualTo(1);
assertAdaptiveSelection(result.selections[0], adaptiveGroup, /* expectedTracks= */ 1, 0); assertAdaptiveSelection(result.selections[0], adaptiveGroup, /* expectedTracks...= */ 1, 0);
} }
/** /**
@ -2418,7 +2421,7 @@ public final class DefaultTrackSelectorTest {
@Test @Test
public void roundTripViaBundle_ofSelectionOverride_yieldsEqualInstance() { public void roundTripViaBundle_ofSelectionOverride_yieldsEqualInstance() {
SelectionOverride selectionOverrideToBundle = SelectionOverride selectionOverrideToBundle =
new SelectionOverride(/* groupIndex= */ 1, /* tracks= */ 2, 3); new SelectionOverride(/* groupIndex= */ 1, /* tracks...= */ 2, 3);
SelectionOverride selectionOverrideFromBundle = SelectionOverride selectionOverrideFromBundle =
DefaultTrackSelector.SelectionOverride.CREATOR.fromBundle( DefaultTrackSelector.SelectionOverride.CREATOR.fromBundle(

View File

@ -689,7 +689,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsPlaylistTracker.Pla
sampleStreamWrapper.prepareWithMultivariantPlaylistInfo( sampleStreamWrapper.prepareWithMultivariantPlaylistInfo(
muxedTrackGroups.toArray(new TrackGroup[0]), muxedTrackGroups.toArray(new TrackGroup[0]),
/* primaryTrackGroupIndex= */ 0, /* primaryTrackGroupIndex= */ 0,
/* optionalTrackGroupsIndices= */ muxedTrackGroups.indexOf(id3TrackGroup)); /* optionalTrackGroupsIndices...= */ muxedTrackGroups.indexOf(id3TrackGroup));
} }
} }

View File

@ -682,7 +682,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ fromPositionUs, /* fromPositionUs= */ fromPositionUs,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ getAdDuration( /* adDurationsUs...= */ getAdDuration(
/* startTimeSeconds= */ cuePoint.getStartTime(), /* startTimeSeconds= */ cuePoint.getStartTime(),
/* endTimeSeconds= */ cuePoint.getEndTime())); /* endTimeSeconds= */ cuePoint.getEndTime()));
} }

View File

@ -443,7 +443,7 @@ import java.util.Set;
private static AdPlaybackState splitAdGroupForPeriod( private static AdPlaybackState splitAdGroupForPeriod(
Object adsId, AdGroup adGroup, long periodStartUs, long periodDurationUs) { Object adsId, AdGroup adGroup, long periodStartUs, long periodDurationUs) {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState(checkNotNull(adsId), /* adGroupTimesUs= */ 0) new AdPlaybackState(checkNotNull(adsId), /* adGroupTimesUs...= */ 0)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, periodDurationUs) .withAdDurationsUs(/* adGroupIndex= */ 0, periodDurationUs)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true) .withIsServerSideInserted(/* adGroupIndex= */ 0, true)
@ -605,7 +605,7 @@ import java.util.Set;
adPlaybackState, adPlaybackState,
/* fromPositionUs= */ currentContentPeriodPositionUs, /* fromPositionUs= */ currentContentPeriodPositionUs,
/* contentResumeOffsetUs= */ sum(adDurationsUs), /* contentResumeOffsetUs= */ sum(adDurationsUs),
/* adDurationsUs= */ adDurationsUs); /* adDurationsUs...= */ adDurationsUs);
adGroupIndex = adGroupIndex =
adPlaybackState.getAdGroupIndexForPositionUs( adPlaybackState.getAdGroupIndexForPositionUs(
mediaPeriodPositionUs, /* periodDurationUs= */ C.TIME_UNSET); mediaPeriodPositionUs, /* periodDurationUs= */ C.TIME_UNSET);

View File

@ -239,7 +239,7 @@ public final class ImaAdsLoaderTest {
assertThat(getAdPlaybackState(/* periodIndex= */ 0)) assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo( .isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US)); .withContentDurationUs(CONTENT_PERIOD_DURATION_US));
} }
@ -312,7 +312,7 @@ public final class ImaAdsLoaderTest {
// Verify that the preroll ad has been marked as played. // Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */ 0)) assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo( .isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US) .withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI) .withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI)
@ -336,7 +336,7 @@ public final class ImaAdsLoaderTest {
assertThat(getAdPlaybackState(/* periodIndex= */ 0)) assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo( .isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 20_500_000) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 20_500_000)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US) .withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdDurationsUs(new long[][] {{TEST_AD_DURATION_US}}) .withAdDurationsUs(new long[][] {{TEST_AD_DURATION_US}})
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
@ -384,7 +384,7 @@ public final class ImaAdsLoaderTest {
assertThat(getAdPlaybackState(/* periodIndex= */ 0)) assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo( .isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ C.TIME_END_OF_SOURCE) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ C.TIME_END_OF_SOURCE)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US) .withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdDurationsUs(new long[][] {{TEST_AD_DURATION_US}}) .withAdDurationsUs(new long[][] {{TEST_AD_DURATION_US}})
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
@ -1114,7 +1114,7 @@ public final class ImaAdsLoaderTest {
// Verify that the preroll ad has been marked as played. // Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */ 0)) assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo( .isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US) .withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI) .withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI)
@ -1123,7 +1123,7 @@ public final class ImaAdsLoaderTest {
.withAdResumePositionUs(/* adResumePositionUs= */ 0)); .withAdResumePositionUs(/* adResumePositionUs= */ 0));
// Verify that the second source's ad cue points have preloaded. // Verify that the second source's ad cue points have preloaded.
assertThat(getAdPlaybackState(/* periodIndex= */ 1)) assertThat(getAdPlaybackState(/* periodIndex= */ 1))
.isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs= */ 0)); .isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs...= */ 0));
} }
@Test @Test
@ -1181,7 +1181,7 @@ public final class ImaAdsLoaderTest {
// Verify that the preroll ad has been marked as played. // Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */ 0)) assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo( .isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0) new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US) .withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1) .withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI) .withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI)
@ -1190,7 +1190,7 @@ public final class ImaAdsLoaderTest {
.withAdResumePositionUs(/* adResumePositionUs= */ 0)); .withAdResumePositionUs(/* adResumePositionUs= */ 0));
// Verify that the second source's ad cue points have preloaded. // Verify that the second source's ad cue points have preloaded.
assertThat(getAdPlaybackState(/* periodIndex= */ 1)) assertThat(getAdPlaybackState(/* periodIndex= */ 1))
.isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs= */ 0)); .isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs...= */ 0));
} }
@Test @Test

View File

@ -37,7 +37,7 @@ public class ImaServerSideAdInsertionMediaSourceTest {
new AdPlaybackState("adsId1"), new AdPlaybackState("adsId1"),
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 10, /* contentResumeOffsetUs= */ 10,
/* adDurationsUs= */ 5_000_000, /* adDurationsUs...= */ 5_000_000,
10_000_000, 10_000_000,
20_000_000); 20_000_000);
AdPlaybackState secondAdPlaybackState = AdPlaybackState secondAdPlaybackState =
@ -45,20 +45,20 @@ public class ImaServerSideAdInsertionMediaSourceTest {
new AdPlaybackState("adsId2"), new AdPlaybackState("adsId2"),
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 10, /* contentResumeOffsetUs= */ 10,
/* adDurationsUs= */ 10_000_000) /* adDurationsUs...= */ 10_000_000)
.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0); .withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
AdPlaybackState thirdAdPlaybackState = AdPlaybackState thirdAdPlaybackState =
ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState( ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(
new AdPlaybackState("adsId3"), new AdPlaybackState("adsId3"),
/* fromPositionUs= */ C.TIME_END_OF_SOURCE, /* fromPositionUs= */ C.TIME_END_OF_SOURCE,
/* contentResumeOffsetUs= */ 10, /* contentResumeOffsetUs= */ 10,
/* adDurationsUs= */ 10_000_000); /* adDurationsUs...= */ 10_000_000);
thirdAdPlaybackState = thirdAdPlaybackState =
ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState( ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(
thirdAdPlaybackState, thirdAdPlaybackState,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 10, /* contentResumeOffsetUs= */ 10,
/* adDurationsUs= */ 10_000_000) /* adDurationsUs...= */ 10_000_000)
.withRemovedAdGroupCount(1); .withRemovedAdGroupCount(1);
State state = State state =
new State( new State(

View File

@ -435,7 +435,7 @@ public class ImaUtilTest {
new AdPlaybackState(/* adsId= */ "adsId", 0) new AdPlaybackState(/* adsId= */ "adsId", 0)
.withAdCount(/* adGroupIndex= */ 0, periodCount) .withAdCount(/* adGroupIndex= */ 0, periodCount)
.withAdDurationsUs( .withAdDurationsUs(
/* adGroupIndex= */ 0, /* adDurationsUs= */ /* adGroupIndex= */ 0, /* adDurationsUs...= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs, DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs,
periodDurationUs, periodDurationUs,
periodDurationUs, periodDurationUs,
@ -475,10 +475,12 @@ public class ImaUtilTest {
.withAdCount(/* adGroupIndex= */ 1, 1) .withAdCount(/* adGroupIndex= */ 1, 1)
.withAdCount(/* adGroupIndex= */ 2, 1) .withAdCount(/* adGroupIndex= */ 2, 1)
.withAdDurationsUs( .withAdDurationsUs(
/* adGroupIndex= */ 0, /* adDurationsUs= */ /* adGroupIndex= */ 0, /* adDurationsUs...= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (2 * periodDurationUs)) DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (2 * periodDurationUs))
.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs= */ (2 * periodDurationUs)) .withAdDurationsUs(
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ (2 * periodDurationUs)) /* adGroupIndex= */ 1, /* adDurationsUs...= */ (2 * periodDurationUs))
.withAdDurationsUs(
/* adGroupIndex= */ 2, /* adDurationsUs...= */ (2 * periodDurationUs))
.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0) .withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0)
.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0) .withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true) .withIsServerSideInserted(/* adGroupIndex= */ 0, true)
@ -520,7 +522,7 @@ public class ImaUtilTest {
// around removed. // around removed.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs + 2) DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs + 2)
.withAdCount(/* adGroupIndex= */ 0, 1) .withAdCount(/* adGroupIndex= */ 0, 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs= */ periodDurationUs) .withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs...= */ periodDurationUs)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true); .withIsServerSideInserted(/* adGroupIndex= */ 0, true);
FakeTimeline timeline = FakeTimeline timeline =
new FakeTimeline( new FakeTimeline(
@ -543,7 +545,7 @@ public class ImaUtilTest {
AdPlaybackState adPlaybackState = AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ "adsId", periodDurationUs - 1) new AdPlaybackState(/* adsId= */ "adsId", periodDurationUs - 1)
.withAdCount(/* adGroupIndex= */ 0, 1) .withAdCount(/* adGroupIndex= */ 0, 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs= */ periodDurationUs) .withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs...= */ periodDurationUs)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true); .withIsServerSideInserted(/* adGroupIndex= */ 0, true);
FakeTimeline timeline = FakeTimeline timeline =
new FakeTimeline( new FakeTimeline(
@ -567,7 +569,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 30_000_000); /* adDurationsUs...= */ 30_000_000);
adPlaybackState = adPlaybackState =
ImaUtil.expandAdGroupPlaceholder( ImaUtil.expandAdGroupPlaceholder(
@ -592,7 +594,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 30_000_000); /* adDurationsUs...= */ 30_000_000);
adPlaybackState = adPlaybackState =
ImaUtil.expandAdGroupPlaceholder( ImaUtil.expandAdGroupPlaceholder(
@ -617,7 +619,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 30_000_000); /* adDurationsUs...= */ 30_000_000);
adPlaybackState = adPlaybackState =
ImaUtil.expandAdGroupPlaceholder( ImaUtil.expandAdGroupPlaceholder(
@ -642,7 +644,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 30_000_000); /* adDurationsUs...= */ 30_000_000);
adPlaybackState = adPlaybackState =
ImaUtil.expandAdGroupPlaceholder( ImaUtil.expandAdGroupPlaceholder(
@ -665,7 +667,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 10_000_001); /* adDurationsUs...= */ 10_000_001);
adPlaybackState = adPlaybackState =
ImaUtil.expandAdGroupPlaceholder( ImaUtil.expandAdGroupPlaceholder(
@ -688,7 +690,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 30_000_000); /* adDurationsUs...= */ 30_000_000);
adPlaybackState = adPlaybackState =
ImaUtil.expandAdGroupPlaceholder( ImaUtil.expandAdGroupPlaceholder(
@ -712,7 +714,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 10_000_000, /* adDurationsUs...= */ 10_000_000,
20_000_000, 20_000_000,
0); 0);
@ -737,7 +739,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 0, /* adDurationsUs...= */ 0,
10_000_000, 10_000_000,
20_000_000); 20_000_000);
@ -762,7 +764,7 @@ public class ImaUtilTest {
AdPlaybackState.NONE, AdPlaybackState.NONE,
/* fromPositionUs= */ 0, /* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0, /* contentResumeOffsetUs= */ 0,
/* adDurationsUs= */ 5_000_000, /* adDurationsUs...= */ 5_000_000,
10_000_000, 10_000_000,
20_000_000); 20_000_000);

View File

@ -69,7 +69,7 @@ public class FakeTrackSelector extends DefaultTrackSelector {
boolean hasTracks = trackGroupArray.length > 0; boolean hasTracks = trackGroupArray.length > 0;
definitions[i] = definitions[i] =
hasTracks hasTracks
? new ExoTrackSelection.Definition(trackGroupArray.get(0), /* tracks= */ 0) ? new ExoTrackSelection.Definition(trackGroupArray.get(0), /* tracks...= */ 0)
: null; : null;
} }
return definitions; return definitions;

View File

@ -39,7 +39,7 @@ public class FakeTimelineTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
windowId, windowId,
numberOfPlayedAds, numberOfPlayedAds,
/* isAdPeriodFlags= */ true, /* isAdPeriodFlags...= */ true,
false, false,
true, true,
true, true,
@ -94,7 +94,7 @@ public class FakeTimelineTest {
FakeTimeline.createMultiPeriodAdTimeline( FakeTimeline.createMultiPeriodAdTimeline(
/* windowId= */ new Object(), /* windowId= */ new Object(),
/* numberOfPlayedAds= */ 0, /* numberOfPlayedAds= */ 0,
/* isAdPeriodFlags= */ false, /* isAdPeriodFlags...= */ false,
true, true,
true, true,
false); false);

View File

@ -24,8 +24,6 @@ import static androidx.media3.exoplayer.DefaultLoadControl.DEFAULT_MIN_BUFFER_MS
import android.content.Context; import android.content.Context;
import android.os.Handler; import android.os.Handler;
import android.os.Looper;
import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.Format; import androidx.media3.common.Format;
import androidx.media3.common.MediaItem; import androidx.media3.common.MediaItem;
@ -64,31 +62,16 @@ import androidx.media3.exoplayer.video.VideoRendererEventListener;
void onError(Exception e); void onError(Exception e);
} }
private final Context context; private final ExoPlayer player;
private final boolean removeAudio;
private final boolean removeVideo;
private final MediaSource.Factory mediaSourceFactory;
private final Looper looper;
private final Clock clock;
@Nullable private ExoPlayer player;
public ExoPlayerAssetLoader( public ExoPlayerAssetLoader(
Context context, Context context,
MediaItem mediaItem,
boolean removeAudio, boolean removeAudio,
boolean removeVideo, boolean removeVideo,
MediaSource.Factory mediaSourceFactory, MediaSource.Factory mediaSourceFactory,
Looper looper, Listener listener,
Clock clock) { Clock clock) {
this.context = context;
this.removeAudio = removeAudio;
this.removeVideo = removeVideo;
this.mediaSourceFactory = mediaSourceFactory;
this.looper = looper;
this.clock = clock;
}
public void start(MediaItem mediaItem, Listener listener) {
DefaultTrackSelector trackSelector = new DefaultTrackSelector(context); DefaultTrackSelector trackSelector = new DefaultTrackSelector(context);
trackSelector.setParameters( trackSelector.setParameters(
new DefaultTrackSelector.Parameters.Builder(context) new DefaultTrackSelector.Parameters.Builder(context)
@ -108,8 +91,7 @@ import androidx.media3.exoplayer.video.VideoRendererEventListener;
new ExoPlayer.Builder(context, new RenderersFactoryImpl(removeAudio, removeVideo, listener)) new ExoPlayer.Builder(context, new RenderersFactoryImpl(removeAudio, removeVideo, listener))
.setMediaSourceFactory(mediaSourceFactory) .setMediaSourceFactory(mediaSourceFactory)
.setTrackSelector(trackSelector) .setTrackSelector(trackSelector)
.setLoadControl(loadControl) .setLoadControl(loadControl);
.setLooper(looper);
if (clock != Clock.DEFAULT) { if (clock != Clock.DEFAULT) {
// Transformer.Builder#setClock is also @VisibleForTesting, so if we're using a non-default // Transformer.Builder#setClock is also @VisibleForTesting, so if we're using a non-default
// clock we must be in a test context. // clock we must be in a test context.
@ -120,14 +102,14 @@ import androidx.media3.exoplayer.video.VideoRendererEventListener;
player = playerBuilder.build(); player = playerBuilder.build();
player.setMediaItem(mediaItem); player.setMediaItem(mediaItem);
player.addListener(new PlayerListener(listener)); player.addListener(new PlayerListener(listener));
}
public void start() {
player.prepare(); player.prepare();
} }
public void release() { public void release() {
if (player != null) { player.release();
player.release();
player = null;
}
} }
private static final class RenderersFactoryImpl implements RenderersFactory { private static final class RenderersFactoryImpl implements RenderersFactory {

View File

@ -16,7 +16,6 @@
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.common.util.Assertions.checkState; import static androidx.media3.common.util.Assertions.checkState;
import static java.lang.annotation.ElementType.TYPE_USE; import static java.lang.annotation.ElementType.TYPE_USE;
@ -49,7 +48,6 @@ import androidx.media3.extractor.DefaultExtractorsFactory;
import androidx.media3.extractor.mp4.Mp4Extractor; import androidx.media3.extractor.mp4.Mp4Extractor;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.errorprone.annotations.CanIgnoreReturnValue; import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.io.File;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@ -566,13 +564,8 @@ public final class Transformer {
private final Looper looper; private final Looper looper;
private final DebugViewProvider debugViewProvider; private final DebugViewProvider debugViewProvider;
private final Clock clock; private final Clock clock;
private final TransformerInternal transformerInternal;
@Nullable private MuxerWrapper muxerWrapper; @Nullable private TransformerInternal transformerInternal;
@Nullable private String outputPath;
@Nullable private ParcelFileDescriptor outputParcelFileDescriptor;
private boolean transformationInProgress;
private boolean isCancelling;
private Transformer( private Transformer(
Context context, Context context,
@ -606,21 +599,6 @@ public final class Transformer {
this.looper = looper; this.looper = looper;
this.debugViewProvider = debugViewProvider; this.debugViewProvider = debugViewProvider;
this.clock = clock; this.clock = clock;
transformerInternal =
new TransformerInternal(
context,
transformationRequest,
audioProcessors,
videoEffects,
removeAudio,
removeVideo,
mediaSourceFactory,
decoderFactory,
encoderFactory,
frameProcessorFactory,
looper,
debugViewProvider,
clock);
} }
/** Returns a {@link Transformer.Builder} initialized with the values of this instance. */ /** Returns a {@link Transformer.Builder} initialized with the values of this instance. */
@ -691,9 +669,7 @@ public final class Transformer {
* @throws IllegalStateException If a transformation is already in progress. * @throws IllegalStateException If a transformation is already in progress.
*/ */
public void startTransformation(MediaItem mediaItem, String path) { public void startTransformation(MediaItem mediaItem, String path) {
this.outputPath = path; startTransformationInternal(mediaItem, path, /* parcelFileDescriptor= */ null);
this.outputParcelFileDescriptor = null;
startTransformationInternal(mediaItem);
} }
/** /**
@ -720,12 +696,13 @@ public final class Transformer {
*/ */
@RequiresApi(26) @RequiresApi(26)
public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor) { public void startTransformation(MediaItem mediaItem, ParcelFileDescriptor parcelFileDescriptor) {
this.outputParcelFileDescriptor = parcelFileDescriptor; startTransformationInternal(mediaItem, /* path= */ null, parcelFileDescriptor);
this.outputPath = null;
startTransformationInternal(mediaItem);
} }
private void startTransformationInternal(MediaItem mediaItem) { private void startTransformationInternal(
MediaItem mediaItem,
@Nullable String path,
@Nullable ParcelFileDescriptor parcelFileDescriptor) {
if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET) if (!mediaItem.clippingConfiguration.equals(MediaItem.ClippingConfiguration.UNSET)
&& transformationRequest.flattenForSlowMotion) { && transformationRequest.flattenForSlowMotion) {
// TODO(b/233986762): Support clipping with SEF flattening. // TODO(b/233986762): Support clipping with SEF flattening.
@ -733,23 +710,34 @@ public final class Transformer {
"Clipping is not supported when slow motion flattening is requested"); "Clipping is not supported when slow motion flattening is requested");
} }
verifyApplicationThread(); verifyApplicationThread();
if (transformationInProgress) { if (transformerInternal != null) {
throw new IllegalStateException("There is already a transformation in progress."); throw new IllegalStateException("There is already a transformation in progress.");
} }
transformationInProgress = true;
TransformerInternalListener transformerInternalListener = TransformerInternalListener transformerInternalListener =
new TransformerInternalListener(mediaItem, looper); new TransformerInternalListener(mediaItem);
MuxerWrapper muxerWrapper =
new MuxerWrapper(
outputPath,
outputParcelFileDescriptor,
muxerFactory,
/* errorConsumer= */ transformerInternalListener::onTransformationError);
this.muxerWrapper = muxerWrapper;
FallbackListener fallbackListener = FallbackListener fallbackListener =
new FallbackListener(mediaItem, listeners, transformationRequest); new FallbackListener(mediaItem, listeners, transformationRequest);
transformerInternal.start( transformerInternal =
mediaItem, muxerWrapper, transformerInternalListener, fallbackListener); new TransformerInternal(
context,
mediaItem,
path,
parcelFileDescriptor,
transformationRequest,
audioProcessors,
videoEffects,
removeAudio,
removeVideo,
mediaSourceFactory,
decoderFactory,
encoderFactory,
frameProcessorFactory,
muxerFactory,
transformerInternalListener,
fallbackListener,
debugViewProvider,
clock);
transformerInternal.start();
} }
/** /**
@ -775,7 +763,9 @@ public final class Transformer {
*/ */
public @ProgressState int getProgress(ProgressHolder progressHolder) { public @ProgressState int getProgress(ProgressHolder progressHolder) {
verifyApplicationThread(); verifyApplicationThread();
return transformerInternal.getProgress(progressHolder); return transformerInternal == null
? PROGRESS_STATE_NO_TRANSFORMATION
: transformerInternal.getProgress(progressHolder);
} }
/** /**
@ -785,36 +775,15 @@ public final class Transformer {
*/ */
public void cancel() { public void cancel() {
verifyApplicationThread(); verifyApplicationThread();
isCancelling = true; if (transformerInternal == null) {
return;
}
try { try {
releaseResources(/* forCancellation= */ true); transformerInternal.release(/* forCancellation= */ true);
} catch (TransformationException impossible) { } catch (TransformationException impossible) {
throw new IllegalStateException(impossible); throw new IllegalStateException(impossible);
} }
isCancelling = false; transformerInternal = null;
}
/**
* Releases the resources.
*
* @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation.
* @throws IllegalStateException If this method is called from the wrong thread.
* @throws TransformationException If the muxer is in the wrong state and {@code forCancellation}
* is false.
*/
private void releaseResources(boolean forCancellation) throws TransformationException {
transformationInProgress = false;
transformerInternal.release();
if (muxerWrapper != null) {
try {
muxerWrapper.release(forCancellation);
} catch (Muxer.MuxerException e) {
throw TransformationException.createForMuxer(
e, TransformationException.ERROR_CODE_MUXING_FAILED);
}
muxerWrapper = null;
}
} }
private void verifyApplicationThread() { private void verifyApplicationThread() {
@ -823,101 +792,41 @@ public final class Transformer {
} }
} }
/**
* Returns the current size in bytes of the current/latest output file, or {@link C#LENGTH_UNSET}
* if unavailable.
*/
private long getCurrentOutputFileCurrentSizeBytes() {
long fileSize = C.LENGTH_UNSET;
if (outputPath != null) {
fileSize = new File(outputPath).length();
} else if (outputParcelFileDescriptor != null) {
fileSize = outputParcelFileDescriptor.getStatSize();
}
if (fileSize <= 0) {
fileSize = C.LENGTH_UNSET;
}
return fileSize;
}
private final class TransformerInternalListener implements TransformerInternal.Listener { private final class TransformerInternalListener implements TransformerInternal.Listener {
private final MediaItem mediaItem; private final MediaItem mediaItem;
private final Handler handler; private final Handler handler;
public TransformerInternalListener(MediaItem mediaItem, Looper looper) { public TransformerInternalListener(MediaItem mediaItem) {
this.mediaItem = mediaItem; this.mediaItem = mediaItem;
handler = new Handler(looper); handler = Util.createHandlerForCurrentLooper();
} }
@Override @Override
public void onTransformationCompleted() { public void onTransformationCompleted(TransformationResult transformationResult) {
handleTransformationEnded(/* exception= */ null); // TODO(b/213341814): Add event flags for Transformer events.
Util.postOrRun(
handler,
() -> {
transformerInternal = null;
listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationCompleted(mediaItem, transformationResult));
listeners.flushEvents();
});
} }
@Override @Override
public void onTransformationError(TransformationException exception) { public void onTransformationError(TransformationException exception) {
if (Looper.myLooper() == looper) { Util.postOrRun(
handleTransformationException(exception); handler,
} else { () -> {
handler.post(() -> handleTransformationException(exception)); transformerInternal = null;
} listeners.queueEvent(
} /* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationError(mediaItem, exception));
private void handleTransformationException(TransformationException transformationException) { listeners.flushEvents();
if (isCancelling) { });
// Resources are already being released.
listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationError(mediaItem, transformationException));
listeners.flushEvents();
} else {
handleTransformationEnded(transformationException);
}
}
private void handleTransformationEnded(@Nullable TransformationException exception) {
MuxerWrapper muxerWrapper = Transformer.this.muxerWrapper;
@Nullable TransformationException resourceReleaseException = null;
try {
releaseResources(/* forCancellation= */ false);
} catch (TransformationException e) {
resourceReleaseException = e;
} catch (RuntimeException e) {
resourceReleaseException = TransformationException.createForUnexpected(e);
}
if (exception == null) {
// We only report the exception caused by releasing the resources if there is no other
// exception. It is more intuitive to call the error callback only once and reporting the
// exception caused by releasing the resources can be confusing if it is a consequence of
// the first exception.
exception = resourceReleaseException;
}
if (exception != null) {
TransformationException finalException = exception;
// TODO(b/213341814): Add event flags for Transformer events.
listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationError(mediaItem, finalException));
} else {
TransformationResult result =
new TransformationResult.Builder()
.setDurationMs(checkNotNull(muxerWrapper).getDurationMs())
.setAverageAudioBitrate(muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_AUDIO))
.setAverageVideoBitrate(muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_VIDEO))
.setVideoFrameCount(muxerWrapper.getTrackSampleCount(C.TRACK_TYPE_VIDEO))
.setFileSizeBytes(getCurrentOutputFileCurrentSizeBytes())
.build();
listeners.queueEvent(
/* eventFlag= */ C.INDEX_UNSET,
listener -> listener.onTransformationCompleted(mediaItem, result));
}
listeners.flushEvents();
} }
} }
} }

View File

@ -16,6 +16,7 @@
package androidx.media3.transformer; package androidx.media3.transformer;
import static androidx.media3.common.util.Assertions.checkNotNull;
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_AVAILABLE; import static androidx.media3.transformer.Transformer.PROGRESS_STATE_AVAILABLE;
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_NO_TRANSFORMATION; import static androidx.media3.transformer.Transformer.PROGRESS_STATE_NO_TRANSFORMATION;
import static androidx.media3.transformer.Transformer.PROGRESS_STATE_UNAVAILABLE; import static androidx.media3.transformer.Transformer.PROGRESS_STATE_UNAVAILABLE;
@ -23,7 +24,8 @@ import static androidx.media3.transformer.Transformer.PROGRESS_STATE_WAITING_FOR
import static java.lang.Math.min; import static java.lang.Math.min;
import android.content.Context; import android.content.Context;
import android.os.Looper; import android.os.Handler;
import android.os.ParcelFileDescriptor;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.media3.common.C; import androidx.media3.common.C;
import androidx.media3.common.DebugViewProvider; import androidx.media3.common.DebugViewProvider;
@ -36,9 +38,11 @@ import androidx.media3.common.MimeTypes;
import androidx.media3.common.PlaybackException; import androidx.media3.common.PlaybackException;
import androidx.media3.common.audio.AudioProcessor; import androidx.media3.common.audio.AudioProcessor;
import androidx.media3.common.util.Clock; import androidx.media3.common.util.Clock;
import androidx.media3.common.util.Util;
import androidx.media3.exoplayer.source.MediaSource; import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.extractor.metadata.mp4.SlowMotionData; import androidx.media3.extractor.metadata.mp4.SlowMotionData;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -46,27 +50,36 @@ import java.util.List;
public interface Listener { public interface Listener {
void onTransformationCompleted(); void onTransformationCompleted(TransformationResult transformationResult);
void onTransformationError(TransformationException exception); void onTransformationError(TransformationException exception);
} }
private final Context context; private final Context context;
@Nullable private final String outputPath;
@Nullable private final ParcelFileDescriptor outputParcelFileDescriptor;
private final TransformationRequest transformationRequest; private final TransformationRequest transformationRequest;
private final ImmutableList<AudioProcessor> audioProcessors; private final ImmutableList<AudioProcessor> audioProcessors;
private final ImmutableList<Effect> videoEffects; private final ImmutableList<Effect> videoEffects;
private final Codec.DecoderFactory decoderFactory; private final Codec.DecoderFactory decoderFactory;
private final Codec.EncoderFactory encoderFactory; private final Codec.EncoderFactory encoderFactory;
private final FrameProcessor.Factory frameProcessorFactory; private final FrameProcessor.Factory frameProcessorFactory;
private final Listener listener;
private final DebugViewProvider debugViewProvider; private final DebugViewProvider debugViewProvider;
private final Handler handler;
private final ExoPlayerAssetLoader exoPlayerAssetLoader; private final ExoPlayerAssetLoader exoPlayerAssetLoader;
private final MuxerWrapper muxerWrapper;
private final List<SamplePipeline> samplePipelines; private final List<SamplePipeline> samplePipelines;
private @Transformer.ProgressState int progressState; private @Transformer.ProgressState int progressState;
private long durationMs; private long durationMs;
private boolean released;
public TransformerInternal( public TransformerInternal(
Context context, Context context,
MediaItem mediaItem,
@Nullable String outputPath,
@Nullable ParcelFileDescriptor outputParcelFileDescriptor,
TransformationRequest transformationRequest, TransformationRequest transformationRequest,
ImmutableList<AudioProcessor> audioProcessors, ImmutableList<AudioProcessor> audioProcessors,
ImmutableList<Effect> videoEffects, ImmutableList<Effect> videoEffects,
@ -76,33 +89,45 @@ import java.util.List;
Codec.DecoderFactory decoderFactory, Codec.DecoderFactory decoderFactory,
Codec.EncoderFactory encoderFactory, Codec.EncoderFactory encoderFactory,
FrameProcessor.Factory frameProcessorFactory, FrameProcessor.Factory frameProcessorFactory,
Looper looper, Muxer.Factory muxerFactory,
Listener listener,
FallbackListener fallbackListener,
DebugViewProvider debugViewProvider, DebugViewProvider debugViewProvider,
Clock clock) { Clock clock) {
this.context = context; this.context = context;
this.outputPath = outputPath;
this.outputParcelFileDescriptor = outputParcelFileDescriptor;
this.transformationRequest = transformationRequest; this.transformationRequest = transformationRequest;
this.audioProcessors = audioProcessors; this.audioProcessors = audioProcessors;
this.videoEffects = videoEffects; this.videoEffects = videoEffects;
this.decoderFactory = decoderFactory; this.decoderFactory = decoderFactory;
this.encoderFactory = encoderFactory; this.encoderFactory = encoderFactory;
this.frameProcessorFactory = frameProcessorFactory; this.frameProcessorFactory = frameProcessorFactory;
this.listener = listener;
this.debugViewProvider = debugViewProvider; this.debugViewProvider = debugViewProvider;
handler = Util.createHandlerForCurrentLooper();
AssetLoaderListener assetLoaderListener = new AssetLoaderListener(mediaItem, fallbackListener);
muxerWrapper =
new MuxerWrapper(
outputPath,
outputParcelFileDescriptor,
muxerFactory,
/* errorConsumer= */ assetLoaderListener::onError);
exoPlayerAssetLoader = exoPlayerAssetLoader =
new ExoPlayerAssetLoader( new ExoPlayerAssetLoader(
context, removeAudio, removeVideo, mediaSourceFactory, looper, clock); context,
mediaItem,
removeAudio,
removeVideo,
mediaSourceFactory,
assetLoaderListener,
clock);
samplePipelines = new ArrayList<>(/* initialCapacity= */ 2); samplePipelines = new ArrayList<>(/* initialCapacity= */ 2);
progressState = PROGRESS_STATE_NO_TRANSFORMATION; progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
} }
public void start( public void start() {
MediaItem mediaItem, exoPlayerAssetLoader.start();
MuxerWrapper muxerWrapper,
Listener listener,
FallbackListener fallbackListener) {
AssetLoaderListener assetLoaderListener =
new AssetLoaderListener(mediaItem, muxerWrapper, listener, fallbackListener);
exoPlayerAssetLoader.start(mediaItem, assetLoaderListener);
progressState = PROGRESS_STATE_WAITING_FOR_AVAILABILITY;
} }
public @Transformer.ProgressState int getProgress(ProgressHolder progressHolder) { public @Transformer.ProgressState int getProgress(ProgressHolder progressHolder) {
@ -113,10 +138,28 @@ import java.util.List;
return progressState; return progressState;
} }
public void release() { /**
* Releases the resources.
*
* @param forCancellation Whether the reason for releasing the resources is the transformation
* cancellation.
* @throws TransformationException If the muxer is in the wrong state and {@code forCancellation}
* is false.
*/
public void release(boolean forCancellation) throws TransformationException {
if (released) {
return;
}
samplePipelines.clear(); samplePipelines.clear();
progressState = PROGRESS_STATE_NO_TRANSFORMATION; progressState = PROGRESS_STATE_NO_TRANSFORMATION;
released = true;
exoPlayerAssetLoader.release(); exoPlayerAssetLoader.release();
try {
muxerWrapper.release(forCancellation);
} catch (Muxer.MuxerException e) {
throw TransformationException.createForMuxer(
e, TransformationException.ERROR_CODE_MUXING_FAILED);
}
} }
private long getCurrentPositionMs() { private long getCurrentPositionMs() {
@ -130,23 +173,35 @@ import java.util.List;
return positionMsSum / samplePipelines.size(); return positionMsSum / samplePipelines.size();
} }
/**
* Returns the current size in bytes of the current/latest output file, or {@link C#LENGTH_UNSET}
* if unavailable.
*/
private long getCurrentOutputFileCurrentSizeBytes() {
long fileSize = C.LENGTH_UNSET;
if (outputPath != null) {
fileSize = new File(outputPath).length();
} else if (outputParcelFileDescriptor != null) {
fileSize = outputParcelFileDescriptor.getStatSize();
}
if (fileSize <= 0) {
fileSize = C.LENGTH_UNSET;
}
return fileSize;
}
private class AssetLoaderListener implements ExoPlayerAssetLoader.Listener { private class AssetLoaderListener implements ExoPlayerAssetLoader.Listener {
private final MediaItem mediaItem; private final MediaItem mediaItem;
private final MuxerWrapper muxerWrapper;
private final TransformerInternal.Listener listener;
private final FallbackListener fallbackListener; private final FallbackListener fallbackListener;
private volatile boolean trackRegistered; private volatile boolean trackRegistered;
public AssetLoaderListener( public AssetLoaderListener(MediaItem mediaItem, FallbackListener fallbackListener) {
MediaItem mediaItem,
MuxerWrapper muxerWrapper,
Listener listener,
FallbackListener fallbackListener) {
this.mediaItem = mediaItem; this.mediaItem = mediaItem;
this.muxerWrapper = muxerWrapper;
this.listener = listener;
this.fallbackListener = fallbackListener; this.fallbackListener = fallbackListener;
} }
@ -197,12 +252,12 @@ import java.util.List;
} else { } else {
transformationException = TransformationException.createForUnexpected(e); transformationException = TransformationException.createForUnexpected(e);
} }
listener.onTransformationError(transformationException); handleTransformationEnded(transformationException);
} }
@Override @Override
public void onEnded() { public void onEnded() {
listener.onTransformationCompleted(); handleTransformationEnded(/* transformationException= */ null);
} }
private SamplePipeline getSamplePipeline( private SamplePipeline getSamplePipeline(
@ -233,7 +288,7 @@ import java.util.List;
encoderFactory, encoderFactory,
muxerWrapper, muxerWrapper,
fallbackListener, fallbackListener,
listener::onTransformationError, this::onError,
debugViewProvider); debugViewProvider);
} else { } else {
return new PassthroughSamplePipeline( return new PassthroughSamplePipeline(
@ -324,5 +379,45 @@ import java.util.List;
} }
return false; return false;
} }
private void handleTransformationEnded(
@Nullable TransformationException transformationException) {
Util.postOrRun(
handler,
() -> {
@Nullable TransformationException releaseException = null;
try {
release(/* forCancellation= */ false);
} catch (TransformationException e) {
releaseException = e;
} catch (RuntimeException e) {
releaseException = TransformationException.createForUnexpected(e);
}
TransformationException exception = transformationException;
if (exception == null) {
// We only report the exception caused by releasing the resources if there is no other
// exception. It is more intuitive to call the error callback only once and reporting
// the exception caused by releasing the resources can be confusing if it is a
// consequence of the first exception.
exception = releaseException;
}
if (exception != null) {
listener.onTransformationError(exception);
} else {
TransformationResult result =
new TransformationResult.Builder()
.setDurationMs(checkNotNull(muxerWrapper).getDurationMs())
.setAverageAudioBitrate(
muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_AUDIO))
.setAverageVideoBitrate(
muxerWrapper.getTrackAverageBitrate(C.TRACK_TYPE_VIDEO))
.setVideoFrameCount(muxerWrapper.getTrackSampleCount(C.TRACK_TYPE_VIDEO))
.setFileSizeBytes(getCurrentOutputFileCurrentSizeBytes())
.build();
listener.onTransformationCompleted(result);
}
});
}
} }
} }

View File

@ -266,7 +266,7 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab
// int arguments (int what, int extra). Since PlaybackException defines a single error // int arguments (int what, int extra). Since PlaybackException defines a single error
// code, we pass 0 as the extra. // code, we pass 0 as the extra.
context.getString( context.getString(
R.string.lb_media_player_error, /* formatArgs= */ error.errorCode, 0)); R.string.lb_media_player_error, /* formatArgs...= */ error.errorCode, 0));
} }
} }