[Pion/WebRTC] Try reading Answer messages 1 (msid-semantic, ssrc)
Tags: webrtc, pion
Published: 2022-07-20 17:32:09

## Intro
From this time, I will try reading answer messages.
Most of the lines are same as offer messages because the answer messages are made according to the offer message.

* [[Pion/WebRTC] Try reading Offer messages](https://dev.to/masanori_msl/pionwebrtc-try-reading-offer-messages-4nho)

I think the main difference between offer and answer is the addition of msid-semantic and ssrc.
So I will try reading them.

## msid-semantic
"a=msid-semantic:~" row is added in the session-level section.

#### SDP Answer Message
```ini
v=0 
o=- 8405074721153909150 2 IN IP4 127.0.0.1 
s=- 
t=0 0 
a=group:BUNDLE 0 1 2 
a=extmap-allow-mixed 
a=msid-semantic: WMS tJtqHKSvpmU907ayq0TVoHEXZKasH43rfz0S
```

This attribute has a group identifier(tJtqHKSvpmU907ayq0TVoHEXZKasH43rfz0S) and its group semantic(WMS:WebRTC Media Stream).
The value of the identifier is the same as the MediaStream ID of the client that sent the answer.

According to the document below, this attribute is for using "a=msid:~" for WebRTC Media Stream.

* [SDP for WebRTC - SlideShare](https://www.slideshare.net/iwashi86/webrtc-for-sdp)

But this attribute is only mentioned in older drafts. 
So I think this attribute may change format or be removed in the future.

* [WebRTC MediaStream Identification in the Session Description Protocol(draft-ietf-mmusic-msid-05)](https://tools.ietf.org/id/draft-ietf-mmusic-msid-05.html#rfc.section.3)

Also, the format of the group identifier varies from client to client.

### Firefox
```
a=msid-semantic: WMS *
```

### microsoft/MixedReality-WebRTC(https://github.com/microsoft/MixedReality-WebRTC)
```
a=msid-semantic: WMS
```

## ssrc(Synchronization Source)
"a=ssrc-group:~" and "a=ssrc:~" rows are added in the media description sections(Video, Audio).

#### SDP Answer Message
```ini
...
m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 102 121 127 120 125 107 108 109 123 118 116
...
a=msid:tJtqHKSvpmU907ayq0TVoHEXZKasH43rfz0S e246d6fc-71e2-4eaa-9e44-0a6e1793fd12 
...
a=ssrc-group:FID 3413810401 2077638419 
a=ssrc:3413810401 cname:nGUZl+/ZMBsWAlSN 
a=ssrc:3413810401 msid:tJtqHKSvpmU907ayq0TVoHEXZKasH43rfz0S e246d6fc-71e2-4eaa-9e44-0a6e1793fd12 
a=ssrc:2077638419 cname:nGUZl+/ZMBsWAlSN 
a=ssrc:2077638419 msid:tJtqHKSvpmU907ayq0TVoHEXZKasH43rfz0S e246d6fc-71e2-4eaa-9e44-0a6e1793fd12 
m=audio 9 UDP/TLS/RTP/SAVPF 111 9 0 8 
...
a=msid:tJtqHKSvpmU907ayq0TVoHEXZKasH43rfz0S 9c775cf1-6300-4535-8e38-73760a8a3f37 
...
a=ssrc:1964009319 cname:nGUZl+/ZMBsWAlSN 
a=ssrc:1964009319 msid:tJtqHKSvpmU907ayq0TVoHEXZKasH43rfz0S 9c775cf1-6300-4535-8e38-73760a8a3f37 
...
```

"ssrc" is for identifing each media sources.

In this sample, every "ssrc" associate "cname", "msid", and "appdata".

In a RTP session, after updating the media source, "ssrc" will be changed.
To avoid losting the media source in the RTP session, "cname" is required when the SDP has "a=ssrc" rows.

At least if the SDP is made by Chrome(Chromium), "msid" is the same as MediaStream ID in JavaScript and "appdata" is the same as MediaStreamTrack.

Because the video stream sends packets with retransmitted packets, this sample has two "ssrc" for video, so "ssrc-group" associats them.

* [RFC5576 - Source-Specific Media Attributes in the Session Description Protocol (SDP)](https://www.rfc-editor.org/rfc/rfc5576.html)
* [RFC8830 - WebRTC MediaStream Identification in the Session Description Protocol](https://www.rfc-editor.org/rfc/rfc8830.html)
* [RFC3550 - RTP: A Transport Protocol for Real-Time Applications](https://www.rfc-editor.org/rfc/rfc3550.html)
* [RFC4588 - RTP Retransmission Payload Format](https://www.rfc-editor.org/rfc/rfc4588.html)
* [Signaling - WebRTC for the Curious](https://webrtcforthecurious.com/docs/02-signaling/)
* [RFC3551 - RTP Profile for Audio and Video Conferences with Minimal Control](https://www.rfc-editor.org/rfc/rfc3551)
* [RFC8829 - JavaScript Session Establishment Protocol (JSEP)](https://www.rfc-editor.org/rfc/rfc8829.html)