SFrame transforms

SFrame transforms of WebRTC Encoded Transform, which encrypt encoded frames end to end with SFrame (RFC 9605).

A key is given as the raw bytes of the RFC 9605 base key together with a key id, in place of a CryptoKey. Whole frames are encrypted (“per-frame”). Codecs whose RTP packetization parses the payload, such as H.264 and AV1, can’t be used. VP8, VP9 and Opus work.

webrtc.interfaces.sframe_transform.SFrameInput

A chunk the SFrame streams take, which is an encoded frame or any buffer

alias of RTCEncodedVideoFrame | RTCEncodedAudioFrame | Buffer

webrtc.interfaces.sframe_transform.SFrameChunk

A chunk the SFrame streams output, which is the encoded frame written or bytes for a buffer

alias of RTCEncodedVideoFrame | RTCEncodedAudioFrame | bytes

class webrtc.interfaces.sframe_transform.RTCRtpSFrameEncryptor(options)

Encrypts the frames of a sender with SFrame, once set as its transform.

Frames are encrypted natively, off the event loop. Until a key is set, frames are dropped so none go out in clear.

Parameters:

options (webrtc.RTCRtpSFrameEncryptorOptions) – The cipher suite and SFrame type.

Raises:

Example:

encryptor = webrtc.RTCRtpSFrameEncryptor(webrtc.RTCRtpSFrameEncryptorOptions('AES_128_GCM_SHA256_128'))
await encryptor.set_encryption_key(key, 1)
sender.transform = encryptor
class webrtc.interfaces.sframe_transform.RTCRtpSFrameDecryptor(options)

Decrypts the SFrame frames of a receiver, once set as its transform.

Frames are decrypted natively, off the event loop. A frame that fails to decrypt is dropped and reported by an error event.

Parameters:

options (webrtc.SFrameTransformOptions) – The cipher suite.

Raises:

TypeError – If the options aren’t webrtc.SFrameTransformOptions.

Events:

error (webrtc.SFrameTransformErrorEvent) – A frame didn’t decrypt.

Events

Handlers are registered with on().

class webrtc.interfaces.sframe_transform.SFrameEncryptorStream(options)

A transform stream that encrypts the frames or buffers written to it with SFrame.

It has readable and writable like a webrtc.TransformStream, so it can be piped through in the worker of an webrtc.RTCRtpScriptTransform. A frame comes out with its data encrypted, and a buffer comes out as the bytes of the ciphertext. Until a key is set, chunks are dropped. The type parameter is the output type. It’s encoded frames by default, and SFrameEncryptorStream[bytes] handles buffers.

Parameters:

options (webrtc.SFrameTransformOptions) – The cipher suite.

Raises:

TypeError – If the options aren’t webrtc.SFrameTransformOptions.

Example:

async def worker(event):
    encryptor = webrtc.SFrameEncryptorStream(webrtc.SFrameTransformOptions('AES_128_GCM_SHA256_128'))
    await encryptor.set_encryption_key(key, 1)
    transformer = event.transformer
    await transformer.readable.pipe_through(encryptor).pipe_to(transformer.writable)
class webrtc.interfaces.sframe_transform.SFrameDecryptorStream(options)

A transform stream that decrypts the SFrame frames or buffers written to it.

It has readable and writable like a webrtc.TransformStream. A frame comes out with its data decrypted, and a buffer comes out as the bytes of the plaintext. A chunk that fails to decrypt is dropped and reported by an error event. The type parameter is the output type. It’s encoded frames by default, and SFrameDecryptorStream[bytes] handles buffers.

Parameters:

options (webrtc.SFrameTransformOptions) – The cipher suite.

Raises:

TypeError – If the options aren’t webrtc.SFrameTransformOptions.

Events:

error (webrtc.SFrameTransformErrorEvent) – A chunk didn’t decrypt.

Events

Handlers are registered with on().