mirror of
https://github.com/samsonjs/media.git
synced 2026-03-26 09:35:47 +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);
|
||||
}
|
||||
if (existingSourceSession != null) {
|
||||
existingSourceSession.releaseReference();
|
||||
existingSourceSession.release();
|
||||
}
|
||||
return newSourceDrmSession;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -657,12 +657,12 @@ public abstract class SimpleDecoderAudioRenderer extends BaseRenderer implements
|
|||
}
|
||||
|
||||
private void setSourceDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||
DrmSession.replaceSessionReferences(sourceDrmSession, session);
|
||||
DrmSession.replaceSession(sourceDrmSession, session);
|
||||
sourceDrmSession = session;
|
||||
}
|
||||
|
||||
private void setDecoderDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||
DrmSession.replaceSessionReferences(decoderDrmSession, session);
|
||||
DrmSession.replaceSession(decoderDrmSession, session);
|
||||
decoderDrmSession = session;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -251,7 +251,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
}
|
||||
|
||||
@Override
|
||||
public void acquireReference() {
|
||||
public void acquire() {
|
||||
Assertions.checkState(referenceCount >= 0);
|
||||
if (++referenceCount == 1) {
|
||||
Assertions.checkState(state == STATE_OPENING);
|
||||
requestHandlerThread = new HandlerThread("DrmRequestHandler");
|
||||
|
|
@ -264,7 +265,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||
}
|
||||
|
||||
@Override
|
||||
public void releaseReference() {
|
||||
public void release() {
|
||||
if (--referenceCount == 0) {
|
||||
// Assigning null to various non-null variables for clean-up.
|
||||
state = STATE_RELEASED;
|
||||
|
|
|
|||
|
|
@ -480,7 +480,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
|
|||
sessions.add(placeholderDrmSession);
|
||||
this.placeholderDrmSession = placeholderDrmSession;
|
||||
}
|
||||
placeholderDrmSession.acquireReference();
|
||||
placeholderDrmSession.acquire();
|
||||
return placeholderDrmSession;
|
||||
}
|
||||
|
||||
|
|
@ -521,7 +521,7 @@ public class DefaultDrmSessionManager<T extends ExoMediaCrypto> implements DrmSe
|
|||
}
|
||||
sessions.add(session);
|
||||
}
|
||||
session.acquireReference();
|
||||
session.acquire();
|
||||
return session;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,21 +30,21 @@ import java.util.Map;
|
|||
public interface DrmSession<T extends ExoMediaCrypto> {
|
||||
|
||||
/**
|
||||
* Invokes {@code newSession's} {@link #acquireReference()} and {@code previousSession's} {@link
|
||||
* #releaseReference()} in that order. Null arguments are ignored. Does nothing if {@code
|
||||
* previousSession} and {@code newSession} are the same session.
|
||||
* Invokes {@code newSession's} {@link #acquire()} and {@code previousSession's} {@link
|
||||
* #release()} in that order. Null arguments are ignored. Does nothing if {@code previousSession}
|
||||
* 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) {
|
||||
if (previousSession == newSession) {
|
||||
// Do nothing.
|
||||
return;
|
||||
}
|
||||
if (newSession != null) {
|
||||
newSession.acquireReference();
|
||||
newSession.acquire();
|
||||
}
|
||||
if (previousSession != null) {
|
||||
previousSession.releaseReference();
|
||||
previousSession.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,16 +130,14 @@ public interface DrmSession<T extends ExoMediaCrypto> {
|
|||
byte[] getOfflineLicenseKeySetId();
|
||||
|
||||
/**
|
||||
* Increments the reference count for this session. A non-zero reference count session will keep
|
||||
* any acquired resources.
|
||||
* Increments the reference count. When the caller no longer needs to use the instance, it must
|
||||
* 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
|
||||
* count will release any resources it holds.
|
||||
*
|
||||
* <p>The session must not be used after its reference count has been reduced to 0.
|
||||
* Decrements the reference count. If the reference count drops to 0 underlying resources are
|
||||
* released, and the instance cannot be re-used.
|
||||
*/
|
||||
void releaseReference();
|
||||
void release();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,8 +105,9 @@ public interface DrmSessionManager<T extends ExoMediaCrypto> {
|
|||
boolean canAcquireSession(DrmInitData drmInitData);
|
||||
|
||||
/**
|
||||
* Returns a {@link DrmSession} with an acquired reference that does not execute key requests.
|
||||
* Returns null if placeholder sessions are not supported by this DRM session manager.
|
||||
* Returns a {@link DrmSession} that does not execute key requests, with an incremented reference
|
||||
* 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
|
||||
* 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}.
|
||||
*
|
||||
* <p>The caller must call {@link DrmSession#releaseReference} to decrement the session's
|
||||
* reference count when the session is no longer required.
|
||||
* 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
|
||||
* DrmSession#release()} to decrement the reference count.
|
||||
*
|
||||
* @param playbackLooper The looper associated with the media playback thread.
|
||||
* @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
|
||||
public void acquireReference() {
|
||||
public void acquire() {
|
||||
// Do nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void releaseReference() {
|
||||
public void release() {
|
||||
// Do nothing.
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
|
|||
DrmSessionException error = drmSession.getError();
|
||||
Pair<Long, Long> licenseDurationRemainingSec =
|
||||
WidevineUtil.getLicenseDurationRemainingSec(drmSession);
|
||||
drmSession.releaseReference();
|
||||
drmSession.release();
|
||||
drmSessionManager.release();
|
||||
if (error != null) {
|
||||
if (error.getCause() instanceof KeysExpiredException) {
|
||||
|
|
@ -236,7 +236,7 @@ public final class OfflineLicenseHelper<T extends ExoMediaCrypto> {
|
|||
drmInitData);
|
||||
DrmSessionException error = drmSession.getError();
|
||||
byte[] keySetId = drmSession.getOfflineLicenseKeySetId();
|
||||
drmSession.releaseReference();
|
||||
drmSession.release();
|
||||
drmSessionManager.release();
|
||||
if (error != null) {
|
||||
throw error;
|
||||
|
|
|
|||
|
|
@ -1011,12 +1011,12 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||
}
|
||||
|
||||
private void setSourceDrmSession(@Nullable DrmSession<FrameworkMediaCrypto> session) {
|
||||
DrmSession.replaceSessionReferences(sourceDrmSession, session);
|
||||
DrmSession.replaceSession(sourceDrmSession, session);
|
||||
sourceDrmSession = session;
|
||||
}
|
||||
|
||||
private void setCodecDrmSession(@Nullable DrmSession<FrameworkMediaCrypto> session) {
|
||||
DrmSession.replaceSessionReferences(codecDrmSession, session);
|
||||
DrmSession.replaceSession(codecDrmSession, session);
|
||||
codecDrmSession = session;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -171,7 +171,7 @@ import java.io.IOException;
|
|||
/** Releases any owned {@link DrmSession} references. */
|
||||
public void releaseDrmSessionReferences() {
|
||||
if (currentDrmSession != null) {
|
||||
currentDrmSession.releaseReference();
|
||||
currentDrmSession.release();
|
||||
currentDrmSession = null;
|
||||
// Clear downstream format to avoid violating the assumption that downstreamFormat.drmInitData
|
||||
// != null implies currentSession != null
|
||||
|
|
@ -629,7 +629,7 @@ import java.io.IOException;
|
|||
outputFormatHolder.drmSession = currentDrmSession;
|
||||
|
||||
if (previousSession != null) {
|
||||
previousSession.releaseReference();
|
||||
previousSession.release();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -635,12 +635,12 @@ public abstract class SimpleDecoderVideoRenderer extends BaseRenderer {
|
|||
// Internal methods.
|
||||
|
||||
private void setSourceDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||
DrmSession.replaceSessionReferences(sourceDrmSession, session);
|
||||
DrmSession.replaceSession(sourceDrmSession, session);
|
||||
sourceDrmSession = session;
|
||||
}
|
||||
|
||||
private void setDecoderDrmSession(@Nullable DrmSession<ExoMediaCrypto> session) {
|
||||
DrmSession.replaceSessionReferences(decoderDrmSession, session);
|
||||
DrmSession.replaceSession(decoderDrmSession, session);
|
||||
decoderDrmSession = session;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue