RTCRtpReceiver: transform property
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Thetransform
property of theRTCRtpReceiver
object is used to insert a transform stream (TransformStream
) running in a worker thread into the receiver pipeline.This allows stream transforms to be applied to encoded video and audio frames as they arrive from the packetizer (before they are played/rendered).
The transform that is to be added is defined using anRTCRtpScriptTransform
and its associatedWorker
.If the transform is set in the peer connectiontrack
event handler, the transform stream will receive the first full incoming frame for the track.
Value
ARTCRtpScriptTransform
, ornull
if the receiver has no associated transform stream.
Example
Note that this is part of a larger example in the guide topicUsing WebRTC Encoded Transforms.
Adding a transform for incoming frames
This example shows how you add a WebRTC encoded transform to modify an incoming stream.The code assumes that there is anRTCPeerConnection
calledpeerConnection
that is already connected to a remote peer.
To add a transform stream into the pipeline for incoming frames we need to construct anRTCRtpScriptTransform
and assign it to the receiver'stransform
property.We can do this in thetrack
event handler as shown.This event is fired on the peer connection whenever the remote end sends a track.Theevent.receiver
property is anRTCRtpReceiver
.
const worker = new Worker("worker.js");peerConnection.ontrack = (event) => { event.receiver.transform = new RTCRtpScriptTransform(worker, { someOption: "receiverTransform", });};
Because the transform is constructed immediately after creation of theRTCRtpReceiver
, it will receive the first incoming frame.The object passed as the second parameter in theRTCRtpScriptTransform
constructor is sent to the worker thread, and can be used by worker code to provide a different transform for the incoming frames than is used for outgoing frames.
Specifications
Specification |
---|
WebRTC Encoded Transform # dom-rtcrtpsender-transform |