mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Test playback of empty timeline completes successfully
------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=142157778
This commit is contained in:
parent
5bb1d5dc99
commit
588124da76
1 changed files with 25 additions and 18 deletions
|
|
@ -31,6 +31,7 @@ import com.google.android.exoplayer2.upstream.Allocator;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
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.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
@ -48,12 +49,25 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
*/
|
*/
|
||||||
private static final int TIMEOUT_MS = 10000;
|
private static final int TIMEOUT_MS = 10000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests playback of a source that exposes a single period.
|
||||||
|
*/
|
||||||
public void testPlayToEnd() throws Exception {
|
public void testPlayToEnd() throws Exception {
|
||||||
PlayerWrapper playerWrapper = new PlayerWrapper();
|
PlayerWrapper playerWrapper = new PlayerWrapper();
|
||||||
Format format = Format.createVideoSampleFormat(null, MimeTypes.VIDEO_H264, null,
|
Format format = Format.createVideoSampleFormat(null, MimeTypes.VIDEO_H264, null,
|
||||||
Format.NO_VALUE, Format.NO_VALUE, 1280, 720, Format.NO_VALUE, null, null);
|
Format.NO_VALUE, Format.NO_VALUE, 1280, 720, Format.NO_VALUE, null, null);
|
||||||
playerWrapper.setup(new SinglePeriodTimeline(0, false), new Object(), format);
|
playerWrapper.setup(new SinglePeriodTimeline(0, false), null, format);
|
||||||
playerWrapper.blockUntilEndedOrError(TIMEOUT_MS);
|
playerWrapper.blockUntilEnded(TIMEOUT_MS);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests playback of a source that exposes an empty timeline. Playback is expected to end without
|
||||||
|
* error.
|
||||||
|
*/
|
||||||
|
public void testPlayEmptyTimeline() throws Exception {
|
||||||
|
PlayerWrapper playerWrapper = new PlayerWrapper();
|
||||||
|
playerWrapper.setup(Timeline.EMPTY, null, null);
|
||||||
|
playerWrapper.blockUntilEnded(TIMEOUT_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,12 +95,11 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
|
|
||||||
// Called on the test thread.
|
// Called on the test thread.
|
||||||
|
|
||||||
public void blockUntilEndedOrError(long timeoutMs) throws Exception {
|
public void blockUntilEnded(long timeoutMs) throws Exception {
|
||||||
if (!endedCountDownLatch.await(timeoutMs, TimeUnit.MILLISECONDS)) {
|
if (!endedCountDownLatch.await(timeoutMs, TimeUnit.MILLISECONDS)) {
|
||||||
exception = new TimeoutException("Test playback timed out.");
|
exception = new TimeoutException("Test playback timed out.");
|
||||||
}
|
}
|
||||||
release();
|
release();
|
||||||
|
|
||||||
// Throw any pending exception (from playback, timing out or releasing).
|
// Throw any pending exception (from playback, timing out or releasing).
|
||||||
if (exception != null) {
|
if (exception != null) {
|
||||||
throw exception;
|
throw exception;
|
||||||
|
|
@ -194,17 +207,16 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
private final Timeline timeline;
|
private final Timeline timeline;
|
||||||
private final Object manifest;
|
private final Object manifest;
|
||||||
private final Format format;
|
private final Format format;
|
||||||
|
private final ArrayList<FakeMediaPeriod> activeMediaPeriods;
|
||||||
|
|
||||||
private FakeMediaPeriod mediaPeriod;
|
|
||||||
private boolean preparedSource;
|
private boolean preparedSource;
|
||||||
private boolean releasedPeriod;
|
|
||||||
private boolean releasedSource;
|
private boolean releasedSource;
|
||||||
|
|
||||||
public FakeMediaSource(Timeline timeline, Object manifest, Format format) {
|
public FakeMediaSource(Timeline timeline, Object manifest, Format format) {
|
||||||
Assertions.checkArgument(timeline.getPeriodCount() == 1);
|
|
||||||
this.timeline = timeline;
|
this.timeline = timeline;
|
||||||
this.manifest = manifest;
|
this.manifest = manifest;
|
||||||
this.format = format;
|
this.format = format;
|
||||||
|
activeMediaPeriods = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -221,33 +233,29 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
public MediaPeriod createPeriod(int index, Allocator allocator, long positionUs) {
|
||||||
|
Assertions.checkIndex(index, 0, timeline.getPeriodCount());
|
||||||
assertTrue(preparedSource);
|
assertTrue(preparedSource);
|
||||||
assertNull(mediaPeriod);
|
|
||||||
assertFalse(releasedPeriod);
|
|
||||||
assertFalse(releasedSource);
|
assertFalse(releasedSource);
|
||||||
assertEquals(0, index);
|
assertEquals(0, index);
|
||||||
assertEquals(0, positionUs);
|
assertEquals(0, positionUs);
|
||||||
mediaPeriod = new FakeMediaPeriod(format);
|
FakeMediaPeriod mediaPeriod = new FakeMediaPeriod(format);
|
||||||
|
activeMediaPeriods.add(mediaPeriod);
|
||||||
return mediaPeriod;
|
return mediaPeriod;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releasePeriod(MediaPeriod mediaPeriod) {
|
public void releasePeriod(MediaPeriod mediaPeriod) {
|
||||||
assertTrue(preparedSource);
|
assertTrue(preparedSource);
|
||||||
assertNotNull(this.mediaPeriod);
|
|
||||||
assertFalse(releasedPeriod);
|
|
||||||
assertFalse(releasedSource);
|
assertFalse(releasedSource);
|
||||||
assertEquals(this.mediaPeriod, mediaPeriod);
|
assertTrue(activeMediaPeriods.remove(mediaPeriod));
|
||||||
this.mediaPeriod.release();
|
((FakeMediaPeriod) mediaPeriod).release();
|
||||||
releasedPeriod = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseSource() {
|
public void releaseSource() {
|
||||||
assertTrue(preparedSource);
|
assertTrue(preparedSource);
|
||||||
assertNotNull(this.mediaPeriod);
|
|
||||||
assertTrue(releasedPeriod);
|
|
||||||
assertFalse(releasedSource);
|
assertFalse(releasedSource);
|
||||||
|
assertTrue(activeMediaPeriods.isEmpty());
|
||||||
releasedSource = true;
|
releasedSource = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,7 +408,6 @@ public final class ExoPlayerTest extends TestCase {
|
||||||
|
|
||||||
public FakeVideoRenderer(Format expectedFormat) {
|
public FakeVideoRenderer(Format expectedFormat) {
|
||||||
super(C.TRACK_TYPE_VIDEO);
|
super(C.TRACK_TYPE_VIDEO);
|
||||||
Assertions.checkArgument(MimeTypes.isVideo(expectedFormat.sampleMimeType));
|
|
||||||
this.expectedFormat = expectedFormat;
|
this.expectedFormat = expectedFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue