Allow multiple Formats per TrackGroup in testutil fake classes.

This enables adaptive media test cases using TrackGroups with multiple
Formats.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162182005
This commit is contained in:
tonihei 2017-07-17 01:42:21 -07:00 committed by Oliver Woodman
parent 8399de4706
commit 508db5fd0a
5 changed files with 39 additions and 19 deletions

View File

@ -57,7 +57,7 @@ public final class ExoPlayerTest extends TestCase {
ExoPlayerWrapper playerWrapper = new ExoPlayerWrapper();
Timeline timeline = Timeline.EMPTY;
MediaSource mediaSource = new FakeMediaSource(timeline, null);
FakeRenderer renderer = new FakeRenderer(null);
FakeRenderer renderer = new FakeRenderer();
playerWrapper.setup(mediaSource, renderer);
playerWrapper.blockUntilEnded(TIMEOUT_MS);
assertEquals(0, playerWrapper.positionDiscontinuityCount);

View File

@ -24,8 +24,8 @@ import com.google.android.exoplayer2.util.MediaClock;
*/
public abstract class FakeMediaClockRenderer extends FakeRenderer implements MediaClock {
public FakeMediaClockRenderer(Format expectedFormat) {
super(expectedFormat);
public FakeMediaClockRenderer(Format... expectedFormats) {
super(expectedFormats);
}
@Override

View File

@ -75,11 +75,13 @@ public final class FakeMediaPeriod implements MediaPeriod {
for (int i = 0; i < rendererCount; i++) {
if (streams[i] == null && selections[i] != null) {
TrackSelection selection = selections[i];
Assert.assertEquals(1, selection.length());
Assert.assertEquals(0, selection.getIndexInTrackGroup(0));
Assert.assertTrue(1 <= selection.length());
TrackGroup trackGroup = selection.getTrackGroup();
Assert.assertTrue(trackGroupArray.indexOf(trackGroup) != C.INDEX_UNSET);
streams[i] = new FakeSampleStream(trackGroup.getFormat(0));
int indexInTrackGroup = selection.getIndexInTrackGroup(selection.getSelectedIndex());
Assert.assertTrue(0 <= indexInTrackGroup);
Assert.assertTrue(indexInTrackGroup < trackGroup.length);
streams[i] = new FakeSampleStream(selection.getSelectedFormat());
streamResetFlags[i] = true;
}
}

View File

@ -42,15 +42,23 @@ public class FakeMediaSource implements MediaSource {
private boolean preparedSource;
private boolean releasedSource;
/**
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with a
* {@link TrackGroupArray} using the given {@link Format}s.
*/
public FakeMediaSource(Timeline timeline, Object manifest, Format... formats) {
this(timeline, manifest, buildTrackGroupArray(formats));
}
/**
* Creates a {@link FakeMediaSource}. This media source creates {@link FakeMediaPeriod}s with the
* given {@link TrackGroupArray}.
*/
public FakeMediaSource(Timeline timeline, Object manifest, TrackGroupArray trackGroupArray) {
this.timeline = timeline;
this.manifest = manifest;
TrackGroup[] trackGroups = new TrackGroup[formats.length];
for (int i = 0; i < formats.length; i++) {
trackGroups[i] = new TrackGroup(formats[i]);
}
trackGroupArray = new TrackGroupArray(trackGroups);
activeMediaPeriods = new ArrayList<>();
this.activeMediaPeriods = new ArrayList<>();
this.trackGroupArray = trackGroupArray;
}
public void assertReleased() {
@ -96,4 +104,11 @@ public class FakeMediaSource implements MediaSource {
releasedSource = true;
}
private static TrackGroupArray buildTrackGroupArray(Format... formats) {
TrackGroup[] trackGroups = new TrackGroup[formats.length];
for (int i = 0; i < formats.length; i++) {
trackGroups[i] = new TrackGroup(formats[i]);
}
return new TrackGroupArray(trackGroups);
}
}

View File

@ -23,25 +23,28 @@ import com.google.android.exoplayer2.FormatHolder;
import com.google.android.exoplayer2.Renderer;
import com.google.android.exoplayer2.decoder.DecoderInputBuffer;
import com.google.android.exoplayer2.util.MimeTypes;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import junit.framework.Assert;
/**
* Fake {@link Renderer} that supports any format with the matching MIME type. The renderer
* verifies that it reads a given {@link Format}.
* verifies that it reads one of the given {@link Format}s.
*/
public class FakeRenderer extends BaseRenderer {
private final Format expectedFormat;
private final List<Format> expectedFormats;
public int positionResetCount;
public int formatReadCount;
public int bufferReadCount;
public boolean isEnded;
public FakeRenderer(Format expectedFormat) {
super(expectedFormat == null ? C.TRACK_TYPE_UNKNOWN
: MimeTypes.getTrackType(expectedFormat.sampleMimeType));
this.expectedFormat = expectedFormat;
public FakeRenderer(Format... expectedFormats) {
super(expectedFormats.length == 0 ? C.TRACK_TYPE_UNKNOWN
: MimeTypes.getTrackType(expectedFormats[0].sampleMimeType));
this.expectedFormats = Collections.unmodifiableList(Arrays.asList(expectedFormats));
}
@Override
@ -63,7 +66,7 @@ public class FakeRenderer extends BaseRenderer {
int result = readSource(formatHolder, buffer, false);
if (result == C.RESULT_FORMAT_READ) {
formatReadCount++;
Assert.assertEquals(expectedFormat, formatHolder.format);
Assert.assertTrue(expectedFormats.contains(formatHolder.format));
} else if (result == C.RESULT_BUFFER_READ) {
bufferReadCount++;
if (buffer.isEndOfStream()) {