Skip to content

Commit

Permalink
Handle buffers in DefaultAudioSink with AudioProcessingPipeline.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 488412695
  • Loading branch information
Samrobbo authored and microkatz committed Nov 16, 2022
1 parent 095c52e commit 52f3ee8
Show file tree
Hide file tree
Showing 43 changed files with 1,057 additions and 403 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ private static MediaQueue mockMediaQueue(int[] itemIds) {
}

private static MediaInfo getMediaInfo(long durationMs) {
return new MediaInfo.Builder(/*contentId= */ "")
return new MediaInfo.Builder(/* contentId= */ "")
.setStreamDuration(durationMs)
.setContentType(MimeTypes.APPLICATION_MP4)
.setStreamType(MediaInfo.STREAM_TYPE_NONE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ public void run() {
@Test
public void redirectParseAndAttachCookie_dataSourceDoesNotHandleSetCookie_followsRedirect()
throws HttpDataSourceException {
mockSingleRedirectSuccess(/*responseCode=*/ 300);
mockSingleRedirectSuccess(/* responseCode= */ 300);
mockFollowRedirectSuccess();

testResponseHeader.put("Set-Cookie", "testcookie=testcookie; Path=/video");
Expand All @@ -1182,7 +1182,7 @@ public void redirectParseAndAttachCookie_dataSourceDoesNotHandleSetCookie_follow
dataSourceUnderTest.addTransferListener(mockTransferListener);
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);

mockSingleRedirectSuccess(/*responseCode=*/ 300);
mockSingleRedirectSuccess(/* responseCode= */ 300);

testResponseHeader.put("Set-Cookie", "testcookie=testcookie; Path=/video");

Expand Down Expand Up @@ -1210,7 +1210,7 @@ public void redirectParseAndAttachCookie_dataSourceDoesNotHandleSetCookie_follow
dataSourceUnderTest.addTransferListener(mockTransferListener);
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);

mockSingleRedirectSuccess(/*responseCode=*/ 300);
mockSingleRedirectSuccess(/* responseCode= */ 300);
mockReadSuccess(0, 1000);

testResponseHeader.put("Set-Cookie", "testcookie=testcookie; Path=/video");
Expand All @@ -1225,7 +1225,7 @@ public void redirectParseAndAttachCookie_dataSourceDoesNotHandleSetCookie_follow

@Test
public void redirectNoSetCookieFollowsRedirect() throws HttpDataSourceException {
mockSingleRedirectSuccess(/*responseCode=*/ 300);
mockSingleRedirectSuccess(/* responseCode= */ 300);
mockFollowRedirectSuccess();

dataSourceUnderTest.open(testDataSpec);
Expand All @@ -1245,7 +1245,7 @@ public void redirectNoSetCookieFollowsRedirect_dataSourceHandlesSetCookie()
.setHandleSetCookieRequests(true)
.createDataSource();
dataSourceUnderTest.addTransferListener(mockTransferListener);
mockSingleRedirectSuccess(/*responseCode=*/ 300);
mockSingleRedirectSuccess(/* responseCode= */ 300);
mockFollowRedirectSuccess();

dataSourceUnderTest.open(testDataSpec);
Expand All @@ -1255,7 +1255,7 @@ public void redirectNoSetCookieFollowsRedirect_dataSourceHandlesSetCookie()

@Test
public void redirectPostFollowRedirect() throws HttpDataSourceException {
mockSingleRedirectSuccess(/*responseCode=*/ 302);
mockSingleRedirectSuccess(/* responseCode= */ 302);
mockFollowRedirectSuccess();
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);

Expand All @@ -1275,7 +1275,7 @@ public void redirect302ChangesPostToGet() throws HttpDataSourceException {
.setKeepPostFor302Redirects(false)
.setHandleSetCookieRequests(true)
.createDataSource();
mockSingleRedirectSuccess(/*responseCode=*/ 302);
mockSingleRedirectSuccess(/* responseCode= */ 302);
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);
testResponseHeader.put("Set-Cookie", "testcookie=testcookie; Path=/video");

Expand All @@ -1297,7 +1297,7 @@ public void redirectKeeps302Post() throws HttpDataSourceException {
.setResetTimeoutOnRedirects(true)
.setKeepPostFor302Redirects(true)
.createDataSource();
mockSingleRedirectSuccess(/*responseCode=*/ 302);
mockSingleRedirectSuccess(/* responseCode= */ 302);
dataSourceUnderTest.setRequestProperty("Content-Type", TEST_CONTENT_TYPE);

dataSourceUnderTest.open(testPostDataSpec);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ private static AdPlaybackState setVodAdGroupPlaceholders(
adPlaybackState,
/* fromPositionUs= */ fromPositionUs,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ getAdDuration(
/* adDurationsUs= */ getAdDuration(
/* startTimeSeconds= */ cuePoint.getStartTime(),
/* endTimeSeconds= */ cuePoint.getEndTime()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ public static ImmutableMap<Object, AdPlaybackState> splitAdPlaybackStateForPerio
private static AdPlaybackState splitAdGroupForPeriod(
Object adsId, AdGroup adGroup, long periodStartUs, long periodDurationUs) {
AdPlaybackState adPlaybackState =
new AdPlaybackState(checkNotNull(adsId), /* adGroupTimesUs...= */ 0)
new AdPlaybackState(checkNotNull(adsId), /* adGroupTimesUs= */ 0)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, periodDurationUs)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true)
Expand Down Expand Up @@ -605,7 +605,7 @@ public static AdPlaybackState addLiveAdBreak(
adPlaybackState,
/* fromPositionUs= */ currentContentPeriodPositionUs,
/* contentResumeOffsetUs= */ sum(adDurationsUs),
/* adDurationsUs...= */ adDurationsUs);
/* adDurationsUs= */ adDurationsUs);
adGroupIndex =
adPlaybackState.getAdGroupIndexForPositionUs(
mediaPeriodPositionUs, /* periodDurationUs= */ C.TIME_UNSET);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public void start_updatesAdPlaybackState() {

assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US));
}

Expand Down Expand Up @@ -312,7 +312,7 @@ public void playback_withPrerollAd_marksAdAsPlayed() {
// Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI)
Expand All @@ -336,7 +336,7 @@ public void playback_withMidrollFetchError_marksAdAsInErrorState() {

assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 20_500_000)
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 20_500_000)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdDurationsUs(new long[][] {{TEST_AD_DURATION_US}})
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
Expand Down Expand Up @@ -384,7 +384,7 @@ public void playback_withPostrollFetchError_marksAdAsInErrorState() {

assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.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)
.withAdDurationsUs(new long[][] {{TEST_AD_DURATION_US}})
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
Expand Down Expand Up @@ -1114,7 +1114,7 @@ public void playbackWithTwoAdsMediaSources_preloadsSecondAdTag() {
// Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI)
Expand All @@ -1123,7 +1123,7 @@ public void playbackWithTwoAdsMediaSources_preloadsSecondAdTag() {
.withAdResumePositionUs(/* adResumePositionUs= */ 0));
// Verify that the second source's ad cue points have preloaded.
assertThat(getAdPlaybackState(/* periodIndex= */ 1))
.isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs...= */ 0));
.isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs= */ 0));
}

