webrtcrtpsdp

Which codec will be used after sdp exchange in WebRTC?


In a WebRTC video call

A->B a SDP offer, it means that A supports VP8, VP9 and 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

while B->A answered a SDP answer, it also means that B supports VP8, VP9 and 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
...

My question is in this case, which codec will be used? How A or B knows another choice? Thanks


Solution

  • The answer can be found in 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.

    The offerer will list the supported codecs in order of preference in the m-line. The answerer will most likely honor that preference, but is not obliged to do so. See 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.

    So in short: the offerer and answerer will most likely use the first codec in the answerer's m-line and this may change during the media session.