[webrtc-rtptransport] BYOB also needs fields giving the byte length (#62)

tonyherre has just created a new issue for https://github.com/w3c/webrtc-rtptransport:

== BYOB also needs fields giving the byte length ==
Trying to implement and use the BYOB methods added in #44, it's difficult to work with them without a field indicating the byte length of the payload etc - you have to first guess and hope your prepared buffer is big enough to receive the data (and need to handle the error if it's too small, reallocate a larger buffer and try again), and after `copyPayloadTo()` returns there's no way to tell where in your large buffer the copied payload ends:
```
let myBuffer = new ArrayBuffer(initialSize);
function HandlePacket(rtcRtpPacket) {
  while(true) {
    try {
      rtcRtpPacket.copyPayloadTo(myBuffer);
      break;
    } catch {
      myBuffer = new ArrayBuffer(myBuffer.byteLength*1.5);
    }
  }
  processThePayload(new Uint8Array(myBuffer, /*length=*/???)); 
}
```


WebCodecs has companion [byteLength](https://www.w3.org/TR/webcodecs/#dom-encodedvideochunk-bytelength) fields next to all of its `copyTo()` methods, which I think we should have added too:
```
let myBuffer = new ArrayBuffer(initialSize);
function HandlePacket(rtcRtpPacket) {
  if (myBuffer.byteLength < rtcRtpPacket.payloadByteLength) {
    myBuffer = new ArrayBuffer(rtcRtpPacket.payloadByteLength); // etc
  }
  rtcRtpPacket.copyPayloadTo(myBuffer);
  processThePayload(new Uint8Array(myBuffer, rtcRtpPacket.payloadByteLength));
}
```


Sure, MTUs might give some decent upperbound for packet sizes, but that's probably a big overestimate for most payloads, and particularly for Header Extension bytes. We still also have the issue of telling how much data was copied.

Please view or discuss this issue at https://github.com/w3c/webrtc-rtptransport/issues/62 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Thursday, 1 August 2024 09:41:23 UTC