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

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

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

Powered by Google App Engine
This is Rietveld 408576698