| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 // a=sctp-port | 147 // a=sctp-port |
| 148 static const char kAttributeSctpPort[] = "sctp-port"; | 148 static const char kAttributeSctpPort[] = "sctp-port"; |
| 149 | 149 |
| 150 // Experimental flags | 150 // Experimental flags |
| 151 static const char kAttributeXGoogleFlag[] = "x-google-flag"; | 151 static const char kAttributeXGoogleFlag[] = "x-google-flag"; |
| 152 static const char kValueConference[] = "conference"; | 152 static const char kValueConference[] = "conference"; |
| 153 | 153 |
| 154 // Candidate | 154 // Candidate |
| 155 static const char kCandidateHost[] = "host"; | 155 static const char kCandidateHost[] = "host"; |
| 156 static const char kCandidateSrflx[] = "srflx"; | 156 static const char kCandidateSrflx[] = "srflx"; |
| 157 // TODO: How to map the prflx with circket candidate type | 157 static const char kCandidatePrflx[] = "prflx"; |
| 158 // static const char kCandidatePrflx[] = "prflx"; | |
| 159 static const char kCandidateRelay[] = "relay"; | 158 static const char kCandidateRelay[] = "relay"; |
| 160 static const char kTcpCandidateType[] = "tcptype"; | 159 static const char kTcpCandidateType[] = "tcptype"; |
| 161 | 160 |
| 162 static const char kSdpDelimiterEqual = '='; | 161 static const char kSdpDelimiterEqual = '='; |
| 163 static const char kSdpDelimiterSpace = ' '; | 162 static const char kSdpDelimiterSpace = ' '; |
| 164 static const char kSdpDelimiterColon = ':'; | 163 static const char kSdpDelimiterColon = ':'; |
| 165 static const char kSdpDelimiterSemicolon = ';'; | 164 static const char kSdpDelimiterSemicolon = ';'; |
| 166 static const char kSdpDelimiterSlash = '/'; | 165 static const char kSdpDelimiterSlash = '/'; |
| 167 static const char kNewLine = '\n'; | 166 static const char kNewLine = '\n'; |
| 168 static const char kReturn = '\r'; | 167 static const char kReturn = '\r'; |
| (...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 864 GetCandidatesByMindex(jdesc, ++mline_index, &candidates); | 863 GetCandidatesByMindex(jdesc, ++mline_index, &candidates); |
| 865 BuildMediaDescription(&*it, desc->GetTransportInfoByName(it->name), | 864 BuildMediaDescription(&*it, desc->GetTransportInfoByName(it->name), |
| 866 mdesc->type(), candidates, unified_plan_sdp, | 865 mdesc->type(), candidates, unified_plan_sdp, |
| 867 &message); | 866 &message); |
| 868 } | 867 } |
| 869 return message; | 868 return message; |
| 870 } | 869 } |
| 871 | 870 |
| 872 // Serializes the passed in IceCandidateInterface to a SDP string. | 871 // Serializes the passed in IceCandidateInterface to a SDP string. |
| 873 // candidate - The candidate to be serialized. | 872 // candidate - The candidate to be serialized. |
| 874 std::string SdpSerializeCandidate( | 873 std::string SdpSerializeCandidate(const IceCandidateInterface& candidate) { |
| 875 const IceCandidateInterface& candidate) { | 874 return SdpSerializeCandidate(candidate.candidate()); |
| 875 } |
| 876 |
| 877 // Serializes a cricket Candidate. |
| 878 std::string SdpSerializeCandidate(const cricket::Candidate& candidate) { |
| 876 std::string message; | 879 std::string message; |
| 877 std::vector<cricket::Candidate> candidates; | 880 std::vector<cricket::Candidate> candidates(1, candidate); |
| 878 candidates.push_back(candidate.candidate()); | |
| 879 BuildCandidate(candidates, true, &message); | 881 BuildCandidate(candidates, true, &message); |
| 880 // From WebRTC draft section 4.8.1.1 candidate-attribute will be | 882 // From WebRTC draft section 4.8.1.1 candidate-attribute will be |
| 881 // just candidate:<candidate> not a=candidate:<blah>CRLF | 883 // just candidate:<candidate> not a=candidate:<blah>CRLF |
| 882 ASSERT(message.find("a=") == 0); | 884 ASSERT(message.find("a=") == 0); |
| 883 message.erase(0, 2); | 885 message.erase(0, 2); |
| 884 ASSERT(message.find(kLineBreak) == message.size() - 2); | 886 ASSERT(message.find(kLineBreak) == message.size() - 2); |
| 885 message.resize(message.size() - 2); | 887 message.resize(message.size() - 2); |
| 886 return message; | 888 return message; |
| 887 } | 889 } |
| 888 | 890 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 931 SdpParseError* error) { | 933 SdpParseError* error) { |
| 932 ASSERT(jcandidate != NULL); | 934 ASSERT(jcandidate != NULL); |
| 933 Candidate candidate; | 935 Candidate candidate; |
| 934 if (!ParseCandidate(message, &candidate, error, true)) { | 936 if (!ParseCandidate(message, &candidate, error, true)) { |
| 935 return false; | 937 return false; |
| 936 } | 938 } |
| 937 jcandidate->SetCandidate(candidate); | 939 jcandidate->SetCandidate(candidate); |
| 938 return true; | 940 return true; |
| 939 } | 941 } |
| 940 | 942 |
| 943 bool SdpDeserializeCandidate(const std::string& transport_name, |
| 944 const std::string& message, |
| 945 cricket::Candidate* candidate, |
| 946 SdpParseError* error) { |
| 947 ASSERT(candidate != nullptr); |
| 948 if (!ParseCandidate(message, candidate, error, true)) { |
| 949 return false; |
| 950 } |
| 951 candidate->set_transport_name(transport_name); |
| 952 return true; |
| 953 } |
| 954 |
| 941 bool ParseCandidate(const std::string& message, Candidate* candidate, | 955 bool ParseCandidate(const std::string& message, Candidate* candidate, |
| 942 SdpParseError* error, bool is_raw) { | 956 SdpParseError* error, bool is_raw) { |
| 943 ASSERT(candidate != NULL); | 957 ASSERT(candidate != NULL); |
| 944 | 958 |
| 945 // Get the first line from |message|. | 959 // Get the first line from |message|. |
| 946 std::string first_line = message; | 960 std::string first_line = message; |
| 947 size_t pos = 0; | 961 size_t pos = 0; |
| 948 GetLine(message, &pos, &first_line); | 962 GetLine(message, &pos, &first_line); |
| 949 | 963 |
| 950 // Makes sure |message| contains only one line. | 964 // Makes sure |message| contains only one line. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 } | 1033 } |
| 1020 | 1034 |
| 1021 std::string candidate_type; | 1035 std::string candidate_type; |
| 1022 const std::string& type = fields[7]; | 1036 const std::string& type = fields[7]; |
| 1023 if (type == kCandidateHost) { | 1037 if (type == kCandidateHost) { |
| 1024 candidate_type = cricket::LOCAL_PORT_TYPE; | 1038 candidate_type = cricket::LOCAL_PORT_TYPE; |
| 1025 } else if (type == kCandidateSrflx) { | 1039 } else if (type == kCandidateSrflx) { |
| 1026 candidate_type = cricket::STUN_PORT_TYPE; | 1040 candidate_type = cricket::STUN_PORT_TYPE; |
| 1027 } else if (type == kCandidateRelay) { | 1041 } else if (type == kCandidateRelay) { |
| 1028 candidate_type = cricket::RELAY_PORT_TYPE; | 1042 candidate_type = cricket::RELAY_PORT_TYPE; |
| 1043 } else if (type == kCandidatePrflx) { |
| 1044 candidate_type = cricket::PRFLX_PORT_TYPE; |
| 1029 } else { | 1045 } else { |
| 1030 return ParseFailed(first_line, "Unsupported candidate type.", error); | 1046 return ParseFailed(first_line, "Unsupported candidate type.", error); |
| 1031 } | 1047 } |
| 1032 | 1048 |
| 1033 size_t current_position = expected_min_fields; | 1049 size_t current_position = expected_min_fields; |
| 1034 SocketAddress related_address; | 1050 SocketAddress related_address; |
| 1035 // The 2 optional fields for related address | 1051 // The 2 optional fields for related address |
| 1036 // [raddr <connection-address>] [rport <port>] | 1052 // [raddr <connection-address>] [rport <port>] |
| 1037 if (fields.size() >= (current_position + 2) && | 1053 if (fields.size() >= (current_position + 2) && |
| 1038 fields[current_position] == kAttributeCandidateRaddr) { | 1054 fields[current_position] == kAttributeCandidateRaddr) { |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 // [raddr <connection-address>] [rport <port>] | 1770 // [raddr <connection-address>] [rport <port>] |
| 1755 // *(SP extension-att-name SP extension-att-value) | 1771 // *(SP extension-att-name SP extension-att-value) |
| 1756 std::string type; | 1772 std::string type; |
| 1757 // Map the cricket candidate type to "host" / "srflx" / "prflx" / "relay" | 1773 // Map the cricket candidate type to "host" / "srflx" / "prflx" / "relay" |
| 1758 if (it->type() == cricket::LOCAL_PORT_TYPE) { | 1774 if (it->type() == cricket::LOCAL_PORT_TYPE) { |
| 1759 type = kCandidateHost; | 1775 type = kCandidateHost; |
| 1760 } else if (it->type() == cricket::STUN_PORT_TYPE) { | 1776 } else if (it->type() == cricket::STUN_PORT_TYPE) { |
| 1761 type = kCandidateSrflx; | 1777 type = kCandidateSrflx; |
| 1762 } else if (it->type() == cricket::RELAY_PORT_TYPE) { | 1778 } else if (it->type() == cricket::RELAY_PORT_TYPE) { |
| 1763 type = kCandidateRelay; | 1779 type = kCandidateRelay; |
| 1780 } else if (it->type() == cricket::PRFLX_PORT_TYPE) { |
| 1781 type = kCandidatePrflx; |
| 1782 // Peer reflexive candidate may be signaled for being removed. |
| 1764 } else { | 1783 } else { |
| 1765 ASSERT(false); | 1784 ASSERT(false); |
| 1766 // Never write out candidates if we don't know the type. | 1785 // Never write out candidates if we don't know the type. |
| 1767 continue; | 1786 continue; |
| 1768 } | 1787 } |
| 1769 | 1788 |
| 1770 InitAttrLine(kAttributeCandidate, &os); | 1789 InitAttrLine(kAttributeCandidate, &os); |
| 1771 os << kSdpDelimiterColon | 1790 os << kSdpDelimiterColon |
| 1772 << it->foundation() << " " | 1791 << it->foundation() << " " |
| 1773 << it->component() << " " | 1792 << it->component() << " " |
| (...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3128 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( | 3147 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( |
| 3129 media_desc, payload_type, feedback_param); | 3148 media_desc, payload_type, feedback_param); |
| 3130 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 3149 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
| 3131 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( | 3150 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( |
| 3132 media_desc, payload_type, feedback_param); | 3151 media_desc, payload_type, feedback_param); |
| 3133 } | 3152 } |
| 3134 return true; | 3153 return true; |
| 3135 } | 3154 } |
| 3136 | 3155 |
| 3137 } // namespace webrtc | 3156 } // namespace webrtc |
| OLD | NEW |