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

RTCEncodedAudioFrame: data property

· 52CE 我爱测

The **`data`** property of the RTCEncodedAudioFrame interface returns a buffer containing the data for an encoded frame.

WebRTCwindow_and_dedicated

The data property of the RTCEncodedAudioFrame interface returns a buffer containing the data for an encoded frame.

Value

An ArrayBuffer.

Examples

This example WebRTC encoded transform shows how you might get the frame data in a TransformStream transform() function modify the bits.

The transform() function constructs a DataView on the buffer in the frame data property, and also creates a view on a new ArrayBuffer. It then writes the negated bytes in the original data to the new buffer, assigns the buffer to the encoded frame data property, and enqueues the modified frame on the stream.

addEventListener("rtctransform", (event) => {
  const transform = new TransformStream({
    async transform(encodedFrame, controller) {
      // Reconstruct the original frame.
      const view = new DataView(encodedFrame.data);

      // Construct a new buffer
      const newData = new ArrayBuffer(encodedFrame.data.byteLength);
      const newView = new DataView(newData);

      // Negate all bits in the incoming frame
      for (let i = 0; i < encodedFrame.data.byteLength; ++i) {
        newView.setInt8(i, ~view.getInt8(i));
      }

      encodedFrame.data = newData;
      controller.enqueue(encodedFrame);
    },
  });
  event.transformer.readable
    .pipeThrough(transform)
    .pipeTo(event.transformer.writable);
});

Note that the surrounding code shown here is described in Using WebRTC Encoded Transforms.

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

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

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