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

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

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

Powered by Google App Engine
This is Rietveld 408576698