Static import Assertions methods in DefaultDrmSessionManager
PiperOrigin-RevId: 358384778
This commit is contained in:
parent
74ad0949fd
commit
93a608d507
@ -15,6 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.drm;
|
package com.google.android.exoplayer2.drm;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkArgument;
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkState;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.media.ResourceBusyException;
|
import android.media.ResourceBusyException;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@ -31,7 +35,6 @@ import com.google.android.exoplayer2.drm.DrmSession.DrmSessionException;
|
|||||||
import com.google.android.exoplayer2.drm.ExoMediaDrm.OnEventListener;
|
import com.google.android.exoplayer2.drm.ExoMediaDrm.OnEventListener;
|
||||||
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
|
import com.google.android.exoplayer2.upstream.DefaultLoadErrorHandlingPolicy;
|
||||||
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
import com.google.android.exoplayer2.upstream.LoadErrorHandlingPolicy;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
|
||||||
import com.google.android.exoplayer2.util.Log;
|
import com.google.android.exoplayer2.util.Log;
|
||||||
import com.google.android.exoplayer2.util.MimeTypes;
|
import com.google.android.exoplayer2.util.MimeTypes;
|
||||||
import com.google.android.exoplayer2.util.Util;
|
import com.google.android.exoplayer2.util.Util;
|
||||||
@ -127,8 +130,8 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
*/
|
*/
|
||||||
public Builder setUuidAndExoMediaDrmProvider(
|
public Builder setUuidAndExoMediaDrmProvider(
|
||||||
UUID uuid, ExoMediaDrm.Provider exoMediaDrmProvider) {
|
UUID uuid, ExoMediaDrm.Provider exoMediaDrmProvider) {
|
||||||
this.uuid = Assertions.checkNotNull(uuid);
|
this.uuid = checkNotNull(uuid);
|
||||||
this.exoMediaDrmProvider = Assertions.checkNotNull(exoMediaDrmProvider);
|
this.exoMediaDrmProvider = checkNotNull(exoMediaDrmProvider);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,8 +167,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
public Builder setUseDrmSessionsForClearContent(
|
public Builder setUseDrmSessionsForClearContent(
|
||||||
int... useDrmSessionsForClearContentTrackTypes) {
|
int... useDrmSessionsForClearContentTrackTypes) {
|
||||||
for (int trackType : useDrmSessionsForClearContentTrackTypes) {
|
for (int trackType : useDrmSessionsForClearContentTrackTypes) {
|
||||||
Assertions.checkArgument(
|
checkArgument(trackType == C.TRACK_TYPE_VIDEO || trackType == C.TRACK_TYPE_AUDIO);
|
||||||
trackType == C.TRACK_TYPE_VIDEO || trackType == C.TRACK_TYPE_AUDIO);
|
|
||||||
}
|
}
|
||||||
this.useDrmSessionsForClearContentTrackTypes =
|
this.useDrmSessionsForClearContentTrackTypes =
|
||||||
useDrmSessionsForClearContentTrackTypes.clone();
|
useDrmSessionsForClearContentTrackTypes.clone();
|
||||||
@ -192,7 +194,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public Builder setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
|
public Builder setLoadErrorHandlingPolicy(LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
|
||||||
this.loadErrorHandlingPolicy = Assertions.checkNotNull(loadErrorHandlingPolicy);
|
this.loadErrorHandlingPolicy = checkNotNull(loadErrorHandlingPolicy);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +214,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
* @return This builder.
|
* @return This builder.
|
||||||
*/
|
*/
|
||||||
public Builder setSessionKeepaliveMs(long sessionKeepaliveMs) {
|
public Builder setSessionKeepaliveMs(long sessionKeepaliveMs) {
|
||||||
Assertions.checkArgument(sessionKeepaliveMs > 0 || sessionKeepaliveMs == C.TIME_UNSET);
|
checkArgument(sessionKeepaliveMs > 0 || sessionKeepaliveMs == C.TIME_UNSET);
|
||||||
this.sessionKeepaliveMs = sessionKeepaliveMs;
|
this.sessionKeepaliveMs = sessionKeepaliveMs;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -396,8 +398,8 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
boolean playClearSamplesWithoutKeys,
|
boolean playClearSamplesWithoutKeys,
|
||||||
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
long sessionKeepaliveMs) {
|
long sessionKeepaliveMs) {
|
||||||
Assertions.checkNotNull(uuid);
|
checkNotNull(uuid);
|
||||||
Assertions.checkArgument(!C.COMMON_PSSH_UUID.equals(uuid), "Use C.CLEARKEY_UUID instead");
|
checkArgument(!C.COMMON_PSSH_UUID.equals(uuid), "Use C.CLEARKEY_UUID instead");
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
this.exoMediaDrmProvider = exoMediaDrmProvider;
|
this.exoMediaDrmProvider = exoMediaDrmProvider;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
@ -441,9 +443,9 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
* @param offlineLicenseKeySetId The key set id of the license to be used with the given mode.
|
* @param offlineLicenseKeySetId The key set id of the license to be used with the given mode.
|
||||||
*/
|
*/
|
||||||
public void setMode(@Mode int mode, @Nullable byte[] offlineLicenseKeySetId) {
|
public void setMode(@Mode int mode, @Nullable byte[] offlineLicenseKeySetId) {
|
||||||
Assertions.checkState(sessions.isEmpty());
|
checkState(sessions.isEmpty());
|
||||||
if (mode == MODE_QUERY || mode == MODE_RELEASE) {
|
if (mode == MODE_QUERY || mode == MODE_RELEASE) {
|
||||||
Assertions.checkNotNull(offlineLicenseKeySetId);
|
checkNotNull(offlineLicenseKeySetId);
|
||||||
}
|
}
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
this.offlineLicenseKeySetId = offlineLicenseKeySetId;
|
this.offlineLicenseKeySetId = offlineLicenseKeySetId;
|
||||||
@ -456,7 +458,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
if (prepareCallsCount++ != 0) {
|
if (prepareCallsCount++ != 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Assertions.checkState(exoMediaDrm == null);
|
checkState(exoMediaDrm == null);
|
||||||
exoMediaDrm = exoMediaDrmProvider.acquireExoMediaDrm(uuid);
|
exoMediaDrm = exoMediaDrmProvider.acquireExoMediaDrm(uuid);
|
||||||
exoMediaDrm.setOnEventListener(new MediaDrmEventListener());
|
exoMediaDrm.setOnEventListener(new MediaDrmEventListener());
|
||||||
}
|
}
|
||||||
@ -477,7 +479,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
}
|
}
|
||||||
releaseAllPreacquiredSessions();
|
releaseAllPreacquiredSessions();
|
||||||
|
|
||||||
Assertions.checkNotNull(exoMediaDrm).release();
|
checkNotNull(exoMediaDrm).release();
|
||||||
exoMediaDrm = null;
|
exoMediaDrm = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,7 +527,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
|
|
||||||
@Nullable List<SchemeData> schemeDatas = null;
|
@Nullable List<SchemeData> schemeDatas = null;
|
||||||
if (offlineLicenseKeySetId == null) {
|
if (offlineLicenseKeySetId == null) {
|
||||||
schemeDatas = getSchemeDatas(Assertions.checkNotNull(format.drmInitData), uuid, false);
|
schemeDatas = getSchemeDatas(checkNotNull(format.drmInitData), uuid, false);
|
||||||
if (schemeDatas.isEmpty()) {
|
if (schemeDatas.isEmpty()) {
|
||||||
final MissingSchemeDataException error = new MissingSchemeDataException(uuid);
|
final MissingSchemeDataException error = new MissingSchemeDataException(uuid);
|
||||||
Log.e(TAG, "DRM error", error);
|
Log.e(TAG, "DRM error", error);
|
||||||
@ -573,7 +575,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
@Nullable
|
@Nullable
|
||||||
public Class<? extends ExoMediaCrypto> getExoMediaCryptoType(Format format) {
|
public Class<? extends ExoMediaCrypto> getExoMediaCryptoType(Format format) {
|
||||||
Class<? extends ExoMediaCrypto> exoMediaCryptoType =
|
Class<? extends ExoMediaCrypto> exoMediaCryptoType =
|
||||||
Assertions.checkNotNull(exoMediaDrm).getExoMediaCryptoType();
|
checkNotNull(exoMediaDrm).getExoMediaCryptoType();
|
||||||
if (format.drmInitData == null) {
|
if (format.drmInitData == null) {
|
||||||
int trackType = MimeTypes.getTrackType(format.sampleMimeType);
|
int trackType = MimeTypes.getTrackType(format.sampleMimeType);
|
||||||
return Util.linearSearch(useDrmSessionsForClearContentTrackTypes, trackType) != C.INDEX_UNSET
|
return Util.linearSearch(useDrmSessionsForClearContentTrackTypes, trackType) != C.INDEX_UNSET
|
||||||
@ -591,7 +593,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private DrmSession maybeAcquirePlaceholderSession(
|
private DrmSession maybeAcquirePlaceholderSession(
|
||||||
int trackType, boolean shouldReleasePreacquiredSessionsBeforeRetrying) {
|
int trackType, boolean shouldReleasePreacquiredSessionsBeforeRetrying) {
|
||||||
ExoMediaDrm exoMediaDrm = Assertions.checkNotNull(this.exoMediaDrm);
|
ExoMediaDrm exoMediaDrm = checkNotNull(this.exoMediaDrm);
|
||||||
boolean avoidPlaceholderDrmSessions =
|
boolean avoidPlaceholderDrmSessions =
|
||||||
FrameworkMediaCrypto.class.equals(exoMediaDrm.getExoMediaCryptoType())
|
FrameworkMediaCrypto.class.equals(exoMediaDrm.getExoMediaCryptoType())
|
||||||
&& FrameworkMediaCrypto.WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC;
|
&& FrameworkMediaCrypto.WORKAROUND_DEVICE_NEEDS_KEYS_TO_CONFIGURE_CODEC;
|
||||||
@ -657,8 +659,8 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
this.playbackLooper = playbackLooper;
|
this.playbackLooper = playbackLooper;
|
||||||
this.playbackHandler = new Handler(playbackLooper);
|
this.playbackHandler = new Handler(playbackLooper);
|
||||||
} else {
|
} else {
|
||||||
Assertions.checkState(this.playbackLooper == playbackLooper);
|
checkState(this.playbackLooper == playbackLooper);
|
||||||
Assertions.checkNotNull(playbackHandler);
|
checkNotNull(playbackHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -707,8 +709,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
// assume any error indicates resource shortage (ensuring we retry).
|
// assume any error indicates resource shortage (ensuring we retry).
|
||||||
return session.getState() == DrmSession.STATE_ERROR
|
return session.getState() == DrmSession.STATE_ERROR
|
||||||
&& (Util.SDK_INT < 19
|
&& (Util.SDK_INT < 19
|
||||||
|| Assertions.checkNotNull(session.getError()).getCause()
|
|| checkNotNull(session.getError()).getCause() instanceof ResourceBusyException);
|
||||||
instanceof ResourceBusyException);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -744,7 +745,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
@Nullable List<SchemeData> schemeDatas,
|
@Nullable List<SchemeData> schemeDatas,
|
||||||
boolean isPlaceholderSession,
|
boolean isPlaceholderSession,
|
||||||
@Nullable DrmSessionEventListener.EventDispatcher eventDispatcher) {
|
@Nullable DrmSessionEventListener.EventDispatcher eventDispatcher) {
|
||||||
Assertions.checkNotNull(exoMediaDrm);
|
checkNotNull(exoMediaDrm);
|
||||||
// Placeholder sessions should always play clear samples without keys.
|
// Placeholder sessions should always play clear samples without keys.
|
||||||
boolean playClearSamplesWithoutKeys = this.playClearSamplesWithoutKeys | isPlaceholderSession;
|
boolean playClearSamplesWithoutKeys = this.playClearSamplesWithoutKeys | isPlaceholderSession;
|
||||||
DefaultDrmSession session =
|
DefaultDrmSession session =
|
||||||
@ -760,7 +761,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
offlineLicenseKeySetId,
|
offlineLicenseKeySetId,
|
||||||
keyRequestParameters,
|
keyRequestParameters,
|
||||||
callback,
|
callback,
|
||||||
Assertions.checkNotNull(playbackLooper),
|
checkNotNull(playbackLooper),
|
||||||
loadErrorHandlingPolicy);
|
loadErrorHandlingPolicy);
|
||||||
// Acquire the session once on behalf of the caller to DrmSessionManager - this is the
|
// Acquire the session once on behalf of the caller to DrmSessionManager - this is the
|
||||||
// reference 'assigned' to the caller which they're responsible for releasing. Do this first,
|
// reference 'assigned' to the caller which they're responsible for releasing. Do this first,
|
||||||
@ -861,7 +862,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
if (sessionKeepaliveMs != C.TIME_UNSET) {
|
if (sessionKeepaliveMs != C.TIME_UNSET) {
|
||||||
// The session has been acquired elsewhere so we want to cancel our timeout.
|
// The session has been acquired elsewhere so we want to cancel our timeout.
|
||||||
keepaliveSessions.remove(session);
|
keepaliveSessions.remove(session);
|
||||||
Assertions.checkNotNull(playbackHandler).removeCallbacksAndMessages(session);
|
checkNotNull(playbackHandler).removeCallbacksAndMessages(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -870,7 +871,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
if (newReferenceCount == 1 && sessionKeepaliveMs != C.TIME_UNSET) {
|
if (newReferenceCount == 1 && sessionKeepaliveMs != C.TIME_UNSET) {
|
||||||
// Only the internal keep-alive reference remains, so we can start the timeout.
|
// Only the internal keep-alive reference remains, so we can start the timeout.
|
||||||
keepaliveSessions.add(session);
|
keepaliveSessions.add(session);
|
||||||
Assertions.checkNotNull(playbackHandler)
|
checkNotNull(playbackHandler)
|
||||||
.postAtTime(
|
.postAtTime(
|
||||||
() -> session.release(/* eventDispatcher= */ null),
|
() -> session.release(/* eventDispatcher= */ null),
|
||||||
session,
|
session,
|
||||||
@ -891,7 +892,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
}
|
}
|
||||||
provisioningSessions.remove(session);
|
provisioningSessions.remove(session);
|
||||||
if (sessionKeepaliveMs != C.TIME_UNSET) {
|
if (sessionKeepaliveMs != C.TIME_UNSET) {
|
||||||
Assertions.checkNotNull(playbackHandler).removeCallbacksAndMessages(session);
|
checkNotNull(playbackHandler).removeCallbacksAndMessages(session);
|
||||||
keepaliveSessions.remove(session);
|
keepaliveSessions.remove(session);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -903,7 +904,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onEvent(
|
public void onEvent(
|
||||||
ExoMediaDrm md, @Nullable byte[] sessionId, int event, int extra, @Nullable byte[] data) {
|
ExoMediaDrm md, @Nullable byte[] sessionId, int event, int extra, @Nullable byte[] data) {
|
||||||
Assertions.checkNotNull(mediaDrmHandler).obtainMessage(event, sessionId).sendToTarget();
|
checkNotNull(mediaDrmHandler).obtainMessage(event, sessionId).sendToTarget();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -951,7 +952,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
}
|
}
|
||||||
this.session =
|
this.session =
|
||||||
acquireSession(
|
acquireSession(
|
||||||
Assertions.checkNotNull(playbackLooper),
|
checkNotNull(playbackLooper),
|
||||||
eventDispatcher,
|
eventDispatcher,
|
||||||
format,
|
format,
|
||||||
/* shouldReleasePreacquiredSessionsBeforeRetrying= */ false);
|
/* shouldReleasePreacquiredSessionsBeforeRetrying= */ false);
|
||||||
@ -964,7 +965,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
// Ensure the underlying session is released immediately if we're already on the playback
|
// Ensure the underlying session is released immediately if we're already on the playback
|
||||||
// thread, to allow a failed session opening to be immediately retried.
|
// thread, to allow a failed session opening to be immediately retried.
|
||||||
Util.postOrRun(
|
Util.postOrRun(
|
||||||
Assertions.checkNotNull(playbackHandler),
|
checkNotNull(playbackHandler),
|
||||||
() -> {
|
() -> {
|
||||||
if (isReleased) {
|
if (isReleased) {
|
||||||
return;
|
return;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user