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

Side by Side Diff: talk/media/webrtc/webrtcvoiceengine_unittest.cc

Issue 1385893002: Remove default receive channel from WVoE; baby step 3. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Don't blow up if unable to set playout on added recv stream Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * libjingle 2 * libjingle
3 * Copyright 2008 Google Inc. 3 * Copyright 2008 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 class WebRtcVoiceEngineTestFake : public testing::Test { 90 class WebRtcVoiceEngineTestFake : public testing::Test {
91 public: 91 public:
92 WebRtcVoiceEngineTestFake() 92 WebRtcVoiceEngineTestFake()
93 : call_(webrtc::Call::Config()), 93 : call_(webrtc::Call::Config()),
94 voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)), 94 voe_(kAudioCodecs, ARRAY_SIZE(kAudioCodecs)),
95 trace_wrapper_(new FakeVoETraceWrapper()), 95 trace_wrapper_(new FakeVoETraceWrapper()),
96 engine_(new FakeVoEWrapper(&voe_), trace_wrapper_), 96 engine_(new FakeVoEWrapper(&voe_), trace_wrapper_),
97 channel_(nullptr) { 97 channel_(nullptr) {
98 send_parameters_.codecs.push_back(kPcmuCodec); 98 send_parameters_.codecs.push_back(kPcmuCodec);
99 recv_parameters_.codecs.push_back(kPcmuCodec); 99 recv_parameters_.codecs.push_back(kPcmuCodec);
100 options_conference_.conference_mode.Set(true);
101 options_adjust_agc_.adjust_agc_delta.Set(-10); 100 options_adjust_agc_.adjust_agc_delta.Set(-10);
102 } 101 }
103 bool SetupEngineWithoutStream() { 102 bool SetupEngine() {
104 if (!engine_.Init(rtc::Thread::Current())) { 103 if (!engine_.Init(rtc::Thread::Current())) {
105 return false; 104 return false;
106 } 105 }
107 channel_ = engine_.CreateChannel(&call_, cricket::AudioOptions()); 106 channel_ = engine_.CreateChannel(&call_, cricket::AudioOptions());
108 return (channel_ != nullptr); 107 return (channel_ != nullptr);
109 } 108 }
110 bool SetupEngine() { 109 bool SetupEngineWithRecvStream() {
111 if (!SetupEngineWithoutStream()) { 110 if (!SetupEngine()) {
111 return false;
112 }
113 return channel_->AddRecvStream(
114 cricket::StreamParams::CreateLegacy(kSsrc1));
115 }
116 bool SetupEngineWithSendStream() {
117 if (!SetupEngine()) {
112 return false; 118 return false;
113 } 119 }
114 return channel_->AddSendStream( 120 return channel_->AddSendStream(
115 cricket::StreamParams::CreateLegacy(kSsrc1)); 121 cricket::StreamParams::CreateLegacy(kSsrc1));
116 } 122 }
117 void SetupForMultiSendStream() { 123 void SetupForMultiSendStream() {
118 EXPECT_TRUE(SetupEngine()); 124 EXPECT_TRUE(SetupEngineWithSendStream());
119 // Remove stream added in Setup, which is corresponding to default channel. 125 // Remove stream added in Setup, which is corresponding to default channel.
120 int default_channel_num = voe_.GetLastChannel(); 126 int default_channel_num = voe_.GetLastChannel();
121 uint32_t default_send_ssrc = 0u; 127 uint32_t default_send_ssrc = 0u;
122 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc)); 128 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
123 EXPECT_EQ(kSsrc1, default_send_ssrc); 129 EXPECT_EQ(kSsrc1, default_send_ssrc);
124 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc)); 130 EXPECT_TRUE(channel_->RemoveSendStream(default_send_ssrc));
125 131
126 // Verify the default channel still exists. 132 // Verify the default channel still exists.
127 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc)); 133 EXPECT_EQ(0, voe_.GetLocalSSRC(default_channel_num, default_send_ssrc));
128 } 134 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 parameters.max_bandwidth_bps = max_bitrate; 205 parameters.max_bandwidth_bps = max_bitrate;
200 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); 206 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters));
201 207
202 int channel_num = voe_.GetLastChannel(); 208 int channel_num = voe_.GetLastChannel();
203 webrtc::CodecInst temp_codec; 209 webrtc::CodecInst temp_codec;
204 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); 210 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
205 EXPECT_EQ(expected_bitrate, temp_codec.rate); 211 EXPECT_EQ(expected_bitrate, temp_codec.rate);
206 } 212 }
207 213
208 void TestSetSendRtpHeaderExtensions(const std::string& ext) { 214 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
209 EXPECT_TRUE(SetupEngineWithoutStream()); 215 EXPECT_TRUE(SetupEngine());
210 int channel_num = voe_.GetLastChannel(); 216 int channel_num = voe_.GetLastChannel();
211 217
212 // Ensure extensions are off by default. 218 // Ensure extensions are off by default.
213 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext)); 219 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
214 220
215 // Ensure unknown extensions won't cause an error. 221 // Ensure unknown extensions won't cause an error.
216 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension( 222 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension(
217 "urn:ietf:params:unknownextention", 1)); 223 "urn:ietf:params:unknownextention", 1));
218 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 224 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
219 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext)); 225 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
(...skipping 21 matching lines...) Expand all
241 247
242 // Ensure all extensions go back off with an empty list. 248 // Ensure all extensions go back off with an empty list.
243 send_parameters_.codecs.push_back(kPcmuCodec); 249 send_parameters_.codecs.push_back(kPcmuCodec);
244 send_parameters_.extensions.clear(); 250 send_parameters_.extensions.clear();
245 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 251 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
246 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext)); 252 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(channel_num, ext));
247 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext)); 253 EXPECT_EQ(-1, voe_.GetSendRtpExtensionId(new_channel_num, ext));
248 } 254 }
249 255
250 void TestSetRecvRtpHeaderExtensions(const std::string& ext) { 256 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
251 EXPECT_TRUE(SetupEngineWithoutStream()); 257 EXPECT_TRUE(SetupEngineWithRecvStream());
252 int channel_num = voe_.GetLastChannel(); 258 int channel_num = voe_.GetLastChannel();
253 259
254 // Ensure extensions are off by default. 260 // Ensure extensions are off by default.
255 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); 261 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
256 262
257 cricket::AudioRecvParameters parameters; 263 cricket::AudioRecvParameters parameters;
258 // Ensure unknown extensions won't cause an error. 264 // Ensure unknown extensions won't cause an error.
259 parameters.extensions.push_back(cricket::RtpHeaderExtension( 265 parameters.extensions.push_back(cricket::RtpHeaderExtension(
260 "urn:ietf:params:unknownextention", 1)); 266 "urn:ietf:params:unknownextention", 1));
261 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 267 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
262 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); 268 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
263 269
264 // Ensure extensions stay off with an empty list of headers. 270 // Ensure extensions stay off with an empty list of headers.
265 parameters.extensions.clear(); 271 parameters.extensions.clear();
266 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 272 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
267 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); 273 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
268 274
269 // Ensure extension is set properly. 275 // Ensure extension is set properly.
270 const int id = 2; 276 const int id = 2;
271 parameters.extensions.push_back(cricket::RtpHeaderExtension(ext, id)); 277 parameters.extensions.push_back(cricket::RtpHeaderExtension(ext, id));
272 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 278 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
273 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext)); 279 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(channel_num, ext));
274 280
275 // Ensure extension is set properly on new channel. 281 // Ensure extension is set properly on new channel.
276 // The first stream to occupy the default channel. 282 // The first stream to occupy the default channel.
277 EXPECT_TRUE(channel_->AddRecvStream( 283 EXPECT_TRUE(channel_->AddRecvStream(
278 cricket::StreamParams::CreateLegacy(345))); 284 cricket::StreamParams::CreateLegacy(kSsrc2)));
279 EXPECT_TRUE(channel_->AddRecvStream(
280 cricket::StreamParams::CreateLegacy(456)));
281 int new_channel_num = voe_.GetLastChannel(); 285 int new_channel_num = voe_.GetLastChannel();
282 EXPECT_NE(channel_num, new_channel_num); 286 EXPECT_NE(channel_num, new_channel_num);
283 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext)); 287 EXPECT_EQ(id, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
284 288
285 // Ensure all extensions go back off with an empty list. 289 // Ensure all extensions go back off with an empty list.
286 parameters.extensions.clear(); 290 parameters.extensions.clear();
287 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 291 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
288 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext)); 292 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(channel_num, ext));
289 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext)); 293 EXPECT_EQ(-1, voe_.GetReceiveRtpExtensionId(new_channel_num, ext));
290 } 294 }
291 295
292 protected: 296 protected:
293 cricket::FakeCall call_; 297 cricket::FakeCall call_;
294 cricket::FakeWebRtcVoiceEngine voe_; 298 cricket::FakeWebRtcVoiceEngine voe_;
295 FakeVoETraceWrapper* trace_wrapper_; 299 FakeVoETraceWrapper* trace_wrapper_;
296 cricket::WebRtcVoiceEngine engine_; 300 cricket::WebRtcVoiceEngine engine_;
297 cricket::VoiceMediaChannel* channel_; 301 cricket::VoiceMediaChannel* channel_;
298 302
299 cricket::AudioSendParameters send_parameters_; 303 cricket::AudioSendParameters send_parameters_;
300 cricket::AudioRecvParameters recv_parameters_; 304 cricket::AudioRecvParameters recv_parameters_;
301 cricket::AudioOptions options_conference_;
302 cricket::AudioOptions options_adjust_agc_; 305 cricket::AudioOptions options_adjust_agc_;
303 }; 306 };
304 307
305 // Tests that our stub library "works". 308 // Tests that our stub library "works".
306 TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) { 309 TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
307 EXPECT_FALSE(voe_.IsInited()); 310 EXPECT_FALSE(voe_.IsInited());
308 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 311 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
309 EXPECT_TRUE(voe_.IsInited()); 312 EXPECT_TRUE(voe_.IsInited());
310 engine_.Terminate(); 313 engine_.Terminate();
311 EXPECT_FALSE(voe_.IsInited()); 314 EXPECT_FALSE(voe_.IsInited());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 codec = kIsacCodec; 377 codec = kIsacCodec;
375 codec.bitrate = 32000; 378 codec.bitrate = 32000;
376 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst)); 379 EXPECT_TRUE(engine_.FindWebRtcCodec(codec, &codec_inst));
377 EXPECT_EQ(codec.id, codec_inst.pltype); 380 EXPECT_EQ(codec.id, codec_inst.pltype);
378 EXPECT_EQ(32000, codec_inst.rate); 381 EXPECT_EQ(32000, codec_inst.rate);
379 } 382 }
380 383
381 // Test that we set our inbound codecs properly, including changing PT. 384 // Test that we set our inbound codecs properly, including changing PT.
382 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) { 385 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
383 EXPECT_TRUE(SetupEngine()); 386 EXPECT_TRUE(SetupEngine());
384 int channel_num = voe_.GetLastChannel();
385 cricket::AudioRecvParameters parameters; 387 cricket::AudioRecvParameters parameters;
386 parameters.codecs.push_back(kIsacCodec); 388 parameters.codecs.push_back(kIsacCodec);
387 parameters.codecs.push_back(kPcmuCodec); 389 parameters.codecs.push_back(kPcmuCodec);
388 parameters.codecs.push_back(kTelephoneEventCodec); 390 parameters.codecs.push_back(kTelephoneEventCodec);
389 parameters.codecs[0].id = 106; // collide with existing telephone-event 391 parameters.codecs[0].id = 106; // collide with existing telephone-event
390 parameters.codecs[2].id = 126; 392 parameters.codecs[2].id = 126;
391 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 393 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
394 EXPECT_TRUE(channel_->AddRecvStream(
395 cricket::StreamParams::CreateLegacy(kSsrc1)));
396 int channel_num = voe_.GetLastChannel();
392 webrtc::CodecInst gcodec; 397 webrtc::CodecInst gcodec;
393 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC"); 398 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
394 gcodec.plfreq = 16000; 399 gcodec.plfreq = 16000;
395 gcodec.channels = 1; 400 gcodec.channels = 1;
396 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); 401 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
397 EXPECT_EQ(106, gcodec.pltype); 402 EXPECT_EQ(106, gcodec.pltype);
398 EXPECT_STREQ("ISAC", gcodec.plname); 403 EXPECT_STREQ("ISAC", gcodec.plname);
399 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), 404 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
400 "telephone-event"); 405 "telephone-event");
401 gcodec.plfreq = 8000; 406 gcodec.plfreq = 8000;
(...skipping 24 matching lines...) Expand all
426 // Test that we can decode OPUS without stereo parameters. 431 // Test that we can decode OPUS without stereo parameters.
427 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) { 432 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
428 EXPECT_TRUE(SetupEngine()); 433 EXPECT_TRUE(SetupEngine());
429 cricket::AudioRecvParameters parameters; 434 cricket::AudioRecvParameters parameters;
430 parameters.codecs.push_back(kIsacCodec); 435 parameters.codecs.push_back(kIsacCodec);
431 parameters.codecs.push_back(kPcmuCodec); 436 parameters.codecs.push_back(kPcmuCodec);
432 parameters.codecs.push_back(kOpusCodec); 437 parameters.codecs.push_back(kOpusCodec);
433 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 438 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
434 EXPECT_TRUE(channel_->AddRecvStream( 439 EXPECT_TRUE(channel_->AddRecvStream(
435 cricket::StreamParams::CreateLegacy(kSsrc1))); 440 cricket::StreamParams::CreateLegacy(kSsrc1)));
436 int channel_num2 = voe_.GetLastChannel(); 441 int channel_num = voe_.GetLastChannel();
437 webrtc::CodecInst opus; 442 webrtc::CodecInst opus;
438 engine_.FindWebRtcCodec(kOpusCodec, &opus); 443 engine_.FindWebRtcCodec(kOpusCodec, &opus);
439 // Even without stereo parameters, recv codecs still specify channels = 2. 444 // Even without stereo parameters, recv codecs still specify channels = 2.
440 EXPECT_EQ(2, opus.channels); 445 EXPECT_EQ(2, opus.channels);
441 EXPECT_EQ(111, opus.pltype); 446 EXPECT_EQ(111, opus.pltype);
442 EXPECT_STREQ("opus", opus.plname); 447 EXPECT_STREQ("opus", opus.plname);
443 opus.pltype = 0; 448 opus.pltype = 0;
444 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); 449 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, opus));
445 EXPECT_EQ(111, opus.pltype); 450 EXPECT_EQ(111, opus.pltype);
446 } 451 }
447 452
448 // Test that we can decode OPUS with stereo = 0. 453 // Test that we can decode OPUS with stereo = 0.
449 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) { 454 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
450 EXPECT_TRUE(SetupEngine()); 455 EXPECT_TRUE(SetupEngine());
451 cricket::AudioRecvParameters parameters; 456 cricket::AudioRecvParameters parameters;
452 parameters.codecs.push_back(kIsacCodec); 457 parameters.codecs.push_back(kIsacCodec);
453 parameters.codecs.push_back(kPcmuCodec); 458 parameters.codecs.push_back(kPcmuCodec);
454 parameters.codecs.push_back(kOpusCodec); 459 parameters.codecs.push_back(kOpusCodec);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), 518 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname),
514 "telephone-event"); 519 "telephone-event");
515 gcodec.plfreq = 8000; 520 gcodec.plfreq = 8000;
516 gcodec.channels = 1; 521 gcodec.channels = 1;
517 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); 522 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
518 EXPECT_EQ(126, gcodec.pltype); 523 EXPECT_EQ(126, gcodec.pltype);
519 EXPECT_STREQ("telephone-event", gcodec.plname); 524 EXPECT_STREQ("telephone-event", gcodec.plname);
520 } 525 }
521 526
522 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) { 527 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
523 EXPECT_TRUE(SetupEngine()); 528 EXPECT_TRUE(SetupEngineWithRecvStream());
524 cricket::AudioRecvParameters parameters; 529 cricket::AudioRecvParameters parameters;
525 parameters.codecs.push_back(kIsacCodec); 530 parameters.codecs.push_back(kIsacCodec);
526 parameters.codecs[0].id = 106; // collide with existing telephone-event 531 parameters.codecs[0].id = 106; // collide with existing telephone-event
527 EXPECT_TRUE(channel_->AddRecvStream(
528 cricket::StreamParams::CreateLegacy(kSsrc1)));
529 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 532 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
530 533
531 int channel_num2 = voe_.GetLastChannel(); 534 int channel_num2 = voe_.GetLastChannel();
532 webrtc::CodecInst gcodec; 535 webrtc::CodecInst gcodec;
533 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC"); 536 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "ISAC");
534 gcodec.plfreq = 16000; 537 gcodec.plfreq = 16000;
535 gcodec.channels = 1; 538 gcodec.channels = 1;
536 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); 539 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
537 EXPECT_EQ(106, gcodec.pltype); 540 EXPECT_EQ(106, gcodec.pltype);
538 EXPECT_STREQ("ISAC", gcodec.plname); 541 EXPECT_STREQ("ISAC", gcodec.plname);
539 } 542 }
540 543
541 // Test that we can apply the same set of codecs again while playing. 544 // Test that we can apply the same set of codecs again while playing.
542 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) { 545 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
543 EXPECT_TRUE(SetupEngine()); 546 EXPECT_TRUE(SetupEngineWithRecvStream());
544 cricket::AudioRecvParameters parameters; 547 cricket::AudioRecvParameters parameters;
545 parameters.codecs.push_back(kIsacCodec); 548 parameters.codecs.push_back(kIsacCodec);
546 parameters.codecs.push_back(kCn16000Codec); 549 parameters.codecs.push_back(kCn16000Codec);
547 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 550 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
548 EXPECT_TRUE(channel_->SetPlayout(true)); 551 EXPECT_TRUE(channel_->SetPlayout(true));
549 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 552 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
550 553
551 // Changing the payload type of a codec should fail. 554 // Changing the payload type of a codec should fail.
552 parameters.codecs[0].id = 127; 555 parameters.codecs[0].id = 127;
553 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); 556 EXPECT_FALSE(channel_->SetRecvParameters(parameters));
554 int channel_num = voe_.GetLastChannel(); 557 int channel_num = voe_.GetLastChannel();
555 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 558 EXPECT_TRUE(voe_.GetPlayout(channel_num));
556 } 559 }
557 560
558 // Test that we can add a codec while playing. 561 // Test that we can add a codec while playing.
559 TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) { 562 TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
560 EXPECT_TRUE(SetupEngine()); 563 EXPECT_TRUE(SetupEngineWithRecvStream());
561 cricket::AudioRecvParameters parameters; 564 cricket::AudioRecvParameters parameters;
562 parameters.codecs.push_back(kIsacCodec); 565 parameters.codecs.push_back(kIsacCodec);
563 parameters.codecs.push_back(kCn16000Codec); 566 parameters.codecs.push_back(kCn16000Codec);
564 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 567 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
565 EXPECT_TRUE(channel_->SetPlayout(true)); 568 EXPECT_TRUE(channel_->SetPlayout(true));
566 569
567 parameters.codecs.push_back(kOpusCodec); 570 parameters.codecs.push_back(kOpusCodec);
568 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 571 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
569 int channel_num = voe_.GetLastChannel(); 572 int channel_num = voe_.GetLastChannel();
570 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 573 EXPECT_TRUE(voe_.GetPlayout(channel_num));
571 webrtc::CodecInst gcodec; 574 webrtc::CodecInst gcodec;
572 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec)); 575 EXPECT_TRUE(engine_.FindWebRtcCodec(kOpusCodec, &gcodec));
573 EXPECT_EQ(kOpusCodec.id, gcodec.pltype); 576 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
574 } 577 }
575 578
576 TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) { 579 TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
577 EXPECT_TRUE(SetupEngine()); 580 EXPECT_TRUE(SetupEngineWithSendStream());
578 581
579 // Test that when autobw is enabled, bitrate is kept as the default 582 // Test that when autobw is enabled, bitrate is kept as the default
580 // value. autobw is enabled for the following tests because the target 583 // value. autobw is enabled for the following tests because the target
581 // bitrate is <= 0. 584 // bitrate is <= 0.
582 585
583 // ISAC, default bitrate == 32000. 586 // ISAC, default bitrate == 32000.
584 TestSendBandwidth(kIsacCodec, 0, true, 32000); 587 TestSendBandwidth(kIsacCodec, 0, true, 32000);
585 588
586 // PCMU, default bitrate == 64000. 589 // PCMU, default bitrate == 64000.
587 TestSendBandwidth(kPcmuCodec, -1, true, 64000); 590 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
588 591
589 // opus, default bitrate == 64000. 592 // opus, default bitrate == 64000.
590 TestSendBandwidth(kOpusCodec, -1, true, 64000); 593 TestSendBandwidth(kOpusCodec, -1, true, 64000);
591 } 594 }
592 595
593 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) { 596 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
594 EXPECT_TRUE(SetupEngine()); 597 EXPECT_TRUE(SetupEngineWithSendStream());
595 598
596 // Test that the bitrate of a multi-rate codec is always the maximum. 599 // Test that the bitrate of a multi-rate codec is always the maximum.
597 600
598 // ISAC, default bitrate == 32000. 601 // ISAC, default bitrate == 32000.
599 TestSendBandwidth(kIsacCodec, 128000, true, 128000); 602 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
600 TestSendBandwidth(kIsacCodec, 16000, true, 16000); 603 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
601 604
602 // opus, default bitrate == 64000. 605 // opus, default bitrate == 64000.
603 TestSendBandwidth(kOpusCodec, 96000, true, 96000); 606 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
604 TestSendBandwidth(kOpusCodec, 48000, true, 48000); 607 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
605 } 608 }
606 609
607 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) { 610 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
608 EXPECT_TRUE(SetupEngine()); 611 EXPECT_TRUE(SetupEngineWithSendStream());
609 612
610 // Test that we can only set a maximum bitrate for a fixed-rate codec 613 // Test that we can only set a maximum bitrate for a fixed-rate codec
611 // if it's bigger than the fixed rate. 614 // if it's bigger than the fixed rate.
612 615
613 // PCMU, fixed bitrate == 64000. 616 // PCMU, fixed bitrate == 64000.
614 TestSendBandwidth(kPcmuCodec, 0, true, 64000); 617 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
615 TestSendBandwidth(kPcmuCodec, 1, false, 64000); 618 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
616 TestSendBandwidth(kPcmuCodec, 128000, true, 64000); 619 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
617 TestSendBandwidth(kPcmuCodec, 32000, false, 64000); 620 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
618 TestSendBandwidth(kPcmuCodec, 64000, true, 64000); 621 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
619 TestSendBandwidth(kPcmuCodec, 63999, false, 64000); 622 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
620 TestSendBandwidth(kPcmuCodec, 64001, true, 64000); 623 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
621 } 624 }
622 625
623 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) { 626 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
624 EXPECT_TRUE(SetupEngineWithoutStream()); 627 EXPECT_TRUE(SetupEngine());
625 const int kDesiredBitrate = 128000; 628 const int kDesiredBitrate = 128000;
626 cricket::AudioSendParameters parameters; 629 cricket::AudioSendParameters parameters;
627 parameters.codecs = engine_.codecs(); 630 parameters.codecs = engine_.codecs();
628 parameters.max_bandwidth_bps = kDesiredBitrate; 631 parameters.max_bandwidth_bps = kDesiredBitrate;
629 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 632 EXPECT_TRUE(channel_->SetSendParameters(parameters));
630 633
631 EXPECT_TRUE(channel_->AddSendStream( 634 EXPECT_TRUE(channel_->AddSendStream(
632 cricket::StreamParams::CreateLegacy(kSsrc1))); 635 cricket::StreamParams::CreateLegacy(kSsrc1)));
633 636
634 int channel_num = voe_.GetLastChannel(); 637 int channel_num = voe_.GetLastChannel();
635 webrtc::CodecInst codec; 638 webrtc::CodecInst codec;
636 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 639 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
637 EXPECT_EQ(kDesiredBitrate, codec.rate); 640 EXPECT_EQ(kDesiredBitrate, codec.rate);
638 } 641 }
639 642
640 // Test that bitrate cannot be set for CBR codecs. 643 // Test that bitrate cannot be set for CBR codecs.
641 // Bitrate is ignored if it is higher than the fixed bitrate. 644 // Bitrate is ignored if it is higher than the fixed bitrate.
642 // Bitrate less then the fixed bitrate is an error. 645 // Bitrate less then the fixed bitrate is an error.
643 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) { 646 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
644 EXPECT_TRUE(SetupEngine()); 647 EXPECT_TRUE(SetupEngineWithSendStream());
645 648
646 // PCMU, default bitrate == 64000. 649 // PCMU, default bitrate == 64000.
647 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 650 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
648 int channel_num = voe_.GetLastChannel(); 651 int channel_num = voe_.GetLastChannel();
649 webrtc::CodecInst codec; 652 webrtc::CodecInst codec;
650 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 653 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
651 EXPECT_EQ(64000, codec.rate); 654 EXPECT_EQ(64000, codec.rate);
652 655
653 send_parameters_.max_bandwidth_bps = 128000; 656 send_parameters_.max_bandwidth_bps = 128000;
654 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 657 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
655 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 658 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
656 EXPECT_EQ(64000, codec.rate); 659 EXPECT_EQ(64000, codec.rate);
657 660
658 send_parameters_.max_bandwidth_bps = 128; 661 send_parameters_.max_bandwidth_bps = 128;
659 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); 662 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_));
660 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 663 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
661 EXPECT_EQ(64000, codec.rate); 664 EXPECT_EQ(64000, codec.rate);
662 } 665 }
663 666
664 // Test that we apply codecs properly. 667 // Test that we apply codecs properly.
665 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { 668 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
666 EXPECT_TRUE(SetupEngine()); 669 EXPECT_TRUE(SetupEngineWithSendStream());
667 cricket::AudioSendParameters parameters; 670 cricket::AudioSendParameters parameters;
668 parameters.codecs.push_back(kIsacCodec); 671 parameters.codecs.push_back(kIsacCodec);
669 parameters.codecs.push_back(kPcmuCodec); 672 parameters.codecs.push_back(kPcmuCodec);
670 parameters.codecs.push_back(kRedCodec); 673 parameters.codecs.push_back(kRedCodec);
671 parameters.codecs[0].id = 96; 674 parameters.codecs[0].id = 96;
672 parameters.codecs[0].bitrate = 48000; 675 parameters.codecs[0].bitrate = 48000;
673 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 676 EXPECT_TRUE(channel_->SetSendParameters(parameters));
674 EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); 677 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
675 int channel_num = voe_.GetLastChannel(); 678 int channel_num = voe_.GetLastChannel();
676 webrtc::CodecInst gcodec; 679 webrtc::CodecInst gcodec;
677 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 680 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
678 EXPECT_EQ(96, gcodec.pltype); 681 EXPECT_EQ(96, gcodec.pltype);
679 EXPECT_EQ(48000, gcodec.rate); 682 EXPECT_EQ(48000, gcodec.rate);
680 EXPECT_STREQ("ISAC", gcodec.plname); 683 EXPECT_STREQ("ISAC", gcodec.plname);
681 EXPECT_FALSE(voe_.GetVAD(channel_num)); 684 EXPECT_FALSE(voe_.GetVAD(channel_num));
682 EXPECT_FALSE(voe_.GetRED(channel_num)); 685 EXPECT_FALSE(voe_.GetRED(channel_num));
683 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); 686 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
684 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true)); 687 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
685 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num)); 688 EXPECT_EQ(106, voe_.GetSendTelephoneEventPayloadType(channel_num));
686 } 689 }
687 690
688 // Test that VoE Channel doesn't call SetSendCodec again if same codec is tried 691 // Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
689 // to apply. 692 // to apply.
690 TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) { 693 TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
691 EXPECT_TRUE(SetupEngine()); 694 EXPECT_TRUE(SetupEngineWithSendStream());
692 cricket::AudioSendParameters parameters; 695 cricket::AudioSendParameters parameters;
693 parameters.codecs.push_back(kIsacCodec); 696 parameters.codecs.push_back(kIsacCodec);
694 parameters.codecs.push_back(kPcmuCodec); 697 parameters.codecs.push_back(kPcmuCodec);
695 parameters.codecs.push_back(kRedCodec); 698 parameters.codecs.push_back(kRedCodec);
696 parameters.codecs[0].id = 96; 699 parameters.codecs[0].id = 96;
697 parameters.codecs[0].bitrate = 48000; 700 parameters.codecs[0].bitrate = 48000;
698 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 701 EXPECT_TRUE(channel_->SetSendParameters(parameters));
699 EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); 702 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
700 // Calling SetSendCodec again with same codec which is already set. 703 // Calling SetSendCodec again with same codec which is already set.
701 // In this case media channel shouldn't send codec to VoE. 704 // In this case media channel shouldn't send codec to VoE.
702 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 705 EXPECT_TRUE(channel_->SetSendParameters(parameters));
703 EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); 706 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
704 } 707 }
705 708
706 // Verify that G722 is set with 16000 samples per second to WebRTC. 709 // Verify that G722 is set with 16000 samples per second to WebRTC.
707 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) { 710 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) {
708 EXPECT_TRUE(SetupEngine()); 711 EXPECT_TRUE(SetupEngineWithSendStream());
709 int channel_num = voe_.GetLastChannel(); 712 int channel_num = voe_.GetLastChannel();
710 cricket::AudioSendParameters parameters; 713 cricket::AudioSendParameters parameters;
711 parameters.codecs.push_back(kG722CodecSdp); 714 parameters.codecs.push_back(kG722CodecSdp);
712 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 715 EXPECT_TRUE(channel_->SetSendParameters(parameters));
713 webrtc::CodecInst gcodec; 716 webrtc::CodecInst gcodec;
714 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 717 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
715 EXPECT_STREQ("G722", gcodec.plname); 718 EXPECT_STREQ("G722", gcodec.plname);
716 EXPECT_EQ(1, gcodec.channels); 719 EXPECT_EQ(1, gcodec.channels);
717 EXPECT_EQ(16000, gcodec.plfreq); 720 EXPECT_EQ(16000, gcodec.plfreq);
718 } 721 }
719 722
720 // Test that if clockrate is not 48000 for opus, we fail. 723 // Test that if clockrate is not 48000 for opus, we fail.
721 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) { 724 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
722 EXPECT_TRUE(SetupEngine()); 725 EXPECT_TRUE(SetupEngineWithSendStream());
723 cricket::AudioSendParameters parameters; 726 cricket::AudioSendParameters parameters;
724 parameters.codecs.push_back(kOpusCodec); 727 parameters.codecs.push_back(kOpusCodec);
725 parameters.codecs[0].bitrate = 0; 728 parameters.codecs[0].bitrate = 0;
726 parameters.codecs[0].clockrate = 50000; 729 parameters.codecs[0].clockrate = 50000;
727 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 730 EXPECT_FALSE(channel_->SetSendParameters(parameters));
728 } 731 }
729 732
730 // Test that if channels=0 for opus, we fail. 733 // Test that if channels=0 for opus, we fail.
731 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) { 734 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
732 EXPECT_TRUE(SetupEngine()); 735 EXPECT_TRUE(SetupEngineWithSendStream());
733 cricket::AudioSendParameters parameters; 736 cricket::AudioSendParameters parameters;
734 parameters.codecs.push_back(kOpusCodec); 737 parameters.codecs.push_back(kOpusCodec);
735 parameters.codecs[0].bitrate = 0; 738 parameters.codecs[0].bitrate = 0;
736 parameters.codecs[0].channels = 0; 739 parameters.codecs[0].channels = 0;
737 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 740 EXPECT_FALSE(channel_->SetSendParameters(parameters));
738 } 741 }
739 742
740 // Test that if channels=0 for opus, we fail. 743 // Test that if channels=0 for opus, we fail.
741 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) { 744 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
742 EXPECT_TRUE(SetupEngine()); 745 EXPECT_TRUE(SetupEngineWithSendStream());
743 cricket::AudioSendParameters parameters; 746 cricket::AudioSendParameters parameters;
744 parameters.codecs.push_back(kOpusCodec); 747 parameters.codecs.push_back(kOpusCodec);
745 parameters.codecs[0].bitrate = 0; 748 parameters.codecs[0].bitrate = 0;
746 parameters.codecs[0].channels = 0; 749 parameters.codecs[0].channels = 0;
747 parameters.codecs[0].params["stereo"] = "1"; 750 parameters.codecs[0].params["stereo"] = "1";
748 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 751 EXPECT_FALSE(channel_->SetSendParameters(parameters));
749 } 752 }
750 753
751 // Test that if channel is 1 for opus and there's no stereo, we fail. 754 // Test that if channel is 1 for opus and there's no stereo, we fail.
752 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) { 755 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
753 EXPECT_TRUE(SetupEngine()); 756 EXPECT_TRUE(SetupEngineWithSendStream());
754 cricket::AudioSendParameters parameters; 757 cricket::AudioSendParameters parameters;
755 parameters.codecs.push_back(kOpusCodec); 758 parameters.codecs.push_back(kOpusCodec);
756 parameters.codecs[0].bitrate = 0; 759 parameters.codecs[0].bitrate = 0;
757 parameters.codecs[0].channels = 1; 760 parameters.codecs[0].channels = 1;
758 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 761 EXPECT_FALSE(channel_->SetSendParameters(parameters));
759 } 762 }
760 763
761 // Test that if channel is 1 for opus and stereo=0, we fail. 764 // Test that if channel is 1 for opus and stereo=0, we fail.
762 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) { 765 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
763 EXPECT_TRUE(SetupEngine()); 766 EXPECT_TRUE(SetupEngineWithSendStream());
764 cricket::AudioSendParameters parameters; 767 cricket::AudioSendParameters parameters;
765 parameters.codecs.push_back(kOpusCodec); 768 parameters.codecs.push_back(kOpusCodec);
766 parameters.codecs[0].bitrate = 0; 769 parameters.codecs[0].bitrate = 0;
767 parameters.codecs[0].channels = 1; 770 parameters.codecs[0].channels = 1;
768 parameters.codecs[0].params["stereo"] = "0"; 771 parameters.codecs[0].params["stereo"] = "0";
769 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 772 EXPECT_FALSE(channel_->SetSendParameters(parameters));
770 } 773 }
771 774
772 // Test that if channel is 1 for opus and stereo=1, we fail. 775 // Test that if channel is 1 for opus and stereo=1, we fail.
773 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) { 776 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
774 EXPECT_TRUE(SetupEngine()); 777 EXPECT_TRUE(SetupEngineWithSendStream());
775 cricket::AudioSendParameters parameters; 778 cricket::AudioSendParameters parameters;
776 parameters.codecs.push_back(kOpusCodec); 779 parameters.codecs.push_back(kOpusCodec);
777 parameters.codecs[0].bitrate = 0; 780 parameters.codecs[0].bitrate = 0;
778 parameters.codecs[0].channels = 1; 781 parameters.codecs[0].channels = 1;
779 parameters.codecs[0].params["stereo"] = "1"; 782 parameters.codecs[0].params["stereo"] = "1";
780 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 783 EXPECT_FALSE(channel_->SetSendParameters(parameters));
781 } 784 }
782 785
783 // Test that with bitrate=0 and no stereo, 786 // Test that with bitrate=0 and no stereo,
784 // channels and bitrate are 1 and 32000. 787 // channels and bitrate are 1 and 32000.
785 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) { 788 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
786 EXPECT_TRUE(SetupEngine()); 789 EXPECT_TRUE(SetupEngineWithSendStream());
787 int channel_num = voe_.GetLastChannel(); 790 int channel_num = voe_.GetLastChannel();
788 cricket::AudioSendParameters parameters; 791 cricket::AudioSendParameters parameters;
789 parameters.codecs.push_back(kOpusCodec); 792 parameters.codecs.push_back(kOpusCodec);
790 parameters.codecs[0].bitrate = 0; 793 parameters.codecs[0].bitrate = 0;
791 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 794 EXPECT_TRUE(channel_->SetSendParameters(parameters));
792 webrtc::CodecInst gcodec; 795 webrtc::CodecInst gcodec;
793 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 796 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
794 EXPECT_STREQ("opus", gcodec.plname); 797 EXPECT_STREQ("opus", gcodec.plname);
795 EXPECT_EQ(1, gcodec.channels); 798 EXPECT_EQ(1, gcodec.channels);
796 EXPECT_EQ(32000, gcodec.rate); 799 EXPECT_EQ(32000, gcodec.rate);
797 } 800 }
798 801
799 // Test that with bitrate=0 and stereo=0, 802 // Test that with bitrate=0 and stereo=0,
800 // channels and bitrate are 1 and 32000. 803 // channels and bitrate are 1 and 32000.
801 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) { 804 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
802 EXPECT_TRUE(SetupEngine()); 805 EXPECT_TRUE(SetupEngineWithSendStream());
803 int channel_num = voe_.GetLastChannel(); 806 int channel_num = voe_.GetLastChannel();
804 cricket::AudioSendParameters parameters; 807 cricket::AudioSendParameters parameters;
805 parameters.codecs.push_back(kOpusCodec); 808 parameters.codecs.push_back(kOpusCodec);
806 parameters.codecs[0].bitrate = 0; 809 parameters.codecs[0].bitrate = 0;
807 parameters.codecs[0].params["stereo"] = "0"; 810 parameters.codecs[0].params["stereo"] = "0";
808 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 811 EXPECT_TRUE(channel_->SetSendParameters(parameters));
809 webrtc::CodecInst gcodec; 812 webrtc::CodecInst gcodec;
810 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 813 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
811 EXPECT_STREQ("opus", gcodec.plname); 814 EXPECT_STREQ("opus", gcodec.plname);
812 EXPECT_EQ(1, gcodec.channels); 815 EXPECT_EQ(1, gcodec.channels);
813 EXPECT_EQ(32000, gcodec.rate); 816 EXPECT_EQ(32000, gcodec.rate);
814 } 817 }
815 818
816 // Test that with bitrate=invalid and stereo=0, 819 // Test that with bitrate=invalid and stereo=0,
817 // channels and bitrate are 1 and 32000. 820 // channels and bitrate are 1 and 32000.
818 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) { 821 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
819 EXPECT_TRUE(SetupEngine()); 822 EXPECT_TRUE(SetupEngineWithSendStream());
820 int channel_num = voe_.GetLastChannel(); 823 int channel_num = voe_.GetLastChannel();
821 cricket::AudioSendParameters parameters; 824 cricket::AudioSendParameters parameters;
822 parameters.codecs.push_back(kOpusCodec); 825 parameters.codecs.push_back(kOpusCodec);
823 parameters.codecs[0].params["stereo"] = "0"; 826 parameters.codecs[0].params["stereo"] = "0";
824 webrtc::CodecInst gcodec; 827 webrtc::CodecInst gcodec;
825 828
826 // bitrate that's out of the range between 6000 and 510000 will be clamped. 829 // bitrate that's out of the range between 6000 and 510000 will be clamped.
827 parameters.codecs[0].bitrate = 5999; 830 parameters.codecs[0].bitrate = 5999;
828 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 831 EXPECT_TRUE(channel_->SetSendParameters(parameters));
829 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 832 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
830 EXPECT_STREQ("opus", gcodec.plname); 833 EXPECT_STREQ("opus", gcodec.plname);
831 EXPECT_EQ(1, gcodec.channels); 834 EXPECT_EQ(1, gcodec.channels);
832 EXPECT_EQ(6000, gcodec.rate); 835 EXPECT_EQ(6000, gcodec.rate);
833 836
834 parameters.codecs[0].bitrate = 510001; 837 parameters.codecs[0].bitrate = 510001;
835 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 838 EXPECT_TRUE(channel_->SetSendParameters(parameters));
836 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 839 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
837 EXPECT_STREQ("opus", gcodec.plname); 840 EXPECT_STREQ("opus", gcodec.plname);
838 EXPECT_EQ(1, gcodec.channels); 841 EXPECT_EQ(1, gcodec.channels);
839 EXPECT_EQ(510000, gcodec.rate); 842 EXPECT_EQ(510000, gcodec.rate);
840 } 843 }
841 844
842 // Test that with bitrate=0 and stereo=1, 845 // Test that with bitrate=0 and stereo=1,
843 // channels and bitrate are 2 and 64000. 846 // channels and bitrate are 2 and 64000.
844 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) { 847 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
845 EXPECT_TRUE(SetupEngine()); 848 EXPECT_TRUE(SetupEngineWithSendStream());
846 int channel_num = voe_.GetLastChannel(); 849 int channel_num = voe_.GetLastChannel();
847 cricket::AudioSendParameters parameters; 850 cricket::AudioSendParameters parameters;
848 parameters.codecs.push_back(kOpusCodec); 851 parameters.codecs.push_back(kOpusCodec);
849 parameters.codecs[0].bitrate = 0; 852 parameters.codecs[0].bitrate = 0;
850 parameters.codecs[0].params["stereo"] = "1"; 853 parameters.codecs[0].params["stereo"] = "1";
851 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 854 EXPECT_TRUE(channel_->SetSendParameters(parameters));
852 webrtc::CodecInst gcodec; 855 webrtc::CodecInst gcodec;
853 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 856 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
854 EXPECT_STREQ("opus", gcodec.plname); 857 EXPECT_STREQ("opus", gcodec.plname);
855 EXPECT_EQ(2, gcodec.channels); 858 EXPECT_EQ(2, gcodec.channels);
856 EXPECT_EQ(64000, gcodec.rate); 859 EXPECT_EQ(64000, gcodec.rate);
857 } 860 }
858 861
859 // Test that with bitrate=invalid and stereo=1, 862 // Test that with bitrate=invalid and stereo=1,
860 // channels and bitrate are 2 and 64000. 863 // channels and bitrate are 2 and 64000.
861 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) { 864 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
862 EXPECT_TRUE(SetupEngine()); 865 EXPECT_TRUE(SetupEngineWithSendStream());
863 int channel_num = voe_.GetLastChannel(); 866 int channel_num = voe_.GetLastChannel();
864 cricket::AudioSendParameters parameters; 867 cricket::AudioSendParameters parameters;
865 parameters.codecs.push_back(kOpusCodec); 868 parameters.codecs.push_back(kOpusCodec);
866 parameters.codecs[0].params["stereo"] = "1"; 869 parameters.codecs[0].params["stereo"] = "1";
867 webrtc::CodecInst gcodec; 870 webrtc::CodecInst gcodec;
868 871
869 // bitrate that's out of the range between 6000 and 510000 will be clamped. 872 // bitrate that's out of the range between 6000 and 510000 will be clamped.
870 parameters.codecs[0].bitrate = 5999; 873 parameters.codecs[0].bitrate = 5999;
871 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 874 EXPECT_TRUE(channel_->SetSendParameters(parameters));
872 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 875 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
873 EXPECT_STREQ("opus", gcodec.plname); 876 EXPECT_STREQ("opus", gcodec.plname);
874 EXPECT_EQ(2, gcodec.channels); 877 EXPECT_EQ(2, gcodec.channels);
875 EXPECT_EQ(6000, gcodec.rate); 878 EXPECT_EQ(6000, gcodec.rate);
876 879
877 parameters.codecs[0].bitrate = 510001; 880 parameters.codecs[0].bitrate = 510001;
878 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 881 EXPECT_TRUE(channel_->SetSendParameters(parameters));
879 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 882 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
880 EXPECT_STREQ("opus", gcodec.plname); 883 EXPECT_STREQ("opus", gcodec.plname);
881 EXPECT_EQ(2, gcodec.channels); 884 EXPECT_EQ(2, gcodec.channels);
882 EXPECT_EQ(510000, gcodec.rate); 885 EXPECT_EQ(510000, gcodec.rate);
883 } 886 }
884 887
885 // Test that with bitrate=N and stereo unset, 888 // Test that with bitrate=N and stereo unset,
886 // channels and bitrate are 1 and N. 889 // channels and bitrate are 1 and N.
887 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) { 890 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
888 EXPECT_TRUE(SetupEngine()); 891 EXPECT_TRUE(SetupEngineWithSendStream());
889 int channel_num = voe_.GetLastChannel(); 892 int channel_num = voe_.GetLastChannel();
890 cricket::AudioSendParameters parameters; 893 cricket::AudioSendParameters parameters;
891 parameters.codecs.push_back(kOpusCodec); 894 parameters.codecs.push_back(kOpusCodec);
892 parameters.codecs[0].bitrate = 96000; 895 parameters.codecs[0].bitrate = 96000;
893 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 896 EXPECT_TRUE(channel_->SetSendParameters(parameters));
894 webrtc::CodecInst gcodec; 897 webrtc::CodecInst gcodec;
895 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 898 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
896 EXPECT_EQ(111, gcodec.pltype); 899 EXPECT_EQ(111, gcodec.pltype);
897 EXPECT_EQ(96000, gcodec.rate); 900 EXPECT_EQ(96000, gcodec.rate);
898 EXPECT_STREQ("opus", gcodec.plname); 901 EXPECT_STREQ("opus", gcodec.plname);
899 EXPECT_EQ(1, gcodec.channels); 902 EXPECT_EQ(1, gcodec.channels);
900 EXPECT_EQ(48000, gcodec.plfreq); 903 EXPECT_EQ(48000, gcodec.plfreq);
901 } 904 }
902 905
903 // Test that with bitrate=N and stereo=0, 906 // Test that with bitrate=N and stereo=0,
904 // channels and bitrate are 1 and N. 907 // channels and bitrate are 1 and N.
905 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) { 908 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
906 EXPECT_TRUE(SetupEngine()); 909 EXPECT_TRUE(SetupEngineWithSendStream());
907 int channel_num = voe_.GetLastChannel(); 910 int channel_num = voe_.GetLastChannel();
908 cricket::AudioSendParameters parameters; 911 cricket::AudioSendParameters parameters;
909 parameters.codecs.push_back(kOpusCodec); 912 parameters.codecs.push_back(kOpusCodec);
910 parameters.codecs[0].bitrate = 30000; 913 parameters.codecs[0].bitrate = 30000;
911 parameters.codecs[0].params["stereo"] = "0"; 914 parameters.codecs[0].params["stereo"] = "0";
912 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 915 EXPECT_TRUE(channel_->SetSendParameters(parameters));
913 webrtc::CodecInst gcodec; 916 webrtc::CodecInst gcodec;
914 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 917 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
915 EXPECT_EQ(1, gcodec.channels); 918 EXPECT_EQ(1, gcodec.channels);
916 EXPECT_EQ(30000, gcodec.rate); 919 EXPECT_EQ(30000, gcodec.rate);
917 EXPECT_STREQ("opus", gcodec.plname); 920 EXPECT_STREQ("opus", gcodec.plname);
918 } 921 }
919 922
920 // Test that with bitrate=N and without any parameters, 923 // Test that with bitrate=N and without any parameters,
921 // channels and bitrate are 1 and N. 924 // channels and bitrate are 1 and N.
922 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) { 925 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
923 EXPECT_TRUE(SetupEngine()); 926 EXPECT_TRUE(SetupEngineWithSendStream());
924 int channel_num = voe_.GetLastChannel(); 927 int channel_num = voe_.GetLastChannel();
925 cricket::AudioSendParameters parameters; 928 cricket::AudioSendParameters parameters;
926 parameters.codecs.push_back(kOpusCodec); 929 parameters.codecs.push_back(kOpusCodec);
927 parameters.codecs[0].bitrate = 30000; 930 parameters.codecs[0].bitrate = 30000;
928 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 931 EXPECT_TRUE(channel_->SetSendParameters(parameters));
929 webrtc::CodecInst gcodec; 932 webrtc::CodecInst gcodec;
930 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 933 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
931 EXPECT_EQ(1, gcodec.channels); 934 EXPECT_EQ(1, gcodec.channels);
932 EXPECT_EQ(30000, gcodec.rate); 935 EXPECT_EQ(30000, gcodec.rate);
933 EXPECT_STREQ("opus", gcodec.plname); 936 EXPECT_STREQ("opus", gcodec.plname);
934 } 937 }
935 938
936 // Test that with bitrate=N and stereo=1, 939 // Test that with bitrate=N and stereo=1,
937 // channels and bitrate are 2 and N. 940 // channels and bitrate are 2 and N.
938 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) { 941 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
939 EXPECT_TRUE(SetupEngine()); 942 EXPECT_TRUE(SetupEngineWithSendStream());
940 int channel_num = voe_.GetLastChannel(); 943 int channel_num = voe_.GetLastChannel();
941 cricket::AudioSendParameters parameters; 944 cricket::AudioSendParameters parameters;
942 parameters.codecs.push_back(kOpusCodec); 945 parameters.codecs.push_back(kOpusCodec);
943 parameters.codecs[0].bitrate = 30000; 946 parameters.codecs[0].bitrate = 30000;
944 parameters.codecs[0].params["stereo"] = "1"; 947 parameters.codecs[0].params["stereo"] = "1";
945 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 948 EXPECT_TRUE(channel_->SetSendParameters(parameters));
946 webrtc::CodecInst gcodec; 949 webrtc::CodecInst gcodec;
947 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 950 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
948 EXPECT_EQ(2, gcodec.channels); 951 EXPECT_EQ(2, gcodec.channels);
949 EXPECT_EQ(30000, gcodec.rate); 952 EXPECT_EQ(30000, gcodec.rate);
950 EXPECT_STREQ("opus", gcodec.plname); 953 EXPECT_STREQ("opus", gcodec.plname);
951 } 954 }
952 955
953 // Test that bitrate will be overridden by the "maxaveragebitrate" parameter. 956 // Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
954 // Also test that the "maxaveragebitrate" can't be set to values outside the 957 // Also test that the "maxaveragebitrate" can't be set to values outside the
955 // range of 6000 and 510000 958 // range of 6000 and 510000
956 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) { 959 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
957 EXPECT_TRUE(SetupEngine()); 960 EXPECT_TRUE(SetupEngineWithSendStream());
958 int channel_num = voe_.GetLastChannel(); 961 int channel_num = voe_.GetLastChannel();
959 cricket::AudioSendParameters parameters; 962 cricket::AudioSendParameters parameters;
960 parameters.codecs.push_back(kOpusCodec); 963 parameters.codecs.push_back(kOpusCodec);
961 parameters.codecs[0].bitrate = 30000; 964 parameters.codecs[0].bitrate = 30000;
962 webrtc::CodecInst gcodec; 965 webrtc::CodecInst gcodec;
963 966
964 // Ignore if less than 6000. 967 // Ignore if less than 6000.
965 parameters.codecs[0].params["maxaveragebitrate"] = "5999"; 968 parameters.codecs[0].params["maxaveragebitrate"] = "5999";
966 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 969 EXPECT_TRUE(channel_->SetSendParameters(parameters));
967 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 970 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
968 EXPECT_EQ(6000, gcodec.rate); 971 EXPECT_EQ(6000, gcodec.rate);
969 972
970 // Ignore if larger than 510000. 973 // Ignore if larger than 510000.
971 parameters.codecs[0].params["maxaveragebitrate"] = "510001"; 974 parameters.codecs[0].params["maxaveragebitrate"] = "510001";
972 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 975 EXPECT_TRUE(channel_->SetSendParameters(parameters));
973 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 976 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
974 EXPECT_EQ(510000, gcodec.rate); 977 EXPECT_EQ(510000, gcodec.rate);
975 978
976 parameters.codecs[0].params["maxaveragebitrate"] = "200000"; 979 parameters.codecs[0].params["maxaveragebitrate"] = "200000";
977 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 980 EXPECT_TRUE(channel_->SetSendParameters(parameters));
978 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 981 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
979 EXPECT_EQ(200000, gcodec.rate); 982 EXPECT_EQ(200000, gcodec.rate);
980 } 983 }
981 984
982 // Test that we can enable NACK with opus as caller. 985 // Test that we can enable NACK with opus as caller.
983 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) { 986 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
984 EXPECT_TRUE(SetupEngine()); 987 EXPECT_TRUE(SetupEngineWithSendStream());
985 int channel_num = voe_.GetLastChannel(); 988 int channel_num = voe_.GetLastChannel();
986 cricket::AudioSendParameters parameters; 989 cricket::AudioSendParameters parameters;
987 parameters.codecs.push_back(kOpusCodec); 990 parameters.codecs.push_back(kOpusCodec);
988 parameters.codecs[0].AddFeedbackParam( 991 parameters.codecs[0].AddFeedbackParam(
989 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 992 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
990 cricket::kParamValueEmpty)); 993 cricket::kParamValueEmpty));
991 EXPECT_FALSE(voe_.GetNACK(channel_num)); 994 EXPECT_FALSE(voe_.GetNACK(channel_num));
992 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 995 EXPECT_TRUE(channel_->SetSendParameters(parameters));
993 EXPECT_TRUE(voe_.GetNACK(channel_num)); 996 EXPECT_TRUE(voe_.GetNACK(channel_num));
994 } 997 }
995 998
996 // Test that we can enable NACK with opus as callee. 999 // Test that we can enable NACK with opus as callee.
997 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) { 1000 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
998 EXPECT_TRUE(SetupEngineWithoutStream()); 1001 EXPECT_TRUE(SetupEngine());
999 int channel_num = voe_.GetLastChannel(); 1002 int channel_num = voe_.GetLastChannel();
1000 cricket::AudioSendParameters parameters; 1003 cricket::AudioSendParameters parameters;
1001 parameters.codecs.push_back(kOpusCodec); 1004 parameters.codecs.push_back(kOpusCodec);
1002 parameters.codecs[0].AddFeedbackParam( 1005 parameters.codecs[0].AddFeedbackParam(
1003 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1006 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1004 cricket::kParamValueEmpty)); 1007 cricket::kParamValueEmpty));
1005 EXPECT_FALSE(voe_.GetNACK(channel_num)); 1008 EXPECT_FALSE(voe_.GetNACK(channel_num));
1006 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1009 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1007 EXPECT_FALSE(voe_.GetNACK(channel_num)); 1010 EXPECT_FALSE(voe_.GetNACK(channel_num));
1008 1011
1009 EXPECT_TRUE(channel_->AddSendStream( 1012 EXPECT_TRUE(channel_->AddSendStream(
1010 cricket::StreamParams::CreateLegacy(kSsrc1))); 1013 cricket::StreamParams::CreateLegacy(kSsrc1)));
1011 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1014 EXPECT_TRUE(voe_.GetNACK(channel_num));
1012 } 1015 }
1013 1016
1014 // Test that we can enable NACK on receive streams. 1017 // Test that we can enable NACK on receive streams.
1015 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) { 1018 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1016 EXPECT_TRUE(SetupEngine()); 1019 EXPECT_TRUE(SetupEngineWithSendStream());
1017 int channel_num1 = voe_.GetLastChannel(); 1020 int channel_num1 = voe_.GetLastChannel();
1018 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 1021 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1019 int channel_num2 = voe_.GetLastChannel(); 1022 int channel_num2 = voe_.GetLastChannel();
1020 cricket::AudioSendParameters parameters; 1023 cricket::AudioSendParameters parameters;
1021 parameters.codecs.push_back(kOpusCodec); 1024 parameters.codecs.push_back(kOpusCodec);
1022 parameters.codecs[0].AddFeedbackParam( 1025 parameters.codecs[0].AddFeedbackParam(
1023 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1026 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1024 cricket::kParamValueEmpty)); 1027 cricket::kParamValueEmpty));
1025 EXPECT_FALSE(voe_.GetNACK(channel_num1)); 1028 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1026 EXPECT_FALSE(voe_.GetNACK(channel_num2)); 1029 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1027 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1030 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1028 EXPECT_TRUE(voe_.GetNACK(channel_num1)); 1031 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1029 EXPECT_TRUE(voe_.GetNACK(channel_num2)); 1032 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1030 } 1033 }
1031 1034
1032 // Test that we can disable NACK. 1035 // Test that we can disable NACK.
1033 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) { 1036 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1034 EXPECT_TRUE(SetupEngine()); 1037 EXPECT_TRUE(SetupEngineWithSendStream());
1035 int channel_num = voe_.GetLastChannel(); 1038 int channel_num = voe_.GetLastChannel();
1036 cricket::AudioSendParameters parameters; 1039 cricket::AudioSendParameters parameters;
1037 parameters.codecs.push_back(kOpusCodec); 1040 parameters.codecs.push_back(kOpusCodec);
1038 parameters.codecs[0].AddFeedbackParam( 1041 parameters.codecs[0].AddFeedbackParam(
1039 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1042 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1040 cricket::kParamValueEmpty)); 1043 cricket::kParamValueEmpty));
1041 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1044 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1042 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1045 EXPECT_TRUE(voe_.GetNACK(channel_num));
1043 1046
1044 parameters.codecs.clear(); 1047 parameters.codecs.clear();
1045 parameters.codecs.push_back(kOpusCodec); 1048 parameters.codecs.push_back(kOpusCodec);
1046 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1049 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1047 EXPECT_FALSE(voe_.GetNACK(channel_num)); 1050 EXPECT_FALSE(voe_.GetNACK(channel_num));
1048 } 1051 }
1049 1052
1050 // Test that we can disable NACK on receive streams. 1053 // Test that we can disable NACK on receive streams.
1051 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) { 1054 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1052 EXPECT_TRUE(SetupEngine()); 1055 EXPECT_TRUE(SetupEngineWithSendStream());
1053 int channel_num1 = voe_.GetLastChannel(); 1056 int channel_num1 = voe_.GetLastChannel();
1054 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 1057 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1055 int channel_num2 = voe_.GetLastChannel(); 1058 int channel_num2 = voe_.GetLastChannel();
1056 cricket::AudioSendParameters parameters; 1059 cricket::AudioSendParameters parameters;
1057 parameters.codecs.push_back(kOpusCodec); 1060 parameters.codecs.push_back(kOpusCodec);
1058 parameters.codecs[0].AddFeedbackParam( 1061 parameters.codecs[0].AddFeedbackParam(
1059 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1062 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1060 cricket::kParamValueEmpty)); 1063 cricket::kParamValueEmpty));
1061 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1064 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1062 EXPECT_TRUE(voe_.GetNACK(channel_num1)); 1065 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1063 EXPECT_TRUE(voe_.GetNACK(channel_num2)); 1066 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1064 1067
1065 parameters.codecs.clear(); 1068 parameters.codecs.clear();
1066 parameters.codecs.push_back(kOpusCodec); 1069 parameters.codecs.push_back(kOpusCodec);
1067 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1070 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1068 EXPECT_FALSE(voe_.GetNACK(channel_num1)); 1071 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1069 EXPECT_FALSE(voe_.GetNACK(channel_num2)); 1072 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1070 } 1073 }
1071 1074
1072 // Test that NACK is enabled on a new receive stream. 1075 // Test that NACK is enabled on a new receive stream.
1073 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) { 1076 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1074 EXPECT_TRUE(SetupEngine()); 1077 EXPECT_TRUE(SetupEngineWithSendStream());
1075 int channel_num = voe_.GetLastChannel(); 1078 int channel_num = voe_.GetLastChannel();
1076 cricket::AudioSendParameters parameters; 1079 cricket::AudioSendParameters parameters;
1077 parameters.codecs.push_back(kIsacCodec); 1080 parameters.codecs.push_back(kIsacCodec);
1078 parameters.codecs.push_back(kCn16000Codec); 1081 parameters.codecs.push_back(kCn16000Codec);
1079 parameters.codecs[0].AddFeedbackParam( 1082 parameters.codecs[0].AddFeedbackParam(
1080 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1083 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1081 cricket::kParamValueEmpty)); 1084 cricket::kParamValueEmpty));
1082 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1085 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1083 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1086 EXPECT_TRUE(voe_.GetNACK(channel_num));
1084 1087
1085 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 1088 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1086 channel_num = voe_.GetLastChannel(); 1089 channel_num = voe_.GetLastChannel();
1087 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1090 EXPECT_TRUE(voe_.GetNACK(channel_num));
1088 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 1091 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1089 channel_num = voe_.GetLastChannel(); 1092 channel_num = voe_.GetLastChannel();
1090 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1093 EXPECT_TRUE(voe_.GetNACK(channel_num));
1091 } 1094 }
1092 1095
1093 // Test that without useinbandfec, Opus FEC is off. 1096 // Test that without useinbandfec, Opus FEC is off.
1094 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) { 1097 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
1095 EXPECT_TRUE(SetupEngine()); 1098 EXPECT_TRUE(SetupEngineWithSendStream());
1096 int channel_num = voe_.GetLastChannel(); 1099 int channel_num = voe_.GetLastChannel();
1097 cricket::AudioSendParameters parameters; 1100 cricket::AudioSendParameters parameters;
1098 parameters.codecs.push_back(kOpusCodec); 1101 parameters.codecs.push_back(kOpusCodec);
1099 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1102 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1100 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1103 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1101 } 1104 }
1102 1105
1103 // Test that with useinbandfec=0, Opus FEC is off. 1106 // Test that with useinbandfec=0, Opus FEC is off.
1104 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) { 1107 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
1105 EXPECT_TRUE(SetupEngine()); 1108 EXPECT_TRUE(SetupEngineWithSendStream());
1106 int channel_num = voe_.GetLastChannel(); 1109 int channel_num = voe_.GetLastChannel();
1107 cricket::AudioSendParameters parameters; 1110 cricket::AudioSendParameters parameters;
1108 parameters.codecs.push_back(kOpusCodec); 1111 parameters.codecs.push_back(kOpusCodec);
1109 parameters.codecs[0].bitrate = 0; 1112 parameters.codecs[0].bitrate = 0;
1110 parameters.codecs[0].params["useinbandfec"] = "0"; 1113 parameters.codecs[0].params["useinbandfec"] = "0";
1111 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1114 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1112 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1115 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1113 webrtc::CodecInst gcodec; 1116 webrtc::CodecInst gcodec;
1114 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1117 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1115 EXPECT_STREQ("opus", gcodec.plname); 1118 EXPECT_STREQ("opus", gcodec.plname);
1116 EXPECT_EQ(1, gcodec.channels); 1119 EXPECT_EQ(1, gcodec.channels);
1117 EXPECT_EQ(32000, gcodec.rate); 1120 EXPECT_EQ(32000, gcodec.rate);
1118 } 1121 }
1119 1122
1120 // Test that with useinbandfec=1, Opus FEC is on. 1123 // Test that with useinbandfec=1, Opus FEC is on.
1121 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) { 1124 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
1122 EXPECT_TRUE(SetupEngine()); 1125 EXPECT_TRUE(SetupEngineWithSendStream());
1123 int channel_num = voe_.GetLastChannel(); 1126 int channel_num = voe_.GetLastChannel();
1124 cricket::AudioSendParameters parameters; 1127 cricket::AudioSendParameters parameters;
1125 parameters.codecs.push_back(kOpusCodec); 1128 parameters.codecs.push_back(kOpusCodec);
1126 parameters.codecs[0].bitrate = 0; 1129 parameters.codecs[0].bitrate = 0;
1127 parameters.codecs[0].params["useinbandfec"] = "1"; 1130 parameters.codecs[0].params["useinbandfec"] = "1";
1128 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1131 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1129 EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); 1132 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1130 webrtc::CodecInst gcodec; 1133 webrtc::CodecInst gcodec;
1131 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1134 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1132 EXPECT_STREQ("opus", gcodec.plname); 1135 EXPECT_STREQ("opus", gcodec.plname);
1133 EXPECT_EQ(1, gcodec.channels); 1136 EXPECT_EQ(1, gcodec.channels);
1134 EXPECT_EQ(32000, gcodec.rate); 1137 EXPECT_EQ(32000, gcodec.rate);
1135 } 1138 }
1136 1139
1137 // Test that with useinbandfec=1, stereo=1, Opus FEC is on. 1140 // Test that with useinbandfec=1, stereo=1, Opus FEC is on.
1138 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) { 1141 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
1139 EXPECT_TRUE(SetupEngine()); 1142 EXPECT_TRUE(SetupEngineWithSendStream());
1140 int channel_num = voe_.GetLastChannel(); 1143 int channel_num = voe_.GetLastChannel();
1141 cricket::AudioSendParameters parameters; 1144 cricket::AudioSendParameters parameters;
1142 parameters.codecs.push_back(kOpusCodec); 1145 parameters.codecs.push_back(kOpusCodec);
1143 parameters.codecs[0].bitrate = 0; 1146 parameters.codecs[0].bitrate = 0;
1144 parameters.codecs[0].params["stereo"] = "1"; 1147 parameters.codecs[0].params["stereo"] = "1";
1145 parameters.codecs[0].params["useinbandfec"] = "1"; 1148 parameters.codecs[0].params["useinbandfec"] = "1";
1146 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1149 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1147 EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); 1150 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1148 webrtc::CodecInst gcodec; 1151 webrtc::CodecInst gcodec;
1149 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1152 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1150 EXPECT_STREQ("opus", gcodec.plname); 1153 EXPECT_STREQ("opus", gcodec.plname);
1151 EXPECT_EQ(2, gcodec.channels); 1154 EXPECT_EQ(2, gcodec.channels);
1152 EXPECT_EQ(64000, gcodec.rate); 1155 EXPECT_EQ(64000, gcodec.rate);
1153 } 1156 }
1154 1157
1155 // Test that with non-Opus, codec FEC is off. 1158 // Test that with non-Opus, codec FEC is off.
1156 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) { 1159 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
1157 EXPECT_TRUE(SetupEngine()); 1160 EXPECT_TRUE(SetupEngineWithSendStream());
1158 int channel_num = voe_.GetLastChannel(); 1161 int channel_num = voe_.GetLastChannel();
1159 cricket::AudioSendParameters parameters; 1162 cricket::AudioSendParameters parameters;
1160 parameters.codecs.push_back(kIsacCodec); 1163 parameters.codecs.push_back(kIsacCodec);
1161 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1164 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1162 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1165 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1163 } 1166 }
1164 1167
1165 // Test the with non-Opus, even if useinbandfec=1, FEC is off. 1168 // Test the with non-Opus, even if useinbandfec=1, FEC is off.
1166 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) { 1169 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1167 EXPECT_TRUE(SetupEngine()); 1170 EXPECT_TRUE(SetupEngineWithSendStream());
1168 int channel_num = voe_.GetLastChannel(); 1171 int channel_num = voe_.GetLastChannel();
1169 cricket::AudioSendParameters parameters; 1172 cricket::AudioSendParameters parameters;
1170 parameters.codecs.push_back(kIsacCodec); 1173 parameters.codecs.push_back(kIsacCodec);
1171 parameters.codecs[0].params["useinbandfec"] = "1"; 1174 parameters.codecs[0].params["useinbandfec"] = "1";
1172 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1175 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1173 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1176 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1174 } 1177 }
1175 1178
1176 // Test that Opus FEC status can be changed. 1179 // Test that Opus FEC status can be changed.
1177 TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) { 1180 TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1178 EXPECT_TRUE(SetupEngine()); 1181 EXPECT_TRUE(SetupEngineWithSendStream());
1179 int channel_num = voe_.GetLastChannel(); 1182 int channel_num = voe_.GetLastChannel();
1180 cricket::AudioSendParameters parameters; 1183 cricket::AudioSendParameters parameters;
1181 parameters.codecs.push_back(kOpusCodec); 1184 parameters.codecs.push_back(kOpusCodec);
1182 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1185 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1183 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1186 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1184 parameters.codecs[0].params["useinbandfec"] = "1"; 1187 parameters.codecs[0].params["useinbandfec"] = "1";
1185 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1188 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1186 EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); 1189 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1187 } 1190 }
1188 1191
1189 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode. 1192 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1190 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) { 1193 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1191 EXPECT_TRUE(SetupEngine()); 1194 EXPECT_TRUE(SetupEngineWithSendStream());
1192 int channel_num = voe_.GetLastChannel(); 1195 int channel_num = voe_.GetLastChannel();
1193 cricket::AudioSendParameters parameters; 1196 cricket::AudioSendParameters parameters;
1194 parameters.codecs.push_back(kOpusCodec); 1197 parameters.codecs.push_back(kOpusCodec);
1195 parameters.codecs[0].bitrate = 0; 1198 parameters.codecs[0].bitrate = 0;
1196 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000); 1199 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1197 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1200 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1198 EXPECT_EQ(cricket::kOpusBandwidthNb, 1201 EXPECT_EQ(cricket::kOpusBandwidthNb,
1199 voe_.GetMaxEncodingBandwidth(channel_num)); 1202 voe_.GetMaxEncodingBandwidth(channel_num));
1200 webrtc::CodecInst gcodec; 1203 webrtc::CodecInst gcodec;
1201 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1204 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1202 EXPECT_STREQ("opus", gcodec.plname); 1205 EXPECT_STREQ("opus", gcodec.plname);
1203 1206
1204 EXPECT_EQ(12000, gcodec.rate); 1207 EXPECT_EQ(12000, gcodec.rate);
1205 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1208 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1206 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1209 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1207 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1210 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1208 EXPECT_EQ(24000, gcodec.rate); 1211 EXPECT_EQ(24000, gcodec.rate);
1209 } 1212 }
1210 1213
1211 // Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode. 1214 // Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1212 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) { 1215 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1213 EXPECT_TRUE(SetupEngine()); 1216 EXPECT_TRUE(SetupEngineWithSendStream());
1214 int channel_num = voe_.GetLastChannel(); 1217 int channel_num = voe_.GetLastChannel();
1215 cricket::AudioSendParameters parameters; 1218 cricket::AudioSendParameters parameters;
1216 parameters.codecs.push_back(kOpusCodec); 1219 parameters.codecs.push_back(kOpusCodec);
1217 parameters.codecs[0].bitrate = 0; 1220 parameters.codecs[0].bitrate = 0;
1218 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001); 1221 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1219 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1222 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1220 EXPECT_EQ(cricket::kOpusBandwidthMb, 1223 EXPECT_EQ(cricket::kOpusBandwidthMb,
1221 voe_.GetMaxEncodingBandwidth(channel_num)); 1224 voe_.GetMaxEncodingBandwidth(channel_num));
1222 webrtc::CodecInst gcodec; 1225 webrtc::CodecInst gcodec;
1223 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1226 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1224 EXPECT_STREQ("opus", gcodec.plname); 1227 EXPECT_STREQ("opus", gcodec.plname);
1225 1228
1226 EXPECT_EQ(20000, gcodec.rate); 1229 EXPECT_EQ(20000, gcodec.rate);
1227 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1230 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1228 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1231 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1229 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1232 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1230 EXPECT_EQ(40000, gcodec.rate); 1233 EXPECT_EQ(40000, gcodec.rate);
1231 } 1234 }
1232 1235
1233 // Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode. 1236 // Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1234 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) { 1237 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1235 EXPECT_TRUE(SetupEngine()); 1238 EXPECT_TRUE(SetupEngineWithSendStream());
1236 int channel_num = voe_.GetLastChannel(); 1239 int channel_num = voe_.GetLastChannel();
1237 cricket::AudioSendParameters parameters; 1240 cricket::AudioSendParameters parameters;
1238 parameters.codecs.push_back(kOpusCodec); 1241 parameters.codecs.push_back(kOpusCodec);
1239 parameters.codecs[0].bitrate = 0; 1242 parameters.codecs[0].bitrate = 0;
1240 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001); 1243 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1241 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1244 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1242 EXPECT_EQ(cricket::kOpusBandwidthWb, 1245 EXPECT_EQ(cricket::kOpusBandwidthWb,
1243 voe_.GetMaxEncodingBandwidth(channel_num)); 1246 voe_.GetMaxEncodingBandwidth(channel_num));
1244 webrtc::CodecInst gcodec; 1247 webrtc::CodecInst gcodec;
1245 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1248 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1246 EXPECT_STREQ("opus", gcodec.plname); 1249 EXPECT_STREQ("opus", gcodec.plname);
1247 1250
1248 EXPECT_EQ(20000, gcodec.rate); 1251 EXPECT_EQ(20000, gcodec.rate);
1249 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1252 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1250 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1253 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1251 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1254 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1252 EXPECT_EQ(40000, gcodec.rate); 1255 EXPECT_EQ(40000, gcodec.rate);
1253 } 1256 }
1254 1257
1255 // Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode. 1258 // Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1256 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) { 1259 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1257 EXPECT_TRUE(SetupEngine()); 1260 EXPECT_TRUE(SetupEngineWithSendStream());
1258 int channel_num = voe_.GetLastChannel(); 1261 int channel_num = voe_.GetLastChannel();
1259 cricket::AudioSendParameters parameters; 1262 cricket::AudioSendParameters parameters;
1260 parameters.codecs.push_back(kOpusCodec); 1263 parameters.codecs.push_back(kOpusCodec);
1261 parameters.codecs[0].bitrate = 0; 1264 parameters.codecs[0].bitrate = 0;
1262 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001); 1265 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1263 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1266 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1264 EXPECT_EQ(cricket::kOpusBandwidthSwb, 1267 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1265 voe_.GetMaxEncodingBandwidth(channel_num)); 1268 voe_.GetMaxEncodingBandwidth(channel_num));
1266 webrtc::CodecInst gcodec; 1269 webrtc::CodecInst gcodec;
1267 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1270 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1268 EXPECT_STREQ("opus", gcodec.plname); 1271 EXPECT_STREQ("opus", gcodec.plname);
1269 1272
1270 EXPECT_EQ(32000, gcodec.rate); 1273 EXPECT_EQ(32000, gcodec.rate);
1271 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1274 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1272 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1275 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1273 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1276 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1274 EXPECT_EQ(64000, gcodec.rate); 1277 EXPECT_EQ(64000, gcodec.rate);
1275 } 1278 }
1276 1279
1277 // Test 24000 < maxplaybackrate triggers Opus full band mode. 1280 // Test 24000 < maxplaybackrate triggers Opus full band mode.
1278 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) { 1281 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1279 EXPECT_TRUE(SetupEngine()); 1282 EXPECT_TRUE(SetupEngineWithSendStream());
1280 int channel_num = voe_.GetLastChannel(); 1283 int channel_num = voe_.GetLastChannel();
1281 cricket::AudioSendParameters parameters; 1284 cricket::AudioSendParameters parameters;
1282 parameters.codecs.push_back(kOpusCodec); 1285 parameters.codecs.push_back(kOpusCodec);
1283 parameters.codecs[0].bitrate = 0; 1286 parameters.codecs[0].bitrate = 0;
1284 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001); 1287 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1285 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1288 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1286 EXPECT_EQ(cricket::kOpusBandwidthFb, 1289 EXPECT_EQ(cricket::kOpusBandwidthFb,
1287 voe_.GetMaxEncodingBandwidth(channel_num)); 1290 voe_.GetMaxEncodingBandwidth(channel_num));
1288 webrtc::CodecInst gcodec; 1291 webrtc::CodecInst gcodec;
1289 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1292 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1290 EXPECT_STREQ("opus", gcodec.plname); 1293 EXPECT_STREQ("opus", gcodec.plname);
1291 1294
1292 EXPECT_EQ(32000, gcodec.rate); 1295 EXPECT_EQ(32000, gcodec.rate);
1293 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1296 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1294 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1297 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1295 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1298 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1296 EXPECT_EQ(64000, gcodec.rate); 1299 EXPECT_EQ(64000, gcodec.rate);
1297 } 1300 }
1298 1301
1299 // Test Opus that without maxplaybackrate, default playback rate is used. 1302 // Test Opus that without maxplaybackrate, default playback rate is used.
1300 TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) { 1303 TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1301 EXPECT_TRUE(SetupEngine()); 1304 EXPECT_TRUE(SetupEngineWithSendStream());
1302 int channel_num = voe_.GetLastChannel(); 1305 int channel_num = voe_.GetLastChannel();
1303 cricket::AudioSendParameters parameters; 1306 cricket::AudioSendParameters parameters;
1304 parameters.codecs.push_back(kOpusCodec); 1307 parameters.codecs.push_back(kOpusCodec);
1305 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1308 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1306 EXPECT_EQ(cricket::kOpusBandwidthFb, 1309 EXPECT_EQ(cricket::kOpusBandwidthFb,
1307 voe_.GetMaxEncodingBandwidth(channel_num)); 1310 voe_.GetMaxEncodingBandwidth(channel_num));
1308 } 1311 }
1309 1312
1310 // Test the with non-Opus, maxplaybackrate has no effect. 1313 // Test the with non-Opus, maxplaybackrate has no effect.
1311 TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) { 1314 TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1312 EXPECT_TRUE(SetupEngine()); 1315 EXPECT_TRUE(SetupEngineWithSendStream());
1313 int channel_num = voe_.GetLastChannel(); 1316 int channel_num = voe_.GetLastChannel();
1314 cricket::AudioSendParameters parameters; 1317 cricket::AudioSendParameters parameters;
1315 parameters.codecs.push_back(kIsacCodec); 1318 parameters.codecs.push_back(kIsacCodec);
1316 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000); 1319 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1317 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1320 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1318 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num)); 1321 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1319 } 1322 }
1320 1323
1321 // Test maxplaybackrate can be set on two streams. 1324 // Test maxplaybackrate can be set on two streams.
1322 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) { 1325 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1323 EXPECT_TRUE(SetupEngine()); 1326 EXPECT_TRUE(SetupEngineWithSendStream());
1324 int channel_num = voe_.GetLastChannel(); 1327 int channel_num = voe_.GetLastChannel();
1325 cricket::AudioSendParameters parameters; 1328 cricket::AudioSendParameters parameters;
1326 parameters.codecs.push_back(kOpusCodec); 1329 parameters.codecs.push_back(kOpusCodec);
1327 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1330 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1328 // Default bandwidth is 24000. 1331 // Default bandwidth is 24000.
1329 EXPECT_EQ(cricket::kOpusBandwidthFb, 1332 EXPECT_EQ(cricket::kOpusBandwidthFb,
1330 voe_.GetMaxEncodingBandwidth(channel_num)); 1333 voe_.GetMaxEncodingBandwidth(channel_num));
1331 1334
1332 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000); 1335 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1333 1336
1334 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1337 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1335 EXPECT_EQ(cricket::kOpusBandwidthNb, 1338 EXPECT_EQ(cricket::kOpusBandwidthNb,
1336 voe_.GetMaxEncodingBandwidth(channel_num)); 1339 voe_.GetMaxEncodingBandwidth(channel_num));
1337 1340
1338 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2)); 1341 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1339 channel_num = voe_.GetLastChannel(); 1342 channel_num = voe_.GetLastChannel();
1340 EXPECT_EQ(cricket::kOpusBandwidthNb, 1343 EXPECT_EQ(cricket::kOpusBandwidthNb,
1341 voe_.GetMaxEncodingBandwidth(channel_num)); 1344 voe_.GetMaxEncodingBandwidth(channel_num));
1342 } 1345 }
1343 1346
1344 // Test that with usedtx=0, Opus DTX is off. 1347 // Test that with usedtx=0, Opus DTX is off.
1345 TEST_F(WebRtcVoiceEngineTestFake, DisableOpusDtxOnOpus) { 1348 TEST_F(WebRtcVoiceEngineTestFake, DisableOpusDtxOnOpus) {
1346 EXPECT_TRUE(SetupEngine()); 1349 EXPECT_TRUE(SetupEngineWithSendStream());
1347 int channel_num = voe_.GetLastChannel(); 1350 int channel_num = voe_.GetLastChannel();
1348 cricket::AudioSendParameters parameters; 1351 cricket::AudioSendParameters parameters;
1349 parameters.codecs.push_back(kOpusCodec); 1352 parameters.codecs.push_back(kOpusCodec);
1350 parameters.codecs[0].params["usedtx"] = "0"; 1353 parameters.codecs[0].params["usedtx"] = "0";
1351 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1354 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1352 EXPECT_FALSE(voe_.GetOpusDtx(channel_num)); 1355 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1353 } 1356 }
1354 1357
1355 // Test that with usedtx=1, Opus DTX is on. 1358 // Test that with usedtx=1, Opus DTX is on.
1356 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpus) { 1359 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpus) {
1357 EXPECT_TRUE(SetupEngine()); 1360 EXPECT_TRUE(SetupEngineWithSendStream());
1358 int channel_num = voe_.GetLastChannel(); 1361 int channel_num = voe_.GetLastChannel();
1359 cricket::AudioSendParameters parameters; 1362 cricket::AudioSendParameters parameters;
1360 parameters.codecs.push_back(kOpusCodec); 1363 parameters.codecs.push_back(kOpusCodec);
1361 parameters.codecs[0].params["usedtx"] = "1"; 1364 parameters.codecs[0].params["usedtx"] = "1";
1362 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1365 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1363 EXPECT_TRUE(voe_.GetOpusDtx(channel_num)); 1366 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1364 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD. 1367 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1365 } 1368 }
1366 1369
1367 // Test that usedtx=1 works with stereo Opus. 1370 // Test that usedtx=1 works with stereo Opus.
1368 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpusStereo) { 1371 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpusStereo) {
1369 EXPECT_TRUE(SetupEngine()); 1372 EXPECT_TRUE(SetupEngineWithSendStream());
1370 int channel_num = voe_.GetLastChannel(); 1373 int channel_num = voe_.GetLastChannel();
1371 cricket::AudioSendParameters parameters; 1374 cricket::AudioSendParameters parameters;
1372 parameters.codecs.push_back(kOpusCodec); 1375 parameters.codecs.push_back(kOpusCodec);
1373 parameters.codecs[0].params["usedtx"] = "1"; 1376 parameters.codecs[0].params["usedtx"] = "1";
1374 parameters.codecs[0].params["stereo"] = "1"; 1377 parameters.codecs[0].params["stereo"] = "1";
1375 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1378 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1376 EXPECT_TRUE(voe_.GetOpusDtx(channel_num)); 1379 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1377 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD. 1380 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1378 } 1381 }
1379 1382
1380 // Test that usedtx=1 does not work with non Opus. 1383 // Test that usedtx=1 does not work with non Opus.
1381 TEST_F(WebRtcVoiceEngineTestFake, CannotEnableOpusDtxOnNonOpus) { 1384 TEST_F(WebRtcVoiceEngineTestFake, CannotEnableOpusDtxOnNonOpus) {
1382 EXPECT_TRUE(SetupEngine()); 1385 EXPECT_TRUE(SetupEngineWithSendStream());
1383 int channel_num = voe_.GetLastChannel(); 1386 int channel_num = voe_.GetLastChannel();
1384 cricket::AudioSendParameters parameters; 1387 cricket::AudioSendParameters parameters;
1385 parameters.codecs.push_back(kIsacCodec); 1388 parameters.codecs.push_back(kIsacCodec);
1386 parameters.codecs[0].params["usedtx"] = "1"; 1389 parameters.codecs[0].params["usedtx"] = "1";
1387 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1390 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1388 EXPECT_FALSE(voe_.GetOpusDtx(channel_num)); 1391 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1389 } 1392 }
1390 1393
1391 // Test that we can switch back and forth between Opus and ISAC with CN. 1394 // Test that we can switch back and forth between Opus and ISAC with CN.
1392 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) { 1395 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) {
1393 EXPECT_TRUE(SetupEngine()); 1396 EXPECT_TRUE(SetupEngineWithSendStream());
1394 int channel_num = voe_.GetLastChannel(); 1397 int channel_num = voe_.GetLastChannel();
1395 cricket::AudioSendParameters opus_parameters; 1398 cricket::AudioSendParameters opus_parameters;
1396 opus_parameters.codecs.push_back(kOpusCodec); 1399 opus_parameters.codecs.push_back(kOpusCodec);
1397 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters)); 1400 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters));
1398 webrtc::CodecInst gcodec; 1401 webrtc::CodecInst gcodec;
1399 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1402 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1400 EXPECT_EQ(111, gcodec.pltype); 1403 EXPECT_EQ(111, gcodec.pltype);
1401 EXPECT_STREQ("opus", gcodec.plname); 1404 EXPECT_STREQ("opus", gcodec.plname);
1402 1405
1403 cricket::AudioSendParameters isac_parameters; 1406 cricket::AudioSendParameters isac_parameters;
1404 isac_parameters.codecs.push_back(kIsacCodec); 1407 isac_parameters.codecs.push_back(kIsacCodec);
1405 isac_parameters.codecs.push_back(kCn16000Codec); 1408 isac_parameters.codecs.push_back(kCn16000Codec);
1406 isac_parameters.codecs.push_back(kOpusCodec); 1409 isac_parameters.codecs.push_back(kOpusCodec);
1407 EXPECT_TRUE(channel_->SetSendParameters(isac_parameters)); 1410 EXPECT_TRUE(channel_->SetSendParameters(isac_parameters));
1408 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1411 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1409 EXPECT_EQ(103, gcodec.pltype); 1412 EXPECT_EQ(103, gcodec.pltype);
1410 EXPECT_STREQ("ISAC", gcodec.plname); 1413 EXPECT_STREQ("ISAC", gcodec.plname);
1411 1414
1412 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters)); 1415 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters));
1413 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1416 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1414 EXPECT_EQ(111, gcodec.pltype); 1417 EXPECT_EQ(111, gcodec.pltype);
1415 EXPECT_STREQ("opus", gcodec.plname); 1418 EXPECT_STREQ("opus", gcodec.plname);
1416 } 1419 }
1417 1420
1418 // Test that we handle various ways of specifying bitrate. 1421 // Test that we handle various ways of specifying bitrate.
1419 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) { 1422 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1420 EXPECT_TRUE(SetupEngine()); 1423 EXPECT_TRUE(SetupEngineWithSendStream());
1421 int channel_num = voe_.GetLastChannel(); 1424 int channel_num = voe_.GetLastChannel();
1422 cricket::AudioSendParameters parameters; 1425 cricket::AudioSendParameters parameters;
1423 parameters.codecs.push_back(kIsacCodec); // bitrate == 32000 1426 parameters.codecs.push_back(kIsacCodec); // bitrate == 32000
1424 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1427 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1425 webrtc::CodecInst gcodec; 1428 webrtc::CodecInst gcodec;
1426 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1429 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1427 EXPECT_EQ(103, gcodec.pltype); 1430 EXPECT_EQ(103, gcodec.pltype);
1428 EXPECT_STREQ("ISAC", gcodec.plname); 1431 EXPECT_STREQ("ISAC", gcodec.plname);
1429 EXPECT_EQ(32000, gcodec.rate); 1432 EXPECT_EQ(32000, gcodec.rate);
1430 1433
(...skipping 29 matching lines...) Expand all
1460 parameters.codecs[0].bitrate = 0; // bitrate == default 1463 parameters.codecs[0].bitrate = 0; // bitrate == default
1461 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1464 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1462 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1465 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1463 EXPECT_EQ(111, gcodec.pltype); 1466 EXPECT_EQ(111, gcodec.pltype);
1464 EXPECT_STREQ("opus", gcodec.plname); 1467 EXPECT_STREQ("opus", gcodec.plname);
1465 EXPECT_EQ(32000, gcodec.rate); 1468 EXPECT_EQ(32000, gcodec.rate);
1466 } 1469 }
1467 1470
1468 // Test that we could set packet size specified in kCodecParamPTime. 1471 // Test that we could set packet size specified in kCodecParamPTime.
1469 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) { 1472 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) {
1470 EXPECT_TRUE(SetupEngine()); 1473 EXPECT_TRUE(SetupEngineWithSendStream());
1471 int channel_num = voe_.GetLastChannel(); 1474 int channel_num = voe_.GetLastChannel();
1472 cricket::AudioSendParameters parameters; 1475 cricket::AudioSendParameters parameters;
1473 parameters.codecs.push_back(kOpusCodec); 1476 parameters.codecs.push_back(kOpusCodec);
1474 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Within range. 1477 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Within range.
1475 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1478 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1476 webrtc::CodecInst gcodec; 1479 webrtc::CodecInst gcodec;
1477 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1480 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1478 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms. 1481 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms.
1479 1482
1480 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Below range. 1483 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Below range.
(...skipping 14 matching lines...) Expand all
1495 1498
1496 parameters.codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP. 1499 parameters.codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP.
1497 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40); 1500 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40);
1498 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1501 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1499 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1502 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1500 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE. 1503 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE.
1501 } 1504 }
1502 1505
1503 // Test that we fail if no codecs are specified. 1506 // Test that we fail if no codecs are specified.
1504 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) { 1507 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1505 EXPECT_TRUE(SetupEngine()); 1508 EXPECT_TRUE(SetupEngineWithSendStream());
1506 cricket::AudioSendParameters parameters; 1509 cricket::AudioSendParameters parameters;
1507 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 1510 EXPECT_FALSE(channel_->SetSendParameters(parameters));
1508 } 1511 }
1509 1512
1510 // Test that we can set send codecs even with telephone-event codec as the first 1513 // Test that we can set send codecs even with telephone-event codec as the first
1511 // one on the list. 1514 // one on the list.
1512 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) { 1515 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1513 EXPECT_TRUE(SetupEngine()); 1516 EXPECT_TRUE(SetupEngineWithSendStream());
1514 int channel_num = voe_.GetLastChannel(); 1517 int channel_num = voe_.GetLastChannel();
1515 cricket::AudioSendParameters parameters; 1518 cricket::AudioSendParameters parameters;
1516 parameters.codecs.push_back(kTelephoneEventCodec); 1519 parameters.codecs.push_back(kTelephoneEventCodec);
1517 parameters.codecs.push_back(kIsacCodec); 1520 parameters.codecs.push_back(kIsacCodec);
1518 parameters.codecs.push_back(kPcmuCodec); 1521 parameters.codecs.push_back(kPcmuCodec);
1519 parameters.codecs[0].id = 98; // DTMF 1522 parameters.codecs[0].id = 98; // DTMF
1520 parameters.codecs[1].id = 96; 1523 parameters.codecs[1].id = 96;
1521 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1524 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1522 webrtc::CodecInst gcodec; 1525 webrtc::CodecInst gcodec;
1523 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1526 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1524 EXPECT_EQ(96, gcodec.pltype); 1527 EXPECT_EQ(96, gcodec.pltype);
1525 EXPECT_STREQ("ISAC", gcodec.plname); 1528 EXPECT_STREQ("ISAC", gcodec.plname);
1526 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); 1529 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1527 } 1530 }
1528 1531
1529 // Test that we can set send codecs even with CN codec as the first 1532 // Test that we can set send codecs even with CN codec as the first
1530 // one on the list. 1533 // one on the list.
1531 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) { 1534 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1532 EXPECT_TRUE(SetupEngine()); 1535 EXPECT_TRUE(SetupEngineWithSendStream());
1533 int channel_num = voe_.GetLastChannel(); 1536 int channel_num = voe_.GetLastChannel();
1534 cricket::AudioSendParameters parameters; 1537 cricket::AudioSendParameters parameters;
1535 parameters.codecs.push_back(kCn16000Codec); 1538 parameters.codecs.push_back(kCn16000Codec);
1536 parameters.codecs.push_back(kIsacCodec); 1539 parameters.codecs.push_back(kIsacCodec);
1537 parameters.codecs.push_back(kPcmuCodec); 1540 parameters.codecs.push_back(kPcmuCodec);
1538 parameters.codecs[0].id = 98; // wideband CN 1541 parameters.codecs[0].id = 98; // wideband CN
1539 parameters.codecs[1].id = 96; 1542 parameters.codecs[1].id = 96;
1540 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1543 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1541 webrtc::CodecInst gcodec; 1544 webrtc::CodecInst gcodec;
1542 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1545 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1543 EXPECT_EQ(96, gcodec.pltype); 1546 EXPECT_EQ(96, gcodec.pltype);
1544 EXPECT_STREQ("ISAC", gcodec.plname); 1547 EXPECT_STREQ("ISAC", gcodec.plname);
1545 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true)); 1548 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
1546 } 1549 }
1547 1550
1548 // Test that we set VAD and DTMF types correctly as caller. 1551 // Test that we set VAD and DTMF types correctly as caller.
1549 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) { 1552 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
1550 EXPECT_TRUE(SetupEngine()); 1553 EXPECT_TRUE(SetupEngineWithSendStream());
1551 int channel_num = voe_.GetLastChannel(); 1554 int channel_num = voe_.GetLastChannel();
1552 cricket::AudioSendParameters parameters; 1555 cricket::AudioSendParameters parameters;
1553 parameters.codecs.push_back(kIsacCodec); 1556 parameters.codecs.push_back(kIsacCodec);
1554 parameters.codecs.push_back(kPcmuCodec); 1557 parameters.codecs.push_back(kPcmuCodec);
1555 // TODO(juberti): cn 32000 1558 // TODO(juberti): cn 32000
1556 parameters.codecs.push_back(kCn16000Codec); 1559 parameters.codecs.push_back(kCn16000Codec);
1557 parameters.codecs.push_back(kCn8000Codec); 1560 parameters.codecs.push_back(kCn8000Codec);
1558 parameters.codecs.push_back(kTelephoneEventCodec); 1561 parameters.codecs.push_back(kTelephoneEventCodec);
1559 parameters.codecs.push_back(kRedCodec); 1562 parameters.codecs.push_back(kRedCodec);
1560 parameters.codecs[0].id = 96; 1563 parameters.codecs[0].id = 96;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1601 EXPECT_TRUE(voe_.GetVAD(channel_num)); 1604 EXPECT_TRUE(voe_.GetVAD(channel_num));
1602 EXPECT_FALSE(voe_.GetRED(channel_num)); 1605 EXPECT_FALSE(voe_.GetRED(channel_num));
1603 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); 1606 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1604 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); 1607 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1605 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); 1608 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1606 } 1609 }
1607 1610
1608 // Test that we only apply VAD if we have a CN codec that matches the 1611 // Test that we only apply VAD if we have a CN codec that matches the
1609 // send codec clockrate. 1612 // send codec clockrate.
1610 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) { 1613 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1611 EXPECT_TRUE(SetupEngine()); 1614 EXPECT_TRUE(SetupEngineWithSendStream());
1612 int channel_num = voe_.GetLastChannel(); 1615 int channel_num = voe_.GetLastChannel();
1613 cricket::AudioSendParameters parameters; 1616 cricket::AudioSendParameters parameters;
1614 // Set ISAC(16K) and CN(16K). VAD should be activated. 1617 // Set ISAC(16K) and CN(16K). VAD should be activated.
1615 parameters.codecs.push_back(kIsacCodec); 1618 parameters.codecs.push_back(kIsacCodec);
1616 parameters.codecs.push_back(kCn16000Codec); 1619 parameters.codecs.push_back(kCn16000Codec);
1617 parameters.codecs[1].id = 97; 1620 parameters.codecs[1].id = 97;
1618 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1621 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1619 webrtc::CodecInst gcodec; 1622 webrtc::CodecInst gcodec;
1620 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1623 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1621 EXPECT_STREQ("ISAC", gcodec.plname); 1624 EXPECT_STREQ("ISAC", gcodec.plname);
(...skipping 15 matching lines...) Expand all
1637 // Set ISAC(16K) and CN(8K). VAD should not be activated. 1640 // Set ISAC(16K) and CN(8K). VAD should not be activated.
1638 parameters.codecs[0] = kIsacCodec; 1641 parameters.codecs[0] = kIsacCodec;
1639 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1642 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1640 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1643 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1641 EXPECT_STREQ("ISAC", gcodec.plname); 1644 EXPECT_STREQ("ISAC", gcodec.plname);
1642 EXPECT_FALSE(voe_.GetVAD(channel_num)); 1645 EXPECT_FALSE(voe_.GetVAD(channel_num));
1643 } 1646 }
1644 1647
1645 // Test that we perform case-insensitive matching of codec names. 1648 // Test that we perform case-insensitive matching of codec names.
1646 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) { 1649 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1647 EXPECT_TRUE(SetupEngine()); 1650 EXPECT_TRUE(SetupEngineWithSendStream());
1648 int channel_num = voe_.GetLastChannel(); 1651 int channel_num = voe_.GetLastChannel();
1649 cricket::AudioSendParameters parameters; 1652 cricket::AudioSendParameters parameters;
1650 parameters.codecs.push_back(kIsacCodec); 1653 parameters.codecs.push_back(kIsacCodec);
1651 parameters.codecs.push_back(kPcmuCodec); 1654 parameters.codecs.push_back(kPcmuCodec);
1652 parameters.codecs.push_back(kCn16000Codec); 1655 parameters.codecs.push_back(kCn16000Codec);
1653 parameters.codecs.push_back(kCn8000Codec); 1656 parameters.codecs.push_back(kCn8000Codec);
1654 parameters.codecs.push_back(kTelephoneEventCodec); 1657 parameters.codecs.push_back(kTelephoneEventCodec);
1655 parameters.codecs.push_back(kRedCodec); 1658 parameters.codecs.push_back(kRedCodec);
1656 parameters.codecs[0].name = "iSaC"; 1659 parameters.codecs[0].name = "iSaC";
1657 parameters.codecs[0].id = 96; 1660 parameters.codecs[0].id = 96;
1658 parameters.codecs[2].id = 97; // wideband CN 1661 parameters.codecs[2].id = 97; // wideband CN
1659 parameters.codecs[4].id = 98; // DTMF 1662 parameters.codecs[4].id = 98; // DTMF
1660 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1663 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1661 webrtc::CodecInst gcodec; 1664 webrtc::CodecInst gcodec;
1662 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1665 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1663 EXPECT_EQ(96, gcodec.pltype); 1666 EXPECT_EQ(96, gcodec.pltype);
1664 EXPECT_STREQ("ISAC", gcodec.plname); 1667 EXPECT_STREQ("ISAC", gcodec.plname);
1665 EXPECT_TRUE(voe_.GetVAD(channel_num)); 1668 EXPECT_TRUE(voe_.GetVAD(channel_num));
1666 EXPECT_FALSE(voe_.GetRED(channel_num)); 1669 EXPECT_FALSE(voe_.GetRED(channel_num));
1667 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); 1670 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1668 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); 1671 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1669 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num)); 1672 EXPECT_EQ(98, voe_.GetSendTelephoneEventPayloadType(channel_num));
1670 } 1673 }
1671 1674
1672 // Test that we set up RED correctly as caller. 1675 // Test that we set up RED correctly as caller.
1673 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) { 1676 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
1674 EXPECT_TRUE(SetupEngine()); 1677 EXPECT_TRUE(SetupEngineWithSendStream());
1675 int channel_num = voe_.GetLastChannel(); 1678 int channel_num = voe_.GetLastChannel();
1676 cricket::AudioSendParameters parameters; 1679 cricket::AudioSendParameters parameters;
1677 parameters.codecs.push_back(kRedCodec); 1680 parameters.codecs.push_back(kRedCodec);
1678 parameters.codecs.push_back(kIsacCodec); 1681 parameters.codecs.push_back(kIsacCodec);
1679 parameters.codecs.push_back(kPcmuCodec); 1682 parameters.codecs.push_back(kPcmuCodec);
1680 parameters.codecs[0].id = 127; 1683 parameters.codecs[0].id = 127;
1681 parameters.codecs[0].params[""] = "96/96"; 1684 parameters.codecs[0].params[""] = "96/96";
1682 parameters.codecs[1].id = 96; 1685 parameters.codecs[1].id = 96;
1683 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1686 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1684 webrtc::CodecInst gcodec; 1687 webrtc::CodecInst gcodec;
(...skipping 24 matching lines...) Expand all
1709 webrtc::CodecInst gcodec; 1712 webrtc::CodecInst gcodec;
1710 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1713 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1711 EXPECT_EQ(96, gcodec.pltype); 1714 EXPECT_EQ(96, gcodec.pltype);
1712 EXPECT_STREQ("ISAC", gcodec.plname); 1715 EXPECT_STREQ("ISAC", gcodec.plname);
1713 EXPECT_TRUE(voe_.GetRED(channel_num)); 1716 EXPECT_TRUE(voe_.GetRED(channel_num));
1714 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); 1717 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
1715 } 1718 }
1716 1719
1717 // Test that we set up RED correctly if params are omitted. 1720 // Test that we set up RED correctly if params are omitted.
1718 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) { 1721 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1719 EXPECT_TRUE(SetupEngine()); 1722 EXPECT_TRUE(SetupEngineWithSendStream());
1720 int channel_num = voe_.GetLastChannel(); 1723 int channel_num = voe_.GetLastChannel();
1721 cricket::AudioSendParameters parameters; 1724 cricket::AudioSendParameters parameters;
1722 parameters.codecs.push_back(kRedCodec); 1725 parameters.codecs.push_back(kRedCodec);
1723 parameters.codecs.push_back(kIsacCodec); 1726 parameters.codecs.push_back(kIsacCodec);
1724 parameters.codecs.push_back(kPcmuCodec); 1727 parameters.codecs.push_back(kPcmuCodec);
1725 parameters.codecs[0].id = 127; 1728 parameters.codecs[0].id = 127;
1726 parameters.codecs[1].id = 96; 1729 parameters.codecs[1].id = 96;
1727 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1730 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1728 webrtc::CodecInst gcodec; 1731 webrtc::CodecInst gcodec;
1729 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1732 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1730 EXPECT_EQ(96, gcodec.pltype); 1733 EXPECT_EQ(96, gcodec.pltype);
1731 EXPECT_STREQ("ISAC", gcodec.plname); 1734 EXPECT_STREQ("ISAC", gcodec.plname);
1732 EXPECT_TRUE(voe_.GetRED(channel_num)); 1735 EXPECT_TRUE(voe_.GetRED(channel_num));
1733 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); 1736 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
1734 } 1737 }
1735 1738
1736 // Test that we ignore RED if the parameters aren't named the way we expect. 1739 // Test that we ignore RED if the parameters aren't named the way we expect.
1737 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) { 1740 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1738 EXPECT_TRUE(SetupEngine()); 1741 EXPECT_TRUE(SetupEngineWithSendStream());
1739 int channel_num = voe_.GetLastChannel(); 1742 int channel_num = voe_.GetLastChannel();
1740 cricket::AudioSendParameters parameters; 1743 cricket::AudioSendParameters parameters;
1741 parameters.codecs.push_back(kRedCodec); 1744 parameters.codecs.push_back(kRedCodec);
1742 parameters.codecs.push_back(kIsacCodec); 1745 parameters.codecs.push_back(kIsacCodec);
1743 parameters.codecs.push_back(kPcmuCodec); 1746 parameters.codecs.push_back(kPcmuCodec);
1744 parameters.codecs[0].id = 127; 1747 parameters.codecs[0].id = 127;
1745 parameters.codecs[0].params["ABC"] = "96/96"; 1748 parameters.codecs[0].params["ABC"] = "96/96";
1746 parameters.codecs[1].id = 96; 1749 parameters.codecs[1].id = 96;
1747 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1750 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1748 webrtc::CodecInst gcodec; 1751 webrtc::CodecInst gcodec;
1749 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1752 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1750 EXPECT_EQ(96, gcodec.pltype); 1753 EXPECT_EQ(96, gcodec.pltype);
1751 EXPECT_STREQ("ISAC", gcodec.plname); 1754 EXPECT_STREQ("ISAC", gcodec.plname);
1752 EXPECT_FALSE(voe_.GetRED(channel_num)); 1755 EXPECT_FALSE(voe_.GetRED(channel_num));
1753 } 1756 }
1754 1757
1755 // Test that we ignore RED if it uses different primary/secondary encoding. 1758 // Test that we ignore RED if it uses different primary/secondary encoding.
1756 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) { 1759 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1757 EXPECT_TRUE(SetupEngine()); 1760 EXPECT_TRUE(SetupEngineWithSendStream());
1758 int channel_num = voe_.GetLastChannel(); 1761 int channel_num = voe_.GetLastChannel();
1759 cricket::AudioSendParameters parameters; 1762 cricket::AudioSendParameters parameters;
1760 parameters.codecs.push_back(kRedCodec); 1763 parameters.codecs.push_back(kRedCodec);
1761 parameters.codecs.push_back(kIsacCodec); 1764 parameters.codecs.push_back(kIsacCodec);
1762 parameters.codecs.push_back(kPcmuCodec); 1765 parameters.codecs.push_back(kPcmuCodec);
1763 parameters.codecs[0].id = 127; 1766 parameters.codecs[0].id = 127;
1764 parameters.codecs[0].params[""] = "96/0"; 1767 parameters.codecs[0].params[""] = "96/0";
1765 parameters.codecs[1].id = 96; 1768 parameters.codecs[1].id = 96;
1766 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1769 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1767 webrtc::CodecInst gcodec; 1770 webrtc::CodecInst gcodec;
1768 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1771 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1769 EXPECT_EQ(96, gcodec.pltype); 1772 EXPECT_EQ(96, gcodec.pltype);
1770 EXPECT_STREQ("ISAC", gcodec.plname); 1773 EXPECT_STREQ("ISAC", gcodec.plname);
1771 EXPECT_FALSE(voe_.GetRED(channel_num)); 1774 EXPECT_FALSE(voe_.GetRED(channel_num));
1772 } 1775 }
1773 1776
1774 // Test that we ignore RED if it uses more than 2 encodings. 1777 // Test that we ignore RED if it uses more than 2 encodings.
1775 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) { 1778 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1776 EXPECT_TRUE(SetupEngine()); 1779 EXPECT_TRUE(SetupEngineWithSendStream());
1777 int channel_num = voe_.GetLastChannel(); 1780 int channel_num = voe_.GetLastChannel();
1778 cricket::AudioSendParameters parameters; 1781 cricket::AudioSendParameters parameters;
1779 parameters.codecs.push_back(kRedCodec); 1782 parameters.codecs.push_back(kRedCodec);
1780 parameters.codecs.push_back(kIsacCodec); 1783 parameters.codecs.push_back(kIsacCodec);
1781 parameters.codecs.push_back(kPcmuCodec); 1784 parameters.codecs.push_back(kPcmuCodec);
1782 parameters.codecs[0].id = 127; 1785 parameters.codecs[0].id = 127;
1783 parameters.codecs[0].params[""] = "96/96/96"; 1786 parameters.codecs[0].params[""] = "96/96/96";
1784 parameters.codecs[1].id = 96; 1787 parameters.codecs[1].id = 96;
1785 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1788 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1786 webrtc::CodecInst gcodec; 1789 webrtc::CodecInst gcodec;
1787 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1790 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1788 EXPECT_EQ(96, gcodec.pltype); 1791 EXPECT_EQ(96, gcodec.pltype);
1789 EXPECT_STREQ("ISAC", gcodec.plname); 1792 EXPECT_STREQ("ISAC", gcodec.plname);
1790 EXPECT_FALSE(voe_.GetRED(channel_num)); 1793 EXPECT_FALSE(voe_.GetRED(channel_num));
1791 } 1794 }
1792 1795
1793 // Test that we ignore RED if it has bogus codec ids. 1796 // Test that we ignore RED if it has bogus codec ids.
1794 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) { 1797 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1795 EXPECT_TRUE(SetupEngine()); 1798 EXPECT_TRUE(SetupEngineWithSendStream());
1796 int channel_num = voe_.GetLastChannel(); 1799 int channel_num = voe_.GetLastChannel();
1797 cricket::AudioSendParameters parameters; 1800 cricket::AudioSendParameters parameters;
1798 parameters.codecs.push_back(kRedCodec); 1801 parameters.codecs.push_back(kRedCodec);
1799 parameters.codecs.push_back(kIsacCodec); 1802 parameters.codecs.push_back(kIsacCodec);
1800 parameters.codecs.push_back(kPcmuCodec); 1803 parameters.codecs.push_back(kPcmuCodec);
1801 parameters.codecs[0].id = 127; 1804 parameters.codecs[0].id = 127;
1802 parameters.codecs[0].params[""] = "ABC/ABC"; 1805 parameters.codecs[0].params[""] = "ABC/ABC";
1803 parameters.codecs[1].id = 96; 1806 parameters.codecs[1].id = 96;
1804 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1807 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1805 webrtc::CodecInst gcodec; 1808 webrtc::CodecInst gcodec;
1806 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1809 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1807 EXPECT_EQ(96, gcodec.pltype); 1810 EXPECT_EQ(96, gcodec.pltype);
1808 EXPECT_STREQ("ISAC", gcodec.plname); 1811 EXPECT_STREQ("ISAC", gcodec.plname);
1809 EXPECT_FALSE(voe_.GetRED(channel_num)); 1812 EXPECT_FALSE(voe_.GetRED(channel_num));
1810 } 1813 }
1811 1814
1812 // Test that we ignore RED if it refers to a codec that is not present. 1815 // Test that we ignore RED if it refers to a codec that is not present.
1813 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) { 1816 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1814 EXPECT_TRUE(SetupEngine()); 1817 EXPECT_TRUE(SetupEngineWithSendStream());
1815 int channel_num = voe_.GetLastChannel(); 1818 int channel_num = voe_.GetLastChannel();
1816 cricket::AudioSendParameters parameters; 1819 cricket::AudioSendParameters parameters;
1817 parameters.codecs.push_back(kRedCodec); 1820 parameters.codecs.push_back(kRedCodec);
1818 parameters.codecs.push_back(kIsacCodec); 1821 parameters.codecs.push_back(kIsacCodec);
1819 parameters.codecs.push_back(kPcmuCodec); 1822 parameters.codecs.push_back(kPcmuCodec);
1820 parameters.codecs[0].id = 127; 1823 parameters.codecs[0].id = 127;
1821 parameters.codecs[0].params[""] = "97/97"; 1824 parameters.codecs[0].params[""] = "97/97";
1822 parameters.codecs[1].id = 96; 1825 parameters.codecs[1].id = 96;
1823 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1826 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1824 webrtc::CodecInst gcodec; 1827 webrtc::CodecInst gcodec;
(...skipping 12 matching lines...) Expand all
1837 } 1840 }
1838 1841
1839 // Test support for absolute send time header extension. 1842 // Test support for absolute send time header extension.
1840 TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) { 1843 TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
1841 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension); 1844 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1842 } 1845 }
1843 TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) { 1846 TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
1844 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension); 1847 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
1845 } 1848 }
1846 1849
1847 // Test that we can create a channel and start sending/playing out on it. 1850 // Test that we can create a channel and start sending on it.
1848 TEST_F(WebRtcVoiceEngineTestFake, SendAndPlayout) { 1851 TEST_F(WebRtcVoiceEngineTestFake, Send) {
1849 EXPECT_TRUE(SetupEngine()); 1852 EXPECT_TRUE(SetupEngineWithSendStream());
1850 int channel_num = voe_.GetLastChannel(); 1853 int channel_num = voe_.GetLastChannel();
1851 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 1854 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
1852 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); 1855 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
1853 EXPECT_TRUE(voe_.GetSend(channel_num)); 1856 EXPECT_TRUE(voe_.GetSend(channel_num));
1857 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1858 EXPECT_FALSE(voe_.GetSend(channel_num));
1859 }
1860
1861 // Test that we can create a channel and start playing out on it.
1862 TEST_F(WebRtcVoiceEngineTestFake, Playout) {
1863 EXPECT_TRUE(SetupEngineWithRecvStream());
1864 int channel_num = voe_.GetLastChannel();
1865 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_));
1854 EXPECT_TRUE(channel_->SetPlayout(true)); 1866 EXPECT_TRUE(channel_->SetPlayout(true));
1855 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 1867 EXPECT_TRUE(voe_.GetPlayout(channel_num));
1856 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
1857 EXPECT_FALSE(voe_.GetSend(channel_num));
1858 EXPECT_TRUE(channel_->SetPlayout(false)); 1868 EXPECT_TRUE(channel_->SetPlayout(false));
1859 EXPECT_FALSE(voe_.GetPlayout(channel_num)); 1869 EXPECT_FALSE(voe_.GetPlayout(channel_num));
1860 } 1870 }
1861 1871
1862 // Test that we can add and remove send streams. 1872 // Test that we can add and remove send streams.
1863 TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) { 1873 TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
1864 SetupForMultiSendStream(); 1874 SetupForMultiSendStream();
1865 1875
1866 static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; 1876 static const uint32_t kSsrcs4[] = {1, 2, 3, 4};
1867 1877
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name); 2001 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
1992 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent); 2002 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].bytes_sent);
1993 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent); 2003 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_sent);
1994 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost); 2004 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].packets_lost);
1995 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost); 2005 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[i].fraction_lost);
1996 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum); 2006 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].ext_seqnum);
1997 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms); 2007 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].rtt_ms);
1998 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms); 2008 EXPECT_EQ(cricket::kIntStatValue, info.senders[i].jitter_ms);
1999 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name); 2009 EXPECT_EQ(kPcmuCodec.name, info.senders[i].codec_name);
2000 } 2010 }
2011 EXPECT_EQ(0u, info.receivers.size());
2001 2012
2002 EXPECT_EQ(0u, info.receivers.size()); 2013 // Registered stream's remote SSRC is kSsrc2. Send a packet with SSRC=1.
2014 // We should drop the packet and no stats should be available.
2003 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 2015 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2004 EXPECT_EQ(true, channel_->GetStats(&info)); 2016 EXPECT_EQ(true, channel_->GetStats(&info));
2017 EXPECT_EQ(0u, info.receivers.size());
2005 2018
2019 // Remove the kSsrc2 stream and deliver a new packet - a default receive
2020 // stream should be created and we should see stats.
2021 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2022 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2023 EXPECT_EQ(true, channel_->GetStats(&info));
2006 EXPECT_EQ(1u, info.receivers.size()); 2024 EXPECT_EQ(1u, info.receivers.size());
2025
2007 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd); 2026 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2008 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd); 2027 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2009 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost); 2028 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2010 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum); 2029 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2011 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name); 2030 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
2012 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) / 2031 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2013 (1 << 14), info.receivers[0].expand_rate); 2032 (1 << 14), info.receivers[0].expand_rate);
2014 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) / 2033 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2015 (1 << 14), info.receivers[0].speech_expand_rate); 2034 (1 << 14), info.receivers[0].speech_expand_rate);
2016 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) / 2035 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2017 (1 << 14), info.receivers[0].secondary_decoded_rate); 2036 (1 << 14), info.receivers[0].secondary_decoded_rate);
2018 EXPECT_EQ( 2037 EXPECT_EQ(
2019 static_cast<float>(cricket::kNetStats.currentAccelerateRate) / (1 << 14), 2038 static_cast<float>(cricket::kNetStats.currentAccelerateRate) / (1 << 14),
2020 info.receivers[0].accelerate_rate); 2039 info.receivers[0].accelerate_rate);
2021 EXPECT_EQ( 2040 EXPECT_EQ(
2022 static_cast<float>(cricket::kNetStats.currentPreemptiveRate) / (1 << 14), 2041 static_cast<float>(cricket::kNetStats.currentPreemptiveRate) / (1 << 14),
2023 info.receivers[0].preemptive_expand_rate); 2042 info.receivers[0].preemptive_expand_rate);
2024 } 2043 }
2025 2044
2026 // Test that we can add and remove receive streams, and do proper send/playout. 2045 // Test that we can add and remove receive streams, and do proper send/playout.
2027 // We can receive on multiple streams while sending one stream. 2046 // We can receive on multiple streams while sending one stream.
2028 TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) { 2047 TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
2029 EXPECT_TRUE(SetupEngine()); 2048 EXPECT_TRUE(SetupEngineWithSendStream());
2030 int channel_num1 = voe_.GetLastChannel(); 2049 int channel_num1 = voe_.GetLastChannel();
2031 2050
2032 // Start playout on the default channel. 2051 // Start playout without a receive stream.
2033 send_parameters_.options = options_conference_;
2034 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2052 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2035 EXPECT_TRUE(channel_->SetPlayout(true)); 2053 EXPECT_TRUE(channel_->SetPlayout(true));
2036 EXPECT_TRUE(voe_.GetPlayout(channel_num1)); 2054 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2037 2055
2038 // Adding another stream should disable playout on the default channel. 2056 // Adding another stream should enable playout on the new stream only.
2039 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2057 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2040 int channel_num2 = voe_.GetLastChannel(); 2058 int channel_num2 = voe_.GetLastChannel();
2041 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); 2059 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2042 EXPECT_TRUE(voe_.GetSend(channel_num1)); 2060 EXPECT_TRUE(voe_.GetSend(channel_num1));
2043 EXPECT_FALSE(voe_.GetSend(channel_num2)); 2061 EXPECT_FALSE(voe_.GetSend(channel_num2));
2044 2062
2045 // Make sure only the new channel is played out. 2063 // Make sure only the new stream is played out.
2046 EXPECT_FALSE(voe_.GetPlayout(channel_num1)); 2064 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2047 EXPECT_TRUE(voe_.GetPlayout(channel_num2)); 2065 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2048 2066
2049 // Adding yet another stream should have stream 2 and 3 enabled for playout. 2067 // Adding yet another stream should have stream 2 and 3 enabled for playout.
2050 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 2068 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2051 int channel_num3 = voe_.GetLastChannel(); 2069 int channel_num3 = voe_.GetLastChannel();
2052 EXPECT_FALSE(voe_.GetPlayout(channel_num1)); 2070 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2053 EXPECT_TRUE(voe_.GetPlayout(channel_num2)); 2071 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2054 EXPECT_TRUE(voe_.GetPlayout(channel_num3)); 2072 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2055 EXPECT_FALSE(voe_.GetSend(channel_num3)); 2073 EXPECT_FALSE(voe_.GetSend(channel_num3));
2056 2074
2057 // Stop sending. 2075 // Stop sending.
2058 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); 2076 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2059 EXPECT_FALSE(voe_.GetSend(channel_num1)); 2077 EXPECT_FALSE(voe_.GetSend(channel_num1));
2060 EXPECT_FALSE(voe_.GetSend(channel_num2)); 2078 EXPECT_FALSE(voe_.GetSend(channel_num2));
2061 EXPECT_FALSE(voe_.GetSend(channel_num3)); 2079 EXPECT_FALSE(voe_.GetSend(channel_num3));
2062 2080
2063 // Stop playout. 2081 // Stop playout.
2064 EXPECT_TRUE(channel_->SetPlayout(false)); 2082 EXPECT_TRUE(channel_->SetPlayout(false));
2065 EXPECT_FALSE(voe_.GetPlayout(channel_num1)); 2083 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2066 EXPECT_FALSE(voe_.GetPlayout(channel_num2)); 2084 EXPECT_FALSE(voe_.GetPlayout(channel_num2));
2067 EXPECT_FALSE(voe_.GetPlayout(channel_num3)); 2085 EXPECT_FALSE(voe_.GetPlayout(channel_num3));
2068 2086
2069 // Restart playout and make sure the default channel still is not played out. 2087 // Restart playout and make sure only recv streams are played out.
2070 EXPECT_TRUE(channel_->SetPlayout(true)); 2088 EXPECT_TRUE(channel_->SetPlayout(true));
2071 EXPECT_FALSE(voe_.GetPlayout(channel_num1)); 2089 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2072 EXPECT_TRUE(voe_.GetPlayout(channel_num2)); 2090 EXPECT_TRUE(voe_.GetPlayout(channel_num2));
2073 EXPECT_TRUE(voe_.GetPlayout(channel_num3)); 2091 EXPECT_TRUE(voe_.GetPlayout(channel_num3));
2074 2092
2075 // Now remove the new streams and verify that the default channel is 2093 // Now remove the recv streams and verify that the send stream doesn't play.
2076 // played out again.
2077 EXPECT_TRUE(channel_->RemoveRecvStream(3)); 2094 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2078 EXPECT_TRUE(channel_->RemoveRecvStream(2)); 2095 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2079 2096 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2080 EXPECT_TRUE(voe_.GetPlayout(channel_num1));
2081 } 2097 }
2082 2098
2083 // Test that we can set the devices to use. 2099 // Test that we can set the devices to use.
2084 TEST_F(WebRtcVoiceEngineTestFake, SetDevices) { 2100 TEST_F(WebRtcVoiceEngineTestFake, SetDevices) {
2085 EXPECT_TRUE(SetupEngine()); 2101 EXPECT_TRUE(SetupEngineWithSendStream());
2086 int channel_num = voe_.GetLastChannel(); 2102 int send_channel = voe_.GetLastChannel();
2103 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2104 int recv_channel = voe_.GetLastChannel();
2087 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2105 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2088 2106
2089 cricket::Device default_dev(cricket::kFakeDefaultDeviceName, 2107 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2090 cricket::kFakeDefaultDeviceId); 2108 cricket::kFakeDefaultDeviceId);
2091 cricket::Device dev(cricket::kFakeDeviceName, 2109 cricket::Device dev(cricket::kFakeDeviceName,
2092 cricket::kFakeDeviceId); 2110 cricket::kFakeDeviceId);
2093 2111
2094 // Test SetDevices() while not sending or playing. 2112 // Test SetDevices() while not sending or playing.
2095 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev)); 2113 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2096 2114
2097 // Test SetDevices() while sending and playing. 2115 // Test SetDevices() while sending and playing.
2098 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); 2116 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2099 EXPECT_TRUE(channel_->SetPlayout(true)); 2117 EXPECT_TRUE(channel_->SetPlayout(true));
2100 EXPECT_TRUE(voe_.GetSend(channel_num)); 2118 EXPECT_TRUE(voe_.GetSend(send_channel));
2101 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 2119 EXPECT_TRUE(voe_.GetPlayout(recv_channel));
2102 2120
2103 EXPECT_TRUE(engine_.SetDevices(&dev, &dev)); 2121 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2104 2122
2105 EXPECT_TRUE(voe_.GetSend(channel_num)); 2123 EXPECT_TRUE(voe_.GetSend(send_channel));
2106 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 2124 EXPECT_TRUE(voe_.GetPlayout(recv_channel));
2107 2125
2108 // Test that failure to open newly selected devices does not prevent opening 2126 // Test that failure to open newly selected devices does not prevent opening
2109 // ones after that. 2127 // ones after that.
2110 voe_.set_playout_fail_channel(channel_num); 2128 voe_.set_playout_fail_channel(recv_channel);
2111 voe_.set_send_fail_channel(channel_num); 2129 voe_.set_send_fail_channel(send_channel);
2112 2130
2113 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev)); 2131 EXPECT_FALSE(engine_.SetDevices(&default_dev, &default_dev));
2114 2132
2115 EXPECT_FALSE(voe_.GetSend(channel_num)); 2133 EXPECT_FALSE(voe_.GetSend(send_channel));
2116 EXPECT_FALSE(voe_.GetPlayout(channel_num)); 2134 EXPECT_FALSE(voe_.GetPlayout(recv_channel));
2117 2135
2118 voe_.set_playout_fail_channel(-1); 2136 voe_.set_playout_fail_channel(-1);
2119 voe_.set_send_fail_channel(-1); 2137 voe_.set_send_fail_channel(-1);
2120 2138
2121 EXPECT_TRUE(engine_.SetDevices(&dev, &dev)); 2139 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2122 2140
2123 EXPECT_TRUE(voe_.GetSend(channel_num)); 2141 EXPECT_TRUE(voe_.GetSend(send_channel));
2124 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 2142 EXPECT_TRUE(voe_.GetPlayout(recv_channel));
2125 } 2143 }
2126 2144
2127 // Test that we can set the devices to use even if we failed to 2145 // Test that we can set the devices to use even if we failed to
2128 // open the initial ones. 2146 // open the initial ones.
2129 TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) { 2147 TEST_F(WebRtcVoiceEngineTestFake, SetDevicesWithInitiallyBadDevices) {
2130 EXPECT_TRUE(SetupEngine()); 2148 EXPECT_TRUE(SetupEngineWithSendStream());
2131 int channel_num = voe_.GetLastChannel(); 2149 int send_channel = voe_.GetLastChannel();
2150 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2151 int recv_channel = voe_.GetLastChannel();
2132 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2152 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2133 2153
2134 cricket::Device default_dev(cricket::kFakeDefaultDeviceName, 2154 cricket::Device default_dev(cricket::kFakeDefaultDeviceName,
2135 cricket::kFakeDefaultDeviceId); 2155 cricket::kFakeDefaultDeviceId);
2136 cricket::Device dev(cricket::kFakeDeviceName, 2156 cricket::Device dev(cricket::kFakeDeviceName,
2137 cricket::kFakeDeviceId); 2157 cricket::kFakeDeviceId);
2138 2158
2139 // Test that failure to open devices selected before starting 2159 // Test that failure to open devices selected before starting
2140 // send/play does not prevent opening newly selected ones after that. 2160 // send/play does not prevent opening newly selected ones after that.
2141 voe_.set_playout_fail_channel(channel_num); 2161 voe_.set_playout_fail_channel(recv_channel);
2142 voe_.set_send_fail_channel(channel_num); 2162 voe_.set_send_fail_channel(send_channel);
2143 2163
2144 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev)); 2164 EXPECT_TRUE(engine_.SetDevices(&default_dev, &default_dev));
2145 2165
2146 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE)); 2166 EXPECT_FALSE(channel_->SetSend(cricket::SEND_MICROPHONE));
2147 EXPECT_FALSE(channel_->SetPlayout(true)); 2167 EXPECT_FALSE(channel_->SetPlayout(true));
2148 EXPECT_FALSE(voe_.GetSend(channel_num)); 2168 EXPECT_FALSE(voe_.GetSend(send_channel));
2149 EXPECT_FALSE(voe_.GetPlayout(channel_num)); 2169 EXPECT_FALSE(voe_.GetPlayout(recv_channel));
2150 2170
2151 voe_.set_playout_fail_channel(-1); 2171 voe_.set_playout_fail_channel(-1);
2152 voe_.set_send_fail_channel(-1); 2172 voe_.set_send_fail_channel(-1);
2153 2173
2154 EXPECT_TRUE(engine_.SetDevices(&dev, &dev)); 2174 EXPECT_TRUE(engine_.SetDevices(&dev, &dev));
2155 2175
2156 EXPECT_TRUE(voe_.GetSend(channel_num)); 2176 EXPECT_TRUE(voe_.GetSend(send_channel));
2157 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 2177 EXPECT_TRUE(voe_.GetPlayout(recv_channel));
2158 }
2159
2160 // Test that we can create a channel configured for multi-point conferences,
2161 // and start sending/playing out on it.
2162 TEST_F(WebRtcVoiceEngineTestFake, ConferenceSendAndPlayout) {
2163 EXPECT_TRUE(SetupEngine());
2164 int channel_num = voe_.GetLastChannel();
2165 send_parameters_.options = options_conference_;
2166 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2167 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2168 EXPECT_TRUE(voe_.GetSend(channel_num));
2169 } 2178 }
2170 2179
2171 // Test that we can create a channel configured for Codian bridges, 2180 // Test that we can create a channel configured for Codian bridges,
2172 // and start sending/playing out on it. 2181 // and start sending on it.
2173 TEST_F(WebRtcVoiceEngineTestFake, CodianSendAndPlayout) { 2182 TEST_F(WebRtcVoiceEngineTestFake, CodianSend) {
2174 EXPECT_TRUE(SetupEngine()); 2183 EXPECT_TRUE(SetupEngineWithSendStream());
2175 int channel_num = voe_.GetLastChannel(); 2184 int channel_num = voe_.GetLastChannel();
2176 webrtc::AgcConfig agc_config; 2185 webrtc::AgcConfig agc_config;
2177 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2186 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2178 EXPECT_EQ(0, agc_config.targetLeveldBOv); 2187 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2179 send_parameters_.options = options_adjust_agc_; 2188 send_parameters_.options = options_adjust_agc_;
2180 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2189 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2181 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); 2190 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2182 EXPECT_TRUE(voe_.GetSend(channel_num)); 2191 EXPECT_TRUE(voe_.GetSend(channel_num));
2183 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2192 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2184 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated 2193 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2185 EXPECT_TRUE(channel_->SetPlayout(true));
2186 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2187 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING)); 2194 EXPECT_TRUE(channel_->SetSend(cricket::SEND_NOTHING));
2188 EXPECT_FALSE(voe_.GetSend(channel_num)); 2195 EXPECT_FALSE(voe_.GetSend(channel_num));
2189 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2196 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2190 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored 2197 EXPECT_EQ(0, agc_config.targetLeveldBOv); // level was restored
2191 EXPECT_TRUE(channel_->SetPlayout(false));
2192 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2193 } 2198 }
2194 2199
2195 TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { 2200 TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2196 EXPECT_TRUE(SetupEngine()); 2201 EXPECT_TRUE(SetupEngineWithSendStream());
2197 webrtc::AgcConfig agc_config; 2202 webrtc::AgcConfig agc_config;
2198 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2203 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2199 EXPECT_EQ(0, agc_config.targetLeveldBOv); 2204 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2200 2205
2201 cricket::AudioOptions options; 2206 cricket::AudioOptions options;
2202 options.tx_agc_target_dbov.Set(3); 2207 options.tx_agc_target_dbov.Set(3);
2203 options.tx_agc_digital_compression_gain.Set(9); 2208 options.tx_agc_digital_compression_gain.Set(9);
2204 options.tx_agc_limiter.Set(true); 2209 options.tx_agc_limiter.Set(true);
2205 options.auto_gain_control.Set(true); 2210 options.auto_gain_control.Set(true);
2206 EXPECT_TRUE(engine_.SetOptions(options)); 2211 EXPECT_TRUE(engine_.SetOptions(options));
2207 2212
2208 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2213 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2209 EXPECT_EQ(3, agc_config.targetLeveldBOv); 2214 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2210 EXPECT_EQ(9, agc_config.digitalCompressionGaindB); 2215 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2211 EXPECT_TRUE(agc_config.limiterEnable); 2216 EXPECT_TRUE(agc_config.limiterEnable);
2212 2217
2213 // Check interaction with adjust_agc_delta. Both should be respected, for 2218 // Check interaction with adjust_agc_delta. Both should be respected, for
2214 // backwards compatibility. 2219 // backwards compatibility.
2215 options.adjust_agc_delta.Set(-10); 2220 options.adjust_agc_delta.Set(-10);
2216 EXPECT_TRUE(engine_.SetOptions(options)); 2221 EXPECT_TRUE(engine_.SetOptions(options));
2217 2222
2218 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2223 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2219 EXPECT_EQ(13, agc_config.targetLeveldBOv); 2224 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2220 } 2225 }
2221 2226
2222 TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) { 2227 TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2223 EXPECT_TRUE(SetupEngine()); 2228 EXPECT_TRUE(SetupEngineWithSendStream());
2224 cricket::AudioOptions options; 2229 cricket::AudioOptions options;
2225 options.recording_sample_rate.Set(48000u); 2230 options.recording_sample_rate.Set(48000u);
2226 options.playout_sample_rate.Set(44100u); 2231 options.playout_sample_rate.Set(44100u);
2227 EXPECT_TRUE(engine_.SetOptions(options)); 2232 EXPECT_TRUE(engine_.SetOptions(options));
2228 2233
2229 unsigned int recording_sample_rate, playout_sample_rate; 2234 unsigned int recording_sample_rate, playout_sample_rate;
2230 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate)); 2235 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2231 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate)); 2236 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2232 EXPECT_EQ(48000u, recording_sample_rate); 2237 EXPECT_EQ(48000u, recording_sample_rate);
2233 EXPECT_EQ(44100u, playout_sample_rate); 2238 EXPECT_EQ(44100u, playout_sample_rate);
2234 } 2239 }
2235 2240
2236 TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) { 2241 TEST_F(WebRtcVoiceEngineTestFake, TraceFilterViaTraceOptions) {
2237 EXPECT_TRUE(SetupEngine()); 2242 EXPECT_TRUE(SetupEngineWithSendStream());
2238 engine_.SetLogging(rtc::LS_INFO, ""); 2243 engine_.SetLogging(rtc::LS_INFO, "");
2239 EXPECT_EQ( 2244 EXPECT_EQ(
2240 // Info: 2245 // Info:
2241 webrtc::kTraceStateInfo | webrtc::kTraceInfo | 2246 webrtc::kTraceStateInfo | webrtc::kTraceInfo |
2242 // Warning: 2247 // Warning:
2243 webrtc::kTraceTerseInfo | webrtc::kTraceWarning | 2248 webrtc::kTraceTerseInfo | webrtc::kTraceWarning |
2244 // Error: 2249 // Error:
2245 webrtc::kTraceError | webrtc::kTraceCritical, 2250 webrtc::kTraceError | webrtc::kTraceCritical,
2246 static_cast<int>(trace_wrapper_->filter_)); 2251 static_cast<int>(trace_wrapper_->filter_));
2247 // Now set it explicitly 2252 // Now set it explicitly
2248 std::string filter = 2253 std::string filter =
2249 "tracefilter " + rtc::ToString(webrtc::kTraceDefault); 2254 "tracefilter " + rtc::ToString(webrtc::kTraceDefault);
2250 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str()); 2255 engine_.SetLogging(rtc::LS_VERBOSE, filter.c_str());
2251 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault), 2256 EXPECT_EQ(static_cast<unsigned int>(webrtc::kTraceDefault),
2252 trace_wrapper_->filter_); 2257 trace_wrapper_->filter_);
2253 } 2258 }
2254 2259
2255 // Test that we can set the outgoing SSRC properly. 2260 // Test that we can set the outgoing SSRC properly.
2256 // SSRC is set in SetupEngine by calling AddSendStream. 2261 // SSRC is set in SetupEngine by calling AddSendStream.
2257 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) { 2262 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2258 EXPECT_TRUE(SetupEngine()); 2263 EXPECT_TRUE(SetupEngineWithSendStream());
2259 int channel_num = voe_.GetLastChannel(); 2264 int channel_num = voe_.GetLastChannel();
2260 unsigned int send_ssrc; 2265 unsigned int send_ssrc;
2261 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc)); 2266 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2262 EXPECT_NE(0U, send_ssrc); 2267 EXPECT_NE(0U, send_ssrc);
2263 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc)); 2268 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num, send_ssrc));
2264 EXPECT_EQ(kSsrc1, send_ssrc); 2269 EXPECT_EQ(kSsrc1, send_ssrc);
2265 } 2270 }
2266 2271
2267 TEST_F(WebRtcVoiceEngineTestFake, GetStats) { 2272 TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2268 // Setup. We need send codec to be set to get all stats. 2273 // Setup. We need send codec to be set to get all stats.
2269 EXPECT_TRUE(SetupEngine()); 2274 EXPECT_TRUE(SetupEngineWithSendStream());
2270 // SetupEngine adds a send stream with kSsrc1, so the receive stream has to 2275 // SetupEngineWithSendStream adds a send stream with kSsrc1, so the receive
2271 // use a different SSRC. 2276 // stream has to use a different SSRC.
2272 EXPECT_TRUE(channel_->AddRecvStream( 2277 EXPECT_TRUE(channel_->AddRecvStream(
2273 cricket::StreamParams::CreateLegacy(kSsrc2))); 2278 cricket::StreamParams::CreateLegacy(kSsrc2)));
2274 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2279 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2275 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); 2280 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_));
2276 2281
2277 cricket::VoiceMediaInfo info; 2282 cricket::VoiceMediaInfo info;
2278 EXPECT_EQ(true, channel_->GetStats(&info)); 2283 EXPECT_EQ(true, channel_->GetStats(&info));
2279 EXPECT_EQ(1u, info.senders.size()); 2284 EXPECT_EQ(1u, info.senders.size());
2280 EXPECT_EQ(kSsrc1, info.senders[0].ssrc()); 2285 EXPECT_EQ(kSsrc1, info.senders[0].ssrc());
2281 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name); 2286 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2282 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent); 2287 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].bytes_sent);
2283 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent); 2288 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_sent);
2284 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost); 2289 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].packets_lost);
2285 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost); 2290 EXPECT_EQ(cricket::kFractionLostStatValue, info.senders[0].fraction_lost);
2286 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum); 2291 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].ext_seqnum);
2287 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms); 2292 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].rtt_ms);
2288 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms); 2293 EXPECT_EQ(cricket::kIntStatValue, info.senders[0].jitter_ms);
2289 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name); 2294 EXPECT_EQ(kPcmuCodec.name, info.senders[0].codec_name);
2290 // TODO(sriniv): Add testing for more fields. These are not populated 2295 // TODO(sriniv): Add testing for more fields. These are not populated
2291 // in FakeWebrtcVoiceEngine yet. 2296 // in FakeWebrtcVoiceEngine yet.
2292 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level); 2297 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].audio_level);
2293 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms); 2298 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_median_ms);
2294 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms); 2299 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_delay_std_ms);
2295 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss); 2300 // EXPECT_EQ(cricket::kIntStatValue, info.senders[0].echo_return_loss);
2296 // EXPECT_EQ(cricket::kIntStatValue, 2301 // EXPECT_EQ(cricket::kIntStatValue,
2297 // info.senders[0].echo_return_loss_enhancement); 2302 // info.senders[0].echo_return_loss_enhancement);
2303 EXPECT_EQ(0u, info.receivers.size());
2298 2304
2305 // Registered stream's remote SSRC is kSsrc2. Send a packet with SSRC=1.
2306 // We should drop the packet and no stats should be available.
2307 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2308 EXPECT_EQ(true, channel_->GetStats(&info));
2299 EXPECT_EQ(0u, info.receivers.size()); 2309 EXPECT_EQ(0u, info.receivers.size());
2310
2311 // Remove the kSsrc2 stream and deliver a new packet - a default receive
2312 // stream should be created and we should see stats.
2313 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc2));
2300 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 2314 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2301 EXPECT_EQ(true, channel_->GetStats(&info)); 2315 EXPECT_EQ(true, channel_->GetStats(&info));
2302 EXPECT_EQ(1u, info.receivers.size()); 2316 EXPECT_EQ(1u, info.receivers.size());
2303 2317
2304 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd); 2318 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].bytes_rcvd);
2305 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd); 2319 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_rcvd);
2306 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost); 2320 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].packets_lost);
2307 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum); 2321 EXPECT_EQ(cricket::kIntStatValue, info.receivers[0].ext_seqnum);
2308 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name); 2322 EXPECT_EQ(kPcmuCodec.name, info.receivers[0].codec_name);
2309 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) / 2323 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentExpandRate) /
2310 (1 << 14), info.receivers[0].expand_rate); 2324 (1 << 14), info.receivers[0].expand_rate);
2311 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) / 2325 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSpeechExpandRate) /
2312 (1 << 14), info.receivers[0].speech_expand_rate); 2326 (1 << 14), info.receivers[0].speech_expand_rate);
2313 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) / 2327 EXPECT_EQ(static_cast<float>(cricket::kNetStats.currentSecondaryDecodedRate) /
2314 (1 << 14), info.receivers[0].secondary_decoded_rate); 2328 (1 << 14), info.receivers[0].secondary_decoded_rate);
2315 // TODO(sriniv): Add testing for more receiver fields. 2329 // TODO(sriniv): Add testing for more receiver fields.
2316 } 2330 }
2317 2331
2318 // Test that we can set the outgoing SSRC properly with multiple streams. 2332 // Test that we can set the outgoing SSRC properly with multiple streams.
2319 // SSRC is set in SetupEngine by calling AddSendStream. 2333 // SSRC is set in SetupEngine by calling AddSendStream.
2320 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) { 2334 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2321 EXPECT_TRUE(SetupEngine()); 2335 EXPECT_TRUE(SetupEngineWithSendStream());
2322 int channel_num1 = voe_.GetLastChannel(); 2336 int channel_num1 = voe_.GetLastChannel();
2323 unsigned int send_ssrc; 2337 unsigned int send_ssrc;
2324 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc)); 2338 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num1, send_ssrc));
2325 EXPECT_EQ(kSsrc1, send_ssrc); 2339 EXPECT_EQ(kSsrc1, send_ssrc);
2326 2340
2327 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2341 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2328 int channel_num2 = voe_.GetLastChannel(); 2342 int channel_num2 = voe_.GetLastChannel();
2329 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc)); 2343 EXPECT_EQ(0, voe_.GetLocalSSRC(channel_num2, send_ssrc));
2330 EXPECT_EQ(kSsrc1, send_ssrc); 2344 EXPECT_EQ(kSsrc1, send_ssrc);
2331 } 2345 }
(...skipping 14 matching lines...) Expand all
2346 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc)); 2360 EXPECT_EQ(0, voe_.GetLocalSSRC(send_channel_num, ssrc));
2347 EXPECT_EQ(1234U, ssrc); 2361 EXPECT_EQ(1234U, ssrc);
2348 ssrc = 0; 2362 ssrc = 0;
2349 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc)); 2363 EXPECT_EQ(0, voe_.GetLocalSSRC(receive_channel_num, ssrc));
2350 EXPECT_EQ(1234U, ssrc); 2364 EXPECT_EQ(1234U, ssrc);
2351 } 2365 }
2352 2366
2353 // Test that we can properly receive packets. 2367 // Test that we can properly receive packets.
2354 TEST_F(WebRtcVoiceEngineTestFake, Recv) { 2368 TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2355 EXPECT_TRUE(SetupEngine()); 2369 EXPECT_TRUE(SetupEngine());
2370 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2356 int channel_num = voe_.GetLastChannel(); 2371 int channel_num = voe_.GetLastChannel();
2357 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2358 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, 2372 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame,
2359 sizeof(kPcmuFrame))); 2373 sizeof(kPcmuFrame)));
2360 } 2374 }
2361 2375
2362 // Test that we can properly receive packets on multiple streams. 2376 // Test that we can properly receive packets on multiple streams.
2363 TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) { 2377 TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2364 EXPECT_TRUE(SetupEngine()); 2378 EXPECT_TRUE(SetupEngineWithSendStream());
2365 send_parameters_.options = options_conference_;
2366 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2379 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2367 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2380 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2368 int channel_num1 = voe_.GetLastChannel(); 2381 int channel_num1 = voe_.GetLastChannel();
2369 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2382 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2370 int channel_num2 = voe_.GetLastChannel(); 2383 int channel_num2 = voe_.GetLastChannel();
2371 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 2384 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2372 int channel_num3 = voe_.GetLastChannel(); 2385 int channel_num3 = voe_.GetLastChannel();
2373 // Create packets with the right SSRCs. 2386 // Create packets with the right SSRCs.
2374 char packets[4][sizeof(kPcmuFrame)]; 2387 char packets[4][sizeof(kPcmuFrame)];
2375 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) { 2388 for (size_t i = 0; i < ARRAY_SIZE(packets); ++i) {
(...skipping 22 matching lines...) Expand all
2398 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); 2411 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2));
2399 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3], 2412 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3],
2400 sizeof(packets[3]))); 2413 sizeof(packets[3])));
2401 EXPECT_TRUE(channel_->RemoveRecvStream(3)); 2414 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2402 EXPECT_TRUE(channel_->RemoveRecvStream(2)); 2415 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2403 EXPECT_TRUE(channel_->RemoveRecvStream(1)); 2416 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2404 } 2417 }
2405 2418
2406 // Test that we properly handle failures to add a stream. 2419 // Test that we properly handle failures to add a stream.
2407 TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) { 2420 TEST_F(WebRtcVoiceEngineTestFake, AddStreamFail) {
2408 EXPECT_TRUE(SetupEngine()); 2421 EXPECT_TRUE(SetupEngineWithSendStream());
2409 voe_.set_fail_create_channel(true); 2422 voe_.set_fail_create_channel(true);
2410 send_parameters_.options = options_conference_;
2411 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2423 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2412 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2424 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2413
2414 // In 1:1 call, we should not try to create a new channel.
2415 send_parameters_.options.conference_mode.Set(false);
2416 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2417 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2418 } 2425 }
2419 2426
2420 // Test that AddRecvStream doesn't create new channel for 1:1 call. 2427 // Test that AddRecvStream creates new stream.
2421 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream1On1) { 2428 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream) {
2422 EXPECT_TRUE(SetupEngine()); 2429 EXPECT_TRUE(SetupEngineWithRecvStream());
2423 int channel_num = voe_.GetLastChannel(); 2430 int channel_num = voe_.GetLastChannel();
2424 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2431 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2425 EXPECT_EQ(channel_num, voe_.GetLastChannel()); 2432 EXPECT_NE(channel_num, voe_.GetLastChannel());
2426 } 2433 }
2427 2434
2428 // Test that after adding a recv stream, we do not decode more codecs than 2435 // Test that after adding a recv stream, we do not decode more codecs than
2429 // those previously passed into SetRecvCodecs. 2436 // those previously passed into SetRecvCodecs.
2430 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) { 2437 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2431 EXPECT_TRUE(SetupEngine()); 2438 EXPECT_TRUE(SetupEngineWithSendStream());
2432 cricket::AudioRecvParameters parameters; 2439 cricket::AudioRecvParameters parameters;
2433 parameters.codecs.push_back(kIsacCodec); 2440 parameters.codecs.push_back(kIsacCodec);
2434 parameters.codecs.push_back(kPcmuCodec); 2441 parameters.codecs.push_back(kPcmuCodec);
2435 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 2442 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
2436 EXPECT_TRUE(channel_->AddRecvStream( 2443 EXPECT_TRUE(channel_->AddRecvStream(
2437 cricket::StreamParams::CreateLegacy(kSsrc1))); 2444 cricket::StreamParams::CreateLegacy(kSsrc1)));
2438 int channel_num2 = voe_.GetLastChannel(); 2445 int channel_num2 = voe_.GetLastChannel();
2439 webrtc::CodecInst gcodec; 2446 webrtc::CodecInst gcodec;
2440 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus"); 2447 rtc::strcpyn(gcodec.plname, ARRAY_SIZE(gcodec.plname), "opus");
2441 gcodec.plfreq = 48000; 2448 gcodec.plfreq = 48000;
2442 gcodec.channels = 2; 2449 gcodec.channels = 2;
2443 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec)); 2450 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2444 } 2451 }
2445 2452
2446 // Test that we properly clean up any streams that were added, even if 2453 // Test that we properly clean up any streams that were added, even if
2447 // not explicitly removed. 2454 // not explicitly removed.
2448 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) { 2455 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2449 EXPECT_TRUE(SetupEngine()); 2456 EXPECT_TRUE(SetupEngineWithSendStream());
2450 send_parameters_.options = options_conference_;
2451 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2457 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2452 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2458 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2453 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2459 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2454 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added 2460 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2455 delete channel_; 2461 delete channel_;
2456 channel_ = NULL; 2462 channel_ = NULL;
2457 EXPECT_EQ(0, voe_.GetNumChannels()); 2463 EXPECT_EQ(0, voe_.GetNumChannels());
2458 } 2464 }
2459 2465
2460 TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) { 2466 TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2461 EXPECT_TRUE(SetupEngine()); 2467 EXPECT_TRUE(SetupEngineWithSendStream());
2462 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0))); 2468 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2463 } 2469 }
2464 2470
2465 TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) { 2471 TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2466 EXPECT_TRUE(SetupEngine()); 2472 EXPECT_TRUE(SetupEngine());
2467 // Stream 1 reuses default channel.
2468 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2473 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2469 // Manually delete default channel to simulate a failure. 2474 // Manually delete channel to simulate a failure.
2470 int default_channel = voe_.GetLastChannel(); 2475 int channel = voe_.GetLastChannel();
2471 EXPECT_EQ(0, voe_.DeleteChannel(default_channel)); 2476 EXPECT_EQ(0, voe_.DeleteChannel(channel));
2472 // Add recv stream 2 should fail because default channel is gone. 2477 // Add recv stream 2 should work.
2473 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2478 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2474 int new_channel = voe_.GetLastChannel(); 2479 int new_channel = voe_.GetLastChannel();
2475 EXPECT_NE(default_channel, new_channel); 2480 EXPECT_NE(channel, new_channel);
2476 // The last created channel should have already been deleted. 2481 // The last created channel is deleted too.
2477 EXPECT_EQ(-1, voe_.DeleteChannel(new_channel)); 2482 EXPECT_EQ(0, voe_.DeleteChannel(new_channel));
2478 } 2483 }
2479 2484
2480 // Test the InsertDtmf on default send stream as caller. 2485 // Test the InsertDtmf on default send stream as caller.
2481 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) { 2486 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCaller) {
2482 TestInsertDtmf(0, true); 2487 TestInsertDtmf(0, true);
2483 } 2488 }
2484 2489
2485 // Test the InsertDtmf on default send stream as callee 2490 // Test the InsertDtmf on default send stream as callee
2486 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) { 2491 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnDefaultSendStreamAsCallee) {
2487 TestInsertDtmf(0, false); 2492 TestInsertDtmf(0, false);
2488 } 2493 }
2489 2494
2490 // Test the InsertDtmf on specified send stream as caller. 2495 // Test the InsertDtmf on specified send stream as caller.
2491 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) { 2496 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2492 TestInsertDtmf(kSsrc1, true); 2497 TestInsertDtmf(kSsrc1, true);
2493 } 2498 }
2494 2499
2495 // Test the InsertDtmf on specified send stream as callee. 2500 // Test the InsertDtmf on specified send stream as callee.
2496 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) { 2501 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2497 TestInsertDtmf(kSsrc1, false); 2502 TestInsertDtmf(kSsrc1, false);
2498 } 2503 }
2499 2504
2500 TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) { 2505 TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2501 EXPECT_TRUE(SetupEngine()); 2506 EXPECT_TRUE(SetupEngineWithSendStream());
2502 send_parameters_.options = options_conference_;
2503 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2507 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2504 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE)); 2508 EXPECT_TRUE(channel_->SetSend(cricket::SEND_MICROPHONE));
2505 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2509 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2506 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 2510 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2507 EXPECT_TRUE(channel_->SetPlayout(true)); 2511 EXPECT_TRUE(channel_->SetPlayout(true));
2508 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1); 2512 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2509 EXPECT_TRUE(channel_->SetPlayout(false)); 2513 EXPECT_TRUE(channel_->SetPlayout(false));
2510 EXPECT_FALSE(channel_->SetPlayout(true)); 2514 EXPECT_FALSE(channel_->SetPlayout(true));
2511 } 2515 }
2512 2516
2513 TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { 2517 TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2514 EXPECT_TRUE(SetupEngine()); 2518 EXPECT_TRUE(SetupEngineWithSendStream());
2515 2519
2516 bool ec_enabled; 2520 bool ec_enabled;
2517 webrtc::EcModes ec_mode; 2521 webrtc::EcModes ec_mode;
2518 bool ec_metrics_enabled; 2522 bool ec_metrics_enabled;
2519 webrtc::AecmModes aecm_mode; 2523 webrtc::AecmModes aecm_mode;
2520 bool cng_enabled; 2524 bool cng_enabled;
2521 bool agc_enabled; 2525 bool agc_enabled;
2522 webrtc::AgcModes agc_mode; 2526 webrtc::AgcModes agc_mode;
2523 webrtc::AgcConfig agc_config; 2527 webrtc::AgcConfig agc_config;
2524 bool ns_enabled; 2528 bool ns_enabled;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
2654 ASSERT_TRUE(engine_.SetOptions(options)); 2658 ASSERT_TRUE(engine_.SetOptions(options));
2655 voe_.GetNsStatus(ns_enabled, ns_mode); 2659 voe_.GetNsStatus(ns_enabled, ns_mode);
2656 highpass_filter_enabled = voe_.IsHighPassFilterEnabled(); 2660 highpass_filter_enabled = voe_.IsHighPassFilterEnabled();
2657 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled(); 2661 stereo_swapping_enabled = voe_.IsStereoChannelSwappingEnabled();
2658 voe_.GetTypingDetectionStatus(typing_detection_enabled); 2662 voe_.GetTypingDetectionStatus(typing_detection_enabled);
2659 EXPECT_FALSE(ns_enabled); 2663 EXPECT_FALSE(ns_enabled);
2660 EXPECT_FALSE(highpass_filter_enabled); 2664 EXPECT_FALSE(highpass_filter_enabled);
2661 EXPECT_FALSE(typing_detection_enabled); 2665 EXPECT_FALSE(typing_detection_enabled);
2662 EXPECT_TRUE(stereo_swapping_enabled); 2666 EXPECT_TRUE(stereo_swapping_enabled);
2663 2667
2664 // Turn on "conference mode" to ensure it has no impact. 2668 // Set options again to ensure it has no impact.
2665 options.conference_mode.Set(true);
2666 ASSERT_TRUE(engine_.SetOptions(options)); 2669 ASSERT_TRUE(engine_.SetOptions(options));
2667 voe_.GetEcStatus(ec_enabled, ec_mode); 2670 voe_.GetEcStatus(ec_enabled, ec_mode);
2668 voe_.GetNsStatus(ns_enabled, ns_mode); 2671 voe_.GetNsStatus(ns_enabled, ns_mode);
2669 EXPECT_TRUE(ec_enabled); 2672 EXPECT_TRUE(ec_enabled);
2670 EXPECT_EQ(webrtc::kEcConference, ec_mode); 2673 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2671 EXPECT_FALSE(ns_enabled); 2674 EXPECT_FALSE(ns_enabled);
2672 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode); 2675 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2673 } 2676 }
2674 2677
2675 TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) { 2678 TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
2676 EXPECT_TRUE(SetupEngine()); 2679 EXPECT_TRUE(SetupEngineWithSendStream());
2677 2680
2678 bool ec_enabled; 2681 bool ec_enabled;
2679 webrtc::EcModes ec_mode; 2682 webrtc::EcModes ec_mode;
2680 bool ec_metrics_enabled; 2683 bool ec_metrics_enabled;
2681 bool agc_enabled; 2684 bool agc_enabled;
2682 webrtc::AgcModes agc_mode; 2685 webrtc::AgcModes agc_mode;
2683 bool ns_enabled; 2686 bool ns_enabled;
2684 webrtc::NsModes ns_mode; 2687 webrtc::NsModes ns_mode;
2685 bool highpass_filter_enabled; 2688 bool highpass_filter_enabled;
2686 bool stereo_swapping_enabled; 2689 bool stereo_swapping_enabled;
(...skipping 24 matching lines...) Expand all
2711 2714
2712 webrtc::AgcConfig config = {0}; 2715 webrtc::AgcConfig config = {0};
2713 EXPECT_EQ(0, voe_.GetAgcConfig(config)); 2716 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2714 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv); 2717 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2715 EXPECT_EQ(set_config.digitalCompressionGaindB, 2718 EXPECT_EQ(set_config.digitalCompressionGaindB,
2716 config.digitalCompressionGaindB); 2719 config.digitalCompressionGaindB);
2717 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable); 2720 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2718 } 2721 }
2719 2722
2720 TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { 2723 TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2721 EXPECT_TRUE(SetupEngine()); 2724 EXPECT_TRUE(SetupEngineWithSendStream());
2722 rtc::scoped_ptr<cricket::WebRtcVoiceMediaChannel> channel1( 2725 rtc::scoped_ptr<cricket::WebRtcVoiceMediaChannel> channel1(
2723 static_cast<cricket::WebRtcVoiceMediaChannel*>( 2726 static_cast<cricket::WebRtcVoiceMediaChannel*>(
2724 engine_.CreateChannel(&call_, cricket::AudioOptions()))); 2727 engine_.CreateChannel(&call_, cricket::AudioOptions())));
2725 rtc::scoped_ptr<cricket::WebRtcVoiceMediaChannel> channel2( 2728 rtc::scoped_ptr<cricket::WebRtcVoiceMediaChannel> channel2(
2726 static_cast<cricket::WebRtcVoiceMediaChannel*>( 2729 static_cast<cricket::WebRtcVoiceMediaChannel*>(
2727 engine_.CreateChannel(&call_, cricket::AudioOptions()))); 2730 engine_.CreateChannel(&call_, cricket::AudioOptions())));
2728 2731
2729 // Have to add a stream to make SetSend work. 2732 // Have to add a stream to make SetSend work.
2730 cricket::StreamParams stream1; 2733 cricket::StreamParams stream1;
2731 stream1.ssrcs.push_back(1); 2734 stream1.ssrcs.push_back(1);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
2824 voe_.GetEcStatus(ec_enabled, ec_mode); 2827 voe_.GetEcStatus(ec_enabled, ec_mode);
2825 voe_.GetAgcStatus(agc_enabled, agc_mode); 2828 voe_.GetAgcStatus(agc_enabled, agc_mode);
2826 voe_.GetNsStatus(ns_enabled, ns_mode); 2829 voe_.GetNsStatus(ns_enabled, ns_mode);
2827 EXPECT_TRUE(ec_enabled); 2830 EXPECT_TRUE(ec_enabled);
2828 EXPECT_FALSE(agc_enabled); 2831 EXPECT_FALSE(agc_enabled);
2829 EXPECT_FALSE(ns_enabled); 2832 EXPECT_FALSE(ns_enabled);
2830 } 2833 }
2831 2834
2832 // This test verifies DSCP settings are properly applied on voice media channel. 2835 // This test verifies DSCP settings are properly applied on voice media channel.
2833 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) { 2836 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
2834 EXPECT_TRUE(SetupEngine()); 2837 EXPECT_TRUE(SetupEngineWithSendStream());
2835 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel( 2838 rtc::scoped_ptr<cricket::VoiceMediaChannel> channel(
2836 engine_.CreateChannel(&call_, cricket::AudioOptions())); 2839 engine_.CreateChannel(&call_, cricket::AudioOptions()));
2837 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface( 2840 rtc::scoped_ptr<cricket::FakeNetworkInterface> network_interface(
2838 new cricket::FakeNetworkInterface); 2841 new cricket::FakeNetworkInterface);
2839 channel->SetInterface(network_interface.get()); 2842 channel->SetInterface(network_interface.get());
2840 cricket::AudioSendParameters parameters = send_parameters_; 2843 cricket::AudioSendParameters parameters = send_parameters_;
2841 parameters.options.dscp.Set(true); 2844 parameters.options.dscp.Set(true);
2842 EXPECT_TRUE(channel->SetSendParameters(parameters)); 2845 EXPECT_TRUE(channel->SetSendParameters(parameters));
2843 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); 2846 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
2844 // Verify previous value is not modified if dscp option is not set. 2847 // Verify previous value is not modified if dscp option is not set.
2845 EXPECT_TRUE(channel->SetSendParameters(send_parameters_)); 2848 EXPECT_TRUE(channel->SetSendParameters(send_parameters_));
2846 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp()); 2849 EXPECT_EQ(rtc::DSCP_EF, network_interface->dscp());
2847 parameters.options.dscp.Set(false); 2850 parameters.options.dscp.Set(false);
2848 EXPECT_TRUE(channel->SetSendParameters(parameters)); 2851 EXPECT_TRUE(channel->SetSendParameters(parameters));
2849 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); 2852 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp());
2850 } 2853 }
2851 2854
2852 // Test that GetReceiveChannelId returns the default channel for the first 2855 TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelId) {
2853 // recv stream in 1-1 calls.
2854 TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelIdIn1To1Calls) {
2855 EXPECT_TRUE(SetupEngine()); 2856 EXPECT_TRUE(SetupEngine());
2856 cricket::WebRtcVoiceMediaChannel* media_channel = 2857 cricket::WebRtcVoiceMediaChannel* media_channel =
2857 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 2858 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2858 // Test that GetChannelNum returns the default channel if the SSRC is unknown. 2859 EXPECT_EQ(-1, media_channel->GetReceiveChannelId(0));
2859 EXPECT_EQ(media_channel->default_send_channel_id(), 2860 EXPECT_TRUE(channel_->AddRecvStream(
2860 media_channel->GetReceiveChannelId(0)); 2861 cricket::StreamParams::CreateLegacy(kSsrc1)));
2861 cricket::StreamParams stream; 2862 int channel_id = voe_.GetLastChannel();
2862 stream.ssrcs.push_back(kSsrc2); 2863 EXPECT_EQ(channel_id, media_channel->GetReceiveChannelId(kSsrc1));
2863 EXPECT_TRUE(channel_->AddRecvStream(stream)); 2864 EXPECT_EQ(-1, media_channel->GetReceiveChannelId(kSsrc2));
2864 EXPECT_EQ(media_channel->default_send_channel_id(), 2865 EXPECT_TRUE(channel_->AddRecvStream(
2865 media_channel->GetReceiveChannelId(kSsrc2)); 2866 cricket::StreamParams::CreateLegacy(kSsrc2)));
2867 int channel_id2 = voe_.GetLastChannel();
2868 EXPECT_EQ(channel_id2, media_channel->GetReceiveChannelId(kSsrc2));
2866 } 2869 }
2867 2870
2868 // Test that GetReceiveChannelId doesn't return the default channel for the 2871 TEST_F(WebRtcVoiceEngineTestFake, TestGetSendChannelId) {
2869 // first recv stream in conference calls.
2870 TEST_F(WebRtcVoiceEngineTestFake, TestGetChannelNumInConferenceCalls) {
2871 EXPECT_TRUE(SetupEngine()); 2872 EXPECT_TRUE(SetupEngine());
2872 send_parameters_.options = options_conference_;
2873 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2874 cricket::StreamParams stream;
2875 stream.ssrcs.push_back(kSsrc2);
2876 EXPECT_TRUE(channel_->AddRecvStream(stream));
2877 cricket::WebRtcVoiceMediaChannel* media_channel = 2873 cricket::WebRtcVoiceMediaChannel* media_channel =
2878 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 2874 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2879 EXPECT_LT(media_channel->default_send_channel_id(), 2875 EXPECT_EQ(-1, media_channel->GetSendChannelId(0));
2880 media_channel->GetReceiveChannelId(kSsrc2)); 2876 EXPECT_TRUE(channel_->AddSendStream(
2877 cricket::StreamParams::CreateLegacy(kSsrc1)));
2878 int channel_id = voe_.GetLastChannel();
2879 EXPECT_EQ(channel_id, media_channel->GetSendChannelId(kSsrc1));
2880 EXPECT_EQ(-1, media_channel->GetSendChannelId(kSsrc2));
2881 EXPECT_TRUE(channel_->AddSendStream(
2882 cricket::StreamParams::CreateLegacy(kSsrc2)));
2883 int channel_id2 = voe_.GetLastChannel();
2884 EXPECT_EQ(channel_id2, media_channel->GetSendChannelId(kSsrc2));
2881 } 2885 }
2882 2886
2883 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolume) { 2887 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolume) {
2884 EXPECT_TRUE(SetupEngine()); 2888 EXPECT_TRUE(SetupEngine());
2885 float scale;
2886 EXPECT_TRUE(channel_->SetOutputVolume(0, 2));
2887 int channel_id = voe_.GetLastChannel();
2888 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale));
2889 EXPECT_DOUBLE_EQ(2, scale);
2890
2891 EXPECT_FALSE(channel_->SetOutputVolume(kSsrc2, 0.5)); 2889 EXPECT_FALSE(channel_->SetOutputVolume(kSsrc2, 0.5));
2892 cricket::StreamParams stream; 2890 cricket::StreamParams stream;
2893 stream.ssrcs.push_back(kSsrc2); 2891 stream.ssrcs.push_back(kSsrc2);
2894 EXPECT_TRUE(channel_->AddRecvStream(stream)); 2892 EXPECT_TRUE(channel_->AddRecvStream(stream));
2895 2893 int channel_id = voe_.GetLastChannel();
2896 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc2, 3)); 2894 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc2, 3));
2897 channel_id = voe_.GetLastChannel(); 2895 float scale = 0;
2898 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale)); 2896 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale));
2899 EXPECT_DOUBLE_EQ(3, scale); 2897 EXPECT_DOUBLE_EQ(3, scale);
2900 } 2898 }
2899
2900 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolumeDefaultRecvStream) {
2901 EXPECT_TRUE(SetupEngine());
2902 EXPECT_TRUE(channel_->SetOutputVolume(0, 2));
2903 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2904 int channel_id = voe_.GetLastChannel();
2905 float scale = 0;
2906 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale));
2907 EXPECT_DOUBLE_EQ(2, scale);
2908 EXPECT_TRUE(channel_->SetOutputVolume(0, 3));
2909 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale));
2910 EXPECT_DOUBLE_EQ(3, scale);
2911 }
2901 2912
2902 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) { 2913 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) {
2903 const uint32_t kAudioSsrc = 123; 2914 const uint32_t kAudioSsrc = 123;
2904 const std::string kSyncLabel = "AvSyncLabel"; 2915 const std::string kSyncLabel = "AvSyncLabel";
2905 2916
2906 EXPECT_TRUE(SetupEngine()); 2917 EXPECT_TRUE(SetupEngineWithSendStream());
2907 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc); 2918 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc);
2908 sp.sync_label = kSyncLabel; 2919 sp.sync_label = kSyncLabel;
2909 // Creating two channels to make sure that sync label is set properly for both 2920 // Creating two channels to make sure that sync label is set properly for both
2910 // the default voice channel and following ones. 2921 // the default voice channel and following ones.
2911 EXPECT_TRUE(channel_->AddRecvStream(sp)); 2922 EXPECT_TRUE(channel_->AddRecvStream(sp));
2912 sp.ssrcs[0] += 1; 2923 sp.ssrcs[0] += 1;
2913 EXPECT_TRUE(channel_->AddRecvStream(sp)); 2924 EXPECT_TRUE(channel_->AddRecvStream(sp));
2914 2925
2915 ASSERT_EQ(2, call_.GetAudioReceiveStreams().size()); 2926 ASSERT_EQ(2, call_.GetAudioReceiveStreams().size());
2916 EXPECT_EQ(kSyncLabel, 2927 EXPECT_EQ(kSyncLabel,
2917 call_.GetAudioReceiveStream(kAudioSsrc)->GetConfig().sync_group) 2928 call_.GetAudioReceiveStream(kAudioSsrc)->GetConfig().sync_group)
2918 << "SyncGroup should be set based on sync_label"; 2929 << "SyncGroup should be set based on sync_label";
2919 EXPECT_EQ(kSyncLabel, 2930 EXPECT_EQ(kSyncLabel,
2920 call_.GetAudioReceiveStream(kAudioSsrc + 1)->GetConfig().sync_group) 2931 call_.GetAudioReceiveStream(kAudioSsrc + 1)->GetConfig().sync_group)
2921 << "SyncGroup should be set based on sync_label"; 2932 << "SyncGroup should be set based on sync_label";
2922 } 2933 }
2923 2934
2924 TEST_F(WebRtcVoiceEngineTestFake, CanChangeCombinedBweOption) { 2935 TEST_F(WebRtcVoiceEngineTestFake, CanChangeCombinedBweOption) {
2925 // Test that changing the combined_audio_video_bwe option results in the 2936 // Test that changing the combined_audio_video_bwe option results in the
2926 // expected state changes on an associated Call. 2937 // expected state changes on an associated Call.
2927 std::vector<uint32_t> ssrcs; 2938 std::vector<uint32_t> ssrcs;
2928 ssrcs.push_back(223); 2939 ssrcs.push_back(223);
2929 ssrcs.push_back(224); 2940 ssrcs.push_back(224);
2930 2941
2931 EXPECT_TRUE(SetupEngine()); 2942 EXPECT_TRUE(SetupEngineWithSendStream());
2932 cricket::WebRtcVoiceMediaChannel* media_channel = 2943 cricket::WebRtcVoiceMediaChannel* media_channel =
2933 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 2944 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2934 for (uint32_t ssrc : ssrcs) { 2945 for (uint32_t ssrc : ssrcs) {
2935 EXPECT_TRUE(media_channel->AddRecvStream( 2946 EXPECT_TRUE(media_channel->AddRecvStream(
2936 cricket::StreamParams::CreateLegacy(ssrc))); 2947 cricket::StreamParams::CreateLegacy(ssrc)));
2937 } 2948 }
2938 EXPECT_EQ(2, call_.GetAudioReceiveStreams().size()); 2949 EXPECT_EQ(2, call_.GetAudioReceiveStreams().size());
2939 2950
2940 // Combined BWE should be disabled. 2951 // Combined BWE should be disabled.
2941 for (uint32_t ssrc : ssrcs) { 2952 for (uint32_t ssrc : ssrcs) {
(...skipping 19 matching lines...) Expand all
2961 EXPECT_NE(nullptr, s); 2972 EXPECT_NE(nullptr, s);
2962 EXPECT_EQ(false, s->GetConfig().combined_audio_video_bwe); 2973 EXPECT_EQ(false, s->GetConfig().combined_audio_video_bwe);
2963 } 2974 }
2964 2975
2965 EXPECT_EQ(2, call_.GetAudioReceiveStreams().size()); 2976 EXPECT_EQ(2, call_.GetAudioReceiveStreams().size());
2966 } 2977 }
2967 2978
2968 TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) { 2979 TEST_F(WebRtcVoiceEngineTestFake, ConfigureCombinedBweForNewRecvStreams) {
2969 // Test that adding receive streams after enabling combined bandwidth 2980 // Test that adding receive streams after enabling combined bandwidth
2970 // estimation will correctly configure each channel. 2981 // estimation will correctly configure each channel.
2971 EXPECT_TRUE(SetupEngine()); 2982 EXPECT_TRUE(SetupEngineWithSendStream());
2972 cricket::WebRtcVoiceMediaChannel* media_channel = 2983 cricket::WebRtcVoiceMediaChannel* media_channel =
2973 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 2984 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2974 send_parameters_.options.combined_audio_video_bwe.Set(true); 2985 send_parameters_.options.combined_audio_video_bwe.Set(true);
2975 EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); 2986 EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_));
2976 2987
2977 static const uint32_t kSsrcs[] = {1, 2, 3, 4}; 2988 static const uint32_t kSsrcs[] = {1, 2, 3, 4};
2978 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) { 2989 for (unsigned int i = 0; i < ARRAY_SIZE(kSsrcs); ++i) {
2979 EXPECT_TRUE(media_channel->AddRecvStream( 2990 EXPECT_TRUE(media_channel->AddRecvStream(
2980 cricket::StreamParams::CreateLegacy(kSsrcs[i]))); 2991 cricket::StreamParams::CreateLegacy(kSsrcs[i])));
2981 EXPECT_NE(nullptr, call_.GetAudioReceiveStream(kSsrcs[i])); 2992 EXPECT_NE(nullptr, call_.GetAudioReceiveStream(kSsrcs[i]));
2982 } 2993 }
2983 EXPECT_EQ(ARRAY_SIZE(kSsrcs), call_.GetAudioReceiveStreams().size()); 2994 EXPECT_EQ(ARRAY_SIZE(kSsrcs), call_.GetAudioReceiveStreams().size());
2984 } 2995 }
2985 2996
2986 TEST_F(WebRtcVoiceEngineTestFake, ConfiguresAudioReceiveStreamRtpExtensions) { 2997 TEST_F(WebRtcVoiceEngineTestFake, ConfiguresAudioReceiveStreamRtpExtensions) {
2987 // Test that setting the header extensions results in the expected state 2998 // Test that setting the header extensions results in the expected state
2988 // changes on an associated Call. 2999 // changes on an associated Call.
2989 std::vector<uint32_t> ssrcs; 3000 std::vector<uint32_t> ssrcs;
2990 ssrcs.push_back(223); 3001 ssrcs.push_back(223);
2991 ssrcs.push_back(224); 3002 ssrcs.push_back(224);
2992 3003
2993 EXPECT_TRUE(SetupEngine()); 3004 EXPECT_TRUE(SetupEngineWithSendStream());
2994 cricket::WebRtcVoiceMediaChannel* media_channel = 3005 cricket::WebRtcVoiceMediaChannel* media_channel =
2995 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 3006 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2996 send_parameters_.options.combined_audio_video_bwe.Set(true); 3007 send_parameters_.options.combined_audio_video_bwe.Set(true);
2997 EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); 3008 EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_));
2998 for (uint32_t ssrc : ssrcs) { 3009 for (uint32_t ssrc : ssrcs) {
2999 EXPECT_TRUE(media_channel->AddRecvStream( 3010 EXPECT_TRUE(media_channel->AddRecvStream(
3000 cricket::StreamParams::CreateLegacy(ssrc))); 3011 cricket::StreamParams::CreateLegacy(ssrc)));
3001 } 3012 }
3002 3013
3003 // Combined BWE should be set up, but with no configured extensions. 3014 // Combined BWE should be set up, but with no configured extensions.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
3042 const uint32_t kAudioSsrc = 1; 3053 const uint32_t kAudioSsrc = 1;
3043 rtc::Buffer kPcmuPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3054 rtc::Buffer kPcmuPacket(kPcmuFrame, sizeof(kPcmuFrame));
3044 static const unsigned char kRtcp[] = { 3055 static const unsigned char kRtcp[] = {
3045 0x80, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 3056 0x80, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
3046 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 3057 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3047 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3058 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3048 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 3059 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3049 }; 3060 };
3050 rtc::Buffer kRtcpPacket(kRtcp, sizeof(kRtcp)); 3061 rtc::Buffer kRtcpPacket(kRtcp, sizeof(kRtcp));
3051 3062
3052 EXPECT_TRUE(SetupEngine()); 3063 EXPECT_TRUE(SetupEngineWithSendStream());
3053 cricket::WebRtcVoiceMediaChannel* media_channel = 3064 cricket::WebRtcVoiceMediaChannel* media_channel =
3054 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 3065 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3055 send_parameters_.options.combined_audio_video_bwe.Set(true); 3066 send_parameters_.options.combined_audio_video_bwe.Set(true);
3056 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 3067 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
3057 EXPECT_TRUE(media_channel->AddRecvStream( 3068 EXPECT_TRUE(media_channel->AddRecvStream(
3058 cricket::StreamParams::CreateLegacy(kAudioSsrc))); 3069 cricket::StreamParams::CreateLegacy(kAudioSsrc)));
3059 3070
3060 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size()); 3071 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size());
3061 const cricket::FakeAudioReceiveStream* s = 3072 const cricket::FakeAudioReceiveStream* s =
3062 call_.GetAudioReceiveStream(kAudioSsrc); 3073 call_.GetAudioReceiveStream(kAudioSsrc);
3063 EXPECT_EQ(0, s->received_packets()); 3074 EXPECT_EQ(0, s->received_packets());
3064 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime()); 3075 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime());
3065 EXPECT_EQ(1, s->received_packets()); 3076 EXPECT_EQ(1, s->received_packets());
3066 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime()); 3077 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime());
3067 EXPECT_EQ(2, s->received_packets()); 3078 EXPECT_EQ(2, s->received_packets());
3068 } 3079 }
3069 3080
3070 // Associate channel should not set on 1:1 call, since the receive channel also 3081 // All receive channels should be associated with the default send channel,
3071 // sends RTCP SR. 3082 // since they do not send RTCP SR.
3072 TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelUnset1On1) {
3073 EXPECT_TRUE(SetupEngine());
3074 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3075 int recv_ch = voe_.GetLastChannel();
3076 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1);
3077 }
3078
3079 // This test is an extension of AssociateChannelUnset1On1. We create two receive
3080 // channels. The second should be associated with the default channel, since it
3081 // does not send RTCP SR.
3082 TEST_F(WebRtcVoiceEngineTestFake, AssociateDefaultChannelOnSecondRecvChannel) {
3083 EXPECT_TRUE(SetupEngine());
3084 int default_channel = voe_.GetLastChannel();
3085 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3086 int recv_ch_1 = voe_.GetLastChannel();
3087 EXPECT_EQ(recv_ch_1, default_channel);
3088 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
3089 int recv_ch_2 = voe_.GetLastChannel();
3090 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_1), -1);
3091 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_2), default_channel);
3092 // Add send stream, the association remains.
3093 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3)));
3094 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_1), -1);
3095 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch_2), default_channel);
3096 }
3097
3098 // In conference mode, all receive channels should be associated with the
3099 // default channel, since they do not send RTCP SR.
3100 TEST_F(WebRtcVoiceEngineTestFake, AssociateDefaultChannelOnConference) { 3083 TEST_F(WebRtcVoiceEngineTestFake, AssociateDefaultChannelOnConference) {
3101 EXPECT_TRUE(SetupEngine()); 3084 EXPECT_TRUE(SetupEngineWithSendStream());
3102 send_parameters_.options = options_conference_;
3103 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 3085 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
3104 int default_channel = voe_.GetLastChannel(); 3086 int default_channel = voe_.GetLastChannel();
3105 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 3087 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3106 int recv_ch = voe_.GetLastChannel(); 3088 int recv_ch = voe_.GetLastChannel();
3107 EXPECT_NE(recv_ch, default_channel); 3089 EXPECT_NE(recv_ch, default_channel);
3108 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel); 3090 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3109 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2))); 3091 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
3110 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel); 3092 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3093 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
3094 recv_ch = voe_.GetLastChannel();
3095 EXPECT_NE(recv_ch, default_channel);
3096 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3111 } 3097 }
3112 3098
3113 TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelResetUponDeleteChannnel) { 3099 TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelResetUponDeleteChannnel) {
3114 EXPECT_TRUE(SetupEngine()); 3100 EXPECT_TRUE(SetupEngineWithSendStream());
3115 send_parameters_.options = options_conference_;
3116 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 3101 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
3117 3102
3118 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 3103 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3119 int recv_ch = voe_.GetLastChannel(); 3104 int recv_ch = voe_.GetLastChannel();
3120 3105
3121 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2))); 3106 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
3122 int send_ch = voe_.GetLastChannel(); 3107 int send_ch = voe_.GetLastChannel();
3123 3108
3124 // Manually associate |recv_ch| to |send_ch|. This test is to verify a 3109 // Manually associate |recv_ch| to |send_ch|. This test is to verify a
3125 // deleting logic, i.e., deleting |send_ch| will reset the associate send 3110 // deleting logic, i.e., deleting |send_ch| will reset the associate send
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3258 break; 3243 break;
3259 channels[num_channels++] = channel; 3244 channels[num_channels++] = channel;
3260 } 3245 }
3261 3246
3262 int expected = ARRAY_SIZE(channels); 3247 int expected = ARRAY_SIZE(channels);
3263 EXPECT_EQ(expected, num_channels); 3248 EXPECT_EQ(expected, num_channels);
3264 3249
3265 while (num_channels > 0) { 3250 while (num_channels > 0) {
3266 delete channels[--num_channels]; 3251 delete channels[--num_channels];
3267 } 3252 }
3268
3269 engine.Terminate(); 3253 engine.Terminate();
3270 } 3254 }
3271 3255
3272 // Test that we set our preferred codecs properly. 3256 // Test that we set our preferred codecs properly.
3273 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3257 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3274 cricket::WebRtcVoiceEngine engine; 3258 cricket::WebRtcVoiceEngine engine;
3275 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3259 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3276 rtc::scoped_ptr<webrtc::Call> call( 3260 rtc::scoped_ptr<webrtc::Call> call(
3277 webrtc::Call::Create(webrtc::Call::Config())); 3261 webrtc::Call::Create(webrtc::Call::Config()));
3278 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), 3262 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(),
3279 call.get()); 3263 call.get());
3280 cricket::AudioRecvParameters parameters; 3264 cricket::AudioRecvParameters parameters;
3281 parameters.codecs = engine.codecs(); 3265 parameters.codecs = engine.codecs();
3282 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3266 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3283 } 3267 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698