Added in API level 26

MediaCas


class MediaCas : AutoCloseable
kotlin.Any
   ↳ android.media.MediaCas

MediaCas can be used to obtain keys for descrambling protected media streams, in conjunction with android.media.MediaDescrambler. The MediaCas APIs are designed to support conditional access such as those in the ISO/IEC13818-1. The CA system is identified by a 16-bit integer CA_system_id. The scrambling algorithms are usually proprietary and implemented by vendor-specific CA plugins installed on the device.

The app is responsible for constructing a MediaCas object for the CA system it intends to use. The app can query if a certain CA system is supported using static method isSystemIdSupported. It can also obtain the entire list of supported CA systems using static method enumeratePlugins.

Once the MediaCas object is constructed, the app should properly provision it by using method provision and/or #processEmm. The EMMs (Entitlement management messages) can be distributed out-of-band, or in-band with the stream.

To descramble elementary streams, the app first calls #openSession to generate a Session object that will uniquely identify a session. A session provides a context for subsequent key updates and descrambling activities. The ECMs (Entitlement control messages) are sent to the session via method android.media.MediaCas.Session#processEcm.

The app next constructs a MediaDescrambler object, and initializes it with the session using MediaDescrambler#setMediaCasSession. This ties the descrambler to the session, and the descrambler can then be used to descramble content secured with the session's key, either during extraction, or during decoding with android.media.MediaCodec.

