Chromium Code Reviews| Index: webrtc/pc/webrtcsdp.cc |
| diff --git a/webrtc/pc/webrtcsdp.cc b/webrtc/pc/webrtcsdp.cc |
| index 13d09a6ee96efd33219e6e7df89ba5983cb49d7e..6ae16c0549acf4fa94b58b12a60796fbd2abafaf 100644 |
| --- a/webrtc/pc/webrtcsdp.cc |
| +++ b/webrtc/pc/webrtcsdp.cc |
| @@ -249,11 +249,13 @@ static void BuildIceOptions(const std::vector<std::string>& transport_options, |
| std::string* message); |
| static bool IsRtp(const std::string& protocol); |
| static bool IsDtlsSctp(const std::string& protocol); |
| -static bool ParseSessionDescription(const std::string& message, size_t* pos, |
| +static bool ParseSessionDescription(const std::string& message, |
| + size_t* pos, |
| std::string* session_id, |
| std::string* session_version, |
| TransportDescription* session_td, |
| RtpHeaderExtensions* session_extmaps, |
| + rtc::SocketAddress* connection_addr, |
| cricket::SessionDescription* desc, |
| SdpParseError* error); |
| static bool ParseGroupAttribute(const std::string& line, |
| @@ -263,7 +265,9 @@ static bool ParseMediaDescription( |
| const std::string& message, |
| const TransportDescription& session_td, |
| const RtpHeaderExtensions& session_extmaps, |
| - size_t* pos, cricket::SessionDescription* desc, |
| + size_t* pos, |
| + const rtc::SocketAddress& session_connection_addr, |
| + cricket::SessionDescription* desc, |
| std::vector<JsepIceCandidate*>* candidates, |
| SdpParseError* error); |
| static bool ParseContent(const std::string& message, |
| @@ -713,7 +717,7 @@ static void GetDefaultDestination( |
| } |
| } |
| -// Update |mline|'s default destination and append a c line after it. |
| +// Update |mline|'s default destination. |
| static void UpdateMediaDefaultDestination( |
| const std::vector<Candidate>& candidates, |
| const std::string& mline, |
| @@ -745,12 +749,6 @@ static void UpdateMediaDefaultDestination( |
| fields[1].size(), |
| rtp_port); |
| } |
| - // Add the c line. |
| - // RFC 4566 |
| - // c=<nettype> <addrtype> <connection-address> |
| - InitLine(kLineTypeConnection, kConnectionNettype, &os); |
| - os << " " << addr_type << " " << rtp_ip; |
| - AddLine(os.str(), &new_lines); |
|
Taylor Brandstetter
2017/03/15 17:57:20
We shouldn't remove this "default destination" log
|
| message->append(new_lines); |
| } |
| @@ -902,6 +900,7 @@ bool SdpDeserialize(const std::string& message, |
| std::string session_version; |
| TransportDescription session_td("", ""); |
| RtpHeaderExtensions session_extmaps; |
| + rtc::SocketAddress session_connection_addr; |
| cricket::SessionDescription* desc = new cricket::SessionDescription(); |
| std::vector<JsepIceCandidate*> candidates; |
| size_t current_pos = 0; |
| @@ -909,14 +908,15 @@ bool SdpDeserialize(const std::string& message, |
| // Session Description |
| if (!ParseSessionDescription(message, ¤t_pos, &session_id, |
| &session_version, &session_td, &session_extmaps, |
| - desc, error)) { |
| + &session_connection_addr, desc, error)) { |
| delete desc; |
| return false; |
| } |
| // Media Description |
| if (!ParseMediaDescription(message, session_td, session_extmaps, ¤t_pos, |
| - desc, &candidates, error)) { |
| + session_connection_addr, desc, &candidates, |
| + error)) { |
| delete desc; |
| for (std::vector<JsepIceCandidate*>::const_iterator |
| it = candidates.begin(); it != candidates.end(); ++it) { |
| @@ -1328,6 +1328,18 @@ void BuildMediaDescription(const ContentInfo* content_info, |
| std::string mline = os.str(); |
| UpdateMediaDefaultDestination(candidates, mline, message); |
| + InitLine(kLineTypeConnection, kConnectionNettype, &os); |
| + if (media_desc->connection_addr().family() == AF_INET) { |
| + os << " " |
| + << "IP4" |
| + << " " << media_desc->connection_addr().ipaddr().ToString(); |
| + } else { |
| + os << " " |
| + << "IP6" |
| + << " " << media_desc->connection_addr().ipaddr().ToString(); |
| + } |
| + AddLine(os.str(), message); |
| + |
| // RFC 4566 |
| // b=AS:<bandwidth> |
| if (media_desc->bandwidth() >= 1000) { |
| @@ -1900,11 +1912,62 @@ bool IsDtlsSctp(const std::string& protocol) { |
| return protocol.find(cricket::kMediaProtocolDtlsSctp) != std::string::npos; |
| } |
| -bool ParseSessionDescription(const std::string& message, size_t* pos, |
| +bool ParseConnectionData(const std::string& line, |
| + rtc::SocketAddress* addr, |
| + SdpParseError* error) { |
| + // Parse the line from left to right. |
| + std::string token; |
| + std::string rightpart; |
| + // RFC 4566 |
| + // c=<nettype> <addrtype> <connection-address> |
| + // Skip the "c=" |
| + if (!rtc::tokenize_first(line, kSdpDelimiterEqual, &token, &rightpart)) { |
| + return ParseFailed(line, "Failed to parse the network type.", error); |
| + } |
| + |
| + // Extract and verify the <nettype> |
| + if (!rtc::tokenize_first(rightpart, kSdpDelimiterSpace, &token, &rightpart) || |
| + token != kConnectionNettype) { |
| + return ParseFailed(line, |
| + "Failed to parse the connection data. The network type " |
| + "is not currently supported.", |
| + error); |
| + } |
| + |
| + // Extract the "<addrtype>" and "<connection-address>". |
| + if (!rtc::tokenize_first(rightpart, kSdpDelimiterSpace, &token, &rightpart)) { |
| + return ParseFailed(line, "Failed to parse the address type.", error); |
| + } |
| + |
| + // The rightpart part should be the IP address without the slash which is used |
| + // for multicast. |
| + if (rightpart.find('/') != std::string::npos) { |
| + return ParseFailed(line, |
| + "Failed to parse the connection data. Multicast is not " |
| + "currently supported.", |
| + error); |
| + } |
| + addr->SetIP(rightpart); |
| + |
| + // Verify that the addrtype matches the type of the parsed address. |
| + if ((addr->family() == AF_INET && token != "IP4") || |
| + (addr->family() == AF_INET6 && token != "IP6")) { |
| + addr->Clear(); |
| + return ParseFailed( |
| + line, |
| + "Failed to parse the connection data. The address type is mismatching.", |
| + error); |
| + } |
| + return true; |
| +} |
| + |
| +bool ParseSessionDescription(const std::string& message, |
| + size_t* pos, |
| std::string* session_id, |
| std::string* session_version, |
| TransportDescription* session_td, |
| RtpHeaderExtensions* session_extmaps, |
| + rtc::SocketAddress* connection_addr, |
| cricket::SessionDescription* desc, |
| SdpParseError* error) { |
| std::string line; |
| @@ -1962,7 +2025,11 @@ bool ParseSessionDescription(const std::string& message, size_t* pos, |
| // RFC 4566 |
| // c=* (connection information -- not required if included in |
| // all media) |
| - GetLineWithType(message, pos, &line, kLineTypeConnection); |
| + if (GetLineWithType(message, pos, &line, kLineTypeConnection)) { |
| + if (!ParseConnectionData(line, connection_addr, error)) { |
| + return false; |
| + } |
| + } |
| // RFC 4566 |
| // b=* (zero or more bandwidth information lines) |
| @@ -2266,7 +2333,7 @@ static C* ParseContentDescription(const std::string& message, |
| pos, content_name, bundle_only, media_desc, transport, |
| candidates, error)) { |
| delete media_desc; |
| - return NULL; |
| + return nullptr; |
| } |
| // Sort the codecs according to the m-line fmt list. |
| std::unordered_map<int, int> payload_type_preferences; |
| @@ -2291,6 +2358,7 @@ bool ParseMediaDescription(const std::string& message, |
| const TransportDescription& session_td, |
| const RtpHeaderExtensions& session_extmaps, |
| size_t* pos, |
| + const rtc::SocketAddress& session_connection_addr, |
| cricket::SessionDescription* desc, |
| std::vector<JsepIceCandidate*>* candidates, |
| SdpParseError* error) { |
| @@ -2420,6 +2488,13 @@ bool ParseMediaDescription(const std::string& message, |
| } |
| } |
| content->set_protocol(protocol); |
| + |
| + // Use the session level connection address if the media level addresses are |
| + // not specified. |
| + if (content->connection_addr().IsNil()) { |
| + content->set_connection_addr(session_connection_addr); |
| + } |
| + |
| desc->AddContent(content_name, |
| IsDtlsSctp(protocol) ? cricket::NS_JINGLE_DRAFT_SCTP |
| : cricket::NS_JINGLE_RTP, |
| @@ -2668,6 +2743,16 @@ bool ParseContent(const std::string& message, |
| continue; |
| } |
| + // Parse the media level connection data. |
| + if (IsLineType(line, kLineTypeConnection)) { |
| + rtc::SocketAddress addr; |
| + if (!ParseConnectionData(line, &addr, error)) { |
| + return false; |
| + } |
| + media_desc->set_connection_addr(addr); |
| + continue; |
| + } |
| + |
| if (!IsLineType(line, kLineTypeAttributes)) { |
| // TODO: Handle other lines if needed. |
| LOG(LS_INFO) << "Ignored line: " << line; |