Package com.castlabs.android.drm
Class DrmUtils
java.lang.Object
com.castlabs.android.drm.DrmUtils
Utility methods for the widevine applications.
- 
Nested Class SummaryNested Classes
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic StringbytesToString(byte[] byteArray) Converts byte array to String representation, used for debuggingstatic UUIDcencFromPlayreadyKID(byte[] decode) Creates a CENC UUID from the decoded playready KeyIDstatic UUIDcencFromPlayreadyKID(String base64KID) Creates a CENC UUID from a base 64 encoded playready key idstatic CastlabsMediaDrmcreateMediaDrm(UUID uuid, boolean forceWidevineL3) Create a new MediaDrm instancestatic UUIDcreateUuid(byte[] bytes) Create a UUID from a byte arraystatic UUIDcreateUuid(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 SecurityLevelReturns the security level supported by the current device and the given DRM if the devices supports the DRM.static UUIDgetKIDFromPlayreadySchemeData(byte[] decode) Takes a Playready Header Object and extracts the KID converted to CENC or null.static UUIDgetKIDFromPlayreadySchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData schemeData) static UUIDTakes a Base64 encoded string representation of a Playready Header Object and extracts the KID converted to CENC or null.static UUIDgetKIDFromWidevineHeader(byte[] wvHeader) static UUIDgetKIDFromWidevineSchemeData(com.google.android.exoplayer2.drm.DrmInitData.SchemeData schemeData) static booleanstatic booleanisDisabled(Drm drm, KeyStatus keyStatus) static booleanisDisabled(KeyStatus keyStatus) static booleanisDrmSupported(Drm drm) Helper function.static booleanstatic booleanisPlayreadyHeader(byte[] data) static booleanstatic booleanisWidevineHeader(byte[] data) static DrmselectAudioDrm(Drm videoDrm, Drm audioDrm) Select the best available DRM if no explicit DRM is specified.static DrmselectAudioDrm(Drm videoDrm, Drm audioDrm, Set<Drm> excludeDrms) static DrmselectBestDrm(Drm drm) Select the best available DRM if no explicit DRM is specified.static DrmselectBestDrm(Set<Drm> excludeDrms) 
- 
Constructor Details- 
DrmUtilspublic DrmUtils()
 
- 
- 
Method Details- 
bytesToStringConverts 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 KeyStatusis not playable and should be disabled, false otherwise
 
- 
selectBestDrmSelect 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
- 
selectAudioDrmSelect the best available DRM if no explicit DRM is specified.- Parameters:
- videoDrm- The video DRM system
- audioDrm- The video DRM system
- Returns:
- Selects the audio drm system based on the given selection and the device
 
- 
selectAudioDrm
- 
executeModifierPostpublic 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
 
- 
generateWidvineCencHeaderpublic 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 ID
- contentId- the content ID
- provider- the provider
- policy- the policy
- Returns:
- The generated Widevine CENC header
 
- 
cencFromPlayreadyKIDCreates a CENC UUID from a base 64 encoded playready key id- Parameters:
- base64KID- the base 64 encoded playready key ID
- Returns:
- Teh CENC UUID
 
- 
cencFromPlayreadyKIDCreates a CENC UUID from the decoded playready KeyID- Parameters:
- decode- the decoded playready key id
- Returns:
- The CENC UUID
 
- 
getKIDFromPlayreadySchemeDataTakes 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
 
- 
getKIDFromPlayreadySchemeDataTakes 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) 
- 
generateWidvineCencHeaderpublic static byte[] generateWidvineCencHeader(byte[] keyId, String widevineProviderId, byte[] widevineContentId, String widevinePolicy) Generates a Widevine CENC header- Parameters:
- keyId- the keyID
- widevineProviderId- the provider
- widevineContentId- the content ID
- widevinePolicy- 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 data
- licenseServerUrl- 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 data
- licenseServerUrl- The wiseplay license server URL
- Returns:
- The Wiseplay Header Object or null if the object could not be generated
 
- 
extractPsshDataExtract 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_UUIDor- SdkConsts.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
 
- 
getBytesConverts a UUID to bytes- Parameters:
- uuid- the UUID
- Returns:
- The UUID as bytes
 
- 
createUuidCreate a UUID from a encoded base64 String- Parameters:
- base64- base64 encoded UUID
- Returns:
- The UUID
 
- 
createUuidCreate a UUID from a byte array- Parameters:
- bytes- the source bytes
- Returns:
- The UUID
 
- 
getDeviceSecurityLevelReturns the security level supported by the current device and the given DRM if the devices supports the DRM. Returnsnullif the DRM is not supported. Please note that this method will always returnSecurityLevel.SOFTWAREif 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
 
- 
isDrmSupportedHelper 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) 
- 
isWidevineHeaderpublic static boolean isWidevineHeader(byte[] data) - Parameters:
- data- The data
- Returns:
- True if the given data represent a Widevine Header object
 
- 
isPlayreadyHeaderpublic static boolean isPlayreadyHeader(byte[] data) - Parameters:
- data- The data
- Returns:
- True if the given data represent a Playready Header object
 
- 
createMediaDrmpublic 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 supported
- com.google.android.exoplayer2.drm.UnsupportedDrmException- in case the DRM is not supported
 
 
-