If the app handles sample extraction using its own extractor, it can use MediaDescrambler to descramble samples into clear buffers (if the session's license doesn't require secure decoders), or descramble a small amount of data to retrieve information necessary for the downstream pipeline to process the sample (if the session's license requires secure decoders).

If the session requires a secure decoder, a MediaDescrambler needs to be provided to MediaCodec to descramble samples queued by MediaCodec#queueSecureInputBuffer into protected buffers. The app should use MediaCodec#configure(MediaFormat, instead of the normal android.media.MediaCodec#configure(android.media.MediaFormat,android.view.Surface,android.media.MediaCrypto,int) method to configure MediaCodec.

Using Android's MediaExtractor

If the app uses MediaExtractor, it can delegate the CAS session management to MediaExtractor by calling MediaExtractor#setMediaCas. MediaExtractor will take over and call #openSession, #processEmm and/or android.media.MediaCas.Session#processEcm, etc.. if necessary.

When using MediaExtractor, the app would still need a MediaDescrambler to use with MediaCodec if the licensing requires a secure decoder. The session associated with the descrambler of a track can be retrieved by calling MediaExtractor#getCasInfo, and used to initialize a MediaDescrambler object for MediaCodec.

Listeners

The app may register a listener to receive events from the CA system using method setEventListener. The exact format of the event is scheme-specific and is not specified by this API.

Summary

Nested classes
abstract

An interface registered by the caller to setEventListener to receives scheme-specific notifications from a MediaCas instance.

Describe a CAS plugin with its CA_system_ID and string name.

Class for an open session with the CA system.

Constants
static Int

The event to indicate that the status of CAS system is changed by the removal or insertion of physical CAS modules.

static Int

The event to indicate that the number of CAS system's session is changed.

static Int

Advanced Encryption System (AES) 128-bit Encryption mode.

static Int

Advanced Encryption System (AES) Cipher Block Chaining (CBC) mode.

static Int

Advanced Encryption System (AES) Electronic Code Book (ECB) mode.

static Int

Advanced Encryption System (AES) Society of Cable Telecommunications Engineers (SCTE) 52 mode.

static Int

DVB Common IPTV Software-oriented Scrambling Algorithm (CISSA) Version 1.

static Int

DVB (Digital Video Broadcasting) Common Scrambling Algorithm (CSA) 1.

static Int

DVB CSA 2.

static Int

DVB CSA 3 in fully enhanced mode.

static Int

DVB CSA 3 in minimally enhanced mode.

static Int

DVB CSA 3 in standard mode.

static Int

ATIS-0800006 IIF Default Scrambling Algorithm (IDSA).

static Int

A symmetric key algorithm.

static Int

DVB (Digital Video Broadcasting) reserved mode.

static Int

Triple Data Encryption Algorithm (TDES) Electronic Code Book (ECB) mode.

static Int

Triple Data Encryption Algorithm (TDES) Society of Cable Telecommunications Engineers (SCTE) 52 mode.

static Int

Cas session is used to descramble live streams.

static Int

Cas session is used to descramble recoreded streams.

static Int

Cas session is used to descramble live streams and encrypt local recorded content

static Int

Cas session is used to descramble live streams , encrypt local recorded content and playback local encrypted content.

Public constructors
MediaCas(casSystemId: Int)

Instantiate a CA system of the specified system id.

MediaCas(context: Context, casSystemId: Int, tvInputServiceSessionId: String?, priorityHint: Int)

Instantiate a CA system of the specified system id.

MediaCas(context: Context, casSystemId: Int, tvInputServiceSessionId: String?, priorityHint: Int, handler: Handler?, listener: MediaCas.EventListener?)

Instantiate a CA system of the specified system id with EvenListener.

Public methods
Unit

static Array<MediaCas.PluginDescriptor!>!

List all available CA plugins on the device.

static Boolean
isSystemIdSupported(CA_system_id: Int)

Query if a certain CA system is supported on this device.

MediaCas.Session!

Open a session to descramble one or more streams scrambled by the conditional access system.

MediaCas.Session?
openSession(sessionUsage: Int, scramblingMode: Int)

Open a session with usage and scrambling information, so that descrambler can be configured to descramble one or more streams scrambled by the conditional access system.

Unit
processEmm(data: ByteArray, offset: Int, length: Int)

Send a received EMM packet to the CA system.

Unit

Send a received EMM packet to the CA system.

Unit
provision(provisionString: String)

Initiate a provisioning operation for a CA system.

Unit
refreshEntitlements(refreshType: Int, refreshData: ByteArray?)

Notify the CA system to refresh entitlement keys.

Unit
sendEvent(event: Int, arg: Int, data: ByteArray?)

Send an event to a CA system.

Unit

Set an event listener to receive notifications from the MediaCas instance.

Unit

Send the private data for the CA system.

Protected methods
Unit

Constants

PLUGIN_STATUS_PHYSICAL_MODULE_CHANGED

Added in API level 30
static val PLUGIN_STATUS_PHYSICAL_MODULE_CHANGED: Int

The event to indicate that the status of CAS system is changed by the removal or insertion of physical CAS modules.

Value: 0

PLUGIN_STATUS_SESSION_NUMBER_CHANGED

Added in API level 30
static val PLUGIN_STATUS_SESSION_NUMBER_CHANGED: Int

The event to indicate that the number of CAS system's session is changed.

Value: 1

SCRAMBLING_MODE_AES128

Added in API level 30
static val SCRAMBLING_MODE_AES128: Int

Advanced Encryption System (AES) 128-bit Encryption mode.

Value: 9

SCRAMBLING_MODE_AES_CBC

Added in API level 34
static val SCRAMBLING_MODE_AES_CBC: Int

Advanced Encryption System (AES) Cipher Block Chaining (CBC) mode.

Value: 14

SCRAMBLING_MODE_AES_ECB

Added in API level 30
static val SCRAMBLING_MODE_AES_ECB: Int

Advanced Encryption System (AES) Electronic Code Book (ECB) mode.

Value: 10

SCRAMBLING_MODE_AES_SCTE52

Added in API level 30
static val SCRAMBLING_MODE_AES_SCTE52: Int

Advanced Encryption System (AES) Society of Cable Telecommunications Engineers (SCTE) 52 mode.

Value: 11

SCRAMBLING_MODE_DVB_CISSA_V1

Added in API level 30
static val SCRAMBLING_MODE_DVB_CISSA_V1: Int

DVB Common IPTV Software-oriented Scrambling Algorithm (CISSA) Version 1.

Value: 6

SCRAMBLING_MODE_DVB_CSA1

Added in API level 30
static val SCRAMBLING_MODE_DVB_CSA1: Int

DVB (Digital Video Broadcasting) Common Scrambling Algorithm (CSA) 1.

Value: 1

SCRAMBLING_MODE_DVB_CSA2

Added in API level 30
static val SCRAMBLING_MODE_DVB_CSA2: Int

DVB CSA 2.

Value: 2

SCRAMBLING_MODE_DVB_CSA3_ENHANCE

Added in API level 30
static val SCRAMBLING_MODE_DVB_CSA3_ENHANCE: Int

DVB CSA 3 in fully enhanced mode.

Value: 5

SCRAMBLING_MODE_DVB_CSA3_MINIMAL

Added in API level 30
static val SCRAMBLING_MODE_DVB_CSA3_MINIMAL: Int

DVB CSA 3 in minimally enhanced mode.

Value: 4

SCRAMBLING_MODE_DVB_CSA3_STANDARD

Added in API level 30
static val SCRAMBLING_MODE_DVB_CSA3_STANDARD: Int

DVB CSA 3 in standard mode.

Value: 3

SCRAMBLING_MODE_DVB_IDSA

Added in API level 30
static val SCRAMBLING_MODE_DVB_IDSA: Int

ATIS-0800006 IIF Default Scrambling Algorithm (IDSA).

Value: 7

SCRAMBLING_MODE_MULTI2

Added in API level 30
static val SCRAMBLING_MODE_MULTI2: Int

A symmetric key algorithm.

Value: 8

SCRAMBLING_MODE_RESERVED

Added in API level 30
static val SCRAMBLING_MODE_RESERVED: Int

DVB (Digital Video Broadcasting) reserved mode.

Value: 0

SCRAMBLING_MODE_TDES_ECB

Added in API level 30
static val SCRAMBLING_MODE_TDES_ECB: Int

Triple Data Encryption Algorithm (TDES) Electronic Code Book (ECB) mode.

Value: 12

SCRAMBLING_MODE_TDES_SCTE52

Added in API level 30
static val SCRAMBLING_MODE_TDES_SCTE52: Int

Triple Data Encryption Algorithm (TDES) Society of Cable Telecommunications Engineers (SCTE) 52 mode.

Value: 13

SESSION_USAGE_LIVE

Added in API level 30
static val SESSION_USAGE_LIVE: Int

Cas session is used to descramble live streams.

Value: 0

SESSION_USAGE_PLAYBACK

Added in API level 30
static val SESSION_USAGE_PLAYBACK: Int

Cas session is used to descramble recoreded streams.

Value: 1

SESSION_USAGE_RECORD

Added in API level 30
static val SESSION_USAGE_RECORD: Int

Cas session is used to descramble live streams and encrypt local recorded content

Value: 2

SESSION_USAGE_TIMESHIFT

Added in API level 30
static val SESSION_USAGE_TIMESHIFT: Int

Cas session is used to descramble live streams , encrypt local recorded content and playback local encrypted content.

Value: 3

Public constructors

MediaCas

Added in API level 26
MediaCas(casSystemId: Int)

Instantiate a CA system of the specified system id.

Parameters
casSystemId Int: The system id of the CA system.
Exceptions
android.media.MediaCasException.UnsupportedCasException if the device does not support the specified CA system.

MediaCas

Added in API level 30
MediaCas(
    context: Context,
    casSystemId: Int,
    tvInputServiceSessionId: String?,
    priorityHint: Int)

Instantiate a CA system of the specified system id.

Parameters
context Context: the context of the caller. This value cannot be null.
casSystemId Int: The system id of the CA system.
tvInputServiceSessionId String?: The Id of the session opened in TV Input Service (TIS) android.media.tv.TvInputService#onCreateSession(String, String) This value may be null.
priorityHint Int: priority hint from the use case type for new created CAS system. Value is android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_BACKGROUND, android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_SCAN, android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK, android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_LIVE, or android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_RECORD
Exceptions
android.media.MediaCasException.UnsupportedCasException if the device does not support the specified CA system.

MediaCas

Added in API level 31
MediaCas(
    context: Context,
    casSystemId: Int,
    tvInputServiceSessionId: String?,
    priorityHint: Int,
    handler: Handler?,
    listener: MediaCas.EventListener?)

Instantiate a CA system of the specified system id with EvenListener.

Parameters
context Context: the context of the caller. This value cannot be null.
casSystemId Int: The system id of the CA system.
tvInputServiceSessionId String?: The Id of the session opened in TV Input Service (TIS) android.media.tv.TvInputService#onCreateSession(String, String) This value may be null.
priorityHint Int: priority hint from the use case type for new created CAS system. Value is android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_BACKGROUND, android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_SCAN, android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_PLAYBACK, android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_LIVE, or android.media.tv.TvInputService#PRIORITY_HINT_USE_CASE_TYPE_RECORD
listener MediaCas.EventListener?: the event listener to be set. This value may be null.
handler Handler?: the handler whose looper the event listener will be called on. If handler is null, we'll try to use current thread's looper, or the main looper. If neither are available, an internal thread will be created instead.
Exceptions
android.media.MediaCasException.UnsupportedCasException if the device does not support the specified CA system.

Public methods

close

Added in API level 26
fun close(): Unit
Exceptions
java.lang.Exception if this resource cannot be closed

enumeratePlugins

Added in API level 26
static fun enumeratePlugins(): Array<MediaCas.PluginDescriptor!>!

List all available CA plugins on the device.

Return
Array<MediaCas.PluginDescriptor!>! an array of descriptors for the available CA plugins.

isSystemIdSupported

Added in API level 26
static fun isSystemIdSupported(CA_system_id: Int): Boolean

Query if a certain CA system is supported on this device.

Parameters
CA_system_id Int: the id of the CA system.
Return
Boolean Whether the specified CA system is supported on this device.

openSession

Added in API level 26
fun openSession(): MediaCas.Session!

Open a session to descramble one or more streams scrambled by the conditional access system.

Tuner resource manager (TRM) uses the client priority value to decide whether it is able to get cas session resource if cas session resources is limited. If the client can't get the resource, this call returns MediaCasException.InsufficientResourceException.

Return
MediaCas.Session! session the newly opened session.
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

openSession

Added in API level 30
fun openSession(
    sessionUsage: Int,
    scramblingMode: Int
): MediaCas.Session?

Open a session with usage and scrambling information, so that descrambler can be configured to descramble one or more streams scrambled by the conditional access system.

Tuner resource manager (TRM) uses the client priority value to decide whether it is able to get cas session resource if cas session resources is limited. If the client can't get the resource, this call returns MediaCasException.InsufficientResourceException.

Parameters
sessionUsage Int: used for the created session. Value is android.media.MediaCas#SESSION_USAGE_LIVE, android.media.MediaCas#SESSION_USAGE_PLAYBACK, android.media.MediaCas#SESSION_USAGE_RECORD, or android.media.MediaCas#SESSION_USAGE_TIMESHIFT
scramblingMode Int: used for the created session. Value is android.media.MediaCas#SCRAMBLING_MODE_RESERVED, android.media.MediaCas#SCRAMBLING_MODE_DVB_CSA1, android.media.MediaCas#SCRAMBLING_MODE_DVB_CSA2, android.media.MediaCas#SCRAMBLING_MODE_DVB_CSA3_STANDARD, android.media.MediaCas#SCRAMBLING_MODE_DVB_CSA3_MINIMAL, android.media.MediaCas#SCRAMBLING_MODE_DVB_CSA3_ENHANCE, android.media.MediaCas#SCRAMBLING_MODE_DVB_CISSA_V1, android.media.MediaCas#SCRAMBLING_MODE_DVB_IDSA, android.media.MediaCas#SCRAMBLING_MODE_MULTI2, android.media.MediaCas#SCRAMBLING_MODE_AES128, android.media.MediaCas#SCRAMBLING_MODE_AES_CBC, android.media.MediaCas#SCRAMBLING_MODE_AES_ECB, android.media.MediaCas#SCRAMBLING_MODE_AES_SCTE52, android.media.MediaCas#SCRAMBLING_MODE_TDES_ECB, or android.media.MediaCas#SCRAMBLING_MODE_TDES_SCTE52
Return
MediaCas.Session? session the newly opened session. This value may be null.
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

processEmm

Added in API level 26
fun processEmm(
    data: ByteArray,
    offset: Int,
    length: Int
): Unit

Send a received EMM packet to the CA system.

Parameters
data ByteArray: byte array of the EMM data. This value cannot be null.
offset Int: position within data where the EMM data begins.
length Int: length of the data (starting from offset).
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

processEmm

Added in API level 26
fun processEmm(data: ByteArray): Unit

Send a received EMM packet to the CA system. This is similar to processEmm(byte[],int,int) except that the entire byte array is sent.

Parameters
data ByteArray: byte array of the EMM data. This value cannot be null.
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

provision

Added in API level 26
fun provision(provisionString: String): Unit

Initiate a provisioning operation for a CA system.

Parameters
provisionString String: string containing information needed for the provisioning operation, the format of which is scheme and implementation specific. This value cannot be null.
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

refreshEntitlements

Added in API level 26
fun refreshEntitlements(
    refreshType: Int,
    refreshData: ByteArray?
): Unit

Notify the CA system to refresh entitlement keys.

Parameters
refreshType Int: the type of the refreshment.
refreshData ByteArray?: private data associated with the refreshment. This value may be null.
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

sendEvent

Added in API level 26
fun sendEvent(
    event: Int,
    arg: Int,
    data: ByteArray?
): Unit

Send an event to a CA system. The format of the event is scheme-specific and is opaque to the framework.

Parameters
event Int: an integer denoting a scheme-specific event to be sent.
arg Int: a scheme-specific integer argument for the event.
data ByteArray?: a byte array containing scheme-specific data for the event. This value may be null.
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

setEventListener

Added in API level 26
fun setEventListener(
    listener: MediaCas.EventListener?,
    handler: Handler?
): Unit

Set an event listener to receive notifications from the MediaCas instance.

Parameters
listener MediaCas.EventListener?: the event listener to be set. This value may be null.
handler Handler?: the handler whose looper the event listener will be called on. If handler is null, we'll try to use current thread's looper, or the main looper. If neither are available, an internal thread will be created instead.

setPrivateData

Added in API level 26
fun setPrivateData(data: ByteArray): Unit

Send the private data for the CA system.

Parameters
data ByteArray: byte array of the private data. This value cannot be null.
Exceptions
java.lang.IllegalStateException if the MediaCas instance is not valid.
android.media.MediaCasException for CAS-specific errors.
android.media.MediaCasStateException for CAS-specific state exceptions.

Protected methods

finalize

Added in API level 26
protected fun finalize(): Unit
Exceptions
java.lang.Throwable the Exception raised by this method