Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
ea7e8cff
authored
Nov 16, 2022
by
kimvde
Committed by
microkatz
Nov 21, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Refactor transformation completion
PiperOrigin-RevId: 488929446
parent
f2a63e9d
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
400 additions
and
387 deletions
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaServerSideAdInsertionMediaSource.java
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaUtil.java
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoaderTest.java
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaServerSideAdInsertionMediaSourceTest.java
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaUtilTest.java
extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java
library/common/src/test/java/com/google/android/exoplayer2/source/ads/AdPlaybackStateTest.java
library/common/src/test/java/com/google/android/exoplayer2/util/FlagSetTest.java
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
library/core/src/test/java/com/google/android/exoplayer2/MediaPeriodQueueTest.java
library/core/src/test/java/com/google/android/exoplayer2/analytics/DefaultAnalyticsCollectorTest.java
library/core/src/test/java/com/google/android/exoplayer2/audio/SilenceSkippingAudioProcessorTest.java
library/core/src/test/java/com/google/android/exoplayer2/source/ads/AdsMediaSourceTest.java
library/core/src/test/java/com/google/android/exoplayer2/source/ads/ServerSideAdInsertionMediaSourceTest.java
library/core/src/test/java/com/google/android/exoplayer2/source/ads/ServerSideAdInsertionUtilTest.java
library/core/src/test/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelectionTest.java
library/core/src/test/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelectorTest.java
library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaPeriod.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoader.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelector.java
testutils/src/test/java/com/google/android/exoplayer2/testutil/FakeTimelineTest.java
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaServerSideAdInsertionMediaSource.java
View file @
ea7e8cff
...
...
@@ -680,7 +680,7 @@ public final class ImaServerSideAdInsertionMediaSource extends CompositeMediaSou
adPlaybackState
,
/* fromPositionUs= */
fromPositionUs
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
getAdDuration
(
/* adDurationsUs
...
= */
getAdDuration
(
/* startTimeSeconds= */
cuePoint
.
getStartTime
(),
/* endTimeSeconds= */
cuePoint
.
getEndTime
()));
}
...
...
extensions/ima/src/main/java/com/google/android/exoplayer2/ext/ima/ImaUtil.java
View file @
ea7e8cff
...
...
@@ -443,7 +443,7 @@ import java.util.Set;
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
)
...
...
@@ -605,7 +605,7 @@ import java.util.Set;
adPlaybackState
,
/* fromPositionUs= */
currentContentPeriodPositionUs
,
/* contentResumeOffsetUs= */
sum
(
adDurationsUs
),
/* adDurationsUs= */
adDurationsUs
);
/* adDurationsUs
...
= */
adDurationsUs
);
adGroupIndex
=
adPlaybackState
.
getAdGroupIndexForPositionUs
(
mediaPeriodPositionUs
,
/* periodDurationUs= */
C
.
TIME_UNSET
);
...
...
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaAdsLoaderTest.java
View file @
ea7e8cff
...
...
@@ -239,7 +239,7 @@ public final class ImaAdsLoaderTest {
assertThat
(
getAdPlaybackState
(
/* periodIndex= */
0
))
.
isEqualTo
(
new
AdPlaybackState
(
TEST_ADS_ID
,
/* adGroupTimesUs= */
0
)
new
AdPlaybackState
(
TEST_ADS_ID
,
/* adGroupTimesUs
...
= */
0
)
.
withContentDurationUs
(
CONTENT_PERIOD_DURATION_US
));
}
...
...
@@ -312,7 +312,7 @@ public final class ImaAdsLoaderTest {
// 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
)
...
...
@@ -336,7 +336,7 @@ public final class ImaAdsLoaderTest {
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
)
...
...
@@ -384,7 +384,7 @@ public final class ImaAdsLoaderTest {
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
)
...
...
@@ -1114,7 +1114,7 @@ public final class ImaAdsLoaderTest {
// 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
)
...
...
@@ -1123,7 +1123,7 @@ public final class ImaAdsLoaderTest {
.
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
...
...
@@ -1181,7 +1181,7 @@ public final class ImaAdsLoaderTest {
// 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
)
...
...
@@ -1190,7 +1190,7 @@ public final class ImaAdsLoaderTest {
.
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
...
...
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaServerSideAdInsertionMediaSourceTest.java
View file @
ea7e8cff
...
...
@@ -37,7 +37,7 @@ public class ImaServerSideAdInsertionMediaSourceTest {
new
AdPlaybackState
(
"adsId1"
),
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
10
,
/* adDurationsUs= */
5_000_000
,
/* adDurationsUs
...
= */
5_000_000
,
10_000_000
,
20_000_000
);
AdPlaybackState
secondAdPlaybackState
=
...
...
@@ -45,20 +45,20 @@ public class ImaServerSideAdInsertionMediaSourceTest {
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
(
...
...
extensions/ima/src/test/java/com/google/android/exoplayer2/ext/ima/ImaUtilTest.java
View file @
ea7e8cff
...
...
@@ -435,7 +435,7 @@ public class ImaUtilTest {
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
,
...
...
@@ -475,10 +475,12 @@ public class ImaUtilTest {
.
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
)
...
...
@@ -520,7 +522,7 @@ public class ImaUtilTest {
// 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
(
...
...
@@ -543,7 +545,7 @@ public class ImaUtilTest {
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
(
...
...
@@ -567,7 +569,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
30_000_000
);
/* adDurationsUs
...
= */
30_000_000
);
adPlaybackState
=
ImaUtil
.
expandAdGroupPlaceholder
(
...
...
@@ -592,7 +594,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
30_000_000
);
/* adDurationsUs
...
= */
30_000_000
);
adPlaybackState
=
ImaUtil
.
expandAdGroupPlaceholder
(
...
...
@@ -617,7 +619,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
30_000_000
);
/* adDurationsUs
...
= */
30_000_000
);
adPlaybackState
=
ImaUtil
.
expandAdGroupPlaceholder
(
...
...
@@ -642,7 +644,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
30_000_000
);
/* adDurationsUs
...
= */
30_000_000
);
adPlaybackState
=
ImaUtil
.
expandAdGroupPlaceholder
(
...
...
@@ -665,7 +667,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
10_000_001
);
/* adDurationsUs
...
= */
10_000_001
);
adPlaybackState
=
ImaUtil
.
expandAdGroupPlaceholder
(
...
...
@@ -688,7 +690,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
30_000_000
);
/* adDurationsUs
...
= */
30_000_000
);
adPlaybackState
=
ImaUtil
.
expandAdGroupPlaceholder
(
...
...
@@ -712,7 +714,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
10_000_000
,
/* adDurationsUs
...
= */
10_000_000
,
20_000_000
,
0
);
...
...
@@ -737,7 +739,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
0
,
/* adDurationsUs
...
= */
0
,
10_000_000
,
20_000_000
);
...
...
@@ -762,7 +764,7 @@ public class ImaUtilTest {
AdPlaybackState
.
NONE
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
5_000_000
,
/* adDurationsUs
...
= */
5_000_000
,
10_000_000
,
20_000_000
);
...
...
extensions/leanback/src/main/java/com/google/android/exoplayer2/ext/leanback/LeanbackPlayerAdapter.java
View file @
ea7e8cff
...
...
@@ -264,7 +264,7 @@ public final class LeanbackPlayerAdapter extends PlayerAdapter implements Runnab
// 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
));
}
}
...
...
library/common/src/test/java/com/google/android/exoplayer2/source/ads/AdPlaybackStateTest.java
View file @
ea7e8cff
...
...
@@ -81,7 +81,7 @@ public class AdPlaybackStateTest {
@Test
public
void
withAdGroupTimeUs_updatesAdGroupTimeUs
()
{
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
);
state
=
...
...
@@ -97,7 +97,7 @@ public class AdPlaybackStateTest {
@Test
public
void
withNewAdGroup_addsGroupAndKeepsExistingGroups
()
{
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
)
.
withAdCount
(
/* adGroupIndex= */
1
,
/* adCount= */
2
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
1
)
...
...
@@ -123,12 +123,12 @@ public class AdPlaybackStateTest {
@Test
public
void
withAdDurationsUs_updatesAdDurations
()
{
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= */
1
,
/* adCount= */
2
)
.
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
[
1
]).
isEqualTo
(
6_000
);
...
...
@@ -315,7 +315,7 @@ public class AdPlaybackStateTest {
@Test
public
void
withOriginalAdCount
()
{
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
);
state
=
state
.
withOriginalAdCount
(
/* adGroupIndex= */
0
,
/* originalAdCount= */
3
);
...
...
@@ -327,7 +327,7 @@ public class AdPlaybackStateTest {
@Test
public
void
withOriginalAdCount_unsetValue_defaultsToIndexUnset
()
{
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
);
assertThat
(
state
.
getAdGroup
(
0
).
count
).
isEqualTo
(
2
);
...
...
@@ -336,7 +336,7 @@ public class AdPlaybackStateTest {
@Test
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
.
withAdCount
(
/* adGroupIndex= */
0
,
3
)
...
...
@@ -363,7 +363,7 @@ public class AdPlaybackStateTest {
state
=
state
.
withAdCount
(
/* adGroupIndex= */
1
,
/* adCount= */
5
);
state
=
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= */
2
,
TEST_URI
);
state
=
state
.
withAvailableAdUri
(
/* adGroupIndex= */
1
,
/* adIndexInAdGroup= */
3
,
TEST_URI
);
...
...
@@ -419,8 +419,8 @@ public class AdPlaybackStateTest {
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
3333
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
1
,
/* isServerSideInserted= */
true
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
2
,
/* isServerSideInserted= */
true
)
.
withAdDurationsUs
(
/* adGroupIndex= */
1
,
/* adDurationsUs= */
12
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
34
,
56
)
.
withAdDurationsUs
(
/* adGroupIndex= */
1
,
/* adDurationsUs
...
= */
12
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
34
,
56
)
.
withAdResumePositionUs
(
123
)
.
withContentDurationUs
(
456
);
...
...
@@ -457,7 +457,7 @@ public class AdPlaybackStateTest {
AdPlaybackState
state
=
new
AdPlaybackState
(
/* adsId= */
new
Object
(),
/* adGroupTimesUs= */
0
,
/* adGroupTimesUs
...
= */
0
,
1000
,
2000
,
3000
,
...
...
@@ -540,7 +540,7 @@ public class AdPlaybackStateTest {
@Test
public
void
getAdGroupIndexAfterPositionUs_withServerSideInsertedAds_returnsNextAdGroup
()
{
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= */
1
,
/* isServerSideInserted= */
true
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
2
,
/* isServerSideInserted= */
true
)
...
...
library/common/src/test/java/com/google/android/exoplayer2/util/FlagSetTest.java
View file @
ea7e8cff
...
...
@@ -80,7 +80,7 @@ public final class FlagSetTest {
public
void
containsAny_withoutAdd_returnsFalseForAllValues
()
{
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
...
...
@@ -95,9 +95,9 @@ public final class FlagSetTest {
assertThat
(
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
();
assertThat
(
flags
.
containsAny
(
/* flags= */
-
1235
,
1
,
Integer
.
MAX_VALUE
-
1
)).
isFalse
();
assertThat
(
flags
.
containsAny
(
/* flags
...
= */
-
1235
,
1
,
Integer
.
MAX_VALUE
-
1
)).
isFalse
();
}
@Test
...
...
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
View file @
ea7e8cff
...
...
@@ -746,7 +746,7 @@ public final class ExoPlayerTest {
public
void
adGroupWithLoadError_noFurtherAdGroup_isSkipped
()
throws
Exception
{
AdPlaybackState
initialAdPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs
...
= */
TimelineWindowDefinition
.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+
5
*
C
.
MICROS_PER_SECOND
);
Timeline
fakeTimeline
=
...
...
@@ -799,7 +799,7 @@ public final class ExoPlayerTest {
public
void
adGroupWithLoadError_withFurtherAdGroup_isSkipped
()
throws
Exception
{
AdPlaybackState
initialAdPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs
...
= */
TimelineWindowDefinition
.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+
5
*
C
.
MICROS_PER_SECOND
,
TimelineWindowDefinition
.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
...
...
@@ -2928,7 +2928,8 @@ public final class ExoPlayerTest {
AdPlaybackState
adPlaybackStateWithMidroll
=
FakeTimeline
.
createAdPlaybackState
(
/* 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
);
Timeline
timeline2
=
new
FakeTimeline
(
...
...
@@ -2979,7 +2980,8 @@ public final class ExoPlayerTest {
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
TimelineWindowDefinition
.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
/* adGroupTimesUs...= */
TimelineWindowDefinition
.
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+
Util
.
msToUs
(
adGroupWindowTimeMs
));
Timeline
timeline
=
new
FakeTimeline
(
...
...
@@ -3612,7 +3614,7 @@ public final class ExoPlayerTest {
@Test
public
void
contentWithInitialSeekPositionAfterPrerollAdStartsAtSeekPosition
()
throws
Exception
{
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
3
,
/* adGroupTimesUs= */
0
);
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
3
,
/* adGroupTimesUs
...
= */
0
);
Timeline
fakeTimeline
=
new
FakeTimeline
(
new
TimelineWindowDefinition
(
...
...
@@ -3661,7 +3663,7 @@ public final class ExoPlayerTest {
@Test
public
void
contentWithoutInitialSeekStartsAtDefaultPositionAfterPrerollAd
()
throws
Exception
{
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
3
,
/* adGroupTimesUs= */
0
);
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
3
,
/* adGroupTimesUs
...
= */
0
);
Timeline
fakeTimeline
=
new
FakeTimeline
(
new
TimelineWindowDefinition
(
...
...
@@ -3715,7 +3717,7 @@ public final class ExoPlayerTest {
ExoPlayer
player
=
new
TestExoPlayerBuilder
(
context
).
build
();
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
42_000_004_000_000L
);
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs
...
= */
42_000_004_000_000L
);
Timeline
liveTimeline1
=
new
FakeTimeline
(
new
TimelineWindowDefinition
(
...
...
@@ -4720,7 +4722,7 @@ public final class ExoPlayerTest {
long
contentDurationMs
=
10_000
;
long
adDurationMs
=
100_000
;
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
.
withAvailableAdUri
(
...
...
@@ -4822,7 +4824,7 @@ public final class ExoPlayerTest {
long
contentDurationMs
=
10_000
;
long
adDurationMs
=
4_000
;
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
.
withAvailableAdUri
(
...
...
@@ -4905,7 +4907,7 @@ public final class ExoPlayerTest {
long
contentDurationMs
=
10_000
;
long
adDurationMs
=
4_000
;
AdPlaybackState
adPlaybackState
=
new
AdPlaybackState
(
/* adsId= */
new
Object
(),
/* adGroupTimesUs= */
0
)
new
AdPlaybackState
(
/* adsId= */
new
Object
(),
/* adGroupTimesUs
...
= */
0
)
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
1
)
.
withAvailableAdUri
(
/* adGroupIndex= */
0
,
...
...
@@ -4950,7 +4952,7 @@ public final class ExoPlayerTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
"windowId"
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
true
,
true
,
false
);
...
...
@@ -5041,7 +5043,7 @@ public final class ExoPlayerTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
"windowId"
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
true
,
false
,
false
);
...
...
@@ -5103,7 +5105,7 @@ public final class ExoPlayerTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
"windowId"
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
true
,
true
,
false
);
...
...
@@ -5170,7 +5172,7 @@ public final class ExoPlayerTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
"windowId"
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
true
,
true
,
false
);
...
...
@@ -5251,7 +5253,7 @@ public final class ExoPlayerTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
"windowId"
,
/* numberOfPlayedAds= */
2
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
true
,
true
,
false
);
...
...
@@ -5306,7 +5308,7 @@ public final class ExoPlayerTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
"windowId"
,
/* numberOfPlayedAds= */
Integer
.
MAX_VALUE
,
/* isAdPeriodFlags= */
true
,
/* isAdPeriodFlags
...
= */
true
,
false
,
true
,
true
,
...
...
@@ -5374,28 +5376,28 @@ public final class ExoPlayerTest {
new
AdPlaybackState
(
"adsId"
),
/* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
C
.
MICROS_PER_SECOND
);
/* adDurationsUs
...
= */
C
.
MICROS_PER_SECOND
);
adPlaybackState
=
addAdGroupToAdPlaybackState
(
adPlaybackState
,
/* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+
(
3
*
C
.
MICROS_PER_SECOND
),
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
C
.
MICROS_PER_SECOND
);
/* adDurationsUs
...
= */
C
.
MICROS_PER_SECOND
);
adPlaybackState
=
addAdGroupToAdPlaybackState
(
adPlaybackState
,
/* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+
(
5
*
C
.
MICROS_PER_SECOND
),
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
C
.
MICROS_PER_SECOND
);
/* adDurationsUs
...
= */
C
.
MICROS_PER_SECOND
);
adPlaybackState
=
addAdGroupToAdPlaybackState
(
adPlaybackState
,
/* fromPositionUs= */
DEFAULT_WINDOW_OFFSET_IN_FIRST_PERIOD_US
+
(
9
*
C
.
MICROS_PER_SECOND
),
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
C
.
MICROS_PER_SECOND
);
/* adDurationsUs
...
= */
C
.
MICROS_PER_SECOND
);
adPlaybackState
=
adPlaybackState
.
withPlayedAd
(
/* adGroupIndex= */
0
,
/* adIndexInAdGroup+ */
0
);
adPlaybackState
=
...
...
@@ -5641,7 +5643,7 @@ public final class ExoPlayerTest {
@Test
public
void
shortAdFollowedByUnpreparedAd_playbackDoesNotGetStuck
()
throws
Exception
{
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
2
,
/* adGroupTimesUs= */
0
);
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
2
,
/* adGroupTimesUs
...
= */
0
);
long
shortAdDurationMs
=
1_000
;
adPlaybackState
=
adPlaybackState
.
withAdDurationsUs
(
new
long
[][]
{{
shortAdDurationMs
,
shortAdDurationMs
}});
...
...
@@ -9053,7 +9055,7 @@ public final class ExoPlayerTest {
@Test
public
void
isCommandAvailable_duringAd_isFalseForSeekCommands
()
throws
Exception
{
AdPlaybackState
adPlaybackState
=
new
AdPlaybackState
(
/* adsId= */
new
Object
(),
/* adGroupTimesUs= */
0
)
new
AdPlaybackState
(
/* adsId= */
new
Object
(),
/* adGroupTimesUs
...
= */
0
)
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
1
)
.
withAvailableAdUri
(
/* adGroupIndex= */
0
,
...
...
@@ -10024,7 +10026,7 @@ public final class ExoPlayerTest {
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
0
,
/* adGroupTimesUs
...
= */
0
,
7
*
C
.
MICROS_PER_SECOND
,
C
.
TIME_END_OF_SOURCE
);
TimelineWindowDefinition
adTimelineDefinition
=
...
...
@@ -10613,7 +10615,7 @@ public final class ExoPlayerTest {
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
2
,
/* adGroupTimesUs= */
0
,
/* adGroupTimesUs
...
= */
0
,
7
*
C
.
MICROS_PER_SECOND
,
C
.
TIME_END_OF_SOURCE
);
TimelineWindowDefinition
adTimeline
=
...
...
@@ -10750,7 +10752,7 @@ public final class ExoPlayerTest {
player
.
addListener
(
listener
);
AdPlaybackState
adPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
2
*
C
.
MICROS_PER_SECOND
);
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs
...
= */
2
*
C
.
MICROS_PER_SECOND
);
TimelineWindowDefinition
adTimeline
=
new
TimelineWindowDefinition
(
/* periodCount= */
1
,
...
...
@@ -10839,7 +10841,7 @@ public final class ExoPlayerTest {
player
.
addListener
(
listener
);
AdPlaybackState
postRollAdPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
C
.
TIME_END_OF_SOURCE
);
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs
...
= */
C
.
TIME_END_OF_SOURCE
);
TimelineWindowDefinition
postRollWindow
=
new
TimelineWindowDefinition
(
/* periodCount= */
1
,
...
...
@@ -10853,7 +10855,7 @@ public final class ExoPlayerTest {
/* windowOffsetInFirstPeriodUs= */
0
,
postRollAdPlaybackState
);
AdPlaybackState
preRollAdPlaybackState
=
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
0
);
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs
...
= */
0
);
TimelineWindowDefinition
preRollWindow
=
new
TimelineWindowDefinition
(
/* periodCount= */
1
,
...
...
@@ -11891,7 +11893,8 @@ public final class ExoPlayerTest {
.
build
();
// Live stream timeline with unassigned next ad group.
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
)
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
1
)
.
withAdDurationsUs
(
new
long
[][]
{
new
long
[]
{
10
*
C
.
MICROS_PER_SECOND
}});
...
...
library/core/src/test/java/com/google/android/exoplayer2/MediaPeriodQueueTest.java
View file @
ea7e8cff
...
...
@@ -121,7 +121,7 @@ public final class MediaPeriodQueueTest {
@Test
public
void
getNextMediaPeriodInfo_withPrerollAd_returnsCorrectMediaPeriodInfos
()
{
setupAdTimeline
(
/* adGroupTimesUs= */
0
);
setupAdTimeline
(
/* adGroupTimesUs
...
= */
0
);
setAdGroupLoaded
(
/* adGroupIndex= */
0
);
assertNextMediaPeriodInfoIsAd
(
/* adGroupIndex= */
0
,
...
...
@@ -143,7 +143,7 @@ public final class MediaPeriodQueueTest {
@Test
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
(
/* periodUid= */
firstPeriodUid
,
/* startPositionUs= */
0
,
...
...
@@ -199,7 +199,7 @@ public final class MediaPeriodQueueTest {
@Test
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
(
/* periodUid= */
firstPeriodUid
,
/* startPositionUs= */
0
,
...
...
@@ -253,7 +253,7 @@ public final class MediaPeriodQueueTest {
adPlaybackState
=
new
AdPlaybackState
(
/* adsId= */
new
Object
(),
/* adGroupTimesUs= */
0
,
/* adGroupTimesUs
...
= */
0
,
FIRST_AD_START_TIME_US
,
C
.
TIME_END_OF_SOURCE
)
.
withContentDurationUs
(
CONTENT_DURATION_US
)
...
...
@@ -324,7 +324,7 @@ public final class MediaPeriodQueueTest {
adPlaybackState
=
new
AdPlaybackState
(
/* adsId= */
new
Object
(),
/* adGroupTimesUs= */
0
,
/* adGroupTimesUs
...
= */
0
,
FIRST_AD_START_TIME_US
,
SECOND_AD_START_TIME_US
)
.
withContentDurationUs
(
CONTENT_DURATION_US
)
...
...
@@ -392,7 +392,7 @@ public final class MediaPeriodQueueTest {
@Test
public
void
getNextMediaPeriodInfo_withPostrollLoadError_returnsEmptyFinalMediaPeriodInfo
()
{
setupAdTimeline
(
/* adGroupTimesUs= */
C
.
TIME_END_OF_SOURCE
);
setupAdTimeline
(
/* adGroupTimesUs
...
= */
C
.
TIME_END_OF_SOURCE
);
assertGetNextMediaPeriodInfoReturnsContentMediaPeriod
(
/* periodUid= */
firstPeriodUid
,
/* startPositionUs= */
0
,
...
...
@@ -419,7 +419,7 @@ public final class MediaPeriodQueueTest {
@Test
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= */
1
);
setAdGroupLoaded
(
/* adGroupIndex= */
2
);
...
...
@@ -503,14 +503,14 @@ public final class MediaPeriodQueueTest {
@Test
public
void
updateQueuedPeriods_withDurationChangeInPlayingContent_handlesChangeAndRemovesPeriodsAfterChangedPeriod
()
{
setupAdTimeline
(
/* adGroupTimesUs= */
FIRST_AD_START_TIME_US
);
setupAdTimeline
(
/* adGroupTimesUs
...
= */
FIRST_AD_START_TIME_US
);
setAdGroupLoaded
(
/* adGroupIndex= */
0
);
enqueueNext
();
// Content before ad.
enqueueNext
();
// Ad.
enqueueNext
();
// Content after 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
);
long
maxRendererReadPositionUs
=
MediaPeriodQueue
.
INITIAL_RENDERER_POSITION_OFFSET_US
+
FIRST_AD_START_TIME_US
-
3000
;
...
...
@@ -531,14 +531,14 @@ public final class MediaPeriodQueueTest {
@Test
public
void
updateQueuedPeriods_withDurationChangeInPlayingContentAfterReadingPosition_doesntHandleChangeAndRemovesPeriodsAfterChangedPeriod
()
{
setupAdTimeline
(
/* adGroupTimesUs= */
FIRST_AD_START_TIME_US
);
setupAdTimeline
(
/* adGroupTimesUs
...
= */
FIRST_AD_START_TIME_US
);
setAdGroupLoaded
(
/* adGroupIndex= */
0
);
enqueueNext
();
// Content before ad.
enqueueNext
();
// Ad.
enqueueNext
();
// Content after 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
);
long
maxRendererReadPositionUs
=
MediaPeriodQueue
.
INITIAL_RENDERER_POSITION_OFFSET_US
+
FIRST_AD_START_TIME_US
-
1000
;
...
...
@@ -573,7 +573,7 @@ public final class MediaPeriodQueueTest {
// Change position of first ad (= change duration of playing content before first ad).
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
);
updateTimeline
();
setAdGroupLoaded
(
/* adGroupIndex= */
0
);
...
...
@@ -596,7 +596,7 @@ public final class MediaPeriodQueueTest {
@Test
public
void
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= */
1
);
enqueueNext
();
// Content before first ad.
...
...
@@ -606,7 +606,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads).
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= */
1
);
boolean
changeHandled
=
...
...
@@ -622,7 +622,7 @@ public final class MediaPeriodQueueTest {
@Test
public
void
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= */
1
);
enqueueNext
();
// Content before first ad.
...
...
@@ -635,7 +635,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads).
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= */
1
);
long
maxRendererReadPositionUs
=
...
...
@@ -653,7 +653,7 @@ public final class MediaPeriodQueueTest {
@Test
public
void
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= */
1
);
enqueueNext
();
// Content before first ad.
...
...
@@ -665,7 +665,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads).
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= */
1
);
long
readingPositionAtStartOfContentBetweenAds
=
...
...
@@ -685,7 +685,7 @@ public final class MediaPeriodQueueTest {
@Test
public
void
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= */
1
);
enqueueNext
();
// Content before first ad.
...
...
@@ -697,7 +697,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads).
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= */
1
);
long
readingPositionAtEndOfContentBetweenAds
=
...
...
@@ -717,7 +717,7 @@ public final class MediaPeriodQueueTest {
@Test
public
void
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= */
1
);
enqueueNext
();
// Content before first ad.
...
...
@@ -729,7 +729,7 @@ public final class MediaPeriodQueueTest {
// Change position of second ad (= change duration of content between ads).
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= */
1
);
boolean
changeHandled
=
...
...
@@ -832,7 +832,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
true
,
/* isAdPeriodFlags
...
= */
true
,
false
,
true
,
true
,
...
...
@@ -867,7 +867,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
4
,
/* isAdPeriodFlags= */
true
,
/* isAdPeriodFlags
...
= */
true
,
false
,
true
,
true
,
...
...
@@ -902,7 +902,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
2
,
/* isAdPeriodFlags= */
true
,
/* isAdPeriodFlags
...
= */
true
,
false
,
true
,
true
,
...
...
@@ -926,7 +926,7 @@ public final class MediaPeriodQueueTest {
Object
windowId
=
new
Object
();
Timeline
timeline
=
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
true
);
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags
...
= */
false
,
true
);
MediaPeriodId
mediaPeriodId
=
mediaPeriodQueue
.
resolveMediaPeriodIdForAdsAfterPeriodPositionChange
(
...
...
@@ -945,7 +945,7 @@ public final class MediaPeriodQueueTest {
Object
windowId
=
new
Object
();
Timeline
timeline
=
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
true
,
false
);
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags
...
= */
false
,
true
,
false
);
MediaPeriodId
mediaPeriodId
=
mediaPeriodQueue
.
resolveMediaPeriodIdForAdsAfterPeriodPositionChange
(
...
...
@@ -964,7 +964,7 @@ public final class MediaPeriodQueueTest {
Object
windowId
=
new
Object
();
Timeline
timeline
=
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
1
,
/* isAdPeriodFlags= */
false
,
true
,
false
);
windowId
,
/* numberOfPlayedAds= */
1
,
/* isAdPeriodFlags
...
= */
false
,
true
,
false
);
MediaPeriodId
mediaPeriodId
=
mediaPeriodQueue
.
resolveMediaPeriodIdForAdsAfterPeriodPositionChange
(
...
...
@@ -983,7 +983,7 @@ public final class MediaPeriodQueueTest {
Object
windowId
=
new
Object
();
Timeline
timeline
=
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
2
,
/* isAdPeriodFlags= */
true
,
true
,
false
);
windowId
,
/* numberOfPlayedAds= */
2
,
/* isAdPeriodFlags
...
= */
true
,
true
,
false
);
MediaPeriodId
mediaPeriodId
=
mediaPeriodQueue
.
resolveMediaPeriodIdForAdsAfterPeriodPositionChange
(
timeline
,
new
Pair
<>(
windowId
,
0
),
/* positionUs= */
0
);
...
...
@@ -1003,7 +1003,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
4
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
true
,
true
,
true
,
...
...
@@ -1026,7 +1026,12 @@ public final class MediaPeriodQueueTest {
Object
windowId
=
new
Object
();
Timeline
timeline
=
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
true
,
false
,
false
,
false
);
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags...= */
true
,
false
,
false
,
false
);
MediaPeriodId
mediaPeriodId
=
mediaPeriodQueue
.
resolveMediaPeriodIdForAdsAfterPeriodPositionChange
(
...
...
@@ -1047,7 +1052,7 @@ public final class MediaPeriodQueueTest {
createMultiPeriodServerSideInsertedTimeline
(
windowId
,
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
false
,
false
,
false
);
...
...
library/core/src/test/java/com/google/android/exoplayer2/analytics/DefaultAnalyticsCollectorTest.java
View file @
ea7e8cff
...
...
@@ -1027,7 +1027,7 @@ public final class DefaultAnalyticsCollectorTest {
new
AtomicReference
<>(
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
windowOffsetInFirstPeriodUs
,
/* adGroupTimesUs
...
= */
windowOffsetInFirstPeriodUs
,
windowOffsetInFirstPeriodUs
+
5
*
C
.
MICROS_PER_SECOND
,
C
.
TIME_END_OF_SOURCE
));
AtomicInteger
playedAdCount
=
new
AtomicInteger
(
0
);
...
...
@@ -1300,7 +1300,7 @@ public final class DefaultAnalyticsCollectorTest {
/* isDynamic= */
false
,
10
*
C
.
MICROS_PER_SECOND
,
FakeTimeline
.
createAdPlaybackState
(
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs= */
/* adsPerAdGroup= */
1
,
/* adGroupTimesUs
...
= */
windowOffsetInFirstPeriodUs
+
5
*
C
.
MICROS_PER_SECOND
)));
FakeMediaSource
fakeMediaSource
=
new
FakeMediaSource
(
...
...
library/core/src/test/java/com/google/android/exoplayer2/audio/SilenceSkippingAudioProcessorTest.java
View file @
ea7e8cff
...
...
@@ -289,10 +289,11 @@ public final class SilenceSkippingAudioProcessorTest {
Pcm16BitAudioBuilder
audioBuilder
=
new
Pcm16BitAudioBuilder
(
channelCount
,
totalFrameCount
);
while
(!
audioBuilder
.
isFull
())
{
int
silenceDurationFrames
=
(
silenceDurationMs
*
sampleRate
)
/
1000
;
audioBuilder
.
appendFrames
(
/* count= */
silenceDurationFrames
,
/* channelLevels= */
(
short
)
0
);
audioBuilder
.
appendFrames
(
/* count= */
silenceDurationFrames
,
/* channelLevels...= */
(
short
)
0
);
int
noiseDurationFrames
=
(
noiseDurationMs
*
sampleRate
)
/
1000
;
audioBuilder
.
appendFrames
(
/* count= */
noiseDurationFrames
,
/* channelLevels= */
Short
.
MAX_VALUE
);
/* count= */
noiseDurationFrames
,
/* channelLevels
...
= */
Short
.
MAX_VALUE
);
}
return
new
InputBufferProvider
(
audioBuilder
.
build
());
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/source/ads/AdsMediaSourceTest.java
View file @
ea7e8cff
...
...
@@ -78,7 +78,7 @@ public final class AdsMediaSourceTest {
CONTENT_TIMELINE
.
getUidOfPeriod
(
/* periodIndex= */
0
);
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
)
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
1
)
.
withAvailableAdUri
(
...
...
library/core/src/test/java/com/google/android/exoplayer2/source/ads/ServerSideAdInsertionMediaSourceTest.java
View file @
ea7e8cff
...
...
@@ -92,16 +92,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
// Test with one ad group before the window, and the window starting within the second ad group.
AdPlaybackState
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= */
1
,
/* isServerSideInserted= */
true
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
2
,
/* isServerSideInserted= */
true
)
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
1
)
.
withAdCount
(
/* adGroupIndex= */
1
,
/* adCount= */
2
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
1
)
.
withAdDurationsUs
(
/* adGroupIndex= */
0
,
/* adDurationsUs= */
500_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
1
,
/* adDurationsUs= */
300_000
,
100_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
400_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
0
,
/* adDurationsUs
...
= */
500_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
1
,
/* adDurationsUs
...
= */
300_000
,
100_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
400_000
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
0
,
/* contentResumeOffsetUs= */
100_000
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
1
,
/* contentResumeOffsetUs= */
400_000
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
200_000
);
...
...
@@ -165,16 +168,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
// Test with one ad group before the window, and the window starting within the second ad group.
AdPlaybackState
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= */
1
,
/* isServerSideInserted= */
true
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
2
,
/* isServerSideInserted= */
true
)
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
1
)
.
withAdCount
(
/* adGroupIndex= */
1
,
/* adCount= */
2
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
1
)
.
withAdDurationsUs
(
/* adGroupIndex= */
0
,
/* adDurationsUs= */
500_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
1
,
/* adDurationsUs= */
300_000
,
100_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
400_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
0
,
/* adDurationsUs
...
= */
500_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
1
,
/* adDurationsUs
...
= */
300_000
,
100_000
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
400_000
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
0
,
/* contentResumeOffsetUs= */
100_000
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
1
,
/* contentResumeOffsetUs= */
400_000
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
200_000
);
...
...
@@ -259,19 +265,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
adPlaybackState
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
200_000
);
/* adDurationsUs
...
= */
200_000
);
adPlaybackState
=
addAdGroupToAdPlaybackState
(
adPlaybackState
,
/* fromPositionUs= */
400_000
,
/* contentResumeOffsetUs= */
1_000_000
,
/* adDurationsUs= */
300_000
);
/* adDurationsUs
...
= */
300_000
);
AdPlaybackState
firstAdPlaybackState
=
addAdGroupToAdPlaybackState
(
adPlaybackState
,
/* fromPositionUs= */
900_000
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
100_000
);
/* adDurationsUs
...
= */
100_000
);
AtomicReference
<
ServerSideAdInsertionMediaSource
>
mediaSourceRef
=
new
AtomicReference
<>();
mediaSourceRef
.
set
(
...
...
@@ -329,7 +335,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
new
AdPlaybackState
(
/* adsId= */
new
Object
()),
/* fromPositionUs= */
900_000
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
100_000
);
/* adDurationsUs
...
= */
100_000
);
AtomicReference
<
ServerSideAdInsertionMediaSource
>
mediaSourceRef
=
new
AtomicReference
<>();
mediaSourceRef
.
set
(
new
ServerSideAdInsertionMediaSource
(
...
...
@@ -357,7 +363,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
firstAdPlaybackState
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
500_000
);
/* adDurationsUs
...
= */
500_000
);
mediaSourceRef
.
get
()
.
setAdPlaybackStates
(
ImmutableMap
.
of
(
periodUid
.
get
(),
secondAdPlaybackState
));
...
...
@@ -400,7 +406,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
new
AdPlaybackState
(
/* adsId= */
new
Object
()),
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
500_000
);
/* adDurationsUs
...
= */
500_000
);
AtomicReference
<
ServerSideAdInsertionMediaSource
>
mediaSourceRef
=
new
AtomicReference
<>();
mediaSourceRef
.
set
(
new
ServerSideAdInsertionMediaSource
(
...
...
@@ -430,7 +436,7 @@ public final class ServerSideAdInsertionMediaSourceTest {
firstAdPlaybackState
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
3
)
.
withAdDurationsUs
(
/* adGroupIndex= */
0
,
/* adDurationsUs= */
50_000
,
250_000
,
200_000
);
/* adGroupIndex= */
0
,
/* adDurationsUs
...
= */
50_000
,
250_000
,
200_000
);
mediaSourceRef
.
get
()
.
setAdPlaybackStates
(
ImmutableMap
.
of
(
periodUid
.
get
(),
secondAdPlaybackState
));
...
...
@@ -468,19 +474,19 @@ public final class ServerSideAdInsertionMediaSourceTest {
adPlaybackState
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
100_000
);
/* adDurationsUs
...
= */
100_000
);
adPlaybackState
=
addAdGroupToAdPlaybackState
(
adPlaybackState
,
/* fromPositionUs= */
600_000
,
/* contentResumeOffsetUs= */
1_000_000
,
/* adDurationsUs= */
100_000
);
/* adDurationsUs
...
= */
100_000
);
AdPlaybackState
firstAdPlaybackState
=
addAdGroupToAdPlaybackState
(
adPlaybackState
,
/* fromPositionUs= */
900_000
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
100_000
);
/* adDurationsUs
...
= */
100_000
);
AtomicReference
<
ServerSideAdInsertionMediaSource
>
mediaSourceRef
=
new
AtomicReference
<>();
mediaSourceRef
.
set
(
...
...
library/core/src/test/java/com/google/android/exoplayer2/source/ads/ServerSideAdInsertionUtilTest.java
View file @
ea7e8cff
...
...
@@ -38,7 +38,7 @@ public final class ServerSideAdInsertionUtilTest {
@Test
public
void
addAdGroupToAdPlaybackState_insertsCorrectAdGroupData
()
{
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
);
// stream: 0-- content --4300-- ad1 --4500-- content
...
...
@@ -48,16 +48,16 @@ public final class ServerSideAdInsertionUtilTest {
state
,
/* fromPositionUs= */
4300
,
/* contentResumeOffsetUs= */
400
,
/* adDurationsUs= */
200
);
/* adDurationsUs
...
= */
200
);
assertThat
(
state
)
.
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
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
1
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
2
,
/* isServerSideInserted= */
true
)
.
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
// content timeline: 0-2100 - [ad1] - 2100-4000 - [ad2] - 4400-end
...
...
@@ -66,20 +66,20 @@ public final class ServerSideAdInsertionUtilTest {
state
,
/* fromPositionUs= */
2100
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
300
);
/* adDurationsUs
...
= */
300
);
assertThat
(
state
)
.
isEqualTo
(
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
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
1
)
.
withAdCount
(
/* adGroupIndex= */
3
,
/* adCount= */
1
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
2
,
/* isServerSideInserted= */
true
)
.
withIsServerSideInserted
(
/* adGroupIndex= */
3
,
/* isServerSideInserted= */
true
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
3
,
/* contentResumeOffsetUs= */
400
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
300
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs= */
200
));
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
300
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs
...
= */
200
));
// 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
...
...
@@ -88,12 +88,12 @@ public final class ServerSideAdInsertionUtilTest {
state
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
50
,
/* adDurationsUs= */
100
);
/* adDurationsUs
...
= */
100
);
assertThat
(
state
)
.
isEqualTo
(
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
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
1
)
.
withAdCount
(
/* adGroupIndex= */
3
,
/* adCount= */
1
)
...
...
@@ -103,9 +103,9 @@ public final class ServerSideAdInsertionUtilTest {
.
withIsServerSideInserted
(
/* adGroupIndex= */
4
,
/* isServerSideInserted= */
true
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
50
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
4
,
/* contentResumeOffsetUs= */
400
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
100
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs= */
300
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs= */
200
));
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
100
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs
...
= */
300
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs
...
= */
200
));
// stream: 0-- ad1 --100-- c --2100-- ad2 --2400-- c --4300-- ad3 --4500-- c --5000-- ad4 --6000
// content timeline: 0 - [ad1] - 50-2050 -[ad2] - 2050-3950 - [ad3] - 4350-4850 - [ad4] - 4850
...
...
@@ -114,12 +114,19 @@ public final class ServerSideAdInsertionUtilTest {
state
,
/* fromPositionUs= */
5000
,
/* contentResumeOffsetUs= */
0
,
/* adDurationsUs= */
1000
);
/* adDurationsUs
...
= */
1000
);
assertThat
(
state
)
.
isEqualTo
(
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
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
1
)
.
withAdCount
(
/* adGroupIndex= */
3
,
/* adCount= */
1
)
...
...
@@ -131,10 +138,10 @@ public final class ServerSideAdInsertionUtilTest {
.
withIsServerSideInserted
(
/* adGroupIndex= */
5
,
/* isServerSideInserted= */
true
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
50
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
4
,
/* contentResumeOffsetUs= */
400
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
100
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs= */
300
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
5
,
/* adDurationsUs= */
1000
));
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
100
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs
...
= */
300
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs
...
= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
5
,
/* adDurationsUs
...
= */
1000
));
}
@Test
...
...
@@ -146,7 +153,7 @@ public final class ServerSideAdInsertionUtilTest {
state
,
/* fromPositionUs= */
0
,
/* contentResumeOffsetUs= */
50_000
,
/* adDurationsUs= */
0
,
/* adDurationsUs
...
= */
0
,
0
,
10_000
,
40_000
,
...
...
@@ -169,7 +176,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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
AdPlaybackState
state
=
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs= */
0
,
0
,
0
,
2000
,
4000
)
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs
...
= */
0
,
0
,
0
,
2000
,
4000
)
.
withRemovedAdGroupCount
(
2
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
2
)
.
withAdCount
(
/* adGroupIndex= */
3
,
/* adCount= */
1
)
...
...
@@ -177,9 +184,9 @@ public final class ServerSideAdInsertionUtilTest {
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
100
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
3
,
/* contentResumeOffsetUs= */
0
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
4
,
/* contentResumeOffsetUs= */
400
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs= */
50
,
50
,
100
);
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs
...
= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs
...
= */
50
,
50
,
100
);
assertThat
(
getStreamPositionUsForAd
(
...
...
@@ -269,7 +276,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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
AdPlaybackState
state
=
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs= */
0
,
0
,
0
,
2000
,
4000
)
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs
...
= */
0
,
0
,
0
,
2000
,
4000
)
.
withRemovedAdGroupCount
(
2
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
2
)
.
withAdCount
(
/* adGroupIndex= */
3
,
/* adCount= */
1
)
...
...
@@ -277,9 +284,9 @@ public final class ServerSideAdInsertionUtilTest {
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
100
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
3
,
/* contentResumeOffsetUs= */
0
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
4
,
/* contentResumeOffsetUs= */
400
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs= */
50
,
50
,
100
);
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs
...
= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs
...
= */
50
,
50
,
100
);
assertThat
(
getMediaPeriodPositionUsForAd
(
...
...
@@ -374,7 +381,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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
AdPlaybackState
state
=
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs= */
0
,
0
,
0
,
2000
,
4000
)
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs
...
= */
0
,
0
,
0
,
2000
,
4000
)
.
withRemovedAdGroupCount
(
2
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
2
)
.
withAdCount
(
/* adGroupIndex= */
3
,
/* adCount= */
1
)
...
...
@@ -382,9 +389,9 @@ public final class ServerSideAdInsertionUtilTest {
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
100
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
3
,
/* contentResumeOffsetUs= */
0
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
4
,
/* contentResumeOffsetUs= */
400
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs= */
50
,
50
,
100
);
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs
...
= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs
...
= */
50
,
50
,
100
);
assertThat
(
getStreamPositionUsForContent
(
/* positionUs= */
0
,
/* nextAdGroupIndex= */
2
,
state
))
.
isEqualTo
(
0
);
...
...
@@ -470,7 +477,7 @@ public final class ServerSideAdInsertionUtilTest {
// 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
AdPlaybackState
state
=
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs= */
0
,
0
,
0
,
2000
,
4000
)
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs
...
= */
0
,
0
,
0
,
2000
,
4000
)
.
withRemovedAdGroupCount
(
2
)
.
withAdCount
(
/* adGroupIndex= */
2
,
/* adCount= */
2
)
.
withAdCount
(
/* adGroupIndex= */
3
,
/* adCount= */
1
)
...
...
@@ -478,9 +485,9 @@ public final class ServerSideAdInsertionUtilTest {
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
2
,
/* contentResumeOffsetUs= */
100
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
3
,
/* contentResumeOffsetUs= */
0
)
.
withContentResumeOffsetUs
(
/* adGroupIndex= */
4
,
/* contentResumeOffsetUs= */
400
)
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs= */
50
,
50
,
100
);
.
withAdDurationsUs
(
/* adGroupIndex= */
2
,
/* adDurationsUs
...
= */
150
,
50
)
.
withAdDurationsUs
(
/* adGroupIndex= */
3
,
/* adDurationsUs
...
= */
200
)
.
withAdDurationsUs
(
/* adGroupIndex= */
4
,
/* adDurationsUs
...
= */
50
,
50
,
100
);
assertThat
(
getMediaPeriodPositionUsForContent
(
...
...
@@ -587,7 +594,7 @@ public final class ServerSideAdInsertionUtilTest {
@Test
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= */
1
)).
isEqualTo
(
0
);
...
...
@@ -596,7 +603,7 @@ public final class ServerSideAdInsertionUtilTest {
@Test
public
void
getAdCountInGroup_withSetCount_returnsCount
()
{
AdPlaybackState
state
=
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs= */
0
,
2000
)
new
AdPlaybackState
(
ADS_ID
,
/* adGroupTimesUs
...
= */
0
,
2000
)
.
withAdCount
(
/* adGroupIndex= */
0
,
/* adCount= */
4
)
.
withAdCount
(
/* adGroupIndex= */
1
,
/* adCount= */
6
);
...
...
library/core/src/test/java/com/google/android/exoplayer2/trackselection/AdaptiveTrackSelectionTest.java
View file @
ea7e8cff
...
...
@@ -570,9 +570,9 @@ public final class AdaptiveTrackSelectionTest {
TrackGroup
trackGroupMultipleFixed
=
new
TrackGroup
(
formatFixed1
,
formatFixed2
);
TrackGroup
trackGroupAdaptive
=
new
TrackGroup
(
formatAdaptive1
,
formatAdaptive2
,
formatAdaptive3
,
formatAdaptive4
);
Definition
definitionFixed1
=
new
Definition
(
trackGroupMultipleFixed
,
/* tracks= */
0
);
Definition
definitionFixed2
=
new
Definition
(
trackGroupMultipleFixed
,
/* tracks= */
1
);
Definition
definitionAdaptive
=
new
Definition
(
trackGroupAdaptive
,
/* tracks= */
1
,
2
,
3
);
Definition
definitionFixed1
=
new
Definition
(
trackGroupMultipleFixed
,
/* tracks
...
= */
0
);
Definition
definitionFixed2
=
new
Definition
(
trackGroupMultipleFixed
,
/* tracks
...
= */
1
);
Definition
definitionAdaptive
=
new
Definition
(
trackGroupAdaptive
,
/* tracks
...
= */
1
,
2
,
3
);
List
<
List
<
AdaptationCheckpoint
>>
checkPoints
=
new
ArrayList
<>();
AdaptiveTrackSelection
.
Factory
factory
=
new
AdaptiveTrackSelection
.
Factory
()
{
...
...
@@ -621,9 +621,9 @@ public final class AdaptiveTrackSelectionTest {
TrackGroup
trackGroup2
=
new
TrackGroup
(
group2Format1
,
group2Format2
,
group2Format3
,
group2UnusedFormat
);
TrackGroup
fixedGroup
=
new
TrackGroup
(
fixedFormat
);
Definition
definition1
=
new
Definition
(
trackGroup1
,
/* tracks= */
0
,
1
);
Definition
definition2
=
new
Definition
(
trackGroup2
,
/* tracks= */
0
,
1
,
2
);
Definition
fixedDefinition
=
new
Definition
(
fixedGroup
,
/* tracks= */
0
);
Definition
definition1
=
new
Definition
(
trackGroup1
,
/* tracks
...
= */
0
,
1
);
Definition
definition2
=
new
Definition
(
trackGroup2
,
/* tracks
...
= */
0
,
1
,
2
);
Definition
fixedDefinition
=
new
Definition
(
fixedGroup
,
/* tracks
...
= */
0
);
List
<
List
<
AdaptationCheckpoint
>>
checkPoints
=
new
ArrayList
<>();
AdaptiveTrackSelection
.
Factory
factory
=
new
AdaptiveTrackSelection
.
Factory
()
{
...
...
library/core/src/test/java/com/google/android/exoplayer2/trackselection/DefaultTrackSelectorTest.java
View file @
ea7e8cff
...
...
@@ -2171,8 +2171,10 @@ public final class DefaultTrackSelectorTest {
TIMELINE
);
assertThat
(
result
.
length
).
isEqualTo
(
2
);
assertAdaptiveSelection
(
result
.
selections
[
0
],
trackGroups
.
get
(
0
),
/* expectedTracks= */
1
,
0
);
assertAdaptiveSelection
(
result
.
selections
[
1
],
trackGroups
.
get
(
1
),
/* expectedTracks= */
1
,
0
);
assertAdaptiveSelection
(
result
.
selections
[
0
],
trackGroups
.
get
(
0
),
/* expectedTracks...= */
1
,
0
);
assertAdaptiveSelection
(
result
.
selections
[
1
],
trackGroups
.
get
(
1
),
/* expectedTracks...= */
1
,
0
);
// Multiple adaptive selection disallowed.
trackSelector
.
setParameters
(
...
...
@@ -2185,7 +2187,8 @@ public final class DefaultTrackSelectorTest {
TIMELINE
);
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
);
}
...
...
@@ -2229,7 +2232,7 @@ public final class DefaultTrackSelectorTest {
trackSelector
.
selectTracks
(
new
RendererCapabilities
[]
{
VIDEO_CAPABILITIES
},
trackGroups
,
periodId
,
TIMELINE
);
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.
trackSelector
.
setParameters
(
defaultParameters
.
buildUpon
().
setPreferredVideoMimeType
(
null
));
...
...
@@ -2237,7 +2240,7 @@ public final class DefaultTrackSelectorTest {
trackSelector
.
selectTracks
(
new
RendererCapabilities
[]
{
VIDEO_CAPABILITIES
},
trackGroups
,
periodId
,
TIMELINE
);
assertThat
(
result
.
length
).
isEqualTo
(
1
);
assertAdaptiveSelection
(
result
.
selections
[
0
],
adaptiveGroup
,
/* expectedTracks= */
1
,
0
);
assertAdaptiveSelection
(
result
.
selections
[
0
],
adaptiveGroup
,
/* expectedTracks
...
= */
1
,
0
);
}
/**
...
...
@@ -2416,7 +2419,7 @@ public final class DefaultTrackSelectorTest {
@Test
public
void
roundTripViaBundle_ofSelectionOverride_yieldsEqualInstance
()
{
SelectionOverride
selectionOverrideToBundle
=
new
SelectionOverride
(
/* groupIndex= */
1
,
/* tracks= */
2
,
3
);
new
SelectionOverride
(
/* groupIndex= */
1
,
/* tracks
...
= */
2
,
3
);
SelectionOverride
selectionOverrideFromBundle
=
DefaultTrackSelector
.
SelectionOverride
.
CREATOR
.
fromBundle
(
...
...
library/hls/src/main/java/com/google/android/exoplayer2/source/hls/HlsMediaPeriod.java
View file @
ea7e8cff
...
...
@@ -687,7 +687,7 @@ public final class HlsMediaPeriod implements MediaPeriod, HlsPlaylistTracker.Pla
sampleStreamWrapper
.
prepareWithMultivariantPlaylistInfo
(
muxedTrackGroups
.
toArray
(
new
TrackGroup
[
0
]),
/* primaryTrackGroupIndex= */
0
,
/* optionalTrackGroupsIndices= */
muxedTrackGroups
.
indexOf
(
id3TrackGroup
));
/* optionalTrackGroupsIndices
...
= */
muxedTrackGroups
.
indexOf
(
id3TrackGroup
));
}
}
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/ExoPlayerAssetLoader.java
View file @
ea7e8cff
...
...
@@ -24,8 +24,6 @@ import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
import
android.content.Context
;
import
android.os.Handler
;
import
android.os.Looper
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.DefaultLoadControl
;
import
com.google.android.exoplayer2.ExoPlayer
;
...
...
@@ -64,31 +62,16 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener;
void
onError
(
Exception
e
);
}
private
final
Context
context
;
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
;
private
final
ExoPlayer
player
;
public
ExoPlayerAssetLoader
(
Context
context
,
MediaItem
mediaItem
,
boolean
removeAudio
,
boolean
removeVideo
,
MediaSource
.
Factory
mediaSourceFactory
,
L
ooper
loop
er
,
L
istener
listen
er
,
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
);
trackSelector
.
setParameters
(
new
DefaultTrackSelector
.
Parameters
.
Builder
(
context
)
...
...
@@ -108,8 +91,7 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener;
new
ExoPlayer
.
Builder
(
context
,
new
RenderersFactoryImpl
(
removeAudio
,
removeVideo
,
listener
))
.
setMediaSourceFactory
(
mediaSourceFactory
)
.
setTrackSelector
(
trackSelector
)
.
setLoadControl
(
loadControl
)
.
setLooper
(
looper
);
.
setLoadControl
(
loadControl
);
if
(
clock
!=
Clock
.
DEFAULT
)
{
// Transformer.Builder#setClock is also @VisibleForTesting, so if we're using a non-default
// clock we must be in a test context.
...
...
@@ -120,14 +102,14 @@ import com.google.android.exoplayer2.video.VideoRendererEventListener;
player
=
playerBuilder
.
build
();
player
.
setMediaItem
(
mediaItem
);
player
.
addListener
(
new
PlayerListener
(
listener
));
}
public
void
start
()
{
player
.
prepare
();
}
public
void
release
()
{
if
(
player
!=
null
)
{
player
.
release
();
player
=
null
;
}
player
.
release
();
}
private
static
final
class
RenderersFactoryImpl
implements
RenderersFactory
{
...
...
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/Transformer.java
View file @
ea7e8cff
...
...
@@ -16,7 +16,6 @@
package
com
.
google
.
android
.
exoplayer2
.
transformer
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkState
;
import
static
java
.
lang
.
annotation
.
ElementType
.
TYPE_USE
;
...
...
@@ -48,7 +47,6 @@ import com.google.android.exoplayer2.util.MimeTypes;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.common.collect.ImmutableList
;
import
com.google.errorprone.annotations.CanIgnoreReturnValue
;
import
java.io.File
;
import
java.lang.annotation.Documented
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
...
...
@@ -564,13 +562,8 @@ public final class Transformer {
private
final
Looper
looper
;
private
final
DebugViewProvider
debugViewProvider
;
private
final
Clock
clock
;
private
final
TransformerInternal
transformerInternal
;
@Nullable
private
MuxerWrapper
muxerWrapper
;
@Nullable
private
String
outputPath
;
@Nullable
private
ParcelFileDescriptor
outputParcelFileDescriptor
;
private
boolean
transformationInProgress
;
private
boolean
isCancelling
;
@Nullable
private
TransformerInternal
transformerInternal
;
private
Transformer
(
Context
context
,
...
...
@@ -604,21 +597,6 @@ public final class Transformer {
this
.
looper
=
looper
;
this
.
debugViewProvider
=
debugViewProvider
;
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. */
...
...
@@ -689,9 +667,7 @@ public final class Transformer {
* @throws IllegalStateException If a transformation is already in progress.
*/
public
void
startTransformation
(
MediaItem
mediaItem
,
String
path
)
{
this
.
outputPath
=
path
;
this
.
outputParcelFileDescriptor
=
null
;
startTransformationInternal
(
mediaItem
);
startTransformationInternal
(
mediaItem
,
path
,
/* parcelFileDescriptor= */
null
);
}
/**
...
...
@@ -718,12 +694,13 @@ public final class Transformer {
*/
@RequiresApi
(
26
)
public
void
startTransformation
(
MediaItem
mediaItem
,
ParcelFileDescriptor
parcelFileDescriptor
)
{
this
.
outputParcelFileDescriptor
=
parcelFileDescriptor
;
this
.
outputPath
=
null
;
startTransformationInternal
(
mediaItem
);
startTransformationInternal
(
mediaItem
,
/* path= */
null
,
parcelFileDescriptor
);
}
private
void
startTransformationInternal
(
MediaItem
mediaItem
)
{
private
void
startTransformationInternal
(
MediaItem
mediaItem
,
@Nullable
String
path
,
@Nullable
ParcelFileDescriptor
parcelFileDescriptor
)
{
if
(!
mediaItem
.
clippingConfiguration
.
equals
(
MediaItem
.
ClippingConfiguration
.
UNSET
)
&&
transformationRequest
.
flattenForSlowMotion
)
{
// TODO(b/233986762): Support clipping with SEF flattening.
...
...
@@ -731,23 +708,34 @@ public final class Transformer {
"Clipping is not supported when slow motion flattening is requested"
);
}
verifyApplicationThread
();
if
(
transform
ationInProgress
)
{
if
(
transform
erInternal
!=
null
)
{
throw
new
IllegalStateException
(
"There is already a transformation in progress."
);
}
transformationInProgress
=
true
;
TransformerInternalListener
transformerInternalListener
=
new
TransformerInternalListener
(
mediaItem
,
looper
);
MuxerWrapper
muxerWrapper
=
new
MuxerWrapper
(
outputPath
,
outputParcelFileDescriptor
,
muxerFactory
,
/* errorConsumer= */
transformerInternalListener:
:
onTransformationError
);
this
.
muxerWrapper
=
muxerWrapper
;
new
TransformerInternalListener
(
mediaItem
);
FallbackListener
fallbackListener
=
new
FallbackListener
(
mediaItem
,
listeners
,
transformationRequest
);
transformerInternal
.
start
(
mediaItem
,
muxerWrapper
,
transformerInternalListener
,
fallbackListener
);
transformerInternal
=
new
TransformerInternal
(
context
,
mediaItem
,
path
,
parcelFileDescriptor
,
transformationRequest
,
audioProcessors
,
videoEffects
,
removeAudio
,
removeVideo
,
mediaSourceFactory
,
decoderFactory
,
encoderFactory
,
frameProcessorFactory
,
muxerFactory
,
transformerInternalListener
,
fallbackListener
,
debugViewProvider
,
clock
);
transformerInternal
.
start
();
}
/**
...
...
@@ -773,7 +761,9 @@ public final class Transformer {
*/
public
@ProgressState
int
getProgress
(
ProgressHolder
progressHolder
)
{
verifyApplicationThread
();
return
transformerInternal
.
getProgress
(
progressHolder
);
return
transformerInternal
==
null
?
PROGRESS_STATE_NO_TRANSFORMATION
:
transformerInternal
.
getProgress
(
progressHolder
);
}
/**
...
...
@@ -783,36 +773,15 @@ public final class Transformer {
*/
public
void
cancel
()
{
verifyApplicationThread
();
isCancelling
=
true
;
if
(
transformerInternal
==
null
)
{
return
;
}
try
{
releaseResources
(
/* forCancellation= */
true
);
transformerInternal
.
release
(
/* forCancellation= */
true
);
}
catch
(
TransformationException
impossible
)
{
throw
new
IllegalStateException
(
impossible
);
}
isCancelling
=
false
;
}
/**
* 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
;
}
transformerInternal
=
null
;
}
private
void
verifyApplicationThread
()
{
...
...
@@ -821,101 +790,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
MediaItem
mediaItem
;
private
final
Handler
handler
;
public
TransformerInternalListener
(
MediaItem
mediaItem
,
Looper
looper
)
{
public
TransformerInternalListener
(
MediaItem
mediaItem
)
{
this
.
mediaItem
=
mediaItem
;
handler
=
new
Handler
(
looper
);
handler
=
Util
.
createHandlerForCurrentLooper
(
);
}
@Override
public
void
onTransformationCompleted
()
{
handleTransformationEnded
(
/* exception= */
null
);
public
void
onTransformationCompleted
(
TransformationResult
transformationResult
)
{
// 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
public
void
onTransformationError
(
TransformationException
exception
)
{
if
(
Looper
.
myLooper
()
==
looper
)
{
handleTransformationException
(
exception
);
}
else
{
handler
.
post
(()
->
handleTransformationException
(
exception
));
}
}
private
void
handleTransformationException
(
TransformationException
transformationException
)
{
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
();
Util
.
postOrRun
(
handler
,
()
->
{
transformerInternal
=
null
;
listeners
.
queueEvent
(
/* eventFlag= */
C
.
INDEX_UNSET
,
listener
->
listener
.
onTransformationError
(
mediaItem
,
exception
));
listeners
.
flushEvents
();
});
}
}
}
library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerInternal.java
View file @
ea7e8cff
...
...
@@ -20,10 +20,12 @@ import static com.google.android.exoplayer2.transformer.Transformer.PROGRESS_STA
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
Transformer
.
PROGRESS_STATE_NO_TRANSFORMATION
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
Transformer
.
PROGRESS_STATE_UNAVAILABLE
;
import
static
com
.
google
.
android
.
exoplayer2
.
transformer
.
Transformer
.
PROGRESS_STATE_WAITING_FOR_AVAILABILITY
;
import
static
com
.
google
.
android
.
exoplayer2
.
util
.
Assertions
.
checkNotNull
;
import
static
java
.
lang
.
Math
.
min
;
import
android.content.Context
;
import
android.os.Looper
;
import
android.os.Handler
;
import
android.os.ParcelFileDescriptor
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.Format
;
...
...
@@ -38,7 +40,9 @@ import com.google.android.exoplayer2.util.DebugViewProvider;
import
com.google.android.exoplayer2.util.Effect
;
import
com.google.android.exoplayer2.util.FrameProcessor
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.common.collect.ImmutableList
;
import
java.io.File
;
import
java.util.ArrayList
;
import
java.util.List
;
...
...
@@ -46,27 +50,36 @@ import java.util.List;
public
interface
Listener
{
void
onTransformationCompleted
();
void
onTransformationCompleted
(
TransformationResult
transformationResult
);
void
onTransformationError
(
TransformationException
exception
);
}
private
final
Context
context
;
@Nullable
private
final
String
outputPath
;
@Nullable
private
final
ParcelFileDescriptor
outputParcelFileDescriptor
;
private
final
TransformationRequest
transformationRequest
;
private
final
ImmutableList
<
AudioProcessor
>
audioProcessors
;
private
final
ImmutableList
<
Effect
>
videoEffects
;
private
final
Codec
.
DecoderFactory
decoderFactory
;
private
final
Codec
.
EncoderFactory
encoderFactory
;
private
final
FrameProcessor
.
Factory
frameProcessorFactory
;
private
final
Listener
listener
;
private
final
DebugViewProvider
debugViewProvider
;
private
final
Handler
handler
;
private
final
ExoPlayerAssetLoader
exoPlayerAssetLoader
;
private
final
MuxerWrapper
muxerWrapper
;
private
final
List
<
SamplePipeline
>
samplePipelines
;
private
@Transformer
.
ProgressState
int
progressState
;
private
long
durationMs
;
private
boolean
released
;
public
TransformerInternal
(
Context
context
,
MediaItem
mediaItem
,
@Nullable
String
outputPath
,
@Nullable
ParcelFileDescriptor
outputParcelFileDescriptor
,
TransformationRequest
transformationRequest
,
ImmutableList
<
AudioProcessor
>
audioProcessors
,
ImmutableList
<
Effect
>
videoEffects
,
...
...
@@ -76,33 +89,45 @@ import java.util.List;
Codec
.
DecoderFactory
decoderFactory
,
Codec
.
EncoderFactory
encoderFactory
,
FrameProcessor
.
Factory
frameProcessorFactory
,
Looper
looper
,
Muxer
.
Factory
muxerFactory
,
Listener
listener
,
FallbackListener
fallbackListener
,
DebugViewProvider
debugViewProvider
,
Clock
clock
)
{
this
.
context
=
context
;
this
.
outputPath
=
outputPath
;
this
.
outputParcelFileDescriptor
=
outputParcelFileDescriptor
;
this
.
transformationRequest
=
transformationRequest
;
this
.
audioProcessors
=
audioProcessors
;
this
.
videoEffects
=
videoEffects
;
this
.
decoderFactory
=
decoderFactory
;
this
.
encoderFactory
=
encoderFactory
;
this
.
frameProcessorFactory
=
frameProcessorFactory
;
this
.
listener
=
listener
;
this
.
debugViewProvider
=
debugViewProvider
;
handler
=
Util
.
createHandlerForCurrentLooper
();
AssetLoaderListener
assetLoaderListener
=
new
AssetLoaderListener
(
mediaItem
,
fallbackListener
);
muxerWrapper
=
new
MuxerWrapper
(
outputPath
,
outputParcelFileDescriptor
,
muxerFactory
,
/* errorConsumer= */
assetLoaderListener:
:
onError
);
exoPlayerAssetLoader
=
new
ExoPlayerAssetLoader
(
context
,
removeAudio
,
removeVideo
,
mediaSourceFactory
,
looper
,
clock
);
context
,
mediaItem
,
removeAudio
,
removeVideo
,
mediaSourceFactory
,
assetLoaderListener
,
clock
);
samplePipelines
=
new
ArrayList
<>(
/* initialCapacity= */
2
);
progressState
=
PROGRESS_STATE_
NO_TRANSFORMATION
;
progressState
=
PROGRESS_STATE_
WAITING_FOR_AVAILABILITY
;
}
public
void
start
(
MediaItem
mediaItem
,
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
void
start
()
{
exoPlayerAssetLoader
.
start
();
}
public
@Transformer
.
ProgressState
int
getProgress
(
ProgressHolder
progressHolder
)
{
...
...
@@ -113,10 +138,28 @@ import java.util.List;
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
();
progressState
=
PROGRESS_STATE_NO_TRANSFORMATION
;
released
=
true
;
exoPlayerAssetLoader
.
release
();
try
{
muxerWrapper
.
release
(
forCancellation
);
}
catch
(
Muxer
.
MuxerException
e
)
{
throw
TransformationException
.
createForMuxer
(
e
,
TransformationException
.
ERROR_CODE_MUXING_FAILED
);
}
}
private
long
getCurrentPositionMs
()
{
...
...
@@ -130,23 +173,35 @@ import java.util.List;
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
final
MediaItem
mediaItem
;
private
final
MuxerWrapper
muxerWrapper
;
private
final
TransformerInternal
.
Listener
listener
;
private
final
FallbackListener
fallbackListener
;
private
volatile
boolean
trackRegistered
;
public
AssetLoaderListener
(
MediaItem
mediaItem
,
MuxerWrapper
muxerWrapper
,
Listener
listener
,
FallbackListener
fallbackListener
)
{
public
AssetLoaderListener
(
MediaItem
mediaItem
,
FallbackListener
fallbackListener
)
{
this
.
mediaItem
=
mediaItem
;
this
.
muxerWrapper
=
muxerWrapper
;
this
.
listener
=
listener
;
this
.
fallbackListener
=
fallbackListener
;
}
...
...
@@ -197,12 +252,12 @@ import java.util.List;
}
else
{
transformationException
=
TransformationException
.
createForUnexpected
(
e
);
}
listener
.
onTransformationError
(
transformationException
);
handleTransformationEnded
(
transformationException
);
}
@Override
public
void
onEnded
()
{
listener
.
onTransformationCompleted
(
);
handleTransformationEnded
(
/* transformationException= */
null
);
}
private
SamplePipeline
getSamplePipeline
(
...
...
@@ -233,7 +288,7 @@ import java.util.List;
encoderFactory
,
muxerWrapper
,
fallbackListener
,
listener:
:
onTransformati
onError
,
this
::
onError
,
debugViewProvider
);
}
else
{
return
new
PassthroughSamplePipeline
(
...
...
@@ -324,5 +379,45 @@ import java.util.List;
}
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
);
}
});
}
}
}
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeTrackSelector.java
View file @
ea7e8cff
...
...
@@ -67,7 +67,7 @@ public class FakeTrackSelector extends DefaultTrackSelector {
boolean
hasTracks
=
trackGroupArray
.
length
>
0
;
definitions
[
i
]
=
hasTracks
?
new
ExoTrackSelection
.
Definition
(
trackGroupArray
.
get
(
0
),
/* tracks= */
0
)
?
new
ExoTrackSelection
.
Definition
(
trackGroupArray
.
get
(
0
),
/* tracks
...
= */
0
)
:
null
;
}
return
definitions
;
...
...
testutils/src/test/java/com/google/android/exoplayer2/testutil/FakeTimelineTest.java
View file @
ea7e8cff
...
...
@@ -39,7 +39,7 @@ public class FakeTimelineTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
windowId
,
numberOfPlayedAds
,
/* isAdPeriodFlags= */
true
,
/* isAdPeriodFlags
...
= */
true
,
false
,
true
,
true
,
...
...
@@ -94,7 +94,7 @@ public class FakeTimelineTest {
FakeTimeline
.
createMultiPeriodAdTimeline
(
/* windowId= */
new
Object
(),
/* numberOfPlayedAds= */
0
,
/* isAdPeriodFlags= */
false
,
/* isAdPeriodFlags
...
= */
false
,
true
,
true
,
false
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment