Skip to content

Commit

Permalink
Prepare and release DrmSessionManager in Renderers
Browse files Browse the repository at this point in the history
Issue: #6951
PiperOrigin-RevId: 294187695
  • Loading branch information
AquilesCanta authored and ojw28 committed Feb 13, 2020
1 parent 67a748f commit 19c8858
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
[#6798](https://github.com/google/ExoPlayer/issues/6798)).
* Fix `DownloadHelper.createMediaSource` to use `customCacheKey` when creating
`ProgressiveMediaSource` instances.
* DRM: Fix `NullPointerException` when playing DRM-protected content
([#6951](https://github.com/google/ExoPlayer/issues/6951)).
* Metadata:
* Update `IcyDecoder` to try ISO-8859-1 decoding if UTF-8 decoding fails.
Also change `IcyInfo.rawMetadata` from `String` to `byte[]` to allow
Expand Down
5 changes: 2 additions & 3 deletions demos/main/src/main/assets/media.exolist.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
"name": "YouTube DASH",
"samples": [
{
"name": "Google Glass (MP4,H264)",
"uri": "https://www.youtube.com/api/manifest/dash/id/bf5bb2419360daf1/source/youtube?as=fmp4_audio_clear,fmp4_sd_hd_clear&sparams=ip,ipbits,expire,source,id,as&ip=0.0.0.0&ipbits=0&expire=19000000000&signature=51AF5F39AB0CEC3E5497CD9C900EBFEAECCCB5C7.8506521BFC350652163895D4C26DEE124209AA9E&key=ik0",
"extension": "mpd"
"name": "6956",
"uri": "http://master255.org/res/%d0%9a%d0%bb%d0%b8%d0%bf%d1%8b/B/Billy%20Mack/Billy%20Mack%20-%20Christmas%20Is%20All%20Around.mpg"
},
{
"name": "Google Play (MP4,H264)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
private final AudioSink audioSink;
private final DecoderInputBuffer flagsOnlyBuffer;

private boolean drmResourcesAcquired;
private DecoderCounters decoderCounters;
private Format inputFormat;
private int encoderDelay;
Expand Down Expand Up @@ -539,6 +540,10 @@ public PlaybackParameters getPlaybackParameters() {

@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
if (drmSessionManager != null && !drmResourcesAcquired) {
drmResourcesAcquired = true;
drmSessionManager.prepare();
}
decoderCounters = new DecoderCounters();
eventDispatcher.enabled(decoderCounters);
int tunnelingAudioSessionId = getConfiguration().tunnelingAudioSessionId;
Expand Down Expand Up @@ -587,6 +592,14 @@ protected void onDisabled() {
}
}

@Override
protected void onReset() {
if (drmSessionManager != null && drmResourcesAcquired) {
drmResourcesAcquired = false;
drmSessionManager.release();
}
}

@Override
public void handleMessage(int messageType, @Nullable Object message) throws ExoPlaybackException {
switch (messageType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ private static String getDiagnosticInfoV21(Throwable cause) {
private final ArrayList<Long> decodeOnlyPresentationTimestamps;
private final MediaCodec.BufferInfo outputBufferInfo;

private boolean drmResourcesAcquired;
@Nullable private Format inputFormat;
private Format outputFormat;
@Nullable private DrmSession<FrameworkMediaCrypto> codecDrmSession;
Expand Down Expand Up @@ -597,6 +598,10 @@ protected final MediaCodec getCodec() {

@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
if (drmSessionManager != null && !drmResourcesAcquired) {
drmResourcesAcquired = true;
drmSessionManager.prepare();
}
decoderCounters = new DecoderCounters();
}

Expand Down Expand Up @@ -637,6 +642,10 @@ protected void onReset() {
} finally {
setSourceDrmSession(null);
}
if (drmSessionManager != null && drmResourcesAcquired) {
drmResourcesAcquired = false;
drmSessionManager.release();
}
}

protected void releaseCodec() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public abstract class SimpleDecoderVideoRenderer extends BaseRenderer {
private final DecoderInputBuffer flagsOnlyBuffer;
private final DrmSessionManager<ExoMediaCrypto> drmSessionManager;

private boolean drmResourcesAcquired;
private Format inputFormat;
private Format outputFormat;
private SimpleDecoder<
Expand Down Expand Up @@ -237,6 +238,10 @@ public boolean isReady() {

@Override
protected void onEnabled(boolean joining) throws ExoPlaybackException {
if (drmSessionManager != null && !drmResourcesAcquired) {
drmResourcesAcquired = true;
drmSessionManager.prepare();
}
decoderCounters = new DecoderCounters();
eventDispatcher.enabled(decoderCounters);
}
Expand Down Expand Up @@ -286,6 +291,14 @@ protected void onDisabled() {
}
}

@Override
protected void onReset() {
if (drmSessionManager != null && drmResourcesAcquired) {
drmResourcesAcquired = false;
drmSessionManager.release();
}
}

@Override
protected void onStreamChanged(Format[] formats, long offsetUs) throws ExoPlaybackException {
outputStreamOffsetUs = offsetUs;
Expand Down

0 comments on commit 19c8858

Please sign in to comment.