@Test
Expand Down Expand Up @@ -1181,7 +1181,7 @@ public void playbackWithTwoAdsMediaSources_preloadsSecondAdTagWithBackgroundResu
// Verify that the preroll ad has been marked as played.
assertThat(getAdPlaybackState(/* periodIndex= */ 0))
.isEqualTo(
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs...= */ 0)
new AdPlaybackState(TEST_ADS_ID, /* adGroupTimesUs= */ 0)
.withContentDurationUs(CONTENT_PERIOD_DURATION_US)
.withAdCount(/* adGroupIndex= */ 0, /* adCount= */ 1)
.withAvailableAdUri(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0, TEST_URI)
Expand All @@ -1190,7 +1190,7 @@ public void playbackWithTwoAdsMediaSources_preloadsSecondAdTagWithBackgroundResu
.withAdResumePositionUs(/* adResumePositionUs= */ 0));
// Verify that the second source's ad cue points have preloaded.
assertThat(getAdPlaybackState(/* periodIndex= */ 1))
.isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs...= */ 0));
.isEqualTo(new AdPlaybackState(secondAdsId, /* adGroupTimesUs= */ 0));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,28 @@ public void adsLoaderStateToBundle_marshallAndUnmarshalling_resultIsEqual() {
new AdPlaybackState("adsId1"),
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 10,
/* adDurationsUs...= */ 5_000_000,
/* adDurationsUs= */ 5_000_000,
10_000_000,
20_000_000);
AdPlaybackState secondAdPlaybackState =
ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(
new AdPlaybackState("adsId2"),
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 10,
/* adDurationsUs...= */ 10_000_000)
/* adDurationsUs= */ 10_000_000)
.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0);
AdPlaybackState thirdAdPlaybackState =
ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(
new AdPlaybackState("adsId3"),
/* fromPositionUs= */ C.TIME_END_OF_SOURCE,
/* contentResumeOffsetUs= */ 10,
/* adDurationsUs...= */ 10_000_000);
/* adDurationsUs= */ 10_000_000);
thirdAdPlaybackState =
ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(
thirdAdPlaybackState,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 10,
/* adDurationsUs...= */ 10_000_000)
/* adDurationsUs= */ 10_000_000)
.withRemovedAdGroupCount(1);
State state =
new State(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public void splitAdPlaybackStateForPeriods_correctAdPlaybackStates() {
new AdPlaybackState(/* adsId= */ "adsId", 0)
.withAdCount(/* adGroupIndex= */ 0, periodCount)
.withAdDurationsUs(
/* adGroupIndex= */ 0, /* adDurationsUs...= */
/* adGroupIndex= */ 0, /* adDurationsUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs,
periodDurationUs,
periodDurationUs,
Expand Down Expand Up @@ -475,12 +475,10 @@ public void splitAdPlaybackStateForPeriods_singleAdOfAdGroupSpansMultiplePeriods
.withAdCount(/* adGroupIndex= */ 1, 1)
.withAdCount(/* adGroupIndex= */ 2, 1)
.withAdDurationsUs(
/* adGroupIndex= */ 0, /* adDurationsUs...= */
/* adGroupIndex= */ 0, /* adDurationsUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + (2 * periodDurationUs))
.withAdDurationsUs(
/* adGroupIndex= */ 1, /* adDurationsUs...= */ (2 * periodDurationUs))
.withAdDurationsUs(
/* adGroupIndex= */ 2, /* adDurationsUs...= */ (2 * periodDurationUs))
.withAdDurationsUs(/* adGroupIndex= */ 1, /* adDurationsUs= */ (2 * periodDurationUs))
.withAdDurationsUs(/* adGroupIndex= */ 2, /* adDurationsUs= */ (2 * periodDurationUs))
.withPlayedAd(/* adGroupIndex= */ 0, /* adIndexInAdGroup= */ 0)
.withPlayedAd(/* adGroupIndex= */ 1, /* adIndexInAdGroup= */ 0)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true)
Expand Down Expand Up @@ -522,7 +520,7 @@ public void splitAdPlaybackStateForPeriods_lateMidrollAdGroupStartTimeUs_adGroup
// around removed.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US + periodDurationUs + 2)
.withAdCount(/* adGroupIndex= */ 0, 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs...= */ periodDurationUs)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs= */ periodDurationUs)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true);
FakeTimeline timeline =
new FakeTimeline(
Expand All @@ -545,7 +543,7 @@ public void splitAdPlaybackStateForPeriods_earlyMidrollAdGroupStartTimeUs_adGrou
AdPlaybackState adPlaybackState =
new AdPlaybackState(/* adsId= */ "adsId", periodDurationUs - 1)
.withAdCount(/* adGroupIndex= */ 0, 1)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs...= */ periodDurationUs)
.withAdDurationsUs(/* adGroupIndex= */ 0, /* adDurationsUs= */ periodDurationUs)
.withIsServerSideInserted(/* adGroupIndex= */ 0, true);
FakeTimeline timeline =
new FakeTimeline(
Expand All @@ -569,7 +567,7 @@ public void expandAdGroupPlaceHolder_expandWithFirstAdInGroup_correctExpansion()
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 30_000_000);
/* adDurationsUs= */ 30_000_000);

