Skip to content

Commit

Permalink
Decide whether to release rather than flush in onInputFormatChanged
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
ojw28 authored and andrewlewis committed Nov 6, 2020
1 parent 1fb675e commit 1bcf1cf
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static String buildCustomDiagnosticInfo(int errorCode) {
@IntDef({
DRAIN_ACTION_NONE,
DRAIN_ACTION_FLUSH,
DRAIN_ACTION_UPDATE_DRM_SESSION,
DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION,
DRAIN_ACTION_REINITIALIZE
})
private @interface DrainAction {}
Expand All @@ -245,7 +245,7 @@ private static String buildCustomDiagnosticInfo(int errorCode) {
/** The codec should be flushed. */
private static final int DRAIN_ACTION_FLUSH = 1;
/** 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. */
private static final int DRAIN_ACTION_REINITIALIZE = 3;

Expand Down Expand Up @@ -839,12 +839,17 @@ protected boolean flushOrReleaseCodec() {
releaseCodec();
return true;
}
flushCodec();
return false;
}

/** Flushes the codec. */
private void flushCodec() {
try {
codecAdapter.flush();
} finally {
resetCodecStateForFlush();
}
return false;
}

/** Resets the renderer internal state after a codec flush. */
Expand Down Expand Up @@ -1652,7 +1657,11 @@ private boolean updateOperatingRateOrReinitializeCodec(Format format)
private void drainAndFlushCodec() {
if (codecReceivedBuffers) {
codecDrainState = DRAIN_STATE_SIGNAL_END_OF_STREAM;
codecDrainAction = DRAIN_ACTION_FLUSH;
if (codecNeedsFlushWorkaround || codecNeedsEosFlushWorkaround) {
codecDrainAction = DRAIN_ACTION_REINITIALIZE;
} else {
codecDrainAction = DRAIN_ACTION_FLUSH;
}
}
}

Expand All @@ -1666,7 +1675,11 @@ private void drainAndFlushCodec() {
private void drainAndUpdateCodecDrmSessionV23() throws ExoPlaybackException {
if (codecReceivedBuffers) {
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 {
// Nothing has been queued to the decoder, so we can do the update immediately.
updateDrmSessionV23();
Expand Down Expand Up @@ -1913,13 +1926,12 @@ private void processEndOfStream() throws ExoPlaybackException {
case DRAIN_ACTION_REINITIALIZE:
reinitializeCodec();
break;
case DRAIN_ACTION_UPDATE_DRM_SESSION:
if (!flushOrReinitializeCodec()) {
updateDrmSessionV23();
}
case DRAIN_ACTION_FLUSH_AND_UPDATE_DRM_SESSION:
flushCodec();
updateDrmSessionV23();
break;
case DRAIN_ACTION_FLUSH:
flushOrReinitializeCodec();
flushCodec();
break;
case DRAIN_ACTION_NONE:
default:
Expand Down

0 comments on commit 1bcf1cf

Please sign in to comment.