Class MediaSourceTestRunner
- java.lang.Object
-
- com.google.android.exoplayer2.testutil.MediaSourceTestRunner
-
public class MediaSourceTestRunner extends Object
A runner forMediaSource
tests.
-
-
Field Summary
Fields Modifier and Type Field Description static int
TIMEOUT_MS
-
Constructor Summary
Constructors Constructor Description MediaSourceTestRunner(MediaSource mediaSource, Allocator allocator)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
assertCompletedManifestLoads(Integer... windowIndices)
Asserts that the media source reported completed loads viaMediaSourceEventListener.onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)
for each specified window index and a null period id.void
assertCompletedMediaPeriodLoads(MediaSource.MediaPeriodId... mediaPeriodIds)
Asserts that the media source reported completed loads viaMediaSourceEventListener.onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)
for each specified media period id, and asserts that the associated window index matches the one in the last known timeline returned fromprepareSource()
,assertTimelineChange()
orassertTimelineChangeBlocking()
.void
assertNoTimelineChange()
Asserts that the source has not notified its listener of a timeline change since the last call toassertTimelineChangeBlocking()
orassertTimelineChange()
(or since the runner was created if neither method has been called).void
assertPrepareAndReleaseAllPeriods()
Creates and releases all periods (including ad periods) defined in the last timeline to be returned fromprepareSource()
,assertTimelineChange()
orassertTimelineChangeBlocking()
.Timeline
assertTimelineChange()
Asserts that the source has notified its listener of a single timeline change.Timeline
assertTimelineChangeBlocking()
Asserts that the source notifies its listener of a single timeline change.MediaPeriod
createPeriod(MediaSource.MediaPeriodId periodId)
CallsMediaSource.createPeriod(MediaSource.MediaPeriodId, Allocator, long)
with a zero start position on the playback thread, asserting that a non-nullMediaPeriod
is returned.MediaPeriod
createPeriod(MediaSource.MediaPeriodId periodId, long startPositionUs)
CallsMediaSource.createPeriod(MediaSource.MediaPeriodId, Allocator, long)
on the playback thread, asserting that a non-nullMediaPeriod
is returned.CountDownLatch
preparePeriod(MediaPeriod mediaPeriod, long positionUs)
CallsMediaPeriod.prepare(MediaPeriod.Callback, long)
on the playback thread and blocks until the method has been called.Timeline
prepareSource()
Prepares the source on the playback thread, asserting that it provides an initial timeline.void
release()
Releases the runner.void
releasePeriod(MediaPeriod mediaPeriod)
CallsMediaSource.releasePeriod(MediaPeriod)
on the playback thread.void
releaseSource()
CallsMediaSource.releaseSource(MediaSourceCaller)
on the playback thread.void
runOnPlaybackThread(Runnable runnable)
Runs the providedRunnable
on the playback thread, blocking until execution completes.
-
-
-
Field Detail
-
TIMEOUT_MS
public static final int TIMEOUT_MS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MediaSourceTestRunner
public MediaSourceTestRunner(MediaSource mediaSource, Allocator allocator)
- Parameters:
mediaSource
- The source under test.allocator
- The allocator to use during the test run.
-
-
Method Detail
-
runOnPlaybackThread
public void runOnPlaybackThread(Runnable runnable)
Runs the providedRunnable
on the playback thread, blocking until execution completes.- Parameters:
runnable
- TheRunnable
to run.
-
prepareSource
public Timeline prepareSource() throws IOException
Prepares the source on the playback thread, asserting that it provides an initial timeline.- Returns:
- The initial
Timeline
. - Throws:
IOException
-
createPeriod
public MediaPeriod createPeriod(MediaSource.MediaPeriodId periodId)
CallsMediaSource.createPeriod(MediaSource.MediaPeriodId, Allocator, long)
with a zero start position on the playback thread, asserting that a non-nullMediaPeriod
is returned.- Parameters:
periodId
- The id of the period to create.- Returns:
- The created
MediaPeriod
.
-
createPeriod
public MediaPeriod createPeriod(MediaSource.MediaPeriodId periodId, long startPositionUs)
CallsMediaSource.createPeriod(MediaSource.MediaPeriodId, Allocator, long)
on the playback thread, asserting that a non-nullMediaPeriod
is returned.- Parameters:
periodId
- The id of the period to create.startPositionUs
- The expected start position, in microseconds.- Returns:
- The created
MediaPeriod
.
-
preparePeriod
public CountDownLatch preparePeriod(MediaPeriod mediaPeriod, long positionUs)
CallsMediaPeriod.prepare(MediaPeriod.Callback, long)
on the playback thread and blocks until the method has been called.- Parameters:
mediaPeriod
- TheMediaPeriod
to prepare.positionUs
- The position at which to prepare.- Returns:
- A
CountDownLatch
that will be counted down when preparation completes.
-
releasePeriod
public void releasePeriod(MediaPeriod mediaPeriod)
CallsMediaSource.releasePeriod(MediaPeriod)
on the playback thread.- Parameters:
mediaPeriod
- TheMediaPeriod
to release.
-
releaseSource
public void releaseSource()
CallsMediaSource.releaseSource(MediaSourceCaller)
on the playback thread.
-
assertNoTimelineChange
public void assertNoTimelineChange()
Asserts that the source has not notified its listener of a timeline change since the last call toassertTimelineChangeBlocking()
orassertTimelineChange()
(or since the runner was created if neither method has been called).
-
assertTimelineChange
public Timeline assertTimelineChange()
Asserts that the source has notified its listener of a single timeline change.- Returns:
- The new
Timeline
.
-
assertTimelineChangeBlocking
public Timeline assertTimelineChangeBlocking()
Asserts that the source notifies its listener of a single timeline change. If the source has not yet notified its listener, it has up to the timeout passed to the constructor to do so.- Returns:
- The new
Timeline
.
-
assertPrepareAndReleaseAllPeriods
public void assertPrepareAndReleaseAllPeriods() throws InterruptedException
Creates and releases all periods (including ad periods) defined in the last timeline to be returned fromprepareSource()
,assertTimelineChange()
orassertTimelineChangeBlocking()
. TheMediaPeriodId.windowSequenceNumber
is set to the index of the window.- Throws:
InterruptedException
-
assertCompletedManifestLoads
public void assertCompletedManifestLoads(Integer... windowIndices)
Asserts that the media source reported completed loads viaMediaSourceEventListener.onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)
for each specified window index and a null period id. Also asserts that no other loads with media period id null are reported.
-
assertCompletedMediaPeriodLoads
public void assertCompletedMediaPeriodLoads(MediaSource.MediaPeriodId... mediaPeriodIds)
Asserts that the media source reported completed loads viaMediaSourceEventListener.onLoadCompleted(int, MediaPeriodId, LoadEventInfo, MediaLoadData)
for each specified media period id, and asserts that the associated window index matches the one in the last known timeline returned fromprepareSource()
,assertTimelineChange()
orassertTimelineChangeBlocking()
.
-
release
public void release()
Releases the runner. Should be called when the runner is no longer required.
-
-