MediaSampleEncryption Class

How a coded frame of a media segment is encrypted (MediaCodedFrame.Encryption): the key that decrypts it, the initialization vector, and the ranges of the frame that are encrypted. The library decrypts the frame with the keys of the MediaKeys of the media element (Encrypted Media Extensions, https://w3c.github.io/encrypted-media/), and the playback waits for the key when no session has it.

public sealed class MediaSampleEncryption

Constructors

NameDescription
MediaSampleEncryption(MediaEncryptionScheme, ReadOnlyMemory<byte>, ReadOnlyMemory<byte>, IReadOnlyList<MediaSubsample>?)Creates the encryption of a sample.

MediaSampleEncryption(MediaEncryptionScheme, ReadOnlyMemory<byte>, ReadOnlyMemory<byte>, IReadOnlyList<MediaSubsample>?)

MediaSampleEncryption.cs

Creates the encryption of a sample.

public MediaSampleEncryption(MediaEncryptionScheme scheme, ReadOnlyMemory<byte> keyId, ReadOnlyMemory<byte> initializationVector, IReadOnlyList<MediaSubsample>? subsamples = null)

Parameters

scheme MediaEncryptionScheme
The protection scheme.
keyId ReadOnlyMemory<byte>
The ID of the key (16 bytes).
initializationVector ReadOnlyMemory<byte>
The initialization vector: 8 or 16 bytes for MediaEncryptionScheme.Cenc, 16 bytes for MediaEncryptionScheme.Cbcs (the constant IV of the track, or the IV of the sample).
subsamples IReadOnlyList<MediaSubsample>?
The subsamples of the sample, or an empty list when the whole sample is encrypted.

Properties

NameDescription
CryptByteBlockGets the number of encrypted 16-byte blocks of the pattern of MediaEncryptionScheme.Cbcs (the default_crypt_byte_block of the tenc box). With MediaSampleEncryption.SkipByteBlock, 0 and 0 encrypt every block.
InitializationVectorGets the initialization vector of the sample.
KeyIdGets the ID of the key that decrypts the sample.
SchemeGets the protection scheme.
SkipByteBlockGets the number of clear 16-byte blocks that follow the encrypted blocks of the pattern of MediaEncryptionScheme.Cbcs.
SubsamplesGets the subsamples of the sample, or an empty list when the whole sample is encrypted.

Gets the number of encrypted 16-byte blocks of the pattern of MediaEncryptionScheme.Cbcs (the default_crypt_byte_block of the tenc box). With MediaSampleEncryption.SkipByteBlock, 0 and 0 encrypt every block.

public int CryptByteBlock { get; init; }

Property value

int

InitializationVector

MediaSampleEncryption.cs

Gets the initialization vector of the sample.

public ReadOnlyMemory<byte> InitializationVector { get; }

Property value

ReadOnlyMemory<byte>

Gets the ID of the key that decrypts the sample.

public ReadOnlyMemory<byte> KeyId { get; }

Property value

ReadOnlyMemory<byte>

Gets the protection scheme.

public MediaEncryptionScheme Scheme { get; }

Property value

MediaEncryptionScheme

Gets the number of clear 16-byte blocks that follow the encrypted blocks of the pattern of MediaEncryptionScheme.Cbcs.

public int SkipByteBlock { get; init; }

Property value

int

Gets the subsamples of the sample, or an empty list when the whole sample is encrypted.

public IReadOnlyList<MediaSubsample> Subsamples { get; }

Constants

NameDescription
KeyIdLengthThe length of the key IDs and of the keys of the Common Encryption schemes, in bytes.

KeyIdLength

The length of the key IDs and of the keys of the Common Encryption schemes, in bytes.

public const int KeyIdLength = 16