adPlaybackState =
ImaUtil.expandAdGroupPlaceholder(
Expand All @@ -594,7 +592,7 @@ public void expandAdGroupPlaceHolder_expandWithMiddleAdInGroup_correctExpansion(
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 30_000_000);
/* adDurationsUs= */ 30_000_000);

adPlaybackState =
ImaUtil.expandAdGroupPlaceholder(
Expand All @@ -619,7 +617,7 @@ public void expandAdGroupPlaceHolder_expandWithLastAdInGroup_correctDurationWrap
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 30_000_000);
/* adDurationsUs= */ 30_000_000);

adPlaybackState =
ImaUtil.expandAdGroupPlaceholder(
Expand All @@ -644,7 +642,7 @@ public void expandAdGroupPlaceHolder_expandSingleAdInAdGroup_noExpansionCorrectD
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 30_000_000);
/* adDurationsUs= */ 30_000_000);

adPlaybackState =
ImaUtil.expandAdGroupPlaceholder(
Expand All @@ -667,7 +665,7 @@ public void expandAdGroupPlaceHolder_singleAdInAdGroupOverLength_correctsAdDurat
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 10_000_001);
/* adDurationsUs= */ 10_000_001);

adPlaybackState =
ImaUtil.expandAdGroupPlaceholder(
Expand All @@ -690,7 +688,7 @@ public void expandAdGroupPlaceHolder_initialDurationTooLarge_overriddenWhenExpan
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 30_000_000);
/* adDurationsUs= */ 30_000_000);

adPlaybackState =
ImaUtil.expandAdGroupPlaceholder(
Expand All @@ -714,7 +712,7 @@ public void insertAdDurationInAdGroup_correctDurationAndPropagation() {
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 10_000_000,
/* adDurationsUs= */ 10_000_000,
20_000_000,
0);

Expand All @@ -739,7 +737,7 @@ public void insertAdDurationInAdGroup_insertLast_correctDurationAndPropagation()
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 0,
/* adDurationsUs= */ 0,
10_000_000,
20_000_000);

Expand All @@ -764,7 +762,7 @@ public void insertAdDurationInAdGroup_allDurationsSetAlready_setDurationNoPropag
AdPlaybackState.NONE,
/* fromPositionUs= */ 0,
/* contentResumeOffsetUs= */ 0,
/* adDurationsUs...= */ 5_000_000,
/* adDurationsUs= */ 5_000_000,
10_000_000,
20_000_000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public void onPlayerError(PlaybackException error) {
// int arguments (int what, int extra). Since PlaybackException defines a single error
// code, we pass 0 as the extra.
context.getString(
R.string.lb_media_player_error, /* formatArgs...= */ error.errorCode, 0));
R.string.lb_media_player_error, /* formatArgs= */ error.errorCode, 0));
}
}

Expand Down

0 comments on commit 52f3ee8

Please sign in to comment.