Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: webrtc/pc/mediasession_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698