Package com.castlabs.android.drm
Class DrmUtils
java.lang.Object
com.castlabs.android.drm.DrmUtils
Utility methods for the widevine applications.
-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
bytesToString
(byte[] byteArray) Converts byte array to String representation, used for debuggingstatic UUID
cencFromPlayreadyKID
(byte[] decode) Creates a CENC UUID from the decoded playready KeyIDstatic UUID
cencFromPlayreadyKID
(String base64KID) Creates a CENC UUID from a base 64 encoded playready key idstatic CastlabsMediaDrm
createMediaDrm
(UUID uuid, boolean forceWidevineL3) Create a new MediaDrm instancestatic UUID
createUuid
(byte[] bytes) Create a UUID from a byte arraystatic UUID
createUuid
(String base64) Create a UUID from a encoded base64 Stringstatic byte[]
executeModifierPost
(String url, byte[] data, Map<String, String> requestProperties, HashMap<String, List<String>> responseHeaders, int connectionTimeoutMs, int readTimeoutMs, int acquisitionTimeoutMs, SSLSocketFactory sslSocketFactory, List<ResponseModifier> responseModifiers, int responseType) executePost
(Uri uri, byte[] data, Map<String, String> requestProperties) executePost
(String url, byte[] data, Map<String, String> requestProperties) executePost
(String url, byte[] data, Map<String, String> requestProperties, Map<String, List<String>> responseHeaders, int connectTimeoutMs, int readTimeoutMs, int acquisitionTimeoutMs, SSLSocketFactory sslSocketFactory) static byte[]
extractPsshData
(UUID drmScheme, byte[] data) Extract the atom data in a given PSSH box.static byte[]
generatePlayreadyHeader
(byte[] initData, String licenseServerUrl) Takes the raw bytes from a Widevine CENC header and generates a Playready Header Objectstatic byte[]
generateWidvineCencHeader
(byte[] keyId, String widevineProviderId, byte[] widevineContentId, String widevinePolicy) Generates a Widevine CENC headerstatic byte[]
generateWidvineCencHeader
(UUID cencKeyId, byte[] contentId, String provider, String policy) Generates a Widevine Header from a CENC UUID and a merchant.static byte[]
generateWiseplayHeader
(byte[] initData, String licenseServerUrl) Takes the raw bytes from a Widevine CENC header and generates a Wiseplay init datastatic byte[]
Converts a UUID to bytesstatic SecurityLevel
Returns the security level supported by the current device and the given DRM if the devices supports the DRM.static UUID
getKIDFromPlayreadySchemeData
(byte[] decode) Takes a Playready Header Object and extracts the KID converted to CENC or null.static UUID
getKIDFromPlayreadySchemeData
(com.google.android.exoplayer2.drm.DrmInitData.SchemeData schemeData) static UUID
Takes a Base64 encoded string representation of a Playready Header Object and extracts the KID converted to CENC or null.static UUID
getKIDFromWidevineHeader
(byte[] wvHeader) static UUID
getKIDFromWidevineSchemeData
(com.google.android.exoplayer2.drm.DrmInitData.SchemeData schemeData) static boolean
static boolean
isDisabled
(Drm drm, KeyStatus keyStatus) static boolean
isDisabled
(KeyStatus keyStatus) static boolean
isDrmSupported
(Drm drm) Helper function.static boolean
static boolean
isPlayreadyHeader
(byte[] data) static boolean
static boolean
isWidevineHeader
(byte[] data) static Drm
selectAudioDrm
(Drm videoDrm, Drm audioDrm) Select the best available DRM if no explicit DRM is specified.static Drm
selectAudioDrm
(Drm videoDrm, Drm audioDrm, Set<Drm> excludeDrms) static Drm
selectBestDrm
(Drm drm) Select the best available DRM if no explicit DRM is specified.static Drm
selectBestDrm
(Set<Drm> excludeDrms)
-
Constructor Details
-
DrmUtils
public DrmUtils()
-
-
Method Details
-
bytesToString
Converts byte array to String representation, used for debugging- Parameters:
byteArray
- The byte array- Returns:
- String representation
-
isDisabled
-
isDisabled
- Returns:
- true if the track with specified
KeyStatus
is not playable and should be disabled, false otherwise
-
selectBestDrm
Select the best available DRM if no explicit DRM is specified.- Parameters:
drm
- The source DRM- Returns:
- The source DRM or the best available DRM if the source selection is
Drm.BestAvailable
-
isUnsupportedSchemeException
-
isNotProvisionedException
-
isDeniedByServerException
-
selectBestDrm
-
selectAudioDrm
Select the best available DRM if no explicit DRM is specified.- Parameters:
videoDrm
- The video DRM systemaudioDrm
- The video DRM system- Returns:
- Selects the audio drm system based on the given selection and the device
-
selectAudioDrm
-
executeModifierPost
public static byte[] executeModifierPost(@NonNull String url, @Nullable byte[] data, @Nullable Map<String, String> requestProperties, @Nullable HashMap<String, throws IOExceptionList<String>> responseHeaders, int connectionTimeoutMs, int readTimeoutMs, int acquisitionTimeoutMs, @Nullable SSLSocketFactory sslSocketFactory, @Nullable List<ResponseModifier> responseModifiers, int responseType) - Throws:
IOException
-
executePost
@NonNull public static Pair<byte[],Integer> executePost(Uri uri, byte[] data, Map<String, String> requestProperties) throws IOException- Throws:
IOException
-
executePost
@NonNull public static Pair<byte[],Integer> executePost(String url, byte[] data, Map<String, String> requestProperties) throws IOException- Throws:
IOException
-
executePost
@NonNull public static Pair<byte[],Integer> executePost(String url, byte[] data, Map<String, String> requestProperties, @Nullable Map<String, throws IOExceptionList<String>> responseHeaders, int connectTimeoutMs, int readTimeoutMs, int acquisitionTimeoutMs, @Nullable SSLSocketFactory sslSocketFactory) - Throws:
IOException
-
generateWidvineCencHeader
public static byte[] generateWidvineCencHeader(@NonNull UUID cencKeyId, @NonNull byte[] contentId, @NonNull String provider, @NonNull String policy) Generates a Widevine Header from a CENC UUID and a merchant. The key ID will be used for both keyID and contentID in the generated header.- Parameters:
cencKeyId
- the CENC key IDcontentId
- the content IDprovider
- the providerpolicy
- the policy- Returns:
- The generated Widevine CENC header
-
cencFromPlayreadyKID
Creates a CENC UUID from a base 64 encoded playready key id- Parameters:
base64KID
- the base 64 encoded playready key ID- Returns:
- Teh CENC UUID
-
cencFromPlayreadyKID
Creates a CENC UUID from the decoded playready KeyID- Parameters:
decode
- the decoded playready key id- Returns:
- The CENC UUID
-
getKIDFromPlayreadySchemeData
Takes a Base64 encoded string representation of a Playready Header Object and extracts the KID converted to CENC or null. See this Document for the spec and what data are expected.- Parameters:
data
- the base64 encoded data- Returns:
- The KIDs or null
- Throws:
IllegalArgumentException
- in case parsing fails
-
getKIDFromPlayreadySchemeData
Takes a Playready Header Object and extracts the KID converted to CENC or null. See this Document for the spec and what data are expected.- Parameters:
decode
- the header object- Returns:
- The KIDs or null
- Throws:
IllegalArgumentException
- in case parsing fails
-
getKIDFromPlayreadySchemeData
@Nullable public static UUID getKIDFromPlayreadySchemeData(@NonNull com.google.android.exoplayer2.drm.DrmInitData.SchemeData schemeData) -
generateWidvineCencHeader
public static byte[] generateWidvineCencHeader(byte[] keyId, String widevineProviderId, byte[] widevineContentId, String widevinePolicy) Generates a Widevine CENC header- Parameters:
keyId
- the keyIDwidevineProviderId
- the providerwidevineContentId
- the content IDwidevinePolicy
- the policy- Returns:
- The Widevine header
-
generatePlayreadyHeader
@Nullable public static byte[] generatePlayreadyHeader(@NonNull byte[] initData, @NonNull String licenseServerUrl) Takes the raw bytes from a Widevine CENC header and generates a Playready Header Object- Parameters:
initData
- The widevine cenc header raw datalicenseServerUrl
- The playready license server URL- Returns:
- The Playready Header Object or null if the object could not be generated
-
generateWiseplayHeader
@Nullable public static byte[] generateWiseplayHeader(@NonNull byte[] initData, @NonNull String licenseServerUrl) Takes the raw bytes from a Widevine CENC header and generates a Wiseplay init data- Parameters:
initData
- The widevine cenc header raw datalicenseServerUrl
- The wiseplay license server URL- Returns:
- The Wiseplay Header Object or null if the object could not be generated
-
extractPsshData
Extract the atom data in a given PSSH box. This method will return the original data if data is not a PSSH box.- Parameters:
drmScheme
- The DRM scheme, i.e.SdkConsts.WIDEVINE_UUID
orSdkConsts.PLAYREADY_UUID
data
- The PSSH box- Returns:
- The data inside the given PSSH box or the original data if the data is not a PSSH box
-
getBytes
Converts a UUID to bytes- Parameters:
uuid
- the UUID- Returns:
- The UUID as bytes
-
createUuid
Create a UUID from a encoded base64 String- Parameters:
base64
- base64 encoded UUID- Returns:
- The UUID
-
createUuid
Create a UUID from a byte array- Parameters:
bytes
- the source bytes- Returns:
- The UUID
-
getDeviceSecurityLevel
Returns the security level supported by the current device and the given DRM if the devices supports the DRM. Returnsnull
if the DRM is not supported. Please note that this method will always returnSecurityLevel.SOFTWARE
if the current API level is below 18.- Parameters:
drm
- The drm system for which the security level is requested- Returns:
- The security level supported for the given DRM or null if the DRM is not supported
-
getSupportedDRM
- Returns:
- plugins an unmodifiable list of currently supported DRM based on the device and player plugins
-
isDrmSupported
Helper function. Checks if drm is supported in the platform.- Parameters:
drm
- Drm to be checked- Returns:
- if drm is supported on the device with the current plugin configuration.
-
getKIDFromWidevineHeader
-
getKIDFromWidevineSchemeData
@Nullable public static UUID getKIDFromWidevineSchemeData(@NonNull com.google.android.exoplayer2.drm.DrmInitData.SchemeData schemeData) -
isWidevineHeader
public static boolean isWidevineHeader(byte[] data) - Parameters:
data
- The data- Returns:
- True if the given data represent a Widevine Header object
-
isPlayreadyHeader
public static boolean isPlayreadyHeader(byte[] data) - Parameters:
data
- The data- Returns:
- True if the given data represent a Playready Header object
-
createMediaDrm
public static CastlabsMediaDrm createMediaDrm(UUID uuid, boolean forceWidevineL3) throws UnsupportedSchemeException, com.google.android.exoplayer2.drm.UnsupportedDrmException Create a new MediaDrm instance- Parameters:
uuid
- The UUID of the DRM scheme- Returns:
- The new instance
- Throws:
UnsupportedSchemeException
- in case the scheme is not supportedcom.google.android.exoplayer2.drm.UnsupportedDrmException
- in case the DRM is not supported
-