Commit e0649db5 by andrewlewis Committed by Oliver Woodman

Handle input format changes in SimpleDecoderAudioRenderer.

This is implemented in the same way as in MediaCodecRenderer.

Move codec != null guard into feedInputBuffer to handle the case of an input
format change with no dequeued buffers where the codec can't be reinitialized
immediately.

Issue: #2111

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=140864942
parent 7ea16a6a
...@@ -472,6 +472,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -472,6 +472,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
@Override @Override
public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException { public void render(long positionUs, long elapsedRealtimeUs) throws ExoPlaybackException {
if (outputStreamEnded) {
return;
}
if (format == null) { if (format == null) {
readFormat(); readFormat();
} }
...@@ -479,9 +482,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -479,9 +482,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
if (codec != null) { if (codec != null) {
TraceUtil.beginSection("drainAndFeed"); TraceUtil.beginSection("drainAndFeed");
while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {} while (drainOutputBuffer(positionUs, elapsedRealtimeUs)) {}
if (codec != null) { while (feedInputBuffer()) {}
while (feedInputBuffer()) {}
}
TraceUtil.endSection(); TraceUtil.endSection();
} else if (format != null) { } else if (format != null) {
skipToKeyframeBefore(positionUs); skipToKeyframeBefore(positionUs);
...@@ -531,10 +532,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -531,10 +532,9 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
* @throws ExoPlaybackException If an error occurs feeding the input buffer. * @throws ExoPlaybackException If an error occurs feeding the input buffer.
*/ */
private boolean feedInputBuffer() throws ExoPlaybackException { private boolean feedInputBuffer() throws ExoPlaybackException {
if (inputStreamEnded if (codec == null || codecReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM
|| codecReinitializationState == REINITIALIZATION_STATE_WAIT_END_OF_STREAM) { || inputStreamEnded) {
// The input stream has ended, or we need to re-initialize the codec but are still waiting // We need to reinitialize the codec or the input stream has ended.
// for the existing codec to output any final output buffers.
return false; return false;
} }
...@@ -848,10 +848,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -848,10 +848,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs) private boolean drainOutputBuffer(long positionUs, long elapsedRealtimeUs)
throws ExoPlaybackException { throws ExoPlaybackException {
if (outputStreamEnded) {
return false;
}
if (outputIndex < 0) { if (outputIndex < 0) {
outputIndex = codec.dequeueOutputBuffer(outputBufferInfo, getDequeueOutputBufferTimeoutUs()); outputIndex = codec.dequeueOutputBuffer(outputBufferInfo, getDequeueOutputBufferTimeoutUs());
if (outputIndex >= 0) { if (outputIndex >= 0) {
......
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