| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 using webrtc::SessionDescriptionInterface; | 73 using webrtc::SessionDescriptionInterface; |
| 74 | 74 |
| 75 typedef std::vector<AudioCodec> AudioCodecs; | 75 typedef std::vector<AudioCodec> AudioCodecs; |
| 76 typedef std::vector<Candidate> Candidates; | 76 typedef std::vector<Candidate> Candidates; |
| 77 | 77 |
| 78 static const uint32_t kDefaultSctpPort = 5000; | 78 static const uint32_t kDefaultSctpPort = 5000; |
| 79 static const char kSessionTime[] = "t=0 0\r\n"; | 79 static const char kSessionTime[] = "t=0 0\r\n"; |
| 80 static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 | 80 static const uint32_t kCandidatePriority = 2130706432U; // pref = 1.0 |
| 81 static const char kCandidateUfragVoice[] = "ufrag_voice"; | 81 static const char kCandidateUfragVoice[] = "ufrag_voice"; |
| 82 static const char kCandidatePwdVoice[] = "pwd_voice"; | 82 static const char kCandidatePwdVoice[] = "pwd_voice"; |
| 83 static const char kAttributeIceUfragVoice[] = "a=ice-ufrag:ufrag_voice\r\n"; |
| 83 static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; | 84 static const char kAttributeIcePwdVoice[] = "a=ice-pwd:pwd_voice\r\n"; |
| 84 static const char kCandidateUfragVideo[] = "ufrag_video"; | 85 static const char kCandidateUfragVideo[] = "ufrag_video"; |
| 85 static const char kCandidatePwdVideo[] = "pwd_video"; | 86 static const char kCandidatePwdVideo[] = "pwd_video"; |
| 86 static const char kCandidateUfragData[] = "ufrag_data"; | 87 static const char kCandidateUfragData[] = "ufrag_data"; |
| 87 static const char kCandidatePwdData[] = "pwd_data"; | 88 static const char kCandidatePwdData[] = "pwd_data"; |
| 89 static const char kAttributeIceUfragVideo[] = "a=ice-ufrag:ufrag_video\r\n"; |
| 88 static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; | 90 static const char kAttributeIcePwdVideo[] = "a=ice-pwd:pwd_video\r\n"; |
| 89 static const uint32_t kCandidateGeneration = 2; | 91 static const uint32_t kCandidateGeneration = 2; |
| 90 static const char kCandidateFoundation1[] = "a0+B/1"; | 92 static const char kCandidateFoundation1[] = "a0+B/1"; |
| 91 static const char kCandidateFoundation2[] = "a0+B/2"; | 93 static const char kCandidateFoundation2[] = "a0+B/2"; |
| 92 static const char kCandidateFoundation3[] = "a0+B/3"; | 94 static const char kCandidateFoundation3[] = "a0+B/3"; |
| 93 static const char kCandidateFoundation4[] = "a0+B/4"; | 95 static const char kCandidateFoundation4[] = "a0+B/4"; |
| 94 static const char kAttributeCryptoVoice[] = | 96 static const char kAttributeCryptoVoice[] = |
| 95 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " | 97 "a=crypto:1 AES_CM_128_HMAC_SHA1_32 " |
| 96 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " | 98 "inline:NzB4d1BINUAvLEw6UzF3WSJ+PSdFcGdUJShpX1Zj|2^20|1:32 " |
| 97 "dummy_session_params\r\n"; | 99 "dummy_session_params\r\n"; |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 default: | 520 default: |
| 519 new_direction = "a=sendrecv"; | 521 new_direction = "a=sendrecv"; |
| 520 break; | 522 break; |
| 521 } | 523 } |
| 522 Replace("a=sendrecv", new_direction, message); | 524 Replace("a=sendrecv", new_direction, message); |
| 523 } | 525 } |
| 524 | 526 |
| 525 static void ReplaceRejected(bool audio_rejected, bool video_rejected, | 527 static void ReplaceRejected(bool audio_rejected, bool video_rejected, |
| 526 std::string* message) { | 528 std::string* message) { |
| 527 if (audio_rejected) { | 529 if (audio_rejected) { |
| 528 Replace("m=audio 2345", "m=audio 0", message); | 530 Replace("m=audio 9", "m=audio 0", message); |
| 531 Replace(kAttributeIceUfragVoice, "", message); |
| 532 Replace(kAttributeIcePwdVoice, "", message); |
| 529 } | 533 } |
| 530 if (video_rejected) { | 534 if (video_rejected) { |
| 531 Replace("m=video 3457", "m=video 0", message); | 535 Replace("m=video 9", "m=video 0", message); |
| 536 Replace(kAttributeIceUfragVideo, "", message); |
| 537 Replace(kAttributeIcePwdVideo, "", message); |
| 532 } | 538 } |
| 533 } | 539 } |
| 534 | 540 |
| 535 // WebRtcSdpTest | 541 // WebRtcSdpTest |
| 536 | 542 |
| 537 class WebRtcSdpTest : public testing::Test { | 543 class WebRtcSdpTest : public testing::Test { |
| 538 public: | 544 public: |
| 539 WebRtcSdpTest() | 545 WebRtcSdpTest() |
| 540 : jdesc_(kDummyString) { | 546 : jdesc_(kDummyString) { |
| 541 // AudioContentDescription | 547 // AudioContentDescription |
| (...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 void AddIceOptions(const std::string& content_name, | 984 void AddIceOptions(const std::string& content_name, |
| 979 const std::vector<std::string>& transport_options) { | 985 const std::vector<std::string>& transport_options) { |
| 980 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); | 986 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 981 cricket::TransportInfo transport_info = | 987 cricket::TransportInfo transport_info = |
| 982 *(desc_.GetTransportInfoByName(content_name)); | 988 *(desc_.GetTransportInfoByName(content_name)); |
| 983 desc_.RemoveTransportInfoByName(content_name); | 989 desc_.RemoveTransportInfoByName(content_name); |
| 984 transport_info.description.transport_options = transport_options; | 990 transport_info.description.transport_options = transport_options; |
| 985 desc_.AddTransportInfo(transport_info); | 991 desc_.AddTransportInfo(transport_info); |
| 986 } | 992 } |
| 987 | 993 |
| 994 void SetIceUfragPwd(const std::string& content_name, |
| 995 const std::string& ice_ufrag, |
| 996 const std::string& ice_pwd) { |
| 997 ASSERT_TRUE(desc_.GetTransportInfoByName(content_name) != NULL); |
| 998 cricket::TransportInfo transport_info = |
| 999 *(desc_.GetTransportInfoByName(content_name)); |
| 1000 desc_.RemoveTransportInfoByName(content_name); |
| 1001 transport_info.description.ice_ufrag = ice_ufrag; |
| 1002 transport_info.description.ice_pwd = ice_pwd; |
| 1003 desc_.AddTransportInfo(transport_info); |
| 1004 } |
| 1005 |
| 988 void AddFingerprint() { | 1006 void AddFingerprint() { |
| 989 desc_.RemoveTransportInfoByName(kAudioContentName); | 1007 desc_.RemoveTransportInfoByName(kAudioContentName); |
| 990 desc_.RemoveTransportInfoByName(kVideoContentName); | 1008 desc_.RemoveTransportInfoByName(kVideoContentName); |
| 991 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, | 1009 rtc::SSLFingerprint fingerprint(rtc::DIGEST_SHA_1, |
| 992 kIdentityDigest, | 1010 kIdentityDigest, |
| 993 sizeof(kIdentityDigest)); | 1011 sizeof(kIdentityDigest)); |
| 994 EXPECT_TRUE(desc_.AddTransportInfo( | 1012 EXPECT_TRUE(desc_.AddTransportInfo( |
| 995 TransportInfo(kAudioContentName, | 1013 TransportInfo(kAudioContentName, |
| 996 TransportDescription(std::vector<std::string>(), | 1014 TransportDescription(std::vector<std::string>(), |
| 997 kCandidateUfragVoice, | 1015 kCandidateUfragVoice, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 audio_desc_ = static_cast<AudioContentDescription*>( | 1067 audio_desc_ = static_cast<AudioContentDescription*>( |
| 1050 audio_desc_->Copy()); | 1068 audio_desc_->Copy()); |
| 1051 video_desc_ = static_cast<VideoContentDescription*>( | 1069 video_desc_ = static_cast<VideoContentDescription*>( |
| 1052 video_desc_->Copy()); | 1070 video_desc_->Copy()); |
| 1053 desc_.RemoveContentByName(kAudioContentName); | 1071 desc_.RemoveContentByName(kAudioContentName); |
| 1054 desc_.RemoveContentByName(kVideoContentName); | 1072 desc_.RemoveContentByName(kVideoContentName); |
| 1055 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, | 1073 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1056 audio_desc_); | 1074 audio_desc_); |
| 1057 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, | 1075 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1058 video_desc_); | 1076 video_desc_); |
| 1059 std::string new_sdp = kSdpFullString; | 1077 SetIceUfragPwd(kAudioContentName, |
| 1078 audio_rejected ? "" : kCandidateUfragVoice, |
| 1079 audio_rejected ? "" : kCandidatePwdVoice); |
| 1080 SetIceUfragPwd(kVideoContentName, |
| 1081 video_rejected ? "" : kCandidateUfragVideo, |
| 1082 video_rejected ? "" : kCandidatePwdVideo); |
| 1083 |
| 1084 std::string new_sdp = kSdpString; |
| 1060 ReplaceRejected(audio_rejected, video_rejected, &new_sdp); | 1085 ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1061 | 1086 |
| 1062 if (!jdesc_.Initialize(desc_.Copy(), | 1087 JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1063 jdesc_.session_id(), | 1088 if (!jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1064 jdesc_.session_version())) { | 1089 kSessionVersion)) { |
| 1065 return false; | 1090 return false; |
| 1066 } | 1091 } |
| 1067 std::string message = webrtc::SdpSerialize(jdesc_); | 1092 std::string message = webrtc::SdpSerialize(jdesc_no_candidates); |
| 1068 EXPECT_EQ(new_sdp, message); | 1093 EXPECT_EQ(new_sdp, message); |
| 1069 return true; | 1094 return true; |
| 1070 } | 1095 } |
| 1071 | 1096 |
| 1072 void AddSctpDataChannel() { | 1097 void AddSctpDataChannel() { |
| 1073 rtc::scoped_ptr<DataContentDescription> data( | 1098 rtc::scoped_ptr<DataContentDescription> data( |
| 1074 new DataContentDescription()); | 1099 new DataContentDescription()); |
| 1075 data_desc_ = data.get(); | 1100 data_desc_ = data.get(); |
| 1076 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); | 1101 data_desc_->set_protocol(cricket::kMediaProtocolDtlsSctp); |
| 1077 DataCodec codec(cricket::kGoogleSctpDataCodecId, | 1102 DataCodec codec(cricket::kGoogleSctpDataCodecId, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 if (!jdesc_.Initialize(desc_.Copy(), | 1145 if (!jdesc_.Initialize(desc_.Copy(), |
| 1121 jdesc_.session_id(), | 1146 jdesc_.session_id(), |
| 1122 jdesc_.session_version())) { | 1147 jdesc_.session_version())) { |
| 1123 return false; | 1148 return false; |
| 1124 } | 1149 } |
| 1125 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); | 1150 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); |
| 1126 return true; | 1151 return true; |
| 1127 } | 1152 } |
| 1128 | 1153 |
| 1129 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { | 1154 bool TestDeserializeRejected(bool audio_rejected, bool video_rejected) { |
| 1130 std::string new_sdp = kSdpFullString; | 1155 std::string new_sdp = kSdpString; |
| 1131 ReplaceRejected(audio_rejected, video_rejected, &new_sdp); | 1156 ReplaceRejected(audio_rejected, video_rejected, &new_sdp); |
| 1132 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer); | 1157 JsepSessionDescription new_jdesc(JsepSessionDescription::kOffer); |
| 1158 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); |
| 1133 | 1159 |
| 1134 EXPECT_TRUE(SdpDeserialize(new_sdp, &new_jdesc)); | |
| 1135 audio_desc_ = static_cast<AudioContentDescription*>( | 1160 audio_desc_ = static_cast<AudioContentDescription*>( |
| 1136 audio_desc_->Copy()); | 1161 audio_desc_->Copy()); |
| 1137 video_desc_ = static_cast<VideoContentDescription*>( | 1162 video_desc_ = static_cast<VideoContentDescription*>( |
| 1138 video_desc_->Copy()); | 1163 video_desc_->Copy()); |
| 1139 desc_.RemoveContentByName(kAudioContentName); | 1164 desc_.RemoveContentByName(kAudioContentName); |
| 1140 desc_.RemoveContentByName(kVideoContentName); | 1165 desc_.RemoveContentByName(kVideoContentName); |
| 1141 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, | 1166 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_rejected, |
| 1142 audio_desc_); | 1167 audio_desc_); |
| 1143 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, | 1168 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_rejected, |
| 1144 video_desc_); | 1169 video_desc_); |
| 1145 if (!jdesc_.Initialize(desc_.Copy(), | 1170 SetIceUfragPwd(kAudioContentName, |
| 1146 jdesc_.session_id(), | 1171 audio_rejected ? "" : kCandidateUfragVoice, |
| 1147 jdesc_.session_version())) { | 1172 audio_rejected ? "" : kCandidatePwdVoice); |
| 1173 SetIceUfragPwd(kVideoContentName, |
| 1174 video_rejected ? "" : kCandidateUfragVideo, |
| 1175 video_rejected ? "" : kCandidatePwdVideo); |
| 1176 JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1177 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(), |
| 1178 jdesc_.session_version())) { |
| 1148 return false; | 1179 return false; |
| 1149 } | 1180 } |
| 1150 EXPECT_TRUE(CompareSessionDescription(jdesc_, new_jdesc)); | 1181 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); |
| 1151 return true; | 1182 return true; |
| 1152 } | 1183 } |
| 1153 | 1184 |
| 1154 void TestDeserializeExtmap(bool session_level, bool media_level) { | 1185 void TestDeserializeExtmap(bool session_level, bool media_level) { |
| 1155 AddExtmap(); | 1186 AddExtmap(); |
| 1156 JsepSessionDescription new_jdesc("dummy"); | 1187 JsepSessionDescription new_jdesc("dummy"); |
| 1157 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), | 1188 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), |
| 1158 jdesc_.session_id(), | 1189 jdesc_.session_id(), |
| 1159 jdesc_.session_version())); | 1190 jdesc_.session_version())); |
| 1160 JsepSessionDescription jdesc_with_extmap("dummy"); | 1191 JsepSessionDescription jdesc_with_extmap("dummy"); |
| (...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 kFingerprint, &sdp_with_fingerprint); | 1570 kFingerprint, &sdp_with_fingerprint); |
| 1540 InjectAfter(kAttributeIcePwdVideo, | 1571 InjectAfter(kAttributeIcePwdVideo, |
| 1541 kFingerprint, &sdp_with_fingerprint); | 1572 kFingerprint, &sdp_with_fingerprint); |
| 1542 | 1573 |
| 1543 EXPECT_EQ(sdp_with_fingerprint, message); | 1574 EXPECT_EQ(sdp_with_fingerprint, message); |
| 1544 } | 1575 } |
| 1545 | 1576 |
| 1546 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { | 1577 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithoutCandidates) { |
| 1547 // JsepSessionDescription with desc but without candidates. | 1578 // JsepSessionDescription with desc but without candidates. |
| 1548 JsepSessionDescription jdesc_no_candidates(kDummyString); | 1579 JsepSessionDescription jdesc_no_candidates(kDummyString); |
| 1549 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), | 1580 ASSERT_TRUE(jdesc_no_candidates.Initialize(desc_.Copy(), kSessionId, |
| 1550 kSessionId, kSessionVersion)); | 1581 kSessionVersion)); |
| 1551 std::string message = webrtc::SdpSerialize(jdesc_no_candidates); | 1582 std::string message = webrtc::SdpSerialize(jdesc_no_candidates); |
| 1552 EXPECT_EQ(std::string(kSdpString), message); | 1583 EXPECT_EQ(std::string(kSdpString), message); |
| 1553 } | 1584 } |
| 1554 | 1585 |
| 1555 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) { | 1586 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithBundle) { |
| 1556 ContentGroup group(cricket::GROUP_TYPE_BUNDLE); | 1587 ContentGroup group(cricket::GROUP_TYPE_BUNDLE); |
| 1557 group.AddContentName(kAudioContentName); | 1588 group.AddContentName(kAudioContentName); |
| 1558 group.AddContentName(kVideoContentName); | 1589 group.AddContentName(kVideoContentName); |
| 1559 desc_.AddGroup(group); | 1590 desc_.AddGroup(group); |
| 1560 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), | 1591 ASSERT_TRUE(jdesc_.Initialize(desc_.Copy(), |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2715 const cricket::MediaContentDescription* mdesc = | 2746 const cricket::MediaContentDescription* mdesc = |
| 2716 static_cast<const cricket::MediaContentDescription*>( | 2747 static_cast<const cricket::MediaContentDescription*>( |
| 2717 desc->contents()[i].description); | 2748 desc->contents()[i].description); |
| 2718 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); | 2749 EXPECT_EQ(media_types[media_content_in_sdp[i]], mdesc->type()); |
| 2719 } | 2750 } |
| 2720 | 2751 |
| 2721 std::string serialized_sdp = webrtc::SdpSerialize(jdesc); | 2752 std::string serialized_sdp = webrtc::SdpSerialize(jdesc); |
| 2722 EXPECT_EQ(sdp_string, serialized_sdp); | 2753 EXPECT_EQ(sdp_string, serialized_sdp); |
| 2723 } | 2754 } |
| 2724 } | 2755 } |
| OLD | NEW |