mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Make DrmSession acquire/release consistent with ExoMediaDrm
This aligns the method naming and Javadoc. The only remaining inconsistency I can see is that the initial reference count for DrmSession is 0 rather than 1. Unfortunately I think it's not trivial to get these aligned, because DefaultDrmSessionManager relies on being able to do something between instantiation and the DrmSession starting to open the session. In practice this doesn't really matter, since DrmSessions will be obtained via the manager, which does increment thee reference count to 1 to be consistent with how ExoMediaDrm acquisition works. PiperOrigin-RevId: 280136574
This commit is contained in:
parent
9b4a3701d4
commit
7ca77c6002
11 changed files with 36 additions and 37 deletions
|
|
@ -321,7 +321,7 @@ public abstract class BaseRenderer implements Renderer, RendererCapabilities {
|
||||||
Assertions.checkNotNull(Looper.myLooper()), newFormat.drmInitData);
|
Assertions.checkNotNull(Looper.myLooper()), newFormat.drmInitData);
|
||||||
}
|
}
|
||||||
if (existingSourceSession != null) {
|
if (existingSourceSession != null) {
|
||||||
existingSourceSession.releaseReference();
|
existingSourceSession.release();
|
||||||
}
|
}
|
||||||
return newSourceDrmSession;
|
return newSourceDrmSession;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -657,12 +657,12 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSourceDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
private void setSourceDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||||
DrmSession.replaceSessionReferences(sourceDrmSession, session);
|
DrmSession.replaceSession(sourceDrmSession, session);
|
||||||
sourceDrmSession = session;
|
sourceDrmSession = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDecoderDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
private void setDecoderDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||||
DrmSession.replaceSessionReferences(decoderDrmSession, session);
|
DrmSession.replaceSession(decoderDrmSession, session);
|
||||||
decoderDrmSession = session;
|
decoderDrmSession = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acquireReference() {
|
public void acquire() {
|
||||||
|
Assertions.checkState(referenceCount >= 0);
|
||||||
if (++referenceCount == 1) {
|
if (++referenceCount == 1) {
|
||||||
Assertions.checkState(state == STATE_OPENING);
|
Assertions.checkState(state == STATE_OPENING);
|
||||||
requestHandlerThread = new HandlerThread("DrmRequestHandler");
|
requestHandlerThread = new HandlerThread("DrmRequestHandler");
|
||||||
|
|
@ -264,7 +265,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseReference() {
|
public void release() {
|
||||||
if (--referenceCount == 0) {
|
if (--referenceCount == 0) {
|
||||||
// Assigning null to various non-null variables for clean-up.
|
// Assigning null to various non-null variables for clean-up.
|
||||||
state = STATE_RELEASED;
|
state = STATE_RELEASED;
|
||||||
|
|
|
||||||
|
|
@ -480,7 +480,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
|
||||||
sessions.add(placeholderDrmSession);
|
sessions.add(placeholderDrmSession);
|
||||||
this.placeholderDrmSession = placeholderDrmSession;
|
this.placeholderDrmSession = placeholderDrmSession;
|
||||||
}
|
}
|
||||||
placeholderDrmSession.acquireReference();
|
placeholderDrmSession.acquire();
|
||||||
return placeholderDrmSession;
|
return placeholderDrmSession;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -521,7 +521,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
|
||||||
}
|
}
|
||||||
sessions.add(session);
|
sessions.add(session);
|
||||||
}
|
}
|
||||||
session.acquireReference();
|
session.acquire();
|
||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,21 +30,21 @@ import java.util.Map;
|
||||||
public interface DrmSession<T extends ExoMediaCrypto> {
|
public interface DrmSession<T extends ExoMediaCrypto> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invokes {@code newSession's} {@link #acquireReference()} and {@code previousSession's} {@link
|
* Invokes {@code newSession's} {@link #acquire()} and {@code previousSession's} {@link
|
||||||
* #releaseReference()} in that order. Null arguments are ignored. Does nothing if {@code
|
* #release()} in that order. Null arguments are ignored. Does nothing if {@code previousSession}
|
||||||
* previousSession} and {@code newSession} are the same session.
|
* and {@code newSession} are the same session.
|
||||||
*/
|
*/
|
||||||
static <T extends ExoMediaCrypto> void replaceSessionReferences(
|
static <T extends ExoMediaCrypto> void replaceSession(
|
||||||
@Nullable DrmSession<T> previousSession, @Nullable DrmSession<T> newSession) {
|
@Nullable DrmSession<T> previousSession, @Nullable DrmSession<T> newSession) {
|
||||||
if (previousSession == newSession) {
|
if (previousSession == newSession) {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (newSession != null) {
|
if (newSession != null) {
|
||||||
newSession.acquireReference();
|
newSession.acquire();
|
||||||
}
|
}
|
||||||
if (previousSession != null) {
|
if (previousSession != null) {
|
||||||
previousSession.releaseReference();
|
previousSession.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,16 +130,14 @@ public interface DrmSession<T extends ExoMediaCrypto> {
|
||||||
byte[] getOfflineLicenseKeySetId();
|
byte[] getOfflineLicenseKeySetId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increments the reference count for this session. A non-zero reference count session will keep
|
* Increments the reference count. When the caller no longer needs to use the instance, it must
|
||||||
* any acquired resources.
|
* call {@link #release()} to decrement the reference count.
|
||||||
*/
|
*/
|
||||||
void acquireReference();
|
void acquire();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Decreases by one the reference count for this session. A session that reaches a zero reference
|
* Decrements the reference count. If the reference count drops to 0 underlying resources are
|
||||||
* count will release any resources it holds.
|
* released, and the instance cannot be re-used.
|
||||||
*
|
|
||||||
* <p>The session must not be used after its reference count has been reduced to 0.
|
|
||||||
*/
|
*/
|
||||||
void releaseReference();
|
void release();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,9 @@ public interface DrmSessionManager<T extends ExoMediaCrypto> {
|
||||||
boolean canAcquireSession(DrmInitData drmInitData);
|
boolean canAcquireSession(DrmInitData drmInitData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link DrmSession} with an acquired reference that does not execute key requests.
|
* Returns a {@link DrmSession} that does not execute key requests, with an incremented reference
|
||||||
* Returns null if placeholder sessions are not supported by this DRM session manager.
|
* count. When the caller no longer needs to use the instance, it must call {@link
|
||||||
|
* DrmSession#release()} to decrement the reference count.
|
||||||
*
|
*
|
||||||
* <p>Placeholder {@link DrmSession DrmSessions} may be used to configure secure decoders for
|
* <p>Placeholder {@link DrmSession DrmSessions} may be used to configure secure decoders for
|
||||||
* playback of clear samples, which reduces the costs of transitioning between clear and encrypted
|
* playback of clear samples, which reduces the costs of transitioning between clear and encrypted
|
||||||
|
|
@ -124,10 +125,9 @@ public interface DrmSessionManager<T extends ExoMediaCrypto> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link DrmSession} with an acquired reference for the specified {@link DrmInitData}.
|
* Returns a {@link DrmSession} for the specified {@link DrmInitData}, with an incremented
|
||||||
*
|
* reference count. When the caller no longer needs to use the instance, it must call {@link
|
||||||
* <p>The caller must call {@link DrmSession#releaseReference} to decrement the session's
|
* DrmSession#release()} to decrement the reference count.
|
||||||
* reference count when the session is no longer required.
|
|
||||||
*
|
*
|
||||||
* @param playbackLooper The looper associated with the media playback thread.
|
* @param playbackLooper The looper associated with the media playback thread.
|
||||||
* @param drmInitData DRM initialization data. All contained {@link SchemeData}s must contain
|
* @param drmInitData DRM initialization data. All contained {@link SchemeData}s must contain
|
||||||
|
|
|
||||||
|
|
@ -58,12 +58,12 @@ public final class ErrorStateDrmSession<T extends ExoMediaCrypto> implements Drm
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acquireReference() {
|
public void acquire() {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void releaseReference() {
|
public void release() {
|
||||||
// Do nothing.
|
// Do nothing.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
|
||||||
DrmSessionException error = drmSession.getError();
|
DrmSessionException error = drmSession.getError();
|
||||||
Pair<Long, Long> licenseDurationRemainingSec =
|
Pair<Long, Long> licenseDurationRemainingSec =
|
||||||
WidevineUtil.getLicenseDurationRemainingSec(drmSession);
|
WidevineUtil.getLicenseDurationRemainingSec(drmSession);
|
||||||
drmSession.releaseReference();
|
drmSession.release();
|
||||||
drmSessionManager.release();
|
drmSessionManager.release();
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
if (error.getCause() instanceof KeysExpiredException) {
|
if (error.getCause() instanceof KeysExpiredException) {
|
||||||
|
|
@ -236,7 +236,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
|
||||||
drmInitData);
|
drmInitData);
|
||||||
DrmSessionException error = drmSession.getError();
|
DrmSessionException error = drmSession.getError();
|
||||||
byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
|
byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
|
||||||
drmSession.releaseReference();
|
drmSession.release();
|
||||||
drmSessionManager.release();
|
drmSessionManager.release();
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
|
|
@ -1011,12 +1011,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setSourceDrmSession(@Nullable DrmSession<FrameworkMediaCrypto> session) {
|
private void setSourceDrmSession(@Nullable DrmSession<FrameworkMediaCrypto> session) {
|
||||||
DrmSession.replaceSessionReferences(sourceDrmSession, session);
|
DrmSession.replaceSession(sourceDrmSession, session);
|
||||||
sourceDrmSession = session;
|
sourceDrmSession = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCodecDrmSession(@Nullable DrmSession<FrameworkMediaCrypto> session) {
|
private void setCodecDrmSession(@Nullable DrmSession<FrameworkMediaCrypto> session) {
|
||||||
DrmSession.replaceSessionReferences(codecDrmSession, session);
|
DrmSession.replaceSession(codecDrmSession, session);
|
||||||
codecDrmSession = session;
|
codecDrmSession = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ import java.io.IOException;
|
||||||
/** Releases any owned {@link DrmSession} references. */
|
/** Releases any owned {@link DrmSession} references. */
|
||||||
public void releaseDrmSessionReferences() {
|
public void releaseDrmSessionReferences() {
|
||||||
if (currentDrmSession != null) {
|
if (currentDrmSession != null) {
|
||||||
currentDrmSession.releaseReference();
|
currentDrmSession.release();
|
||||||
currentDrmSession = null;
|
currentDrmSession = null;
|
||||||
// Clear downstream format to avoid violating the assumption that downstreamFormat.drmInitData
|
// Clear downstream format to avoid violating the assumption that downstreamFormat.drmInitData
|
||||||
// != null implies currentSession != null
|
// != null implies currentSession != null
|
||||||
|
|
@ -629,7 +629,7 @@ import java.io.IOException;
|
||||||
outputFormatHolder.drmSession = currentDrmSession;
|
outputFormatHolder.drmSession = currentDrmSession;
|
||||||
|
|
||||||
if (previousSession != null) {
|
if (previousSession != null) {
|
||||||
previousSession.releaseReference();
|
previousSession.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -635,12 +635,12 @@ public abstract class SimpleDecoderVideoRenderer extends BaseRenderer {
|
||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
|
||||||
private void setSourceDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
private void setSourceDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||||
DrmSession.replaceSessionReferences(sourceDrmSession, session);
|
DrmSession.replaceSession(sourceDrmSession, session);
|
||||||
sourceDrmSession = session;
|
sourceDrmSession = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDecoderDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
private void setDecoderDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||||
DrmSession.replaceSessionReferences(decoderDrmSession, session);
|
DrmSession.replaceSession(decoderDrmSession, session);
|
||||||
decoderDrmSession = session;
|
decoderDrmSession = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue