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
cda6cba5
authored
Feb 03, 2020
by
olly
Committed by
Oliver Woodman
Feb 03, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
More nullness fixes in testutil
PiperOrigin-RevId: 292907271
parent
ad115a5a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
167 additions
and
100 deletions
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/AnalyticsCollectorTest.java
library/core/src/test/java/com/google/android/exoplayer2/source/ClippingMediaSourceTest.java
library/core/src/test/java/com/google/android/exoplayer2/source/ConcatenatingMediaSourceTest.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/CacheAsserts.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoHostedTest.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaPeriod.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaSource.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/MediaPeriodAsserts.java
testutils/src/main/java/com/google/android/exoplayer2/testutil/package-info.java
library/core/src/test/java/com/google/android/exoplayer2/ExoPlayerTest.java
View file @
cda6cba5
...
@@ -484,7 +484,7 @@ public final class ExoPlayerTest {
...
@@ -484,7 +484,7 @@ public final class ExoPlayerTest {
new
ActionSchedule
.
Builder
(
"testAdGroupWithLoadErrorIsSkipped"
)
new
ActionSchedule
.
Builder
(
"testAdGroupWithLoadErrorIsSkipped"
)
.
pause
()
.
pause
()
.
waitForPlaybackState
(
Player
.
STATE_READY
)
.
waitForPlaybackState
(
Player
.
STATE_READY
)
.
executeRunnable
(()
->
fakeMediaSource
.
setNewSourceInfo
(
adErrorTimeline
,
null
))
.
executeRunnable
(()
->
fakeMediaSource
.
setNewSourceInfo
(
adErrorTimeline
))
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
adErrorTimeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
adErrorTimeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
play
()
.
play
()
...
@@ -864,7 +864,7 @@ public final class ExoPlayerTest {
...
@@ -864,7 +864,7 @@ public final class ExoPlayerTest {
.
pause
()
.
pause
()
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
timeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
timeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline2
,
null
))
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline2
))
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
timeline2
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
timeline2
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
play
()
.
play
()
...
@@ -2061,7 +2061,7 @@ public final class ExoPlayerTest {
...
@@ -2061,7 +2061,7 @@ public final class ExoPlayerTest {
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
timeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
timeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
sendMessage
(
target
,
/* positionMs= */
50
)
.
sendMessage
(
target
,
/* positionMs= */
50
)
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
secondTimeline
,
null
))
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
secondTimeline
))
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
secondTimeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
secondTimeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
play
()
.
play
()
...
@@ -2137,7 +2137,7 @@ public final class ExoPlayerTest {
...
@@ -2137,7 +2137,7 @@ public final class ExoPlayerTest {
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
timeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
timeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
sendMessage
(
target
,
/* windowIndex = */
1
,
/* positionMs= */
50
)
.
sendMessage
(
target
,
/* windowIndex = */
1
,
/* positionMs= */
50
)
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
secondTimeline
,
null
))
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
secondTimeline
))
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
secondTimeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
secondTimeline
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
seek
(
/* windowIndex= */
0
,
/* positionMs= */
0
)
.
seek
(
/* windowIndex= */
0
,
/* positionMs= */
0
)
...
@@ -2223,7 +2223,7 @@ public final class ExoPlayerTest {
...
@@ -2223,7 +2223,7 @@ public final class ExoPlayerTest {
@Test
@Test
public
void
testCancelRepeatedMessageAfterDelivery
()
throws
Exception
{
public
void
testCancelRepeatedMessageAfterDelivery
()
throws
Exception
{
Timeline
timeline
=
new
FakeTimeline
(
/* windowCount= */
1
);
Timeline
timeline
=
new
FakeTimeline
(
/* windowCount= */
1
);
final
PositionGrabbingMessageTarget
target
=
new
PositionGrabb
ingMessageTarget
();
final
CountingMessageTarget
target
=
new
Count
ingMessageTarget
();
final
AtomicReference
<
PlayerMessage
>
message
=
new
AtomicReference
<>();
final
AtomicReference
<
PlayerMessage
>
message
=
new
AtomicReference
<>();
ActionSchedule
actionSchedule
=
ActionSchedule
actionSchedule
=
new
ActionSchedule
.
Builder
(
"testCancelMessage"
)
new
ActionSchedule
.
Builder
(
"testCancelMessage"
)
...
@@ -2315,7 +2315,7 @@ public final class ExoPlayerTest {
...
@@ -2315,7 +2315,7 @@ public final class ExoPlayerTest {
.
playUntilPosition
(
.
playUntilPosition
(
/* windowIndex= */
0
,
/* windowIndex= */
0
,
/* positionMs= */
C
.
usToMs
(
TimelineWindowDefinition
.
DEFAULT_WINDOW_DURATION_US
))
/* positionMs= */
C
.
usToMs
(
TimelineWindowDefinition
.
DEFAULT_WINDOW_DURATION_US
))
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline2
,
/* newManifest= */
null
))
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline2
))
.
waitForTimelineChanged
(
.
waitForTimelineChanged
(
timeline2
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
timeline2
,
/* expectedReason */
Player
.
TIMELINE_CHANGE_REASON_SOURCE_UPDATE
)
.
play
()
.
play
()
...
@@ -2844,7 +2844,7 @@ public final class ExoPlayerTest {
...
@@ -2844,7 +2844,7 @@ public final class ExoPlayerTest {
.
waitForPlaybackState
(
Player
.
STATE_BUFFERING
)
.
waitForPlaybackState
(
Player
.
STATE_BUFFERING
)
.
seek
(
/* positionMs= */
10
)
.
seek
(
/* positionMs= */
10
)
.
waitForSeekProcessed
()
.
waitForSeekProcessed
()
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline
,
/* newManifest= */
null
))
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline
))
.
waitForTimelineChanged
()
.
waitForTimelineChanged
()
.
waitForPlaybackState
(
Player
.
STATE_READY
)
.
waitForPlaybackState
(
Player
.
STATE_READY
)
.
executeRunnable
(
.
executeRunnable
(
...
@@ -2889,7 +2889,7 @@ public final class ExoPlayerTest {
...
@@ -2889,7 +2889,7 @@ public final class ExoPlayerTest {
// Seek 10ms into the second period.
// Seek 10ms into the second period.
.
seek
(
/* positionMs= */
periodDurationMs
+
10
)
.
seek
(
/* positionMs= */
periodDurationMs
+
10
)
.
waitForSeekProcessed
()
.
waitForSeekProcessed
()
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline
,
/* newManifest= */
null
))
.
executeRunnable
(()
->
mediaSource
.
setNewSourceInfo
(
timeline
))
.
waitForTimelineChanged
()
.
waitForTimelineChanged
()
.
waitForPlaybackState
(
Player
.
STATE_READY
)
.
waitForPlaybackState
(
Player
.
STATE_READY
)
.
executeRunnable
(
.
executeRunnable
(
...
@@ -5682,6 +5682,16 @@ public final class ExoPlayerTest {
...
@@ -5682,6 +5682,16 @@ public final class ExoPlayerTest {
// Internal classes.
// Internal classes.
private
static
final
class
CountingMessageTarget
implements
PlayerMessage
.
Target
{
public
int
messageCount
;
@Override
public
void
handleMessage
(
int
x
,
@Nullable
Object
message
)
{
messageCount
++;
}
}
private
static
final
class
PositionGrabbingMessageTarget
extends
PlayerTarget
{
private
static
final
class
PositionGrabbingMessageTarget
extends
PlayerTarget
{
public
int
windowIndex
;
public
int
windowIndex
;
...
@@ -5695,10 +5705,8 @@ public final class ExoPlayerTest {
...
@@ -5695,10 +5705,8 @@ public final class ExoPlayerTest {
@Override
@Override
public
void
handleMessage
(
SimpleExoPlayer
player
,
int
messageType
,
@Nullable
Object
message
)
{
public
void
handleMessage
(
SimpleExoPlayer
player
,
int
messageType
,
@Nullable
Object
message
)
{
if
(
player
!=
null
)
{
windowIndex
=
player
.
getCurrentWindowIndex
();
windowIndex
=
player
.
getCurrentWindowIndex
();
positionMs
=
player
.
getCurrentPosition
();
positionMs
=
player
.
getCurrentPosition
();
}
messageCount
++;
messageCount
++;
}
}
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/MediaPeriodQueueTest.java
View file @
cda6cba5
...
@@ -374,7 +374,7 @@ public final class MediaPeriodQueueTest {
...
@@ -374,7 +374,7 @@ public final class MediaPeriodQueueTest {
private
void
updateTimeline
()
{
private
void
updateTimeline
()
{
SinglePeriodAdTimeline
adTimeline
=
SinglePeriodAdTimeline
adTimeline
=
new
SinglePeriodAdTimeline
(
CONTENT_TIMELINE
,
adPlaybackState
);
new
SinglePeriodAdTimeline
(
CONTENT_TIMELINE
,
adPlaybackState
);
fakeMediaSource
.
setNewSourceInfo
(
adTimeline
,
/* manifest */
null
);
fakeMediaSource
.
setNewSourceInfo
(
adTimeline
);
playbackInfo
=
playbackInfo
.
copyWithTimeline
(
createPlaylistTimeline
());
playbackInfo
=
playbackInfo
.
copyWithTimeline
(
createPlaylistTimeline
());
}
}
...
...
library/core/src/test/java/com/google/android/exoplayer2/analytics/AnalyticsCollectorTest.java
View file @
cda6cba5
...
@@ -785,8 +785,7 @@ public final class AnalyticsCollectorTest {
...
@@ -785,8 +785,7 @@ public final class AnalyticsCollectorTest {
/* isSeekable= */
true
,
/* isSeekable= */
true
,
/* isDynamic= */
false
,
/* isDynamic= */
false
,
/* durationUs =*/
10
*
C
.
MICROS_PER_SECOND
,
/* durationUs =*/
10
*
C
.
MICROS_PER_SECOND
,
adPlaybackState
.
get
())),
adPlaybackState
.
get
())));
/* newManifest= */
null
);
}
}
}
}
});
});
...
...
library/core/src/test/java/com/google/android/exoplayer2/source/ClippingMediaSourceTest.java
View file @
cda6cba5
...
@@ -635,7 +635,7 @@ public final class ClippingMediaSourceTest {
...
@@ -635,7 +635,7 @@ public final class ClippingMediaSourceTest {
clippedTimelines
[
0
].
getUidOfPeriod
(
/* periodIndex= */
0
),
clippedTimelines
[
0
].
getUidOfPeriod
(
/* periodIndex= */
0
),
/* windowSequenceNumber= */
0
));
/* windowSequenceNumber= */
0
));
for
(
int
i
=
0
;
i
<
additionalTimelines
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
additionalTimelines
.
length
;
i
++)
{
fakeMediaSource
.
setNewSourceInfo
(
additionalTimelines
[
i
]
,
/* newManifest= */
null
);
fakeMediaSource
.
setNewSourceInfo
(
additionalTimelines
[
i
]);
clippedTimelines
[
i
+
1
]
=
testRunner
.
assertTimelineChangeBlocking
();
clippedTimelines
[
i
+
1
]
=
testRunner
.
assertTimelineChangeBlocking
();
}
}
testRunner
.
releasePeriod
(
mediaPeriod
);
testRunner
.
releasePeriod
(
mediaPeriod
);
...
...
library/core/src/test/java/com/google/android/exoplayer2/source/ConcatenatingMediaSourceTest.java
View file @
cda6cba5
...
@@ -246,8 +246,7 @@ public final class ConcatenatingMediaSourceTest {
...
@@ -246,8 +246,7 @@ public final class ConcatenatingMediaSourceTest {
// Trigger source info refresh for lazy source and check that the timeline now contains all
// Trigger source info refresh for lazy source and check that the timeline now contains all
// information for all windows.
// information for all windows.
testRunner
.
runOnPlaybackThread
(
testRunner
.
runOnPlaybackThread
(()
->
lazySources
[
1
].
setNewSourceInfo
(
createFakeTimeline
(
8
)));
()
->
lazySources
[
1
].
setNewSourceInfo
(
createFakeTimeline
(
8
),
null
));
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
,
9
);
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
,
9
);
TimelineAsserts
.
assertWindowTags
(
timeline
,
111
,
999
);
TimelineAsserts
.
assertWindowTags
(
timeline
,
111
,
999
);
...
@@ -281,8 +280,7 @@ public final class ConcatenatingMediaSourceTest {
...
@@ -281,8 +280,7 @@ public final class ConcatenatingMediaSourceTest {
// Trigger source info refresh for lazy media source. Assert that now all information is
// Trigger source info refresh for lazy media source. Assert that now all information is
// available again and the previously created period now also finished preparing.
// available again and the previously created period now also finished preparing.
testRunner
.
runOnPlaybackThread
(
testRunner
.
runOnPlaybackThread
(()
->
lazySources
[
3
].
setNewSourceInfo
(
createFakeTimeline
(
7
)));
()
->
lazySources
[
3
].
setNewSourceInfo
(
createFakeTimeline
(
7
),
null
));
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
8
,
1
,
2
,
9
);
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
8
,
1
,
2
,
9
);
TimelineAsserts
.
assertWindowTags
(
timeline
,
888
,
111
,
222
,
999
);
TimelineAsserts
.
assertWindowTags
(
timeline
,
888
,
111
,
222
,
999
);
...
@@ -372,15 +370,15 @@ public final class ConcatenatingMediaSourceTest {
...
@@ -372,15 +370,15 @@ public final class ConcatenatingMediaSourceTest {
Timeline
timeline
=
testRunner
.
prepareSource
();
Timeline
timeline
=
testRunner
.
prepareSource
();
TimelineAsserts
.
assertEmpty
(
timeline
);
TimelineAsserts
.
assertEmpty
(
timeline
);
childSources
[
0
].
setNewSourceInfo
(
nonEmptyTimeline
,
/* newManifest== */
null
);
childSources
[
0
].
setNewSourceInfo
(
nonEmptyTimeline
);
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
);
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
);
childSources
[
2
].
setNewSourceInfo
(
nonEmptyTimeline
,
/* newManifest== */
null
);
childSources
[
2
].
setNewSourceInfo
(
nonEmptyTimeline
);
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
,
1
);
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
,
1
);
childSources
[
1
].
setNewSourceInfo
(
nonEmptyTimeline
,
/* newManifest== */
null
);
childSources
[
1
].
setNewSourceInfo
(
nonEmptyTimeline
);
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
timeline
=
testRunner
.
assertTimelineChangeBlocking
();
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
,
1
,
1
);
TimelineAsserts
.
assertPeriodCounts
(
timeline
,
1
,
1
,
1
);
}
}
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/Action.java
View file @
cda6cba5
This diff is collapsed.
Click to expand it.
testutils/src/main/java/com/google/android/exoplayer2/testutil/ActionSchedule.java
View file @
cda6cba5
...
@@ -54,6 +54,7 @@ import com.google.android.exoplayer2.testutil.Action.WaitForTimelineChanged;
...
@@ -54,6 +54,7 @@ import com.google.android.exoplayer2.testutil.Action.WaitForTimelineChanged;
import
com.google.android.exoplayer2.trackselection.DefaultTrackSelector
;
import
com.google.android.exoplayer2.trackselection.DefaultTrackSelector
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.HandlerWrapper
;
import
com.google.android.exoplayer2.util.HandlerWrapper
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
/**
/**
* Schedules a sequence of {@link Action}s for execution during a test.
* Schedules a sequence of {@link Action}s for execution during a test.
...
@@ -89,7 +90,8 @@ public final class ActionSchedule {
...
@@ -89,7 +90,8 @@ public final class ActionSchedule {
*
*
* @param player The player to which actions should be applied.
* @param player The player to which actions should be applied.
* @param trackSelector The track selector to which actions should be applied.
* @param trackSelector The track selector to which actions should be applied.
* @param surface The surface to use when applying actions.
* @param surface The surface to use when applying actions, or {@code null} if no surface is
* needed.
* @param mainHandler A handler associated with the main thread of the host activity.
* @param mainHandler A handler associated with the main thread of the host activity.
* @param callback A {@link Callback} to notify when the action schedule finishes, or null if no
* @param callback A {@link Callback} to notify when the action schedule finishes, or null if no
* notification is needed.
* notification is needed.
...
@@ -97,7 +99,7 @@ public final class ActionSchedule {
...
@@ -97,7 +99,7 @@ public final class ActionSchedule {
/* package */
void
start
(
/* package */
void
start
(
SimpleExoPlayer
player
,
SimpleExoPlayer
player
,
DefaultTrackSelector
trackSelector
,
DefaultTrackSelector
trackSelector
,
Surface
surface
,
@Nullable
Surface
surface
,
HandlerWrapper
mainHandler
,
HandlerWrapper
mainHandler
,
@Nullable
Callback
callback
)
{
@Nullable
Callback
callback
)
{
callbackAction
.
setCallback
(
callback
);
callbackAction
.
setCallback
(
callback
);
...
@@ -607,9 +609,9 @@ public final class ActionSchedule {
...
@@ -607,9 +609,9 @@ public final class ActionSchedule {
void
onMessageArrived
();
void
onMessageArrived
();
}
}
private
SimpleExoPlayer
player
;
@Nullable
private
SimpleExoPlayer
player
;
private
boolean
hasArrived
;
private
boolean
hasArrived
;
private
Callback
callback
;
@Nullable
private
Callback
callback
;
public
void
setCallback
(
Callback
callback
)
{
public
void
setCallback
(
Callback
callback
)
{
this
.
callback
=
callback
;
this
.
callback
=
callback
;
...
@@ -629,7 +631,7 @@ public final class ActionSchedule {
...
@@ -629,7 +631,7 @@ public final class ActionSchedule {
@Override
@Override
public
final
void
handleMessage
(
int
messageType
,
@Nullable
Object
message
)
{
public
final
void
handleMessage
(
int
messageType
,
@Nullable
Object
message
)
{
handleMessage
(
player
,
messageType
,
message
);
handleMessage
(
Assertions
.
checkStateNotNull
(
player
)
,
messageType
,
message
);
if
(
callback
!=
null
)
{
if
(
callback
!=
null
)
{
hasArrived
=
true
;
hasArrived
=
true
;
callback
.
onMessageArrived
();
callback
.
onMessageArrived
();
...
@@ -643,7 +645,7 @@ public final class ActionSchedule {
...
@@ -643,7 +645,7 @@ public final class ActionSchedule {
*/
*/
public
abstract
static
class
PlayerRunnable
implements
Runnable
{
public
abstract
static
class
PlayerRunnable
implements
Runnable
{
private
SimpleExoPlayer
player
;
@Nullable
private
SimpleExoPlayer
player
;
/** Executes Runnable with reference to player. */
/** Executes Runnable with reference to player. */
public
abstract
void
run
(
SimpleExoPlayer
player
);
public
abstract
void
run
(
SimpleExoPlayer
player
);
...
@@ -655,7 +657,7 @@ public final class ActionSchedule {
...
@@ -655,7 +657,7 @@ public final class ActionSchedule {
@Override
@Override
public
final
void
run
()
{
public
final
void
run
()
{
run
(
player
);
run
(
Assertions
.
checkStateNotNull
(
player
)
);
}
}
}
}
...
@@ -666,12 +668,12 @@ public final class ActionSchedule {
...
@@ -666,12 +668,12 @@ public final class ActionSchedule {
private
final
long
delayMs
;
private
final
long
delayMs
;
private
final
long
repeatIntervalMs
;
private
final
long
repeatIntervalMs
;
private
ActionNode
next
;
@Nullable
private
ActionNode
next
;
private
SimpleExoPlayer
player
;
private
@MonotonicNonNull
SimpleExoPlayer
player
;
private
DefaultTrackSelector
trackSelector
;
private
@MonotonicNonNull
DefaultTrackSelector
trackSelector
;
private
Surface
surface
;
@Nullable
private
Surface
surface
;
private
HandlerWrapper
mainHandler
;
private
@MonotonicNonNull
HandlerWrapper
mainHandler
;
/**
/**
* @param action The wrapped action.
* @param action The wrapped action.
...
@@ -708,13 +710,13 @@ public final class ActionSchedule {
...
@@ -708,13 +710,13 @@ public final class ActionSchedule {
*
*
* @param player The player to which actions should be applied.
* @param player The player to which actions should be applied.
* @param trackSelector The track selector to which actions should be applied.
* @param trackSelector The track selector to which actions should be applied.
* @param surface The surface to use when applying actions.
* @param surface The surface to use when applying actions
, or {@code null}
.
* @param mainHandler A handler associated with the main thread of the host activity.
* @param mainHandler A handler associated with the main thread of the host activity.
*/
*/
public
void
schedule
(
public
void
schedule
(
SimpleExoPlayer
player
,
SimpleExoPlayer
player
,
DefaultTrackSelector
trackSelector
,
DefaultTrackSelector
trackSelector
,
Surface
surface
,
@Nullable
Surface
surface
,
HandlerWrapper
mainHandler
)
{
HandlerWrapper
mainHandler
)
{
this
.
player
=
player
;
this
.
player
=
player
;
this
.
trackSelector
=
trackSelector
;
this
.
trackSelector
=
trackSelector
;
...
@@ -729,14 +731,20 @@ public final class ActionSchedule {
...
@@ -729,14 +731,20 @@ public final class ActionSchedule {
@Override
@Override
public
void
run
()
{
public
void
run
()
{
action
.
doActionAndScheduleNext
(
player
,
trackSelector
,
surface
,
mainHandler
,
next
);
action
.
doActionAndScheduleNext
(
Assertions
.
checkStateNotNull
(
player
),
Assertions
.
checkStateNotNull
(
trackSelector
),
surface
,
Assertions
.
checkStateNotNull
(
mainHandler
),
next
);
if
(
repeatIntervalMs
!=
C
.
TIME_UNSET
)
{
if
(
repeatIntervalMs
!=
C
.
TIME_UNSET
)
{
mainHandler
.
postDelayed
(
mainHandler
.
postDelayed
(
new
Runnable
()
{
new
Runnable
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
action
.
doActionAndScheduleNext
(
player
,
trackSelector
,
surface
,
mainHandler
,
null
);
action
.
doActionAndScheduleNext
(
mainHandler
.
postDelayed
(
this
,
repeatIntervalMs
);
player
,
trackSelector
,
surface
,
mainHandler
,
/* nextAction= */
null
);
mainHandler
.
postDelayed
(
/* runnable= */
this
,
repeatIntervalMs
);
}
}
},
},
repeatIntervalMs
);
repeatIntervalMs
);
...
@@ -756,7 +764,7 @@ public final class ActionSchedule {
...
@@ -756,7 +764,7 @@ public final class ActionSchedule {
@Override
@Override
protected
void
doActionImpl
(
protected
void
doActionImpl
(
SimpleExoPlayer
player
,
DefaultTrackSelector
trackSelector
,
Surface
surface
)
{
SimpleExoPlayer
player
,
DefaultTrackSelector
trackSelector
,
@Nullable
Surface
surface
)
{
// Do nothing.
// Do nothing.
}
}
}
}
...
@@ -780,18 +788,19 @@ public final class ActionSchedule {
...
@@ -780,18 +788,19 @@ public final class ActionSchedule {
protected
void
doActionAndScheduleNextImpl
(
protected
void
doActionAndScheduleNextImpl
(
SimpleExoPlayer
player
,
SimpleExoPlayer
player
,
DefaultTrackSelector
trackSelector
,
DefaultTrackSelector
trackSelector
,
Surface
surface
,
@Nullable
Surface
surface
,
HandlerWrapper
handler
,
HandlerWrapper
handler
,
ActionNode
nextAction
)
{
@Nullable
ActionNode
nextAction
)
{
Assertions
.
checkArgument
(
nextAction
==
null
);
Assertions
.
checkArgument
(
nextAction
==
null
);
@Nullable
Callback
callback
=
this
.
callback
;
if
(
callback
!=
null
)
{
if
(
callback
!=
null
)
{
handler
.
post
(
()
->
callback
.
onActionScheduleFinished
()
);
handler
.
post
(
callback:
:
onActionScheduleFinished
);
}
}
}
}
@Override
@Override
protected
void
doActionImpl
(
protected
void
doActionImpl
(
SimpleExoPlayer
player
,
DefaultTrackSelector
trackSelector
,
Surface
surface
)
{
SimpleExoPlayer
player
,
DefaultTrackSelector
trackSelector
,
@Nullable
Surface
surface
)
{
// Not triggered.
// Not triggered.
}
}
}
}
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/CacheAsserts.java
View file @
cda6cba5
...
@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.upstream.DataSpec;
...
@@ -26,6 +26,7 @@ import com.google.android.exoplayer2.upstream.DataSpec;
import
com.google.android.exoplayer2.upstream.DummyDataSource
;
import
com.google.android.exoplayer2.upstream.DummyDataSource
;
import
com.google.android.exoplayer2.upstream.cache.Cache
;
import
com.google.android.exoplayer2.upstream.cache.Cache
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.upstream.cache.CacheDataSource
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -44,7 +45,7 @@ public final class CacheAsserts {
...
@@ -44,7 +45,7 @@ public final class CacheAsserts {
ArrayList
<
FakeData
>
allData
=
fakeDataSet
.
getAllData
();
ArrayList
<
FakeData
>
allData
=
fakeDataSet
.
getAllData
();
dataSpecs
=
new
DataSpec
[
allData
.
size
()];
dataSpecs
=
new
DataSpec
[
allData
.
size
()];
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
dataSpecs
[
i
]
=
new
DataSpec
(
allData
.
get
(
i
).
uri
);
dataSpecs
[
i
]
=
new
DataSpec
(
Assertions
.
checkNotNull
(
allData
.
get
(
i
).
uri
)
);
}
}
}
}
...
@@ -74,7 +75,7 @@ public final class CacheAsserts {
...
@@ -74,7 +75,7 @@ public final class CacheAsserts {
}
}
public
byte
[]
getData
(
int
i
)
{
public
byte
[]
getData
(
int
i
)
{
return
fakeDataSet
.
getData
(
dataSpecs
[
i
].
uri
).
getData
();
return
Assertions
.
checkNotNull
(
fakeDataSet
.
getData
(
dataSpecs
[
i
].
uri
)
).
getData
();
}
}
public
DataSpec
getDataSpec
(
int
i
)
{
public
DataSpec
getDataSpec
(
int
i
)
{
...
@@ -82,10 +83,10 @@ public final class CacheAsserts {
...
@@ -82,10 +83,10 @@ public final class CacheAsserts {
}
}
public
RequestSet
useBoundedDataSpecFor
(
String
uriString
)
{
public
RequestSet
useBoundedDataSpecFor
(
String
uriString
)
{
FakeData
data
=
fakeDataSet
.
getData
(
uriString
);
FakeData
data
=
Assertions
.
checkStateNotNull
(
fakeDataSet
.
getData
(
uriString
)
);
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
dataSpecs
.
length
;
i
++)
{
DataSpec
spec
=
dataSpecs
[
i
];
DataSpec
spec
=
dataSpecs
[
i
];
if
(
spec
.
uri
.
getPath
(
).
equals
(
uriString
))
{
if
(
Assertions
.
checkNotNull
(
spec
.
uri
.
getPath
()
).
equals
(
uriString
))
{
dataSpecs
[
i
]
=
spec
.
subrange
(
0
,
data
.
getData
().
length
);
dataSpecs
[
i
]
=
spec
.
subrange
(
0
,
data
.
getData
().
length
);
return
this
;
return
this
;
}
}
...
@@ -148,13 +149,10 @@ public final class CacheAsserts {
...
@@ -148,13 +149,10 @@ public final class CacheAsserts {
*/
*/
public
static
void
assertReadData
(
DataSource
dataSource
,
DataSpec
dataSpec
,
byte
[]
expected
)
public
static
void
assertReadData
(
DataSource
dataSource
,
DataSpec
dataSpec
,
byte
[]
expected
)
throws
IOException
{
throws
IOException
{
byte
[]
bytes
=
null
;
try
(
DataSourceInputStream
inputStream
=
new
DataSourceInputStream
(
dataSource
,
dataSpec
))
{
try
(
DataSourceInputStream
inputStream
=
new
DataSourceInputStream
(
dataSource
,
dataSpec
))
{
bytes
=
Util
.
toByteArray
(
inputStream
);
byte
[]
bytes
=
Util
.
toByteArray
(
inputStream
);
}
catch
(
IOException
e
)
{
assertThat
(
bytes
).
isEqualTo
(
expected
);
// Ignore
}
}
assertThat
(
bytes
).
isEqualTo
(
expected
);
}
}
/** Asserts that the cache is empty. */
/** Asserts that the cache is empty. */
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/ExoHostedTest.java
View file @
cda6cba5
...
@@ -18,9 +18,9 @@ package com.google.android.exoplayer2.testutil;
...
@@ -18,9 +18,9 @@ package com.google.android.exoplayer2.testutil;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertWithMessage
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertWithMessage
;
import
android.os.ConditionVariable
;
import
android.os.ConditionVariable
;
import
android.os.Looper
;
import
android.os.SystemClock
;
import
android.os.SystemClock
;
import
android.view.Surface
;
import
android.view.Surface
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.C
;
import
com.google.android.exoplayer2.DefaultRenderersFactory
;
import
com.google.android.exoplayer2.DefaultRenderersFactory
;
import
com.google.android.exoplayer2.ExoPlaybackException
;
import
com.google.android.exoplayer2.ExoPlaybackException
;
...
@@ -41,6 +41,8 @@ import com.google.android.exoplayer2.util.EventLogger;
...
@@ -41,6 +41,8 @@ import com.google.android.exoplayer2.util.EventLogger;
import
com.google.android.exoplayer2.util.HandlerWrapper
;
import
com.google.android.exoplayer2.util.HandlerWrapper
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
org.checkerframework.checker.nullness.qual.EnsuresNonNullIf
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
/** A {@link HostedTest} for {@link ExoPlayer} playback tests. */
/** A {@link HostedTest} for {@link ExoPlayer} playback tests. */
public
abstract
class
ExoHostedTest
implements
AnalyticsListener
,
HostedTest
{
public
abstract
class
ExoHostedTest
implements
AnalyticsListener
,
HostedTest
{
...
@@ -64,12 +66,12 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
...
@@ -64,12 +66,12 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
private
final
DecoderCounters
audioDecoderCounters
;
private
final
DecoderCounters
audioDecoderCounters
;
private
final
ConditionVariable
testFinished
;
private
final
ConditionVariable
testFinished
;
private
ActionSchedule
pendingSchedule
;
@Nullable
private
ActionSchedule
pendingSchedule
;
private
HandlerWrapper
actionHandl
er
;
private
@MonotonicNonNull
SimpleExoPlayer
play
er
;
private
DefaultTrackSelector
trackSelecto
r
;
private
@MonotonicNonNull
HandlerWrapper
actionHandle
r
;
private
SimpleExoPlayer
playe
r
;
private
@MonotonicNonNull
DefaultTrackSelector
trackSelecto
r
;
private
Surface
surface
;
private
@MonotonicNonNull
Surface
surface
;
private
ExoPlaybackException
playerError
;
private
@MonotonicNonNull
ExoPlaybackException
playerError
;
private
boolean
playerWasPrepared
;
private
boolean
playerWasPrepared
;
private
boolean
playing
;
private
boolean
playing
;
...
@@ -115,7 +117,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
...
@@ -115,7 +117,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
* @param schedule The schedule.
* @param schedule The schedule.
*/
*/
public
final
void
setSchedule
(
ActionSchedule
schedule
)
{
public
final
void
setSchedule
(
ActionSchedule
schedule
)
{
if
(
player
==
null
)
{
if
(
!
isStarted
()
)
{
pendingSchedule
=
schedule
;
pendingSchedule
=
schedule
;
}
else
{
}
else
{
schedule
.
start
(
player
,
trackSelector
,
surface
,
actionHandler
,
/* callback= */
null
);
schedule
.
start
(
player
,
trackSelector
,
surface
,
actionHandler
,
/* callback= */
null
);
...
@@ -135,7 +137,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
...
@@ -135,7 +137,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
player
.
addAnalyticsListener
(
this
);
player
.
addAnalyticsListener
(
this
);
player
.
addAnalyticsListener
(
new
EventLogger
(
trackSelector
,
tag
));
player
.
addAnalyticsListener
(
new
EventLogger
(
trackSelector
,
tag
));
// Schedule any pending actions.
// Schedule any pending actions.
actionHandler
=
Clock
.
DEFAULT
.
createHandler
(
Looper
.
my
Looper
(),
/* callback= */
null
);
actionHandler
=
Clock
.
DEFAULT
.
createHandler
(
Util
.
get
Looper
(),
/* callback= */
null
);
if
(
pendingSchedule
!=
null
)
{
if
(
pendingSchedule
!=
null
)
{
pendingSchedule
.
start
(
player
,
trackSelector
,
surface
,
actionHandler
,
/* callback= */
null
);
pendingSchedule
.
start
(
player
,
trackSelector
,
surface
,
actionHandler
,
/* callback= */
null
);
pendingSchedule
=
null
;
pendingSchedule
=
null
;
...
@@ -216,13 +218,12 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
...
@@ -216,13 +218,12 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
// Internal logic
// Internal logic
private
boolean
stopTest
()
{
private
boolean
stopTest
()
{
if
(
player
==
null
)
{
if
(
!
isStarted
()
)
{
return
false
;
return
false
;
}
}
actionHandler
.
removeCallbacksAndMessages
(
null
);
actionHandler
.
removeCallbacksAndMessages
(
null
);
sourceDurationMs
=
player
.
getDuration
();
sourceDurationMs
=
player
.
getDuration
();
player
.
release
();
player
.
release
();
player
=
null
;
// We post opening of the finished condition so that any events posted to the main thread as a
// We post opening of the finished condition so that any events posted to the main thread as a
// result of player.release() are guaranteed to be handled before the test returns.
// result of player.release() are guaranteed to be handled before the test returns.
actionHandler
.
post
(
testFinished:
:
open
);
actionHandler
.
post
(
testFinished:
:
open
);
...
@@ -261,4 +262,17 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
...
@@ -261,4 +262,17 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
protected
void
onTestFinished
(
DecoderCounters
audioCounters
,
DecoderCounters
videoCounters
)
{
protected
void
onTestFinished
(
DecoderCounters
audioCounters
,
DecoderCounters
videoCounters
)
{
// Do nothing. Subclasses may override to add clean-up and assertions.
// Do nothing. Subclasses may override to add clean-up and assertions.
}
}
@EnsuresNonNullIf
(
result
=
true
,
expression
=
{
"player"
,
"actionHandler"
,
"trackSelector"
,
"surface"
})
private
boolean
isStarted
()
{
if
(
player
==
null
)
{
return
false
;
}
Util
.
castNonNull
(
actionHandler
);
Util
.
castNonNull
(
trackSelector
);
Util
.
castNonNull
(
surface
);
return
true
;
}
}
}
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeAdaptiveMediaSource.java
View file @
cda6cba5
...
@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispat
...
@@ -23,6 +23,7 @@ import com.google.android.exoplayer2.source.MediaSourceEventListener.EventDispat
import
com.google.android.exoplayer2.source.TrackGroupArray
;
import
com.google.android.exoplayer2.source.TrackGroupArray
;
import
com.google.android.exoplayer2.upstream.Allocator
;
import
com.google.android.exoplayer2.upstream.Allocator
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.util.Util
;
/**
/**
* Fake {@link MediaSource} that provides a given timeline. Creating the period returns a
* Fake {@link MediaSource} that provides a given timeline. Creating the period returns a
...
@@ -47,7 +48,7 @@ public class FakeAdaptiveMediaSource extends FakeMediaSource {
...
@@ -47,7 +48,7 @@ public class FakeAdaptiveMediaSource extends FakeMediaSource {
Allocator
allocator
,
Allocator
allocator
,
EventDispatcher
eventDispatcher
,
EventDispatcher
eventDispatcher
,
@Nullable
TransferListener
transferListener
)
{
@Nullable
TransferListener
transferListener
)
{
Period
period
=
timeline
.
getPeriodByUid
(
id
.
periodUid
,
new
Period
());
Period
period
=
Util
.
castNonNull
(
getTimeline
())
.
getPeriodByUid
(
id
.
periodUid
,
new
Period
());
return
new
FakeAdaptiveMediaPeriod
(
return
new
FakeAdaptiveMediaPeriod
(
trackGroupArray
,
trackGroupArray
,
eventDispatcher
,
eventDispatcher
,
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeChunkSource.java
View file @
cda6cba5
...
@@ -31,8 +31,8 @@ import com.google.android.exoplayer2.trackselection.TrackSelection;
...
@@ -31,8 +31,8 @@ import com.google.android.exoplayer2.trackselection.TrackSelection;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSource
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.DataSpec
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.upstream.TransferListener
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
com.google.android.exoplayer2.util.MimeTypes
;
import
java.io.IOException
;
import
java.util.List
;
import
java.util.List
;
/**
/**
...
@@ -93,7 +93,7 @@ public final class FakeChunkSource implements ChunkSource {
...
@@ -93,7 +93,7 @@ public final class FakeChunkSource implements ChunkSource {
}
}
@Override
@Override
public
void
maybeThrowError
()
throws
IOException
{
public
void
maybeThrowError
()
{
// Do nothing.
// Do nothing.
}
}
...
@@ -128,7 +128,8 @@ public final class FakeChunkSource implements ChunkSource {
...
@@ -128,7 +128,8 @@ public final class FakeChunkSource implements ChunkSource {
long
endTimeUs
=
startTimeUs
+
dataSet
.
getChunkDuration
(
chunkIndex
);
long
endTimeUs
=
startTimeUs
+
dataSet
.
getChunkDuration
(
chunkIndex
);
int
trackGroupIndex
=
trackSelection
.
getIndexInTrackGroup
(
trackSelection
.
getSelectedIndex
());
int
trackGroupIndex
=
trackSelection
.
getIndexInTrackGroup
(
trackSelection
.
getSelectedIndex
());
String
uri
=
dataSet
.
getUri
(
trackGroupIndex
);
String
uri
=
dataSet
.
getUri
(
trackGroupIndex
);
Segment
fakeDataChunk
=
dataSet
.
getData
(
uri
).
getSegments
().
get
(
chunkIndex
);
Segment
fakeDataChunk
=
Assertions
.
checkStateNotNull
(
dataSet
.
getData
(
uri
)).
getSegments
().
get
(
chunkIndex
);
DataSpec
dataSpec
=
new
DataSpec
(
Uri
.
parse
(
uri
),
fakeDataChunk
.
byteOffset
,
DataSpec
dataSpec
=
new
DataSpec
(
Uri
.
parse
(
uri
),
fakeDataChunk
.
byteOffset
,
fakeDataChunk
.
length
,
null
);
fakeDataChunk
.
length
,
null
);
int
trackType
=
MimeTypes
.
getTrackType
(
selectedFormat
.
sampleMimeType
);
int
trackType
=
MimeTypes
.
getTrackType
(
selectedFormat
.
sampleMimeType
);
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaPeriod.java
View file @
cda6cba5
...
@@ -272,7 +272,7 @@ public class FakeMediaPeriod implements MediaPeriod {
...
@@ -272,7 +272,7 @@ public class FakeMediaPeriod implements MediaPeriod {
private
void
finishPreparation
()
{
private
void
finishPreparation
()
{
prepared
=
true
;
prepared
=
true
;
prepareCallback
.
onPrepared
(
this
);
Util
.
castNonNull
(
prepareCallback
)
.
onPrepared
(
this
);
eventDispatcher
.
loadCompleted
(
eventDispatcher
.
loadCompleted
(
FAKE_DATA_SPEC
,
FAKE_DATA_SPEC
,
FAKE_DATA_SPEC
.
uri
,
FAKE_DATA_SPEC
.
uri
,
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/FakeMediaSource.java
View file @
cda6cba5
...
@@ -43,6 +43,7 @@ import java.io.IOException;
...
@@ -43,6 +43,7 @@ import java.io.IOException;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.List
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
/**
/**
* Fake {@link MediaSource} that provides a given timeline. Creating the period will return a {@link
* Fake {@link MediaSource} that provides a given timeline. Creating the period will return a {@link
...
@@ -73,17 +74,17 @@ public class FakeMediaSource extends BaseMediaSource {
...
@@ -73,17 +74,17 @@ public class FakeMediaSource extends BaseMediaSource {
private
final
ArrayList
<
FakeMediaPeriod
>
activeMediaPeriods
;
private
final
ArrayList
<
FakeMediaPeriod
>
activeMediaPeriods
;
private
final
ArrayList
<
MediaPeriodId
>
createdMediaPeriods
;
private
final
ArrayList
<
MediaPeriodId
>
createdMediaPeriods
;
pr
otected
Timeline
timeline
;
pr
ivate
@MonotonicNonNull
Timeline
timeline
;
private
boolean
preparedSource
;
private
boolean
preparedSource
;
private
boolean
releasedSource
;
private
boolean
releasedSource
;
private
Handler
sourceInfoRefreshHandler
;
@Nullable
private
Handler
sourceInfoRefreshHandler
;
@Nullable
private
TransferListener
transferListener
;
@Nullable
private
TransferListener
transferListener
;
/**
/**
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with a
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with a
* {@link TrackGroupArray} using the given {@link Format}s. The provided {@link Timeline} may be
* {@link TrackGroupArray} using the given {@link Format}s. The provided {@link Timeline} may be
* null to prevent an immediate source info refresh message when preparing the media source. It
* null to prevent an immediate source info refresh message when preparing the media source. It
* can be manually set later using {@link #setNewSourceInfo(Timeline
, Object
)}.
* can be manually set later using {@link #setNewSourceInfo(Timeline)}.
*/
*/
public
FakeMediaSource
(
@Nullable
Timeline
timeline
,
Format
...
formats
)
{
public
FakeMediaSource
(
@Nullable
Timeline
timeline
,
Format
...
formats
)
{
this
(
timeline
,
buildTrackGroupArray
(
formats
));
this
(
timeline
,
buildTrackGroupArray
(
formats
));
...
@@ -93,20 +94,29 @@ public class FakeMediaSource extends BaseMediaSource {
...
@@ -93,20 +94,29 @@ public class FakeMediaSource extends BaseMediaSource {
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with the
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with the
* given {@link TrackGroupArray}. The provided {@link Timeline} may be null to prevent an
* given {@link TrackGroupArray}. The provided {@link Timeline} may be null to prevent an
* immediate source info refresh message when preparing the media source. It can be manually set
* immediate source info refresh message when preparing the media source. It can be manually set
* later using {@link #setNewSourceInfo(Timeline
, Object
)}.
* later using {@link #setNewSourceInfo(Timeline)}.
*/
*/
public
FakeMediaSource
(
@Nullable
Timeline
timeline
,
TrackGroupArray
trackGroupArray
)
{
public
FakeMediaSource
(
@Nullable
Timeline
timeline
,
TrackGroupArray
trackGroupArray
)
{
this
.
timeline
=
timeline
;
if
(
timeline
!=
null
)
{
this
.
timeline
=
timeline
;
}
this
.
trackGroupArray
=
trackGroupArray
;
this
.
activeMediaPeriods
=
new
ArrayList
<>();
this
.
activeMediaPeriods
=
new
ArrayList
<>();
this
.
createdMediaPeriods
=
new
ArrayList
<>();
this
.
createdMediaPeriods
=
new
ArrayList
<>();
this
.
trackGroupArray
=
trackGroupArray
;
}
@Nullable
protected
Timeline
getTimeline
()
{
return
timeline
;
}
}
@Override
@Override
@Nullable
@Nullable
public
Object
getTag
()
{
public
Object
getTag
()
{
boolean
hasTimeline
=
timeline
!=
null
&&
!
timeline
.
isEmpty
();
if
(
timeline
==
null
||
timeline
.
isEmpty
())
{
return
hasTimeline
?
timeline
.
getWindow
(
0
,
new
Timeline
.
Window
()).
tag
:
null
;
return
null
;
}
return
timeline
.
getWindow
(
0
,
new
Timeline
.
Window
()).
tag
;
}
}
@Nullable
@Nullable
...
@@ -143,7 +153,7 @@ public class FakeMediaSource extends BaseMediaSource {
...
@@ -143,7 +153,7 @@ public class FakeMediaSource extends BaseMediaSource {
public
MediaPeriod
createPeriod
(
MediaPeriodId
id
,
Allocator
allocator
,
long
startPositionUs
)
{
public
MediaPeriod
createPeriod
(
MediaPeriodId
id
,
Allocator
allocator
,
long
startPositionUs
)
{
assertThat
(
preparedSource
).
isTrue
();
assertThat
(
preparedSource
).
isTrue
();
assertThat
(
releasedSource
).
isFalse
();
assertThat
(
releasedSource
).
isFalse
();
int
periodIndex
=
timeline
.
getIndexOfPeriod
(
id
.
periodUid
);
int
periodIndex
=
Util
.
castNonNull
(
timeline
)
.
getIndexOfPeriod
(
id
.
periodUid
);
Assertions
.
checkArgument
(
periodIndex
!=
C
.
INDEX_UNSET
);
Assertions
.
checkArgument
(
periodIndex
!=
C
.
INDEX_UNSET
);
Period
period
=
timeline
.
getPeriod
(
periodIndex
,
new
Period
());
Period
period
=
timeline
.
getPeriod
(
periodIndex
,
new
Period
());
EventDispatcher
eventDispatcher
=
EventDispatcher
eventDispatcher
=
...
@@ -171,15 +181,15 @@ public class FakeMediaSource extends BaseMediaSource {
...
@@ -171,15 +181,15 @@ public class FakeMediaSource extends BaseMediaSource {
assertThat
(
activeMediaPeriods
.
isEmpty
()).
isTrue
();
assertThat
(
activeMediaPeriods
.
isEmpty
()).
isTrue
();
releasedSource
=
true
;
releasedSource
=
true
;
preparedSource
=
false
;
preparedSource
=
false
;
sourceInfoRefreshHandler
.
removeCallbacksAndMessages
(
null
);
Util
.
castNonNull
(
sourceInfoRefreshHandler
)
.
removeCallbacksAndMessages
(
null
);
sourceInfoRefreshHandler
=
null
;
sourceInfoRefreshHandler
=
null
;
}
}
/**
/**
* Sets a new timeline
and manifest. If the source is already prepared, this triggers a source
* Sets a new timeline
. If the source is already prepared, this triggers a source info refresh
*
info refresh
message being sent to the listener.
* message being sent to the listener.
*/
*/
public
synchronized
void
setNewSourceInfo
(
final
Timeline
newTimeline
,
final
Object
newManifest
)
{
public
synchronized
void
setNewSourceInfo
(
final
Timeline
newTimeline
)
{
if
(
sourceInfoRefreshHandler
!=
null
)
{
if
(
sourceInfoRefreshHandler
!=
null
)
{
sourceInfoRefreshHandler
.
post
(
sourceInfoRefreshHandler
.
post
(
()
->
{
()
->
{
...
@@ -238,7 +248,7 @@ public class FakeMediaSource extends BaseMediaSource {
...
@@ -238,7 +248,7 @@ public class FakeMediaSource extends BaseMediaSource {
}
}
private
void
finishSourcePreparation
()
{
private
void
finishSourcePreparation
()
{
refreshSourceInfo
(
timeline
);
refreshSourceInfo
(
Assertions
.
checkStateNotNull
(
timeline
)
);
if
(!
timeline
.
isEmpty
())
{
if
(!
timeline
.
isEmpty
())
{
MediaLoadData
mediaLoadData
=
MediaLoadData
mediaLoadData
=
new
MediaLoadData
(
new
MediaLoadData
(
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/HostActivity.java
View file @
cda6cba5
...
@@ -29,9 +29,11 @@ import android.view.Surface;
...
@@ -29,9 +29,11 @@ import android.view.Surface;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceHolder
;
import
android.view.SurfaceView
;
import
android.view.SurfaceView
;
import
android.view.Window
;
import
android.view.Window
;
import
androidx.annotation.Nullable
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Assertions
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Log
;
import
com.google.android.exoplayer2.util.Util
;
import
com.google.android.exoplayer2.util.Util
;
import
org.checkerframework.checker.nullness.qual.MonotonicNonNull
;
/** A host activity for performing playback tests. */
/** A host activity for performing playback tests. */
public
final
class
HostActivity
extends
Activity
implements
SurfaceHolder
.
Callback
{
public
final
class
HostActivity
extends
Activity
implements
SurfaceHolder
.
Callback
{
...
@@ -81,13 +83,13 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
...
@@ -81,13 +83,13 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
private
static
final
String
LOCK_TAG
=
"ExoPlayerTestUtil:"
+
TAG
;
private
static
final
String
LOCK_TAG
=
"ExoPlayerTestUtil:"
+
TAG
;
private
static
final
long
START_TIMEOUT_MS
=
5000
;
private
static
final
long
START_TIMEOUT_MS
=
5000
;
private
WakeLock
wakeLock
;
@Nullable
private
WakeLock
wakeLock
;
private
WifiLock
wifiLock
;
@Nullable
private
WifiLock
wifiLock
;
private
SurfaceView
surfaceView
;
private
@MonotonicNonNull
SurfaceView
surfaceView
;
private
HostedTest
hostedTest
;
@Nullable
private
HostedTest
hostedTest
;
private
boolean
hostedTestStarted
;
private
boolean
hostedTestStarted
;
private
ConditionVariable
hostedTestStartedCondition
;
private
@MonotonicNonNull
ConditionVariable
hostedTestStartedCondition
;
private
boolean
forcedStopped
;
private
boolean
forcedStopped
;
/**
/**
...
@@ -161,7 +163,7 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
...
@@ -161,7 +163,7 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
// Activity lifecycle
// Activity lifecycle
@Override
@Override
public
void
onCreate
(
Bundle
savedInstanceState
)
{
public
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
requestWindowFeature
(
Window
.
FEATURE_NO_TITLE
);
setContentView
(
setContentView
(
...
@@ -174,10 +176,14 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
...
@@ -174,10 +176,14 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
@Override
@Override
public
void
onStart
()
{
public
void
onStart
()
{
Context
appContext
=
getApplicationContext
();
Context
appContext
=
getApplicationContext
();
WifiManager
wifiManager
=
(
WifiManager
)
appContext
.
getSystemService
(
Context
.
WIFI_SERVICE
);
WifiManager
wifiManager
=
Assertions
.
checkStateNotNull
(
(
WifiManager
)
appContext
.
getSystemService
(
Context
.
WIFI_SERVICE
));
wifiLock
=
wifiManager
.
createWifiLock
(
WifiManager
.
WIFI_MODE_FULL_HIGH_PERF
,
LOCK_TAG
);
wifiLock
=
wifiManager
.
createWifiLock
(
WifiManager
.
WIFI_MODE_FULL_HIGH_PERF
,
LOCK_TAG
);
wifiLock
.
acquire
();
wifiLock
.
acquire
();
PowerManager
powerManager
=
(
PowerManager
)
appContext
.
getSystemService
(
Context
.
POWER_SERVICE
);
PowerManager
powerManager
=
Assertions
.
checkStateNotNull
(
(
PowerManager
)
appContext
.
getSystemService
(
Context
.
POWER_SERVICE
));
wakeLock
=
powerManager
.
newWakeLock
(
PowerManager
.
PARTIAL_WAKE_LOCK
,
LOCK_TAG
);
wakeLock
=
powerManager
.
newWakeLock
(
PowerManager
.
PARTIAL_WAKE_LOCK
,
LOCK_TAG
);
wakeLock
.
acquire
();
wakeLock
.
acquire
();
super
.
onStart
();
super
.
onStart
();
...
@@ -197,10 +203,14 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
...
@@ -197,10 +203,14 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
if
(
Util
.
SDK_INT
>
23
)
{
if
(
Util
.
SDK_INT
>
23
)
{
maybeStopHostedTest
();
maybeStopHostedTest
();
}
}
wakeLock
.
release
();
if
(
wakeLock
!=
null
)
{
wakeLock
=
null
;
wakeLock
.
release
();
wifiLock
.
release
();
wakeLock
=
null
;
wifiLock
=
null
;
}
if
(
wifiLock
!=
null
)
{
wifiLock
.
release
();
wifiLock
=
null
;
}
}
}
// SurfaceHolder.Callback
// SurfaceHolder.Callback
...
@@ -226,12 +236,12 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
...
@@ -226,12 +236,12 @@ public final class HostActivity extends Activity implements SurfaceHolder.Callba
if
(
hostedTest
==
null
||
hostedTestStarted
)
{
if
(
hostedTest
==
null
||
hostedTestStarted
)
{
return
;
return
;
}
}
Surface
surface
=
surfaceView
.
getHolder
().
getSurface
();
@Nullable
Surface
surface
=
Util
.
castNonNull
(
surfaceView
)
.
getHolder
().
getSurface
();
if
(
surface
!=
null
&&
surface
.
isValid
())
{
if
(
surface
!=
null
&&
surface
.
isValid
())
{
hostedTestStarted
=
true
;
hostedTestStarted
=
true
;
Log
.
d
(
TAG
,
"Starting test."
);
Log
.
d
(
TAG
,
"Starting test."
);
hostedTest
.
onStart
(
this
,
surface
);
Util
.
castNonNull
(
hostedTest
)
.
onStart
(
this
,
surface
);
hostedTestStartedCondition
.
open
();
Util
.
castNonNull
(
hostedTestStartedCondition
)
.
open
();
}
}
}
}
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/MediaPeriodAsserts.java
View file @
cda6cba5
...
@@ -187,7 +187,7 @@ public final class MediaPeriodAsserts {
...
@@ -187,7 +187,7 @@ public final class MediaPeriodAsserts {
}
}
private
static
TrackGroupArray
getTrackGroups
(
MediaPeriod
mediaPeriod
)
{
private
static
TrackGroupArray
getTrackGroups
(
MediaPeriod
mediaPeriod
)
{
AtomicReference
<
TrackGroupArray
>
trackGroupArray
=
new
AtomicReference
<>(
null
);
AtomicReference
<
TrackGroupArray
>
trackGroupArray
=
new
AtomicReference
<>();
DummyMainThread
dummyMainThread
=
new
DummyMainThread
();
DummyMainThread
dummyMainThread
=
new
DummyMainThread
();
ConditionVariable
preparedCondition
=
new
ConditionVariable
();
ConditionVariable
preparedCondition
=
new
ConditionVariable
();
dummyMainThread
.
runOnMainThread
(
dummyMainThread
.
runOnMainThread
(
...
...
testutils/src/main/java/com/google/android/exoplayer2/testutil/package-info.java
0 → 100644
View file @
cda6cba5
/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NonNullApi
package
com
.
google
.
android
.
exoplayer2
.
testutil
;
import
com.google.android.exoplayer2.util.NonNullApi
;
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