Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 1882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1893 bool IsRtp(const std::string& protocol) { | 1893 bool IsRtp(const std::string& protocol) { |
| 1894 return protocol.empty() || | 1894 return protocol.empty() || |
| 1895 (protocol.find(cricket::kMediaProtocolRtpPrefix) != std::string::npos); | 1895 (protocol.find(cricket::kMediaProtocolRtpPrefix) != std::string::npos); |
| 1896 } | 1896 } |
| 1897 | 1897 |
| 1898 bool IsDtlsSctp(const std::string& protocol) { | 1898 bool IsDtlsSctp(const std::string& protocol) { |
| 1899 // This intentionally excludes "SCTP" and "SCTP/DTLS". | 1899 // This intentionally excludes "SCTP" and "SCTP/DTLS". |
| 1900 return protocol.find(cricket::kMediaProtocolDtlsSctp) != std::string::npos; | 1900 return protocol.find(cricket::kMediaProtocolDtlsSctp) != std::string::npos; |
| 1901 } | 1901 } |
| 1902 | 1902 |
| 1903 bool ParseConnectionData(const std::string line, rtc::SocketAddress* addr) { | |
|
Taylor Brandstetter
2017/03/10 22:41:18
Meant to be const ref string?
Zhi Huang
2017/03/15 04:04:59
Ah, yes. I missed the &.
| |
| 1904 // Parse the line from left to right. | |
| 1905 std::string token; | |
| 1906 std::string rightpart; | |
| 1907 // RFC 4566 | |
| 1908 // c=<nettype> <addrtype> <connection-address> | |
| 1909 // Skip "c=<nettype>". | |
|
Taylor Brandstetter
2017/03/10 22:41:18
We should verify that "nettype" is "IN" since that
Zhi Huang
2017/03/15 04:04:59
Done.
| |
| 1910 if (!rtc::tokenize_first(line, kSdpDelimiterSpace, &token, &rightpart)) { | |
| 1911 return false; | |
| 1912 } | |
| 1913 // Skip the "<addrtype>". | |
|
Taylor Brandstetter
2017/03/10 22:41:18
To be more thorough, we could verify that addrtype
Zhi Huang
2017/03/15 04:04:59
Done.
| |
| 1914 if (!rtc::tokenize_first(rightpart, kSdpDelimiterSpace, &token, &rightpart)) { | |
| 1915 return false; | |
| 1916 } | |
| 1917 // Extract the IP address. The rightpart part should be the IP address without | |
| 1918 // the slash which is used for multicast. | |
| 1919 if (rightpart.find('/') != std::string::npos) { | |
| 1920 LOG(LS_ERROR) << "Failed to parse the connection data. Multicast is not " | |
|
Taylor Brandstetter
2017/03/10 22:41:18
This method should take an error output parameter
Zhi Huang
2017/03/15 04:04:59
Done.
| |
| 1921 "currently supported."; | |
| 1922 return false; | |
| 1923 } | |
| 1924 addr->SetIP(rightpart); | |
| 1925 return true; | |
| 1926 } | |
| 1927 | |
| 1903 bool ParseSessionDescription(const std::string& message, size_t* pos, | 1928 bool ParseSessionDescription(const std::string& message, size_t* pos, |
| 1904 std::string* session_id, | 1929 std::string* session_id, |
| 1905 std::string* session_version, | 1930 std::string* session_version, |
| 1906 TransportDescription* session_td, | 1931 TransportDescription* session_td, |
| 1907 RtpHeaderExtensions* session_extmaps, | 1932 RtpHeaderExtensions* session_extmaps, |
| 1908 cricket::SessionDescription* desc, | 1933 cricket::SessionDescription* desc, |
| 1909 SdpParseError* error) { | 1934 SdpParseError* error) { |
| 1910 std::string line; | 1935 std::string line; |
| 1911 | 1936 |
| 1912 desc->set_msid_supported(false); | 1937 desc->set_msid_supported(false); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1955 // e=* (email address) | 1980 // e=* (email address) |
| 1956 GetLineWithType(message, pos, &line, kLineTypeSessionEmail); | 1981 GetLineWithType(message, pos, &line, kLineTypeSessionEmail); |
| 1957 | 1982 |
| 1958 // RFC 4566 | 1983 // RFC 4566 |
| 1959 // p=* (phone number) | 1984 // p=* (phone number) |
| 1960 GetLineWithType(message, pos, &line, kLineTypeSessionPhone); | 1985 GetLineWithType(message, pos, &line, kLineTypeSessionPhone); |
| 1961 | 1986 |
| 1962 // RFC 4566 | 1987 // RFC 4566 |
| 1963 // c=* (connection information -- not required if included in | 1988 // c=* (connection information -- not required if included in |
| 1964 // all media) | 1989 // all media) |
| 1965 GetLineWithType(message, pos, &line, kLineTypeConnection); | 1990 if (GetLineWithType(message, pos, &line, kLineTypeConnection)) { |
| 1991 rtc::SocketAddress addr; | |
| 1992 if (!ParseConnectionData(line, &addr)) { | |
| 1993 LOG(LS_ERROR) << "Failed to parse the session level connection data:" | |
|
Taylor Brandstetter
2017/03/10 22:41:18
This doesn't need to log an error if ParseConnecti
Zhi Huang
2017/03/15 04:04:59
Done.
| |
| 1994 << line; | |
| 1995 return false; | |
| 1996 } | |
| 1997 desc->set_session_connection_addr(rtc::Optional<rtc::SocketAddress>(addr)); | |
| 1998 } | |
| 1966 | 1999 |
| 1967 // RFC 4566 | 2000 // RFC 4566 |
| 1968 // b=* (zero or more bandwidth information lines) | 2001 // b=* (zero or more bandwidth information lines) |
| 1969 while (GetLineWithType(message, pos, &line, kLineTypeSessionBandwidth)) { | 2002 while (GetLineWithType(message, pos, &line, kLineTypeSessionBandwidth)) { |
| 1970 // By pass zero or more b lines. | 2003 // By pass zero or more b lines. |
| 1971 } | 2004 } |
| 1972 | 2005 |
| 1973 // RFC 4566 | 2006 // RFC 4566 |
| 1974 // One or more time descriptions ("t=" and "r=" lines; see below) | 2007 // One or more time descriptions ("t=" and "r=" lines; see below) |
| 1975 // t= (time the session is active) | 2008 // t= (time the session is active) |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2259 *content_name = cricket::CN_DATA; | 2292 *content_name = cricket::CN_DATA; |
| 2260 break; | 2293 break; |
| 2261 default: | 2294 default: |
| 2262 RTC_NOTREACHED(); | 2295 RTC_NOTREACHED(); |
| 2263 break; | 2296 break; |
| 2264 } | 2297 } |
| 2265 if (!ParseContent(message, media_type, mline_index, protocol, payload_types, | 2298 if (!ParseContent(message, media_type, mline_index, protocol, payload_types, |
| 2266 pos, content_name, bundle_only, media_desc, transport, | 2299 pos, content_name, bundle_only, media_desc, transport, |
| 2267 candidates, error)) { | 2300 candidates, error)) { |
| 2268 delete media_desc; | 2301 delete media_desc; |
| 2269 return NULL; | 2302 return nullptr; |
| 2270 } | 2303 } |
| 2271 // Sort the codecs according to the m-line fmt list. | 2304 // Sort the codecs according to the m-line fmt list. |
| 2272 std::unordered_map<int, int> payload_type_preferences; | 2305 std::unordered_map<int, int> payload_type_preferences; |
| 2273 // "size + 1" so that the lowest preference payload type has a preference of | 2306 // "size + 1" so that the lowest preference payload type has a preference of |
| 2274 // 1, which is greater than the default (0) for payload types not in the fmt | 2307 // 1, which is greater than the default (0) for payload types not in the fmt |
| 2275 // list. | 2308 // list. |
| 2276 int preference = static_cast<int>(payload_types.size() + 1); | 2309 int preference = static_cast<int>(payload_types.size() + 1); |
| 2277 for (int pt : payload_types) { | 2310 for (int pt : payload_types) { |
| 2278 payload_type_preferences[pt] = preference--; | 2311 payload_type_preferences[pt] = preference--; |
| 2279 } | 2312 } |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2661 return ParseFailed(line, description.str(), error); | 2694 return ParseFailed(line, description.str(), error); |
| 2662 } | 2695 } |
| 2663 // Prevent integer overflow. | 2696 // Prevent integer overflow. |
| 2664 b = std::min(b, INT_MAX / 1000); | 2697 b = std::min(b, INT_MAX / 1000); |
| 2665 media_desc->set_bandwidth(b * 1000); | 2698 media_desc->set_bandwidth(b * 1000); |
| 2666 } | 2699 } |
| 2667 } | 2700 } |
| 2668 continue; | 2701 continue; |
| 2669 } | 2702 } |
| 2670 | 2703 |
| 2704 // Parse the media level connection data. | |
| 2705 if (IsLineType(line, kLineTypeConnection)) { | |
| 2706 rtc::SocketAddress addr; | |
| 2707 if (!ParseConnectionData(line, &addr)) { | |
| 2708 LOG(LS_ERROR) << "Failed to parse the session level connection data:" | |
| 2709 << line; | |
| 2710 return false; | |
| 2711 } | |
| 2712 media_desc->set_media_connection_addr( | |
| 2713 rtc::Optional<rtc::SocketAddress>(addr)); | |
| 2714 continue; | |
| 2715 } | |
| 2716 | |
| 2671 if (!IsLineType(line, kLineTypeAttributes)) { | 2717 if (!IsLineType(line, kLineTypeAttributes)) { |
| 2672 // TODO: Handle other lines if needed. | 2718 // TODO: Handle other lines if needed. |
| 2673 LOG(LS_INFO) << "Ignored line: " << line; | 2719 LOG(LS_INFO) << "Ignored line: " << line; |
| 2674 continue; | 2720 continue; |
| 2675 } | 2721 } |
| 2676 | 2722 |
| 2677 // Handle attributes common to SCTP and RTP. | 2723 // Handle attributes common to SCTP and RTP. |
| 2678 if (HasAttribute(line, kAttributeMid)) { | 2724 if (HasAttribute(line, kAttributeMid)) { |
| 2679 // RFC 3388 | 2725 // RFC 3388 |
| 2680 // mid-attribute = "a=mid:" identification-tag | 2726 // mid-attribute = "a=mid:" identification-tag |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3234 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( | 3280 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( |
| 3235 media_desc, payload_type, feedback_param); | 3281 media_desc, payload_type, feedback_param); |
| 3236 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 3282 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
| 3237 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( | 3283 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( |
| 3238 media_desc, payload_type, feedback_param); | 3284 media_desc, payload_type, feedback_param); |
| 3239 } | 3285 } |
| 3240 return true; | 3286 return true; |
| 3241 } | 3287 } |
| 3242 | 3288 |
| 3243 } // namespace webrtc | 3289 } // namespace webrtc |
| OLD | NEW |