Commit 958f12e2 by tonihei Committed by Oliver Woodman

Make isReady of FakeRenderer more realistic.

Currently the renderer is only ready when the input stream has more data to
read. Actual renderers, however, are also ready as long as their output buffer
contains some audio/video samples to play, roughly corresponding to the fact
that the playback time hasn't reached the timestamp of the last buffered
sample. Added a isready flag to FakeRenderer to simulate this behaviour.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=162343074
parent 4fd516e3
......@@ -35,16 +35,19 @@ import junit.framework.Assert;
public class FakeRenderer extends BaseRenderer {
private final List<Format> expectedFormats;
private final DecoderInputBuffer buffer;
public int positionResetCount;
public int formatReadCount;
public int bufferReadCount;
public boolean isEnded;
public boolean isReady;
public FakeRenderer(Format... expectedFormats) {
super(expectedFormats.length == 0 ? C.TRACK_TYPE_UNKNOWN
: MimeTypes.getTrackType(expectedFormats[0].sampleMimeType));
this.expectedFormats = Collections.unmodifiableList(Arrays.asList(expectedFormats));
this.buffer = new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
}
@Override
......@@ -55,29 +58,26 @@ public class FakeRenderer extends BaseRenderer {
@Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (isEnded) {
return;
}
// Verify the format matches the expected format.
FormatHolder formatHolder = new FormatHolder();
DecoderInputBuffer buffer =
new DecoderInputBuffer(DecoderInputBuffer.BUFFER_REPLACEMENT_MODE_NORMAL);
int result = readSource(formatHolder, buffer, false);
if (result == C.RESULT_FORMAT_READ) {
formatReadCount++;
Assert.assertTrue(expectedFormats.contains(formatHolder.format));
} else if (result == C.RESULT_BUFFER_READ) {
bufferReadCount++;
if (buffer.isEndOfStream()) {
isEnded = true;
if (!isEnded) {
// Verify the format matches the expected format.
FormatHolder formatHolder = new FormatHolder();
int result = readSource(formatHolder, buffer, false);
if (result == C.RESULT_FORMAT_READ) {
formatReadCount++;
Assert.assertTrue(expectedFormats.contains(formatHolder.format));
} else if (result == C.RESULT_BUFFER_READ) {
bufferReadCount++;
if (buffer.isEndOfStream()) {
isEnded = true;
}
}
}
isReady = buffer.timeUs >= positionUs;
}
@Override
public boolean isReady() {
return isSourceReady();
return isReady || isSourceReady();
}
@Override
......@@ -87,8 +87,8 @@ public class FakeRenderer extends BaseRenderer {
@Override
public int supportsFormat(Format format) throws ExoPlaybackException {
return getTrackType() == MimeTypes.getTrackType(format.sampleMimeType) ? FORMAT_HANDLED
: FORMAT_UNSUPPORTED_TYPE;
return getTrackType() == MimeTypes.getTrackType(format.sampleMimeType)
? (FORMAT_HANDLED | ADAPTIVE_SEAMLESS) : FORMAT_UNSUPPORTED_TYPE;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment