Skip to content

Commit

Permalink
Keep DRM sessions alive for a while before fully releasing them
Browse files Browse the repository at this point in the history
Issue: #7011
Issue: #6725
Issue: #7066

This also mitigates (but doesn't fix) Issue: #4133 because it
prevents a second key load after a short clear section.

PiperOrigin-RevId: 319184325
  • Loading branch information
icbaker authored and ojw28 committed Jul 3, 2020
1 parent e4e743a commit 316f8a8
Show file tree
Hide file tree
Showing 5 changed files with 377 additions and 58 deletions.
4 changes: 4 additions & 0 deletions RELEASENOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@
`OfflineLicenseHelper`
([#7078](https://github.com/google/ExoPlayer/issues/7078)).
* Remove generics from DRM components.
* Keep DRM sessions alive for a short time before fully releasing them
([#7011](https://github.com/google/ExoPlayer/issues/7011),
[#6725](https://github.com/google/ExoPlayer/issues/6725),
[#7066](https://github.com/google/ExoPlayer/issues/7066)).
* Downloads and caching:
* Support passing an `Executor` to `DefaultDownloaderFactory` on which
data downloads are performed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,26 @@ public interface ProvisioningManager {
void onProvisionCompleted();
}

/** Callback to be notified when the session is released. */
public interface ReleaseCallback {
/** Callback to be notified when the reference count of this session changes. */
public interface ReferenceCountListener {

/**
* Called immediately after releasing session resources.
* Called when the internal reference count of this session is incremented.
*
* @param session The session.
* @param session This session.
* @param newReferenceCount The reference count after being incremented.
*/
void onReferenceCountIncremented(DefaultDrmSession session, int newReferenceCount);

/**
* Called when the internal reference count of this session is decremented.
*
* <p>{@code newReferenceCount == 0} indicates this session is in {@link #STATE_RELEASED}.
*
* @param session This session.
* @param newReferenceCount The reference count after being decremented.
*/
void onSessionReleased(DefaultDrmSession session);
void onReferenceCountDecremented(DefaultDrmSession session, int newReferenceCount);
}

private static final String TAG = "DefaultDrmSession";
Expand All @@ -107,7 +118,7 @@ public interface ReleaseCallback {

private final ExoMediaDrm mediaDrm;
private final ProvisioningManager provisioningManager;
private final ReleaseCallback releaseCallback;
private final ReferenceCountListener referenceCountListener;
private final @DefaultDrmSessionManager.Mode int mode;
private final boolean playClearSamplesWithoutKeys;
private final boolean isPlaceholderSession;
Expand Down Expand Up @@ -137,7 +148,7 @@ public interface ReleaseCallback {
* @param uuid The UUID of the drm scheme.
* @param mediaDrm The media DRM.
* @param provisioningManager The manager for provisioning.
* @param releaseCallback The {@link ReleaseCallback}.
* @param referenceCountListener The {@link ReferenceCountListener}.
* @param schemeDatas DRM scheme datas for this session, or null if an {@code
* offlineLicenseKeySetId} is provided or if {@code isPlaceholderSession} is true.
* @param mode The DRM mode. Ignored if {@code isPlaceholderSession} is true.
Expand All @@ -154,7 +165,7 @@ public DefaultDrmSession(
UUID uuid,
ExoMediaDrm mediaDrm,
ProvisioningManager provisioningManager,
ReleaseCallback releaseCallback,
ReferenceCountListener referenceCountListener,
@Nullable List<SchemeData> schemeDatas,
@DefaultDrmSessionManager.Mode int mode,
boolean playClearSamplesWithoutKeys,
Expand All @@ -170,7 +181,7 @@ public DefaultDrmSession(
}
this.uuid = uuid;
this.provisioningManager = provisioningManager;
this.releaseCallback = releaseCallback;
this.referenceCountListener = referenceCountListener;
this.mediaDrm = mediaDrm;
this.mode = mode;
this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
Expand Down Expand Up @@ -280,6 +291,7 @@ public void acquire(@Nullable MediaSourceEventDispatcher eventDispatcher) {
eventDispatcher.dispatch(
DrmSessionEventListener::onDrmSessionAcquired, DrmSessionEventListener.class);
}
referenceCountListener.onReferenceCountIncremented(this, referenceCount);
}

@Override
Expand All @@ -300,7 +312,6 @@ public void release(@Nullable MediaSourceEventDispatcher eventDispatcher) {
mediaDrm.closeSession(sessionId);
sessionId = null;
}
releaseCallback.onSessionReleased(this);
dispatchEvent(DrmSessionEventListener::onDrmSessionReleased);
}
if (eventDispatcher != null) {
Expand All @@ -312,6 +323,7 @@ public void release(@Nullable MediaSourceEventDispatcher eventDispatcher) {
}
eventDispatchers.remove(eventDispatcher);
}
referenceCountListener.onReferenceCountDecremented(this, referenceCount);
}

// Internal methods.
Expand Down
Loading

0 comments on commit 316f8a8

Please sign in to comment.