Keep secure MediaCodec instances when disabling the renderer

A renderer is disabled (without being reset) in two situations:
* When transitioning into a period that starts with a discontinuity
* When stopping the player with setForegroundMode(true)

Before this change the behaviour of `MediaCodecRenderer` when disabled
(but not reset) depended on whether the content being decoded had an
associated `DrmSession`:
* For content without an associated DRM session the MediaCodec instance
  was kept alive.
* For content with an associated DRM session, the MediaCodec instance
  was released. This was to prevent the DRM session from staying alive
  and continuing to make license refresh network requests while the
  player was stopped in 'foreground mode'.

This change removes the second bullet, and keeps MediaCodec instances
alive in both the secure and insecure case. This will result in the
DRM machinery making occasional license refresh network requests (at
a frequency defined by the license policy) while the player is stopped
and in 'foreground mode'. This network usage is considered to be a
'limited resource' as described by the `ExoPlayer#setForegroundMode`
javadoc.

This means that switches between secure content (or between secure and
clear content when `MediaItem.drmConfiguration.sessionForClearTypes`
indicates a secure decoder should be used for clear content) should
keep the same video decoder, thus avoiding the 'black flash' that occurs
on some devices when switching the surface away from a secure decoder.

Issue: #8842

#minor-release

PiperOrigin-RevId: 376825501
This commit is contained in:
ibaker 2021-06-01 15:11:25 +01:00 committed by Oliver Woodman
parent 1bf5a273ff
commit 58e307c6b0
2 changed files with 8 additions and 6 deletions

View File

@ -70,6 +70,13 @@
must be released without restoring them first.
* Ensure `DefaultDrmSession` instances keep working even after their
`DefaultDrmSessionManager` instance is released.
* Keep secure `MediaCodec` instances initialized when disabling (but not
resetting) `MediaCodecRenderer`. This helps re-use secure decoders in
more contexts, which avoids the 'black flash' caused by detaching a
`Surface` from a secure decoder on some devices
([#8842](https://github.com/google/ExoPlayer/issues/8842)). It will also
result in DRM license refresh network requests while the player is
stopped if `Player#setForegroundMode` is true.
* UI:
* Keep subtitle language features embedded (e.g. rubies & tate-chu-yoko)
in `Cue.text` even when `SubtitleView#setApplyEmbeddedStyles()` is

View File

@ -745,13 +745,8 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
outputStreamStartPositionUs = C.TIME_UNSET;
outputStreamOffsetUs = C.TIME_UNSET;
pendingOutputStreamOffsetCount = 0;
if (sourceDrmSession != null || codecDrmSession != null) {
// TODO: Do something better with this case.
onReset();
} else {
flushOrReleaseCodec();
}
}
@Override
protected void onReset() {