Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2004 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 16 matching lines...) Expand all Loading... | |
| 27 | 27 |
| 28 #define ASSERT_CRYPTO(cd, s, cs) \ | 28 #define ASSERT_CRYPTO(cd, s, cs) \ |
| 29 ASSERT_EQ(s, cd->cryptos().size()); \ | 29 ASSERT_EQ(s, cd->cryptos().size()); \ |
| 30 ASSERT_EQ(std::string(cs), cd->cryptos()[0].cipher_suite) | 30 ASSERT_EQ(std::string(cs), cd->cryptos()[0].cipher_suite) |
| 31 | 31 |
| 32 typedef std::vector<cricket::Candidate> Candidates; | 32 typedef std::vector<cricket::Candidate> Candidates; |
| 33 | 33 |
| 34 using cricket::MediaContentDescription; | 34 using cricket::MediaContentDescription; |
| 35 using cricket::MediaSessionDescriptionFactory; | 35 using cricket::MediaSessionDescriptionFactory; |
| 36 using cricket::MediaContentDirection; | 36 using cricket::MediaContentDirection; |
| 37 using cricket::MediaDescriptionOptions; | |
| 37 using cricket::MediaSessionOptions; | 38 using cricket::MediaSessionOptions; |
| 38 using cricket::MediaType; | 39 using cricket::MediaType; |
| 39 using cricket::SessionDescription; | 40 using cricket::SessionDescription; |
| 40 using cricket::SsrcGroup; | 41 using cricket::SsrcGroup; |
| 41 using cricket::StreamParams; | 42 using cricket::StreamParams; |
| 42 using cricket::StreamParamsVec; | 43 using cricket::StreamParamsVec; |
| 43 using cricket::TransportDescription; | 44 using cricket::TransportDescription; |
| 44 using cricket::TransportDescriptionFactory; | 45 using cricket::TransportDescriptionFactory; |
| 45 using cricket::TransportInfo; | 46 using cricket::TransportInfo; |
| 46 using cricket::ContentInfo; | 47 using cricket::ContentInfo; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 58 using cricket::AudioCodec; | 59 using cricket::AudioCodec; |
| 59 using cricket::VideoCodec; | 60 using cricket::VideoCodec; |
| 60 using cricket::DataCodec; | 61 using cricket::DataCodec; |
| 61 using cricket::NS_JINGLE_RTP; | 62 using cricket::NS_JINGLE_RTP; |
| 62 using cricket::MEDIA_TYPE_AUDIO; | 63 using cricket::MEDIA_TYPE_AUDIO; |
| 63 using cricket::MEDIA_TYPE_VIDEO; | 64 using cricket::MEDIA_TYPE_VIDEO; |
| 64 using cricket::MEDIA_TYPE_DATA; | 65 using cricket::MEDIA_TYPE_DATA; |
| 65 using cricket::SEC_DISABLED; | 66 using cricket::SEC_DISABLED; |
| 66 using cricket::SEC_ENABLED; | 67 using cricket::SEC_ENABLED; |
| 67 using cricket::SEC_REQUIRED; | 68 using cricket::SEC_REQUIRED; |
| 69 using cricket::RtpTransceiverDirection; | |
| 68 using rtc::CS_AES_CM_128_HMAC_SHA1_32; | 70 using rtc::CS_AES_CM_128_HMAC_SHA1_32; |
| 69 using rtc::CS_AES_CM_128_HMAC_SHA1_80; | 71 using rtc::CS_AES_CM_128_HMAC_SHA1_80; |
| 70 using rtc::CS_AEAD_AES_128_GCM; | 72 using rtc::CS_AEAD_AES_128_GCM; |
| 71 using rtc::CS_AEAD_AES_256_GCM; | 73 using rtc::CS_AEAD_AES_256_GCM; |
| 72 using webrtc::RtpExtension; | 74 using webrtc::RtpExtension; |
| 73 | 75 |
| 74 static const AudioCodec kAudioCodecs1[] = { | 76 static const AudioCodec kAudioCodecs1[] = { |
| 75 AudioCodec(103, "ISAC", 16000, -1, 1), | 77 AudioCodec(103, "ISAC", 16000, -1, 1), |
| 76 AudioCodec(102, "iLBC", 8000, 13300, 1), | 78 AudioCodec(102, "iLBC", 8000, 13300, 1), |
| 77 AudioCodec(0, "PCMU", 8000, 64000, 1), | 79 AudioCodec(0, "PCMU", 8000, 64000, 1), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 static const char kDataTrack1[] = "data_1"; | 203 static const char kDataTrack1[] = "data_1"; |
| 202 static const char kDataTrack2[] = "data_2"; | 204 static const char kDataTrack2[] = "data_2"; |
| 203 static const char kDataTrack3[] = "data_3"; | 205 static const char kDataTrack3[] = "data_3"; |
| 204 | 206 |
| 205 static const char* kMediaProtocols[] = {"RTP/AVP", "RTP/SAVP", "RTP/AVPF", | 207 static const char* kMediaProtocols[] = {"RTP/AVP", "RTP/SAVP", "RTP/AVPF", |
| 206 "RTP/SAVPF"}; | 208 "RTP/SAVPF"}; |
| 207 static const char* kMediaProtocolsDtls[] = { | 209 static const char* kMediaProtocolsDtls[] = { |
| 208 "TCP/TLS/RTP/SAVPF", "TCP/TLS/RTP/SAVP", "UDP/TLS/RTP/SAVPF", | 210 "TCP/TLS/RTP/SAVPF", "TCP/TLS/RTP/SAVP", "UDP/TLS/RTP/SAVPF", |
| 209 "UDP/TLS/RTP/SAVP"}; | 211 "UDP/TLS/RTP/SAVP"}; |
| 210 | 212 |
| 213 static constexpr bool kStopped = true; | |
|
Taylor Brandstetter
2017/08/05 00:39:09
May want to comment that this is used to make code
Zhi Huang
2017/08/09 00:54:50
Done.
| |
| 214 | |
| 211 static bool IsMediaContentOfType(const ContentInfo* content, | 215 static bool IsMediaContentOfType(const ContentInfo* content, |
| 212 MediaType media_type) { | 216 MediaType media_type) { |
| 213 const MediaContentDescription* mdesc = | 217 const MediaContentDescription* mdesc = |
| 214 static_cast<const MediaContentDescription*>(content->description); | 218 static_cast<const MediaContentDescription*>(content->description); |
| 215 return mdesc && mdesc->type() == media_type; | 219 return mdesc && mdesc->type() == media_type; |
| 216 } | 220 } |
| 217 | 221 |
| 218 static cricket::MediaContentDirection | 222 static cricket::MediaContentDirection |
| 219 GetMediaDirection(const ContentInfo* content) { | 223 GetMediaDirection(const ContentInfo* content) { |
| 220 cricket::MediaContentDescription* desc = | 224 cricket::MediaContentDescription* desc = |
| 221 reinterpret_cast<cricket::MediaContentDescription*>(content->description); | 225 reinterpret_cast<cricket::MediaContentDescription*>(content->description); |
| 222 return desc->direction(); | 226 return desc->direction(); |
| 223 } | 227 } |
| 224 | 228 |
| 225 static void AddRtxCodec(const VideoCodec& rtx_codec, | 229 static void AddRtxCodec(const VideoCodec& rtx_codec, |
| 226 std::vector<VideoCodec>* codecs) { | 230 std::vector<VideoCodec>* codecs) { |
| 227 ASSERT_FALSE(cricket::FindCodecById(*codecs, rtx_codec.id)); | 231 ASSERT_FALSE(cricket::FindCodecById(*codecs, rtx_codec.id)); |
| 228 codecs->push_back(rtx_codec); | 232 codecs->push_back(rtx_codec); |
| 229 } | 233 } |
| 230 | 234 |
| 231 template <class T> | 235 template <class T> |
| 232 static std::vector<std::string> GetCodecNames(const std::vector<T>& codecs) { | 236 static std::vector<std::string> GetCodecNames(const std::vector<T>& codecs) { |
| 233 std::vector<std::string> codec_names; | 237 std::vector<std::string> codec_names; |
| 234 for (const auto& codec : codecs) { | 238 for (const auto& codec : codecs) { |
| 235 codec_names.push_back(codec.name); | 239 codec_names.push_back(codec.name); |
| 236 } | 240 } |
| 237 return codec_names; | 241 return codec_names; |
| 238 } | 242 } |
| 239 | 243 |
| 244 // This is used for test only. MIDs are not the identification of the | |
| 245 // MediaDescriptionOptions since some end points may not support MID and the SDP | |
| 246 // may not contain 'mid'. | |
| 247 std::vector<MediaDescriptionOptions>::iterator FindFirstMediaDescriptionByMid( | |
| 248 const std::string& mid, | |
| 249 MediaSessionOptions* opts) { | |
| 250 return std::find_if( | |
| 251 opts->media_description_options.begin(), | |
| 252 opts->media_description_options.end(), | |
| 253 [mid](const MediaDescriptionOptions& t) { return t.mid == mid; }); | |
| 254 } | |
| 255 | |
| 256 // Add a media section to the |session_options|. | |
| 257 static void AddMediaSection(MediaType type, | |
| 258 const std::string& mid, | |
| 259 MediaContentDirection direction, | |
| 260 bool stopped, | |
| 261 MediaSessionOptions* opts) { | |
| 262 opts->media_description_options.push_back(MediaDescriptionOptions( | |
| 263 type, mid, | |
| 264 cricket::RtpTransceiverDirection::FromMediaContentDirection(direction), | |
| 265 stopped)); | |
| 266 } | |
| 267 | |
| 268 static void AddAudioVideoSections(MediaContentDirection direction, | |
| 269 MediaSessionOptions* opts) { | |
| 270 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", direction, !kStopped, opts); | |
| 271 AddMediaSection(MEDIA_TYPE_VIDEO, "video", direction, !kStopped, opts); | |
| 272 } | |
| 273 | |
| 274 static void AddDataSection(cricket::DataChannelType dct, | |
| 275 MediaContentDirection direction, | |
| 276 MediaSessionOptions* opts) { | |
| 277 opts->data_channel_type = dct; | |
| 278 AddMediaSection(MEDIA_TYPE_DATA, "data", direction, !kStopped, opts); | |
| 279 } | |
| 280 | |
| 281 static void AttachSenderToMediaSection(const std::string& mid, | |
| 282 MediaType type, | |
| 283 const std::string& track_id, | |
| 284 const std::string& stream_id, | |
| 285 int num_sim_layer, | |
| 286 MediaSessionOptions* session_options) { | |
| 287 auto it = FindFirstMediaDescriptionByMid(mid, session_options); | |
| 288 switch (type) { | |
| 289 case MEDIA_TYPE_AUDIO: | |
| 290 it->AddAudioSender(track_id, stream_id); | |
| 291 break; | |
| 292 case MEDIA_TYPE_VIDEO: | |
| 293 it->AddVideoSender(track_id, stream_id, num_sim_layer); | |
| 294 break; | |
| 295 case MEDIA_TYPE_DATA: | |
| 296 it->AddRtpDataChannel(track_id, stream_id); | |
| 297 break; | |
| 298 default: | |
| 299 RTC_NOTREACHED(); | |
| 300 } | |
| 301 } | |
| 302 | |
| 303 static void DetachSenderFromMediaSection(const std::string& mid, | |
| 304 const std::string& track_id, | |
| 305 MediaSessionOptions* session_options) { | |
| 306 auto it = FindFirstMediaDescriptionByMid(mid, session_options); | |
| 307 auto sender_it = it->sender_options.begin(); | |
| 308 for (; sender_it != it->sender_options.end(); ++sender_it) { | |
| 309 if (sender_it->track_id == track_id) { | |
| 310 it->sender_options.erase(sender_it); | |
| 311 return; | |
| 312 } | |
| 313 } | |
| 314 RTC_NOTREACHED(); | |
| 315 } | |
| 316 | |
| 317 // Helper function used to create a default MediaSessionOptions for Plan B SDP. | |
| 318 // (https://tools.ietf.org/html/draft-uberti-rtcweb-plan-00). | |
| 319 static MediaSessionOptions CreatePlanBMediaSessionOptions() { | |
| 320 MediaSessionOptions session_options; | |
| 321 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, | |
| 322 &session_options); | |
| 323 return session_options; | |
| 324 } | |
| 325 | |
| 326 // Helper function used to create a default MediaSessionOptions for unified plan | |
| 327 // SDP. | |
| 328 static MediaSessionOptions CreateUnifiedPlanMediaSessionOptions() { | |
| 329 MediaSessionOptions opts; | |
| 330 AddMediaSection(MEDIA_TYPE_AUDIO, "audio_1", cricket::MD_SENDRECV, !kStopped, | |
| 331 &opts); | |
| 332 AttachSenderToMediaSection("audio_1", MEDIA_TYPE_AUDIO, kAudioTrack1, | |
| 333 kMediaStream1, 1, &opts); | |
| 334 | |
| 335 AddMediaSection(MEDIA_TYPE_VIDEO, "video_1", cricket::MD_SENDRECV, !kStopped, | |
| 336 &opts); | |
| 337 AttachSenderToMediaSection("video_1", MEDIA_TYPE_VIDEO, kVideoTrack1, | |
| 338 kMediaStream1, 1, &opts); | |
| 339 | |
| 340 AddMediaSection(MEDIA_TYPE_AUDIO, "audio_2", cricket::MD_SENDRECV, !kStopped, | |
| 341 &opts); | |
| 342 AttachSenderToMediaSection("audio_2", MEDIA_TYPE_AUDIO, kAudioTrack2, | |
| 343 kMediaStream2, 1, &opts); | |
| 344 | |
| 345 AddMediaSection(MEDIA_TYPE_VIDEO, "video_2", cricket::MD_SENDRECV, !kStopped, | |
| 346 &opts); | |
| 347 AttachSenderToMediaSection("video_2", MEDIA_TYPE_VIDEO, kVideoTrack2, | |
| 348 kMediaStream2, 1, &opts); | |
| 349 return opts; | |
| 350 } | |
| 351 | |
| 352 // TODO(zhihuang): Most of these tests were written while MediaSessionOptions | |
| 353 // was designed for Plan B SDP, where only one audio "m=" section and one video | |
| 354 // "m=" section could be generated, and ordering couldn't be controlled. Many of | |
| 355 // these tests may be obsolete as a result, and should be refactored or removed. | |
| 240 class MediaSessionDescriptionFactoryTest : public testing::Test { | 356 class MediaSessionDescriptionFactoryTest : public testing::Test { |
| 241 public: | 357 public: |
| 242 MediaSessionDescriptionFactoryTest() | 358 MediaSessionDescriptionFactoryTest() : f1_(&tdf1_), f2_(&tdf2_) { |
| 243 : f1_(&tdf1_), | |
| 244 f2_(&tdf2_) { | |
| 245 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), | 359 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 246 MAKE_VECTOR(kAudioCodecs1)); | 360 MAKE_VECTOR(kAudioCodecs1)); |
| 247 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); | 361 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 248 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); | 362 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
| 249 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), | 363 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 250 MAKE_VECTOR(kAudioCodecs2)); | 364 MAKE_VECTOR(kAudioCodecs2)); |
| 251 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); | 365 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); |
| 252 f2_.set_data_codecs(MAKE_VECTOR(kDataCodecs2)); | 366 f2_.set_data_codecs(MAKE_VECTOR(kDataCodecs2)); |
| 253 tdf1_.set_certificate(rtc::RTCCertificate::Create( | 367 tdf1_.set_certificate(rtc::RTCCertificate::Create( |
| 254 std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); | 368 std::unique_ptr<rtc::SSLIdentity>(new rtc::FakeSSLIdentity("id1")))); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 // Returns true if the transport info contains "renomination" as an | 412 // Returns true if the transport info contains "renomination" as an |
| 299 // ICE option. | 413 // ICE option. |
| 300 bool GetIceRenomination(const TransportInfo* transport_info) { | 414 bool GetIceRenomination(const TransportInfo* transport_info) { |
| 301 const std::vector<std::string>& ice_options = | 415 const std::vector<std::string>& ice_options = |
| 302 transport_info->description.transport_options; | 416 transport_info->description.transport_options; |
| 303 auto iter = | 417 auto iter = |
| 304 std::find(ice_options.begin(), ice_options.end(), "renomination"); | 418 std::find(ice_options.begin(), ice_options.end(), "renomination"); |
| 305 return iter != ice_options.end(); | 419 return iter != ice_options.end(); |
| 306 } | 420 } |
| 307 | 421 |
| 308 void TestTransportInfo(bool offer, const MediaSessionOptions& options, | 422 void TestTransportInfo(bool offer, |
| 423 MediaSessionOptions& options, | |
| 309 bool has_current_desc) { | 424 bool has_current_desc) { |
| 310 const std::string current_audio_ufrag = "current_audio_ufrag"; | 425 const std::string current_audio_ufrag = "current_audio_ufrag"; |
| 311 const std::string current_audio_pwd = "current_audio_pwd"; | 426 const std::string current_audio_pwd = "current_audio_pwd"; |
| 312 const std::string current_video_ufrag = "current_video_ufrag"; | 427 const std::string current_video_ufrag = "current_video_ufrag"; |
| 313 const std::string current_video_pwd = "current_video_pwd"; | 428 const std::string current_video_pwd = "current_video_pwd"; |
| 314 const std::string current_data_ufrag = "current_data_ufrag"; | 429 const std::string current_data_ufrag = "current_data_ufrag"; |
| 315 const std::string current_data_pwd = "current_data_pwd"; | 430 const std::string current_data_pwd = "current_data_pwd"; |
| 316 std::unique_ptr<SessionDescription> current_desc; | 431 std::unique_ptr<SessionDescription> current_desc; |
| 317 std::unique_ptr<SessionDescription> desc; | 432 std::unique_ptr<SessionDescription> desc; |
| 318 if (has_current_desc) { | 433 if (has_current_desc) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 343 EXPECT_TRUE(ti_audio != NULL); | 458 EXPECT_TRUE(ti_audio != NULL); |
| 344 if (has_current_desc) { | 459 if (has_current_desc) { |
| 345 EXPECT_EQ(current_audio_ufrag, ti_audio->description.ice_ufrag); | 460 EXPECT_EQ(current_audio_ufrag, ti_audio->description.ice_ufrag); |
| 346 EXPECT_EQ(current_audio_pwd, ti_audio->description.ice_pwd); | 461 EXPECT_EQ(current_audio_pwd, ti_audio->description.ice_pwd); |
| 347 } else { | 462 } else { |
| 348 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), | 463 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 349 ti_audio->description.ice_ufrag.size()); | 464 ti_audio->description.ice_ufrag.size()); |
| 350 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), | 465 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 351 ti_audio->description.ice_pwd.size()); | 466 ti_audio->description.ice_pwd.size()); |
| 352 } | 467 } |
| 353 EXPECT_EQ(options.enable_ice_renomination, GetIceRenomination(ti_audio)); | 468 auto media_desc_options_it = |
| 469 FindFirstMediaDescriptionByMid("audio", &options); | |
| 470 EXPECT_EQ( | |
| 471 media_desc_options_it->transport_options.enable_ice_renomination, | |
| 472 GetIceRenomination(ti_audio)); | |
| 354 | 473 |
| 355 } else { | 474 } else { |
| 356 EXPECT_TRUE(ti_audio == NULL); | 475 EXPECT_TRUE(ti_audio == NULL); |
| 357 } | 476 } |
| 358 const TransportInfo* ti_video = desc->GetTransportInfoByName("video"); | 477 const TransportInfo* ti_video = desc->GetTransportInfoByName("video"); |
| 359 if (options.has_video()) { | 478 if (options.has_video()) { |
| 360 EXPECT_TRUE(ti_video != NULL); | 479 EXPECT_TRUE(ti_video != NULL); |
| 361 if (options.bundle_enabled) { | 480 if (options.bundle_enabled) { |
| 362 EXPECT_EQ(ti_audio->description.ice_ufrag, | 481 EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 363 ti_video->description.ice_ufrag); | 482 ti_video->description.ice_ufrag); |
| 364 EXPECT_EQ(ti_audio->description.ice_pwd, | 483 EXPECT_EQ(ti_audio->description.ice_pwd, |
| 365 ti_video->description.ice_pwd); | 484 ti_video->description.ice_pwd); |
| 366 } else { | 485 } else { |
| 367 if (has_current_desc) { | 486 if (has_current_desc) { |
| 368 EXPECT_EQ(current_video_ufrag, ti_video->description.ice_ufrag); | 487 EXPECT_EQ(current_video_ufrag, ti_video->description.ice_ufrag); |
| 369 EXPECT_EQ(current_video_pwd, ti_video->description.ice_pwd); | 488 EXPECT_EQ(current_video_pwd, ti_video->description.ice_pwd); |
| 370 } else { | 489 } else { |
| 371 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), | 490 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 372 ti_video->description.ice_ufrag.size()); | 491 ti_video->description.ice_ufrag.size()); |
| 373 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), | 492 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 374 ti_video->description.ice_pwd.size()); | 493 ti_video->description.ice_pwd.size()); |
| 375 } | 494 } |
| 376 } | 495 } |
| 377 EXPECT_EQ(options.enable_ice_renomination, GetIceRenomination(ti_video)); | 496 auto media_desc_options_it = |
| 497 FindFirstMediaDescriptionByMid("video", &options); | |
| 498 EXPECT_EQ( | |
| 499 media_desc_options_it->transport_options.enable_ice_renomination, | |
| 500 GetIceRenomination(ti_video)); | |
| 378 } else { | 501 } else { |
| 379 EXPECT_TRUE(ti_video == NULL); | 502 EXPECT_TRUE(ti_video == NULL); |
| 380 } | 503 } |
| 381 const TransportInfo* ti_data = desc->GetTransportInfoByName("data"); | 504 const TransportInfo* ti_data = desc->GetTransportInfoByName("data"); |
| 382 if (options.has_data()) { | 505 if (options.has_data()) { |
| 383 EXPECT_TRUE(ti_data != NULL); | 506 EXPECT_TRUE(ti_data != NULL); |
| 384 if (options.bundle_enabled) { | 507 if (options.bundle_enabled) { |
| 385 EXPECT_EQ(ti_audio->description.ice_ufrag, | 508 EXPECT_EQ(ti_audio->description.ice_ufrag, |
| 386 ti_data->description.ice_ufrag); | 509 ti_data->description.ice_ufrag); |
| 387 EXPECT_EQ(ti_audio->description.ice_pwd, | 510 EXPECT_EQ(ti_audio->description.ice_pwd, |
| 388 ti_data->description.ice_pwd); | 511 ti_data->description.ice_pwd); |
| 389 } else { | 512 } else { |
| 390 if (has_current_desc) { | 513 if (has_current_desc) { |
| 391 EXPECT_EQ(current_data_ufrag, ti_data->description.ice_ufrag); | 514 EXPECT_EQ(current_data_ufrag, ti_data->description.ice_ufrag); |
| 392 EXPECT_EQ(current_data_pwd, ti_data->description.ice_pwd); | 515 EXPECT_EQ(current_data_pwd, ti_data->description.ice_pwd); |
| 393 } else { | 516 } else { |
| 394 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), | 517 EXPECT_EQ(static_cast<size_t>(cricket::ICE_UFRAG_LENGTH), |
| 395 ti_data->description.ice_ufrag.size()); | 518 ti_data->description.ice_ufrag.size()); |
| 396 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), | 519 EXPECT_EQ(static_cast<size_t>(cricket::ICE_PWD_LENGTH), |
| 397 ti_data->description.ice_pwd.size()); | 520 ti_data->description.ice_pwd.size()); |
| 398 } | 521 } |
| 399 } | 522 } |
| 400 EXPECT_EQ(options.enable_ice_renomination, GetIceRenomination(ti_data)); | 523 auto media_desc_options_it = |
| 524 FindFirstMediaDescriptionByMid("data", &options); | |
| 525 EXPECT_EQ( | |
| 526 media_desc_options_it->transport_options.enable_ice_renomination, | |
| 527 GetIceRenomination(ti_data)); | |
| 401 | 528 |
| 402 } else { | 529 } else { |
| 403 EXPECT_TRUE(ti_video == NULL); | 530 EXPECT_TRUE(ti_video == NULL); |
| 404 } | 531 } |
| 405 } | 532 } |
| 406 | 533 |
| 407 void TestCryptoWithBundle(bool offer) { | 534 void TestCryptoWithBundle(bool offer) { |
| 408 f1_.set_secure(SEC_ENABLED); | 535 f1_.set_secure(SEC_ENABLED); |
| 409 MediaSessionOptions options; | 536 MediaSessionOptions options; |
| 410 options.recv_audio = true; | 537 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 411 options.recv_video = true; | 538 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 412 options.data_channel_type = cricket::DCT_RTP; | |
| 413 std::unique_ptr<SessionDescription> ref_desc; | 539 std::unique_ptr<SessionDescription> ref_desc; |
| 414 std::unique_ptr<SessionDescription> desc; | 540 std::unique_ptr<SessionDescription> desc; |
| 415 if (offer) { | 541 if (offer) { |
| 416 options.bundle_enabled = false; | 542 options.bundle_enabled = false; |
| 417 ref_desc.reset(f1_.CreateOffer(options, NULL)); | 543 ref_desc.reset(f1_.CreateOffer(options, NULL)); |
| 418 options.bundle_enabled = true; | 544 options.bundle_enabled = true; |
| 419 desc.reset(f1_.CreateOffer(options, ref_desc.get())); | 545 desc.reset(f1_.CreateOffer(options, ref_desc.get())); |
| 420 } else { | 546 } else { |
| 421 options.bundle_enabled = true; | 547 options.bundle_enabled = true; |
| 422 ref_desc.reset(f1_.CreateOffer(options, NULL)); | 548 ref_desc.reset(f1_.CreateOffer(options, NULL)); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 448 audio_media_desc->cryptos()[0])) { | 574 audio_media_desc->cryptos()[0])) { |
| 449 found = true; | 575 found = true; |
| 450 break; | 576 break; |
| 451 } | 577 } |
| 452 } | 578 } |
| 453 EXPECT_TRUE(found); | 579 EXPECT_TRUE(found); |
| 454 } | 580 } |
| 455 | 581 |
| 456 // This test that the audio and video media direction is set to | 582 // This test that the audio and video media direction is set to |
| 457 // |expected_direction_in_answer| in an answer if the offer direction is set | 583 // |expected_direction_in_answer| in an answer if the offer direction is set |
| 458 // to |direction_in_offer|. | 584 // to |direction_in_offer| and the answer is willing to both send and receive. |
| 459 void TestMediaDirectionInAnswer( | 585 void TestMediaDirectionInAnswer( |
| 460 cricket::MediaContentDirection direction_in_offer, | 586 cricket::MediaContentDirection direction_in_offer, |
| 461 cricket::MediaContentDirection expected_direction_in_answer) { | 587 cricket::MediaContentDirection expected_direction_in_answer) { |
| 462 MediaSessionOptions opts; | 588 MediaSessionOptions offer_opts; |
| 463 opts.recv_video = true; | 589 AddAudioVideoSections(direction_in_offer, &offer_opts); |
| 464 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 590 |
| 591 std::unique_ptr<SessionDescription> offer( | |
| 592 f1_.CreateOffer(offer_opts, NULL)); | |
| 465 ASSERT_TRUE(offer.get() != NULL); | 593 ASSERT_TRUE(offer.get() != NULL); |
| 466 ContentInfo* ac_offer = offer->GetContentByName("audio"); | 594 ContentInfo* ac_offer = offer->GetContentByName("audio"); |
| 467 ASSERT_TRUE(ac_offer != NULL); | 595 ASSERT_TRUE(ac_offer != NULL); |
| 468 AudioContentDescription* acd_offer = | |
| 469 static_cast<AudioContentDescription*>(ac_offer->description); | |
| 470 acd_offer->set_direction(direction_in_offer); | |
| 471 ContentInfo* vc_offer = offer->GetContentByName("video"); | 596 ContentInfo* vc_offer = offer->GetContentByName("video"); |
| 472 ASSERT_TRUE(vc_offer != NULL); | 597 ASSERT_TRUE(vc_offer != NULL); |
| 473 VideoContentDescription* vcd_offer = | |
| 474 static_cast<VideoContentDescription*>(vc_offer->description); | |
| 475 vcd_offer->set_direction(direction_in_offer); | |
| 476 | 598 |
| 599 MediaSessionOptions answer_opts; | |
| 600 AddAudioVideoSections(cricket::MD_SENDRECV, &answer_opts); | |
| 477 std::unique_ptr<SessionDescription> answer( | 601 std::unique_ptr<SessionDescription> answer( |
| 478 f2_.CreateAnswer(offer.get(), opts, NULL)); | 602 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 479 const AudioContentDescription* acd_answer = | 603 const AudioContentDescription* acd_answer = |
| 480 GetFirstAudioContentDescription(answer.get()); | 604 GetFirstAudioContentDescription(answer.get()); |
| 481 EXPECT_EQ(expected_direction_in_answer, acd_answer->direction()); | 605 EXPECT_EQ(expected_direction_in_answer, acd_answer->direction()); |
| 482 const VideoContentDescription* vcd_answer = | 606 const VideoContentDescription* vcd_answer = |
| 483 GetFirstVideoContentDescription(answer.get()); | 607 GetFirstVideoContentDescription(answer.get()); |
| 484 EXPECT_EQ(expected_direction_in_answer, vcd_answer->direction()); | 608 EXPECT_EQ(expected_direction_in_answer, vcd_answer->direction()); |
| 485 } | 609 } |
| 486 | 610 |
| 487 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { | 611 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) { |
| 488 const cricket::ContentDescription* description = content->description; | 612 const cricket::ContentDescription* description = content->description; |
| 489 RTC_CHECK(description != NULL); | 613 RTC_CHECK(description != NULL); |
| 490 const cricket::AudioContentDescription* audio_content_desc = | 614 const cricket::AudioContentDescription* audio_content_desc = |
| 491 static_cast<const cricket::AudioContentDescription*>(description); | 615 static_cast<const cricket::AudioContentDescription*>(description); |
| 492 RTC_CHECK(audio_content_desc != NULL); | 616 RTC_CHECK(audio_content_desc != NULL); |
| 493 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { | 617 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) { |
| 494 if (audio_content_desc->codecs()[i].name == "CN") | 618 if (audio_content_desc->codecs()[i].name == "CN") |
| 495 return false; | 619 return false; |
| 496 } | 620 } |
| 497 return true; | 621 return true; |
| 498 } | 622 } |
| 499 | 623 |
| 500 void TestVideoGcmCipher(bool gcm_offer, bool gcm_answer) { | 624 void TestVideoGcmCipher(bool gcm_offer, bool gcm_answer) { |
| 501 MediaSessionOptions offer_opts; | 625 MediaSessionOptions offer_opts; |
| 502 offer_opts.recv_video = true; | 626 AddAudioVideoSections(cricket::MD_RECVONLY, &offer_opts); |
| 503 offer_opts.crypto_options.enable_gcm_crypto_suites = gcm_offer; | 627 offer_opts.crypto_options.enable_gcm_crypto_suites = gcm_offer; |
| 628 | |
| 504 MediaSessionOptions answer_opts; | 629 MediaSessionOptions answer_opts; |
| 505 answer_opts.recv_video = true; | 630 AddAudioVideoSections(cricket::MD_RECVONLY, &answer_opts); |
| 506 answer_opts.crypto_options.enable_gcm_crypto_suites = gcm_answer; | 631 answer_opts.crypto_options.enable_gcm_crypto_suites = gcm_answer; |
| 632 | |
| 507 f1_.set_secure(SEC_ENABLED); | 633 f1_.set_secure(SEC_ENABLED); |
| 508 f2_.set_secure(SEC_ENABLED); | 634 f2_.set_secure(SEC_ENABLED); |
| 509 std::unique_ptr<SessionDescription> offer( | 635 std::unique_ptr<SessionDescription> offer( |
| 510 f1_.CreateOffer(offer_opts, NULL)); | 636 f1_.CreateOffer(offer_opts, NULL)); |
| 511 ASSERT_TRUE(offer.get() != NULL); | 637 ASSERT_TRUE(offer.get() != NULL); |
| 512 std::unique_ptr<SessionDescription> answer( | 638 std::unique_ptr<SessionDescription> answer( |
| 513 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); | 639 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 514 const ContentInfo* ac = answer->GetContentByName("audio"); | 640 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 515 const ContentInfo* vc = answer->GetContentByName("video"); | 641 const ContentInfo* vc = answer->GetContentByName("video"); |
| 516 ASSERT_TRUE(ac != NULL); | 642 ASSERT_TRUE(ac != NULL); |
| 517 ASSERT_TRUE(vc != NULL); | 643 ASSERT_TRUE(vc != NULL); |
| 518 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 644 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 519 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); | 645 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); |
| 520 const AudioContentDescription* acd = | 646 const AudioContentDescription* acd = |
| 521 static_cast<const AudioContentDescription*>(ac->description); | 647 static_cast<const AudioContentDescription*>(ac->description); |
| 522 const VideoContentDescription* vcd = | 648 const VideoContentDescription* vcd = |
| 523 static_cast<const VideoContentDescription*>(vc->description); | 649 static_cast<const VideoContentDescription*>(vc->description); |
| 524 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 650 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 525 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 651 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 526 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 652 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 527 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 653 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 528 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 654 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 529 if (gcm_offer && gcm_answer) { | 655 if (gcm_offer && gcm_answer) { |
| 530 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); | 656 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 531 } else { | 657 } else { |
| 532 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 658 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 533 } | 659 } |
| 534 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); | 660 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 535 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); | 661 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); |
| 536 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc | 662 EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 537 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux | 663 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 538 if (gcm_offer && gcm_answer) { | 664 if (gcm_offer && gcm_answer) { |
| 539 ASSERT_CRYPTO(vcd, 1U, CS_AEAD_AES_256_GCM); | 665 ASSERT_CRYPTO(vcd, 1U, CS_AEAD_AES_256_GCM); |
| 540 } else { | 666 } else { |
| 541 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 667 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 542 } | 668 } |
| 543 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 669 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 544 } | 670 } |
| 545 | 671 |
| 546 protected: | 672 protected: |
| 547 MediaSessionDescriptionFactory f1_; | 673 MediaSessionDescriptionFactory f1_; |
| 548 MediaSessionDescriptionFactory f2_; | 674 MediaSessionDescriptionFactory f2_; |
| 549 TransportDescriptionFactory tdf1_; | 675 TransportDescriptionFactory tdf1_; |
| 550 TransportDescriptionFactory tdf2_; | 676 TransportDescriptionFactory tdf2_; |
| 551 }; | 677 }; |
| 552 | 678 |
| 553 // Create a typical audio offer, and ensure it matches what we expect. | 679 // Create a typical audio offer, and ensure it matches what we expect. |
| 554 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { | 680 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioOffer) { |
| 555 f1_.set_secure(SEC_ENABLED); | 681 f1_.set_secure(SEC_ENABLED); |
| 556 std::unique_ptr<SessionDescription> offer( | 682 std::unique_ptr<SessionDescription> offer( |
| 557 f1_.CreateOffer(MediaSessionOptions(), NULL)); | 683 f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL)); |
| 558 ASSERT_TRUE(offer.get() != NULL); | 684 ASSERT_TRUE(offer.get() != NULL); |
| 559 const ContentInfo* ac = offer->GetContentByName("audio"); | 685 const ContentInfo* ac = offer->GetContentByName("audio"); |
| 560 const ContentInfo* vc = offer->GetContentByName("video"); | 686 const ContentInfo* vc = offer->GetContentByName("video"); |
| 561 ASSERT_TRUE(ac != NULL); | 687 ASSERT_TRUE(ac != NULL); |
| 562 ASSERT_TRUE(vc == NULL); | 688 ASSERT_TRUE(vc == NULL); |
| 563 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 689 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 564 const AudioContentDescription* acd = | 690 const AudioContentDescription* acd = |
| 565 static_cast<const AudioContentDescription*>(ac->description); | 691 static_cast<const AudioContentDescription*>(ac->description); |
| 566 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 692 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 567 EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); | 693 EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
| 568 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 694 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached. |
| 569 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) | 695 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 570 EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on | 696 EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
| 571 ASSERT_CRYPTO(acd, 2U, CS_AES_CM_128_HMAC_SHA1_32); | 697 ASSERT_CRYPTO(acd, 2U, CS_AES_CM_128_HMAC_SHA1_32); |
| 572 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 698 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 573 } | 699 } |
| 574 | 700 |
| 575 // Create a typical video offer, and ensure it matches what we expect. | 701 // Create a typical video offer, and ensure it matches what we expect. |
| 576 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoOffer) { | 702 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoOffer) { |
| 577 MediaSessionOptions opts; | 703 MediaSessionOptions opts; |
| 578 opts.recv_video = true; | 704 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 579 f1_.set_secure(SEC_ENABLED); | 705 f1_.set_secure(SEC_ENABLED); |
| 580 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 706 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 581 ASSERT_TRUE(offer.get() != NULL); | 707 ASSERT_TRUE(offer.get() != NULL); |
| 582 const ContentInfo* ac = offer->GetContentByName("audio"); | 708 const ContentInfo* ac = offer->GetContentByName("audio"); |
| 583 const ContentInfo* vc = offer->GetContentByName("video"); | 709 const ContentInfo* vc = offer->GetContentByName("video"); |
| 584 ASSERT_TRUE(ac != NULL); | 710 ASSERT_TRUE(ac != NULL); |
| 585 ASSERT_TRUE(vc != NULL); | 711 ASSERT_TRUE(vc != NULL); |
| 586 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 712 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 587 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); | 713 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); |
| 588 const AudioContentDescription* acd = | 714 const AudioContentDescription* acd = |
| 589 static_cast<const AudioContentDescription*>(ac->description); | 715 static_cast<const AudioContentDescription*>(ac->description); |
| 590 const VideoContentDescription* vcd = | 716 const VideoContentDescription* vcd = |
| 591 static_cast<const VideoContentDescription*>(vc->description); | 717 static_cast<const VideoContentDescription*>(vc->description); |
| 592 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 718 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 593 EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); | 719 EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
| 594 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 720 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 595 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) | 721 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 596 EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on | 722 EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
| 597 ASSERT_CRYPTO(acd, 2U, CS_AES_CM_128_HMAC_SHA1_32); | 723 ASSERT_CRYPTO(acd, 2U, CS_AES_CM_128_HMAC_SHA1_32); |
| 598 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 724 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 599 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); | 725 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 600 EXPECT_EQ(f1_.video_codecs(), vcd->codecs()); | 726 EXPECT_EQ(f1_.video_codecs(), vcd->codecs()); |
| 601 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc | 727 EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 602 EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) | 728 EXPECT_EQ(kAutoBandwidth, vcd->bandwidth()); // default bandwidth (auto) |
| 603 EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on | 729 EXPECT_TRUE(vcd->rtcp_mux()); // rtcp-mux defaults on |
| 604 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 730 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 605 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 731 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 606 } | 732 } |
| 607 | 733 |
| 608 // Test creating an offer with bundle where the Codecs have the same dynamic | 734 // Test creating an offer with bundle where the Codecs have the same dynamic |
| 609 // RTP playlod type. The test verifies that the offer don't contain the | 735 // RTP playlod type. The test verifies that the offer don't contain the |
| 610 // duplicate RTP payload types. | 736 // duplicate RTP payload types. |
| 611 TEST_F(MediaSessionDescriptionFactoryTest, TestBundleOfferWithSameCodecPlType) { | 737 TEST_F(MediaSessionDescriptionFactoryTest, TestBundleOfferWithSameCodecPlType) { |
| 612 const VideoCodec& offered_video_codec = f2_.video_codecs()[0]; | 738 const VideoCodec& offered_video_codec = f2_.video_codecs()[0]; |
| 613 const AudioCodec& offered_audio_codec = f2_.audio_sendrecv_codecs()[0]; | 739 const AudioCodec& offered_audio_codec = f2_.audio_sendrecv_codecs()[0]; |
| 614 const DataCodec& offered_data_codec = f2_.data_codecs()[0]; | 740 const DataCodec& offered_data_codec = f2_.data_codecs()[0]; |
| 615 ASSERT_EQ(offered_video_codec.id, offered_audio_codec.id); | 741 ASSERT_EQ(offered_video_codec.id, offered_audio_codec.id); |
| 616 ASSERT_EQ(offered_video_codec.id, offered_data_codec.id); | 742 ASSERT_EQ(offered_video_codec.id, offered_data_codec.id); |
| 617 | 743 |
| 618 MediaSessionOptions opts; | 744 MediaSessionOptions opts; |
| 619 opts.recv_audio = true; | 745 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 620 opts.recv_video = true; | 746 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); |
| 621 opts.data_channel_type = cricket::DCT_RTP; | |
| 622 opts.bundle_enabled = true; | 747 opts.bundle_enabled = true; |
| 623 std::unique_ptr<SessionDescription> offer(f2_.CreateOffer(opts, NULL)); | 748 std::unique_ptr<SessionDescription> offer(f2_.CreateOffer(opts, NULL)); |
| 624 const VideoContentDescription* vcd = | 749 const VideoContentDescription* vcd = |
| 625 GetFirstVideoContentDescription(offer.get()); | 750 GetFirstVideoContentDescription(offer.get()); |
| 626 const AudioContentDescription* acd = | 751 const AudioContentDescription* acd = |
| 627 GetFirstAudioContentDescription(offer.get()); | 752 GetFirstAudioContentDescription(offer.get()); |
| 628 const DataContentDescription* dcd = | 753 const DataContentDescription* dcd = |
| 629 GetFirstDataContentDescription(offer.get()); | 754 GetFirstDataContentDescription(offer.get()); |
| 630 ASSERT_TRUE(NULL != vcd); | 755 ASSERT_TRUE(NULL != vcd); |
| 631 ASSERT_TRUE(NULL != acd); | 756 ASSERT_TRUE(NULL != acd); |
| 632 ASSERT_TRUE(NULL != dcd); | 757 ASSERT_TRUE(NULL != dcd); |
| 633 EXPECT_NE(vcd->codecs()[0].id, acd->codecs()[0].id); | 758 EXPECT_NE(vcd->codecs()[0].id, acd->codecs()[0].id); |
| 634 EXPECT_NE(vcd->codecs()[0].id, dcd->codecs()[0].id); | 759 EXPECT_NE(vcd->codecs()[0].id, dcd->codecs()[0].id); |
| 635 EXPECT_NE(acd->codecs()[0].id, dcd->codecs()[0].id); | 760 EXPECT_NE(acd->codecs()[0].id, dcd->codecs()[0].id); |
| 636 EXPECT_EQ(vcd->codecs()[0].name, offered_video_codec.name); | 761 EXPECT_EQ(vcd->codecs()[0].name, offered_video_codec.name); |
| 637 EXPECT_EQ(acd->codecs()[0].name, offered_audio_codec.name); | 762 EXPECT_EQ(acd->codecs()[0].name, offered_audio_codec.name); |
| 638 EXPECT_EQ(dcd->codecs()[0].name, offered_data_codec.name); | 763 EXPECT_EQ(dcd->codecs()[0].name, offered_data_codec.name); |
| 639 } | 764 } |
| 640 | 765 |
| 641 // Test creating an updated offer with with bundle, audio, video and data | 766 // Test creating an updated offer with with bundle, audio, video and data |
| 642 // after an audio only session has been negotiated. | 767 // after an audio only session has been negotiated. |
| 643 TEST_F(MediaSessionDescriptionFactoryTest, | 768 TEST_F(MediaSessionDescriptionFactoryTest, |
| 644 TestCreateUpdatedVideoOfferWithBundle) { | 769 TestCreateUpdatedVideoOfferWithBundle) { |
| 645 f1_.set_secure(SEC_ENABLED); | 770 f1_.set_secure(SEC_ENABLED); |
| 646 f2_.set_secure(SEC_ENABLED); | 771 f2_.set_secure(SEC_ENABLED); |
| 647 MediaSessionOptions opts; | 772 MediaSessionOptions opts; |
| 648 opts.recv_audio = true; | 773 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 649 opts.recv_video = false; | 774 &opts); |
| 775 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_INACTIVE, kStopped, | |
| 776 &opts); | |
| 650 opts.data_channel_type = cricket::DCT_NONE; | 777 opts.data_channel_type = cricket::DCT_NONE; |
| 651 opts.bundle_enabled = true; | 778 opts.bundle_enabled = true; |
| 652 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 779 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 653 std::unique_ptr<SessionDescription> answer( | 780 std::unique_ptr<SessionDescription> answer( |
| 654 f2_.CreateAnswer(offer.get(), opts, NULL)); | 781 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 655 | 782 |
| 656 MediaSessionOptions updated_opts; | 783 MediaSessionOptions updated_opts; |
| 657 updated_opts.recv_audio = true; | 784 AddAudioVideoSections(cricket::MD_RECVONLY, &updated_opts); |
| 658 updated_opts.recv_video = true; | 785 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &updated_opts); |
| 659 updated_opts.data_channel_type = cricket::DCT_RTP; | |
| 660 updated_opts.bundle_enabled = true; | 786 updated_opts.bundle_enabled = true; |
| 661 std::unique_ptr<SessionDescription> updated_offer( | 787 std::unique_ptr<SessionDescription> updated_offer( |
| 662 f1_.CreateOffer(updated_opts, answer.get())); | 788 f1_.CreateOffer(updated_opts, answer.get())); |
| 663 | 789 |
| 664 const AudioContentDescription* acd = | 790 const AudioContentDescription* acd = |
| 665 GetFirstAudioContentDescription(updated_offer.get()); | 791 GetFirstAudioContentDescription(updated_offer.get()); |
| 666 const VideoContentDescription* vcd = | 792 const VideoContentDescription* vcd = |
| 667 GetFirstVideoContentDescription(updated_offer.get()); | 793 GetFirstVideoContentDescription(updated_offer.get()); |
| 668 const DataContentDescription* dcd = | 794 const DataContentDescription* dcd = |
| 669 GetFirstDataContentDescription(updated_offer.get()); | 795 GetFirstDataContentDescription(updated_offer.get()); |
| 670 EXPECT_TRUE(NULL != vcd); | 796 EXPECT_TRUE(NULL != vcd); |
| 671 EXPECT_TRUE(NULL != acd); | 797 EXPECT_TRUE(NULL != acd); |
| 672 EXPECT_TRUE(NULL != dcd); | 798 EXPECT_TRUE(NULL != dcd); |
| 673 | 799 |
| 674 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 800 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 675 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 801 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 676 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 802 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 677 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 803 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 678 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 804 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 679 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); | 805 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); |
| 680 } | 806 } |
| 681 | 807 |
| 682 // Create a RTP data offer, and ensure it matches what we expect. | 808 // Create a RTP data offer, and ensure it matches what we expect. |
| 683 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateRtpDataOffer) { | 809 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateRtpDataOffer) { |
| 684 MediaSessionOptions opts; | 810 MediaSessionOptions opts; |
| 685 opts.data_channel_type = cricket::DCT_RTP; | 811 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 812 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); | |
| 686 f1_.set_secure(SEC_ENABLED); | 813 f1_.set_secure(SEC_ENABLED); |
| 687 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 814 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 688 ASSERT_TRUE(offer.get() != NULL); | 815 ASSERT_TRUE(offer.get() != NULL); |
| 689 const ContentInfo* ac = offer->GetContentByName("audio"); | 816 const ContentInfo* ac = offer->GetContentByName("audio"); |
| 690 const ContentInfo* dc = offer->GetContentByName("data"); | 817 const ContentInfo* dc = offer->GetContentByName("data"); |
| 691 ASSERT_TRUE(ac != NULL); | 818 ASSERT_TRUE(ac != NULL); |
| 692 ASSERT_TRUE(dc != NULL); | 819 ASSERT_TRUE(dc != NULL); |
| 693 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 820 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 694 EXPECT_EQ(std::string(NS_JINGLE_RTP), dc->type); | 821 EXPECT_EQ(std::string(NS_JINGLE_RTP), dc->type); |
| 695 const AudioContentDescription* acd = | 822 const AudioContentDescription* acd = |
| 696 static_cast<const AudioContentDescription*>(ac->description); | 823 static_cast<const AudioContentDescription*>(ac->description); |
| 697 const DataContentDescription* dcd = | 824 const DataContentDescription* dcd = |
| 698 static_cast<const DataContentDescription*>(dc->description); | 825 static_cast<const DataContentDescription*>(dc->description); |
| 699 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 826 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 700 EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); | 827 EXPECT_EQ(f1_.audio_sendrecv_codecs(), acd->codecs()); |
| 701 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 828 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attched. |
| 702 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) | 829 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // default bandwidth (auto) |
| 703 EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on | 830 EXPECT_TRUE(acd->rtcp_mux()); // rtcp-mux defaults on |
| 704 ASSERT_CRYPTO(acd, 2U, CS_AES_CM_128_HMAC_SHA1_32); | 831 ASSERT_CRYPTO(acd, 2U, CS_AES_CM_128_HMAC_SHA1_32); |
| 705 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 832 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 706 EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); | 833 EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
| 707 EXPECT_EQ(f1_.data_codecs(), dcd->codecs()); | 834 EXPECT_EQ(f1_.data_codecs(), dcd->codecs()); |
| 708 EXPECT_NE(0U, dcd->first_ssrc()); // a random nonzero ssrc | 835 EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached. |
| 709 EXPECT_EQ(cricket::kDataMaxBandwidth, | 836 EXPECT_EQ(cricket::kDataMaxBandwidth, |
| 710 dcd->bandwidth()); // default bandwidth (auto) | 837 dcd->bandwidth()); // default bandwidth (auto) |
| 711 EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on | 838 EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
| 712 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 839 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 713 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); | 840 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); |
| 714 } | 841 } |
| 715 | 842 |
| 716 // Create an SCTP data offer with bundle without error. | 843 // Create an SCTP data offer with bundle without error. |
| 717 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { | 844 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSctpDataOffer) { |
| 718 MediaSessionOptions opts; | 845 MediaSessionOptions opts; |
| 719 opts.recv_audio = false; | |
| 720 opts.bundle_enabled = true; | 846 opts.bundle_enabled = true; |
| 721 opts.data_channel_type = cricket::DCT_SCTP; | 847 AddDataSection(cricket::DCT_SCTP, cricket::MD_SENDRECV, &opts); |
| 722 f1_.set_secure(SEC_ENABLED); | 848 f1_.set_secure(SEC_ENABLED); |
| 723 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 849 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 724 EXPECT_TRUE(offer.get() != NULL); | 850 EXPECT_TRUE(offer.get() != NULL); |
| 725 EXPECT_TRUE(offer->GetContentByName("data") != NULL); | 851 EXPECT_TRUE(offer->GetContentByName("data") != NULL); |
| 726 } | 852 } |
| 727 | 853 |
| 728 // Test creating an sctp data channel from an already generated offer. | 854 // Test creating an sctp data channel from an already generated offer. |
| 729 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { | 855 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateImplicitSctpDataOffer) { |
| 730 MediaSessionOptions opts; | 856 MediaSessionOptions opts; |
| 731 opts.recv_audio = false; | |
| 732 opts.bundle_enabled = true; | 857 opts.bundle_enabled = true; |
| 733 opts.data_channel_type = cricket::DCT_SCTP; | 858 AddDataSection(cricket::DCT_SCTP, cricket::MD_SENDRECV, &opts); |
| 734 f1_.set_secure(SEC_ENABLED); | 859 f1_.set_secure(SEC_ENABLED); |
| 735 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); | 860 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
| 736 ASSERT_TRUE(offer1.get() != NULL); | 861 ASSERT_TRUE(offer1.get() != NULL); |
| 737 const ContentInfo* data = offer1->GetContentByName("data"); | 862 const ContentInfo* data = offer1->GetContentByName("data"); |
| 738 ASSERT_TRUE(data != NULL); | 863 ASSERT_TRUE(data != NULL); |
| 739 const MediaContentDescription* mdesc = | 864 const MediaContentDescription* mdesc = |
| 740 static_cast<const MediaContentDescription*>(data->description); | 865 static_cast<const MediaContentDescription*>(data->description); |
| 741 ASSERT_EQ(cricket::kMediaProtocolSctp, mdesc->protocol()); | 866 ASSERT_EQ(cricket::kMediaProtocolSctp, mdesc->protocol()); |
| 742 | 867 |
| 743 // Now set data_channel_type to 'none' (default) and make sure that the | 868 // Now set data_channel_type to 'none' (default) and make sure that the |
| 744 // datachannel type that gets generated from the previous offer, is of the | 869 // datachannel type that gets generated from the previous offer, is of the |
| 745 // same type. | 870 // same type. |
| 746 opts.data_channel_type = cricket::DCT_NONE; | 871 opts.data_channel_type = cricket::DCT_NONE; |
| 747 std::unique_ptr<SessionDescription> offer2( | 872 std::unique_ptr<SessionDescription> offer2( |
| 748 f1_.CreateOffer(opts, offer1.get())); | 873 f1_.CreateOffer(opts, offer1.get())); |
| 749 data = offer2->GetContentByName("data"); | 874 data = offer2->GetContentByName("data"); |
| 750 ASSERT_TRUE(data != NULL); | 875 ASSERT_TRUE(data != NULL); |
| 751 mdesc = static_cast<const MediaContentDescription*>(data->description); | 876 mdesc = static_cast<const MediaContentDescription*>(data->description); |
| 752 EXPECT_EQ(cricket::kMediaProtocolSctp, mdesc->protocol()); | 877 EXPECT_EQ(cricket::kMediaProtocolSctp, mdesc->protocol()); |
| 753 } | 878 } |
| 754 | 879 |
| 755 // Create an audio, video offer without legacy StreamParams. | 880 // Create an audio, video offer without legacy StreamParams. |
| 756 TEST_F(MediaSessionDescriptionFactoryTest, | 881 TEST_F(MediaSessionDescriptionFactoryTest, |
| 757 TestCreateOfferWithoutLegacyStreams) { | 882 TestCreateOfferWithoutLegacyStreams) { |
| 758 MediaSessionOptions opts; | 883 MediaSessionOptions opts; |
| 759 opts.recv_video = true; | 884 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 760 f1_.set_add_legacy_streams(false); | |
| 761 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 885 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 762 ASSERT_TRUE(offer.get() != NULL); | 886 ASSERT_TRUE(offer.get() != NULL); |
| 763 const ContentInfo* ac = offer->GetContentByName("audio"); | 887 const ContentInfo* ac = offer->GetContentByName("audio"); |
| 764 const ContentInfo* vc = offer->GetContentByName("video"); | 888 const ContentInfo* vc = offer->GetContentByName("video"); |
| 765 ASSERT_TRUE(ac != NULL); | 889 ASSERT_TRUE(ac != NULL); |
| 766 ASSERT_TRUE(vc != NULL); | 890 ASSERT_TRUE(vc != NULL); |
| 767 const AudioContentDescription* acd = | 891 const AudioContentDescription* acd = |
| 768 static_cast<const AudioContentDescription*>(ac->description); | 892 static_cast<const AudioContentDescription*>(ac->description); |
| 769 const VideoContentDescription* vcd = | 893 const VideoContentDescription* vcd = |
| 770 static_cast<const VideoContentDescription*>(vc->description); | 894 static_cast<const VideoContentDescription*>(vc->description); |
| 771 | 895 |
| 772 EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. | 896 EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 773 EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. | 897 EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
| 774 } | 898 } |
| 775 | 899 |
| 776 // Creates an audio+video sendonly offer. | 900 // Creates an audio+video sendonly offer. |
| 777 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSendOnlyOffer) { | 901 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSendOnlyOffer) { |
| 778 MediaSessionOptions options; | 902 MediaSessionOptions opts; |
| 779 options.recv_audio = false; | 903 AddAudioVideoSections(cricket::MD_SENDONLY, &opts); |
| 780 options.recv_video = false; | 904 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 781 options.AddSendStream(MEDIA_TYPE_VIDEO, kVideoTrack1, kMediaStream1); | 905 kMediaStream1, 1, &opts); |
| 782 options.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | 906 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 907 kMediaStream1, 1, &opts); | |
| 783 | 908 |
| 784 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(options, NULL)); | 909 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 785 ASSERT_TRUE(offer.get() != NULL); | 910 ASSERT_TRUE(offer.get() != NULL); |
| 786 EXPECT_EQ(2u, offer->contents().size()); | 911 EXPECT_EQ(2u, offer->contents().size()); |
| 787 EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[0], MEDIA_TYPE_AUDIO)); | 912 EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[0], MEDIA_TYPE_AUDIO)); |
| 788 EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[1], MEDIA_TYPE_VIDEO)); | 913 EXPECT_TRUE(IsMediaContentOfType(&offer->contents()[1], MEDIA_TYPE_VIDEO)); |
| 789 | 914 |
| 790 EXPECT_EQ(cricket::MD_SENDONLY, GetMediaDirection(&offer->contents()[0])); | 915 EXPECT_EQ(cricket::MD_SENDONLY, GetMediaDirection(&offer->contents()[0])); |
| 791 EXPECT_EQ(cricket::MD_SENDONLY, GetMediaDirection(&offer->contents()[1])); | 916 EXPECT_EQ(cricket::MD_SENDONLY, GetMediaDirection(&offer->contents()[1])); |
| 792 } | 917 } |
| 793 | 918 |
| 794 // Verifies that the order of the media contents in the current | 919 // Verifies that the order of the media contents in the current |
| 795 // SessionDescription is preserved in the new SessionDescription. | 920 // SessionDescription is preserved in the new SessionDescription. |
| 796 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { | 921 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateOfferContentOrder) { |
| 797 MediaSessionOptions opts; | 922 MediaSessionOptions opts; |
| 798 opts.recv_audio = false; | 923 AddDataSection(cricket::DCT_SCTP, cricket::MD_SENDRECV, &opts); |
| 799 opts.recv_video = false; | |
| 800 opts.data_channel_type = cricket::DCT_SCTP; | |
| 801 | 924 |
| 802 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); | 925 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
| 803 ASSERT_TRUE(offer1.get() != NULL); | 926 ASSERT_TRUE(offer1.get() != NULL); |
| 804 EXPECT_EQ(1u, offer1->contents().size()); | 927 EXPECT_EQ(1u, offer1->contents().size()); |
| 805 EXPECT_TRUE(IsMediaContentOfType(&offer1->contents()[0], MEDIA_TYPE_DATA)); | 928 EXPECT_TRUE(IsMediaContentOfType(&offer1->contents()[0], MEDIA_TYPE_DATA)); |
| 806 | 929 |
| 807 opts.recv_video = true; | 930 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_RECVONLY, !kStopped, |
| 931 &opts); | |
| 808 std::unique_ptr<SessionDescription> offer2( | 932 std::unique_ptr<SessionDescription> offer2( |
| 809 f1_.CreateOffer(opts, offer1.get())); | 933 f1_.CreateOffer(opts, offer1.get())); |
| 810 ASSERT_TRUE(offer2.get() != NULL); | 934 ASSERT_TRUE(offer2.get() != NULL); |
| 811 EXPECT_EQ(2u, offer2->contents().size()); | 935 EXPECT_EQ(2u, offer2->contents().size()); |
| 812 EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[0], MEDIA_TYPE_DATA)); | 936 EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[0], MEDIA_TYPE_DATA)); |
| 813 EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[1], MEDIA_TYPE_VIDEO)); | 937 EXPECT_TRUE(IsMediaContentOfType(&offer2->contents()[1], MEDIA_TYPE_VIDEO)); |
| 814 | 938 |
| 815 opts.recv_audio = true; | 939 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 940 &opts); | |
| 816 std::unique_ptr<SessionDescription> offer3( | 941 std::unique_ptr<SessionDescription> offer3( |
| 817 f1_.CreateOffer(opts, offer2.get())); | 942 f1_.CreateOffer(opts, offer2.get())); |
| 818 ASSERT_TRUE(offer3.get() != NULL); | 943 ASSERT_TRUE(offer3.get() != NULL); |
| 819 EXPECT_EQ(3u, offer3->contents().size()); | 944 EXPECT_EQ(3u, offer3->contents().size()); |
| 820 EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[0], MEDIA_TYPE_DATA)); | 945 EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[0], MEDIA_TYPE_DATA)); |
| 821 EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[1], MEDIA_TYPE_VIDEO)); | 946 EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[1], MEDIA_TYPE_VIDEO)); |
| 822 EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[2], MEDIA_TYPE_AUDIO)); | 947 EXPECT_TRUE(IsMediaContentOfType(&offer3->contents()[2], MEDIA_TYPE_AUDIO)); |
| 823 | |
| 824 // Verifies the default order is audio-video-data, so that the previous checks | |
| 825 // didn't pass by accident. | |
| 826 std::unique_ptr<SessionDescription> offer4(f1_.CreateOffer(opts, NULL)); | |
| 827 ASSERT_TRUE(offer4.get() != NULL); | |
| 828 EXPECT_EQ(3u, offer4->contents().size()); | |
| 829 EXPECT_TRUE(IsMediaContentOfType(&offer4->contents()[0], MEDIA_TYPE_AUDIO)); | |
| 830 EXPECT_TRUE(IsMediaContentOfType(&offer4->contents()[1], MEDIA_TYPE_VIDEO)); | |
| 831 EXPECT_TRUE(IsMediaContentOfType(&offer4->contents()[2], MEDIA_TYPE_DATA)); | |
| 832 } | 948 } |
| 833 | 949 |
| 834 // Create a typical audio answer, and ensure it matches what we expect. | 950 // Create a typical audio answer, and ensure it matches what we expect. |
| 835 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswer) { | 951 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswer) { |
| 836 f1_.set_secure(SEC_ENABLED); | 952 f1_.set_secure(SEC_ENABLED); |
| 837 f2_.set_secure(SEC_ENABLED); | 953 f2_.set_secure(SEC_ENABLED); |
| 838 std::unique_ptr<SessionDescription> offer( | 954 std::unique_ptr<SessionDescription> offer( |
| 839 f1_.CreateOffer(MediaSessionOptions(), NULL)); | 955 f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL)); |
| 840 ASSERT_TRUE(offer.get() != NULL); | 956 ASSERT_TRUE(offer.get() != NULL); |
| 841 std::unique_ptr<SessionDescription> answer( | 957 std::unique_ptr<SessionDescription> answer( |
| 842 f2_.CreateAnswer(offer.get(), MediaSessionOptions(), NULL)); | 958 f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL)); |
| 843 const ContentInfo* ac = answer->GetContentByName("audio"); | 959 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 844 const ContentInfo* vc = answer->GetContentByName("video"); | 960 const ContentInfo* vc = answer->GetContentByName("video"); |
| 845 ASSERT_TRUE(ac != NULL); | 961 ASSERT_TRUE(ac != NULL); |
| 846 ASSERT_TRUE(vc == NULL); | 962 ASSERT_TRUE(vc == NULL); |
| 847 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 963 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 848 const AudioContentDescription* acd = | 964 const AudioContentDescription* acd = |
| 849 static_cast<const AudioContentDescription*>(ac->description); | 965 static_cast<const AudioContentDescription*>(ac->description); |
| 850 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 966 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 851 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 967 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 852 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 968 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 853 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 969 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 854 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 970 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 855 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 971 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 856 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 972 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 857 } | 973 } |
| 858 | 974 |
| 859 // Create a typical audio answer with GCM ciphers enabled, and ensure it | 975 // Create a typical audio answer with GCM ciphers enabled, and ensure it |
| 860 // matches what we expect. | 976 // matches what we expect. |
| 861 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { | 977 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerGcm) { |
| 862 f1_.set_secure(SEC_ENABLED); | 978 f1_.set_secure(SEC_ENABLED); |
| 863 f2_.set_secure(SEC_ENABLED); | 979 f2_.set_secure(SEC_ENABLED); |
| 864 MediaSessionOptions options; | 980 MediaSessionOptions opts; |
| 865 options.crypto_options.enable_gcm_crypto_suites = true; | 981 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, kStopped, |
|
Taylor Brandstetter
2017/08/05 00:39:09
Meant to be "!kStopped"? Could also use CreatePlan
Zhi Huang
2017/08/09 00:54:50
Done.
| |
| 866 std::unique_ptr<SessionDescription> offer( | 982 &opts); |
| 867 f1_.CreateOffer(options, NULL)); | 983 opts.crypto_options.enable_gcm_crypto_suites = true; |
| 984 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | |
| 868 ASSERT_TRUE(offer.get() != NULL); | 985 ASSERT_TRUE(offer.get() != NULL); |
| 869 std::unique_ptr<SessionDescription> answer( | 986 std::unique_ptr<SessionDescription> answer( |
| 870 f2_.CreateAnswer(offer.get(), options, NULL)); | 987 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 871 const ContentInfo* ac = answer->GetContentByName("audio"); | 988 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 872 const ContentInfo* vc = answer->GetContentByName("video"); | 989 const ContentInfo* vc = answer->GetContentByName("video"); |
| 873 ASSERT_TRUE(ac != NULL); | 990 ASSERT_TRUE(ac != NULL); |
| 874 ASSERT_TRUE(vc == NULL); | 991 ASSERT_TRUE(vc == NULL); |
| 875 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 992 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 876 const AudioContentDescription* acd = | 993 const AudioContentDescription* acd = |
| 877 static_cast<const AudioContentDescription*>(ac->description); | 994 static_cast<const AudioContentDescription*>(ac->description); |
| 878 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 995 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 879 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 996 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 880 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 997 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 881 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 998 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 882 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 999 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 883 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); | 1000 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 884 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); | 1001 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), acd->protocol()); |
| 885 } | 1002 } |
| 886 | 1003 |
| 887 // Create a typical video answer, and ensure it matches what we expect. | 1004 // Create a typical video answer, and ensure it matches what we expect. |
| 888 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { | 1005 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswer) { |
| 889 MediaSessionOptions opts; | 1006 MediaSessionOptions opts; |
| 890 opts.recv_video = true; | 1007 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 891 f1_.set_secure(SEC_ENABLED); | 1008 f1_.set_secure(SEC_ENABLED); |
| 892 f2_.set_secure(SEC_ENABLED); | 1009 f2_.set_secure(SEC_ENABLED); |
| 893 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1010 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 894 ASSERT_TRUE(offer.get() != NULL); | 1011 ASSERT_TRUE(offer.get() != NULL); |
| 895 std::unique_ptr<SessionDescription> answer( | 1012 std::unique_ptr<SessionDescription> answer( |
| 896 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1013 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 897 const ContentInfo* ac = answer->GetContentByName("audio"); | 1014 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 898 const ContentInfo* vc = answer->GetContentByName("video"); | 1015 const ContentInfo* vc = answer->GetContentByName("video"); |
| 899 ASSERT_TRUE(ac != NULL); | 1016 ASSERT_TRUE(ac != NULL); |
| 900 ASSERT_TRUE(vc != NULL); | 1017 ASSERT_TRUE(vc != NULL); |
| 901 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 1018 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 902 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); | 1019 EXPECT_EQ(std::string(NS_JINGLE_RTP), vc->type); |
| 903 const AudioContentDescription* acd = | 1020 const AudioContentDescription* acd = |
| 904 static_cast<const AudioContentDescription*>(ac->description); | 1021 static_cast<const AudioContentDescription*>(ac->description); |
| 905 const VideoContentDescription* vcd = | 1022 const VideoContentDescription* vcd = |
| 906 static_cast<const VideoContentDescription*>(vc->description); | 1023 static_cast<const VideoContentDescription*>(vc->description); |
| 907 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 1024 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 908 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 1025 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 909 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 1026 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 910 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 1027 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 911 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 1028 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 912 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 1029 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 913 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); | 1030 EXPECT_EQ(MEDIA_TYPE_VIDEO, vcd->type()); |
| 914 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); | 1031 EXPECT_EQ(MAKE_VECTOR(kVideoCodecsAnswer), vcd->codecs()); |
| 915 EXPECT_NE(0U, vcd->first_ssrc()); // a random nonzero ssrc | 1032 EXPECT_EQ(0U, vcd->first_ssrc()); // no sender is attached |
| 916 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux | 1033 EXPECT_TRUE(vcd->rtcp_mux()); // negotiated rtcp-mux |
| 917 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 1034 ASSERT_CRYPTO(vcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 918 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); | 1035 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), vcd->protocol()); |
| 919 } | 1036 } |
| 920 | 1037 |
| 921 // Create a typical video answer with GCM ciphers enabled, and ensure it | 1038 // Create a typical video answer with GCM ciphers enabled, and ensure it |
| 922 // matches what we expect. | 1039 // matches what we expect. |
| 923 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcm) { | 1040 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcm) { |
| 924 TestVideoGcmCipher(true, true); | 1041 TestVideoGcmCipher(true, true); |
| 925 } | 1042 } |
| 926 | 1043 |
| 927 // Create a typical video answer with GCM ciphers enabled for the offer only, | 1044 // Create a typical video answer with GCM ciphers enabled for the offer only, |
| 928 // and ensure it matches what we expect. | 1045 // and ensure it matches what we expect. |
| 929 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmOffer) { | 1046 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmOffer) { |
| 930 TestVideoGcmCipher(true, false); | 1047 TestVideoGcmCipher(true, false); |
| 931 } | 1048 } |
| 932 | 1049 |
| 933 // Create a typical video answer with GCM ciphers enabled for the answer only, | 1050 // Create a typical video answer with GCM ciphers enabled for the answer only, |
| 934 // and ensure it matches what we expect. | 1051 // and ensure it matches what we expect. |
| 935 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmAnswer) { | 1052 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerGcmAnswer) { |
| 936 TestVideoGcmCipher(false, true); | 1053 TestVideoGcmCipher(false, true); |
| 937 } | 1054 } |
| 938 | 1055 |
| 939 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { | 1056 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswer) { |
| 940 MediaSessionOptions opts; | 1057 MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
| 941 opts.data_channel_type = cricket::DCT_RTP; | 1058 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); |
| 942 f1_.set_secure(SEC_ENABLED); | 1059 f1_.set_secure(SEC_ENABLED); |
| 943 f2_.set_secure(SEC_ENABLED); | 1060 f2_.set_secure(SEC_ENABLED); |
| 944 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1061 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 945 ASSERT_TRUE(offer.get() != NULL); | 1062 ASSERT_TRUE(offer.get() != NULL); |
| 946 std::unique_ptr<SessionDescription> answer( | 1063 std::unique_ptr<SessionDescription> answer( |
| 947 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1064 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 948 const ContentInfo* ac = answer->GetContentByName("audio"); | 1065 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 949 const ContentInfo* dc = answer->GetContentByName("data"); | 1066 const ContentInfo* dc = answer->GetContentByName("data"); |
| 950 ASSERT_TRUE(ac != NULL); | 1067 ASSERT_TRUE(ac != NULL); |
| 951 ASSERT_TRUE(dc != NULL); | 1068 ASSERT_TRUE(dc != NULL); |
| 952 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 1069 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 953 EXPECT_EQ(std::string(NS_JINGLE_RTP), dc->type); | 1070 EXPECT_EQ(std::string(NS_JINGLE_RTP), dc->type); |
| 954 const AudioContentDescription* acd = | 1071 const AudioContentDescription* acd = |
| 955 static_cast<const AudioContentDescription*>(ac->description); | 1072 static_cast<const AudioContentDescription*>(ac->description); |
| 956 const DataContentDescription* dcd = | 1073 const DataContentDescription* dcd = |
| 957 static_cast<const DataContentDescription*>(dc->description); | 1074 static_cast<const DataContentDescription*>(dc->description); |
| 958 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 1075 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 959 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 1076 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 960 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 1077 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 961 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 1078 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 962 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 1079 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 963 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); | 1080 ASSERT_CRYPTO(acd, 1U, CS_AES_CM_128_HMAC_SHA1_32); |
| 964 EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); | 1081 EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
| 965 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), dcd->codecs()); | 1082 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), dcd->codecs()); |
| 966 EXPECT_NE(0U, dcd->first_ssrc()); // a random nonzero ssrc | 1083 EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
| 967 EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux | 1084 EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
| 968 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 1085 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 969 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); | 1086 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); |
| 970 } | 1087 } |
| 971 | 1088 |
| 972 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) { | 1089 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerGcm) { |
| 973 MediaSessionOptions opts; | 1090 MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
| 974 opts.data_channel_type = cricket::DCT_RTP; | 1091 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); |
| 975 opts.crypto_options.enable_gcm_crypto_suites = true; | 1092 opts.crypto_options.enable_gcm_crypto_suites = true; |
| 976 f1_.set_secure(SEC_ENABLED); | 1093 f1_.set_secure(SEC_ENABLED); |
| 977 f2_.set_secure(SEC_ENABLED); | 1094 f2_.set_secure(SEC_ENABLED); |
| 978 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1095 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 979 ASSERT_TRUE(offer.get() != NULL); | 1096 ASSERT_TRUE(offer.get() != NULL); |
| 980 std::unique_ptr<SessionDescription> answer( | 1097 std::unique_ptr<SessionDescription> answer( |
| 981 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1098 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 982 const ContentInfo* ac = answer->GetContentByName("audio"); | 1099 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 983 const ContentInfo* dc = answer->GetContentByName("data"); | 1100 const ContentInfo* dc = answer->GetContentByName("data"); |
| 984 ASSERT_TRUE(ac != NULL); | 1101 ASSERT_TRUE(ac != NULL); |
| 985 ASSERT_TRUE(dc != NULL); | 1102 ASSERT_TRUE(dc != NULL); |
| 986 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); | 1103 EXPECT_EQ(std::string(NS_JINGLE_RTP), ac->type); |
| 987 EXPECT_EQ(std::string(NS_JINGLE_RTP), dc->type); | 1104 EXPECT_EQ(std::string(NS_JINGLE_RTP), dc->type); |
| 988 const AudioContentDescription* acd = | 1105 const AudioContentDescription* acd = |
| 989 static_cast<const AudioContentDescription*>(ac->description); | 1106 static_cast<const AudioContentDescription*>(ac->description); |
| 990 const DataContentDescription* dcd = | 1107 const DataContentDescription* dcd = |
| 991 static_cast<const DataContentDescription*>(dc->description); | 1108 static_cast<const DataContentDescription*>(dc->description); |
| 992 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 1109 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 993 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 1110 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 994 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw | 1111 EXPECT_EQ(kAutoBandwidth, acd->bandwidth()); // negotiated auto bw |
| 995 EXPECT_NE(0U, acd->first_ssrc()); // a random nonzero ssrc | 1112 EXPECT_EQ(0U, acd->first_ssrc()); // no sender is attached |
| 996 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux | 1113 EXPECT_TRUE(acd->rtcp_mux()); // negotiated rtcp-mux |
| 997 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); | 1114 ASSERT_CRYPTO(acd, 1U, CS_AEAD_AES_256_GCM); |
| 998 EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); | 1115 EXPECT_EQ(MEDIA_TYPE_DATA, dcd->type()); |
| 999 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), dcd->codecs()); | 1116 EXPECT_EQ(MAKE_VECTOR(kDataCodecsAnswer), dcd->codecs()); |
| 1000 EXPECT_NE(0U, dcd->first_ssrc()); // a random nonzero ssrc | 1117 EXPECT_EQ(0U, dcd->first_ssrc()); // no sender is attached |
| 1001 EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux | 1118 EXPECT_TRUE(dcd->rtcp_mux()); // negotiated rtcp-mux |
| 1002 ASSERT_CRYPTO(dcd, 1U, CS_AEAD_AES_256_GCM); | 1119 ASSERT_CRYPTO(dcd, 1U, CS_AEAD_AES_256_GCM); |
| 1003 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); | 1120 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf), dcd->protocol()); |
| 1004 } | 1121 } |
| 1005 | 1122 |
| 1006 // The use_sctpmap flag should be set in a DataContentDescription by default. | 1123 // The use_sctpmap flag should be set in a DataContentDescription by default. |
| 1007 // The answer's use_sctpmap flag should match the offer's. | 1124 // The answer's use_sctpmap flag should match the offer's. |
| 1008 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { | 1125 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerUsesSctpmap) { |
| 1009 MediaSessionOptions opts; | 1126 MediaSessionOptions opts; |
| 1010 opts.data_channel_type = cricket::DCT_SCTP; | 1127 AddDataSection(cricket::DCT_SCTP, cricket::MD_SENDRECV, &opts); |
| 1011 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1128 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1012 ASSERT_TRUE(offer.get() != NULL); | 1129 ASSERT_TRUE(offer.get() != NULL); |
| 1013 ContentInfo* dc_offer = offer->GetContentByName("data"); | 1130 ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1014 ASSERT_TRUE(dc_offer != NULL); | 1131 ASSERT_TRUE(dc_offer != NULL); |
| 1015 DataContentDescription* dcd_offer = | 1132 DataContentDescription* dcd_offer = |
| 1016 static_cast<DataContentDescription*>(dc_offer->description); | 1133 static_cast<DataContentDescription*>(dc_offer->description); |
| 1017 EXPECT_TRUE(dcd_offer->use_sctpmap()); | 1134 EXPECT_TRUE(dcd_offer->use_sctpmap()); |
| 1018 | 1135 |
| 1019 std::unique_ptr<SessionDescription> answer( | 1136 std::unique_ptr<SessionDescription> answer( |
| 1020 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1137 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1021 const ContentInfo* dc_answer = answer->GetContentByName("data"); | 1138 const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1022 ASSERT_TRUE(dc_answer != NULL); | 1139 ASSERT_TRUE(dc_answer != NULL); |
| 1023 const DataContentDescription* dcd_answer = | 1140 const DataContentDescription* dcd_answer = |
| 1024 static_cast<const DataContentDescription*>(dc_answer->description); | 1141 static_cast<const DataContentDescription*>(dc_answer->description); |
| 1025 EXPECT_TRUE(dcd_answer->use_sctpmap()); | 1142 EXPECT_TRUE(dcd_answer->use_sctpmap()); |
| 1026 } | 1143 } |
| 1027 | 1144 |
| 1028 // The answer's use_sctpmap flag should match the offer's. | 1145 // The answer's use_sctpmap flag should match the offer's. |
| 1029 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerWithoutSctpmap) { | 1146 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateDataAnswerWithoutSctpmap) { |
| 1030 MediaSessionOptions opts; | 1147 MediaSessionOptions opts; |
| 1031 opts.data_channel_type = cricket::DCT_SCTP; | 1148 AddDataSection(cricket::DCT_SCTP, cricket::MD_SENDRECV, &opts); |
| 1032 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1149 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1033 ASSERT_TRUE(offer.get() != NULL); | 1150 ASSERT_TRUE(offer.get() != NULL); |
| 1034 ContentInfo* dc_offer = offer->GetContentByName("data"); | 1151 ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1035 ASSERT_TRUE(dc_offer != NULL); | 1152 ASSERT_TRUE(dc_offer != NULL); |
| 1036 DataContentDescription* dcd_offer = | 1153 DataContentDescription* dcd_offer = |
| 1037 static_cast<DataContentDescription*>(dc_offer->description); | 1154 static_cast<DataContentDescription*>(dc_offer->description); |
| 1038 dcd_offer->set_use_sctpmap(false); | 1155 dcd_offer->set_use_sctpmap(false); |
| 1039 | 1156 |
| 1040 std::unique_ptr<SessionDescription> answer( | 1157 std::unique_ptr<SessionDescription> answer( |
| 1041 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1158 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1042 const ContentInfo* dc_answer = answer->GetContentByName("data"); | 1159 const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1043 ASSERT_TRUE(dc_answer != NULL); | 1160 ASSERT_TRUE(dc_answer != NULL); |
| 1044 const DataContentDescription* dcd_answer = | 1161 const DataContentDescription* dcd_answer = |
| 1045 static_cast<const DataContentDescription*>(dc_answer->description); | 1162 static_cast<const DataContentDescription*>(dc_answer->description); |
| 1046 EXPECT_FALSE(dcd_answer->use_sctpmap()); | 1163 EXPECT_FALSE(dcd_answer->use_sctpmap()); |
| 1047 } | 1164 } |
| 1048 | 1165 |
| 1049 // Test that a valid answer will be created for "DTLS/SCTP", "UDP/DTLS/SCTP" | 1166 // Test that a valid answer will be created for "DTLS/SCTP", "UDP/DTLS/SCTP" |
| 1050 // and "TCP/DTLS/SCTP" offers. | 1167 // and "TCP/DTLS/SCTP" offers. |
| 1051 TEST_F(MediaSessionDescriptionFactoryTest, | 1168 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1052 TestCreateDataAnswerToDifferentOfferedProtos) { | 1169 TestCreateDataAnswerToDifferentOfferedProtos) { |
| 1053 // Need to enable DTLS offer/answer generation (disabled by default in this | 1170 // Need to enable DTLS offer/answer generation (disabled by default in this |
| 1054 // test). | 1171 // test). |
| 1055 f1_.set_secure(SEC_ENABLED); | 1172 f1_.set_secure(SEC_ENABLED); |
| 1056 f2_.set_secure(SEC_ENABLED); | 1173 f2_.set_secure(SEC_ENABLED); |
| 1057 tdf1_.set_secure(SEC_ENABLED); | 1174 tdf1_.set_secure(SEC_ENABLED); |
| 1058 tdf2_.set_secure(SEC_ENABLED); | 1175 tdf2_.set_secure(SEC_ENABLED); |
| 1059 | 1176 |
| 1060 MediaSessionOptions opts; | 1177 MediaSessionOptions opts; |
| 1061 opts.data_channel_type = cricket::DCT_SCTP; | 1178 AddDataSection(cricket::DCT_SCTP, cricket::MD_SENDRECV, &opts); |
| 1062 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | 1179 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); |
| 1063 ASSERT_TRUE(offer.get() != nullptr); | 1180 ASSERT_TRUE(offer.get() != nullptr); |
| 1064 ContentInfo* dc_offer = offer->GetContentByName("data"); | 1181 ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1065 ASSERT_TRUE(dc_offer != nullptr); | 1182 ASSERT_TRUE(dc_offer != nullptr); |
| 1066 DataContentDescription* dcd_offer = | 1183 DataContentDescription* dcd_offer = |
| 1067 static_cast<DataContentDescription*>(dc_offer->description); | 1184 static_cast<DataContentDescription*>(dc_offer->description); |
| 1068 | 1185 |
| 1069 std::vector<std::string> protos = {"DTLS/SCTP", "UDP/DTLS/SCTP", | 1186 std::vector<std::string> protos = {"DTLS/SCTP", "UDP/DTLS/SCTP", |
| 1070 "TCP/DTLS/SCTP"}; | 1187 "TCP/DTLS/SCTP"}; |
| 1071 for (const std::string& proto : protos) { | 1188 for (const std::string& proto : protos) { |
| 1072 dcd_offer->set_protocol(proto); | 1189 dcd_offer->set_protocol(proto); |
| 1073 std::unique_ptr<SessionDescription> answer( | 1190 std::unique_ptr<SessionDescription> answer( |
| 1074 f2_.CreateAnswer(offer.get(), opts, nullptr)); | 1191 f2_.CreateAnswer(offer.get(), opts, nullptr)); |
| 1075 const ContentInfo* dc_answer = answer->GetContentByName("data"); | 1192 const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1076 ASSERT_TRUE(dc_answer != nullptr); | 1193 ASSERT_TRUE(dc_answer != nullptr); |
| 1077 const DataContentDescription* dcd_answer = | 1194 const DataContentDescription* dcd_answer = |
| 1078 static_cast<const DataContentDescription*>(dc_answer->description); | 1195 static_cast<const DataContentDescription*>(dc_answer->description); |
| 1079 EXPECT_FALSE(dc_answer->rejected); | 1196 EXPECT_FALSE(dc_answer->rejected); |
| 1080 EXPECT_EQ(proto, dcd_answer->protocol()); | 1197 EXPECT_EQ(proto, dcd_answer->protocol()); |
| 1081 } | 1198 } |
| 1082 } | 1199 } |
| 1083 | 1200 |
| 1084 // Verifies that the order of the media contents in the offer is preserved in | 1201 // Verifies that the order of the media contents in the offer is preserved in |
| 1085 // the answer. | 1202 // the answer. |
| 1086 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { | 1203 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAnswerContentOrder) { |
| 1087 MediaSessionOptions opts; | 1204 MediaSessionOptions opts; |
| 1088 | 1205 |
| 1089 // Creates a data only offer. | 1206 // Creates a data only offer. |
| 1090 opts.recv_audio = false; | 1207 AddDataSection(cricket::DCT_SCTP, cricket::MD_SENDRECV, &opts); |
| 1091 opts.data_channel_type = cricket::DCT_SCTP; | |
| 1092 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); | 1208 std::unique_ptr<SessionDescription> offer1(f1_.CreateOffer(opts, NULL)); |
| 1093 ASSERT_TRUE(offer1.get() != NULL); | 1209 ASSERT_TRUE(offer1.get() != NULL); |
| 1094 | 1210 |
| 1095 // Appends audio to the offer. | 1211 // Appends audio to the offer. |
| 1096 opts.recv_audio = true; | 1212 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 1213 &opts); | |
| 1097 std::unique_ptr<SessionDescription> offer2( | 1214 std::unique_ptr<SessionDescription> offer2( |
| 1098 f1_.CreateOffer(opts, offer1.get())); | 1215 f1_.CreateOffer(opts, offer1.get())); |
| 1099 ASSERT_TRUE(offer2.get() != NULL); | 1216 ASSERT_TRUE(offer2.get() != NULL); |
| 1100 | 1217 |
| 1101 // Appends video to the offer. | 1218 // Appends video to the offer. |
| 1102 opts.recv_video = true; | 1219 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_RECVONLY, !kStopped, |
| 1220 &opts); | |
| 1103 std::unique_ptr<SessionDescription> offer3( | 1221 std::unique_ptr<SessionDescription> offer3( |
| 1104 f1_.CreateOffer(opts, offer2.get())); | 1222 f1_.CreateOffer(opts, offer2.get())); |
| 1105 ASSERT_TRUE(offer3.get() != NULL); | 1223 ASSERT_TRUE(offer3.get() != NULL); |
| 1106 | 1224 |
| 1107 std::unique_ptr<SessionDescription> answer( | 1225 std::unique_ptr<SessionDescription> answer( |
| 1108 f2_.CreateAnswer(offer3.get(), opts, NULL)); | 1226 f2_.CreateAnswer(offer3.get(), opts, NULL)); |
| 1109 ASSERT_TRUE(answer.get() != NULL); | 1227 ASSERT_TRUE(answer.get() != NULL); |
| 1110 EXPECT_EQ(3u, answer->contents().size()); | 1228 EXPECT_EQ(3u, answer->contents().size()); |
| 1111 EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[0], MEDIA_TYPE_DATA)); | 1229 EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[0], MEDIA_TYPE_DATA)); |
| 1112 EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[1], MEDIA_TYPE_AUDIO)); | 1230 EXPECT_TRUE(IsMediaContentOfType(&answer->contents()[1], MEDIA_TYPE_AUDIO)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1137 // This test that the media direction is set to inactive in an answer if | 1255 // This test that the media direction is set to inactive in an answer if |
| 1138 // the offer is inactive. | 1256 // the offer is inactive. |
| 1139 TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToInactiveOffer) { | 1257 TEST_F(MediaSessionDescriptionFactoryTest, CreateAnswerToInactiveOffer) { |
| 1140 TestMediaDirectionInAnswer(cricket::MD_INACTIVE, cricket::MD_INACTIVE); | 1258 TestMediaDirectionInAnswer(cricket::MD_INACTIVE, cricket::MD_INACTIVE); |
| 1141 } | 1259 } |
| 1142 | 1260 |
| 1143 // Test that a data content with an unknown protocol is rejected in an answer. | 1261 // Test that a data content with an unknown protocol is rejected in an answer. |
| 1144 TEST_F(MediaSessionDescriptionFactoryTest, | 1262 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1145 CreateDataAnswerToOfferWithUnknownProtocol) { | 1263 CreateDataAnswerToOfferWithUnknownProtocol) { |
| 1146 MediaSessionOptions opts; | 1264 MediaSessionOptions opts; |
| 1147 opts.data_channel_type = cricket::DCT_RTP; | 1265 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); |
| 1148 opts.recv_audio = false; | |
| 1149 f1_.set_secure(SEC_ENABLED); | 1266 f1_.set_secure(SEC_ENABLED); |
| 1150 f2_.set_secure(SEC_ENABLED); | 1267 f2_.set_secure(SEC_ENABLED); |
| 1151 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1268 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1152 ContentInfo* dc_offer = offer->GetContentByName("data"); | 1269 ContentInfo* dc_offer = offer->GetContentByName("data"); |
| 1153 ASSERT_TRUE(dc_offer != NULL); | 1270 ASSERT_TRUE(dc_offer != NULL); |
| 1154 DataContentDescription* dcd_offer = | 1271 DataContentDescription* dcd_offer = |
| 1155 static_cast<DataContentDescription*>(dc_offer->description); | 1272 static_cast<DataContentDescription*>(dc_offer->description); |
| 1156 ASSERT_TRUE(dcd_offer != NULL); | 1273 ASSERT_TRUE(dcd_offer != NULL); |
| 1157 std::string protocol = "a weird unknown protocol"; | 1274 std::string protocol = "a weird unknown protocol"; |
| 1158 dcd_offer->set_protocol(protocol); | 1275 dcd_offer->set_protocol(protocol); |
| 1159 | 1276 |
| 1160 std::unique_ptr<SessionDescription> answer( | 1277 std::unique_ptr<SessionDescription> answer( |
| 1161 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1278 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1162 | 1279 |
| 1163 const ContentInfo* dc_answer = answer->GetContentByName("data"); | 1280 const ContentInfo* dc_answer = answer->GetContentByName("data"); |
| 1164 ASSERT_TRUE(dc_answer != NULL); | 1281 ASSERT_TRUE(dc_answer != NULL); |
| 1165 EXPECT_TRUE(dc_answer->rejected); | 1282 EXPECT_TRUE(dc_answer->rejected); |
| 1166 const DataContentDescription* dcd_answer = | 1283 const DataContentDescription* dcd_answer = |
| 1167 static_cast<const DataContentDescription*>(dc_answer->description); | 1284 static_cast<const DataContentDescription*>(dc_answer->description); |
| 1168 ASSERT_TRUE(dcd_answer != NULL); | 1285 ASSERT_TRUE(dcd_answer != NULL); |
| 1169 EXPECT_EQ(protocol, dcd_answer->protocol()); | 1286 EXPECT_EQ(protocol, dcd_answer->protocol()); |
| 1170 } | 1287 } |
| 1171 | 1288 |
| 1172 // Test that the media protocol is RTP/AVPF if DTLS and SDES are disabled. | 1289 // Test that the media protocol is RTP/AVPF if DTLS and SDES are disabled. |
| 1173 TEST_F(MediaSessionDescriptionFactoryTest, AudioOfferAnswerWithCryptoDisabled) { | 1290 TEST_F(MediaSessionDescriptionFactoryTest, AudioOfferAnswerWithCryptoDisabled) { |
| 1174 MediaSessionOptions opts; | 1291 MediaSessionOptions opts = CreatePlanBMediaSessionOptions(); |
| 1175 f1_.set_secure(SEC_DISABLED); | 1292 f1_.set_secure(SEC_DISABLED); |
| 1176 f2_.set_secure(SEC_DISABLED); | 1293 f2_.set_secure(SEC_DISABLED); |
| 1177 tdf1_.set_secure(SEC_DISABLED); | 1294 tdf1_.set_secure(SEC_DISABLED); |
| 1178 tdf2_.set_secure(SEC_DISABLED); | 1295 tdf2_.set_secure(SEC_DISABLED); |
| 1179 | 1296 |
| 1180 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1297 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1181 const AudioContentDescription* offer_acd = | 1298 const AudioContentDescription* offer_acd = |
| 1182 GetFirstAudioContentDescription(offer.get()); | 1299 GetFirstAudioContentDescription(offer.get()); |
| 1183 ASSERT_TRUE(offer_acd != NULL); | 1300 ASSERT_TRUE(offer_acd != NULL); |
| 1184 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), offer_acd->protocol()); | 1301 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), offer_acd->protocol()); |
| 1185 | 1302 |
| 1186 std::unique_ptr<SessionDescription> answer( | 1303 std::unique_ptr<SessionDescription> answer( |
| 1187 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1304 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1188 | 1305 |
| 1189 const ContentInfo* ac_answer = answer->GetContentByName("audio"); | 1306 const ContentInfo* ac_answer = answer->GetContentByName("audio"); |
| 1190 ASSERT_TRUE(ac_answer != NULL); | 1307 ASSERT_TRUE(ac_answer != NULL); |
| 1191 EXPECT_FALSE(ac_answer->rejected); | 1308 EXPECT_FALSE(ac_answer->rejected); |
| 1192 | 1309 |
| 1193 const AudioContentDescription* answer_acd = | 1310 const AudioContentDescription* answer_acd = |
| 1194 GetFirstAudioContentDescription(answer.get()); | 1311 GetFirstAudioContentDescription(answer.get()); |
| 1195 ASSERT_TRUE(answer_acd != NULL); | 1312 ASSERT_TRUE(answer_acd != NULL); |
| 1196 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), answer_acd->protocol()); | 1313 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf), answer_acd->protocol()); |
| 1197 } | 1314 } |
| 1198 | 1315 |
| 1199 // Create a video offer and answer and ensure the RTP header extensions | 1316 // Create a video offer and answer and ensure the RTP header extensions |
| 1200 // matches what we expect. | 1317 // matches what we expect. |
| 1201 TEST_F(MediaSessionDescriptionFactoryTest, TestOfferAnswerWithRtpExtensions) { | 1318 TEST_F(MediaSessionDescriptionFactoryTest, TestOfferAnswerWithRtpExtensions) { |
| 1202 MediaSessionOptions opts; | 1319 MediaSessionOptions opts; |
| 1203 opts.recv_video = true; | 1320 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1204 | |
| 1205 f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); | 1321 f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 1206 f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); | 1322 f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 1207 f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); | 1323 f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 1208 f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); | 1324 f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 1209 | 1325 |
| 1210 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1326 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1211 ASSERT_TRUE(offer.get() != NULL); | 1327 ASSERT_TRUE(offer.get() != NULL); |
| 1212 std::unique_ptr<SessionDescription> answer( | 1328 std::unique_ptr<SessionDescription> answer( |
| 1213 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1329 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1214 | 1330 |
| 1215 EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension1), | 1331 EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtension1), |
| 1216 GetFirstAudioContentDescription( | 1332 GetFirstAudioContentDescription( |
| 1217 offer.get())->rtp_header_extensions()); | 1333 offer.get())->rtp_header_extensions()); |
| 1218 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtension1), | 1334 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtension1), |
| 1219 GetFirstVideoContentDescription( | 1335 GetFirstVideoContentDescription( |
| 1220 offer.get())->rtp_header_extensions()); | 1336 offer.get())->rtp_header_extensions()); |
| 1221 EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtensionAnswer), | 1337 EXPECT_EQ(MAKE_VECTOR(kAudioRtpExtensionAnswer), |
| 1222 GetFirstAudioContentDescription( | 1338 GetFirstAudioContentDescription( |
| 1223 answer.get())->rtp_header_extensions()); | 1339 answer.get())->rtp_header_extensions()); |
| 1224 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionAnswer), | 1340 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1225 GetFirstVideoContentDescription( | 1341 GetFirstVideoContentDescription( |
| 1226 answer.get())->rtp_header_extensions()); | 1342 answer.get())->rtp_header_extensions()); |
| 1227 } | 1343 } |
| 1228 | 1344 |
| 1229 TEST_F(MediaSessionDescriptionFactoryTest, | 1345 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1230 TestOfferAnswerWithEncryptedRtpExtensionsBoth) { | 1346 TestOfferAnswerWithEncryptedRtpExtensionsBoth) { |
| 1231 MediaSessionOptions opts; | 1347 MediaSessionOptions opts; |
| 1232 opts.recv_video = true; | 1348 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1233 | 1349 |
| 1234 f1_.set_enable_encrypted_rtp_header_extensions(true); | 1350 f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1235 f2_.set_enable_encrypted_rtp_header_extensions(true); | 1351 f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1236 | 1352 |
| 1237 f1_.set_audio_rtp_header_extensions( | 1353 f1_.set_audio_rtp_header_extensions( |
| 1238 MAKE_VECTOR(kAudioRtpExtension1)); | 1354 MAKE_VECTOR(kAudioRtpExtension1)); |
| 1239 f1_.set_video_rtp_header_extensions( | 1355 f1_.set_video_rtp_header_extensions( |
| 1240 MAKE_VECTOR(kVideoRtpExtension1)); | 1356 MAKE_VECTOR(kVideoRtpExtension1)); |
| 1241 f2_.set_audio_rtp_header_extensions( | 1357 f2_.set_audio_rtp_header_extensions( |
| 1242 MAKE_VECTOR(kAudioRtpExtension2)); | 1358 MAKE_VECTOR(kAudioRtpExtension2)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1258 GetFirstAudioContentDescription( | 1374 GetFirstAudioContentDescription( |
| 1259 answer.get())->rtp_header_extensions()); | 1375 answer.get())->rtp_header_extensions()); |
| 1260 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionEncryptedAnswer), | 1376 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionEncryptedAnswer), |
| 1261 GetFirstVideoContentDescription( | 1377 GetFirstVideoContentDescription( |
| 1262 answer.get())->rtp_header_extensions()); | 1378 answer.get())->rtp_header_extensions()); |
| 1263 } | 1379 } |
| 1264 | 1380 |
| 1265 TEST_F(MediaSessionDescriptionFactoryTest, | 1381 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1266 TestOfferAnswerWithEncryptedRtpExtensionsOffer) { | 1382 TestOfferAnswerWithEncryptedRtpExtensionsOffer) { |
| 1267 MediaSessionOptions opts; | 1383 MediaSessionOptions opts; |
| 1268 opts.recv_video = true; | 1384 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1269 | 1385 |
| 1270 f1_.set_enable_encrypted_rtp_header_extensions(true); | 1386 f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 1271 | 1387 |
| 1272 f1_.set_audio_rtp_header_extensions( | 1388 f1_.set_audio_rtp_header_extensions( |
| 1273 MAKE_VECTOR(kAudioRtpExtension1)); | 1389 MAKE_VECTOR(kAudioRtpExtension1)); |
| 1274 f1_.set_video_rtp_header_extensions( | 1390 f1_.set_video_rtp_header_extensions( |
| 1275 MAKE_VECTOR(kVideoRtpExtension1)); | 1391 MAKE_VECTOR(kVideoRtpExtension1)); |
| 1276 f2_.set_audio_rtp_header_extensions( | 1392 f2_.set_audio_rtp_header_extensions( |
| 1277 MAKE_VECTOR(kAudioRtpExtension2)); | 1393 MAKE_VECTOR(kAudioRtpExtension2)); |
| 1278 f2_.set_video_rtp_header_extensions( | 1394 f2_.set_video_rtp_header_extensions( |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1293 GetFirstAudioContentDescription( | 1409 GetFirstAudioContentDescription( |
| 1294 answer.get())->rtp_header_extensions()); | 1410 answer.get())->rtp_header_extensions()); |
| 1295 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionAnswer), | 1411 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1296 GetFirstVideoContentDescription( | 1412 GetFirstVideoContentDescription( |
| 1297 answer.get())->rtp_header_extensions()); | 1413 answer.get())->rtp_header_extensions()); |
| 1298 } | 1414 } |
| 1299 | 1415 |
| 1300 TEST_F(MediaSessionDescriptionFactoryTest, | 1416 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1301 TestOfferAnswerWithEncryptedRtpExtensionsAnswer) { | 1417 TestOfferAnswerWithEncryptedRtpExtensionsAnswer) { |
| 1302 MediaSessionOptions opts; | 1418 MediaSessionOptions opts; |
| 1303 opts.recv_video = true; | 1419 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1304 | 1420 |
| 1305 f2_.set_enable_encrypted_rtp_header_extensions(true); | 1421 f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 1306 | 1422 |
| 1307 f1_.set_audio_rtp_header_extensions( | 1423 f1_.set_audio_rtp_header_extensions( |
| 1308 MAKE_VECTOR(kAudioRtpExtension1)); | 1424 MAKE_VECTOR(kAudioRtpExtension1)); |
| 1309 f1_.set_video_rtp_header_extensions( | 1425 f1_.set_video_rtp_header_extensions( |
| 1310 MAKE_VECTOR(kVideoRtpExtension1)); | 1426 MAKE_VECTOR(kVideoRtpExtension1)); |
| 1311 f2_.set_audio_rtp_header_extensions( | 1427 f2_.set_audio_rtp_header_extensions( |
| 1312 MAKE_VECTOR(kAudioRtpExtension2)); | 1428 MAKE_VECTOR(kAudioRtpExtension2)); |
| 1313 f2_.set_video_rtp_header_extensions( | 1429 f2_.set_video_rtp_header_extensions( |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1329 answer.get())->rtp_header_extensions()); | 1445 answer.get())->rtp_header_extensions()); |
| 1330 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionAnswer), | 1446 EXPECT_EQ(MAKE_VECTOR(kVideoRtpExtensionAnswer), |
| 1331 GetFirstVideoContentDescription( | 1447 GetFirstVideoContentDescription( |
| 1332 answer.get())->rtp_header_extensions()); | 1448 answer.get())->rtp_header_extensions()); |
| 1333 } | 1449 } |
| 1334 | 1450 |
| 1335 // Create an audio, video, data answer without legacy StreamParams. | 1451 // Create an audio, video, data answer without legacy StreamParams. |
| 1336 TEST_F(MediaSessionDescriptionFactoryTest, | 1452 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1337 TestCreateAnswerWithoutLegacyStreams) { | 1453 TestCreateAnswerWithoutLegacyStreams) { |
| 1338 MediaSessionOptions opts; | 1454 MediaSessionOptions opts; |
| 1339 opts.recv_video = true; | 1455 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1340 opts.data_channel_type = cricket::DCT_RTP; | 1456 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); |
| 1341 f1_.set_add_legacy_streams(false); | |
| 1342 f2_.set_add_legacy_streams(false); | |
| 1343 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1457 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1344 ASSERT_TRUE(offer.get() != NULL); | 1458 ASSERT_TRUE(offer.get() != NULL); |
| 1345 std::unique_ptr<SessionDescription> answer( | 1459 std::unique_ptr<SessionDescription> answer( |
| 1346 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1460 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1347 const ContentInfo* ac = answer->GetContentByName("audio"); | 1461 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1348 const ContentInfo* vc = answer->GetContentByName("video"); | 1462 const ContentInfo* vc = answer->GetContentByName("video"); |
| 1349 const ContentInfo* dc = answer->GetContentByName("data"); | 1463 const ContentInfo* dc = answer->GetContentByName("data"); |
| 1350 ASSERT_TRUE(ac != NULL); | 1464 ASSERT_TRUE(ac != NULL); |
| 1351 ASSERT_TRUE(vc != NULL); | 1465 ASSERT_TRUE(vc != NULL); |
| 1352 const AudioContentDescription* acd = | 1466 const AudioContentDescription* acd = |
| 1353 static_cast<const AudioContentDescription*>(ac->description); | 1467 static_cast<const AudioContentDescription*>(ac->description); |
| 1354 const VideoContentDescription* vcd = | 1468 const VideoContentDescription* vcd = |
| 1355 static_cast<const VideoContentDescription*>(vc->description); | 1469 static_cast<const VideoContentDescription*>(vc->description); |
| 1356 const DataContentDescription* dcd = | 1470 const DataContentDescription* dcd = |
| 1357 static_cast<const DataContentDescription*>(dc->description); | 1471 static_cast<const DataContentDescription*>(dc->description); |
| 1358 | 1472 |
| 1359 EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. | 1473 EXPECT_FALSE(acd->has_ssrcs()); // No StreamParams. |
| 1360 EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. | 1474 EXPECT_FALSE(vcd->has_ssrcs()); // No StreamParams. |
| 1361 EXPECT_FALSE(dcd->has_ssrcs()); // No StreamParams. | 1475 EXPECT_FALSE(dcd->has_ssrcs()); // No StreamParams. |
| 1362 } | 1476 } |
| 1363 | 1477 |
| 1364 TEST_F(MediaSessionDescriptionFactoryTest, TestPartial) { | 1478 TEST_F(MediaSessionDescriptionFactoryTest, TestPartial) { |
| 1365 MediaSessionOptions opts; | 1479 MediaSessionOptions opts; |
| 1366 opts.recv_video = true; | 1480 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1367 opts.data_channel_type = cricket::DCT_RTP; | 1481 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); |
| 1368 f1_.set_secure(SEC_ENABLED); | 1482 f1_.set_secure(SEC_ENABLED); |
| 1369 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1483 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1370 ASSERT_TRUE(offer.get() != NULL); | 1484 ASSERT_TRUE(offer.get() != NULL); |
| 1371 const ContentInfo* ac = offer->GetContentByName("audio"); | 1485 const ContentInfo* ac = offer->GetContentByName("audio"); |
| 1372 const ContentInfo* vc = offer->GetContentByName("video"); | 1486 const ContentInfo* vc = offer->GetContentByName("video"); |
| 1373 const ContentInfo* dc = offer->GetContentByName("data"); | 1487 const ContentInfo* dc = offer->GetContentByName("data"); |
| 1374 AudioContentDescription* acd = const_cast<AudioContentDescription*>( | 1488 AudioContentDescription* acd = const_cast<AudioContentDescription*>( |
| 1375 static_cast<const AudioContentDescription*>(ac->description)); | 1489 static_cast<const AudioContentDescription*>(ac->description)); |
| 1376 VideoContentDescription* vcd = const_cast<VideoContentDescription*>( | 1490 VideoContentDescription* vcd = const_cast<VideoContentDescription*>( |
| 1377 static_cast<const VideoContentDescription*>(vc->description)); | 1491 static_cast<const VideoContentDescription*>(vc->description)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1393 EXPECT_FALSE(dcd->partial()); // default is false. | 1507 EXPECT_FALSE(dcd->partial()); // default is false. |
| 1394 dcd->set_partial(true); | 1508 dcd->set_partial(true); |
| 1395 EXPECT_TRUE(dcd->partial()); | 1509 EXPECT_TRUE(dcd->partial()); |
| 1396 dcd->set_partial(false); | 1510 dcd->set_partial(false); |
| 1397 EXPECT_FALSE(dcd->partial()); | 1511 EXPECT_FALSE(dcd->partial()); |
| 1398 } | 1512 } |
| 1399 | 1513 |
| 1400 // Create a typical video answer, and ensure it matches what we expect. | 1514 // Create a typical video answer, and ensure it matches what we expect. |
| 1401 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { | 1515 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateVideoAnswerRtcpMux) { |
| 1402 MediaSessionOptions offer_opts; | 1516 MediaSessionOptions offer_opts; |
| 1517 AddAudioVideoSections(cricket::MD_SENDRECV, &offer_opts); | |
| 1518 AddDataSection(cricket::DCT_RTP, cricket::MD_SENDRECV, &offer_opts); | |
| 1519 | |
| 1403 MediaSessionOptions answer_opts; | 1520 MediaSessionOptions answer_opts; |
| 1404 answer_opts.recv_video = true; | 1521 AddAudioVideoSections(cricket::MD_SENDRECV, &answer_opts); |
| 1405 offer_opts.recv_video = true; | 1522 AddDataSection(cricket::DCT_RTP, cricket::MD_SENDRECV, &answer_opts); |
| 1406 answer_opts.data_channel_type = cricket::DCT_RTP; | |
| 1407 offer_opts.data_channel_type = cricket::DCT_RTP; | |
| 1408 | 1523 |
| 1409 std::unique_ptr<SessionDescription> offer; | 1524 std::unique_ptr<SessionDescription> offer; |
| 1410 std::unique_ptr<SessionDescription> answer; | 1525 std::unique_ptr<SessionDescription> answer; |
| 1411 | 1526 |
| 1412 offer_opts.rtcp_mux_enabled = true; | 1527 offer_opts.rtcp_mux_enabled = true; |
| 1413 answer_opts.rtcp_mux_enabled = true; | 1528 answer_opts.rtcp_mux_enabled = true; |
| 1414 | |
| 1415 offer.reset(f1_.CreateOffer(offer_opts, NULL)); | 1529 offer.reset(f1_.CreateOffer(offer_opts, NULL)); |
| 1416 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); | 1530 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 1417 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); | 1531 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1418 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); | 1532 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
| 1419 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); | 1533 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); |
| 1420 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); | 1534 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1421 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); | 1535 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
| 1422 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); | 1536 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); |
| 1423 EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); | 1537 EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1424 EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); | 1538 EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
| 1425 EXPECT_TRUE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); | 1539 EXPECT_TRUE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); |
| 1426 EXPECT_TRUE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); | 1540 EXPECT_TRUE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1427 EXPECT_TRUE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); | 1541 EXPECT_TRUE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
| 1428 EXPECT_TRUE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); | 1542 EXPECT_TRUE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); |
| 1429 | 1543 |
| 1430 offer_opts.rtcp_mux_enabled = true; | 1544 offer_opts.rtcp_mux_enabled = true; |
| 1431 answer_opts.rtcp_mux_enabled = false; | 1545 answer_opts.rtcp_mux_enabled = false; |
| 1432 | |
| 1433 offer.reset(f1_.CreateOffer(offer_opts, NULL)); | 1546 offer.reset(f1_.CreateOffer(offer_opts, NULL)); |
| 1434 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); | 1547 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 1435 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); | 1548 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1436 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); | 1549 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
| 1437 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); | 1550 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); |
| 1438 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); | 1551 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1439 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); | 1552 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
| 1440 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); | 1553 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); |
| 1441 EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); | 1554 EXPECT_TRUE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1442 EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); | 1555 EXPECT_TRUE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
| 1443 EXPECT_TRUE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); | 1556 EXPECT_TRUE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); |
| 1444 EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); | 1557 EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1445 EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); | 1558 EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
| 1446 EXPECT_FALSE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); | 1559 EXPECT_FALSE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); |
| 1447 | 1560 |
| 1448 offer_opts.rtcp_mux_enabled = false; | 1561 offer_opts.rtcp_mux_enabled = false; |
| 1449 answer_opts.rtcp_mux_enabled = true; | 1562 answer_opts.rtcp_mux_enabled = true; |
| 1450 | |
| 1451 offer.reset(f1_.CreateOffer(offer_opts, NULL)); | 1563 offer.reset(f1_.CreateOffer(offer_opts, NULL)); |
| 1452 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); | 1564 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 1453 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); | 1565 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1454 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); | 1566 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
| 1455 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); | 1567 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); |
| 1456 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); | 1568 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1457 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); | 1569 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
| 1458 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); | 1570 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); |
| 1459 EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); | 1571 EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1460 EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); | 1572 EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
| 1461 EXPECT_FALSE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); | 1573 EXPECT_FALSE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); |
| 1462 EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); | 1574 EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1463 EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); | 1575 EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
| 1464 EXPECT_FALSE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); | 1576 EXPECT_FALSE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); |
| 1465 | 1577 |
| 1466 offer_opts.rtcp_mux_enabled = false; | 1578 offer_opts.rtcp_mux_enabled = false; |
| 1467 answer_opts.rtcp_mux_enabled = false; | 1579 answer_opts.rtcp_mux_enabled = false; |
| 1468 | |
| 1469 offer.reset(f1_.CreateOffer(offer_opts, NULL)); | 1580 offer.reset(f1_.CreateOffer(offer_opts, NULL)); |
| 1470 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); | 1581 answer.reset(f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 1471 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); | 1582 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(offer.get())); |
| 1472 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); | 1583 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(offer.get())); |
| 1473 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); | 1584 ASSERT_TRUE(NULL != GetFirstDataContentDescription(offer.get())); |
| 1474 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); | 1585 ASSERT_TRUE(NULL != GetFirstAudioContentDescription(answer.get())); |
| 1475 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); | 1586 ASSERT_TRUE(NULL != GetFirstVideoContentDescription(answer.get())); |
| 1476 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); | 1587 ASSERT_TRUE(NULL != GetFirstDataContentDescription(answer.get())); |
| 1477 EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); | 1588 EXPECT_FALSE(GetFirstAudioContentDescription(offer.get())->rtcp_mux()); |
| 1478 EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); | 1589 EXPECT_FALSE(GetFirstVideoContentDescription(offer.get())->rtcp_mux()); |
| 1479 EXPECT_FALSE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); | 1590 EXPECT_FALSE(GetFirstDataContentDescription(offer.get())->rtcp_mux()); |
| 1480 EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); | 1591 EXPECT_FALSE(GetFirstAudioContentDescription(answer.get())->rtcp_mux()); |
| 1481 EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); | 1592 EXPECT_FALSE(GetFirstVideoContentDescription(answer.get())->rtcp_mux()); |
| 1482 EXPECT_FALSE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); | 1593 EXPECT_FALSE(GetFirstDataContentDescription(answer.get())->rtcp_mux()); |
| 1483 } | 1594 } |
| 1484 | 1595 |
| 1485 // Create an audio-only answer to a video offer. | 1596 // Create an audio-only answer to a video offer. |
| 1486 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerToVideo) { | 1597 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateAudioAnswerToVideo) { |
| 1487 MediaSessionOptions opts; | 1598 MediaSessionOptions offer_opts; |
| 1488 opts.recv_video = true; | 1599 AddAudioVideoSections(cricket::MD_RECVONLY, &offer_opts); |
|
Taylor Brandstetter
2017/08/05 00:39:09
Since this test needs the offer/answer options to
Zhi Huang
2017/08/09 00:54:51
Done.
| |
| 1489 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1600 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(offer_opts, NULL)); |
| 1490 ASSERT_TRUE(offer.get() != NULL); | 1601 ASSERT_TRUE(offer.get() != NULL); |
| 1602 | |
| 1603 MediaSessionOptions answer_opts; | |
| 1604 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, | |
| 1605 &answer_opts); | |
| 1606 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_INACTIVE, kStopped, | |
| 1607 &answer_opts); | |
| 1491 std::unique_ptr<SessionDescription> answer( | 1608 std::unique_ptr<SessionDescription> answer( |
| 1492 f2_.CreateAnswer(offer.get(), MediaSessionOptions(), NULL)); | 1609 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 1493 const ContentInfo* ac = answer->GetContentByName("audio"); | 1610 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1494 const ContentInfo* vc = answer->GetContentByName("video"); | 1611 const ContentInfo* vc = answer->GetContentByName("video"); |
| 1495 ASSERT_TRUE(ac != NULL); | 1612 ASSERT_TRUE(ac != NULL); |
| 1496 ASSERT_TRUE(vc != NULL); | 1613 ASSERT_TRUE(vc != NULL); |
| 1497 ASSERT_TRUE(vc->description != NULL); | 1614 ASSERT_TRUE(vc->description != NULL); |
| 1498 EXPECT_TRUE(vc->rejected); | 1615 EXPECT_TRUE(vc->rejected); |
| 1499 } | 1616 } |
| 1500 | 1617 |
| 1501 // Create an audio-only answer to an offer with data. | 1618 // Create an audio-only answer to an offer with data. |
| 1502 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateNoDataAnswerToDataOffer) { | 1619 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateNoDataAnswerToDataOffer) { |
| 1503 MediaSessionOptions opts; | 1620 MediaSessionOptions offer_opts = CreatePlanBMediaSessionOptions(); |
| 1504 opts.data_channel_type = cricket::DCT_RTP; | 1621 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &offer_opts); |
|
Taylor Brandstetter
2017/08/05 00:39:09
Same thing here.
Zhi Huang
2017/08/09 00:54:51
Done.
| |
| 1505 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1622 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(offer_opts, NULL)); |
| 1506 ASSERT_TRUE(offer.get() != NULL); | 1623 ASSERT_TRUE(offer.get() != NULL); |
| 1624 | |
| 1625 MediaSessionOptions answer_opts = CreatePlanBMediaSessionOptions(); | |
| 1626 answer_opts.data_channel_type = cricket::DCT_RTP; | |
| 1627 AddMediaSection(MEDIA_TYPE_DATA, "data", cricket::MD_INACTIVE, kStopped, | |
| 1628 &answer_opts); | |
| 1507 std::unique_ptr<SessionDescription> answer( | 1629 std::unique_ptr<SessionDescription> answer( |
| 1508 f2_.CreateAnswer(offer.get(), MediaSessionOptions(), NULL)); | 1630 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 1509 const ContentInfo* ac = answer->GetContentByName("audio"); | 1631 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1510 const ContentInfo* dc = answer->GetContentByName("data"); | 1632 const ContentInfo* dc = answer->GetContentByName("data"); |
| 1511 ASSERT_TRUE(ac != NULL); | 1633 ASSERT_TRUE(ac != NULL); |
| 1512 ASSERT_TRUE(dc != NULL); | 1634 ASSERT_TRUE(dc != NULL); |
| 1513 ASSERT_TRUE(dc->description != NULL); | 1635 ASSERT_TRUE(dc->description != NULL); |
| 1514 EXPECT_TRUE(dc->rejected); | 1636 EXPECT_TRUE(dc->rejected); |
| 1515 } | 1637 } |
| 1516 | 1638 |
| 1517 // Create an answer that rejects the contents which are rejected in the offer. | 1639 // Create an answer that rejects the contents which are rejected in the offer. |
| 1518 TEST_F(MediaSessionDescriptionFactoryTest, | 1640 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1519 CreateAnswerToOfferWithRejectedMedia) { | 1641 CreateAnswerToOfferWithRejectedMedia) { |
| 1520 MediaSessionOptions opts; | 1642 MediaSessionOptions opts; |
| 1521 opts.recv_video = true; | 1643 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1522 opts.data_channel_type = cricket::DCT_RTP; | 1644 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &opts); |
| 1523 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1645 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1524 ASSERT_TRUE(offer.get() != NULL); | 1646 ASSERT_TRUE(offer.get() != NULL); |
| 1525 ContentInfo* ac = offer->GetContentByName("audio"); | 1647 ContentInfo* ac = offer->GetContentByName("audio"); |
| 1526 ContentInfo* vc = offer->GetContentByName("video"); | 1648 ContentInfo* vc = offer->GetContentByName("video"); |
| 1527 ContentInfo* dc = offer->GetContentByName("data"); | 1649 ContentInfo* dc = offer->GetContentByName("data"); |
| 1528 ASSERT_TRUE(ac != NULL); | 1650 ASSERT_TRUE(ac != NULL); |
| 1529 ASSERT_TRUE(vc != NULL); | 1651 ASSERT_TRUE(vc != NULL); |
| 1530 ASSERT_TRUE(dc != NULL); | 1652 ASSERT_TRUE(dc != NULL); |
| 1531 ac->rejected = true; | 1653 ac->rejected = true; |
| 1532 vc->rejected = true; | 1654 vc->rejected = true; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1545 } | 1667 } |
| 1546 | 1668 |
| 1547 // Create an audio and video offer with: | 1669 // Create an audio and video offer with: |
| 1548 // - one video track | 1670 // - one video track |
| 1549 // - two audio tracks | 1671 // - two audio tracks |
| 1550 // - two data tracks | 1672 // - two data tracks |
| 1551 // and ensure it matches what we expect. Also updates the initial offer by | 1673 // and ensure it matches what we expect. Also updates the initial offer by |
| 1552 // adding a new video track and replaces one of the audio tracks. | 1674 // adding a new video track and replaces one of the audio tracks. |
| 1553 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { | 1675 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoOffer) { |
| 1554 MediaSessionOptions opts; | 1676 MediaSessionOptions opts; |
| 1555 opts.AddSendStream(MEDIA_TYPE_VIDEO, kVideoTrack1, kMediaStream1); | 1677 AddAudioVideoSections(cricket::MD_SENDRECV, &opts); |
| 1556 opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | 1678 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 1557 opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack2, kMediaStream1); | 1679 kMediaStream1, 1, &opts); |
| 1558 opts.data_channel_type = cricket::DCT_RTP; | 1680 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 1559 opts.AddSendStream(MEDIA_TYPE_DATA, kDataTrack1, kMediaStream1); | 1681 kMediaStream1, 1, &opts); |
| 1560 opts.AddSendStream(MEDIA_TYPE_DATA, kDataTrack2, kMediaStream1); | 1682 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 1683 kMediaStream1, 1, &opts); | |
| 1684 | |
| 1685 AddDataSection(cricket::DCT_RTP, cricket::MD_SENDRECV, &opts); | |
| 1686 AttachSenderToMediaSection("data", MEDIA_TYPE_DATA, kDataTrack1, | |
| 1687 kMediaStream1, 1, &opts); | |
| 1688 AttachSenderToMediaSection("data", MEDIA_TYPE_DATA, kDataTrack2, | |
| 1689 kMediaStream1, 1, &opts); | |
| 1561 | 1690 |
| 1562 f1_.set_secure(SEC_ENABLED); | 1691 f1_.set_secure(SEC_ENABLED); |
| 1563 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1692 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1564 | 1693 |
| 1565 ASSERT_TRUE(offer.get() != NULL); | 1694 ASSERT_TRUE(offer.get() != NULL); |
| 1566 const ContentInfo* ac = offer->GetContentByName("audio"); | 1695 const ContentInfo* ac = offer->GetContentByName("audio"); |
| 1567 const ContentInfo* vc = offer->GetContentByName("video"); | 1696 const ContentInfo* vc = offer->GetContentByName("video"); |
| 1568 const ContentInfo* dc = offer->GetContentByName("data"); | 1697 const ContentInfo* dc = offer->GetContentByName("data"); |
| 1569 ASSERT_TRUE(ac != NULL); | 1698 ASSERT_TRUE(ac != NULL); |
| 1570 ASSERT_TRUE(vc != NULL); | 1699 ASSERT_TRUE(vc != NULL); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1615 EXPECT_NE(0U, data_streams[0].ssrcs[0]); | 1744 EXPECT_NE(0U, data_streams[0].ssrcs[0]); |
| 1616 EXPECT_EQ(kDataTrack2, data_streams[1].id); | 1745 EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 1617 ASSERT_EQ(1U, data_streams[1].ssrcs.size()); | 1746 ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 1618 EXPECT_NE(0U, data_streams[1].ssrcs[0]); | 1747 EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 1619 | 1748 |
| 1620 EXPECT_EQ(cricket::kDataMaxBandwidth, | 1749 EXPECT_EQ(cricket::kDataMaxBandwidth, |
| 1621 dcd->bandwidth()); // default bandwidth (auto) | 1750 dcd->bandwidth()); // default bandwidth (auto) |
| 1622 EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on | 1751 EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
| 1623 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); | 1752 ASSERT_CRYPTO(dcd, 1U, CS_AES_CM_128_HMAC_SHA1_80); |
| 1624 | 1753 |
| 1625 | |
| 1626 // Update the offer. Add a new video track that is not synched to the | 1754 // Update the offer. Add a new video track that is not synched to the |
| 1627 // other tracks and replace audio track 2 with audio track 3. | 1755 // other tracks and replace audio track 2 with audio track 3. |
| 1628 opts.AddSendStream(MEDIA_TYPE_VIDEO, kVideoTrack2, kMediaStream2); | 1756 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 1629 opts.RemoveSendStream(MEDIA_TYPE_AUDIO, kAudioTrack2); | 1757 kMediaStream2, 1, &opts); |
| 1630 opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack3, kMediaStream1); | 1758 DetachSenderFromMediaSection("audio", kAudioTrack2, &opts); |
| 1631 opts.RemoveSendStream(MEDIA_TYPE_DATA, kDataTrack2); | 1759 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack3, |
| 1632 opts.AddSendStream(MEDIA_TYPE_DATA, kDataTrack3, kMediaStream1); | 1760 kMediaStream1, 1, &opts); |
| 1761 DetachSenderFromMediaSection("data", kDataTrack2, &opts); | |
| 1762 AttachSenderToMediaSection("data", MEDIA_TYPE_DATA, kDataTrack3, | |
| 1763 kMediaStream1, 1, &opts); | |
| 1633 std::unique_ptr<SessionDescription> updated_offer( | 1764 std::unique_ptr<SessionDescription> updated_offer( |
| 1634 f1_.CreateOffer(opts, offer.get())); | 1765 f1_.CreateOffer(opts, offer.get())); |
| 1635 | 1766 |
| 1636 ASSERT_TRUE(updated_offer.get() != NULL); | 1767 ASSERT_TRUE(updated_offer.get() != NULL); |
| 1637 ac = updated_offer->GetContentByName("audio"); | 1768 ac = updated_offer->GetContentByName("audio"); |
| 1638 vc = updated_offer->GetContentByName("video"); | 1769 vc = updated_offer->GetContentByName("video"); |
| 1639 dc = updated_offer->GetContentByName("data"); | 1770 dc = updated_offer->GetContentByName("data"); |
| 1640 ASSERT_TRUE(ac != NULL); | 1771 ASSERT_TRUE(ac != NULL); |
| 1641 ASSERT_TRUE(vc != NULL); | 1772 ASSERT_TRUE(vc != NULL); |
| 1642 ASSERT_TRUE(dc != NULL); | 1773 ASSERT_TRUE(dc != NULL); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1684 EXPECT_EQ(updated_data_streams[0].cname, updated_data_streams[1].cname); | 1815 EXPECT_EQ(updated_data_streams[0].cname, updated_data_streams[1].cname); |
| 1685 // The stream correctly got the CNAME from the MediaSessionOptions. | 1816 // The stream correctly got the CNAME from the MediaSessionOptions. |
| 1686 // The Expected RTCP CNAME is the default one as we are using the default | 1817 // The Expected RTCP CNAME is the default one as we are using the default |
| 1687 // MediaSessionOptions. | 1818 // MediaSessionOptions. |
| 1688 EXPECT_EQ(updated_data_streams[0].cname, cricket::kDefaultRtcpCname); | 1819 EXPECT_EQ(updated_data_streams[0].cname, cricket::kDefaultRtcpCname); |
| 1689 } | 1820 } |
| 1690 | 1821 |
| 1691 // Create an offer with simulcast video stream. | 1822 // Create an offer with simulcast video stream. |
| 1692 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { | 1823 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateSimulcastVideoOffer) { |
| 1693 MediaSessionOptions opts; | 1824 MediaSessionOptions opts; |
| 1825 AddAudioVideoSections(cricket::MD_SENDRECV, &opts); | |
| 1694 const int num_sim_layers = 3; | 1826 const int num_sim_layers = 3; |
| 1695 opts.AddSendVideoStream(kVideoTrack1, kMediaStream1, num_sim_layers); | 1827 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
|
Taylor Brandstetter
2017/08/05 00:39:09
Similar comment for this test; it relies on specif
Zhi Huang
2017/08/09 00:54:50
Done.
| |
| 1828 kMediaStream1, num_sim_layers, &opts); | |
| 1696 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1829 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1697 | 1830 |
| 1698 ASSERT_TRUE(offer.get() != NULL); | 1831 ASSERT_TRUE(offer.get() != NULL); |
| 1699 const ContentInfo* vc = offer->GetContentByName("video"); | 1832 const ContentInfo* vc = offer->GetContentByName("video"); |
| 1700 ASSERT_TRUE(vc != NULL); | 1833 ASSERT_TRUE(vc != NULL); |
| 1701 const VideoContentDescription* vcd = | 1834 const VideoContentDescription* vcd = |
| 1702 static_cast<const VideoContentDescription*>(vc->description); | 1835 static_cast<const VideoContentDescription*>(vc->description); |
| 1703 | 1836 |
| 1704 const StreamParamsVec& video_streams = vcd->streams(); | 1837 const StreamParamsVec& video_streams = vcd->streams(); |
| 1705 ASSERT_EQ(1U, video_streams.size()); | 1838 ASSERT_EQ(1U, video_streams.size()); |
| 1706 EXPECT_EQ(kVideoTrack1, video_streams[0].id); | 1839 EXPECT_EQ(kVideoTrack1, video_streams[0].id); |
| 1707 const SsrcGroup* sim_ssrc_group = | 1840 const SsrcGroup* sim_ssrc_group = |
| 1708 video_streams[0].get_ssrc_group(cricket::kSimSsrcGroupSemantics); | 1841 video_streams[0].get_ssrc_group(cricket::kSimSsrcGroupSemantics); |
| 1709 ASSERT_TRUE(sim_ssrc_group != NULL); | 1842 ASSERT_TRUE(sim_ssrc_group != NULL); |
| 1710 EXPECT_EQ(static_cast<size_t>(num_sim_layers), sim_ssrc_group->ssrcs.size()); | 1843 EXPECT_EQ(static_cast<size_t>(num_sim_layers), sim_ssrc_group->ssrcs.size()); |
| 1711 } | 1844 } |
| 1712 | 1845 |
| 1713 // Create an audio and video answer to a standard video offer with: | 1846 // Create an audio and video answer to a standard video offer with: |
| 1714 // - one video track | 1847 // - one video track |
| 1715 // - two audio tracks | 1848 // - two audio tracks |
| 1716 // - two data tracks | 1849 // - two data tracks |
| 1717 // and ensure it matches what we expect. Also updates the initial answer by | 1850 // and ensure it matches what we expect. Also updates the initial answer by |
| 1718 // adding a new video track and removes one of the audio tracks. | 1851 // adding a new video track and removes one of the audio tracks. |
| 1719 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { | 1852 TEST_F(MediaSessionDescriptionFactoryTest, TestCreateMultiStreamVideoAnswer) { |
| 1720 MediaSessionOptions offer_opts; | 1853 MediaSessionOptions offer_opts; |
| 1721 offer_opts.recv_video = true; | 1854 AddAudioVideoSections(cricket::MD_RECVONLY, &offer_opts); |
|
Taylor Brandstetter
2017/08/05 00:39:09
Same thing here.
Zhi Huang
2017/08/09 00:54:51
Done.
| |
| 1722 offer_opts.data_channel_type = cricket::DCT_RTP; | 1855 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &offer_opts); |
| 1723 f1_.set_secure(SEC_ENABLED); | 1856 f1_.set_secure(SEC_ENABLED); |
| 1724 f2_.set_secure(SEC_ENABLED); | 1857 f2_.set_secure(SEC_ENABLED); |
| 1725 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(offer_opts, NULL)); | 1858 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(offer_opts, NULL)); |
| 1726 | 1859 |
| 1727 MediaSessionOptions opts; | 1860 MediaSessionOptions answer_opts; |
| 1728 opts.AddSendStream(MEDIA_TYPE_VIDEO, kVideoTrack1, kMediaStream1); | 1861 AddAudioVideoSections(cricket::MD_SENDRECV, &answer_opts); |
| 1729 opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | 1862 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, kVideoTrack1, |
| 1730 opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack2, kMediaStream1); | 1863 kMediaStream1, 1, &answer_opts); |
| 1731 opts.data_channel_type = cricket::DCT_RTP; | 1864 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 1732 opts.AddSendStream(MEDIA_TYPE_DATA, kDataTrack1, kMediaStream1); | 1865 kMediaStream1, 1, &answer_opts); |
| 1733 opts.AddSendStream(MEDIA_TYPE_DATA, kDataTrack2, kMediaStream1); | 1866 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack2, |
| 1867 kMediaStream1, 1, &answer_opts); | |
| 1868 | |
| 1869 AddDataSection(cricket::DCT_RTP, cricket::MD_SENDRECV, &answer_opts); | |
| 1870 AttachSenderToMediaSection("data", MEDIA_TYPE_DATA, kDataTrack1, | |
| 1871 kMediaStream1, 1, &answer_opts); | |
| 1872 AttachSenderToMediaSection("data", MEDIA_TYPE_DATA, kDataTrack2, | |
| 1873 kMediaStream1, 1, &answer_opts); | |
| 1734 | 1874 |
| 1735 std::unique_ptr<SessionDescription> answer( | 1875 std::unique_ptr<SessionDescription> answer( |
| 1736 f2_.CreateAnswer(offer.get(), opts, NULL)); | 1876 f2_.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 1737 | 1877 |
| 1738 ASSERT_TRUE(answer.get() != NULL); | 1878 ASSERT_TRUE(answer.get() != NULL); |
| 1739 const ContentInfo* ac = answer->GetContentByName("audio"); | 1879 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 1740 const ContentInfo* vc = answer->GetContentByName("video"); | 1880 const ContentInfo* vc = answer->GetContentByName("video"); |
| 1741 const ContentInfo* dc = answer->GetContentByName("data"); | 1881 const ContentInfo* dc = answer->GetContentByName("data"); |
| 1742 ASSERT_TRUE(ac != NULL); | 1882 ASSERT_TRUE(ac != NULL); |
| 1743 ASSERT_TRUE(vc != NULL); | 1883 ASSERT_TRUE(vc != NULL); |
| 1744 ASSERT_TRUE(dc != NULL); | 1884 ASSERT_TRUE(dc != NULL); |
| 1745 const AudioContentDescription* acd = | 1885 const AudioContentDescription* acd = |
| 1746 static_cast<const AudioContentDescription*>(ac->description); | 1886 static_cast<const AudioContentDescription*>(ac->description); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1790 EXPECT_EQ(kDataTrack2, data_streams[1].id); | 1930 EXPECT_EQ(kDataTrack2, data_streams[1].id); |
| 1791 ASSERT_EQ(1U, data_streams[1].ssrcs.size()); | 1931 ASSERT_EQ(1U, data_streams[1].ssrcs.size()); |
| 1792 EXPECT_NE(0U, data_streams[1].ssrcs[0]); | 1932 EXPECT_NE(0U, data_streams[1].ssrcs[0]); |
| 1793 | 1933 |
| 1794 EXPECT_EQ(cricket::kDataMaxBandwidth, | 1934 EXPECT_EQ(cricket::kDataMaxBandwidth, |
| 1795 dcd->bandwidth()); // default bandwidth (auto) | 1935 dcd->bandwidth()); // default bandwidth (auto) |
| 1796 EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on | 1936 EXPECT_TRUE(dcd->rtcp_mux()); // rtcp-mux defaults on |
| 1797 | 1937 |
| 1798 // Update the answer. Add a new video track that is not synched to the | 1938 // Update the answer. Add a new video track that is not synched to the |
| 1799 // other tracks and remove 1 audio track. | 1939 // other tracks and remove 1 audio track. |
| 1800 opts.AddSendStream(MEDIA_TYPE_VIDEO, kVideoTrack2, kMediaStream2); | 1940 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, kVideoTrack2, |
| 1801 opts.RemoveSendStream(MEDIA_TYPE_AUDIO, kAudioTrack2); | 1941 kMediaStream2, 1, &answer_opts); |
| 1802 opts.RemoveSendStream(MEDIA_TYPE_DATA, kDataTrack2); | 1942 DetachSenderFromMediaSection("audio", kAudioTrack2, &answer_opts); |
| 1943 DetachSenderFromMediaSection("data", kDataTrack2, &answer_opts); | |
| 1803 std::unique_ptr<SessionDescription> updated_answer( | 1944 std::unique_ptr<SessionDescription> updated_answer( |
| 1804 f2_.CreateAnswer(offer.get(), opts, answer.get())); | 1945 f2_.CreateAnswer(offer.get(), answer_opts, answer.get())); |
| 1805 | 1946 |
| 1806 ASSERT_TRUE(updated_answer.get() != NULL); | 1947 ASSERT_TRUE(updated_answer.get() != NULL); |
| 1807 ac = updated_answer->GetContentByName("audio"); | 1948 ac = updated_answer->GetContentByName("audio"); |
| 1808 vc = updated_answer->GetContentByName("video"); | 1949 vc = updated_answer->GetContentByName("video"); |
| 1809 dc = updated_answer->GetContentByName("data"); | 1950 dc = updated_answer->GetContentByName("data"); |
| 1810 ASSERT_TRUE(ac != NULL); | 1951 ASSERT_TRUE(ac != NULL); |
| 1811 ASSERT_TRUE(vc != NULL); | 1952 ASSERT_TRUE(vc != NULL); |
| 1812 ASSERT_TRUE(dc != NULL); | 1953 ASSERT_TRUE(dc != NULL); |
| 1813 const AudioContentDescription* updated_acd = | 1954 const AudioContentDescription* updated_acd = |
| 1814 static_cast<const AudioContentDescription*>(ac->description); | 1955 static_cast<const AudioContentDescription*>(ac->description); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 ASSERT_EQ(1U, updated_data_streams.size()); | 1987 ASSERT_EQ(1U, updated_data_streams.size()); |
| 1847 EXPECT_TRUE(data_streams[0] == updated_data_streams[0]); | 1988 EXPECT_TRUE(data_streams[0] == updated_data_streams[0]); |
| 1848 } | 1989 } |
| 1849 | 1990 |
| 1850 // Create an updated offer after creating an answer to the original offer and | 1991 // Create an updated offer after creating an answer to the original offer and |
| 1851 // verify that the codecs that were part of the original answer are not changed | 1992 // verify that the codecs that were part of the original answer are not changed |
| 1852 // in the updated offer. | 1993 // in the updated offer. |
| 1853 TEST_F(MediaSessionDescriptionFactoryTest, | 1994 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1854 RespondentCreatesOfferAfterCreatingAnswer) { | 1995 RespondentCreatesOfferAfterCreatingAnswer) { |
| 1855 MediaSessionOptions opts; | 1996 MediaSessionOptions opts; |
| 1856 opts.recv_audio = true; | 1997 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1857 opts.recv_video = true; | |
| 1858 | 1998 |
| 1859 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 1999 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1860 std::unique_ptr<SessionDescription> answer( | 2000 std::unique_ptr<SessionDescription> answer( |
| 1861 f2_.CreateAnswer(offer.get(), opts, NULL)); | 2001 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1862 | 2002 |
| 1863 const AudioContentDescription* acd = | 2003 const AudioContentDescription* acd = |
| 1864 GetFirstAudioContentDescription(answer.get()); | 2004 GetFirstAudioContentDescription(answer.get()); |
| 1865 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 2005 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 1866 | 2006 |
| 1867 const VideoContentDescription* vcd = | 2007 const VideoContentDescription* vcd = |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1898 GetFirstVideoContentDescription(updated_offer.get()); | 2038 GetFirstVideoContentDescription(updated_offer.get()); |
| 1899 EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoCodecOffer), updated_vcd->codecs()); | 2039 EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoCodecOffer), updated_vcd->codecs()); |
| 1900 } | 2040 } |
| 1901 | 2041 |
| 1902 // Create an updated offer after creating an answer to the original offer and | 2042 // Create an updated offer after creating an answer to the original offer and |
| 1903 // verify that the codecs that were part of the original answer are not changed | 2043 // verify that the codecs that were part of the original answer are not changed |
| 1904 // in the updated offer. In this test Rtx is enabled. | 2044 // in the updated offer. In this test Rtx is enabled. |
| 1905 TEST_F(MediaSessionDescriptionFactoryTest, | 2045 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1906 RespondentCreatesOfferAfterCreatingAnswerWithRtx) { | 2046 RespondentCreatesOfferAfterCreatingAnswerWithRtx) { |
| 1907 MediaSessionOptions opts; | 2047 MediaSessionOptions opts; |
| 1908 opts.recv_video = true; | 2048 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_RECVONLY, !kStopped, |
| 1909 opts.recv_audio = false; | 2049 &opts); |
| 1910 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); | 2050 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 1911 // This creates rtx for H264 with the payload type |f1_| uses. | 2051 // This creates rtx for H264 with the payload type |f1_| uses. |
| 1912 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); | 2052 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 1913 f1_.set_video_codecs(f1_codecs); | 2053 f1_.set_video_codecs(f1_codecs); |
| 1914 | 2054 |
| 1915 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); | 2055 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 1916 // This creates rtx for H264 with the payload type |f2_| uses. | 2056 // This creates rtx for H264 with the payload type |f2_| uses. |
| 1917 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); | 2057 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
| 1918 f2_.set_video_codecs(f2_codecs); | 2058 f2_.set_video_codecs(f2_codecs); |
| 1919 | 2059 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1951 // codec have the same default payload type as an audio codec that is already in | 2091 // codec have the same default payload type as an audio codec that is already in |
| 1952 // use, the added codecs payload types are changed. | 2092 // use, the added codecs payload types are changed. |
| 1953 TEST_F(MediaSessionDescriptionFactoryTest, | 2093 TEST_F(MediaSessionDescriptionFactoryTest, |
| 1954 RespondentCreatesOfferWithVideoAndRtxAfterCreatingAudioAnswer) { | 2094 RespondentCreatesOfferWithVideoAndRtxAfterCreatingAudioAnswer) { |
| 1955 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); | 2095 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 1956 // This creates rtx for H264 with the payload type |f1_| uses. | 2096 // This creates rtx for H264 with the payload type |f1_| uses. |
| 1957 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); | 2097 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 1958 f1_.set_video_codecs(f1_codecs); | 2098 f1_.set_video_codecs(f1_codecs); |
| 1959 | 2099 |
| 1960 MediaSessionOptions opts; | 2100 MediaSessionOptions opts; |
| 1961 opts.recv_audio = true; | 2101 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 1962 opts.recv_video = false; | 2102 &opts); |
| 1963 | 2103 |
| 1964 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 2104 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 1965 std::unique_ptr<SessionDescription> answer( | 2105 std::unique_ptr<SessionDescription> answer( |
| 1966 f2_.CreateAnswer(offer.get(), opts, NULL)); | 2106 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 1967 | 2107 |
| 1968 const AudioContentDescription* acd = | 2108 const AudioContentDescription* acd = |
| 1969 GetFirstAudioContentDescription(answer.get()); | 2109 GetFirstAudioContentDescription(answer.get()); |
| 1970 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); | 2110 EXPECT_EQ(MAKE_VECTOR(kAudioCodecsAnswer), acd->codecs()); |
| 1971 | 2111 |
| 1972 // Now - let |f2_| add video with RTX and let the payload type the RTX codec | 2112 // Now - let |f2_| add video with RTX and let the payload type the RTX codec |
| 1973 // reference be the same as an audio codec that was negotiated in the | 2113 // reference be the same as an audio codec that was negotiated in the |
| 1974 // first offer/answer exchange. | 2114 // first offer/answer exchange. |
| 1975 opts.recv_audio = true; | 2115 opts.media_description_options.clear(); |
| 1976 opts.recv_video = true; | 2116 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 1977 | 2117 |
| 1978 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); | 2118 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 1979 int used_pl_type = acd->codecs()[0].id; | 2119 int used_pl_type = acd->codecs()[0].id; |
| 1980 f2_codecs[0].id = used_pl_type; // Set the payload type for H264. | 2120 f2_codecs[0].id = used_pl_type; // Set the payload type for H264. |
| 1981 AddRtxCodec(VideoCodec::CreateRtxCodec(125, used_pl_type), &f2_codecs); | 2121 AddRtxCodec(VideoCodec::CreateRtxCodec(125, used_pl_type), &f2_codecs); |
| 1982 f2_.set_video_codecs(f2_codecs); | 2122 f2_.set_video_codecs(f2_codecs); |
| 1983 | 2123 |
| 1984 std::unique_ptr<SessionDescription> updated_offer( | 2124 std::unique_ptr<SessionDescription> updated_offer( |
| 1985 f2_.CreateOffer(opts, answer.get())); | 2125 f2_.CreateOffer(opts, answer.get())); |
| 1986 ASSERT_TRUE(updated_offer); | 2126 ASSERT_TRUE(updated_offer); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2003 rtx.params[cricket::kCodecParamAssociatedPayloadType]); | 2143 rtx.params[cricket::kCodecParamAssociatedPayloadType]); |
| 2004 EXPECT_EQ(new_h264_pl_type, pt_referenced_by_rtx); | 2144 EXPECT_EQ(new_h264_pl_type, pt_referenced_by_rtx); |
| 2005 } | 2145 } |
| 2006 | 2146 |
| 2007 // Create an updated offer with RTX after creating an answer to an offer | 2147 // Create an updated offer with RTX after creating an answer to an offer |
| 2008 // without RTX, and with different default payload types. | 2148 // without RTX, and with different default payload types. |
| 2009 // Verify that the added RTX codec references the correct payload type. | 2149 // Verify that the added RTX codec references the correct payload type. |
| 2010 TEST_F(MediaSessionDescriptionFactoryTest, | 2150 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2011 RespondentCreatesOfferWithRtxAfterCreatingAnswerWithoutRtx) { | 2151 RespondentCreatesOfferWithRtxAfterCreatingAnswerWithoutRtx) { |
| 2012 MediaSessionOptions opts; | 2152 MediaSessionOptions opts; |
| 2013 opts.recv_video = true; | 2153 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 2014 opts.recv_audio = true; | |
| 2015 | 2154 |
| 2016 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); | 2155 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2017 // This creates rtx for H264 with the payload type |f2_| uses. | 2156 // This creates rtx for H264 with the payload type |f2_| uses. |
| 2018 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); | 2157 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
| 2019 f2_.set_video_codecs(f2_codecs); | 2158 f2_.set_video_codecs(f2_codecs); |
| 2020 | 2159 |
| 2021 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | 2160 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); |
| 2022 ASSERT_TRUE(offer.get() != nullptr); | 2161 ASSERT_TRUE(offer.get() != nullptr); |
| 2023 std::unique_ptr<SessionDescription> answer( | 2162 std::unique_ptr<SessionDescription> answer( |
| 2024 f2_.CreateAnswer(offer.get(), opts, nullptr)); | 2163 f2_.CreateAnswer(offer.get(), opts, nullptr)); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2042 // New offer should attempt to add H263, and RTX for H264. | 2181 // New offer should attempt to add H263, and RTX for H264. |
| 2043 expected_codecs.push_back(kVideoCodecs2[1]); | 2182 expected_codecs.push_back(kVideoCodecs2[1]); |
| 2044 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[1].id), | 2183 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[1].id), |
| 2045 &expected_codecs); | 2184 &expected_codecs); |
| 2046 EXPECT_EQ(expected_codecs, updated_vcd->codecs()); | 2185 EXPECT_EQ(expected_codecs, updated_vcd->codecs()); |
| 2047 } | 2186 } |
| 2048 | 2187 |
| 2049 // Test that RTX is ignored when there is no associated payload type parameter. | 2188 // Test that RTX is ignored when there is no associated payload type parameter. |
| 2050 TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { | 2189 TEST_F(MediaSessionDescriptionFactoryTest, RtxWithoutApt) { |
| 2051 MediaSessionOptions opts; | 2190 MediaSessionOptions opts; |
| 2052 opts.recv_video = true; | 2191 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_RECVONLY, !kStopped, |
| 2053 opts.recv_audio = false; | 2192 &opts); |
| 2054 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); | 2193 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2055 // This creates RTX without associated payload type parameter. | 2194 // This creates RTX without associated payload type parameter. |
| 2056 AddRtxCodec(VideoCodec(126, cricket::kRtxCodecName), &f1_codecs); | 2195 AddRtxCodec(VideoCodec(126, cricket::kRtxCodecName), &f1_codecs); |
| 2057 f1_.set_video_codecs(f1_codecs); | 2196 f1_.set_video_codecs(f1_codecs); |
| 2058 | 2197 |
| 2059 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); | 2198 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2060 // This creates RTX for H264 with the payload type |f2_| uses. | 2199 // This creates RTX for H264 with the payload type |f2_| uses. |
| 2061 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); | 2200 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[0].id), &f2_codecs); |
| 2062 f2_.set_video_codecs(f2_codecs); | 2201 f2_.set_video_codecs(f2_codecs); |
| 2063 | 2202 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 2086 std::vector<std::string> codec_names = | 2225 std::vector<std::string> codec_names = |
| 2087 GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()); | 2226 GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()); |
| 2088 EXPECT_EQ(codec_names.end(), std::find(codec_names.begin(), codec_names.end(), | 2227 EXPECT_EQ(codec_names.end(), std::find(codec_names.begin(), codec_names.end(), |
| 2089 cricket::kRtxCodecName)); | 2228 cricket::kRtxCodecName)); |
| 2090 } | 2229 } |
| 2091 | 2230 |
| 2092 // Test that RTX will be filtered out in the answer if its associated payload | 2231 // Test that RTX will be filtered out in the answer if its associated payload |
| 2093 // type doesn't match the local value. | 2232 // type doesn't match the local value. |
| 2094 TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { | 2233 TEST_F(MediaSessionDescriptionFactoryTest, FilterOutRtxIfAptDoesntMatch) { |
| 2095 MediaSessionOptions opts; | 2234 MediaSessionOptions opts; |
| 2096 opts.recv_video = true; | 2235 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_RECVONLY, !kStopped, |
| 2097 opts.recv_audio = false; | 2236 &opts); |
| 2098 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); | 2237 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2099 // This creates RTX for H264 in sender. | 2238 // This creates RTX for H264 in sender. |
| 2100 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); | 2239 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 2101 f1_.set_video_codecs(f1_codecs); | 2240 f1_.set_video_codecs(f1_codecs); |
| 2102 | 2241 |
| 2103 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); | 2242 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| 2104 // This creates RTX for H263 in receiver. | 2243 // This creates RTX for H263 in receiver. |
| 2105 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[1].id), &f2_codecs); | 2244 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs2[1].id), &f2_codecs); |
| 2106 f2_.set_video_codecs(f2_codecs); | 2245 f2_.set_video_codecs(f2_codecs); |
| 2107 | 2246 |
| 2108 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 2247 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 2109 ASSERT_TRUE(offer.get() != NULL); | 2248 ASSERT_TRUE(offer.get() != NULL); |
| 2110 // Associated payload type doesn't match, therefore, RTX codec is removed in | 2249 // Associated payload type doesn't match, therefore, RTX codec is removed in |
| 2111 // the answer. | 2250 // the answer. |
| 2112 std::unique_ptr<SessionDescription> answer( | 2251 std::unique_ptr<SessionDescription> answer( |
| 2113 f2_.CreateAnswer(offer.get(), opts, NULL)); | 2252 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 2114 | 2253 |
| 2115 std::vector<std::string> codec_names = | 2254 std::vector<std::string> codec_names = |
| 2116 GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()); | 2255 GetCodecNames(GetFirstVideoContentDescription(answer.get())->codecs()); |
| 2117 EXPECT_EQ(codec_names.end(), std::find(codec_names.begin(), codec_names.end(), | 2256 EXPECT_EQ(codec_names.end(), std::find(codec_names.begin(), codec_names.end(), |
| 2118 cricket::kRtxCodecName)); | 2257 cricket::kRtxCodecName)); |
| 2119 } | 2258 } |
| 2120 | 2259 |
| 2121 // Test that when multiple RTX codecs are offered, only the matched RTX codec | 2260 // Test that when multiple RTX codecs are offered, only the matched RTX codec |
| 2122 // is added in the answer, and the unsupported RTX codec is filtered out. | 2261 // is added in the answer, and the unsupported RTX codec is filtered out. |
| 2123 TEST_F(MediaSessionDescriptionFactoryTest, | 2262 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2124 FilterOutUnsupportedRtxWhenCreatingAnswer) { | 2263 FilterOutUnsupportedRtxWhenCreatingAnswer) { |
| 2125 MediaSessionOptions opts; | 2264 MediaSessionOptions opts; |
| 2126 opts.recv_video = true; | 2265 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_RECVONLY, !kStopped, |
| 2127 opts.recv_audio = false; | 2266 &opts); |
| 2128 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); | 2267 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2129 // This creates RTX for H264-SVC in sender. | 2268 // This creates RTX for H264-SVC in sender. |
| 2130 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); | 2269 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), &f1_codecs); |
| 2131 f1_.set_video_codecs(f1_codecs); | 2270 f1_.set_video_codecs(f1_codecs); |
| 2132 | 2271 |
| 2133 // This creates RTX for H264 in sender. | 2272 // This creates RTX for H264 in sender. |
| 2134 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); | 2273 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 2135 f1_.set_video_codecs(f1_codecs); | 2274 f1_.set_video_codecs(f1_codecs); |
| 2136 | 2275 |
| 2137 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); | 2276 std::vector<VideoCodec> f2_codecs = MAKE_VECTOR(kVideoCodecs2); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2151 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), | 2290 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), |
| 2152 &expected_codecs); | 2291 &expected_codecs); |
| 2153 | 2292 |
| 2154 EXPECT_EQ(expected_codecs, vcd->codecs()); | 2293 EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2155 } | 2294 } |
| 2156 | 2295 |
| 2157 // Test that after one RTX codec has been negotiated, a new offer can attempt | 2296 // Test that after one RTX codec has been negotiated, a new offer can attempt |
| 2158 // to add another. | 2297 // to add another. |
| 2159 TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { | 2298 TEST_F(MediaSessionDescriptionFactoryTest, AddSecondRtxInNewOffer) { |
| 2160 MediaSessionOptions opts; | 2299 MediaSessionOptions opts; |
| 2161 opts.recv_video = true; | 2300 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_RECVONLY, !kStopped, |
| 2162 opts.recv_audio = false; | 2301 &opts); |
| 2163 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); | 2302 std::vector<VideoCodec> f1_codecs = MAKE_VECTOR(kVideoCodecs1); |
| 2164 // This creates RTX for H264 for the offerer. | 2303 // This creates RTX for H264 for the offerer. |
| 2165 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); | 2304 AddRtxCodec(VideoCodec::CreateRtxCodec(126, kVideoCodecs1[1].id), &f1_codecs); |
| 2166 f1_.set_video_codecs(f1_codecs); | 2305 f1_.set_video_codecs(f1_codecs); |
| 2167 | 2306 |
| 2168 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | 2307 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); |
| 2169 ASSERT_TRUE(offer); | 2308 ASSERT_TRUE(offer); |
| 2170 const VideoContentDescription* vcd = | 2309 const VideoContentDescription* vcd = |
| 2171 GetFirstVideoContentDescription(offer.get()); | 2310 GetFirstVideoContentDescription(offer.get()); |
| 2172 | 2311 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2186 | 2325 |
| 2187 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), | 2326 AddRtxCodec(VideoCodec::CreateRtxCodec(125, kVideoCodecs1[0].id), |
| 2188 &expected_codecs); | 2327 &expected_codecs); |
| 2189 EXPECT_EQ(expected_codecs, vcd->codecs()); | 2328 EXPECT_EQ(expected_codecs, vcd->codecs()); |
| 2190 } | 2329 } |
| 2191 | 2330 |
| 2192 // Test that when RTX is used in conjunction with simulcast, an RTX ssrc is | 2331 // Test that when RTX is used in conjunction with simulcast, an RTX ssrc is |
| 2193 // generated for each simulcast ssrc and correctly grouped. | 2332 // generated for each simulcast ssrc and correctly grouped. |
| 2194 TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { | 2333 TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateMultipleRtxSsrcs) { |
| 2195 MediaSessionOptions opts; | 2334 MediaSessionOptions opts; |
| 2196 opts.recv_video = true; | 2335 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_SENDRECV, !kStopped, |
| 2197 opts.recv_audio = false; | 2336 &opts); |
| 2198 | |
| 2199 // Add simulcast streams. | 2337 // Add simulcast streams. |
| 2200 opts.AddSendVideoStream("stream1", "stream1label", 3); | 2338 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, "stream1", |
| 2339 "stream1label", 3, &opts); | |
| 2201 | 2340 |
| 2202 // Use a single real codec, and then add RTX for it. | 2341 // Use a single real codec, and then add RTX for it. |
| 2203 std::vector<VideoCodec> f1_codecs; | 2342 std::vector<VideoCodec> f1_codecs; |
| 2204 f1_codecs.push_back(VideoCodec(97, "H264")); | 2343 f1_codecs.push_back(VideoCodec(97, "H264")); |
| 2205 AddRtxCodec(VideoCodec::CreateRtxCodec(125, 97), &f1_codecs); | 2344 AddRtxCodec(VideoCodec::CreateRtxCodec(125, 97), &f1_codecs); |
| 2206 f1_.set_video_codecs(f1_codecs); | 2345 f1_.set_video_codecs(f1_codecs); |
| 2207 | 2346 |
| 2208 // Ensure that the offer has an RTX ssrc for each regular ssrc, and that there | 2347 // Ensure that the offer has an RTX ssrc for each regular ssrc, and that there |
| 2209 // is a FID ssrc + grouping for each. | 2348 // is a FID ssrc + grouping for each. |
| 2210 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 2349 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 2227 EXPECT_EQ(3u, primary_ssrcs.size()); | 2366 EXPECT_EQ(3u, primary_ssrcs.size()); |
| 2228 std::vector<uint32_t> fid_ssrcs; | 2367 std::vector<uint32_t> fid_ssrcs; |
| 2229 streams[0].GetFidSsrcs(primary_ssrcs, &fid_ssrcs); | 2368 streams[0].GetFidSsrcs(primary_ssrcs, &fid_ssrcs); |
| 2230 EXPECT_EQ(3u, fid_ssrcs.size()); | 2369 EXPECT_EQ(3u, fid_ssrcs.size()); |
| 2231 } | 2370 } |
| 2232 | 2371 |
| 2233 // Test that, when the FlexFEC codec is added, a FlexFEC ssrc is created | 2372 // Test that, when the FlexFEC codec is added, a FlexFEC ssrc is created |
| 2234 // together with a FEC-FR grouping. | 2373 // together with a FEC-FR grouping. |
| 2235 TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { | 2374 TEST_F(MediaSessionDescriptionFactoryTest, GenerateFlexfecSsrc) { |
| 2236 MediaSessionOptions opts; | 2375 MediaSessionOptions opts; |
| 2237 opts.recv_video = true; | 2376 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_SENDRECV, !kStopped, |
| 2238 opts.recv_audio = false; | 2377 &opts); |
| 2239 | |
| 2240 // Add single stream. | 2378 // Add single stream. |
| 2241 opts.AddSendVideoStream("stream1", "stream1label", 1); | 2379 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, "stream1", |
| 2380 "stream1label", 1, &opts); | |
| 2242 | 2381 |
| 2243 // Use a single real codec, and then add FlexFEC for it. | 2382 // Use a single real codec, and then add FlexFEC for it. |
| 2244 std::vector<VideoCodec> f1_codecs; | 2383 std::vector<VideoCodec> f1_codecs; |
| 2245 f1_codecs.push_back(VideoCodec(97, "H264")); | 2384 f1_codecs.push_back(VideoCodec(97, "H264")); |
| 2246 f1_codecs.push_back(VideoCodec(118, "flexfec-03")); | 2385 f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
| 2247 f1_.set_video_codecs(f1_codecs); | 2386 f1_.set_video_codecs(f1_codecs); |
| 2248 | 2387 |
| 2249 // Ensure that the offer has a single FlexFEC ssrc and that | 2388 // Ensure that the offer has a single FlexFEC ssrc and that |
| 2250 // there is no FEC-FR ssrc + grouping for each. | 2389 // there is no FEC-FR ssrc + grouping for each. |
| 2251 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | 2390 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2267 uint32_t flexfec_ssrc; | 2406 uint32_t flexfec_ssrc; |
| 2268 EXPECT_TRUE(streams[0].GetFecFrSsrc(primary_ssrcs[0], &flexfec_ssrc)); | 2407 EXPECT_TRUE(streams[0].GetFecFrSsrc(primary_ssrcs[0], &flexfec_ssrc)); |
| 2269 EXPECT_NE(flexfec_ssrc, 0u); | 2408 EXPECT_NE(flexfec_ssrc, 0u); |
| 2270 } | 2409 } |
| 2271 | 2410 |
| 2272 // Test that FlexFEC is disabled for simulcast. | 2411 // Test that FlexFEC is disabled for simulcast. |
| 2273 // TODO(brandtr): Remove this test when we support simulcast, either through | 2412 // TODO(brandtr): Remove this test when we support simulcast, either through |
| 2274 // multiple FlexfecSenders, or through multistream protection. | 2413 // multiple FlexfecSenders, or through multistream protection. |
| 2275 TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { | 2414 TEST_F(MediaSessionDescriptionFactoryTest, SimSsrcsGenerateNoFlexfecSsrcs) { |
| 2276 MediaSessionOptions opts; | 2415 MediaSessionOptions opts; |
| 2277 opts.recv_video = true; | 2416 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_SENDRECV, !kStopped, |
| 2278 opts.recv_audio = false; | 2417 &opts); |
| 2279 | |
| 2280 // Add simulcast streams. | 2418 // Add simulcast streams. |
| 2281 opts.AddSendVideoStream("stream1", "stream1label", 3); | 2419 AttachSenderToMediaSection("video", MEDIA_TYPE_VIDEO, "stream1", |
| 2420 "stream1label", 3, &opts); | |
| 2282 | 2421 |
| 2283 // Use a single real codec, and then add FlexFEC for it. | 2422 // Use a single real codec, and then add FlexFEC for it. |
| 2284 std::vector<VideoCodec> f1_codecs; | 2423 std::vector<VideoCodec> f1_codecs; |
| 2285 f1_codecs.push_back(VideoCodec(97, "H264")); | 2424 f1_codecs.push_back(VideoCodec(97, "H264")); |
| 2286 f1_codecs.push_back(VideoCodec(118, "flexfec-03")); | 2425 f1_codecs.push_back(VideoCodec(118, "flexfec-03")); |
| 2287 f1_.set_video_codecs(f1_codecs); | 2426 f1_.set_video_codecs(f1_codecs); |
| 2288 | 2427 |
| 2289 // Ensure that the offer has no FlexFEC ssrcs for each regular ssrc, and that | 2428 // Ensure that the offer has no FlexFEC ssrcs for each regular ssrc, and that |
| 2290 // there is no FEC-FR ssrc + grouping for each. | 2429 // there is no FEC-FR ssrc + grouping for each. |
| 2291 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | 2430 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2311 EXPECT_FALSE(streams[0].GetFecFrSsrc(primary_ssrc, &flexfec_ssrc)); | 2450 EXPECT_FALSE(streams[0].GetFecFrSsrc(primary_ssrc, &flexfec_ssrc)); |
| 2312 } | 2451 } |
| 2313 } | 2452 } |
| 2314 | 2453 |
| 2315 // Create an updated offer after creating an answer to the original offer and | 2454 // Create an updated offer after creating an answer to the original offer and |
| 2316 // verify that the RTP header extensions that were part of the original answer | 2455 // verify that the RTP header extensions that were part of the original answer |
| 2317 // are not changed in the updated offer. | 2456 // are not changed in the updated offer. |
| 2318 TEST_F(MediaSessionDescriptionFactoryTest, | 2457 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2319 RespondentCreatesOfferAfterCreatingAnswerWithRtpExtensions) { | 2458 RespondentCreatesOfferAfterCreatingAnswerWithRtpExtensions) { |
| 2320 MediaSessionOptions opts; | 2459 MediaSessionOptions opts; |
| 2321 opts.recv_audio = true; | 2460 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 2322 opts.recv_video = true; | |
| 2323 | 2461 |
| 2324 f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); | 2462 f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension1)); |
| 2325 f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); | 2463 f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension1)); |
| 2326 f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); | 2464 f2_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension2)); |
| 2327 f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); | 2465 f2_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension2)); |
| 2328 | 2466 |
| 2329 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 2467 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 2330 std::unique_ptr<SessionDescription> answer( | 2468 std::unique_ptr<SessionDescription> answer( |
| 2331 f2_.CreateAnswer(offer.get(), opts, NULL)); | 2469 f2_.CreateAnswer(offer.get(), opts, NULL)); |
| 2332 | 2470 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2366 GetFirstVideoContentDescription(updated_offer.get()); | 2504 GetFirstVideoContentDescription(updated_offer.get()); |
| 2367 EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoRtpExtensions), | 2505 EXPECT_EQ(MAKE_VECTOR(kUpdatedVideoRtpExtensions), |
| 2368 updated_vcd->rtp_header_extensions()); | 2506 updated_vcd->rtp_header_extensions()); |
| 2369 } | 2507 } |
| 2370 | 2508 |
| 2371 // Verify that if the same RTP extension URI is used for audio and video, the | 2509 // Verify that if the same RTP extension URI is used for audio and video, the |
| 2372 // same ID is used. Also verify that the ID isn't changed when creating an | 2510 // same ID is used. Also verify that the ID isn't changed when creating an |
| 2373 // updated offer (this was previously a bug). | 2511 // updated offer (this was previously a bug). |
| 2374 TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { | 2512 TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReused) { |
| 2375 MediaSessionOptions opts; | 2513 MediaSessionOptions opts; |
| 2376 opts.recv_audio = true; | 2514 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 2377 opts.recv_video = true; | |
| 2378 | 2515 |
| 2379 f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension3)); | 2516 f1_.set_audio_rtp_header_extensions(MAKE_VECTOR(kAudioRtpExtension3)); |
| 2380 f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension3)); | 2517 f1_.set_video_rtp_header_extensions(MAKE_VECTOR(kVideoRtpExtension3)); |
| 2381 | 2518 |
| 2382 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 2519 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| 2383 | 2520 |
| 2384 // Since the audio extensions used ID 3 for "both_audio_and_video", so should | 2521 // Since the audio extensions used ID 3 for "both_audio_and_video", so should |
| 2385 // the video extensions. | 2522 // the video extensions. |
| 2386 const RtpExtension kExpectedVideoRtpExtension[] = { | 2523 const RtpExtension kExpectedVideoRtpExtension[] = { |
| 2387 kVideoRtpExtension3[0], kAudioRtpExtension3[1], | 2524 kVideoRtpExtension3[0], kAudioRtpExtension3[1], |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2402 GetFirstAudioContentDescription( | 2539 GetFirstAudioContentDescription( |
| 2403 updated_offer.get())->rtp_header_extensions()); | 2540 updated_offer.get())->rtp_header_extensions()); |
| 2404 EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), | 2541 EXPECT_EQ(MAKE_VECTOR(kExpectedVideoRtpExtension), |
| 2405 GetFirstVideoContentDescription( | 2542 GetFirstVideoContentDescription( |
| 2406 updated_offer.get())->rtp_header_extensions()); | 2543 updated_offer.get())->rtp_header_extensions()); |
| 2407 } | 2544 } |
| 2408 | 2545 |
| 2409 // Same as "RtpExtensionIdReused" above for encrypted RTP extensions. | 2546 // Same as "RtpExtensionIdReused" above for encrypted RTP extensions. |
| 2410 TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { | 2547 TEST_F(MediaSessionDescriptionFactoryTest, RtpExtensionIdReusedEncrypted) { |
| 2411 MediaSessionOptions opts; | 2548 MediaSessionOptions opts; |
| 2412 opts.recv_audio = true; | 2549 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 2413 opts.recv_video = true; | |
| 2414 | 2550 |
| 2415 f1_.set_enable_encrypted_rtp_header_extensions(true); | 2551 f1_.set_enable_encrypted_rtp_header_extensions(true); |
| 2416 f2_.set_enable_encrypted_rtp_header_extensions(true); | 2552 f2_.set_enable_encrypted_rtp_header_extensions(true); |
| 2417 | 2553 |
| 2418 f1_.set_audio_rtp_header_extensions( | 2554 f1_.set_audio_rtp_header_extensions( |
| 2419 MAKE_VECTOR(kAudioRtpExtension3ForEncryption)); | 2555 MAKE_VECTOR(kAudioRtpExtension3ForEncryption)); |
| 2420 f1_.set_video_rtp_header_extensions( | 2556 f1_.set_video_rtp_header_extensions( |
| 2421 MAKE_VECTOR(kVideoRtpExtension3ForEncryption)); | 2557 MAKE_VECTOR(kVideoRtpExtension3ForEncryption)); |
| 2422 | 2558 |
| 2423 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); | 2559 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, NULL)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2479 const VideoContentDescription* vcd_copy = | 2615 const VideoContentDescription* vcd_copy = |
| 2480 static_cast<const VideoContentDescription*>(vc->description); | 2616 static_cast<const VideoContentDescription*>(vc->description); |
| 2481 EXPECT_EQ(vcd->codecs(), vcd_copy->codecs()); | 2617 EXPECT_EQ(vcd->codecs(), vcd_copy->codecs()); |
| 2482 EXPECT_EQ(2u, vcd->first_ssrc()); | 2618 EXPECT_EQ(2u, vcd->first_ssrc()); |
| 2483 } | 2619 } |
| 2484 | 2620 |
| 2485 // The below TestTransportInfoXXX tests create different offers/answers, and | 2621 // The below TestTransportInfoXXX tests create different offers/answers, and |
| 2486 // ensure the TransportInfo in the SessionDescription matches what we expect. | 2622 // ensure the TransportInfo in the SessionDescription matches what we expect. |
| 2487 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudio) { | 2623 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudio) { |
| 2488 MediaSessionOptions options; | 2624 MediaSessionOptions options; |
| 2489 options.recv_audio = true; | 2625 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 2626 &options); | |
| 2490 TestTransportInfo(true, options, false); | 2627 TestTransportInfo(true, options, false); |
| 2491 } | 2628 } |
| 2492 | 2629 |
| 2493 TEST_F(MediaSessionDescriptionFactoryTest, | 2630 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2494 TestTransportInfoOfferIceRenomination) { | 2631 TestTransportInfoOfferIceRenomination) { |
| 2495 MediaSessionOptions options; | 2632 MediaSessionOptions options; |
| 2496 options.enable_ice_renomination = true; | 2633 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 2634 &options); | |
| 2635 auto media_desc_options_it = | |
| 2636 FindFirstMediaDescriptionByMid("audio", &options); | |
|
Taylor Brandstetter
2017/08/05 00:39:09
nit: Don't really have to look up by MID, since th
Zhi Huang
2017/08/09 00:54:50
Done.
| |
| 2637 media_desc_options_it->transport_options.enable_ice_renomination = true; | |
| 2497 TestTransportInfo(true, options, false); | 2638 TestTransportInfo(true, options, false); |
| 2498 } | 2639 } |
| 2499 | 2640 |
| 2500 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudioCurrent) { | 2641 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferAudioCurrent) { |
| 2501 MediaSessionOptions options; | 2642 MediaSessionOptions options; |
| 2502 options.recv_audio = true; | 2643 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 2644 &options); | |
| 2503 TestTransportInfo(true, options, true); | 2645 TestTransportInfo(true, options, true); |
| 2504 } | 2646 } |
| 2505 | 2647 |
| 2506 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferMultimedia) { | 2648 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferMultimedia) { |
| 2507 MediaSessionOptions options; | 2649 MediaSessionOptions options; |
| 2508 options.recv_audio = true; | 2650 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2509 options.recv_video = true; | 2651 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2510 options.data_channel_type = cricket::DCT_RTP; | |
| 2511 TestTransportInfo(true, options, false); | 2652 TestTransportInfo(true, options, false); |
| 2512 } | 2653 } |
| 2513 | 2654 |
| 2514 TEST_F(MediaSessionDescriptionFactoryTest, | 2655 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2515 TestTransportInfoOfferMultimediaCurrent) { | 2656 TestTransportInfoOfferMultimediaCurrent) { |
| 2516 MediaSessionOptions options; | 2657 MediaSessionOptions options; |
| 2517 options.recv_audio = true; | 2658 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2518 options.recv_video = true; | 2659 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2519 options.data_channel_type = cricket::DCT_RTP; | |
| 2520 TestTransportInfo(true, options, true); | 2660 TestTransportInfo(true, options, true); |
| 2521 } | 2661 } |
| 2522 | 2662 |
| 2523 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferBundle) { | 2663 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoOfferBundle) { |
| 2524 MediaSessionOptions options; | 2664 MediaSessionOptions options; |
| 2525 options.recv_audio = true; | 2665 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2526 options.recv_video = true; | 2666 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2527 options.data_channel_type = cricket::DCT_RTP; | |
| 2528 options.bundle_enabled = true; | 2667 options.bundle_enabled = true; |
| 2529 TestTransportInfo(true, options, false); | 2668 TestTransportInfo(true, options, false); |
| 2530 } | 2669 } |
| 2531 | 2670 |
| 2532 TEST_F(MediaSessionDescriptionFactoryTest, | 2671 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2533 TestTransportInfoOfferBundleCurrent) { | 2672 TestTransportInfoOfferBundleCurrent) { |
| 2534 MediaSessionOptions options; | 2673 MediaSessionOptions options; |
| 2535 options.recv_audio = true; | 2674 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2536 options.recv_video = true; | 2675 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2537 options.data_channel_type = cricket::DCT_RTP; | |
| 2538 options.bundle_enabled = true; | 2676 options.bundle_enabled = true; |
| 2539 TestTransportInfo(true, options, true); | 2677 TestTransportInfo(true, options, true); |
| 2540 } | 2678 } |
| 2541 | 2679 |
| 2542 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerAudio) { | 2680 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerAudio) { |
| 2543 MediaSessionOptions options; | 2681 MediaSessionOptions options; |
| 2544 options.recv_audio = true; | 2682 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 2683 &options); | |
| 2545 TestTransportInfo(false, options, false); | 2684 TestTransportInfo(false, options, false); |
| 2546 } | 2685 } |
| 2547 | 2686 |
| 2548 TEST_F(MediaSessionDescriptionFactoryTest, | 2687 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2549 TestTransportInfoAnswerIceRenomination) { | 2688 TestTransportInfoAnswerIceRenomination) { |
| 2550 MediaSessionOptions options; | 2689 MediaSessionOptions options; |
| 2551 options.enable_ice_renomination = true; | 2690 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 2691 &options); | |
| 2692 auto media_desc_options_it = | |
| 2693 FindFirstMediaDescriptionByMid("audio", &options); | |
|
Taylor Brandstetter
2017/08/05 00:39:09
Same here.
Zhi Huang
2017/08/09 00:54:51
Done.
| |
| 2694 media_desc_options_it->transport_options.enable_ice_renomination = true; | |
| 2552 TestTransportInfo(false, options, false); | 2695 TestTransportInfo(false, options, false); |
| 2553 } | 2696 } |
| 2554 | 2697 |
| 2555 TEST_F(MediaSessionDescriptionFactoryTest, | 2698 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2556 TestTransportInfoAnswerAudioCurrent) { | 2699 TestTransportInfoAnswerAudioCurrent) { |
| 2557 MediaSessionOptions options; | 2700 MediaSessionOptions options; |
| 2558 options.recv_audio = true; | 2701 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_RECVONLY, !kStopped, |
| 2702 &options); | |
| 2559 TestTransportInfo(false, options, true); | 2703 TestTransportInfo(false, options, true); |
| 2560 } | 2704 } |
| 2561 | 2705 |
| 2562 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerMultimedia) { | 2706 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerMultimedia) { |
| 2563 MediaSessionOptions options; | 2707 MediaSessionOptions options; |
| 2564 options.recv_audio = true; | 2708 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2565 options.recv_video = true; | 2709 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2566 options.data_channel_type = cricket::DCT_RTP; | |
| 2567 TestTransportInfo(false, options, false); | 2710 TestTransportInfo(false, options, false); |
| 2568 } | 2711 } |
| 2569 | 2712 |
| 2570 TEST_F(MediaSessionDescriptionFactoryTest, | 2713 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2571 TestTransportInfoAnswerMultimediaCurrent) { | 2714 TestTransportInfoAnswerMultimediaCurrent) { |
| 2572 MediaSessionOptions options; | 2715 MediaSessionOptions options; |
| 2573 options.recv_audio = true; | 2716 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2574 options.recv_video = true; | 2717 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2575 options.data_channel_type = cricket::DCT_RTP; | |
| 2576 TestTransportInfo(false, options, true); | 2718 TestTransportInfo(false, options, true); |
| 2577 } | 2719 } |
| 2578 | 2720 |
| 2579 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerBundle) { | 2721 TEST_F(MediaSessionDescriptionFactoryTest, TestTransportInfoAnswerBundle) { |
| 2580 MediaSessionOptions options; | 2722 MediaSessionOptions options; |
| 2581 options.recv_audio = true; | 2723 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2582 options.recv_video = true; | 2724 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2583 options.data_channel_type = cricket::DCT_RTP; | |
| 2584 options.bundle_enabled = true; | 2725 options.bundle_enabled = true; |
| 2585 TestTransportInfo(false, options, false); | 2726 TestTransportInfo(false, options, false); |
| 2586 } | 2727 } |
| 2587 | 2728 |
| 2588 TEST_F(MediaSessionDescriptionFactoryTest, | 2729 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2589 TestTransportInfoAnswerBundleCurrent) { | 2730 TestTransportInfoAnswerBundleCurrent) { |
| 2590 MediaSessionOptions options; | 2731 MediaSessionOptions options; |
| 2591 options.recv_audio = true; | 2732 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2592 options.recv_video = true; | 2733 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2593 options.data_channel_type = cricket::DCT_RTP; | |
| 2594 options.bundle_enabled = true; | 2734 options.bundle_enabled = true; |
| 2595 TestTransportInfo(false, options, true); | 2735 TestTransportInfo(false, options, true); |
| 2596 } | 2736 } |
| 2597 | 2737 |
| 2598 // Create an offer with bundle enabled and verify the crypto parameters are | 2738 // Create an offer with bundle enabled and verify the crypto parameters are |
| 2599 // the common set of the available cryptos. | 2739 // the common set of the available cryptos. |
| 2600 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithOfferBundle) { | 2740 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithOfferBundle) { |
| 2601 TestCryptoWithBundle(true); | 2741 TestCryptoWithBundle(true); |
| 2602 } | 2742 } |
| 2603 | 2743 |
| 2604 // Create an answer with bundle enabled and verify the crypto parameters are | 2744 // Create an answer with bundle enabled and verify the crypto parameters are |
| 2605 // the common set of the available cryptos. | 2745 // the common set of the available cryptos. |
| 2606 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithAnswerBundle) { | 2746 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoWithAnswerBundle) { |
| 2607 TestCryptoWithBundle(false); | 2747 TestCryptoWithBundle(false); |
| 2608 } | 2748 } |
| 2609 | 2749 |
| 2610 // Verifies that creating answer fails if the offer has UDP/TLS/RTP/SAVPF but | 2750 // Verifies that creating answer fails if the offer has UDP/TLS/RTP/SAVPF but |
| 2611 // DTLS is not enabled locally. | 2751 // DTLS is not enabled locally. |
| 2612 TEST_F(MediaSessionDescriptionFactoryTest, | 2752 TEST_F(MediaSessionDescriptionFactoryTest, |
| 2613 TestOfferDtlsSavpfWithoutDtlsFailed) { | 2753 TestOfferDtlsSavpfWithoutDtlsFailed) { |
| 2614 f1_.set_secure(SEC_ENABLED); | 2754 f1_.set_secure(SEC_ENABLED); |
| 2615 f2_.set_secure(SEC_ENABLED); | 2755 f2_.set_secure(SEC_ENABLED); |
| 2616 tdf1_.set_secure(SEC_DISABLED); | 2756 tdf1_.set_secure(SEC_DISABLED); |
| 2617 tdf2_.set_secure(SEC_DISABLED); | 2757 tdf2_.set_secure(SEC_DISABLED); |
| 2618 | 2758 |
| 2619 std::unique_ptr<SessionDescription> offer( | 2759 std::unique_ptr<SessionDescription> offer( |
| 2620 f1_.CreateOffer(MediaSessionOptions(), NULL)); | 2760 f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL)); |
| 2621 ASSERT_TRUE(offer.get() != NULL); | 2761 ASSERT_TRUE(offer.get() != NULL); |
| 2622 ContentInfo* offer_content = offer->GetContentByName("audio"); | 2762 ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 2623 ASSERT_TRUE(offer_content != NULL); | 2763 ASSERT_TRUE(offer_content != NULL); |
| 2624 AudioContentDescription* offer_audio_desc = | 2764 AudioContentDescription* offer_audio_desc = |
| 2625 static_cast<AudioContentDescription*>(offer_content->description); | 2765 static_cast<AudioContentDescription*>(offer_content->description); |
| 2626 offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); | 2766 offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 2627 | 2767 |
| 2628 std::unique_ptr<SessionDescription> answer( | 2768 std::unique_ptr<SessionDescription> answer( |
| 2629 f2_.CreateAnswer(offer.get(), MediaSessionOptions(), NULL)); | 2769 f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL)); |
| 2630 ASSERT_TRUE(answer != NULL); | 2770 ASSERT_TRUE(answer != NULL); |
| 2631 ContentInfo* answer_content = answer->GetContentByName("audio"); | 2771 ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 2632 ASSERT_TRUE(answer_content != NULL); | 2772 ASSERT_TRUE(answer_content != NULL); |
| 2633 | 2773 |
| 2634 ASSERT_TRUE(answer_content->rejected); | 2774 ASSERT_TRUE(answer_content->rejected); |
| 2635 } | 2775 } |
| 2636 | 2776 |
| 2637 // Offers UDP/TLS/RTP/SAVPF and verifies the answer can be created and contains | 2777 // Offers UDP/TLS/RTP/SAVPF and verifies the answer can be created and contains |
| 2638 // UDP/TLS/RTP/SAVPF. | 2778 // UDP/TLS/RTP/SAVPF. |
| 2639 TEST_F(MediaSessionDescriptionFactoryTest, TestOfferDtlsSavpfCreateAnswer) { | 2779 TEST_F(MediaSessionDescriptionFactoryTest, TestOfferDtlsSavpfCreateAnswer) { |
| 2640 f1_.set_secure(SEC_ENABLED); | 2780 f1_.set_secure(SEC_ENABLED); |
| 2641 f2_.set_secure(SEC_ENABLED); | 2781 f2_.set_secure(SEC_ENABLED); |
| 2642 tdf1_.set_secure(SEC_ENABLED); | 2782 tdf1_.set_secure(SEC_ENABLED); |
| 2643 tdf2_.set_secure(SEC_ENABLED); | 2783 tdf2_.set_secure(SEC_ENABLED); |
| 2644 | 2784 |
| 2645 std::unique_ptr<SessionDescription> offer( | 2785 std::unique_ptr<SessionDescription> offer( |
| 2646 f1_.CreateOffer(MediaSessionOptions(), NULL)); | 2786 f1_.CreateOffer(CreatePlanBMediaSessionOptions(), NULL)); |
| 2647 ASSERT_TRUE(offer.get() != NULL); | 2787 ASSERT_TRUE(offer.get() != NULL); |
| 2648 ContentInfo* offer_content = offer->GetContentByName("audio"); | 2788 ContentInfo* offer_content = offer->GetContentByName("audio"); |
| 2649 ASSERT_TRUE(offer_content != NULL); | 2789 ASSERT_TRUE(offer_content != NULL); |
| 2650 AudioContentDescription* offer_audio_desc = | 2790 AudioContentDescription* offer_audio_desc = |
| 2651 static_cast<AudioContentDescription*>(offer_content->description); | 2791 static_cast<AudioContentDescription*>(offer_content->description); |
| 2652 offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); | 2792 offer_audio_desc->set_protocol(cricket::kMediaProtocolDtlsSavpf); |
| 2653 | 2793 |
| 2654 std::unique_ptr<SessionDescription> answer( | 2794 std::unique_ptr<SessionDescription> answer( |
| 2655 f2_.CreateAnswer(offer.get(), MediaSessionOptions(), NULL)); | 2795 f2_.CreateAnswer(offer.get(), CreatePlanBMediaSessionOptions(), NULL)); |
| 2656 ASSERT_TRUE(answer != NULL); | 2796 ASSERT_TRUE(answer != NULL); |
| 2657 | 2797 |
| 2658 const ContentInfo* answer_content = answer->GetContentByName("audio"); | 2798 const ContentInfo* answer_content = answer->GetContentByName("audio"); |
| 2659 ASSERT_TRUE(answer_content != NULL); | 2799 ASSERT_TRUE(answer_content != NULL); |
| 2660 ASSERT_FALSE(answer_content->rejected); | 2800 ASSERT_FALSE(answer_content->rejected); |
| 2661 | 2801 |
| 2662 const AudioContentDescription* answer_audio_desc = | 2802 const AudioContentDescription* answer_audio_desc = |
| 2663 static_cast<const AudioContentDescription*>(answer_content->description); | 2803 static_cast<const AudioContentDescription*>(answer_content->description); |
| 2664 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), | 2804 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf), |
| 2665 answer_audio_desc->protocol()); | 2805 answer_audio_desc->protocol()); |
| 2666 } | 2806 } |
| 2667 | 2807 |
| 2668 // Test that we include both SDES and DTLS in the offer, but only include SDES | 2808 // Test that we include both SDES and DTLS in the offer, but only include SDES |
| 2669 // in the answer if DTLS isn't negotiated. | 2809 // in the answer if DTLS isn't negotiated. |
| 2670 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoDtls) { | 2810 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoDtls) { |
| 2671 f1_.set_secure(SEC_ENABLED); | 2811 f1_.set_secure(SEC_ENABLED); |
| 2672 f2_.set_secure(SEC_ENABLED); | 2812 f2_.set_secure(SEC_ENABLED); |
| 2673 tdf1_.set_secure(SEC_ENABLED); | 2813 tdf1_.set_secure(SEC_ENABLED); |
| 2674 tdf2_.set_secure(SEC_DISABLED); | 2814 tdf2_.set_secure(SEC_DISABLED); |
| 2675 MediaSessionOptions options; | 2815 MediaSessionOptions options; |
| 2676 options.recv_audio = true; | 2816 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2677 options.recv_video = true; | |
| 2678 std::unique_ptr<SessionDescription> offer, answer; | 2817 std::unique_ptr<SessionDescription> offer, answer; |
| 2679 const cricket::MediaContentDescription* audio_media_desc; | 2818 const cricket::MediaContentDescription* audio_media_desc; |
| 2680 const cricket::MediaContentDescription* video_media_desc; | 2819 const cricket::MediaContentDescription* video_media_desc; |
| 2681 const cricket::TransportDescription* audio_trans_desc; | 2820 const cricket::TransportDescription* audio_trans_desc; |
| 2682 const cricket::TransportDescription* video_trans_desc; | 2821 const cricket::TransportDescription* video_trans_desc; |
| 2683 | 2822 |
| 2684 // Generate an offer with SDES and DTLS support. | 2823 // Generate an offer with SDES and DTLS support. |
| 2685 offer.reset(f1_.CreateOffer(options, NULL)); | 2824 offer.reset(f1_.CreateOffer(options, NULL)); |
| 2686 ASSERT_TRUE(offer.get() != NULL); | 2825 ASSERT_TRUE(offer.get() != NULL); |
| 2687 | 2826 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2763 ASSERT_TRUE(audio_trans_desc != NULL); | 2902 ASSERT_TRUE(audio_trans_desc != NULL); |
| 2764 video_trans_desc = offer->GetTransportDescriptionByName("video"); | 2903 video_trans_desc = offer->GetTransportDescriptionByName("video"); |
| 2765 ASSERT_TRUE(video_trans_desc != NULL); | 2904 ASSERT_TRUE(video_trans_desc != NULL); |
| 2766 ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); | 2905 ASSERT_TRUE(audio_trans_desc->identity_fingerprint.get() != NULL); |
| 2767 ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); | 2906 ASSERT_TRUE(video_trans_desc->identity_fingerprint.get() != NULL); |
| 2768 } | 2907 } |
| 2769 | 2908 |
| 2770 // Test that an answer can't be created if cryptos are required but the offer is | 2909 // Test that an answer can't be created if cryptos are required but the offer is |
| 2771 // unsecure. | 2910 // unsecure. |
| 2772 TEST_F(MediaSessionDescriptionFactoryTest, TestSecureAnswerToUnsecureOffer) { | 2911 TEST_F(MediaSessionDescriptionFactoryTest, TestSecureAnswerToUnsecureOffer) { |
| 2773 MediaSessionOptions options; | 2912 MediaSessionOptions options = CreatePlanBMediaSessionOptions(); |
| 2774 f1_.set_secure(SEC_DISABLED); | 2913 f1_.set_secure(SEC_DISABLED); |
| 2775 tdf1_.set_secure(SEC_DISABLED); | 2914 tdf1_.set_secure(SEC_DISABLED); |
| 2776 f2_.set_secure(SEC_REQUIRED); | 2915 f2_.set_secure(SEC_REQUIRED); |
| 2777 tdf1_.set_secure(SEC_ENABLED); | 2916 tdf1_.set_secure(SEC_ENABLED); |
| 2778 | 2917 |
| 2779 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(options, NULL)); | 2918 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(options, NULL)); |
| 2780 ASSERT_TRUE(offer.get() != NULL); | 2919 ASSERT_TRUE(offer.get() != NULL); |
| 2781 std::unique_ptr<SessionDescription> answer( | 2920 std::unique_ptr<SessionDescription> answer( |
| 2782 f2_.CreateAnswer(offer.get(), options, NULL)); | 2921 f2_.CreateAnswer(offer.get(), options, NULL)); |
| 2783 EXPECT_TRUE(answer.get() == NULL); | 2922 EXPECT_TRUE(answer.get() == NULL); |
| 2784 } | 2923 } |
| 2785 | 2924 |
| 2786 // Test that we accept a DTLS offer without SDES and create an appropriate | 2925 // Test that we accept a DTLS offer without SDES and create an appropriate |
| 2787 // answer. | 2926 // answer. |
| 2788 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { | 2927 TEST_F(MediaSessionDescriptionFactoryTest, TestCryptoOfferDtlsButNotSdes) { |
| 2789 f1_.set_secure(SEC_DISABLED); | 2928 f1_.set_secure(SEC_DISABLED); |
| 2790 f2_.set_secure(SEC_ENABLED); | 2929 f2_.set_secure(SEC_ENABLED); |
| 2791 tdf1_.set_secure(SEC_ENABLED); | 2930 tdf1_.set_secure(SEC_ENABLED); |
| 2792 tdf2_.set_secure(SEC_ENABLED); | 2931 tdf2_.set_secure(SEC_ENABLED); |
| 2793 MediaSessionOptions options; | 2932 MediaSessionOptions options; |
| 2794 options.recv_audio = true; | 2933 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2795 options.recv_video = true; | 2934 AddDataSection(cricket::DCT_RTP, cricket::MD_RECVONLY, &options); |
| 2796 options.data_channel_type = cricket::DCT_RTP; | |
| 2797 | 2935 |
| 2798 std::unique_ptr<SessionDescription> offer, answer; | 2936 std::unique_ptr<SessionDescription> offer, answer; |
| 2799 | 2937 |
| 2800 // Generate an offer with DTLS but without SDES. | 2938 // Generate an offer with DTLS but without SDES. |
| 2801 offer.reset(f1_.CreateOffer(options, NULL)); | 2939 offer.reset(f1_.CreateOffer(options, NULL)); |
| 2802 ASSERT_TRUE(offer.get() != NULL); | 2940 ASSERT_TRUE(offer.get() != NULL); |
| 2803 | 2941 |
| 2804 const AudioContentDescription* audio_offer = | 2942 const AudioContentDescription* audio_offer = |
| 2805 GetFirstAudioContentDescription(offer.get()); | 2943 GetFirstAudioContentDescription(offer.get()); |
| 2806 ASSERT_TRUE(audio_offer->cryptos().empty()); | 2944 ASSERT_TRUE(audio_offer->cryptos().empty()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 2833 EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get() != NULL); | 2971 EXPECT_TRUE(video_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 2834 const cricket::TransportDescription* data_answer_trans_desc = | 2972 const cricket::TransportDescription* data_answer_trans_desc = |
| 2835 answer->GetTransportDescriptionByName("data"); | 2973 answer->GetTransportDescriptionByName("data"); |
| 2836 EXPECT_TRUE(data_answer_trans_desc->identity_fingerprint.get() != NULL); | 2974 EXPECT_TRUE(data_answer_trans_desc->identity_fingerprint.get() != NULL); |
| 2837 } | 2975 } |
| 2838 | 2976 |
| 2839 // Verifies if vad_enabled option is set to false, CN codecs are not present in | 2977 // Verifies if vad_enabled option is set to false, CN codecs are not present in |
| 2840 // offer or answer. | 2978 // offer or answer. |
| 2841 TEST_F(MediaSessionDescriptionFactoryTest, TestVADEnableOption) { | 2979 TEST_F(MediaSessionDescriptionFactoryTest, TestVADEnableOption) { |
| 2842 MediaSessionOptions options; | 2980 MediaSessionOptions options; |
| 2843 options.recv_audio = true; | 2981 AddAudioVideoSections(cricket::MD_RECVONLY, &options); |
| 2844 options.recv_video = true; | |
| 2845 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(options, NULL)); | 2982 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(options, NULL)); |
| 2846 ASSERT_TRUE(offer.get() != NULL); | 2983 ASSERT_TRUE(offer.get() != NULL); |
| 2847 const ContentInfo* audio_content = offer->GetContentByName("audio"); | 2984 const ContentInfo* audio_content = offer->GetContentByName("audio"); |
| 2848 EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); | 2985 EXPECT_FALSE(VerifyNoCNCodecs(audio_content)); |
| 2849 | 2986 |
| 2850 options.vad_enabled = false; | 2987 options.vad_enabled = false; |
| 2851 offer.reset(f1_.CreateOffer(options, NULL)); | 2988 offer.reset(f1_.CreateOffer(options, NULL)); |
| 2852 ASSERT_TRUE(offer.get() != NULL); | 2989 ASSERT_TRUE(offer.get() != NULL); |
| 2853 audio_content = offer->GetContentByName("audio"); | 2990 audio_content = offer->GetContentByName("audio"); |
| 2854 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); | 2991 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
| 2855 std::unique_ptr<SessionDescription> answer( | 2992 std::unique_ptr<SessionDescription> answer( |
| 2856 f1_.CreateAnswer(offer.get(), options, NULL)); | 2993 f1_.CreateAnswer(offer.get(), options, NULL)); |
| 2857 ASSERT_TRUE(answer.get() != NULL); | 2994 ASSERT_TRUE(answer.get() != NULL); |
| 2858 audio_content = answer->GetContentByName("audio"); | 2995 audio_content = answer->GetContentByName("audio"); |
| 2859 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); | 2996 EXPECT_TRUE(VerifyNoCNCodecs(audio_content)); |
| 2860 } | 2997 } |
| 2861 | 2998 |
| 2862 // Test that the content name ("mid" in SDP) is unchanged when creating a | 2999 // Test that the generated MIDs match the existing offer. |
| 2863 // new offer. | 3000 TEST_F(MediaSessionDescriptionFactoryTest, TestMIDsMatchesExistingOffer) { |
| 2864 TEST_F(MediaSessionDescriptionFactoryTest, | |
| 2865 TestContentNameNotChangedInSubsequentOffers) { | |
| 2866 MediaSessionOptions opts; | 3001 MediaSessionOptions opts; |
| 2867 opts.recv_audio = true; | 3002 AddMediaSection(MEDIA_TYPE_AUDIO, "audio_modified", cricket::MD_RECVONLY, |
| 2868 opts.recv_video = true; | 3003 !kStopped, &opts); |
| 3004 AddMediaSection(MEDIA_TYPE_VIDEO, "video_modified", cricket::MD_RECVONLY, | |
| 3005 !kStopped, &opts); | |
| 2869 opts.data_channel_type = cricket::DCT_SCTP; | 3006 opts.data_channel_type = cricket::DCT_SCTP; |
| 2870 // Create offer and modify the default content names. | 3007 AddMediaSection(MEDIA_TYPE_DATA, "data_modified", cricket::MD_SENDRECV, |
| 3008 !kStopped, &opts); | |
| 3009 // Create offer. | |
| 2871 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | 3010 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); |
| 2872 for (ContentInfo& content : offer->contents()) { | |
| 2873 content.name.append("_modified"); | |
| 2874 } | |
| 2875 | |
| 2876 std::unique_ptr<SessionDescription> updated_offer( | 3011 std::unique_ptr<SessionDescription> updated_offer( |
| 2877 f1_.CreateOffer(opts, offer.get())); | 3012 f1_.CreateOffer(opts, offer.get())); |
| 3013 | |
| 2878 const ContentInfo* audio_content = GetFirstAudioContent(updated_offer.get()); | 3014 const ContentInfo* audio_content = GetFirstAudioContent(updated_offer.get()); |
| 2879 const ContentInfo* video_content = GetFirstVideoContent(updated_offer.get()); | 3015 const ContentInfo* video_content = GetFirstVideoContent(updated_offer.get()); |
| 2880 const ContentInfo* data_content = GetFirstDataContent(updated_offer.get()); | 3016 const ContentInfo* data_content = GetFirstDataContent(updated_offer.get()); |
| 2881 ASSERT_TRUE(audio_content != nullptr); | 3017 ASSERT_TRUE(audio_content != nullptr); |
| 2882 ASSERT_TRUE(video_content != nullptr); | 3018 ASSERT_TRUE(video_content != nullptr); |
| 2883 ASSERT_TRUE(data_content != nullptr); | 3019 ASSERT_TRUE(data_content != nullptr); |
| 2884 EXPECT_EQ("audio_modified", audio_content->name); | 3020 EXPECT_EQ("audio_modified", audio_content->name); |
| 2885 EXPECT_EQ("video_modified", video_content->name); | 3021 EXPECT_EQ("video_modified", video_content->name); |
| 2886 EXPECT_EQ("data_modified", data_content->name); | 3022 EXPECT_EQ("data_modified", data_content->name); |
| 2887 } | 3023 } |
| 2888 | 3024 |
| 3025 // The following tests verify that the unified plan SDP is supported. | |
| 3026 // Test that we can create an offer with multiple media sections of same media | |
| 3027 // type. | |
| 3028 TEST_F(MediaSessionDescriptionFactoryTest, | |
| 3029 CreateOfferWithMultipleAVMediaSections) { | |
| 3030 MediaSessionOptions opts = CreateUnifiedPlanMediaSessionOptions(); | |
|
Taylor Brandstetter
2017/08/05 00:39:09
This test has assertions that rely on specific thi
Zhi Huang
2017/08/09 00:54:50
Good to know this. Thanks for the link.
| |
| 3031 | |
| 3032 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | |
| 3033 ASSERT_TRUE(offer); | |
| 3034 | |
| 3035 ASSERT_EQ(4u, offer->contents().size()); | |
| 3036 EXPECT_FALSE(offer->contents()[0].rejected); | |
| 3037 const AudioContentDescription* acd = | |
| 3038 static_cast<const AudioContentDescription*>( | |
| 3039 offer->contents()[0].description); | |
| 3040 ASSERT_EQ(1u, acd->streams().size()); | |
| 3041 EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); | |
| 3042 EXPECT_EQ(cricket::MD_SENDRECV, acd->direction()); | |
| 3043 | |
| 3044 EXPECT_FALSE(offer->contents()[1].rejected); | |
| 3045 const VideoContentDescription* vcd = | |
| 3046 static_cast<const VideoContentDescription*>( | |
| 3047 offer->contents()[1].description); | |
| 3048 ASSERT_EQ(1u, vcd->streams().size()); | |
| 3049 EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); | |
| 3050 EXPECT_EQ(cricket::MD_SENDRECV, vcd->direction()); | |
| 3051 | |
| 3052 EXPECT_FALSE(offer->contents()[2].rejected); | |
| 3053 acd = static_cast<const AudioContentDescription*>( | |
| 3054 offer->contents()[2].description); | |
| 3055 ASSERT_EQ(1u, acd->streams().size()); | |
| 3056 EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); | |
| 3057 EXPECT_EQ(cricket::MD_SENDRECV, acd->direction()); | |
| 3058 | |
| 3059 EXPECT_FALSE(offer->contents()[3].rejected); | |
| 3060 vcd = static_cast<const VideoContentDescription*>( | |
| 3061 offer->contents()[3].description); | |
| 3062 ASSERT_EQ(1u, vcd->streams().size()); | |
| 3063 EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); | |
| 3064 EXPECT_EQ(cricket::MD_SENDRECV, vcd->direction()); | |
| 3065 } | |
| 3066 | |
| 3067 // Test that we can create an answer with multiple media sections of same media | |
| 3068 // type. | |
| 3069 TEST_F(MediaSessionDescriptionFactoryTest, | |
| 3070 CreateAnswerWithMultipleAVMediaSections) { | |
| 3071 MediaSessionOptions opts = CreateUnifiedPlanMediaSessionOptions(); | |
| 3072 | |
| 3073 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | |
| 3074 ASSERT_TRUE(offer); | |
| 3075 std::unique_ptr<SessionDescription> answer( | |
| 3076 f2_.CreateAnswer(offer.get(), opts, nullptr)); | |
| 3077 | |
| 3078 ASSERT_EQ(4u, answer->contents().size()); | |
| 3079 EXPECT_FALSE(answer->contents()[0].rejected); | |
| 3080 const AudioContentDescription* acd = | |
| 3081 static_cast<const AudioContentDescription*>( | |
| 3082 answer->contents()[0].description); | |
| 3083 ASSERT_EQ(1u, acd->streams().size()); | |
| 3084 EXPECT_EQ(kAudioTrack1, acd->streams()[0].id); | |
| 3085 EXPECT_EQ(cricket::MD_SENDRECV, acd->direction()); | |
| 3086 | |
| 3087 EXPECT_FALSE(answer->contents()[1].rejected); | |
| 3088 const VideoContentDescription* vcd = | |
| 3089 static_cast<const VideoContentDescription*>( | |
| 3090 answer->contents()[1].description); | |
| 3091 ASSERT_EQ(1u, vcd->streams().size()); | |
| 3092 EXPECT_EQ(kVideoTrack1, vcd->streams()[0].id); | |
| 3093 EXPECT_EQ(cricket::MD_SENDRECV, vcd->direction()); | |
| 3094 | |
| 3095 EXPECT_FALSE(answer->contents()[2].rejected); | |
| 3096 acd = static_cast<const AudioContentDescription*>( | |
| 3097 answer->contents()[2].description); | |
| 3098 ASSERT_EQ(1u, acd->streams().size()); | |
| 3099 EXPECT_EQ(kAudioTrack2, acd->streams()[0].id); | |
| 3100 EXPECT_EQ(cricket::MD_SENDRECV, acd->direction()); | |
| 3101 | |
| 3102 EXPECT_FALSE(answer->contents()[3].rejected); | |
| 3103 vcd = static_cast<const VideoContentDescription*>( | |
| 3104 answer->contents()[3].description); | |
| 3105 ASSERT_EQ(1u, vcd->streams().size()); | |
| 3106 EXPECT_EQ(kVideoTrack2, vcd->streams()[0].id); | |
| 3107 EXPECT_EQ(cricket::MD_SENDRECV, vcd->direction()); | |
| 3108 } | |
| 3109 | |
| 3110 // Test that the media section will be rejected if the corresponding | |
| 3111 // MediaDescriptionOptions is stopped by the offerer. | |
| 3112 TEST_F(MediaSessionDescriptionFactoryTest, MediaSectionStoppedByOfferer) { | |
| 3113 // Create an offer with two audio sections and one of them is stopped. | |
| 3114 MediaSessionOptions offer_opts; | |
| 3115 AddMediaSection(MEDIA_TYPE_AUDIO, "audio1", cricket::MD_SENDRECV, !kStopped, | |
| 3116 &offer_opts); | |
| 3117 AddMediaSection(MEDIA_TYPE_AUDIO, "audio2", cricket::MD_INACTIVE, kStopped, | |
| 3118 &offer_opts); | |
| 3119 std::unique_ptr<SessionDescription> offer( | |
| 3120 f1_.CreateOffer(offer_opts, nullptr)); | |
| 3121 ASSERT_TRUE(offer); | |
| 3122 ASSERT_EQ(2u, offer->contents().size()); | |
| 3123 EXPECT_FALSE(offer->contents()[0].rejected); | |
| 3124 EXPECT_TRUE(offer->contents()[1].rejected); | |
| 3125 | |
| 3126 // Create an answer based on the offer. | |
|
Taylor Brandstetter
2017/08/05 00:39:09
nit: I think "answer rejects m= section if rejecte
Zhi Huang
2017/08/09 00:54:50
Done.
| |
| 3127 MediaSessionOptions answer_opts; | |
| 3128 AddMediaSection(MEDIA_TYPE_AUDIO, "audio1", cricket::MD_SENDRECV, !kStopped, | |
| 3129 &answer_opts); | |
| 3130 AddMediaSection(MEDIA_TYPE_AUDIO, "audio2", cricket::MD_SENDRECV, !kStopped, | |
| 3131 &answer_opts); | |
| 3132 std::unique_ptr<SessionDescription> answer( | |
| 3133 f2_.CreateAnswer(offer.get(), answer_opts, nullptr)); | |
| 3134 ASSERT_EQ(2u, answer->contents().size()); | |
| 3135 EXPECT_FALSE(answer->contents()[0].rejected); | |
| 3136 EXPECT_TRUE(answer->contents()[1].rejected); | |
| 3137 } | |
| 3138 | |
| 3139 // Test that the media section will be rejected if the corresponding | |
| 3140 // MediaDescriptionOptions is stopped by the answerer. | |
| 3141 TEST_F(MediaSessionDescriptionFactoryTest, MediaSectionRejectedByAnswerer) { | |
| 3142 // Create an offer with two audio sections. | |
| 3143 MediaSessionOptions offer_opts; | |
| 3144 AddMediaSection(MEDIA_TYPE_AUDIO, "audio1", cricket::MD_SENDRECV, !kStopped, | |
| 3145 &offer_opts); | |
| 3146 AddMediaSection(MEDIA_TYPE_AUDIO, "audio2", cricket::MD_SENDRECV, !kStopped, | |
| 3147 &offer_opts); | |
| 3148 std::unique_ptr<SessionDescription> offer( | |
| 3149 f1_.CreateOffer(offer_opts, nullptr)); | |
| 3150 ASSERT_TRUE(offer); | |
| 3151 ASSERT_EQ(2u, offer->contents().size()); | |
| 3152 EXPECT_FALSE(offer->contents()[0].rejected); | |
| 3153 EXPECT_FALSE(offer->contents()[1].rejected); | |
|
Taylor Brandstetter
2017/08/05 00:39:09
nit: Since these aren't the main thing this test i
Zhi Huang
2017/08/09 00:54:50
Done.
| |
| 3154 | |
| 3155 // The answerer rejects one of the audio sections. | |
| 3156 MediaSessionOptions answer_opts; | |
| 3157 AddMediaSection(MEDIA_TYPE_AUDIO, "audio1", cricket::MD_SENDRECV, !kStopped, | |
| 3158 &answer_opts); | |
| 3159 AddMediaSection(MEDIA_TYPE_AUDIO, "audio2", cricket::MD_INACTIVE, kStopped, | |
| 3160 &answer_opts); | |
| 3161 std::unique_ptr<SessionDescription> answer( | |
| 3162 f2_.CreateAnswer(offer.get(), answer_opts, nullptr)); | |
| 3163 ASSERT_EQ(2u, answer->contents().size()); | |
| 3164 EXPECT_FALSE(answer->contents()[0].rejected); | |
| 3165 EXPECT_TRUE(answer->contents()[1].rejected); | |
| 3166 } | |
| 3167 | |
| 3168 // Test the generated media sections has the same order of the | |
| 3169 // corresponding MediaDescriptionOptions. | |
| 3170 TEST_F(MediaSessionDescriptionFactoryTest, TestMediaSectionsOrder) { | |
|
Taylor Brandstetter
2017/08/05 00:39:09
nit: I think having the name "Test" in a test name
Zhi Huang
2017/08/09 00:54:50
Done.
| |
| 3171 MediaSessionOptions opts; | |
| 3172 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_SENDRECV, !kStopped, | |
|
Taylor Brandstetter
2017/08/05 00:39:09
Can you comment that this test puts "video" first,
Zhi Huang
2017/08/09 00:54:51
Done.
| |
| 3173 &opts); | |
| 3174 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", cricket::MD_SENDRECV, !kStopped, | |
| 3175 &opts); | |
| 3176 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | |
| 3177 | |
| 3178 ASSERT_TRUE(offer); | |
| 3179 ASSERT_EQ(2u, offer->contents().size()); | |
| 3180 EXPECT_EQ("video", offer->contents()[0].name); | |
| 3181 EXPECT_EQ("audio", offer->contents()[1].name); | |
| 3182 } | |
| 3183 | |
| 3184 // Test that different media sections using the same codec have same payload | |
| 3185 // type. | |
| 3186 TEST_F(MediaSessionDescriptionFactoryTest, | |
| 3187 TestPayloadTypeOfSameCodecInOfferAnswer) { | |
|
Taylor Brandstetter
2017/08/05 00:39:09
nit: Again, I think "Test" can be removed from the
Zhi Huang
2017/08/09 00:54:51
Done.
| |
| 3188 MediaSessionOptions opts; | |
| 3189 AddMediaSection(MEDIA_TYPE_VIDEO, "video1", cricket::MD_SENDRECV, !kStopped, | |
| 3190 &opts); | |
| 3191 AddMediaSection(MEDIA_TYPE_VIDEO, "video2", cricket::MD_SENDRECV, !kStopped, | |
| 3192 &opts); | |
| 3193 // Create an offer with two video sections using same codecs. | |
| 3194 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | |
| 3195 ASSERT_TRUE(offer); | |
| 3196 ASSERT_EQ(2u, offer->contents().size()); | |
| 3197 const VideoContentDescription* vcd1 = | |
| 3198 static_cast<const VideoContentDescription*>( | |
| 3199 offer->contents()[0].description); | |
| 3200 const VideoContentDescription* vcd2 = | |
| 3201 static_cast<const VideoContentDescription*>( | |
| 3202 offer->contents()[1].description); | |
| 3203 EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); | |
| 3204 ASSERT_EQ(2u, vcd1->codecs().size()); | |
| 3205 EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); | |
| 3206 EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); | |
| 3207 EXPECT_EQ(vcd1->codecs()[1].name, vcd2->codecs()[1].name); | |
| 3208 EXPECT_EQ(vcd1->codecs()[1].id, vcd2->codecs()[1].id); | |
| 3209 | |
| 3210 // Create answer and negotiate the codecs. | |
| 3211 std::unique_ptr<SessionDescription> answer( | |
| 3212 f2_.CreateAnswer(offer.get(), opts, nullptr)); | |
| 3213 ASSERT_TRUE(answer); | |
| 3214 ASSERT_EQ(2u, answer->contents().size()); | |
| 3215 vcd1 = static_cast<const VideoContentDescription*>( | |
| 3216 answer->contents()[0].description); | |
| 3217 vcd2 = static_cast<const VideoContentDescription*>( | |
| 3218 answer->contents()[1].description); | |
| 3219 EXPECT_EQ(vcd1->codecs().size(), vcd2->codecs().size()); | |
| 3220 ASSERT_EQ(1u, vcd1->codecs().size()); | |
| 3221 EXPECT_EQ(vcd1->codecs()[0].name, vcd2->codecs()[0].name); | |
| 3222 EXPECT_EQ(vcd1->codecs()[0].id, vcd2->codecs()[0].id); | |
| 3223 } | |
| 3224 | |
| 2889 class MediaProtocolTest : public ::testing::TestWithParam<const char*> { | 3225 class MediaProtocolTest : public ::testing::TestWithParam<const char*> { |
| 2890 public: | 3226 public: |
| 2891 MediaProtocolTest() : f1_(&tdf1_), f2_(&tdf2_) { | 3227 MediaProtocolTest() : f1_(&tdf1_), f2_(&tdf2_) { |
| 2892 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), | 3228 f1_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs1), |
| 2893 MAKE_VECTOR(kAudioCodecs1)); | 3229 MAKE_VECTOR(kAudioCodecs1)); |
| 2894 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); | 3230 f1_.set_video_codecs(MAKE_VECTOR(kVideoCodecs1)); |
| 2895 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); | 3231 f1_.set_data_codecs(MAKE_VECTOR(kDataCodecs1)); |
| 2896 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), | 3232 f2_.set_audio_codecs(MAKE_VECTOR(kAudioCodecs2), |
| 2897 MAKE_VECTOR(kAudioCodecs2)); | 3233 MAKE_VECTOR(kAudioCodecs2)); |
| 2898 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); | 3234 f2_.set_video_codecs(MAKE_VECTOR(kVideoCodecs2)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2909 | 3245 |
| 2910 protected: | 3246 protected: |
| 2911 MediaSessionDescriptionFactory f1_; | 3247 MediaSessionDescriptionFactory f1_; |
| 2912 MediaSessionDescriptionFactory f2_; | 3248 MediaSessionDescriptionFactory f2_; |
| 2913 TransportDescriptionFactory tdf1_; | 3249 TransportDescriptionFactory tdf1_; |
| 2914 TransportDescriptionFactory tdf2_; | 3250 TransportDescriptionFactory tdf2_; |
| 2915 }; | 3251 }; |
| 2916 | 3252 |
| 2917 TEST_P(MediaProtocolTest, TestAudioVideoAcceptance) { | 3253 TEST_P(MediaProtocolTest, TestAudioVideoAcceptance) { |
| 2918 MediaSessionOptions opts; | 3254 MediaSessionOptions opts; |
| 2919 opts.recv_video = true; | 3255 AddAudioVideoSections(cricket::MD_RECVONLY, &opts); |
| 2920 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); | 3256 std::unique_ptr<SessionDescription> offer(f1_.CreateOffer(opts, nullptr)); |
| 2921 ASSERT_TRUE(offer.get() != nullptr); | 3257 ASSERT_TRUE(offer.get() != nullptr); |
| 2922 // Set the protocol for all the contents. | 3258 // Set the protocol for all the contents. |
| 2923 for (auto content : offer.get()->contents()) { | 3259 for (auto content : offer.get()->contents()) { |
| 2924 static_cast<MediaContentDescription*>(content.description) | 3260 static_cast<MediaContentDescription*>(content.description) |
| 2925 ->set_protocol(GetParam()); | 3261 ->set_protocol(GetParam()); |
| 2926 } | 3262 } |
| 2927 std::unique_ptr<SessionDescription> answer( | 3263 std::unique_ptr<SessionDescription> answer( |
| 2928 f2_.CreateAnswer(offer.get(), opts, nullptr)); | 3264 f2_.CreateAnswer(offer.get(), opts, nullptr)); |
| 2929 const ContentInfo* ac = answer->GetContentByName("audio"); | 3265 const ContentInfo* ac = answer->GetContentByName("audio"); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2969 // Alter iLBC send codec to have zero channels, to test that that is handled | 3305 // Alter iLBC send codec to have zero channels, to test that that is handled |
| 2970 // properly. | 3306 // properly. |
| 2971 send_codecs[1].channels = 0; | 3307 send_codecs[1].channels = 0; |
| 2972 | 3308 |
| 2973 // Alther iLBC receive codec to be lowercase, to test that case conversions | 3309 // Alther iLBC receive codec to be lowercase, to test that case conversions |
| 2974 // are handled properly. | 3310 // are handled properly. |
| 2975 recv_codecs[2].name = "ilbc"; | 3311 recv_codecs[2].name = "ilbc"; |
| 2976 | 3312 |
| 2977 // Test proper merge | 3313 // Test proper merge |
| 2978 sf.set_audio_codecs(send_codecs, recv_codecs); | 3314 sf.set_audio_codecs(send_codecs, recv_codecs); |
| 2979 EXPECT_TRUE(sf.audio_send_codecs() == send_codecs); | 3315 EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 2980 EXPECT_TRUE(sf.audio_recv_codecs() == recv_codecs); | 3316 EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 2981 EXPECT_TRUE(sf.audio_sendrecv_codecs() == sendrecv_codecs); | 3317 EXPECT_EQ(sendrecv_codecs, sf.audio_sendrecv_codecs()); |
| 2982 | 3318 |
| 2983 // Test empty send codecs list | 3319 // Test empty send codecs list |
| 2984 sf.set_audio_codecs(no_codecs, recv_codecs); | 3320 sf.set_audio_codecs(no_codecs, recv_codecs); |
| 2985 EXPECT_TRUE(sf.audio_send_codecs() == no_codecs); | 3321 EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 2986 EXPECT_TRUE(sf.audio_recv_codecs() == recv_codecs); | 3322 EXPECT_EQ(recv_codecs, sf.audio_recv_codecs()); |
| 2987 EXPECT_TRUE(sf.audio_sendrecv_codecs() == no_codecs); | 3323 EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
| 2988 | 3324 |
| 2989 // Test empty recv codecs list | 3325 // Test empty recv codecs list |
| 2990 sf.set_audio_codecs(send_codecs, no_codecs); | 3326 sf.set_audio_codecs(send_codecs, no_codecs); |
| 2991 EXPECT_TRUE(sf.audio_send_codecs() == send_codecs); | 3327 EXPECT_EQ(send_codecs, sf.audio_send_codecs()); |
| 2992 EXPECT_TRUE(sf.audio_recv_codecs() == no_codecs); | 3328 EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 2993 EXPECT_TRUE(sf.audio_sendrecv_codecs() == no_codecs); | 3329 EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
| 2994 | 3330 |
| 2995 // Test all empty codec lists | 3331 // Test all empty codec lists |
| 2996 sf.set_audio_codecs(no_codecs, no_codecs); | 3332 sf.set_audio_codecs(no_codecs, no_codecs); |
| 2997 EXPECT_TRUE(sf.audio_send_codecs() == no_codecs); | 3333 EXPECT_EQ(no_codecs, sf.audio_send_codecs()); |
| 2998 EXPECT_TRUE(sf.audio_recv_codecs() == no_codecs); | 3334 EXPECT_EQ(no_codecs, sf.audio_recv_codecs()); |
| 2999 EXPECT_TRUE(sf.audio_sendrecv_codecs() == no_codecs); | 3335 EXPECT_EQ(no_codecs, sf.audio_sendrecv_codecs()); |
| 3000 } | 3336 } |
| 3001 | 3337 |
| 3002 namespace { | 3338 namespace { |
| 3003 void TestAudioCodecsOffer(MediaContentDirection direction, | 3339 void TestAudioCodecsOffer(MediaContentDirection direction) { |
| 3004 bool add_legacy_stream) { | |
| 3005 TransportDescriptionFactory tdf; | 3340 TransportDescriptionFactory tdf; |
| 3006 MediaSessionDescriptionFactory sf(&tdf); | 3341 MediaSessionDescriptionFactory sf(&tdf); |
| 3007 const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); | 3342 const std::vector<AudioCodec> send_codecs = MAKE_VECTOR(kAudioCodecs1); |
| 3008 const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); | 3343 const std::vector<AudioCodec> recv_codecs = MAKE_VECTOR(kAudioCodecs2); |
| 3009 const std::vector<AudioCodec> sendrecv_codecs = | 3344 const std::vector<AudioCodec> sendrecv_codecs = |
| 3010 MAKE_VECTOR(kAudioCodecsAnswer); | 3345 MAKE_VECTOR(kAudioCodecsAnswer); |
| 3011 sf.set_audio_codecs(send_codecs, recv_codecs); | 3346 sf.set_audio_codecs(send_codecs, recv_codecs); |
| 3012 sf.set_add_legacy_streams(add_legacy_stream); | |
| 3013 | 3347 |
| 3014 MediaSessionOptions opts; | 3348 MediaSessionOptions opts; |
| 3015 opts.recv_audio = (direction == cricket::MD_RECVONLY || | 3349 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", direction, !kStopped, &opts); |
| 3016 direction == cricket::MD_SENDRECV); | 3350 |
| 3017 opts.recv_video = false; | 3351 if (RtpTransceiverDirection::FromMediaContentDirection(direction).send) { |
| 3018 if (direction == cricket::MD_SENDONLY || direction == cricket::MD_SENDRECV) | 3352 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, |
| 3019 opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | 3353 kMediaStream1, 1, &opts); |
| 3354 } | |
| 3020 | 3355 |
| 3021 std::unique_ptr<SessionDescription> offer(sf.CreateOffer(opts, NULL)); | 3356 std::unique_ptr<SessionDescription> offer(sf.CreateOffer(opts, NULL)); |
| 3022 ASSERT_TRUE(offer.get() != NULL); | 3357 ASSERT_TRUE(offer.get() != NULL); |
| 3023 const ContentInfo* ac = offer->GetContentByName("audio"); | 3358 const ContentInfo* ac = offer->GetContentByName("audio"); |
| 3024 | 3359 |
| 3025 // If the factory didn't add any audio content to the offer, we cannot check | 3360 // If the factory didn't add any audio content to the offer, we cannot check |
| 3026 // that the codecs put in are right. This happens when we neither want to send | 3361 // that the codecs put in are right. This happens when we neither want to |
| 3027 // nor receive audio. The checks are still in place if at some point we'd | 3362 // send nor receive audio. The checks are still in place if at some point |
| 3028 // instead create an inactive stream. | 3363 // we'd instead create an inactive stream. |
| 3029 if (ac) { | 3364 if (ac) { |
| 3030 AudioContentDescription* acd = | 3365 AudioContentDescription* acd = |
| 3031 static_cast<AudioContentDescription*>(ac->description); | 3366 static_cast<AudioContentDescription*>(ac->description); |
| 3032 // sendrecv and inactive should both present lists as if the channel was to | 3367 // sendrecv and inactive should both present lists as if the channel was |
| 3033 // be used for sending and receiving. Inactive essentially means it might | 3368 // to be used for sending and receiving. Inactive essentially means it |
| 3034 // eventually be used anything, but we don't know more at this moment. | 3369 // might eventually be used anything, but we don't know more at this |
| 3370 // moment. | |
| 3035 if (acd->direction() == cricket::MD_SENDONLY) { | 3371 if (acd->direction() == cricket::MD_SENDONLY) { |
| 3036 EXPECT_TRUE(acd->codecs() == send_codecs); | 3372 EXPECT_EQ(send_codecs, acd->codecs()); |
| 3037 } else if (acd->direction() == cricket::MD_RECVONLY) { | 3373 } else if (acd->direction() == cricket::MD_RECVONLY) { |
| 3038 EXPECT_TRUE(acd->codecs() == recv_codecs); | 3374 EXPECT_EQ(recv_codecs, acd->codecs()); |
| 3039 } else { | 3375 } else { |
| 3040 EXPECT_TRUE(acd->codecs() == sendrecv_codecs); | 3376 EXPECT_EQ(sendrecv_codecs, acd->codecs()); |
| 3041 } | 3377 } |
| 3042 } | 3378 } |
| 3043 } | 3379 } |
| 3044 | 3380 |
| 3045 static const AudioCodec kOfferAnswerCodecs[] = { | 3381 static const AudioCodec kOfferAnswerCodecs[] = { |
| 3046 AudioCodec(0, "codec0", 16000, -1, 1), | 3382 AudioCodec(0, "codec0", 16000, -1, 1), |
| 3047 AudioCodec(1, "codec1", 8000, 13300, 1), | 3383 AudioCodec(1, "codec1", 8000, 13300, 1), |
| 3048 AudioCodec(2, "codec2", 8000, 64000, 1), | 3384 AudioCodec(2, "codec2", 8000, 64000, 1), |
| 3049 AudioCodec(3, "codec3", 8000, 64000, 1), | 3385 AudioCodec(3, "codec3", 8000, 64000, 1), |
| 3050 AudioCodec(4, "codec4", 8000, 0, 2), | 3386 AudioCodec(4, "codec4", 8000, 0, 2), |
| 3051 AudioCodec(5, "codec5", 32000, 0, 1), | 3387 AudioCodec(5, "codec5", 32000, 0, 1), |
| 3052 AudioCodec(6, "codec6", 48000, 0, 1) | 3388 AudioCodec(6, "codec6", 48000, 0, 1)}; |
| 3053 }; | |
| 3054 | 3389 |
| 3055 | 3390 /* The codecs groups below are chosen as per the matrix below. The objective |
| 3056 /* The codecs groups below are chosen as per the matrix below. The objective is | 3391 * is to have different sets of codecs in the inputs, to get unique sets of |
| 3057 * to have different sets of codecs in the inputs, to get unique sets of codecs | 3392 * codecs after negotiation, depending on offer and answer communication |
| 3058 * after negotiation, depending on offer and answer communication directions. | 3393 * directions. One-way directions in the offer should either result in the |
| 3059 * One-way directions in the offer should either result in the opposite | 3394 * opposite direction in the answer, or an inactive answer. Regardless, the |
| 3060 * direction in the answer, or an inactive answer. Regardless, the choice of | 3395 * choice of codecs should be as if the answer contained the opposite |
| 3061 * codecs should be as if the answer contained the opposite direction. | 3396 * direction. Inactive offers should be treated as sendrecv/sendrecv. |
| 3062 * Inactive offers should be treated as sendrecv/sendrecv. | |
| 3063 * | 3397 * |
| 3064 * | Offer | Answer | Result | 3398 * | Offer | Answer | Result |
| 3065 * codec|send recv sr | send recv sr | s/r r/s sr/s sr/r sr/sr | 3399 * codec|send recv sr | send recv sr | s/r r/s sr/s sr/r sr/sr |
| 3066 * 0 | x - - | - x - | x - - - - | 3400 * 0 | x - - | - x - | x - - - - |
| 3067 * 1 | x x x | - x - | x - - x - | 3401 * 1 | x x x | - x - | x - - x - |
| 3068 * 2 | - x - | x - - | - x - - - | 3402 * 2 | - x - | x - - | - x - - - |
| 3069 * 3 | x x x | x - - | - x x - - | 3403 * 3 | x x x | x - - | - x x - - |
| 3070 * 4 | - x - | x x x | - x - - - | 3404 * 4 | - x - | x x x | - x - - - |
| 3071 * 5 | x - - | x x x | x - - - - | 3405 * 5 | x - - | x x x | x - - - - |
| 3072 * 6 | x x x | x x x | x x x x x | 3406 * 6 | x x x | x x x | x x x x x |
| 3073 */ | 3407 */ |
| 3074 // Codecs used by offerer in the AudioCodecsAnswerTest | 3408 // Codecs used by offerer in the AudioCodecsAnswerTest |
| 3075 static const int kOfferSendCodecs[] = { 0, 1, 3, 5, 6 }; | 3409 static const int kOfferSendCodecs[] = {0, 1, 3, 5, 6}; |
| 3076 static const int kOfferRecvCodecs[] = { 1, 2, 3, 4, 6 }; | 3410 static const int kOfferRecvCodecs[] = {1, 2, 3, 4, 6}; |
| 3077 // Codecs used in the answerer in the AudioCodecsAnswerTest. The order is | 3411 // Codecs used in the answerer in the AudioCodecsAnswerTest. The order is |
| 3078 // jumbled to catch the answer not following the order in the offer. | 3412 // jumbled to catch the answer not following the order in the offer. |
| 3079 static const int kAnswerSendCodecs[] = { 6, 5, 2, 3, 4 }; | 3413 static const int kAnswerSendCodecs[] = {6, 5, 2, 3, 4}; |
| 3080 static const int kAnswerRecvCodecs[] = { 6, 5, 4, 1, 0 }; | 3414 static const int kAnswerRecvCodecs[] = {6, 5, 4, 1, 0}; |
| 3081 // The resulting sets of codecs in the answer in the AudioCodecsAnswerTest | 3415 // The resulting sets of codecs in the answer in the AudioCodecsAnswerTest |
| 3082 static const int kResultSend_RecvCodecs[] = { 0, 1, 5, 6 }; | 3416 static const int kResultSend_RecvCodecs[] = {0, 1, 5, 6}; |
| 3083 static const int kResultRecv_SendCodecs[] = { 2, 3, 4, 6 }; | 3417 static const int kResultRecv_SendCodecs[] = {2, 3, 4, 6}; |
| 3084 static const int kResultSendrecv_SendCodecs[] = { 3, 6 }; | 3418 static const int kResultSendrecv_SendCodecs[] = {3, 6}; |
| 3085 static const int kResultSendrecv_RecvCodecs[] = { 1, 6 }; | 3419 static const int kResultSendrecv_RecvCodecs[] = {1, 6}; |
| 3086 static const int kResultSendrecv_SendrecvCodecs[] = { 6 }; | 3420 static const int kResultSendrecv_SendrecvCodecs[] = {6}; |
| 3087 | 3421 |
| 3088 template <typename T, int IDXS> | 3422 template <typename T, int IDXS> |
| 3089 std::vector<T> VectorFromIndices(const T* array, const int (&indices)[IDXS]) { | 3423 std::vector<T> VectorFromIndices(const T* array, const int (&indices)[IDXS]) { |
| 3090 std::vector<T> out; | 3424 std::vector<T> out; |
| 3091 out.reserve(IDXS); | 3425 out.reserve(IDXS); |
| 3092 for (int idx : indices) | 3426 for (int idx : indices) |
| 3093 out.push_back(array[idx]); | 3427 out.push_back(array[idx]); |
| 3094 | 3428 |
| 3095 return out; | 3429 return out; |
| 3096 } | 3430 } |
| 3097 | 3431 |
| 3098 void TestAudioCodecsAnswer(MediaContentDirection offer_direction, | 3432 void TestAudioCodecsAnswer(MediaContentDirection offer_direction, |
| 3099 MediaContentDirection answer_direction, | 3433 MediaContentDirection answer_direction, |
| 3100 bool add_legacy_stream) { | 3434 bool add_legacy_stream) { |
| 3101 TransportDescriptionFactory offer_tdf; | 3435 TransportDescriptionFactory offer_tdf; |
| 3102 TransportDescriptionFactory answer_tdf; | 3436 TransportDescriptionFactory answer_tdf; |
| 3103 MediaSessionDescriptionFactory offer_factory(&offer_tdf); | 3437 MediaSessionDescriptionFactory offer_factory(&offer_tdf); |
| 3104 MediaSessionDescriptionFactory answer_factory(&answer_tdf); | 3438 MediaSessionDescriptionFactory answer_factory(&answer_tdf); |
| 3105 offer_factory.set_audio_codecs( | 3439 offer_factory.set_audio_codecs( |
| 3106 VectorFromIndices(kOfferAnswerCodecs, kOfferSendCodecs), | 3440 VectorFromIndices(kOfferAnswerCodecs, kOfferSendCodecs), |
| 3107 VectorFromIndices(kOfferAnswerCodecs, kOfferRecvCodecs)); | 3441 VectorFromIndices(kOfferAnswerCodecs, kOfferRecvCodecs)); |
| 3108 answer_factory.set_audio_codecs( | 3442 answer_factory.set_audio_codecs( |
| 3109 VectorFromIndices(kOfferAnswerCodecs, kAnswerSendCodecs), | 3443 VectorFromIndices(kOfferAnswerCodecs, kAnswerSendCodecs), |
| 3110 VectorFromIndices(kOfferAnswerCodecs, kAnswerRecvCodecs)); | 3444 VectorFromIndices(kOfferAnswerCodecs, kAnswerRecvCodecs)); |
| 3111 | 3445 |
| 3112 // Never add a legacy stream to offer - we want to control the offer | |
| 3113 // parameters exactly. | |
| 3114 offer_factory.set_add_legacy_streams(false); | |
| 3115 answer_factory.set_add_legacy_streams(add_legacy_stream); | |
| 3116 MediaSessionOptions offer_opts; | 3446 MediaSessionOptions offer_opts; |
| 3117 offer_opts.recv_audio = (offer_direction == cricket::MD_RECVONLY || | 3447 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", offer_direction, !kStopped, |
| 3118 offer_direction == cricket::MD_SENDRECV); | 3448 &offer_opts); |
| 3119 offer_opts.recv_video = false; | 3449 |
| 3120 if (offer_direction == cricket::MD_SENDONLY || | 3450 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_INACTIVE, kStopped, |
| 3121 offer_direction == cricket::MD_SENDRECV) { | 3451 &offer_opts); |
|
Taylor Brandstetter
2017/08/05 00:39:09
Does this test need a video section at all?
Zhi Huang
2017/08/09 00:54:51
It can be removed (and the one for answer below).
| |
| 3122 offer_opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | 3452 |
| 3453 if (RtpTransceiverDirection::FromMediaContentDirection(offer_direction) | |
| 3454 .send) { | |
| 3455 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, | |
| 3456 kMediaStream1, 1, &offer_opts); | |
| 3123 } | 3457 } |
| 3124 | 3458 |
| 3125 std::unique_ptr<SessionDescription> offer( | 3459 std::unique_ptr<SessionDescription> offer( |
| 3126 offer_factory.CreateOffer(offer_opts, NULL)); | 3460 offer_factory.CreateOffer(offer_opts, NULL)); |
| 3127 ASSERT_TRUE(offer.get() != NULL); | 3461 ASSERT_TRUE(offer.get() != NULL); |
| 3128 | 3462 |
| 3129 MediaSessionOptions answer_opts; | 3463 MediaSessionOptions answer_opts; |
| 3130 answer_opts.recv_audio = (answer_direction == cricket::MD_RECVONLY || | 3464 AddMediaSection(MEDIA_TYPE_AUDIO, "audio", answer_direction, !kStopped, |
| 3131 answer_direction == cricket::MD_SENDRECV); | 3465 &answer_opts); |
| 3132 answer_opts.recv_video = false; | 3466 |
| 3133 if (answer_direction == cricket::MD_SENDONLY || | 3467 AddMediaSection(MEDIA_TYPE_VIDEO, "video", cricket::MD_INACTIVE, kStopped, |
| 3134 answer_direction == cricket::MD_SENDRECV) { | 3468 &answer_opts); |
| 3135 answer_opts.AddSendStream(MEDIA_TYPE_AUDIO, kAudioTrack1, kMediaStream1); | 3469 |
| 3470 if (RtpTransceiverDirection::FromMediaContentDirection(answer_direction) | |
| 3471 .send) { | |
| 3472 AttachSenderToMediaSection("audio", MEDIA_TYPE_AUDIO, kAudioTrack1, | |
| 3473 kMediaStream1, 1, &answer_opts); | |
| 3136 } | 3474 } |
| 3137 std::unique_ptr<SessionDescription> answer( | 3475 std::unique_ptr<SessionDescription> answer( |
| 3138 answer_factory.CreateAnswer(offer.get(), answer_opts, NULL)); | 3476 answer_factory.CreateAnswer(offer.get(), answer_opts, NULL)); |
| 3139 const ContentInfo* ac = answer->GetContentByName("audio"); | 3477 const ContentInfo* ac = answer->GetContentByName("audio"); |
| 3140 | 3478 |
| 3141 // If the factory didn't add any audio content to the answer, we cannot check | 3479 // If the factory didn't add any audio content to the answer, we cannot |
| 3142 // that the codecs put in are right. This happens when we neither want to send | 3480 // check that the codecs put in are right. This happens when we neither want |
| 3143 // nor receive audio. The checks are still in place if at some point we'd | 3481 // to send nor receive audio. The checks are still in place if at some point |
| 3144 // instead create an inactive stream. | 3482 // we'd instead create an inactive stream. |
| 3145 if (ac) { | 3483 if (ac) { |
| 3146 const AudioContentDescription* acd = | 3484 const AudioContentDescription* acd = |
| 3147 static_cast<const AudioContentDescription*>(ac->description); | 3485 static_cast<const AudioContentDescription*>(ac->description); |
| 3148 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); | 3486 EXPECT_EQ(MEDIA_TYPE_AUDIO, acd->type()); |
| 3149 | 3487 |
| 3150 | |
| 3151 std::vector<AudioCodec> target_codecs; | 3488 std::vector<AudioCodec> target_codecs; |
| 3152 // For offers with sendrecv or inactive, we should never reply with more | 3489 // For offers with sendrecv or inactive, we should never reply with more |
| 3153 // codecs than offered, with these codec sets. | 3490 // codecs than offered, with these codec sets. |
| 3154 switch (offer_direction) { | 3491 switch (offer_direction) { |
| 3155 case cricket::MD_INACTIVE: | 3492 case cricket::MD_INACTIVE: |
| 3156 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | 3493 target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 3157 kResultSendrecv_SendrecvCodecs); | 3494 kResultSendrecv_SendrecvCodecs); |
| 3158 break; | 3495 break; |
| 3159 case cricket::MD_SENDONLY: | 3496 case cricket::MD_SENDONLY: |
| 3160 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | 3497 target_codecs = |
| 3161 kResultSend_RecvCodecs); | 3498 VectorFromIndices(kOfferAnswerCodecs, kResultSend_RecvCodecs); |
| 3162 break; | 3499 break; |
| 3163 case cricket::MD_RECVONLY: | 3500 case cricket::MD_RECVONLY: |
| 3164 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | 3501 target_codecs = |
| 3165 kResultRecv_SendCodecs); | 3502 VectorFromIndices(kOfferAnswerCodecs, kResultRecv_SendCodecs); |
| 3166 break; | 3503 break; |
| 3167 case cricket::MD_SENDRECV: | 3504 case cricket::MD_SENDRECV: |
| 3168 if (acd->direction() == cricket::MD_SENDONLY) { | 3505 if (acd->direction() == cricket::MD_SENDONLY) { |
| 3169 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | 3506 target_codecs = |
| 3170 kResultSendrecv_SendCodecs); | 3507 VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_SendCodecs); |
| 3171 } else if (acd->direction() == cricket::MD_RECVONLY) { | 3508 } else if (acd->direction() == cricket::MD_RECVONLY) { |
| 3172 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | 3509 target_codecs = |
| 3173 kResultSendrecv_RecvCodecs); | 3510 VectorFromIndices(kOfferAnswerCodecs, kResultSendrecv_RecvCodecs); |
| 3174 } else { | 3511 } else { |
| 3175 target_codecs = VectorFromIndices(kOfferAnswerCodecs, | 3512 target_codecs = VectorFromIndices(kOfferAnswerCodecs, |
| 3176 kResultSendrecv_SendrecvCodecs); | 3513 kResultSendrecv_SendrecvCodecs); |
| 3177 } | 3514 } |
| 3178 break; | 3515 break; |
| 3179 } | 3516 } |
| 3180 | 3517 |
| 3181 auto format_codecs = [] (const std::vector<AudioCodec>& codecs) { | 3518 auto format_codecs = [](const std::vector<AudioCodec>& codecs) { |
| 3182 std::stringstream os; | 3519 std::stringstream os; |
| 3183 bool first = true; | 3520 bool first = true; |
| 3184 os << "{"; | 3521 os << "{"; |
| 3185 for (const auto& c : codecs) { | 3522 for (const auto& c : codecs) { |
| 3186 os << (first ? " " : ", ") << c.id; | 3523 os << (first ? " " : ", ") << c.id; |
| 3187 first = false; | 3524 first = false; |
| 3188 } | 3525 } |
| 3189 os << " }"; | 3526 os << " }"; |
| 3190 return os.str(); | 3527 return os.str(); |
| 3191 }; | 3528 }; |
| 3192 | 3529 |
| 3193 EXPECT_TRUE(acd->codecs() == target_codecs) | 3530 EXPECT_TRUE(acd->codecs() == target_codecs) |
| 3194 << "Expected: " << format_codecs(target_codecs) | 3531 << "Expected: " << format_codecs(target_codecs) |
| 3195 << ", got: " << format_codecs(acd->codecs()) | 3532 << ", got: " << format_codecs(acd->codecs()) |
| 3196 << "; Offered: " << MediaContentDirectionToString(offer_direction) | 3533 << "; Offered: " << MediaContentDirectionToString(offer_direction) |
| 3197 << ", answerer wants: " | 3534 << ", answerer wants: " |
| 3198 << MediaContentDirectionToString(answer_direction) | 3535 << MediaContentDirectionToString(answer_direction) |
| 3199 << "; got: " << MediaContentDirectionToString(acd->direction()); | 3536 << "; got: " << MediaContentDirectionToString(acd->direction()); |
| 3200 } else { | 3537 } else { |
| 3201 EXPECT_EQ(offer_direction, cricket::MD_INACTIVE) | 3538 EXPECT_EQ(offer_direction, cricket::MD_INACTIVE) |
| 3202 << "Only inactive offers are allowed to not generate any audio content"; | 3539 << "Only inactive offers are allowed to not generate any audio " |
| 3540 "content"; | |
| 3203 } | 3541 } |
| 3204 } | 3542 } |
| 3205 | 3543 |
| 3206 } // namespace | 3544 } // namespace |
| 3207 | 3545 |
| 3208 class AudioCodecsOfferTest | 3546 class AudioCodecsOfferTest |
| 3209 : public ::testing::TestWithParam<::testing::tuple<MediaContentDirection, | 3547 : public ::testing::TestWithParam<MediaContentDirection> {}; |
| 3210 bool>> { | |
| 3211 }; | |
| 3212 | 3548 |
| 3213 TEST_P(AudioCodecsOfferTest, TestCodecsInOffer) { | 3549 TEST_P(AudioCodecsOfferTest, TestCodecsInOffer) { |
| 3214 TestAudioCodecsOffer(::testing::get<0>(GetParam()), | 3550 TestAudioCodecsOffer(GetParam()); |
| 3215 ::testing::get<1>(GetParam())); | |
| 3216 } | 3551 } |
| 3217 | 3552 |
| 3218 INSTANTIATE_TEST_CASE_P(MediaSessionDescriptionFactoryTest, | 3553 INSTANTIATE_TEST_CASE_P(MediaSessionDescriptionFactoryTest, |
| 3219 AudioCodecsOfferTest, | 3554 AudioCodecsOfferTest, |
| 3220 ::testing::Combine( | 3555 ::testing::Values(cricket::MD_SENDONLY, |
| 3221 ::testing::Values(cricket::MD_SENDONLY, | 3556 cricket::MD_RECVONLY, |
| 3222 cricket::MD_RECVONLY, | 3557 cricket::MD_SENDRECV, |
| 3223 cricket::MD_SENDRECV, | 3558 cricket::MD_INACTIVE)); |
| 3224 cricket::MD_INACTIVE), | |
| 3225 ::testing::Bool())); | |
| 3226 | 3559 |
| 3227 class AudioCodecsAnswerTest | 3560 class AudioCodecsAnswerTest |
| 3228 : public ::testing::TestWithParam<::testing::tuple<MediaContentDirection, | 3561 : public ::testing::TestWithParam<::testing::tuple<MediaContentDirection, |
| 3229 MediaContentDirection, | 3562 MediaContentDirection, |
| 3230 bool>> { | 3563 bool>> {}; |
| 3231 }; | |
| 3232 | 3564 |
| 3233 TEST_P(AudioCodecsAnswerTest, TestCodecsInAnswer) { | 3565 TEST_P(AudioCodecsAnswerTest, TestCodecsInAnswer) { |
| 3234 TestAudioCodecsAnswer(::testing::get<0>(GetParam()), | 3566 TestAudioCodecsAnswer(::testing::get<0>(GetParam()), |
| 3235 ::testing::get<1>(GetParam()), | 3567 ::testing::get<1>(GetParam()), |
| 3236 ::testing::get<2>(GetParam())); | 3568 ::testing::get<2>(GetParam())); |
| 3237 } | 3569 } |
| 3238 | 3570 |
| 3239 INSTANTIATE_TEST_CASE_P(MediaSessionDescriptionFactoryTest, | 3571 INSTANTIATE_TEST_CASE_P( |
| 3240 AudioCodecsAnswerTest, | 3572 MediaSessionDescriptionFactoryTest, |
| 3241 ::testing::Combine( | 3573 AudioCodecsAnswerTest, |
| 3242 ::testing::Values(cricket::MD_SENDONLY, | 3574 ::testing::Combine(::testing::Values(cricket::MD_SENDONLY, |
| 3243 cricket::MD_RECVONLY, | 3575 cricket::MD_RECVONLY, |
| 3244 cricket::MD_SENDRECV, | 3576 cricket::MD_SENDRECV, |
| 3245 cricket::MD_INACTIVE), | 3577 cricket::MD_INACTIVE), |
| 3246 ::testing::Values(cricket::MD_SENDONLY, | 3578 ::testing::Values(cricket::MD_SENDONLY, |
| 3247 cricket::MD_RECVONLY, | 3579 cricket::MD_RECVONLY, |
| 3248 cricket::MD_SENDRECV, | 3580 cricket::MD_SENDRECV, |
| 3249 cricket::MD_INACTIVE), | 3581 cricket::MD_INACTIVE), |
| 3250 ::testing::Bool())); | 3582 ::testing::Bool())); |
| OLD | NEW |