RTCEncodedAudioFrame: data property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since August 2023.

Note: This feature is available in Dedicated Web Workers.

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.

js
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

Specification
WebRTC Encoded Transform
# dom-rtcencodedaudioframe-data

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
data
Chrome – Full support
Chrome 86 (Release date: 2020-10-20)
footnote Full support
Edge – Full support
Edge 86 (Release date: 2020-10-09)
footnote Full support
Firefox – Full support
Firefox 117 (Release date: 2023-08-29)
footnote Full support
Opera – Full support
Opera 72 (Release date: 2020-10-21)
footnote Full support
Safari – Full support
Safari 15.4 (Release date: 2022-03-14)
footnote Full support
Chrome Android – Full support
Chrome Android 86 (Release date: 2020-10-20)
footnote Full support
Firefox for Android – Full support
Firefox for Android 117 (Release date: 2023-08-29)
footnote Full support
Opera Android – Full support
Opera Android 61 (Release date: 2020-12-07)
footnote Full support
Safari on iOS – Full support
Safari on iOS 15.4 (Release date: 2022-03-14)
footnote Full support
Samsung Internet – Full support
Samsung Internet 14 (Release date: 2021-04-17)
footnote Full support
WebView Android – Full support
WebView Android 86 (Release date: 2020-10-20)
footnote Full support
WebView on iOS – Full support
WebView on iOS 15.4 (Release date: 2022-03-14)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also