Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * libjingle | 2 * libjingle |
| 3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
| 9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 static const char kSsrcAttributeMsid[] = "msid"; | 133 static const char kSsrcAttributeMsid[] = "msid"; |
| 134 static const char kDefaultMsid[] = "default"; | 134 static const char kDefaultMsid[] = "default"; |
| 135 static const char kSsrcAttributeMslabel[] = "mslabel"; | 135 static const char kSsrcAttributeMslabel[] = "mslabel"; |
| 136 static const char kSSrcAttributeLabel[] = "label"; | 136 static const char kSSrcAttributeLabel[] = "label"; |
| 137 static const char kAttributeSsrcGroup[] = "ssrc-group"; | 137 static const char kAttributeSsrcGroup[] = "ssrc-group"; |
| 138 static const char kAttributeCrypto[] = "crypto"; | 138 static const char kAttributeCrypto[] = "crypto"; |
| 139 static const char kAttributeCandidate[] = "candidate"; | 139 static const char kAttributeCandidate[] = "candidate"; |
| 140 static const char kAttributeCandidateTyp[] = "typ"; | 140 static const char kAttributeCandidateTyp[] = "typ"; |
| 141 static const char kAttributeCandidateRaddr[] = "raddr"; | 141 static const char kAttributeCandidateRaddr[] = "raddr"; |
| 142 static const char kAttributeCandidateRport[] = "rport"; | 142 static const char kAttributeCandidateRport[] = "rport"; |
| 143 static const char kAttributeCandidateUsername[] = "username"; | |
| 144 static const char kAttributeCandidatePassword[] = "password"; | |
| 145 static const char kAttributeCandidateGeneration[] = "generation"; | 143 static const char kAttributeCandidateGeneration[] = "generation"; |
| 146 static const char kAttributeFingerprint[] = "fingerprint"; | 144 static const char kAttributeFingerprint[] = "fingerprint"; |
| 147 static const char kAttributeSetup[] = "setup"; | 145 static const char kAttributeSetup[] = "setup"; |
| 148 static const char kAttributeFmtp[] = "fmtp"; | 146 static const char kAttributeFmtp[] = "fmtp"; |
| 149 static const char kAttributeRtpmap[] = "rtpmap"; | 147 static const char kAttributeRtpmap[] = "rtpmap"; |
| 150 static const char kAttributeSctpmap[] = "sctpmap"; | 148 static const char kAttributeSctpmap[] = "sctpmap"; |
| 151 static const char kAttributeRtcp[] = "rtcp"; | 149 static const char kAttributeRtcp[] = "rtcp"; |
| 152 static const char kAttributeIceUfrag[] = "ice-ufrag"; | 150 static const char kAttributeIceUfrag[] = "ice-ufrag"; |
| 153 static const char kAttributeIcePwd[] = "ice-pwd"; | 151 static const char kAttributeIcePwd[] = "ice-pwd"; |
| 154 static const char kAttributeIceLite[] = "ice-lite"; | 152 static const char kAttributeIceLite[] = "ice-lite"; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 std::string* message); | 253 std::string* message); |
| 256 static void BuildSctpContentAttributes(std::string* message, int sctp_port); | 254 static void BuildSctpContentAttributes(std::string* message, int sctp_port); |
| 257 static void BuildRtpContentAttributes( | 255 static void BuildRtpContentAttributes( |
| 258 const MediaContentDescription* media_desc, | 256 const MediaContentDescription* media_desc, |
| 259 const MediaType media_type, | 257 const MediaType media_type, |
| 260 std::string* message); | 258 std::string* message); |
| 261 static void BuildRtpMap(const MediaContentDescription* media_desc, | 259 static void BuildRtpMap(const MediaContentDescription* media_desc, |
| 262 const MediaType media_type, | 260 const MediaType media_type, |
| 263 std::string* message); | 261 std::string* message); |
| 264 static void BuildCandidate(const std::vector<Candidate>& candidates, | 262 static void BuildCandidate(const std::vector<Candidate>& candidates, |
| 263 bool include_ufrag, | |
| 265 std::string* message); | 264 std::string* message); |
| 266 static void BuildIceOptions(const std::vector<std::string>& transport_options, | 265 static void BuildIceOptions(const std::vector<std::string>& transport_options, |
| 267 std::string* message); | 266 std::string* message); |
| 268 static bool IsRtp(const std::string& protocol); | 267 static bool IsRtp(const std::string& protocol); |
| 269 static bool IsDtlsSctp(const std::string& protocol); | 268 static bool IsDtlsSctp(const std::string& protocol); |
| 270 static bool ParseSessionDescription(const std::string& message, size_t* pos, | 269 static bool ParseSessionDescription(const std::string& message, size_t* pos, |
| 271 std::string* session_id, | 270 std::string* session_id, |
| 272 std::string* session_version, | 271 std::string* session_version, |
| 273 TransportDescription* session_td, | 272 TransportDescription* session_td, |
| 274 RtpHeaderExtensions* session_extmaps, | 273 RtpHeaderExtensions* session_extmaps, |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 871 return message; | 870 return message; |
| 872 } | 871 } |
| 873 | 872 |
| 874 // Serializes the passed in IceCandidateInterface to a SDP string. | 873 // Serializes the passed in IceCandidateInterface to a SDP string. |
| 875 // candidate - The candidate to be serialized. | 874 // candidate - The candidate to be serialized. |
| 876 std::string SdpSerializeCandidate( | 875 std::string SdpSerializeCandidate( |
| 877 const IceCandidateInterface& candidate) { | 876 const IceCandidateInterface& candidate) { |
| 878 std::string message; | 877 std::string message; |
| 879 std::vector<cricket::Candidate> candidates; | 878 std::vector<cricket::Candidate> candidates; |
| 880 candidates.push_back(candidate.candidate()); | 879 candidates.push_back(candidate.candidate()); |
| 881 BuildCandidate(candidates, &message); | 880 BuildCandidate(candidates, true, &message); |
| 882 // From WebRTC draft section 4.8.1.1 candidate-attribute will be | 881 // From WebRTC draft section 4.8.1.1 candidate-attribute will be |
| 883 // just candidate:<candidate> not a=candidate:<blah>CRLF | 882 // just candidate:<candidate> not a=candidate:<blah>CRLF |
| 884 ASSERT(message.find("a=") == 0); | 883 ASSERT(message.find("a=") == 0); |
| 885 message.erase(0, 2); | 884 message.erase(0, 2); |
| 886 ASSERT(message.find(kLineBreak) == message.size() - 2); | 885 ASSERT(message.find(kLineBreak) == message.size() - 2); |
| 887 message.resize(message.size() - 2); | 886 message.resize(message.size() - 2); |
| 888 return message; | 887 return message; |
| 889 } | 888 } |
| 890 | 889 |
| 891 bool SdpDeserialize(const std::string& message, | 890 bool SdpDeserialize(const std::string& message, |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1065 tcptype != cricket::TCPTYPE_SIMOPEN_STR) { | 1064 tcptype != cricket::TCPTYPE_SIMOPEN_STR) { |
| 1066 return ParseFailed(first_line, "Invalid TCP candidate type.", error); | 1065 return ParseFailed(first_line, "Invalid TCP candidate type.", error); |
| 1067 } | 1066 } |
| 1068 | 1067 |
| 1069 if (protocol != cricket::PROTO_TCP) { | 1068 if (protocol != cricket::PROTO_TCP) { |
| 1070 return ParseFailed(first_line, "Invalid non-TCP candidate", error); | 1069 return ParseFailed(first_line, "Invalid non-TCP candidate", error); |
| 1071 } | 1070 } |
| 1072 } | 1071 } |
| 1073 | 1072 |
| 1074 // Extension | 1073 // Extension |
| 1075 // Empty string as the candidate username and password. | 1074 // ice-ufrag is stored as username and ice-pwd is stored as password in |
| 1076 // Will be updated later with the ice-ufrag and ice-pwd. | 1075 // the candidate. |
|
pthatcher1
2015/12/10 22:08:06
I think this comment would be more valuable as "Th
honghaiz3
2015/12/11 04:47:29
Done.
| |
| 1077 // TODO: Remove the username/password extension, which is currently | |
| 1078 // kept for backwards compatibility. | |
| 1079 std::string username; | 1076 std::string username; |
| 1080 std::string password; | 1077 std::string password; |
| 1081 uint32_t generation = 0; | 1078 uint32_t generation = 0; |
| 1082 for (size_t i = current_position; i + 1 < fields.size(); ++i) { | 1079 for (size_t i = current_position; i + 1 < fields.size(); ++i) { |
| 1083 // RFC 5245 | 1080 // RFC 5245 |
| 1084 // *(SP extension-att-name SP extension-att-value) | 1081 // *(SP extension-att-name SP extension-att-value) |
| 1085 if (fields[i] == kAttributeCandidateGeneration) { | 1082 if (fields[i] == kAttributeCandidateGeneration) { |
| 1086 if (!GetValueFromString(first_line, fields[++i], &generation, error)) { | 1083 if (!GetValueFromString(first_line, fields[++i], &generation, error)) { |
| 1087 return false; | 1084 return false; |
| 1088 } | 1085 } |
| 1089 } else if (fields[i] == kAttributeCandidateUsername) { | 1086 } else if (fields[i] == kAttributeIceUfrag) { |
| 1090 username = fields[++i]; | 1087 username = fields[++i]; |
| 1091 } else if (fields[i] == kAttributeCandidatePassword) { | 1088 } else if (fields[i] == kAttributeIcePwd) { |
| 1092 password = fields[++i]; | 1089 password = fields[++i]; |
| 1093 } else { | 1090 } else { |
| 1094 // Skip the unknown extension. | 1091 // Skip the unknown extension. |
| 1095 ++i; | 1092 ++i; |
| 1096 } | 1093 } |
| 1097 } | 1094 } |
| 1098 | 1095 |
| 1099 *candidate = Candidate(component_id, cricket::ProtoToString(protocol), | 1096 *candidate = Candidate(component_id, cricket::ProtoToString(protocol), |
| 1100 address, priority, username, password, candidate_type, | 1097 address, priority, username, password, candidate_type, |
| 1101 generation, foundation); | 1098 generation, foundation); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1279 | 1276 |
| 1280 // Add the a=rtcp line. | 1277 // Add the a=rtcp line. |
| 1281 if (IsRtp(media_desc->protocol())) { | 1278 if (IsRtp(media_desc->protocol())) { |
| 1282 std::string rtcp_line = GetRtcpLine(candidates); | 1279 std::string rtcp_line = GetRtcpLine(candidates); |
| 1283 if (!rtcp_line.empty()) { | 1280 if (!rtcp_line.empty()) { |
| 1284 AddLine(rtcp_line, message); | 1281 AddLine(rtcp_line, message); |
| 1285 } | 1282 } |
| 1286 } | 1283 } |
| 1287 | 1284 |
| 1288 // Build the a=candidate lines. | 1285 // Build the a=candidate lines. |
| 1289 BuildCandidate(candidates, message); | 1286 BuildCandidate(candidates, false, message); |
|
pthatcher1
2015/12/10 22:08:06
Can you leave a comment like "We don't include the
honghaiz3
2015/12/11 04:47:29
Done.
| |
| 1290 | 1287 |
| 1291 // Use the transport_info to build the media level ice-ufrag and ice-pwd. | 1288 // Use the transport_info to build the media level ice-ufrag and ice-pwd. |
| 1292 if (transport_info) { | 1289 if (transport_info) { |
| 1293 // RFC 5245 | 1290 // RFC 5245 |
| 1294 // ice-pwd-att = "ice-pwd" ":" password | 1291 // ice-pwd-att = "ice-pwd" ":" password |
| 1295 // ice-ufrag-att = "ice-ufrag" ":" ufrag | 1292 // ice-ufrag-att = "ice-ufrag" ":" ufrag |
| 1296 // ice-ufrag | 1293 // ice-ufrag |
| 1297 InitAttrLine(kAttributeIceUfrag, &os); | 1294 InitAttrLine(kAttributeIceUfrag, &os); |
| 1298 os << kSdpDelimiterColon << transport_info->description.ice_ufrag; | 1295 os << kSdpDelimiterColon << transport_info->description.ice_ufrag; |
| 1299 AddLine(os.str(), message); | 1296 AddLine(os.str(), message); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1710 // [/<encodingparameters>] | 1707 // [/<encodingparameters>] |
| 1711 InitAttrLine(kAttributeRtpmap, &os); | 1708 InitAttrLine(kAttributeRtpmap, &os); |
| 1712 os << kSdpDelimiterColon << it->id << " " | 1709 os << kSdpDelimiterColon << it->id << " " |
| 1713 << it->name << "/" << it->clockrate; | 1710 << it->name << "/" << it->clockrate; |
| 1714 AddLine(os.str(), message); | 1711 AddLine(os.str(), message); |
| 1715 } | 1712 } |
| 1716 } | 1713 } |
| 1717 } | 1714 } |
| 1718 | 1715 |
| 1719 void BuildCandidate(const std::vector<Candidate>& candidates, | 1716 void BuildCandidate(const std::vector<Candidate>& candidates, |
| 1717 bool include_ufrag, | |
| 1720 std::string* message) { | 1718 std::string* message) { |
| 1721 std::ostringstream os; | 1719 std::ostringstream os; |
| 1722 | 1720 |
| 1723 for (std::vector<Candidate>::const_iterator it = candidates.begin(); | 1721 for (std::vector<Candidate>::const_iterator it = candidates.begin(); |
| 1724 it != candidates.end(); ++it) { | 1722 it != candidates.end(); ++it) { |
| 1725 // RFC 5245 | 1723 // RFC 5245 |
| 1726 // a=candidate:<foundation> <component-id> <transport> <priority> | 1724 // a=candidate:<foundation> <component-id> <transport> <priority> |
| 1727 // <connection-address> <port> typ <candidate-types> | 1725 // <connection-address> <port> typ <candidate-types> |
| 1728 // [raddr <connection-address>] [rport <port>] | 1726 // [raddr <connection-address>] [rport <port>] |
| 1729 // *(SP extension-att-name SP extension-att-value) | 1727 // *(SP extension-att-name SP extension-att-value) |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1759 << kAttributeCandidateRport << " " | 1757 << kAttributeCandidateRport << " " |
| 1760 << it->related_address().PortAsString() << " "; | 1758 << it->related_address().PortAsString() << " "; |
| 1761 } | 1759 } |
| 1762 | 1760 |
| 1763 if (it->protocol() == cricket::TCP_PROTOCOL_NAME) { | 1761 if (it->protocol() == cricket::TCP_PROTOCOL_NAME) { |
| 1764 os << kTcpCandidateType << " " << it->tcptype() << " "; | 1762 os << kTcpCandidateType << " " << it->tcptype() << " "; |
| 1765 } | 1763 } |
| 1766 | 1764 |
| 1767 // Extensions | 1765 // Extensions |
| 1768 os << kAttributeCandidateGeneration << " " << it->generation(); | 1766 os << kAttributeCandidateGeneration << " " << it->generation(); |
| 1767 if (include_ufrag && !it->username().empty()) { | |
| 1768 os << " " << kAttributeIceUfrag << " " << it->username(); | |
| 1769 } | |
| 1769 | 1770 |
| 1770 AddLine(os.str(), message); | 1771 AddLine(os.str(), message); |
| 1771 } | 1772 } |
| 1772 } | 1773 } |
| 1773 | 1774 |
| 1774 void BuildIceOptions(const std::vector<std::string>& transport_options, | 1775 void BuildIceOptions(const std::vector<std::string>& transport_options, |
| 1775 std::string* message) { | 1776 std::string* message) { |
| 1776 if (!transport_options.empty()) { | 1777 if (!transport_options.empty()) { |
| 1777 std::ostringstream os; | 1778 std::ostringstream os; |
| 1778 InitAttrLine(kAttributeIceOption, &os); | 1779 InitAttrLine(kAttributeIceOption, &os); |
| (...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2670 // only rtcp-fb. | 2671 // only rtcp-fb. |
| 2671 if (!VerifyVideoCodecs(video_desc)) { | 2672 if (!VerifyVideoCodecs(video_desc)) { |
| 2672 return ParseFailed("Failed to parse video codecs correctly.", error); | 2673 return ParseFailed("Failed to parse video codecs correctly.", error); |
| 2673 } | 2674 } |
| 2674 } | 2675 } |
| 2675 | 2676 |
| 2676 // RFC 5245 | 2677 // RFC 5245 |
| 2677 // Update the candidates with the media level "ice-pwd" and "ice-ufrag". | 2678 // Update the candidates with the media level "ice-pwd" and "ice-ufrag". |
| 2678 for (Candidates::iterator it = candidates_orig.begin(); | 2679 for (Candidates::iterator it = candidates_orig.begin(); |
| 2679 it != candidates_orig.end(); ++it) { | 2680 it != candidates_orig.end(); ++it) { |
| 2680 ASSERT((*it).username().empty()); | 2681 ASSERT((*it).username().empty() || |
| 2682 (*it).username() == transport->ice_ufrag); | |
| 2681 (*it).set_username(transport->ice_ufrag); | 2683 (*it).set_username(transport->ice_ufrag); |
| 2682 ASSERT((*it).password().empty()); | 2684 ASSERT((*it).password().empty()); |
| 2683 (*it).set_password(transport->ice_pwd); | 2685 (*it).set_password(transport->ice_pwd); |
| 2684 candidates->push_back( | 2686 candidates->push_back( |
| 2685 new JsepIceCandidate(mline_id, mline_index, *it)); | 2687 new JsepIceCandidate(mline_id, mline_index, *it)); |
| 2686 } | 2688 } |
| 2687 return true; | 2689 return true; |
| 2688 } | 2690 } |
| 2689 | 2691 |
| 2690 bool ParseSsrcAttribute(const std::string& line, SsrcInfoVec* ssrc_infos, | 2692 bool ParseSsrcAttribute(const std::string& line, SsrcInfoVec* ssrc_infos, |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3067 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( | 3069 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( |
| 3068 media_desc, payload_type, feedback_param); | 3070 media_desc, payload_type, feedback_param); |
| 3069 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 3071 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
| 3070 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( | 3072 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( |
| 3071 media_desc, payload_type, feedback_param); | 3073 media_desc, payload_type, feedback_param); |
| 3072 } | 3074 } |
| 3073 return true; | 3075 return true; |
| 3074 } | 3076 } |
| 3075 | 3077 |
| 3076 } // namespace webrtc | 3078 } // namespace webrtc |
| OLD | NEW |