mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +00:00
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
This commit is contained in:
parent
4fd516e35b
commit
958f12e2cc
1 changed files with 19 additions and 19 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue