Decide whether to release rather than flush in onInputFormatChanged

- This change removes the last piece of logic that could cause deferred
  codec release (i.e., where the decision to release was made in
  processEndOfStream rather than in onInputFormatChanged.
- After this change, whether the codec will be released as a result of
  a format change is always established in onInputFormatChanged.

PiperOrigin-RevId: 341012403
This commit is contained in:
olly 2020-11-06 10:10:23 +00:00 committed by Andrew Lewis
parent 1fb675e876
commit 1bcf1cf9f7

View File

@ -236,7 +236,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
@IntDef({ @IntDef({
DRAIN_ACTION_NONE, DRAIN_ACTION_NONE,
DRAIN_ACTION_FLUSH, DRAIN_ACTION_FLUSH,
DRAIN_ACTION_UPDATE_DRM_SESSION, DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION,
DRAIN_ACTION_REINITIALIZE DRAIN_ACTION_REINITIALIZE
}) })
private @interface DrainAction {} private @interface DrainAction {}
@ -245,7 +245,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
/** The codec should be flushed. */ /** The codec should be flushed. */
private static final int DRAIN_ACTION_FLUSH = 1; private static final int DRAIN_ACTION_FLUSH = 1;
/** The codec should be flushed and updated to use the pending DRM session. */ /** The codec should be flushed and updated to use the pending DRM session. */
private static final int DRAIN_ACTION_UPDATE_DRM_SESSION = 2; private static final int DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION = 2;
/** The codec should be reinitialized. */ /** The codec should be reinitialized. */
private static final int DRAIN_ACTION_REINITIALIZE = 3; private static final int DRAIN_ACTION_REINITIALIZE = 3;
@ -839,12 +839,17 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
releaseCodec(); releaseCodec();
return true; return true;
} }
flushCodec();
return false;
}
/** Flushes the codec. */
private void flushCodec() {
try { try {
codecAdapter.flush(); codecAdapter.flush();
} finally { } finally {
resetCodecStateForFlush(); resetCodecStateForFlush();
} }
return false;
} }
/** Resets the renderer internal state after a codec flush. */ /** Resets the renderer internal state after a codec flush. */
@ -1652,7 +1657,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
private void drainAndFlushCodec() { private void drainAndFlushCodec() {
if (codecReceivedBuffers) { if (codecReceivedBuffers) {
codecDrainState = DRAIN_STATE_SIGNAL_END_OF_STREAM; codecDrainState = DRAIN_STATE_SIGNAL_END_OF_STREAM;
codecDrainAction = DRAIN_ACTION_FLUSH; if (codecNeedsFlushWorkaround || codecNeedsEosFlushWorkaround) {
codecDrainAction = DRAIN_ACTION_REINITIALIZE;
} else {
codecDrainAction = DRAIN_ACTION_FLUSH;
}
} }
} }
@ -1666,7 +1675,11 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
private void drainAndUpdateCodecDrmSessionV23() throws ExoPlaybackException { private void drainAndUpdateCodecDrmSessionV23() throws ExoPlaybackException {
if (codecReceivedBuffers) { if (codecReceivedBuffers) {
codecDrainState = DRAIN_STATE_SIGNAL_END_OF_STREAM; codecDrainState = DRAIN_STATE_SIGNAL_END_OF_STREAM;
codecDrainAction = DRAIN_ACTION_UPDATE_DRM_SESSION; if (codecNeedsFlushWorkaround || codecNeedsEosFlushWorkaround) {
codecDrainAction = DRAIN_ACTION_REINITIALIZE;
} else {
codecDrainAction = DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION;
}
} else { } else {
// Nothing has been queued to the decoder, so we can do the update immediately. // Nothing has been queued to the decoder, so we can do the update immediately.
updateDrmSessionV23(); updateDrmSessionV23();
@ -1913,13 +1926,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
case DRAIN_ACTION_REINITIALIZE: case DRAIN_ACTION_REINITIALIZE:
reinitializeCodec(); reinitializeCodec();
break; break;
case DRAIN_ACTION_UPDATE_DRM_SESSION: case DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION:
if (!flushOrReinitializeCodec()) { flushCodec();
updateDrmSessionV23(); updateDrmSessionV23();
}
break; break;
case DRAIN_ACTION_FLUSH: case DRAIN_ACTION_FLUSH:
flushOrReinitializeCodec(); flushCodec();
break; break;
case DRAIN_ACTION_NONE: case DRAIN_ACTION_NONE:
default: default: