WebRTC中sdp exchange后会用到哪个codec?

Which codec will be used after sdp exchange in WebRTC?

在 WebRTC 视频通话中

A​​->B一个SDP offer,表示A支持VP8、VP9和H264

m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127 124 125
a=sendrecv
a=rtpmap:96 VP8/90000
...
a=rtpmap:98 VP9/90000
...
a=rtpmap:100 H264/90000

虽然B->A回答了一个SDP回答,也意味着B支持VP8、VP9和H264

m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 127 124 125
a=sendrecv
a=rtpmap:96 VP8/90000
...
a=rtpmap:98 VP9/90000
...
a=rtpmap:100 H264/90000
...

我的问题是在这种情况下,将使用哪种编解码器? A或B怎么知道另一个选择? 谢谢

B 表示它更喜欢 96,即 VP8,因为它在 m= 行格式中排在第一位。

https://webrtc.github.io/samples/src/content/peerconnection/change-codecs/ 有一个示例允许您更改编解码器的顺序并检查结果。

答案可以在 RFC3264 中找到。

Section 5.1:

If multiple formats are listed, it means that the offerer is capable of making use of any of those formats during the session. In other words, the answerer MAY change formats in the middle of the session, making use of any of the formats listed, without sending a new offer.

提供者将在 m 行中按优先顺序列出支持的编解码器。回答者很可能会尊重该偏好,但没有义务这样做。见 Section 6.1:

Although the answerer MAY list the formats in their desired order of preference, it is RECOMMENDED that unless there is a specific reason, the answerer list formats in the same relative order they were present in the offer.

Section 7:

When the offerer receives the answer, it MAY send media on the accepted stream(s) (assuming it is listed as sendrecv or recvonly in the answer). It MUST send using a media format listed in the answer, and it SHOULD use the first media format listed in the answer when it does send.

简而言之:提供者和回答者很可能会使用回答者 m 行中的第一个编解码器,这可能会在媒体会话期间发生变化。