[webrtc-pc] What is setCodecPreferences's contract? (#2845)

jan-ivar has just created a new issue for https://github.com/w3c/webrtc-pc:

== What is setCodecPreferences's contract? ==
If codecs were [interfaces](https://webidl.spec.whatwg.org/#dfn-interface) (platform objects passed by reference) with [read only](https://webidl.spec.whatwg.org/#dfn-read-only) members, then prose in [setCodecPreferences](https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences) would make sense: _"The codecs sequence passed into [setCodecPreferences](https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences) can only contain codecs that are returned by [RTCRtpSender](https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender).[getCapabilities](https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-getcapabilities)(kind) or [RTCRtpReceiver](https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver).[getCapabilities](https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-getcapabilities)(kind)"_.

The user agent could easily enforce this, giving us a nice and tight contract:
```js
const {codecs} = RTCRtpSender.getCapabilities(transceiver.sender.track.kind);
transceiver.setCodecPreferences([codecs[0]]); // OK
transceiver.setCodecPreferences([{mimeType: "video/VP8", clockRate: 90000}]); // InvalidModificationError
```
...because the second input clearly did NOT come from RTCRtpSender.getCapabilities() or RTCRtpReceiver.getCapabilities().

Q1: Was this the intended contract?

Unfortunately, codecs aren't platform objects passed by reference, so there's no way to ensure they came from either.

_" ... Additionally, the [RTCRtpCodecCapability](https://w3c.github.io/webrtc-pc/#dom-rtcrtpcodeccapability) dictionary members cannot be modified."_

Um, yes they can!

_" ... If codecs does not fulfill these requirements, the user agent MUST [throw](https://webidl.spec.whatwg.org/#dfn-throw) an [InvalidModificationError](https://webidl.spec.whatwg.org/#invalidmodificationerror)."_

The intent here seems to be to ensure the dictionaries have not been modified since they were obtained using RTCRtp*.getCapabilities(). Again, since we have no way to know they came from there, the closest thing we could do would be to check that a serialized representation of the dictionary matches a serialized representation of one (or more) dictionaries that RTCRtp*.getCapabilities() regularly produces (i.e. a member-wise comparison).

But knowing this, should the second input now succeed or throw?
```js
transceiver.setCodecPreferences([{mimeType: "video/VP8", clockRate: 90000}]);
```
The answer is NO, because it's missing 



But now we have a problem. Doe 
, but what does that mean?
. But compared to what? Again, dictionaries 


So this is allowed:
```js
const {codecs} = RTCRtpSender.getCapabilities(transceiver.sender.track.kind);
transceiver.setCodecPreferences(codecs);
```

As mentioned in https://github.com/w3c/webrtc-pc/issues/2805, [setCodecPreferences](https://w3c.github.io/webrtc-pc/#dom-rtcrtptransceiver-setcodecpreferences) isn't implementable as written.





Additionally, the [RTCRtpCodecCapability](https://w3c.github.io/webrtc-pc/#dom-rtcrtpcodeccapability) dictionary members cannot be modified. If codecs does not fulfill these requirements, the user agent MUST [throw](https://webidl.spec.whatwg.org/#dfn-throw) an [InvalidModificationError](https://webidl.spec.whatwg.org/#invalidmodificationerror).


Modifiable codecs make a mess of setCodecPreferences, which seems written as

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


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

Received on Friday, 24 March 2023 22:28:34 UTC