mirror of
https://github.com/androidx/media.git
synced 2025-05-07 15:40:37 +08:00
Set LogSessionId on MediaDrm session.
PiperOrigin-RevId: 411047184
This commit is contained in:
parent
4fd6d670c6
commit
f64c28f2a6
@ -31,6 +31,7 @@ import androidx.annotation.GuardedBy;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||||
import com.google.android.exoplayer2.decoder.CryptoConfig;
|
import com.google.android.exoplayer2.decoder.CryptoConfig;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
||||||
import com.google.android.exoplayer2.drm.ExoMediaDrm.KeyRequest;
|
import com.google.android.exoplayer2.drm.ExoMediaDrm.KeyRequest;
|
||||||
@ -133,6 +134,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
private final HashMap<String, String> keyRequestParameters;
|
private final HashMap<String, String> keyRequestParameters;
|
||||||
private final CopyOnWriteMultiset<DrmSessionEventListener.EventDispatcher> eventDispatchers;
|
private final CopyOnWriteMultiset<DrmSessionEventListener.EventDispatcher> eventDispatchers;
|
||||||
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
private final LoadErrorHandlingPolicy loadErrorHandlingPolicy;
|
||||||
|
private final PlayerId playerId;
|
||||||
|
|
||||||
/* package */ final MediaDrmCallback callback;
|
/* package */ final MediaDrmCallback callback;
|
||||||
/* package */ final UUID uuid;
|
/* package */ final UUID uuid;
|
||||||
@ -182,7 +184,8 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
HashMap<String, String> keyRequestParameters,
|
HashMap<String, String> keyRequestParameters,
|
||||||
MediaDrmCallback callback,
|
MediaDrmCallback callback,
|
||||||
Looper playbackLooper,
|
Looper playbackLooper,
|
||||||
LoadErrorHandlingPolicy loadErrorHandlingPolicy) {
|
LoadErrorHandlingPolicy loadErrorHandlingPolicy,
|
||||||
|
PlayerId playerId) {
|
||||||
if (mode == DefaultDrmSessionManager.MODE_QUERY
|
if (mode == DefaultDrmSessionManager.MODE_QUERY
|
||||||
|| mode == DefaultDrmSessionManager.MODE_RELEASE) {
|
|| mode == DefaultDrmSessionManager.MODE_RELEASE) {
|
||||||
Assertions.checkNotNull(offlineLicenseKeySetId);
|
Assertions.checkNotNull(offlineLicenseKeySetId);
|
||||||
@ -204,6 +207,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.eventDispatchers = new CopyOnWriteMultiset<>();
|
this.eventDispatchers = new CopyOnWriteMultiset<>();
|
||||||
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
this.loadErrorHandlingPolicy = loadErrorHandlingPolicy;
|
||||||
|
this.playerId = playerId;
|
||||||
state = STATE_OPENING;
|
state = STATE_OPENING;
|
||||||
responseHandler = new ResponseHandler(playbackLooper);
|
responseHandler = new ResponseHandler(playbackLooper);
|
||||||
}
|
}
|
||||||
@ -370,6 +374,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
sessionId = mediaDrm.openSession();
|
sessionId = mediaDrm.openSession();
|
||||||
|
mediaDrm.setPlayerIdForSession(sessionId, playerId);
|
||||||
cryptoConfig = mediaDrm.createCryptoConfig(sessionId);
|
cryptoConfig = mediaDrm.createCryptoConfig(sessionId);
|
||||||
state = STATE_OPENED;
|
state = STATE_OPENED;
|
||||||
// Capture state into a local so a consistent value is seen by the lambda.
|
// Capture state into a local so a consistent value is seen by the lambda.
|
||||||
|
@ -304,6 +304,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
private @MonotonicNonNull Handler playbackHandler;
|
private @MonotonicNonNull Handler playbackHandler;
|
||||||
private int mode;
|
private int mode;
|
||||||
@Nullable private byte[] offlineLicenseKeySetId;
|
@Nullable private byte[] offlineLicenseKeySetId;
|
||||||
|
private @MonotonicNonNull PlayerId playerId;
|
||||||
|
|
||||||
/* package */ volatile @Nullable MediaDrmHandler mediaDrmHandler;
|
/* package */ volatile @Nullable MediaDrmHandler mediaDrmHandler;
|
||||||
|
|
||||||
@ -492,6 +493,7 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
@Override
|
@Override
|
||||||
public void setPlayer(Looper playbackLooper, PlayerId playerId) {
|
public void setPlayer(Looper playbackLooper, PlayerId playerId) {
|
||||||
initPlaybackLooper(playbackLooper);
|
initPlaybackLooper(playbackLooper);
|
||||||
|
this.playerId = playerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -777,7 +779,8 @@ public class DefaultDrmSessionManager implements DrmSessionManager {
|
|||||||
keyRequestParameters,
|
keyRequestParameters,
|
||||||
callback,
|
callback,
|
||||||
checkNotNull(playbackLooper),
|
checkNotNull(playbackLooper),
|
||||||
loadErrorHandlingPolicy);
|
loadErrorHandlingPolicy,
|
||||||
|
checkNotNull(playerId));
|
||||||
// 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,
|
||||||
// to ensure that eventDispatcher receives all events related to the initial
|
// to ensure that eventDispatcher receives all events related to the initial
|
||||||
|
@ -26,6 +26,7 @@ import android.os.PersistableBundle;
|
|||||||
import androidx.annotation.IntDef;
|
import androidx.annotation.IntDef;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||||
import com.google.android.exoplayer2.decoder.CryptoConfig;
|
import com.google.android.exoplayer2.decoder.CryptoConfig;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
@ -395,6 +396,14 @@ public interface ExoMediaDrm {
|
|||||||
*/
|
*/
|
||||||
void closeSession(byte[] sessionId);
|
void closeSession(byte[] sessionId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the {@link PlayerId} of the player using a session.
|
||||||
|
*
|
||||||
|
* @param sessionId The ID of the session.
|
||||||
|
* @param playerId The {@link PlayerId} of the player using the session.
|
||||||
|
*/
|
||||||
|
default void setPlayerIdForSession(byte[] sessionId, PlayerId playerId) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a key request.
|
* Generates a key request.
|
||||||
*
|
*
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.exoplayer2.drm;
|
package com.google.android.exoplayer2.drm;
|
||||||
|
|
||||||
|
import static com.google.android.exoplayer2.util.Assertions.checkNotNull;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.media.DeniedByServerException;
|
import android.media.DeniedByServerException;
|
||||||
import android.media.MediaCrypto;
|
import android.media.MediaCrypto;
|
||||||
@ -23,12 +25,14 @@ import android.media.MediaDrm;
|
|||||||
import android.media.MediaDrmException;
|
import android.media.MediaDrmException;
|
||||||
import android.media.NotProvisionedException;
|
import android.media.NotProvisionedException;
|
||||||
import android.media.UnsupportedSchemeException;
|
import android.media.UnsupportedSchemeException;
|
||||||
|
import android.media.metrics.LogSessionId;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import androidx.annotation.DoNotInline;
|
import androidx.annotation.DoNotInline;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
|
import com.google.android.exoplayer2.analytics.PlayerId;
|
||||||
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
import com.google.android.exoplayer2.drm.DrmInitData.SchemeData;
|
||||||
import com.google.android.exoplayer2.extractor.mp4.PsshAtomUtil;
|
import com.google.android.exoplayer2.extractor.mp4.PsshAtomUtil;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
@ -182,6 +186,13 @@ public final class FrameworkMediaDrm implements ExoMediaDrm {
|
|||||||
mediaDrm.closeSession(sessionId);
|
mediaDrm.closeSession(sessionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPlayerIdForSession(byte[] sessionId, PlayerId playerId) {
|
||||||
|
if (Util.SDK_INT >= 31) {
|
||||||
|
Api31.setLogSessionIdOnMediaDrmSession(mediaDrm, sessionId, playerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Return values of MediaDrm.KeyRequest.getRequestType are equal to KeyRequest.RequestType.
|
// Return values of MediaDrm.KeyRequest.getRequestType are equal to KeyRequest.RequestType.
|
||||||
@SuppressLint("WrongConstant")
|
@SuppressLint("WrongConstant")
|
||||||
@Override
|
@Override
|
||||||
@ -504,9 +515,22 @@ public final class FrameworkMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@RequiresApi(31)
|
@RequiresApi(31)
|
||||||
private static class Api31 {
|
private static class Api31 {
|
||||||
|
private Api31() {}
|
||||||
|
|
||||||
@DoNotInline
|
@DoNotInline
|
||||||
public static boolean requiresSecureDecoder(MediaDrm mediaDrm, String mimeType) {
|
public static boolean requiresSecureDecoder(MediaDrm mediaDrm, String mimeType) {
|
||||||
return mediaDrm.requiresSecureDecoder(mimeType);
|
return mediaDrm.requiresSecureDecoder(mimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DoNotInline
|
||||||
|
public static void setLogSessionIdOnMediaDrmSession(
|
||||||
|
MediaDrm mediaDrm, byte[] drmSessionId, PlayerId playerId) {
|
||||||
|
LogSessionId logSessionId = playerId.getLogSessionId();
|
||||||
|
if (!logSessionId.equals(LogSessionId.LOG_SESSION_ID_NONE)) {
|
||||||
|
MediaDrm.PlaybackComponent playbackComponent =
|
||||||
|
checkNotNull(mediaDrm.getPlaybackComponent(drmSessionId));
|
||||||
|
playbackComponent.setLogSessionId(logSessionId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user