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