大网数据广告活动
Web 标准与前端开发

RTCRtpScriptTransformer: readable property

· 52CE 我爱测

The **`readable`** read-only property of the RTCRtpScriptTransformer interface returns a ReadableStream instance is a source for encoded media frames.

WebRTC

The readable read-only property of the RTCRtpScriptTransformer interface returns a ReadableStream instance is a source for encoded media frames.

When the corresponding RTCRtpScriptTransform is inserted into the WebRTC sender and receiver pipelines, this stream may be enqueued with outgoing or incoming encoded media frames (RTCEncodedVideoFrame or RTCEncodedAudioFrame). A WebRTC encoded transform can read the frames, modify them as needed, and then send them back into the WebRTC pipeline by writing them to RTCRtpScriptTransformer.writable. A common way to perform this operation is to pipe the frames through a TransformStream.

Value

A ReadableStream.

Examples

The following example shows how readable is piped through a TransformStream to RTCRtpScriptTransformer.writable.

addEventListener("rtctransform", (event) => {
  let transform;
  // Select a transform based on passed options
  if (event.transformer.options.name === "senderTransform")
    transform = createSenderTransform(); // A TransformStream
  else if (event.transformer.options.name === "receiverTransform")
    transform = createReceiverTransform(); // A TransformStream
  else return;

  // Pipe frames from the readable to writeable through TransformStream
  event.transformer.readable
    .pipeThrough(transform)
    .pipeTo(event.transformer.writable);
});

The code implements a handler for the DedicatedWorkerGlobalScope.rtctransform_event event, which is fired at the global worker object on construction of the corresponding RTCRtpScriptTransform, and when new frames are enqueued for processing. event.transformer is the RTCRtpScriptTransformer that has a readable and writable property.

A different TransformStream is created to process outgoing and incoming frames, using createSenderTransform() or createReceiverTransform(), respectively (implementations not shown). The event handler chooses the correct transform stream to use based on options passed through from the RTCRtpScriptTransform constructor and assigns it to transform.

The code calls ReadableStream.pipeThrough() on the readable to pipe encoded frames through the selected TransformStream, and then ReadableStream.pipeTo() to pipe them to the RTCRtpScriptTransformer.writable.

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。