| 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 683 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 852 GetCandidatesByMindex(jdesc, ++mline_index, &candidates); | 851 GetCandidatesByMindex(jdesc, ++mline_index, &candidates); |
| 853 BuildMediaDescription(&*it, desc->GetTransportInfoByName(it->name), | 852 BuildMediaDescription(&*it, desc->GetTransportInfoByName(it->name), |
| 854 mdesc->type(), candidates, unified_plan_sdp, | 853 mdesc->type(), candidates, unified_plan_sdp, |
| 855 &message); | 854 &message); |
| 856 } | 855 } |
| 857 return message; | 856 return message; |
| 858 } | 857 } |
| 859 | 858 |
| 860 // Serializes the passed in IceCandidateInterface to a SDP string. | 859 // Serializes the passed in IceCandidateInterface to a SDP string. |
| 861 // candidate - The candidate to be serialized. | 860 // candidate - The candidate to be serialized. |
| 862 std::string SdpSerializeCandidate( | 861 std::string SdpSerializeCandidate(const IceCandidateInterface& candidate) { |
| 863 const IceCandidateInterface& candidate) { | 862 return SdpSerializeCandidate(candidate.candidate()); |
| 863 } |
| 864 |
| 865 // Serializes a cricket Candidate. |
| 866 std::string SdpSerializeCandidate(const cricket::Candidate& candidate) { |
| 864 std::string message; | 867 std::string message; |
| 865 std::vector<cricket::Candidate> candidates; | 868 std::vector<cricket::Candidate> candidates(1, candidate); |
| 866 candidates.push_back(candidate.candidate()); | |
| 867 BuildCandidate(candidates, true, &message); | 869 BuildCandidate(candidates, true, &message); |
| 868 // From WebRTC draft section 4.8.1.1 candidate-attribute will be | 870 // From WebRTC draft section 4.8.1.1 candidate-attribute will be |
| 869 // just candidate:<candidate> not a=candidate:<blah>CRLF | 871 // just candidate:<candidate> not a=candidate:<blah>CRLF |
| 870 ASSERT(message.find("a=") == 0); | 872 ASSERT(message.find("a=") == 0); |
| 871 message.erase(0, 2); | 873 message.erase(0, 2); |
| 872 ASSERT(message.find(kLineBreak) == message.size() - 2); | 874 ASSERT(message.find(kLineBreak) == message.size() - 2); |
| 873 message.resize(message.size() - 2); | 875 message.resize(message.size() - 2); |
| 874 return message; | 876 return message; |
| 875 } | 877 } |
| 876 | 878 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 SdpParseError* error) { | 921 SdpParseError* error) { |
| 920 ASSERT(jcandidate != NULL); | 922 ASSERT(jcandidate != NULL); |
| 921 Candidate candidate; | 923 Candidate candidate; |
| 922 if (!ParseCandidate(message, &candidate, error, true)) { | 924 if (!ParseCandidate(message, &candidate, error, true)) { |
| 923 return false; | 925 return false; |
| 924 } | 926 } |
| 925 jcandidate->SetCandidate(candidate); | 927 jcandidate->SetCandidate(candidate); |
| 926 return true; | 928 return true; |
| 927 } | 929 } |
| 928 | 930 |
| 931 bool SdpDeserializeCandidate(const std::string& transport_name, |
| 932 const std::string& message, |
| 933 cricket::Candidate* candidate, |
| 934 SdpParseError* error) { |
| 935 ASSERT(candidate != nullptr); |
| 936 if (!ParseCandidate(message, candidate, error, true)) { |
| 937 return false; |
| 938 } |
| 939 candidate->set_transport_name(transport_name); |
| 940 return true; |
| 941 } |
| 942 |
| 929 bool ParseCandidate(const std::string& message, Candidate* candidate, | 943 bool ParseCandidate(const std::string& message, Candidate* candidate, |
| 930 SdpParseError* error, bool is_raw) { | 944 SdpParseError* error, bool is_raw) { |
| 931 ASSERT(candidate != NULL); | 945 ASSERT(candidate != NULL); |
| 932 | 946 |
| 933 // Get the first line from |message|. | 947 // Get the first line from |message|. |
| 934 std::string first_line = message; | 948 std::string first_line = message; |
| 935 size_t pos = 0; | 949 size_t pos = 0; |
| 936 GetLine(message, &pos, &first_line); | 950 GetLine(message, &pos, &first_line); |
| 937 | 951 |
| 938 // Makes sure |message| contains only one line. | 952 // Makes sure |message| contains only one line. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 } | 1021 } |
| 1008 | 1022 |
| 1009 std::string candidate_type; | 1023 std::string candidate_type; |
| 1010 const std::string& type = fields[7]; | 1024 const std::string& type = fields[7]; |
| 1011 if (type == kCandidateHost) { | 1025 if (type == kCandidateHost) { |
| 1012 candidate_type = cricket::LOCAL_PORT_TYPE; | 1026 candidate_type = cricket::LOCAL_PORT_TYPE; |
| 1013 } else if (type == kCandidateSrflx) { | 1027 } else if (type == kCandidateSrflx) { |
| 1014 candidate_type = cricket::STUN_PORT_TYPE; | 1028 candidate_type = cricket::STUN_PORT_TYPE; |
| 1015 } else if (type == kCandidateRelay) { | 1029 } else if (type == kCandidateRelay) { |
| 1016 candidate_type = cricket::RELAY_PORT_TYPE; | 1030 candidate_type = cricket::RELAY_PORT_TYPE; |
| 1031 } else if (type == kCandidatePrflx) { |
| 1032 candidate_type = cricket::PRFLX_PORT_TYPE; |
| 1017 } else { | 1033 } else { |
| 1018 return ParseFailed(first_line, "Unsupported candidate type.", error); | 1034 return ParseFailed(first_line, "Unsupported candidate type.", error); |
| 1019 } | 1035 } |
| 1020 | 1036 |
| 1021 size_t current_position = expected_min_fields; | 1037 size_t current_position = expected_min_fields; |
| 1022 SocketAddress related_address; | 1038 SocketAddress related_address; |
| 1023 // The 2 optional fields for related address | 1039 // The 2 optional fields for related address |
| 1024 // [raddr <connection-address>] [rport <port>] | 1040 // [raddr <connection-address>] [rport <port>] |
| 1025 if (fields.size() >= (current_position + 2) && | 1041 if (fields.size() >= (current_position + 2) && |
| 1026 fields[current_position] == kAttributeCandidateRaddr) { | 1042 fields[current_position] == kAttributeCandidateRaddr) { |
| (...skipping 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1742 // [raddr <connection-address>] [rport <port>] | 1758 // [raddr <connection-address>] [rport <port>] |
| 1743 // *(SP extension-att-name SP extension-att-value) | 1759 // *(SP extension-att-name SP extension-att-value) |
| 1744 std::string type; | 1760 std::string type; |
| 1745 // Map the cricket candidate type to "host" / "srflx" / "prflx" / "relay" | 1761 // Map the cricket candidate type to "host" / "srflx" / "prflx" / "relay" |
| 1746 if (it->type() == cricket::LOCAL_PORT_TYPE) { | 1762 if (it->type() == cricket::LOCAL_PORT_TYPE) { |
| 1747 type = kCandidateHost; | 1763 type = kCandidateHost; |
| 1748 } else if (it->type() == cricket::STUN_PORT_TYPE) { | 1764 } else if (it->type() == cricket::STUN_PORT_TYPE) { |
| 1749 type = kCandidateSrflx; | 1765 type = kCandidateSrflx; |
| 1750 } else if (it->type() == cricket::RELAY_PORT_TYPE) { | 1766 } else if (it->type() == cricket::RELAY_PORT_TYPE) { |
| 1751 type = kCandidateRelay; | 1767 type = kCandidateRelay; |
| 1768 } else if (it->type() == cricket::PRFLX_PORT_TYPE) { |
| 1769 type = kCandidatePrflx; |
| 1770 // Peer reflexive candidate may be signaled for being removed. |
| 1752 } else { | 1771 } else { |
| 1753 ASSERT(false); | 1772 ASSERT(false); |
| 1754 // Never write out candidates if we don't know the type. | 1773 // Never write out candidates if we don't know the type. |
| 1755 continue; | 1774 continue; |
| 1756 } | 1775 } |
| 1757 | 1776 |
| 1758 InitAttrLine(kAttributeCandidate, &os); | 1777 InitAttrLine(kAttributeCandidate, &os); |
| 1759 os << kSdpDelimiterColon | 1778 os << kSdpDelimiterColon |
| 1760 << it->foundation() << " " | 1779 << it->foundation() << " " |
| 1761 << it->component() << " " | 1780 << it->component() << " " |
| (...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3124 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( | 3143 UpdateCodec<AudioContentDescription, cricket::AudioCodec>( |
| 3125 media_desc, payload_type, feedback_param); | 3144 media_desc, payload_type, feedback_param); |
| 3126 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { | 3145 } else if (media_type == cricket::MEDIA_TYPE_VIDEO) { |
| 3127 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( | 3146 UpdateCodec<VideoContentDescription, cricket::VideoCodec>( |
| 3128 media_desc, payload_type, feedback_param); | 3147 media_desc, payload_type, feedback_param); |
| 3129 } | 3148 } |
| 3130 return true; | 3149 return true; |
| 3131 } | 3150 } |
| 3132 | 3151 |
| 3133 } // namespace webrtc | 3152 } // namespace webrtc |
| OLD | NEW |