/// <summary> /// Updates the session after receiving the remote SDP. /// At this point check that the codecs match. We currently only support: /// - Audio: PCMU, /// - Video: VP8. /// If they are not available there's no point carrying on. /// </summary> /// <param name="remoteSdp">The answer/offer SDP from the remote party.</param> public void OnSdpAnswer(SDP remoteSdp) { // Check remote party audio is acceptable. if (_supportedAudioFormats?.Count() > 0) { var remoteAudioOffer = remoteSdp.Media.Where(x => x.Media == SDPMediaTypesEnum.audio).FirstOrDefault(); if (remoteAudioOffer?.MediaFormats.Count() == 0) { logger.LogWarning("No audio formats were available in the remote party's SDP."); Close("No audio codecs offered."); } else if (remoteAudioOffer.MediaFormats.Select(x => x.FormatCodec).Union(_supportedAudioFormats.Select(y => y.FormatCodec)).Count() == 0) { logger.LogWarning("No matching audio codec was available."); Close("No matching audio codec."); } } // Check remote party video is acceptable. if (_supportedVideoFormats?.Count() > 0) { var remoteVideoOffer = remoteSdp.Media.Where(x => x.Media == SDPMediaTypesEnum.video).FirstOrDefault(); if (remoteVideoOffer?.MediaFormats.Count() == 0) { logger.LogWarning("No video formats were available in the remote party's SDP."); Close("No video codecs offered."); } else if (remoteVideoOffer.MediaFormats.Select(x => x.FormatCodec).Union(_supportedVideoFormats.Select(y => y.FormatCodec)).Count() == 0) { logger.LogWarning("No matching video codec was available."); Close("No matching video codec."); } // Since we only currently support VP8 there's only a single remote payload ID that can be // associated with the video stream. var remoteVP8MediaFormat = remoteVideoOffer.MediaFormats.Where(x => x.FormatCodec == SDPMediaFormatsEnum.VP8).Single(); RtpSession.AddStream(SDPMediaTypesEnum.video, VP8_PAYLOAD_TYPE_ID, new List <int> { Convert.ToInt32(remoteVP8MediaFormat.FormatID) }); } SdpSessionID = remoteSdp.SessionId; RemoteIceUser = remoteSdp.IceUfrag; RemoteIcePassword = remoteSdp.IcePwd; // All browsers seem to have gone to trickling ICE candidates now but just // in case one or more are given we can start the STUN dance immediately. if (remoteSdp.IceCandidates != null) { foreach (var iceCandidate in remoteSdp.IceCandidates) { AppendRemoteIceCandidate(iceCandidate); } } }
public WebRtcSession(string dtlsFingerprint, List <IPAddress> offerAddresses) { _dtlsCertificateFingerprint = dtlsFingerprint; SessionID = Guid.NewGuid().ToString(); _rtpSession = new RTPSession((int)SDPMediaFormatsEnum.PCMU, AddressFamily.InterNetwork, true); _videoSessionID = _rtpSession.AddStream(VP8_PAYLOAD_TYPE_ID, null); _rtpChannel = _rtpSession.RtpChannel; _rtpChannel.OnRTPDataReceived += OnRTPDataReceived; _rtpSession.OnRtpClosed += Close; _offerAddresses = offerAddresses; }