Optimize DrmSession reference replacement

Potentially avoids up to two calls to synchronized methods

PiperOrigin-RevId: 257578304
This commit is contained in:
aquilescanta 2019-07-11 11:33:38 +01:00 committed by Oliver Woodman
parent 91750b8009
commit 3f24d4433a

View file

@ -31,10 +31,15 @@ public interface DrmSession<T extends ExoMediaCrypto> {
/**
* Invokes {@code newSession's} {@link #acquireReference()} and {@code previousSession's} {@link
* #releaseReference()} in that order. Does nothing for passed null values.
* #releaseReference()} 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(
@Nullable DrmSession<T> previousSession, @Nullable DrmSession<T> newSession) {
if (previousSession == newSession) {
// Do nothing.
return;
}
if (newSession != null) {
newSession.acquireReference();
}