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

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

Issue 1830213002: Remove WVoE::SetAudioDeviceModule() - it is now set in ctor. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | webrtc/pc/channelmanager.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 engine, // base 52 engine, // base
53 engine, // codec 53 engine, // codec
54 engine, // hw 54 engine, // hw
55 engine, // network 55 engine, // network
56 engine, // rtp 56 engine, // rtp
57 engine) { // volume 57 engine) { // volume
58 } 58 }
59 }; 59 };
60 } // namespace 60 } // namespace
61 61
62 // Tests that our stub library "works".
63 TEST(WebRtcVoiceEngineTestStubLibrary, StartupShutdown) {
64 cricket::FakeWebRtcVoiceEngine voe;
65 EXPECT_FALSE(voe.IsInited());
66 {
67 cricket::WebRtcVoiceEngine engine(nullptr, new FakeVoEWrapper(&voe));
68 EXPECT_TRUE(voe.IsInited());
69 }
70 EXPECT_FALSE(voe.IsInited());
71 }
72
62 class FakeAudioSink : public webrtc::AudioSinkInterface { 73 class FakeAudioSink : public webrtc::AudioSinkInterface {
63 public: 74 public:
64 void OnData(const Data& audio) override {} 75 void OnData(const Data& audio) override {}
65 }; 76 };
66 77
67 class FakeAudioSource : public cricket::AudioSource { 78 class FakeAudioSource : public cricket::AudioSource {
68 void SetSink(Sink* sink) override {} 79 void SetSink(Sink* sink) override {}
69 }; 80 };
70 81
71 class WebRtcVoiceEngineTestFake : public testing::Test { 82 class WebRtcVoiceEngineTestFake : public testing::Test {
72 public: 83 public:
73 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {} 84 WebRtcVoiceEngineTestFake() : WebRtcVoiceEngineTestFake("") {}
74 85
75 explicit WebRtcVoiceEngineTestFake(const char* field_trials) 86 explicit WebRtcVoiceEngineTestFake(const char* field_trials)
76 : call_(webrtc::Call::Config()), 87 : call_(webrtc::Call::Config()),
77 engine_(new FakeVoEWrapper(&voe_)), 88 engine_(nullptr, new FakeVoEWrapper(&voe_)),
78 channel_(nullptr),
79 override_field_trials_(field_trials) { 89 override_field_trials_(field_trials) {
80 send_parameters_.codecs.push_back(kPcmuCodec); 90 send_parameters_.codecs.push_back(kPcmuCodec);
81 recv_parameters_.codecs.push_back(kPcmuCodec); 91 recv_parameters_.codecs.push_back(kPcmuCodec);
82 } 92 }
83 bool SetupEngine() { 93 bool SetupChannel() {
84 if (!engine_.Init(rtc::Thread::Current())) {
85 return false;
86 }
87 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(), 94 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(),
88 cricket::AudioOptions()); 95 cricket::AudioOptions());
89 return (channel_ != nullptr); 96 return (channel_ != nullptr);
90 } 97 }
91 bool SetupEngineWithRecvStream() { 98 bool SetupRecvStream() {
92 if (!SetupEngine()) { 99 if (!SetupChannel()) {
93 return false; 100 return false;
94 } 101 }
95 return channel_->AddRecvStream( 102 return channel_->AddRecvStream(
96 cricket::StreamParams::CreateLegacy(kSsrc1)); 103 cricket::StreamParams::CreateLegacy(kSsrc1));
97 } 104 }
98 bool SetupEngineWithSendStream() { 105 bool SetupSendStream() {
99 if (!SetupEngine()) { 106 if (!SetupChannel()) {
100 return false; 107 return false;
101 } 108 }
102 if (!channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc1))) { 109 if (!channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc1))) {
103 return false; 110 return false;
104 } 111 }
105 return channel_->SetAudioSend(kSsrc1, true, nullptr, &fake_source_); 112 return channel_->SetAudioSend(kSsrc1, true, nullptr, &fake_source_);
106 } 113 }
107 void SetupForMultiSendStream() { 114 void SetupForMultiSendStream() {
108 EXPECT_TRUE(SetupEngineWithSendStream()); 115 EXPECT_TRUE(SetupSendStream());
109 // Remove stream added in Setup. 116 // Remove stream added in Setup.
110 EXPECT_TRUE(call_.GetAudioSendStream(kSsrc1)); 117 EXPECT_TRUE(call_.GetAudioSendStream(kSsrc1));
111 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc1)); 118 EXPECT_TRUE(channel_->RemoveSendStream(kSsrc1));
112 // Verify the channel does not exist. 119 // Verify the channel does not exist.
113 EXPECT_FALSE(call_.GetAudioSendStream(kSsrc1)); 120 EXPECT_FALSE(call_.GetAudioSendStream(kSsrc1));
114 } 121 }
115 void DeliverPacket(const void* data, int len) { 122 void DeliverPacket(const void* data, int len) {
116 rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len); 123 rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len);
117 channel_->OnPacketReceived(&packet, rtc::PacketTime()); 124 channel_->OnPacketReceived(&packet, rtc::PacketTime());
118 } 125 }
119 void TearDown() override { 126 void TearDown() override {
120 delete channel_; 127 delete channel_;
121 engine_.Terminate();
122 } 128 }
123 129
124 const cricket::FakeAudioSendStream& GetSendStream(uint32_t ssrc) { 130 const cricket::FakeAudioSendStream& GetSendStream(uint32_t ssrc) {
125 const auto* send_stream = call_.GetAudioSendStream(ssrc); 131 const auto* send_stream = call_.GetAudioSendStream(ssrc);
126 EXPECT_TRUE(send_stream); 132 EXPECT_TRUE(send_stream);
127 return *send_stream; 133 return *send_stream;
128 } 134 }
129 135
130 const cricket::FakeAudioReceiveStream& GetRecvStream(uint32_t ssrc) { 136 const cricket::FakeAudioReceiveStream& GetRecvStream(uint32_t ssrc) {
131 const auto* recv_stream = call_.GetAudioReceiveStream(ssrc); 137 const auto* recv_stream = call_.GetAudioReceiveStream(ssrc);
132 EXPECT_TRUE(recv_stream); 138 EXPECT_TRUE(recv_stream);
133 return *recv_stream; 139 return *recv_stream;
134 } 140 }
135 141
136 const webrtc::AudioSendStream::Config& GetSendStreamConfig(uint32_t ssrc) { 142 const webrtc::AudioSendStream::Config& GetSendStreamConfig(uint32_t ssrc) {
137 return GetSendStream(ssrc).GetConfig(); 143 return GetSendStream(ssrc).GetConfig();
138 } 144 }
139 145
140 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) { 146 const webrtc::AudioReceiveStream::Config& GetRecvStreamConfig(uint32_t ssrc) {
141 return GetRecvStream(ssrc).GetConfig(); 147 return GetRecvStream(ssrc).GetConfig();
142 } 148 }
143 149
144 void TestInsertDtmf(uint32_t ssrc, bool caller) { 150 void TestInsertDtmf(uint32_t ssrc, bool caller) {
145 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 151 EXPECT_TRUE(SetupChannel());
146 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(),
147 cricket::AudioOptions());
148 EXPECT_TRUE(channel_ != nullptr);
149 if (caller) { 152 if (caller) {
150 // If this is a caller, local description will be applied and add the 153 // If this is a caller, local description will be applied and add the
151 // send stream. 154 // send stream.
152 EXPECT_TRUE(channel_->AddSendStream( 155 EXPECT_TRUE(channel_->AddSendStream(
153 cricket::StreamParams::CreateLegacy(kSsrc1))); 156 cricket::StreamParams::CreateLegacy(kSsrc1)));
154 } 157 }
155 158
156 // Test we can only InsertDtmf when the other side supports telephone-event. 159 // Test we can only InsertDtmf when the other side supports telephone-event.
157 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 160 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
158 channel_->SetSend(true); 161 channel_->SetSend(true);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 parameters.max_bandwidth_bps = max_bitrate; 200 parameters.max_bandwidth_bps = max_bitrate;
198 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters)); 201 EXPECT_EQ(expected_result, channel_->SetSendParameters(parameters));
199 202
200 int channel_num = voe_.GetLastChannel(); 203 int channel_num = voe_.GetLastChannel();
201 webrtc::CodecInst temp_codec; 204 webrtc::CodecInst temp_codec;
202 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec)); 205 EXPECT_FALSE(voe_.GetSendCodec(channel_num, temp_codec));
203 EXPECT_EQ(expected_bitrate, temp_codec.rate); 206 EXPECT_EQ(expected_bitrate, temp_codec.rate);
204 } 207 }
205 208
206 void TestSetSendRtpHeaderExtensions(const std::string& ext) { 209 void TestSetSendRtpHeaderExtensions(const std::string& ext) {
207 EXPECT_TRUE(SetupEngineWithSendStream()); 210 EXPECT_TRUE(SetupSendStream());
208 211
209 // Ensure extensions are off by default. 212 // Ensure extensions are off by default.
210 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); 213 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size());
211 214
212 // Ensure unknown extensions won't cause an error. 215 // Ensure unknown extensions won't cause an error.
213 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension( 216 send_parameters_.extensions.push_back(cricket::RtpHeaderExtension(
214 "urn:ietf:params:unknownextention", 1)); 217 "urn:ietf:params:unknownextention", 1));
215 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 218 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
216 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); 219 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size());
217 220
(...skipping 21 matching lines...) Expand all
239 242
240 // Ensure all extensions go back off with an empty list. 243 // Ensure all extensions go back off with an empty list.
241 send_parameters_.codecs.push_back(kPcmuCodec); 244 send_parameters_.codecs.push_back(kPcmuCodec);
242 send_parameters_.extensions.clear(); 245 send_parameters_.extensions.clear();
243 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 246 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
244 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size()); 247 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc1).rtp.extensions.size());
245 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc2).rtp.extensions.size()); 248 EXPECT_EQ(0u, GetSendStreamConfig(kSsrc2).rtp.extensions.size());
246 } 249 }
247 250
248 void TestSetRecvRtpHeaderExtensions(const std::string& ext) { 251 void TestSetRecvRtpHeaderExtensions(const std::string& ext) {
249 EXPECT_TRUE(SetupEngineWithRecvStream()); 252 EXPECT_TRUE(SetupRecvStream());
250 253
251 // Ensure extensions are off by default. 254 // Ensure extensions are off by default.
252 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc1).rtp.extensions.size()); 255 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc1).rtp.extensions.size());
253 256
254 // Ensure unknown extensions won't cause an error. 257 // Ensure unknown extensions won't cause an error.
255 recv_parameters_.extensions.push_back(cricket::RtpHeaderExtension( 258 recv_parameters_.extensions.push_back(cricket::RtpHeaderExtension(
256 "urn:ietf:params:unknownextention", 1)); 259 "urn:ietf:params:unknownextention", 1));
257 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); 260 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_));
258 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc1).rtp.extensions.size()); 261 EXPECT_EQ(0u, GetRecvStreamConfig(kSsrc1).rtp.extensions.size());
259 262
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 EXPECT_EQ(info.decoding_plc, stats.decoding_plc); 397 EXPECT_EQ(info.decoding_plc, stats.decoding_plc);
395 EXPECT_EQ(info.decoding_cng, stats.decoding_cng); 398 EXPECT_EQ(info.decoding_cng, stats.decoding_cng);
396 EXPECT_EQ(info.decoding_plc_cng, stats.decoding_plc_cng); 399 EXPECT_EQ(info.decoding_plc_cng, stats.decoding_plc_cng);
397 EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms); 400 EXPECT_EQ(info.capture_start_ntp_time_ms, stats.capture_start_ntp_time_ms);
398 } 401 }
399 402
400 protected: 403 protected:
401 cricket::FakeCall call_; 404 cricket::FakeCall call_;
402 cricket::FakeWebRtcVoiceEngine voe_; 405 cricket::FakeWebRtcVoiceEngine voe_;
403 cricket::WebRtcVoiceEngine engine_; 406 cricket::WebRtcVoiceEngine engine_;
404 cricket::VoiceMediaChannel* channel_; 407 cricket::VoiceMediaChannel* channel_ = nullptr;
405 cricket::AudioSendParameters send_parameters_; 408 cricket::AudioSendParameters send_parameters_;
406 cricket::AudioRecvParameters recv_parameters_; 409 cricket::AudioRecvParameters recv_parameters_;
407 FakeAudioSource fake_source_; 410 FakeAudioSource fake_source_;
408 411
409 private: 412 private:
410 webrtc::test::ScopedFieldTrials override_field_trials_; 413 webrtc::test::ScopedFieldTrials override_field_trials_;
411 }; 414 };
412 415
413 // Tests that our stub library "works".
414 TEST_F(WebRtcVoiceEngineTestFake, StartupShutdown) {
415 EXPECT_FALSE(voe_.IsInited());
416 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
417 EXPECT_TRUE(voe_.IsInited());
418 engine_.Terminate();
419 EXPECT_FALSE(voe_.IsInited());
420 }
421
422 // Tests that we can create and destroy a channel. 416 // Tests that we can create and destroy a channel.
423 TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) { 417 TEST_F(WebRtcVoiceEngineTestFake, CreateChannel) {
424 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 418 EXPECT_TRUE(SetupChannel());
425 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(),
426 cricket::AudioOptions());
427 EXPECT_TRUE(channel_ != nullptr);
428 } 419 }
429 420
430 // Tests that the list of supported codecs is created properly and ordered 421 // Tests that the list of supported codecs is created properly and ordered
431 // correctly 422 // correctly
432 TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) { 423 TEST_F(WebRtcVoiceEngineTestFake, CodecPreference) {
433 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs(); 424 const std::vector<cricket::AudioCodec>& codecs = engine_.codecs();
434 ASSERT_FALSE(codecs.empty()); 425 ASSERT_FALSE(codecs.empty());
435 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str()); 426 EXPECT_STRCASEEQ("opus", codecs[0].name.c_str());
436 EXPECT_EQ(48000, codecs[0].clockrate); 427 EXPECT_EQ(48000, codecs[0].clockrate);
437 EXPECT_EQ(2, codecs[0].channels); 428 EXPECT_EQ(2, codecs[0].channels);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 // Find ISAC with an explicit bitrate. 478 // Find ISAC with an explicit bitrate.
488 codec = kIsacCodec; 479 codec = kIsacCodec;
489 codec.bitrate = 32000; 480 codec.bitrate = 32000;
490 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(codec, &codec_inst)); 481 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(codec, &codec_inst));
491 EXPECT_EQ(codec.id, codec_inst.pltype); 482 EXPECT_EQ(codec.id, codec_inst.pltype);
492 EXPECT_EQ(32000, codec_inst.rate); 483 EXPECT_EQ(32000, codec_inst.rate);
493 } 484 }
494 485
495 // Test that we set our inbound codecs properly, including changing PT. 486 // Test that we set our inbound codecs properly, including changing PT.
496 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) { 487 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecs) {
497 EXPECT_TRUE(SetupEngine()); 488 EXPECT_TRUE(SetupChannel());
498 cricket::AudioRecvParameters parameters; 489 cricket::AudioRecvParameters parameters;
499 parameters.codecs.push_back(kIsacCodec); 490 parameters.codecs.push_back(kIsacCodec);
500 parameters.codecs.push_back(kPcmuCodec); 491 parameters.codecs.push_back(kPcmuCodec);
501 parameters.codecs.push_back(kTelephoneEventCodec); 492 parameters.codecs.push_back(kTelephoneEventCodec);
502 parameters.codecs[0].id = 106; // collide with existing telephone-event 493 parameters.codecs[0].id = 106; // collide with existing telephone-event
503 parameters.codecs[2].id = 126; 494 parameters.codecs[2].id = 126;
504 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 495 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
505 EXPECT_TRUE(channel_->AddRecvStream( 496 EXPECT_TRUE(channel_->AddRecvStream(
506 cricket::StreamParams::CreateLegacy(kSsrc1))); 497 cricket::StreamParams::CreateLegacy(kSsrc1)));
507 int channel_num = voe_.GetLastChannel(); 498 int channel_num = voe_.GetLastChannel();
508 webrtc::CodecInst gcodec; 499 webrtc::CodecInst gcodec;
509 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); 500 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC");
510 gcodec.plfreq = 16000; 501 gcodec.plfreq = 16000;
511 gcodec.channels = 1; 502 gcodec.channels = 1;
512 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); 503 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
513 EXPECT_EQ(106, gcodec.pltype); 504 EXPECT_EQ(106, gcodec.pltype);
514 EXPECT_STREQ("ISAC", gcodec.plname); 505 EXPECT_STREQ("ISAC", gcodec.plname);
515 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event"); 506 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event");
516 gcodec.plfreq = 8000; 507 gcodec.plfreq = 8000;
517 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec)); 508 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, gcodec));
518 EXPECT_EQ(126, gcodec.pltype); 509 EXPECT_EQ(126, gcodec.pltype);
519 EXPECT_STREQ("telephone-event", gcodec.plname); 510 EXPECT_STREQ("telephone-event", gcodec.plname);
520 } 511 }
521 512
522 // Test that we fail to set an unknown inbound codec. 513 // Test that we fail to set an unknown inbound codec.
523 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) { 514 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsUnsupportedCodec) {
524 EXPECT_TRUE(SetupEngine()); 515 EXPECT_TRUE(SetupChannel());
525 cricket::AudioRecvParameters parameters; 516 cricket::AudioRecvParameters parameters;
526 parameters.codecs.push_back(kIsacCodec); 517 parameters.codecs.push_back(kIsacCodec);
527 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0)); 518 parameters.codecs.push_back(cricket::AudioCodec(127, "XYZ", 32000, 0, 1, 0));
528 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); 519 EXPECT_FALSE(channel_->SetRecvParameters(parameters));
529 } 520 }
530 521
531 // Test that we fail if we have duplicate types in the inbound list. 522 // Test that we fail if we have duplicate types in the inbound list.
532 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) { 523 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsDuplicatePayloadType) {
533 EXPECT_TRUE(SetupEngine()); 524 EXPECT_TRUE(SetupChannel());
534 cricket::AudioRecvParameters parameters; 525 cricket::AudioRecvParameters parameters;
535 parameters.codecs.push_back(kIsacCodec); 526 parameters.codecs.push_back(kIsacCodec);
536 parameters.codecs.push_back(kCn16000Codec); 527 parameters.codecs.push_back(kCn16000Codec);
537 parameters.codecs[1].id = kIsacCodec.id; 528 parameters.codecs[1].id = kIsacCodec.id;
538 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); 529 EXPECT_FALSE(channel_->SetRecvParameters(parameters));
539 } 530 }
540 531
541 // Test that we can decode OPUS without stereo parameters. 532 // Test that we can decode OPUS without stereo parameters.
542 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) { 533 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpusNoStereo) {
543 EXPECT_TRUE(SetupEngine()); 534 EXPECT_TRUE(SetupChannel());
544 cricket::AudioRecvParameters parameters; 535 cricket::AudioRecvParameters parameters;
545 parameters.codecs.push_back(kIsacCodec); 536 parameters.codecs.push_back(kIsacCodec);
546 parameters.codecs.push_back(kPcmuCodec); 537 parameters.codecs.push_back(kPcmuCodec);
547 parameters.codecs.push_back(kOpusCodec); 538 parameters.codecs.push_back(kOpusCodec);
548 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 539 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
549 EXPECT_TRUE(channel_->AddRecvStream( 540 EXPECT_TRUE(channel_->AddRecvStream(
550 cricket::StreamParams::CreateLegacy(kSsrc1))); 541 cricket::StreamParams::CreateLegacy(kSsrc1)));
551 int channel_num = voe_.GetLastChannel(); 542 int channel_num = voe_.GetLastChannel();
552 webrtc::CodecInst opus; 543 webrtc::CodecInst opus;
553 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 544 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus);
554 // Even without stereo parameters, recv codecs still specify channels = 2. 545 // Even without stereo parameters, recv codecs still specify channels = 2.
555 EXPECT_EQ(2, opus.channels); 546 EXPECT_EQ(2, opus.channels);
556 EXPECT_EQ(111, opus.pltype); 547 EXPECT_EQ(111, opus.pltype);
557 EXPECT_STREQ("opus", opus.plname); 548 EXPECT_STREQ("opus", opus.plname);
558 opus.pltype = 0; 549 opus.pltype = 0;
559 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, opus)); 550 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num, opus));
560 EXPECT_EQ(111, opus.pltype); 551 EXPECT_EQ(111, opus.pltype);
561 } 552 }
562 553
563 // Test that we can decode OPUS with stereo = 0. 554 // Test that we can decode OPUS with stereo = 0.
564 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) { 555 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus0Stereo) {
565 EXPECT_TRUE(SetupEngine()); 556 EXPECT_TRUE(SetupChannel());
566 cricket::AudioRecvParameters parameters; 557 cricket::AudioRecvParameters parameters;
567 parameters.codecs.push_back(kIsacCodec); 558 parameters.codecs.push_back(kIsacCodec);
568 parameters.codecs.push_back(kPcmuCodec); 559 parameters.codecs.push_back(kPcmuCodec);
569 parameters.codecs.push_back(kOpusCodec); 560 parameters.codecs.push_back(kOpusCodec);
570 parameters.codecs[2].params["stereo"] = "0"; 561 parameters.codecs[2].params["stereo"] = "0";
571 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 562 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
572 EXPECT_TRUE(channel_->AddRecvStream( 563 EXPECT_TRUE(channel_->AddRecvStream(
573 cricket::StreamParams::CreateLegacy(kSsrc1))); 564 cricket::StreamParams::CreateLegacy(kSsrc1)));
574 int channel_num2 = voe_.GetLastChannel(); 565 int channel_num2 = voe_.GetLastChannel();
575 webrtc::CodecInst opus; 566 webrtc::CodecInst opus;
576 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 567 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus);
577 // Even when stereo is off, recv codecs still specify channels = 2. 568 // Even when stereo is off, recv codecs still specify channels = 2.
578 EXPECT_EQ(2, opus.channels); 569 EXPECT_EQ(2, opus.channels);
579 EXPECT_EQ(111, opus.pltype); 570 EXPECT_EQ(111, opus.pltype);
580 EXPECT_STREQ("opus", opus.plname); 571 EXPECT_STREQ("opus", opus.plname);
581 opus.pltype = 0; 572 opus.pltype = 0;
582 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); 573 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
583 EXPECT_EQ(111, opus.pltype); 574 EXPECT_EQ(111, opus.pltype);
584 } 575 }
585 576
586 // Test that we can decode OPUS with stereo = 1. 577 // Test that we can decode OPUS with stereo = 1.
587 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) { 578 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithOpus1Stereo) {
588 EXPECT_TRUE(SetupEngine()); 579 EXPECT_TRUE(SetupChannel());
589 cricket::AudioRecvParameters parameters; 580 cricket::AudioRecvParameters parameters;
590 parameters.codecs.push_back(kIsacCodec); 581 parameters.codecs.push_back(kIsacCodec);
591 parameters.codecs.push_back(kPcmuCodec); 582 parameters.codecs.push_back(kPcmuCodec);
592 parameters.codecs.push_back(kOpusCodec); 583 parameters.codecs.push_back(kOpusCodec);
593 parameters.codecs[2].params["stereo"] = "1"; 584 parameters.codecs[2].params["stereo"] = "1";
594 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 585 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
595 EXPECT_TRUE(channel_->AddRecvStream( 586 EXPECT_TRUE(channel_->AddRecvStream(
596 cricket::StreamParams::CreateLegacy(kSsrc1))); 587 cricket::StreamParams::CreateLegacy(kSsrc1)));
597 int channel_num2 = voe_.GetLastChannel(); 588 int channel_num2 = voe_.GetLastChannel();
598 webrtc::CodecInst opus; 589 webrtc::CodecInst opus;
599 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus); 590 cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &opus);
600 EXPECT_EQ(2, opus.channels); 591 EXPECT_EQ(2, opus.channels);
601 EXPECT_EQ(111, opus.pltype); 592 EXPECT_EQ(111, opus.pltype);
602 EXPECT_STREQ("opus", opus.plname); 593 EXPECT_STREQ("opus", opus.plname);
603 opus.pltype = 0; 594 opus.pltype = 0;
604 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus)); 595 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, opus));
605 EXPECT_EQ(111, opus.pltype); 596 EXPECT_EQ(111, opus.pltype);
606 } 597 }
607 598
608 // Test that changes to recv codecs are applied to all streams. 599 // Test that changes to recv codecs are applied to all streams.
609 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) { 600 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWithMultipleStreams) {
610 EXPECT_TRUE(SetupEngine()); 601 EXPECT_TRUE(SetupChannel());
611 cricket::AudioRecvParameters parameters; 602 cricket::AudioRecvParameters parameters;
612 parameters.codecs.push_back(kIsacCodec); 603 parameters.codecs.push_back(kIsacCodec);
613 parameters.codecs.push_back(kPcmuCodec); 604 parameters.codecs.push_back(kPcmuCodec);
614 parameters.codecs.push_back(kTelephoneEventCodec); 605 parameters.codecs.push_back(kTelephoneEventCodec);
615 parameters.codecs[0].id = 106; // collide with existing telephone-event 606 parameters.codecs[0].id = 106; // collide with existing telephone-event
616 parameters.codecs[2].id = 126; 607 parameters.codecs[2].id = 126;
617 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 608 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
618 EXPECT_TRUE(channel_->AddRecvStream( 609 EXPECT_TRUE(channel_->AddRecvStream(
619 cricket::StreamParams::CreateLegacy(kSsrc1))); 610 cricket::StreamParams::CreateLegacy(kSsrc1)));
620 int channel_num2 = voe_.GetLastChannel(); 611 int channel_num2 = voe_.GetLastChannel();
621 webrtc::CodecInst gcodec; 612 webrtc::CodecInst gcodec;
622 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); 613 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC");
623 gcodec.plfreq = 16000; 614 gcodec.plfreq = 16000;
624 gcodec.channels = 1; 615 gcodec.channels = 1;
625 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); 616 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
626 EXPECT_EQ(106, gcodec.pltype); 617 EXPECT_EQ(106, gcodec.pltype);
627 EXPECT_STREQ("ISAC", gcodec.plname); 618 EXPECT_STREQ("ISAC", gcodec.plname);
628 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event"); 619 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "telephone-event");
629 gcodec.plfreq = 8000; 620 gcodec.plfreq = 8000;
630 gcodec.channels = 1; 621 gcodec.channels = 1;
631 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); 622 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
632 EXPECT_EQ(126, gcodec.pltype); 623 EXPECT_EQ(126, gcodec.pltype);
633 EXPECT_STREQ("telephone-event", gcodec.plname); 624 EXPECT_STREQ("telephone-event", gcodec.plname);
634 } 625 }
635 626
636 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) { 627 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsAfterAddingStreams) {
637 EXPECT_TRUE(SetupEngineWithRecvStream()); 628 EXPECT_TRUE(SetupRecvStream());
638 cricket::AudioRecvParameters parameters; 629 cricket::AudioRecvParameters parameters;
639 parameters.codecs.push_back(kIsacCodec); 630 parameters.codecs.push_back(kIsacCodec);
640 parameters.codecs[0].id = 106; // collide with existing telephone-event 631 parameters.codecs[0].id = 106; // collide with existing telephone-event
641 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 632 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
642 633
643 int channel_num2 = voe_.GetLastChannel(); 634 int channel_num2 = voe_.GetLastChannel();
644 webrtc::CodecInst gcodec; 635 webrtc::CodecInst gcodec;
645 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC"); 636 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "ISAC");
646 gcodec.plfreq = 16000; 637 gcodec.plfreq = 16000;
647 gcodec.channels = 1; 638 gcodec.channels = 1;
648 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec)); 639 EXPECT_EQ(0, voe_.GetRecPayloadType(channel_num2, gcodec));
649 EXPECT_EQ(106, gcodec.pltype); 640 EXPECT_EQ(106, gcodec.pltype);
650 EXPECT_STREQ("ISAC", gcodec.plname); 641 EXPECT_STREQ("ISAC", gcodec.plname);
651 } 642 }
652 643
653 // Test that we can apply the same set of codecs again while playing. 644 // Test that we can apply the same set of codecs again while playing.
654 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) { 645 TEST_F(WebRtcVoiceEngineTestFake, SetRecvCodecsWhilePlaying) {
655 EXPECT_TRUE(SetupEngineWithRecvStream()); 646 EXPECT_TRUE(SetupRecvStream());
656 cricket::AudioRecvParameters parameters; 647 cricket::AudioRecvParameters parameters;
657 parameters.codecs.push_back(kIsacCodec); 648 parameters.codecs.push_back(kIsacCodec);
658 parameters.codecs.push_back(kCn16000Codec); 649 parameters.codecs.push_back(kCn16000Codec);
659 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 650 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
660 EXPECT_TRUE(channel_->SetPlayout(true)); 651 EXPECT_TRUE(channel_->SetPlayout(true));
661 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 652 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
662 653
663 // Changing the payload type of a codec should fail. 654 // Changing the payload type of a codec should fail.
664 parameters.codecs[0].id = 127; 655 parameters.codecs[0].id = 127;
665 EXPECT_FALSE(channel_->SetRecvParameters(parameters)); 656 EXPECT_FALSE(channel_->SetRecvParameters(parameters));
666 int channel_num = voe_.GetLastChannel(); 657 int channel_num = voe_.GetLastChannel();
667 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 658 EXPECT_TRUE(voe_.GetPlayout(channel_num));
668 } 659 }
669 660
670 // Test that we can add a codec while playing. 661 // Test that we can add a codec while playing.
671 TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) { 662 TEST_F(WebRtcVoiceEngineTestFake, AddRecvCodecsWhilePlaying) {
672 EXPECT_TRUE(SetupEngineWithRecvStream()); 663 EXPECT_TRUE(SetupRecvStream());
673 cricket::AudioRecvParameters parameters; 664 cricket::AudioRecvParameters parameters;
674 parameters.codecs.push_back(kIsacCodec); 665 parameters.codecs.push_back(kIsacCodec);
675 parameters.codecs.push_back(kCn16000Codec); 666 parameters.codecs.push_back(kCn16000Codec);
676 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 667 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
677 EXPECT_TRUE(channel_->SetPlayout(true)); 668 EXPECT_TRUE(channel_->SetPlayout(true));
678 669
679 parameters.codecs.push_back(kOpusCodec); 670 parameters.codecs.push_back(kOpusCodec);
680 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 671 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
681 int channel_num = voe_.GetLastChannel(); 672 int channel_num = voe_.GetLastChannel();
682 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 673 EXPECT_TRUE(voe_.GetPlayout(channel_num));
683 webrtc::CodecInst gcodec; 674 webrtc::CodecInst gcodec;
684 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &gcodec)); 675 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(kOpusCodec, &gcodec));
685 EXPECT_EQ(kOpusCodec.id, gcodec.pltype); 676 EXPECT_EQ(kOpusCodec.id, gcodec.pltype);
686 } 677 }
687 678
688 TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) { 679 TEST_F(WebRtcVoiceEngineTestFake, SetSendBandwidthAuto) {
689 EXPECT_TRUE(SetupEngineWithSendStream()); 680 EXPECT_TRUE(SetupSendStream());
690 681
691 // Test that when autobw is enabled, bitrate is kept as the default 682 // Test that when autobw is enabled, bitrate is kept as the default
692 // value. autobw is enabled for the following tests because the target 683 // value. autobw is enabled for the following tests because the target
693 // bitrate is <= 0. 684 // bitrate is <= 0.
694 685
695 // ISAC, default bitrate == 32000. 686 // ISAC, default bitrate == 32000.
696 TestSendBandwidth(kIsacCodec, 0, true, 32000); 687 TestSendBandwidth(kIsacCodec, 0, true, 32000);
697 688
698 // PCMU, default bitrate == 64000. 689 // PCMU, default bitrate == 64000.
699 TestSendBandwidth(kPcmuCodec, -1, true, 64000); 690 TestSendBandwidth(kPcmuCodec, -1, true, 64000);
700 691
701 // opus, default bitrate == 64000. 692 // opus, default bitrate == 64000.
702 TestSendBandwidth(kOpusCodec, -1, true, 64000); 693 TestSendBandwidth(kOpusCodec, -1, true, 64000);
703 } 694 }
704 695
705 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) { 696 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCaller) {
706 EXPECT_TRUE(SetupEngineWithSendStream()); 697 EXPECT_TRUE(SetupSendStream());
707 698
708 // Test that the bitrate of a multi-rate codec is always the maximum. 699 // Test that the bitrate of a multi-rate codec is always the maximum.
709 700
710 // ISAC, default bitrate == 32000. 701 // ISAC, default bitrate == 32000.
711 TestSendBandwidth(kIsacCodec, 128000, true, 128000); 702 TestSendBandwidth(kIsacCodec, 128000, true, 128000);
712 TestSendBandwidth(kIsacCodec, 16000, true, 16000); 703 TestSendBandwidth(kIsacCodec, 16000, true, 16000);
713 704
714 // opus, default bitrate == 64000. 705 // opus, default bitrate == 64000.
715 TestSendBandwidth(kOpusCodec, 96000, true, 96000); 706 TestSendBandwidth(kOpusCodec, 96000, true, 96000);
716 TestSendBandwidth(kOpusCodec, 48000, true, 48000); 707 TestSendBandwidth(kOpusCodec, 48000, true, 48000);
717 } 708 }
718 709
719 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) { 710 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthFixedRateAsCaller) {
720 EXPECT_TRUE(SetupEngineWithSendStream()); 711 EXPECT_TRUE(SetupSendStream());
721 712
722 // Test that we can only set a maximum bitrate for a fixed-rate codec 713 // Test that we can only set a maximum bitrate for a fixed-rate codec
723 // if it's bigger than the fixed rate. 714 // if it's bigger than the fixed rate.
724 715
725 // PCMU, fixed bitrate == 64000. 716 // PCMU, fixed bitrate == 64000.
726 TestSendBandwidth(kPcmuCodec, 0, true, 64000); 717 TestSendBandwidth(kPcmuCodec, 0, true, 64000);
727 TestSendBandwidth(kPcmuCodec, 1, false, 64000); 718 TestSendBandwidth(kPcmuCodec, 1, false, 64000);
728 TestSendBandwidth(kPcmuCodec, 128000, true, 64000); 719 TestSendBandwidth(kPcmuCodec, 128000, true, 64000);
729 TestSendBandwidth(kPcmuCodec, 32000, false, 64000); 720 TestSendBandwidth(kPcmuCodec, 32000, false, 64000);
730 TestSendBandwidth(kPcmuCodec, 64000, true, 64000); 721 TestSendBandwidth(kPcmuCodec, 64000, true, 64000);
731 TestSendBandwidth(kPcmuCodec, 63999, false, 64000); 722 TestSendBandwidth(kPcmuCodec, 63999, false, 64000);
732 TestSendBandwidth(kPcmuCodec, 64001, true, 64000); 723 TestSendBandwidth(kPcmuCodec, 64001, true, 64000);
733 } 724 }
734 725
735 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) { 726 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthMultiRateAsCallee) {
736 EXPECT_TRUE(SetupEngine()); 727 EXPECT_TRUE(SetupChannel());
737 const int kDesiredBitrate = 128000; 728 const int kDesiredBitrate = 128000;
738 cricket::AudioSendParameters parameters; 729 cricket::AudioSendParameters parameters;
739 parameters.codecs = engine_.codecs(); 730 parameters.codecs = engine_.codecs();
740 parameters.max_bandwidth_bps = kDesiredBitrate; 731 parameters.max_bandwidth_bps = kDesiredBitrate;
741 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 732 EXPECT_TRUE(channel_->SetSendParameters(parameters));
742 733
743 EXPECT_TRUE(channel_->AddSendStream( 734 EXPECT_TRUE(channel_->AddSendStream(
744 cricket::StreamParams::CreateLegacy(kSsrc1))); 735 cricket::StreamParams::CreateLegacy(kSsrc1)));
745 736
746 int channel_num = voe_.GetLastChannel(); 737 int channel_num = voe_.GetLastChannel();
747 webrtc::CodecInst codec; 738 webrtc::CodecInst codec;
748 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 739 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
749 EXPECT_EQ(kDesiredBitrate, codec.rate); 740 EXPECT_EQ(kDesiredBitrate, codec.rate);
750 } 741 }
751 742
752 // Test that bitrate cannot be set for CBR codecs. 743 // Test that bitrate cannot be set for CBR codecs.
753 // Bitrate is ignored if it is higher than the fixed bitrate. 744 // Bitrate is ignored if it is higher than the fixed bitrate.
754 // Bitrate less then the fixed bitrate is an error. 745 // Bitrate less then the fixed bitrate is an error.
755 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) { 746 TEST_F(WebRtcVoiceEngineTestFake, SetMaxSendBandwidthCbr) {
756 EXPECT_TRUE(SetupEngineWithSendStream()); 747 EXPECT_TRUE(SetupSendStream());
757 748
758 // PCMU, default bitrate == 64000. 749 // PCMU, default bitrate == 64000.
759 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 750 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
760 int channel_num = voe_.GetLastChannel(); 751 int channel_num = voe_.GetLastChannel();
761 webrtc::CodecInst codec; 752 webrtc::CodecInst codec;
762 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 753 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
763 EXPECT_EQ(64000, codec.rate); 754 EXPECT_EQ(64000, codec.rate);
764 755
765 send_parameters_.max_bandwidth_bps = 128000; 756 send_parameters_.max_bandwidth_bps = 128000;
766 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 757 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
767 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 758 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
768 EXPECT_EQ(64000, codec.rate); 759 EXPECT_EQ(64000, codec.rate);
769 760
770 send_parameters_.max_bandwidth_bps = 128; 761 send_parameters_.max_bandwidth_bps = 128;
771 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); 762 EXPECT_FALSE(channel_->SetSendParameters(send_parameters_));
772 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec)); 763 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, codec));
773 EXPECT_EQ(64000, codec.rate); 764 EXPECT_EQ(64000, codec.rate);
774 } 765 }
775 766
776 // Test that we apply codecs properly. 767 // Test that we apply codecs properly.
777 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) { 768 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecs) {
778 EXPECT_TRUE(SetupEngineWithSendStream()); 769 EXPECT_TRUE(SetupSendStream());
779 cricket::AudioSendParameters parameters; 770 cricket::AudioSendParameters parameters;
780 parameters.codecs.push_back(kIsacCodec); 771 parameters.codecs.push_back(kIsacCodec);
781 parameters.codecs.push_back(kPcmuCodec); 772 parameters.codecs.push_back(kPcmuCodec);
782 parameters.codecs.push_back(kRedCodec); 773 parameters.codecs.push_back(kRedCodec);
783 parameters.codecs[0].id = 96; 774 parameters.codecs[0].id = 96;
784 parameters.codecs[0].bitrate = 48000; 775 parameters.codecs[0].bitrate = 48000;
785 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 776 EXPECT_TRUE(channel_->SetSendParameters(parameters));
786 EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); 777 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
787 int channel_num = voe_.GetLastChannel(); 778 int channel_num = voe_.GetLastChannel();
788 webrtc::CodecInst gcodec; 779 webrtc::CodecInst gcodec;
789 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 780 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
790 EXPECT_EQ(96, gcodec.pltype); 781 EXPECT_EQ(96, gcodec.pltype);
791 EXPECT_EQ(48000, gcodec.rate); 782 EXPECT_EQ(48000, gcodec.rate);
792 EXPECT_STREQ("ISAC", gcodec.plname); 783 EXPECT_STREQ("ISAC", gcodec.plname);
793 EXPECT_FALSE(voe_.GetVAD(channel_num)); 784 EXPECT_FALSE(voe_.GetVAD(channel_num));
794 EXPECT_FALSE(voe_.GetRED(channel_num)); 785 EXPECT_FALSE(voe_.GetRED(channel_num));
795 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); 786 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
796 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true)); 787 EXPECT_EQ(105, voe_.GetSendCNPayloadType(channel_num, true));
797 EXPECT_FALSE(channel_->CanInsertDtmf()); 788 EXPECT_FALSE(channel_->CanInsertDtmf());
798 } 789 }
799 790
800 // Test that VoE Channel doesn't call SetSendCodec again if same codec is tried 791 // Test that VoE Channel doesn't call SetSendCodec again if same codec is tried
801 // to apply. 792 // to apply.
802 TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) { 793 TEST_F(WebRtcVoiceEngineTestFake, DontResetSetSendCodec) {
803 EXPECT_TRUE(SetupEngineWithSendStream()); 794 EXPECT_TRUE(SetupSendStream());
804 cricket::AudioSendParameters parameters; 795 cricket::AudioSendParameters parameters;
805 parameters.codecs.push_back(kIsacCodec); 796 parameters.codecs.push_back(kIsacCodec);
806 parameters.codecs.push_back(kPcmuCodec); 797 parameters.codecs.push_back(kPcmuCodec);
807 parameters.codecs.push_back(kRedCodec); 798 parameters.codecs.push_back(kRedCodec);
808 parameters.codecs[0].id = 96; 799 parameters.codecs[0].id = 96;
809 parameters.codecs[0].bitrate = 48000; 800 parameters.codecs[0].bitrate = 48000;
810 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 801 EXPECT_TRUE(channel_->SetSendParameters(parameters));
811 EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); 802 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
812 // Calling SetSendCodec again with same codec which is already set. 803 // Calling SetSendCodec again with same codec which is already set.
813 // In this case media channel shouldn't send codec to VoE. 804 // In this case media channel shouldn't send codec to VoE.
814 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 805 EXPECT_TRUE(channel_->SetSendParameters(parameters));
815 EXPECT_EQ(1, voe_.GetNumSetSendCodecs()); 806 EXPECT_EQ(1, voe_.GetNumSetSendCodecs());
816 } 807 }
817 808
818 // Verify that G722 is set with 16000 samples per second to WebRTC. 809 // Verify that G722 is set with 16000 samples per second to WebRTC.
819 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) { 810 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecG722) {
820 EXPECT_TRUE(SetupEngineWithSendStream()); 811 EXPECT_TRUE(SetupSendStream());
821 int channel_num = voe_.GetLastChannel(); 812 int channel_num = voe_.GetLastChannel();
822 cricket::AudioSendParameters parameters; 813 cricket::AudioSendParameters parameters;
823 parameters.codecs.push_back(kG722CodecSdp); 814 parameters.codecs.push_back(kG722CodecSdp);
824 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 815 EXPECT_TRUE(channel_->SetSendParameters(parameters));
825 webrtc::CodecInst gcodec; 816 webrtc::CodecInst gcodec;
826 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 817 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
827 EXPECT_STREQ("G722", gcodec.plname); 818 EXPECT_STREQ("G722", gcodec.plname);
828 EXPECT_EQ(1, gcodec.channels); 819 EXPECT_EQ(1, gcodec.channels);
829 EXPECT_EQ(16000, gcodec.plfreq); 820 EXPECT_EQ(16000, gcodec.plfreq);
830 } 821 }
831 822
832 // Test that if clockrate is not 48000 for opus, we fail. 823 // Test that if clockrate is not 48000 for opus, we fail.
833 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) { 824 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBadClockrate) {
834 EXPECT_TRUE(SetupEngineWithSendStream()); 825 EXPECT_TRUE(SetupSendStream());
835 cricket::AudioSendParameters parameters; 826 cricket::AudioSendParameters parameters;
836 parameters.codecs.push_back(kOpusCodec); 827 parameters.codecs.push_back(kOpusCodec);
837 parameters.codecs[0].bitrate = 0; 828 parameters.codecs[0].bitrate = 0;
838 parameters.codecs[0].clockrate = 50000; 829 parameters.codecs[0].clockrate = 50000;
839 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 830 EXPECT_FALSE(channel_->SetSendParameters(parameters));
840 } 831 }
841 832
842 // Test that if channels=0 for opus, we fail. 833 // Test that if channels=0 for opus, we fail.
843 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) { 834 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0ChannelsNoStereo) {
844 EXPECT_TRUE(SetupEngineWithSendStream()); 835 EXPECT_TRUE(SetupSendStream());
845 cricket::AudioSendParameters parameters; 836 cricket::AudioSendParameters parameters;
846 parameters.codecs.push_back(kOpusCodec); 837 parameters.codecs.push_back(kOpusCodec);
847 parameters.codecs[0].bitrate = 0; 838 parameters.codecs[0].bitrate = 0;
848 parameters.codecs[0].channels = 0; 839 parameters.codecs[0].channels = 0;
849 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 840 EXPECT_FALSE(channel_->SetSendParameters(parameters));
850 } 841 }
851 842
852 // Test that if channels=0 for opus, we fail. 843 // Test that if channels=0 for opus, we fail.
853 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) { 844 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad0Channels1Stereo) {
854 EXPECT_TRUE(SetupEngineWithSendStream()); 845 EXPECT_TRUE(SetupSendStream());
855 cricket::AudioSendParameters parameters; 846 cricket::AudioSendParameters parameters;
856 parameters.codecs.push_back(kOpusCodec); 847 parameters.codecs.push_back(kOpusCodec);
857 parameters.codecs[0].bitrate = 0; 848 parameters.codecs[0].bitrate = 0;
858 parameters.codecs[0].channels = 0; 849 parameters.codecs[0].channels = 0;
859 parameters.codecs[0].params["stereo"] = "1"; 850 parameters.codecs[0].params["stereo"] = "1";
860 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 851 EXPECT_FALSE(channel_->SetSendParameters(parameters));
861 } 852 }
862 853
863 // Test that if channel is 1 for opus and there's no stereo, we fail. 854 // Test that if channel is 1 for opus and there's no stereo, we fail.
864 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) { 855 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpus1ChannelNoStereo) {
865 EXPECT_TRUE(SetupEngineWithSendStream()); 856 EXPECT_TRUE(SetupSendStream());
866 cricket::AudioSendParameters parameters; 857 cricket::AudioSendParameters parameters;
867 parameters.codecs.push_back(kOpusCodec); 858 parameters.codecs.push_back(kOpusCodec);
868 parameters.codecs[0].bitrate = 0; 859 parameters.codecs[0].bitrate = 0;
869 parameters.codecs[0].channels = 1; 860 parameters.codecs[0].channels = 1;
870 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 861 EXPECT_FALSE(channel_->SetSendParameters(parameters));
871 } 862 }
872 863
873 // Test that if channel is 1 for opus and stereo=0, we fail. 864 // Test that if channel is 1 for opus and stereo=0, we fail.
874 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) { 865 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel0Stereo) {
875 EXPECT_TRUE(SetupEngineWithSendStream()); 866 EXPECT_TRUE(SetupSendStream());
876 cricket::AudioSendParameters parameters; 867 cricket::AudioSendParameters parameters;
877 parameters.codecs.push_back(kOpusCodec); 868 parameters.codecs.push_back(kOpusCodec);
878 parameters.codecs[0].bitrate = 0; 869 parameters.codecs[0].bitrate = 0;
879 parameters.codecs[0].channels = 1; 870 parameters.codecs[0].channels = 1;
880 parameters.codecs[0].params["stereo"] = "0"; 871 parameters.codecs[0].params["stereo"] = "0";
881 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 872 EXPECT_FALSE(channel_->SetSendParameters(parameters));
882 } 873 }
883 874
884 // Test that if channel is 1 for opus and stereo=1, we fail. 875 // Test that if channel is 1 for opus and stereo=1, we fail.
885 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) { 876 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusBad1Channel1Stereo) {
886 EXPECT_TRUE(SetupEngineWithSendStream()); 877 EXPECT_TRUE(SetupSendStream());
887 cricket::AudioSendParameters parameters; 878 cricket::AudioSendParameters parameters;
888 parameters.codecs.push_back(kOpusCodec); 879 parameters.codecs.push_back(kOpusCodec);
889 parameters.codecs[0].bitrate = 0; 880 parameters.codecs[0].bitrate = 0;
890 parameters.codecs[0].channels = 1; 881 parameters.codecs[0].channels = 1;
891 parameters.codecs[0].params["stereo"] = "1"; 882 parameters.codecs[0].params["stereo"] = "1";
892 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 883 EXPECT_FALSE(channel_->SetSendParameters(parameters));
893 } 884 }
894 885
895 // Test that with bitrate=0 and no stereo, 886 // Test that with bitrate=0 and no stereo,
896 // channels and bitrate are 1 and 32000. 887 // channels and bitrate are 1 and 32000.
897 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) { 888 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0BitrateNoStereo) {
898 EXPECT_TRUE(SetupEngineWithSendStream()); 889 EXPECT_TRUE(SetupSendStream());
899 int channel_num = voe_.GetLastChannel(); 890 int channel_num = voe_.GetLastChannel();
900 cricket::AudioSendParameters parameters; 891 cricket::AudioSendParameters parameters;
901 parameters.codecs.push_back(kOpusCodec); 892 parameters.codecs.push_back(kOpusCodec);
902 parameters.codecs[0].bitrate = 0; 893 parameters.codecs[0].bitrate = 0;
903 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 894 EXPECT_TRUE(channel_->SetSendParameters(parameters));
904 webrtc::CodecInst gcodec; 895 webrtc::CodecInst gcodec;
905 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 896 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
906 EXPECT_STREQ("opus", gcodec.plname); 897 EXPECT_STREQ("opus", gcodec.plname);
907 EXPECT_EQ(1, gcodec.channels); 898 EXPECT_EQ(1, gcodec.channels);
908 EXPECT_EQ(32000, gcodec.rate); 899 EXPECT_EQ(32000, gcodec.rate);
909 } 900 }
910 901
911 // Test that with bitrate=0 and stereo=0, 902 // Test that with bitrate=0 and stereo=0,
912 // channels and bitrate are 1 and 32000. 903 // channels and bitrate are 1 and 32000.
913 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) { 904 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate0Stereo) {
914 EXPECT_TRUE(SetupEngineWithSendStream()); 905 EXPECT_TRUE(SetupSendStream());
915 int channel_num = voe_.GetLastChannel(); 906 int channel_num = voe_.GetLastChannel();
916 cricket::AudioSendParameters parameters; 907 cricket::AudioSendParameters parameters;
917 parameters.codecs.push_back(kOpusCodec); 908 parameters.codecs.push_back(kOpusCodec);
918 parameters.codecs[0].bitrate = 0; 909 parameters.codecs[0].bitrate = 0;
919 parameters.codecs[0].params["stereo"] = "0"; 910 parameters.codecs[0].params["stereo"] = "0";
920 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 911 EXPECT_TRUE(channel_->SetSendParameters(parameters));
921 webrtc::CodecInst gcodec; 912 webrtc::CodecInst gcodec;
922 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 913 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
923 EXPECT_STREQ("opus", gcodec.plname); 914 EXPECT_STREQ("opus", gcodec.plname);
924 EXPECT_EQ(1, gcodec.channels); 915 EXPECT_EQ(1, gcodec.channels);
925 EXPECT_EQ(32000, gcodec.rate); 916 EXPECT_EQ(32000, gcodec.rate);
926 } 917 }
927 918
928 // Test that with bitrate=invalid and stereo=0, 919 // Test that with bitrate=invalid and stereo=0,
929 // channels and bitrate are 1 and 32000. 920 // channels and bitrate are 1 and 32000.
930 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) { 921 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate0Stereo) {
931 EXPECT_TRUE(SetupEngineWithSendStream()); 922 EXPECT_TRUE(SetupSendStream());
932 int channel_num = voe_.GetLastChannel(); 923 int channel_num = voe_.GetLastChannel();
933 cricket::AudioSendParameters parameters; 924 cricket::AudioSendParameters parameters;
934 parameters.codecs.push_back(kOpusCodec); 925 parameters.codecs.push_back(kOpusCodec);
935 parameters.codecs[0].params["stereo"] = "0"; 926 parameters.codecs[0].params["stereo"] = "0";
936 webrtc::CodecInst gcodec; 927 webrtc::CodecInst gcodec;
937 928
938 // bitrate that's out of the range between 6000 and 510000 will be clamped. 929 // bitrate that's out of the range between 6000 and 510000 will be clamped.
939 parameters.codecs[0].bitrate = 5999; 930 parameters.codecs[0].bitrate = 5999;
940 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 931 EXPECT_TRUE(channel_->SetSendParameters(parameters));
941 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 932 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
942 EXPECT_STREQ("opus", gcodec.plname); 933 EXPECT_STREQ("opus", gcodec.plname);
943 EXPECT_EQ(1, gcodec.channels); 934 EXPECT_EQ(1, gcodec.channels);
944 EXPECT_EQ(6000, gcodec.rate); 935 EXPECT_EQ(6000, gcodec.rate);
945 936
946 parameters.codecs[0].bitrate = 510001; 937 parameters.codecs[0].bitrate = 510001;
947 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 938 EXPECT_TRUE(channel_->SetSendParameters(parameters));
948 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 939 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
949 EXPECT_STREQ("opus", gcodec.plname); 940 EXPECT_STREQ("opus", gcodec.plname);
950 EXPECT_EQ(1, gcodec.channels); 941 EXPECT_EQ(1, gcodec.channels);
951 EXPECT_EQ(510000, gcodec.rate); 942 EXPECT_EQ(510000, gcodec.rate);
952 } 943 }
953 944
954 // Test that with bitrate=0 and stereo=1, 945 // Test that with bitrate=0 and stereo=1,
955 // channels and bitrate are 2 and 64000. 946 // channels and bitrate are 2 and 64000.
956 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) { 947 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGood0Bitrate1Stereo) {
957 EXPECT_TRUE(SetupEngineWithSendStream()); 948 EXPECT_TRUE(SetupSendStream());
958 int channel_num = voe_.GetLastChannel(); 949 int channel_num = voe_.GetLastChannel();
959 cricket::AudioSendParameters parameters; 950 cricket::AudioSendParameters parameters;
960 parameters.codecs.push_back(kOpusCodec); 951 parameters.codecs.push_back(kOpusCodec);
961 parameters.codecs[0].bitrate = 0; 952 parameters.codecs[0].bitrate = 0;
962 parameters.codecs[0].params["stereo"] = "1"; 953 parameters.codecs[0].params["stereo"] = "1";
963 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 954 EXPECT_TRUE(channel_->SetSendParameters(parameters));
964 webrtc::CodecInst gcodec; 955 webrtc::CodecInst gcodec;
965 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 956 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
966 EXPECT_STREQ("opus", gcodec.plname); 957 EXPECT_STREQ("opus", gcodec.plname);
967 EXPECT_EQ(2, gcodec.channels); 958 EXPECT_EQ(2, gcodec.channels);
968 EXPECT_EQ(64000, gcodec.rate); 959 EXPECT_EQ(64000, gcodec.rate);
969 } 960 }
970 961
971 // Test that with bitrate=invalid and stereo=1, 962 // Test that with bitrate=invalid and stereo=1,
972 // channels and bitrate are 2 and 64000. 963 // channels and bitrate are 2 and 64000.
973 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) { 964 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodXBitrate1Stereo) {
974 EXPECT_TRUE(SetupEngineWithSendStream()); 965 EXPECT_TRUE(SetupSendStream());
975 int channel_num = voe_.GetLastChannel(); 966 int channel_num = voe_.GetLastChannel();
976 cricket::AudioSendParameters parameters; 967 cricket::AudioSendParameters parameters;
977 parameters.codecs.push_back(kOpusCodec); 968 parameters.codecs.push_back(kOpusCodec);
978 parameters.codecs[0].params["stereo"] = "1"; 969 parameters.codecs[0].params["stereo"] = "1";
979 webrtc::CodecInst gcodec; 970 webrtc::CodecInst gcodec;
980 971
981 // bitrate that's out of the range between 6000 and 510000 will be clamped. 972 // bitrate that's out of the range between 6000 and 510000 will be clamped.
982 parameters.codecs[0].bitrate = 5999; 973 parameters.codecs[0].bitrate = 5999;
983 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 974 EXPECT_TRUE(channel_->SetSendParameters(parameters));
984 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 975 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
985 EXPECT_STREQ("opus", gcodec.plname); 976 EXPECT_STREQ("opus", gcodec.plname);
986 EXPECT_EQ(2, gcodec.channels); 977 EXPECT_EQ(2, gcodec.channels);
987 EXPECT_EQ(6000, gcodec.rate); 978 EXPECT_EQ(6000, gcodec.rate);
988 979
989 parameters.codecs[0].bitrate = 510001; 980 parameters.codecs[0].bitrate = 510001;
990 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 981 EXPECT_TRUE(channel_->SetSendParameters(parameters));
991 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 982 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
992 EXPECT_STREQ("opus", gcodec.plname); 983 EXPECT_STREQ("opus", gcodec.plname);
993 EXPECT_EQ(2, gcodec.channels); 984 EXPECT_EQ(2, gcodec.channels);
994 EXPECT_EQ(510000, gcodec.rate); 985 EXPECT_EQ(510000, gcodec.rate);
995 } 986 }
996 987
997 // Test that with bitrate=N and stereo unset, 988 // Test that with bitrate=N and stereo unset,
998 // channels and bitrate are 1 and N. 989 // channels and bitrate are 1 and N.
999 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) { 990 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoStereo) {
1000 EXPECT_TRUE(SetupEngineWithSendStream()); 991 EXPECT_TRUE(SetupSendStream());
1001 int channel_num = voe_.GetLastChannel(); 992 int channel_num = voe_.GetLastChannel();
1002 cricket::AudioSendParameters parameters; 993 cricket::AudioSendParameters parameters;
1003 parameters.codecs.push_back(kOpusCodec); 994 parameters.codecs.push_back(kOpusCodec);
1004 parameters.codecs[0].bitrate = 96000; 995 parameters.codecs[0].bitrate = 96000;
1005 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 996 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1006 webrtc::CodecInst gcodec; 997 webrtc::CodecInst gcodec;
1007 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 998 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1008 EXPECT_EQ(111, gcodec.pltype); 999 EXPECT_EQ(111, gcodec.pltype);
1009 EXPECT_EQ(96000, gcodec.rate); 1000 EXPECT_EQ(96000, gcodec.rate);
1010 EXPECT_STREQ("opus", gcodec.plname); 1001 EXPECT_STREQ("opus", gcodec.plname);
1011 EXPECT_EQ(1, gcodec.channels); 1002 EXPECT_EQ(1, gcodec.channels);
1012 EXPECT_EQ(48000, gcodec.plfreq); 1003 EXPECT_EQ(48000, gcodec.plfreq);
1013 } 1004 }
1014 1005
1015 // Test that with bitrate=N and stereo=0, 1006 // Test that with bitrate=N and stereo=0,
1016 // channels and bitrate are 1 and N. 1007 // channels and bitrate are 1 and N.
1017 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) { 1008 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate0Stereo) {
1018 EXPECT_TRUE(SetupEngineWithSendStream()); 1009 EXPECT_TRUE(SetupSendStream());
1019 int channel_num = voe_.GetLastChannel(); 1010 int channel_num = voe_.GetLastChannel();
1020 cricket::AudioSendParameters parameters; 1011 cricket::AudioSendParameters parameters;
1021 parameters.codecs.push_back(kOpusCodec); 1012 parameters.codecs.push_back(kOpusCodec);
1022 parameters.codecs[0].bitrate = 30000; 1013 parameters.codecs[0].bitrate = 30000;
1023 parameters.codecs[0].params["stereo"] = "0"; 1014 parameters.codecs[0].params["stereo"] = "0";
1024 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1015 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1025 webrtc::CodecInst gcodec; 1016 webrtc::CodecInst gcodec;
1026 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1017 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1027 EXPECT_EQ(1, gcodec.channels); 1018 EXPECT_EQ(1, gcodec.channels);
1028 EXPECT_EQ(30000, gcodec.rate); 1019 EXPECT_EQ(30000, gcodec.rate);
1029 EXPECT_STREQ("opus", gcodec.plname); 1020 EXPECT_STREQ("opus", gcodec.plname);
1030 } 1021 }
1031 1022
1032 // Test that with bitrate=N and without any parameters, 1023 // Test that with bitrate=N and without any parameters,
1033 // channels and bitrate are 1 and N. 1024 // channels and bitrate are 1 and N.
1034 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) { 1025 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrateNoParameters) {
1035 EXPECT_TRUE(SetupEngineWithSendStream()); 1026 EXPECT_TRUE(SetupSendStream());
1036 int channel_num = voe_.GetLastChannel(); 1027 int channel_num = voe_.GetLastChannel();
1037 cricket::AudioSendParameters parameters; 1028 cricket::AudioSendParameters parameters;
1038 parameters.codecs.push_back(kOpusCodec); 1029 parameters.codecs.push_back(kOpusCodec);
1039 parameters.codecs[0].bitrate = 30000; 1030 parameters.codecs[0].bitrate = 30000;
1040 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1031 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1041 webrtc::CodecInst gcodec; 1032 webrtc::CodecInst gcodec;
1042 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1033 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1043 EXPECT_EQ(1, gcodec.channels); 1034 EXPECT_EQ(1, gcodec.channels);
1044 EXPECT_EQ(30000, gcodec.rate); 1035 EXPECT_EQ(30000, gcodec.rate);
1045 EXPECT_STREQ("opus", gcodec.plname); 1036 EXPECT_STREQ("opus", gcodec.plname);
1046 } 1037 }
1047 1038
1048 // Test that with bitrate=N and stereo=1, 1039 // Test that with bitrate=N and stereo=1,
1049 // channels and bitrate are 2 and N. 1040 // channels and bitrate are 2 and N.
1050 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) { 1041 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusGoodNBitrate1Stereo) {
1051 EXPECT_TRUE(SetupEngineWithSendStream()); 1042 EXPECT_TRUE(SetupSendStream());
1052 int channel_num = voe_.GetLastChannel(); 1043 int channel_num = voe_.GetLastChannel();
1053 cricket::AudioSendParameters parameters; 1044 cricket::AudioSendParameters parameters;
1054 parameters.codecs.push_back(kOpusCodec); 1045 parameters.codecs.push_back(kOpusCodec);
1055 parameters.codecs[0].bitrate = 30000; 1046 parameters.codecs[0].bitrate = 30000;
1056 parameters.codecs[0].params["stereo"] = "1"; 1047 parameters.codecs[0].params["stereo"] = "1";
1057 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1048 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1058 webrtc::CodecInst gcodec; 1049 webrtc::CodecInst gcodec;
1059 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1050 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1060 EXPECT_EQ(2, gcodec.channels); 1051 EXPECT_EQ(2, gcodec.channels);
1061 EXPECT_EQ(30000, gcodec.rate); 1052 EXPECT_EQ(30000, gcodec.rate);
1062 EXPECT_STREQ("opus", gcodec.plname); 1053 EXPECT_STREQ("opus", gcodec.plname);
1063 } 1054 }
1064 1055
1065 // Test that bitrate will be overridden by the "maxaveragebitrate" parameter. 1056 // Test that bitrate will be overridden by the "maxaveragebitrate" parameter.
1066 // Also test that the "maxaveragebitrate" can't be set to values outside the 1057 // Also test that the "maxaveragebitrate" can't be set to values outside the
1067 // range of 6000 and 510000 1058 // range of 6000 and 510000
1068 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) { 1059 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusMaxAverageBitrate) {
1069 EXPECT_TRUE(SetupEngineWithSendStream()); 1060 EXPECT_TRUE(SetupSendStream());
1070 int channel_num = voe_.GetLastChannel(); 1061 int channel_num = voe_.GetLastChannel();
1071 cricket::AudioSendParameters parameters; 1062 cricket::AudioSendParameters parameters;
1072 parameters.codecs.push_back(kOpusCodec); 1063 parameters.codecs.push_back(kOpusCodec);
1073 parameters.codecs[0].bitrate = 30000; 1064 parameters.codecs[0].bitrate = 30000;
1074 webrtc::CodecInst gcodec; 1065 webrtc::CodecInst gcodec;
1075 1066
1076 // Ignore if less than 6000. 1067 // Ignore if less than 6000.
1077 parameters.codecs[0].params["maxaveragebitrate"] = "5999"; 1068 parameters.codecs[0].params["maxaveragebitrate"] = "5999";
1078 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1069 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1079 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1070 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1080 EXPECT_EQ(6000, gcodec.rate); 1071 EXPECT_EQ(6000, gcodec.rate);
1081 1072
1082 // Ignore if larger than 510000. 1073 // Ignore if larger than 510000.
1083 parameters.codecs[0].params["maxaveragebitrate"] = "510001"; 1074 parameters.codecs[0].params["maxaveragebitrate"] = "510001";
1084 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1075 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1085 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1076 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1086 EXPECT_EQ(510000, gcodec.rate); 1077 EXPECT_EQ(510000, gcodec.rate);
1087 1078
1088 parameters.codecs[0].params["maxaveragebitrate"] = "200000"; 1079 parameters.codecs[0].params["maxaveragebitrate"] = "200000";
1089 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1080 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1090 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1081 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1091 EXPECT_EQ(200000, gcodec.rate); 1082 EXPECT_EQ(200000, gcodec.rate);
1092 } 1083 }
1093 1084
1094 // Test that we can enable NACK with opus as caller. 1085 // Test that we can enable NACK with opus as caller.
1095 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) { 1086 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCaller) {
1096 EXPECT_TRUE(SetupEngineWithSendStream()); 1087 EXPECT_TRUE(SetupSendStream());
1097 int channel_num = voe_.GetLastChannel(); 1088 int channel_num = voe_.GetLastChannel();
1098 cricket::AudioSendParameters parameters; 1089 cricket::AudioSendParameters parameters;
1099 parameters.codecs.push_back(kOpusCodec); 1090 parameters.codecs.push_back(kOpusCodec);
1100 parameters.codecs[0].AddFeedbackParam( 1091 parameters.codecs[0].AddFeedbackParam(
1101 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1092 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1102 cricket::kParamValueEmpty)); 1093 cricket::kParamValueEmpty));
1103 EXPECT_FALSE(voe_.GetNACK(channel_num)); 1094 EXPECT_FALSE(voe_.GetNACK(channel_num));
1104 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1095 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1105 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1096 EXPECT_TRUE(voe_.GetNACK(channel_num));
1106 } 1097 }
1107 1098
1108 // Test that we can enable NACK with opus as callee. 1099 // Test that we can enable NACK with opus as callee.
1109 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) { 1100 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackAsCallee) {
1110 EXPECT_TRUE(SetupEngineWithRecvStream()); 1101 EXPECT_TRUE(SetupRecvStream());
1111 int channel_num = voe_.GetLastChannel(); 1102 int channel_num = voe_.GetLastChannel();
1112 cricket::AudioSendParameters parameters; 1103 cricket::AudioSendParameters parameters;
1113 parameters.codecs.push_back(kOpusCodec); 1104 parameters.codecs.push_back(kOpusCodec);
1114 parameters.codecs[0].AddFeedbackParam( 1105 parameters.codecs[0].AddFeedbackParam(
1115 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1106 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1116 cricket::kParamValueEmpty)); 1107 cricket::kParamValueEmpty));
1117 EXPECT_FALSE(voe_.GetNACK(channel_num)); 1108 EXPECT_FALSE(voe_.GetNACK(channel_num));
1118 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1109 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1119 EXPECT_FALSE(voe_.GetNACK(channel_num)); 1110 EXPECT_FALSE(voe_.GetNACK(channel_num));
1120 1111
1121 EXPECT_TRUE(channel_->AddSendStream( 1112 EXPECT_TRUE(channel_->AddSendStream(
1122 cricket::StreamParams::CreateLegacy(kSsrc1))); 1113 cricket::StreamParams::CreateLegacy(kSsrc1)));
1123 EXPECT_TRUE(voe_.GetNACK(voe_.GetLastChannel())); 1114 EXPECT_TRUE(voe_.GetNACK(voe_.GetLastChannel()));
1124 } 1115 }
1125 1116
1126 // Test that we can enable NACK on receive streams. 1117 // Test that we can enable NACK on receive streams.
1127 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) { 1118 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecEnableNackRecvStreams) {
1128 EXPECT_TRUE(SetupEngineWithSendStream()); 1119 EXPECT_TRUE(SetupSendStream());
1129 int channel_num1 = voe_.GetLastChannel(); 1120 int channel_num1 = voe_.GetLastChannel();
1130 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 1121 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1131 int channel_num2 = voe_.GetLastChannel(); 1122 int channel_num2 = voe_.GetLastChannel();
1132 cricket::AudioSendParameters parameters; 1123 cricket::AudioSendParameters parameters;
1133 parameters.codecs.push_back(kOpusCodec); 1124 parameters.codecs.push_back(kOpusCodec);
1134 parameters.codecs[0].AddFeedbackParam( 1125 parameters.codecs[0].AddFeedbackParam(
1135 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1126 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1136 cricket::kParamValueEmpty)); 1127 cricket::kParamValueEmpty));
1137 EXPECT_FALSE(voe_.GetNACK(channel_num1)); 1128 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1138 EXPECT_FALSE(voe_.GetNACK(channel_num2)); 1129 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1139 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1130 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1140 EXPECT_TRUE(voe_.GetNACK(channel_num1)); 1131 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1141 EXPECT_TRUE(voe_.GetNACK(channel_num2)); 1132 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1142 } 1133 }
1143 1134
1144 // Test that we can disable NACK. 1135 // Test that we can disable NACK.
1145 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) { 1136 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNack) {
1146 EXPECT_TRUE(SetupEngineWithSendStream()); 1137 EXPECT_TRUE(SetupSendStream());
1147 int channel_num = voe_.GetLastChannel(); 1138 int channel_num = voe_.GetLastChannel();
1148 cricket::AudioSendParameters parameters; 1139 cricket::AudioSendParameters parameters;
1149 parameters.codecs.push_back(kOpusCodec); 1140 parameters.codecs.push_back(kOpusCodec);
1150 parameters.codecs[0].AddFeedbackParam( 1141 parameters.codecs[0].AddFeedbackParam(
1151 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1142 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1152 cricket::kParamValueEmpty)); 1143 cricket::kParamValueEmpty));
1153 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1144 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1154 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1145 EXPECT_TRUE(voe_.GetNACK(channel_num));
1155 1146
1156 parameters.codecs.clear(); 1147 parameters.codecs.clear();
1157 parameters.codecs.push_back(kOpusCodec); 1148 parameters.codecs.push_back(kOpusCodec);
1158 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1149 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1159 EXPECT_FALSE(voe_.GetNACK(channel_num)); 1150 EXPECT_FALSE(voe_.GetNACK(channel_num));
1160 } 1151 }
1161 1152
1162 // Test that we can disable NACK on receive streams. 1153 // Test that we can disable NACK on receive streams.
1163 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) { 1154 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecDisableNackRecvStreams) {
1164 EXPECT_TRUE(SetupEngineWithSendStream()); 1155 EXPECT_TRUE(SetupSendStream());
1165 int channel_num1 = voe_.GetLastChannel(); 1156 int channel_num1 = voe_.GetLastChannel();
1166 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 1157 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1167 int channel_num2 = voe_.GetLastChannel(); 1158 int channel_num2 = voe_.GetLastChannel();
1168 cricket::AudioSendParameters parameters; 1159 cricket::AudioSendParameters parameters;
1169 parameters.codecs.push_back(kOpusCodec); 1160 parameters.codecs.push_back(kOpusCodec);
1170 parameters.codecs[0].AddFeedbackParam( 1161 parameters.codecs[0].AddFeedbackParam(
1171 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1162 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1172 cricket::kParamValueEmpty)); 1163 cricket::kParamValueEmpty));
1173 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1164 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1174 EXPECT_TRUE(voe_.GetNACK(channel_num1)); 1165 EXPECT_TRUE(voe_.GetNACK(channel_num1));
1175 EXPECT_TRUE(voe_.GetNACK(channel_num2)); 1166 EXPECT_TRUE(voe_.GetNACK(channel_num2));
1176 1167
1177 parameters.codecs.clear(); 1168 parameters.codecs.clear();
1178 parameters.codecs.push_back(kOpusCodec); 1169 parameters.codecs.push_back(kOpusCodec);
1179 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1170 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1180 EXPECT_FALSE(voe_.GetNACK(channel_num1)); 1171 EXPECT_FALSE(voe_.GetNACK(channel_num1));
1181 EXPECT_FALSE(voe_.GetNACK(channel_num2)); 1172 EXPECT_FALSE(voe_.GetNACK(channel_num2));
1182 } 1173 }
1183 1174
1184 // Test that NACK is enabled on a new receive stream. 1175 // Test that NACK is enabled on a new receive stream.
1185 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) { 1176 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamEnableNack) {
1186 EXPECT_TRUE(SetupEngineWithSendStream()); 1177 EXPECT_TRUE(SetupSendStream());
1187 int channel_num = voe_.GetLastChannel(); 1178 int channel_num = voe_.GetLastChannel();
1188 cricket::AudioSendParameters parameters; 1179 cricket::AudioSendParameters parameters;
1189 parameters.codecs.push_back(kIsacCodec); 1180 parameters.codecs.push_back(kIsacCodec);
1190 parameters.codecs.push_back(kCn16000Codec); 1181 parameters.codecs.push_back(kCn16000Codec);
1191 parameters.codecs[0].AddFeedbackParam( 1182 parameters.codecs[0].AddFeedbackParam(
1192 cricket::FeedbackParam(cricket::kRtcpFbParamNack, 1183 cricket::FeedbackParam(cricket::kRtcpFbParamNack,
1193 cricket::kParamValueEmpty)); 1184 cricket::kParamValueEmpty));
1194 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1185 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1195 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1186 EXPECT_TRUE(voe_.GetNACK(channel_num));
1196 1187
1197 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 1188 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
1198 channel_num = voe_.GetLastChannel(); 1189 channel_num = voe_.GetLastChannel();
1199 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1190 EXPECT_TRUE(voe_.GetNACK(channel_num));
1200 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 1191 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
1201 channel_num = voe_.GetLastChannel(); 1192 channel_num = voe_.GetLastChannel();
1202 EXPECT_TRUE(voe_.GetNACK(channel_num)); 1193 EXPECT_TRUE(voe_.GetNACK(channel_num));
1203 } 1194 }
1204 1195
1205 // Test that without useinbandfec, Opus FEC is off. 1196 // Test that without useinbandfec, Opus FEC is off.
1206 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) { 1197 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecNoOpusFec) {
1207 EXPECT_TRUE(SetupEngineWithSendStream()); 1198 EXPECT_TRUE(SetupSendStream());
1208 int channel_num = voe_.GetLastChannel(); 1199 int channel_num = voe_.GetLastChannel();
1209 cricket::AudioSendParameters parameters; 1200 cricket::AudioSendParameters parameters;
1210 parameters.codecs.push_back(kOpusCodec); 1201 parameters.codecs.push_back(kOpusCodec);
1211 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1202 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1212 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1203 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1213 } 1204 }
1214 1205
1215 // Test that with useinbandfec=0, Opus FEC is off. 1206 // Test that with useinbandfec=0, Opus FEC is off.
1216 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) { 1207 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusDisableFec) {
1217 EXPECT_TRUE(SetupEngineWithSendStream()); 1208 EXPECT_TRUE(SetupSendStream());
1218 int channel_num = voe_.GetLastChannel(); 1209 int channel_num = voe_.GetLastChannel();
1219 cricket::AudioSendParameters parameters; 1210 cricket::AudioSendParameters parameters;
1220 parameters.codecs.push_back(kOpusCodec); 1211 parameters.codecs.push_back(kOpusCodec);
1221 parameters.codecs[0].bitrate = 0; 1212 parameters.codecs[0].bitrate = 0;
1222 parameters.codecs[0].params["useinbandfec"] = "0"; 1213 parameters.codecs[0].params["useinbandfec"] = "0";
1223 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1214 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1224 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1215 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1225 webrtc::CodecInst gcodec; 1216 webrtc::CodecInst gcodec;
1226 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1217 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1227 EXPECT_STREQ("opus", gcodec.plname); 1218 EXPECT_STREQ("opus", gcodec.plname);
1228 EXPECT_EQ(1, gcodec.channels); 1219 EXPECT_EQ(1, gcodec.channels);
1229 EXPECT_EQ(32000, gcodec.rate); 1220 EXPECT_EQ(32000, gcodec.rate);
1230 } 1221 }
1231 1222
1232 // Test that with useinbandfec=1, Opus FEC is on. 1223 // Test that with useinbandfec=1, Opus FEC is on.
1233 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) { 1224 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFec) {
1234 EXPECT_TRUE(SetupEngineWithSendStream()); 1225 EXPECT_TRUE(SetupSendStream());
1235 int channel_num = voe_.GetLastChannel(); 1226 int channel_num = voe_.GetLastChannel();
1236 cricket::AudioSendParameters parameters; 1227 cricket::AudioSendParameters parameters;
1237 parameters.codecs.push_back(kOpusCodec); 1228 parameters.codecs.push_back(kOpusCodec);
1238 parameters.codecs[0].bitrate = 0; 1229 parameters.codecs[0].bitrate = 0;
1239 parameters.codecs[0].params["useinbandfec"] = "1"; 1230 parameters.codecs[0].params["useinbandfec"] = "1";
1240 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1231 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1241 EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); 1232 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1242 webrtc::CodecInst gcodec; 1233 webrtc::CodecInst gcodec;
1243 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1234 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1244 EXPECT_STREQ("opus", gcodec.plname); 1235 EXPECT_STREQ("opus", gcodec.plname);
1245 EXPECT_EQ(1, gcodec.channels); 1236 EXPECT_EQ(1, gcodec.channels);
1246 EXPECT_EQ(32000, gcodec.rate); 1237 EXPECT_EQ(32000, gcodec.rate);
1247 } 1238 }
1248 1239
1249 // Test that with useinbandfec=1, stereo=1, Opus FEC is on. 1240 // Test that with useinbandfec=1, stereo=1, Opus FEC is on.
1250 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) { 1241 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecOpusEnableFecStereo) {
1251 EXPECT_TRUE(SetupEngineWithSendStream()); 1242 EXPECT_TRUE(SetupSendStream());
1252 int channel_num = voe_.GetLastChannel(); 1243 int channel_num = voe_.GetLastChannel();
1253 cricket::AudioSendParameters parameters; 1244 cricket::AudioSendParameters parameters;
1254 parameters.codecs.push_back(kOpusCodec); 1245 parameters.codecs.push_back(kOpusCodec);
1255 parameters.codecs[0].bitrate = 0; 1246 parameters.codecs[0].bitrate = 0;
1256 parameters.codecs[0].params["stereo"] = "1"; 1247 parameters.codecs[0].params["stereo"] = "1";
1257 parameters.codecs[0].params["useinbandfec"] = "1"; 1248 parameters.codecs[0].params["useinbandfec"] = "1";
1258 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1249 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1259 EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); 1250 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1260 webrtc::CodecInst gcodec; 1251 webrtc::CodecInst gcodec;
1261 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1252 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1262 EXPECT_STREQ("opus", gcodec.plname); 1253 EXPECT_STREQ("opus", gcodec.plname);
1263 EXPECT_EQ(2, gcodec.channels); 1254 EXPECT_EQ(2, gcodec.channels);
1264 EXPECT_EQ(64000, gcodec.rate); 1255 EXPECT_EQ(64000, gcodec.rate);
1265 } 1256 }
1266 1257
1267 // Test that with non-Opus, codec FEC is off. 1258 // Test that with non-Opus, codec FEC is off.
1268 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) { 1259 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacNoFec) {
1269 EXPECT_TRUE(SetupEngineWithSendStream()); 1260 EXPECT_TRUE(SetupSendStream());
1270 int channel_num = voe_.GetLastChannel(); 1261 int channel_num = voe_.GetLastChannel();
1271 cricket::AudioSendParameters parameters; 1262 cricket::AudioSendParameters parameters;
1272 parameters.codecs.push_back(kIsacCodec); 1263 parameters.codecs.push_back(kIsacCodec);
1273 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1264 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1274 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1265 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1275 } 1266 }
1276 1267
1277 // Test the with non-Opus, even if useinbandfec=1, FEC is off. 1268 // Test the with non-Opus, even if useinbandfec=1, FEC is off.
1278 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) { 1269 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecIsacWithParamNoFec) {
1279 EXPECT_TRUE(SetupEngineWithSendStream()); 1270 EXPECT_TRUE(SetupSendStream());
1280 int channel_num = voe_.GetLastChannel(); 1271 int channel_num = voe_.GetLastChannel();
1281 cricket::AudioSendParameters parameters; 1272 cricket::AudioSendParameters parameters;
1282 parameters.codecs.push_back(kIsacCodec); 1273 parameters.codecs.push_back(kIsacCodec);
1283 parameters.codecs[0].params["useinbandfec"] = "1"; 1274 parameters.codecs[0].params["useinbandfec"] = "1";
1284 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1275 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1285 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1276 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1286 } 1277 }
1287 1278
1288 // Test that Opus FEC status can be changed. 1279 // Test that Opus FEC status can be changed.
1289 TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) { 1280 TEST_F(WebRtcVoiceEngineTestFake, ChangeOpusFecStatus) {
1290 EXPECT_TRUE(SetupEngineWithSendStream()); 1281 EXPECT_TRUE(SetupSendStream());
1291 int channel_num = voe_.GetLastChannel(); 1282 int channel_num = voe_.GetLastChannel();
1292 cricket::AudioSendParameters parameters; 1283 cricket::AudioSendParameters parameters;
1293 parameters.codecs.push_back(kOpusCodec); 1284 parameters.codecs.push_back(kOpusCodec);
1294 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1285 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1295 EXPECT_FALSE(voe_.GetCodecFEC(channel_num)); 1286 EXPECT_FALSE(voe_.GetCodecFEC(channel_num));
1296 parameters.codecs[0].params["useinbandfec"] = "1"; 1287 parameters.codecs[0].params["useinbandfec"] = "1";
1297 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1288 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1298 EXPECT_TRUE(voe_.GetCodecFEC(channel_num)); 1289 EXPECT_TRUE(voe_.GetCodecFEC(channel_num));
1299 } 1290 }
1300 1291
1301 TEST_F(WebRtcVoiceEngineTestFake, TransportCcCanBeEnabledAndDisabled) { 1292 TEST_F(WebRtcVoiceEngineTestFake, TransportCcCanBeEnabledAndDisabled) {
1302 EXPECT_TRUE(SetupEngine()); 1293 EXPECT_TRUE(SetupChannel());
1303 cricket::AudioSendParameters send_parameters; 1294 cricket::AudioSendParameters send_parameters;
1304 send_parameters.codecs.push_back(kOpusCodec); 1295 send_parameters.codecs.push_back(kOpusCodec);
1305 EXPECT_TRUE(send_parameters.codecs[0].feedback_params.params().empty()); 1296 EXPECT_TRUE(send_parameters.codecs[0].feedback_params.params().empty());
1306 EXPECT_TRUE(channel_->SetSendParameters(send_parameters)); 1297 EXPECT_TRUE(channel_->SetSendParameters(send_parameters));
1307 1298
1308 cricket::AudioRecvParameters recv_parameters; 1299 cricket::AudioRecvParameters recv_parameters;
1309 recv_parameters.codecs.push_back(kIsacCodec); 1300 recv_parameters.codecs.push_back(kIsacCodec);
1310 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters)); 1301 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters));
1311 EXPECT_TRUE( 1302 EXPECT_TRUE(
1312 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1))); 1303 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1)));
1313 ASSERT_TRUE(call_.GetAudioReceiveStream(kSsrc1) != nullptr); 1304 ASSERT_TRUE(call_.GetAudioReceiveStream(kSsrc1) != nullptr);
1314 EXPECT_FALSE( 1305 EXPECT_FALSE(
1315 call_.GetAudioReceiveStream(kSsrc1)->GetConfig().rtp.transport_cc); 1306 call_.GetAudioReceiveStream(kSsrc1)->GetConfig().rtp.transport_cc);
1316 1307
1317 send_parameters.codecs = engine_.codecs(); 1308 send_parameters.codecs = engine_.codecs();
1318 EXPECT_TRUE(channel_->SetSendParameters(send_parameters)); 1309 EXPECT_TRUE(channel_->SetSendParameters(send_parameters));
1319 ASSERT_TRUE(call_.GetAudioReceiveStream(kSsrc1) != nullptr); 1310 ASSERT_TRUE(call_.GetAudioReceiveStream(kSsrc1) != nullptr);
1320 EXPECT_TRUE( 1311 EXPECT_TRUE(
1321 call_.GetAudioReceiveStream(kSsrc1)->GetConfig().rtp.transport_cc); 1312 call_.GetAudioReceiveStream(kSsrc1)->GetConfig().rtp.transport_cc);
1322 } 1313 }
1323 1314
1324 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode. 1315 // Test maxplaybackrate <= 8000 triggers Opus narrow band mode.
1325 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) { 1316 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateNb) {
1326 EXPECT_TRUE(SetupEngineWithSendStream()); 1317 EXPECT_TRUE(SetupSendStream());
1327 int channel_num = voe_.GetLastChannel(); 1318 int channel_num = voe_.GetLastChannel();
1328 cricket::AudioSendParameters parameters; 1319 cricket::AudioSendParameters parameters;
1329 parameters.codecs.push_back(kOpusCodec); 1320 parameters.codecs.push_back(kOpusCodec);
1330 parameters.codecs[0].bitrate = 0; 1321 parameters.codecs[0].bitrate = 0;
1331 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000); 1322 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1332 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1323 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1333 EXPECT_EQ(cricket::kOpusBandwidthNb, 1324 EXPECT_EQ(cricket::kOpusBandwidthNb,
1334 voe_.GetMaxEncodingBandwidth(channel_num)); 1325 voe_.GetMaxEncodingBandwidth(channel_num));
1335 webrtc::CodecInst gcodec; 1326 webrtc::CodecInst gcodec;
1336 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1327 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1337 EXPECT_STREQ("opus", gcodec.plname); 1328 EXPECT_STREQ("opus", gcodec.plname);
1338 1329
1339 EXPECT_EQ(12000, gcodec.rate); 1330 EXPECT_EQ(12000, gcodec.rate);
1340 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1331 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1341 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1332 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1342 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1333 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1343 EXPECT_EQ(24000, gcodec.rate); 1334 EXPECT_EQ(24000, gcodec.rate);
1344 } 1335 }
1345 1336
1346 // Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode. 1337 // Test 8000 < maxplaybackrate <= 12000 triggers Opus medium band mode.
1347 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) { 1338 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateMb) {
1348 EXPECT_TRUE(SetupEngineWithSendStream()); 1339 EXPECT_TRUE(SetupSendStream());
1349 int channel_num = voe_.GetLastChannel(); 1340 int channel_num = voe_.GetLastChannel();
1350 cricket::AudioSendParameters parameters; 1341 cricket::AudioSendParameters parameters;
1351 parameters.codecs.push_back(kOpusCodec); 1342 parameters.codecs.push_back(kOpusCodec);
1352 parameters.codecs[0].bitrate = 0; 1343 parameters.codecs[0].bitrate = 0;
1353 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001); 1344 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8001);
1354 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1345 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1355 EXPECT_EQ(cricket::kOpusBandwidthMb, 1346 EXPECT_EQ(cricket::kOpusBandwidthMb,
1356 voe_.GetMaxEncodingBandwidth(channel_num)); 1347 voe_.GetMaxEncodingBandwidth(channel_num));
1357 webrtc::CodecInst gcodec; 1348 webrtc::CodecInst gcodec;
1358 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1349 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1359 EXPECT_STREQ("opus", gcodec.plname); 1350 EXPECT_STREQ("opus", gcodec.plname);
1360 1351
1361 EXPECT_EQ(20000, gcodec.rate); 1352 EXPECT_EQ(20000, gcodec.rate);
1362 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1353 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1363 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1354 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1364 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1355 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1365 EXPECT_EQ(40000, gcodec.rate); 1356 EXPECT_EQ(40000, gcodec.rate);
1366 } 1357 }
1367 1358
1368 // Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode. 1359 // Test 12000 < maxplaybackrate <= 16000 triggers Opus wide band mode.
1369 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) { 1360 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateWb) {
1370 EXPECT_TRUE(SetupEngineWithSendStream()); 1361 EXPECT_TRUE(SetupSendStream());
1371 int channel_num = voe_.GetLastChannel(); 1362 int channel_num = voe_.GetLastChannel();
1372 cricket::AudioSendParameters parameters; 1363 cricket::AudioSendParameters parameters;
1373 parameters.codecs.push_back(kOpusCodec); 1364 parameters.codecs.push_back(kOpusCodec);
1374 parameters.codecs[0].bitrate = 0; 1365 parameters.codecs[0].bitrate = 0;
1375 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001); 1366 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 12001);
1376 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1367 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1377 EXPECT_EQ(cricket::kOpusBandwidthWb, 1368 EXPECT_EQ(cricket::kOpusBandwidthWb,
1378 voe_.GetMaxEncodingBandwidth(channel_num)); 1369 voe_.GetMaxEncodingBandwidth(channel_num));
1379 webrtc::CodecInst gcodec; 1370 webrtc::CodecInst gcodec;
1380 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1371 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1381 EXPECT_STREQ("opus", gcodec.plname); 1372 EXPECT_STREQ("opus", gcodec.plname);
1382 1373
1383 EXPECT_EQ(20000, gcodec.rate); 1374 EXPECT_EQ(20000, gcodec.rate);
1384 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1375 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1385 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1376 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1386 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1377 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1387 EXPECT_EQ(40000, gcodec.rate); 1378 EXPECT_EQ(40000, gcodec.rate);
1388 } 1379 }
1389 1380
1390 // Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode. 1381 // Test 16000 < maxplaybackrate <= 24000 triggers Opus super wide band mode.
1391 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) { 1382 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateSwb) {
1392 EXPECT_TRUE(SetupEngineWithSendStream()); 1383 EXPECT_TRUE(SetupSendStream());
1393 int channel_num = voe_.GetLastChannel(); 1384 int channel_num = voe_.GetLastChannel();
1394 cricket::AudioSendParameters parameters; 1385 cricket::AudioSendParameters parameters;
1395 parameters.codecs.push_back(kOpusCodec); 1386 parameters.codecs.push_back(kOpusCodec);
1396 parameters.codecs[0].bitrate = 0; 1387 parameters.codecs[0].bitrate = 0;
1397 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001); 1388 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 16001);
1398 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1389 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1399 EXPECT_EQ(cricket::kOpusBandwidthSwb, 1390 EXPECT_EQ(cricket::kOpusBandwidthSwb,
1400 voe_.GetMaxEncodingBandwidth(channel_num)); 1391 voe_.GetMaxEncodingBandwidth(channel_num));
1401 webrtc::CodecInst gcodec; 1392 webrtc::CodecInst gcodec;
1402 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1393 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1403 EXPECT_STREQ("opus", gcodec.plname); 1394 EXPECT_STREQ("opus", gcodec.plname);
1404 1395
1405 EXPECT_EQ(32000, gcodec.rate); 1396 EXPECT_EQ(32000, gcodec.rate);
1406 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1397 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1407 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1398 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1408 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1399 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1409 EXPECT_EQ(64000, gcodec.rate); 1400 EXPECT_EQ(64000, gcodec.rate);
1410 } 1401 }
1411 1402
1412 // Test 24000 < maxplaybackrate triggers Opus full band mode. 1403 // Test 24000 < maxplaybackrate triggers Opus full band mode.
1413 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) { 1404 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateFb) {
1414 EXPECT_TRUE(SetupEngineWithSendStream()); 1405 EXPECT_TRUE(SetupSendStream());
1415 int channel_num = voe_.GetLastChannel(); 1406 int channel_num = voe_.GetLastChannel();
1416 cricket::AudioSendParameters parameters; 1407 cricket::AudioSendParameters parameters;
1417 parameters.codecs.push_back(kOpusCodec); 1408 parameters.codecs.push_back(kOpusCodec);
1418 parameters.codecs[0].bitrate = 0; 1409 parameters.codecs[0].bitrate = 0;
1419 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001); 1410 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 24001);
1420 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1411 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1421 EXPECT_EQ(cricket::kOpusBandwidthFb, 1412 EXPECT_EQ(cricket::kOpusBandwidthFb,
1422 voe_.GetMaxEncodingBandwidth(channel_num)); 1413 voe_.GetMaxEncodingBandwidth(channel_num));
1423 webrtc::CodecInst gcodec; 1414 webrtc::CodecInst gcodec;
1424 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1415 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1425 EXPECT_STREQ("opus", gcodec.plname); 1416 EXPECT_STREQ("opus", gcodec.plname);
1426 1417
1427 EXPECT_EQ(32000, gcodec.rate); 1418 EXPECT_EQ(32000, gcodec.rate);
1428 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1"); 1419 parameters.codecs[0].SetParam(cricket::kCodecParamStereo, "1");
1429 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1420 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1430 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1421 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1431 EXPECT_EQ(64000, gcodec.rate); 1422 EXPECT_EQ(64000, gcodec.rate);
1432 } 1423 }
1433 1424
1434 // Test Opus that without maxplaybackrate, default playback rate is used. 1425 // Test Opus that without maxplaybackrate, default playback rate is used.
1435 TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) { 1426 TEST_F(WebRtcVoiceEngineTestFake, DefaultOpusMaxPlaybackRate) {
1436 EXPECT_TRUE(SetupEngineWithSendStream()); 1427 EXPECT_TRUE(SetupSendStream());
1437 int channel_num = voe_.GetLastChannel(); 1428 int channel_num = voe_.GetLastChannel();
1438 cricket::AudioSendParameters parameters; 1429 cricket::AudioSendParameters parameters;
1439 parameters.codecs.push_back(kOpusCodec); 1430 parameters.codecs.push_back(kOpusCodec);
1440 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1431 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1441 EXPECT_EQ(cricket::kOpusBandwidthFb, 1432 EXPECT_EQ(cricket::kOpusBandwidthFb,
1442 voe_.GetMaxEncodingBandwidth(channel_num)); 1433 voe_.GetMaxEncodingBandwidth(channel_num));
1443 } 1434 }
1444 1435
1445 // Test the with non-Opus, maxplaybackrate has no effect. 1436 // Test the with non-Opus, maxplaybackrate has no effect.
1446 TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) { 1437 TEST_F(WebRtcVoiceEngineTestFake, SetNonOpusMaxPlaybackRate) {
1447 EXPECT_TRUE(SetupEngineWithSendStream()); 1438 EXPECT_TRUE(SetupSendStream());
1448 int channel_num = voe_.GetLastChannel(); 1439 int channel_num = voe_.GetLastChannel();
1449 cricket::AudioSendParameters parameters; 1440 cricket::AudioSendParameters parameters;
1450 parameters.codecs.push_back(kIsacCodec); 1441 parameters.codecs.push_back(kIsacCodec);
1451 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000); 1442 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 32000);
1452 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1443 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1453 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num)); 1444 EXPECT_EQ(0, voe_.GetMaxEncodingBandwidth(channel_num));
1454 } 1445 }
1455 1446
1456 // Test maxplaybackrate can be set on two streams. 1447 // Test maxplaybackrate can be set on two streams.
1457 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) { 1448 TEST_F(WebRtcVoiceEngineTestFake, SetOpusMaxPlaybackRateOnTwoStreams) {
1458 EXPECT_TRUE(SetupEngineWithSendStream()); 1449 EXPECT_TRUE(SetupSendStream());
1459 int channel_num = voe_.GetLastChannel(); 1450 int channel_num = voe_.GetLastChannel();
1460 cricket::AudioSendParameters parameters; 1451 cricket::AudioSendParameters parameters;
1461 parameters.codecs.push_back(kOpusCodec); 1452 parameters.codecs.push_back(kOpusCodec);
1462 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1453 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1463 // Default bandwidth is 24000. 1454 // Default bandwidth is 24000.
1464 EXPECT_EQ(cricket::kOpusBandwidthFb, 1455 EXPECT_EQ(cricket::kOpusBandwidthFb,
1465 voe_.GetMaxEncodingBandwidth(channel_num)); 1456 voe_.GetMaxEncodingBandwidth(channel_num));
1466 1457
1467 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000); 1458 parameters.codecs[0].SetParam(cricket::kCodecParamMaxPlaybackRate, 8000);
1468 1459
1469 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1460 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1470 EXPECT_EQ(cricket::kOpusBandwidthNb, 1461 EXPECT_EQ(cricket::kOpusBandwidthNb,
1471 voe_.GetMaxEncodingBandwidth(channel_num)); 1462 voe_.GetMaxEncodingBandwidth(channel_num));
1472 1463
1473 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2)); 1464 channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc2));
1474 channel_num = voe_.GetLastChannel(); 1465 channel_num = voe_.GetLastChannel();
1475 EXPECT_EQ(cricket::kOpusBandwidthNb, 1466 EXPECT_EQ(cricket::kOpusBandwidthNb,
1476 voe_.GetMaxEncodingBandwidth(channel_num)); 1467 voe_.GetMaxEncodingBandwidth(channel_num));
1477 } 1468 }
1478 1469
1479 // Test that with usedtx=0, Opus DTX is off. 1470 // Test that with usedtx=0, Opus DTX is off.
1480 TEST_F(WebRtcVoiceEngineTestFake, DisableOpusDtxOnOpus) { 1471 TEST_F(WebRtcVoiceEngineTestFake, DisableOpusDtxOnOpus) {
1481 EXPECT_TRUE(SetupEngineWithSendStream()); 1472 EXPECT_TRUE(SetupSendStream());
1482 int channel_num = voe_.GetLastChannel(); 1473 int channel_num = voe_.GetLastChannel();
1483 cricket::AudioSendParameters parameters; 1474 cricket::AudioSendParameters parameters;
1484 parameters.codecs.push_back(kOpusCodec); 1475 parameters.codecs.push_back(kOpusCodec);
1485 parameters.codecs[0].params["usedtx"] = "0"; 1476 parameters.codecs[0].params["usedtx"] = "0";
1486 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1477 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1487 EXPECT_FALSE(voe_.GetOpusDtx(channel_num)); 1478 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1488 } 1479 }
1489 1480
1490 // Test that with usedtx=1, Opus DTX is on. 1481 // Test that with usedtx=1, Opus DTX is on.
1491 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpus) { 1482 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpus) {
1492 EXPECT_TRUE(SetupEngineWithSendStream()); 1483 EXPECT_TRUE(SetupSendStream());
1493 int channel_num = voe_.GetLastChannel(); 1484 int channel_num = voe_.GetLastChannel();
1494 cricket::AudioSendParameters parameters; 1485 cricket::AudioSendParameters parameters;
1495 parameters.codecs.push_back(kOpusCodec); 1486 parameters.codecs.push_back(kOpusCodec);
1496 parameters.codecs[0].params["usedtx"] = "1"; 1487 parameters.codecs[0].params["usedtx"] = "1";
1497 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1488 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1498 EXPECT_TRUE(voe_.GetOpusDtx(channel_num)); 1489 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1499 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD. 1490 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1500 } 1491 }
1501 1492
1502 // Test that usedtx=1 works with stereo Opus. 1493 // Test that usedtx=1 works with stereo Opus.
1503 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpusStereo) { 1494 TEST_F(WebRtcVoiceEngineTestFake, EnableOpusDtxOnOpusStereo) {
1504 EXPECT_TRUE(SetupEngineWithSendStream()); 1495 EXPECT_TRUE(SetupSendStream());
1505 int channel_num = voe_.GetLastChannel(); 1496 int channel_num = voe_.GetLastChannel();
1506 cricket::AudioSendParameters parameters; 1497 cricket::AudioSendParameters parameters;
1507 parameters.codecs.push_back(kOpusCodec); 1498 parameters.codecs.push_back(kOpusCodec);
1508 parameters.codecs[0].params["usedtx"] = "1"; 1499 parameters.codecs[0].params["usedtx"] = "1";
1509 parameters.codecs[0].params["stereo"] = "1"; 1500 parameters.codecs[0].params["stereo"] = "1";
1510 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1501 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1511 EXPECT_TRUE(voe_.GetOpusDtx(channel_num)); 1502 EXPECT_TRUE(voe_.GetOpusDtx(channel_num));
1512 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD. 1503 EXPECT_FALSE(voe_.GetVAD(channel_num)); // Opus DTX should not affect VAD.
1513 } 1504 }
1514 1505
1515 // Test that usedtx=1 does not work with non Opus. 1506 // Test that usedtx=1 does not work with non Opus.
1516 TEST_F(WebRtcVoiceEngineTestFake, CannotEnableOpusDtxOnNonOpus) { 1507 TEST_F(WebRtcVoiceEngineTestFake, CannotEnableOpusDtxOnNonOpus) {
1517 EXPECT_TRUE(SetupEngineWithSendStream()); 1508 EXPECT_TRUE(SetupSendStream());
1518 int channel_num = voe_.GetLastChannel(); 1509 int channel_num = voe_.GetLastChannel();
1519 cricket::AudioSendParameters parameters; 1510 cricket::AudioSendParameters parameters;
1520 parameters.codecs.push_back(kIsacCodec); 1511 parameters.codecs.push_back(kIsacCodec);
1521 parameters.codecs[0].params["usedtx"] = "1"; 1512 parameters.codecs[0].params["usedtx"] = "1";
1522 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1513 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1523 EXPECT_FALSE(voe_.GetOpusDtx(channel_num)); 1514 EXPECT_FALSE(voe_.GetOpusDtx(channel_num));
1524 } 1515 }
1525 1516
1526 // Test that we can switch back and forth between Opus and ISAC with CN. 1517 // Test that we can switch back and forth between Opus and ISAC with CN.
1527 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) { 1518 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsIsacOpusSwitching) {
1528 EXPECT_TRUE(SetupEngineWithSendStream()); 1519 EXPECT_TRUE(SetupSendStream());
1529 int channel_num = voe_.GetLastChannel(); 1520 int channel_num = voe_.GetLastChannel();
1530 cricket::AudioSendParameters opus_parameters; 1521 cricket::AudioSendParameters opus_parameters;
1531 opus_parameters.codecs.push_back(kOpusCodec); 1522 opus_parameters.codecs.push_back(kOpusCodec);
1532 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters)); 1523 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters));
1533 webrtc::CodecInst gcodec; 1524 webrtc::CodecInst gcodec;
1534 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1525 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1535 EXPECT_EQ(111, gcodec.pltype); 1526 EXPECT_EQ(111, gcodec.pltype);
1536 EXPECT_STREQ("opus", gcodec.plname); 1527 EXPECT_STREQ("opus", gcodec.plname);
1537 1528
1538 cricket::AudioSendParameters isac_parameters; 1529 cricket::AudioSendParameters isac_parameters;
1539 isac_parameters.codecs.push_back(kIsacCodec); 1530 isac_parameters.codecs.push_back(kIsacCodec);
1540 isac_parameters.codecs.push_back(kCn16000Codec); 1531 isac_parameters.codecs.push_back(kCn16000Codec);
1541 isac_parameters.codecs.push_back(kOpusCodec); 1532 isac_parameters.codecs.push_back(kOpusCodec);
1542 EXPECT_TRUE(channel_->SetSendParameters(isac_parameters)); 1533 EXPECT_TRUE(channel_->SetSendParameters(isac_parameters));
1543 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1534 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1544 EXPECT_EQ(103, gcodec.pltype); 1535 EXPECT_EQ(103, gcodec.pltype);
1545 EXPECT_STREQ("ISAC", gcodec.plname); 1536 EXPECT_STREQ("ISAC", gcodec.plname);
1546 1537
1547 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters)); 1538 EXPECT_TRUE(channel_->SetSendParameters(opus_parameters));
1548 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1539 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1549 EXPECT_EQ(111, gcodec.pltype); 1540 EXPECT_EQ(111, gcodec.pltype);
1550 EXPECT_STREQ("opus", gcodec.plname); 1541 EXPECT_STREQ("opus", gcodec.plname);
1551 } 1542 }
1552 1543
1553 // Test that we handle various ways of specifying bitrate. 1544 // Test that we handle various ways of specifying bitrate.
1554 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) { 1545 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBitrate) {
1555 EXPECT_TRUE(SetupEngineWithSendStream()); 1546 EXPECT_TRUE(SetupSendStream());
1556 int channel_num = voe_.GetLastChannel(); 1547 int channel_num = voe_.GetLastChannel();
1557 cricket::AudioSendParameters parameters; 1548 cricket::AudioSendParameters parameters;
1558 parameters.codecs.push_back(kIsacCodec); // bitrate == 32000 1549 parameters.codecs.push_back(kIsacCodec); // bitrate == 32000
1559 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1550 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1560 webrtc::CodecInst gcodec; 1551 webrtc::CodecInst gcodec;
1561 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1552 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1562 EXPECT_EQ(103, gcodec.pltype); 1553 EXPECT_EQ(103, gcodec.pltype);
1563 EXPECT_STREQ("ISAC", gcodec.plname); 1554 EXPECT_STREQ("ISAC", gcodec.plname);
1564 EXPECT_EQ(32000, gcodec.rate); 1555 EXPECT_EQ(32000, gcodec.rate);
1565 1556
(...skipping 29 matching lines...) Expand all
1595 parameters.codecs[0].bitrate = 0; // bitrate == default 1586 parameters.codecs[0].bitrate = 0; // bitrate == default
1596 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1587 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1597 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1588 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1598 EXPECT_EQ(111, gcodec.pltype); 1589 EXPECT_EQ(111, gcodec.pltype);
1599 EXPECT_STREQ("opus", gcodec.plname); 1590 EXPECT_STREQ("opus", gcodec.plname);
1600 EXPECT_EQ(32000, gcodec.rate); 1591 EXPECT_EQ(32000, gcodec.rate);
1601 } 1592 }
1602 1593
1603 // Test that we could set packet size specified in kCodecParamPTime. 1594 // Test that we could set packet size specified in kCodecParamPTime.
1604 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) { 1595 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsPTimeAsPacketSize) {
1605 EXPECT_TRUE(SetupEngineWithSendStream()); 1596 EXPECT_TRUE(SetupSendStream());
1606 int channel_num = voe_.GetLastChannel(); 1597 int channel_num = voe_.GetLastChannel();
1607 cricket::AudioSendParameters parameters; 1598 cricket::AudioSendParameters parameters;
1608 parameters.codecs.push_back(kOpusCodec); 1599 parameters.codecs.push_back(kOpusCodec);
1609 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Within range. 1600 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40); // Within range.
1610 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1601 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1611 webrtc::CodecInst gcodec; 1602 webrtc::CodecInst gcodec;
1612 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1603 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1613 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms. 1604 EXPECT_EQ(1920, gcodec.pacsize); // Opus gets 40ms.
1614 1605
1615 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Below range. 1606 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 5); // Below range.
(...skipping 14 matching lines...) Expand all
1630 1621
1631 parameters.codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP. 1622 parameters.codecs[0] = kG722CodecSdp; // Try G722 @8kHz as negotiated in SDP.
1632 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40); 1623 parameters.codecs[0].SetParam(cricket::kCodecParamPTime, 40);
1633 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1624 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1634 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1625 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1635 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE. 1626 EXPECT_EQ(640, gcodec.pacsize); // G722 gets 40ms @16kHz as defined in VoE.
1636 } 1627 }
1637 1628
1638 // Test that we fail if no codecs are specified. 1629 // Test that we fail if no codecs are specified.
1639 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) { 1630 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsNoCodecs) {
1640 EXPECT_TRUE(SetupEngineWithSendStream()); 1631 EXPECT_TRUE(SetupSendStream());
1641 cricket::AudioSendParameters parameters; 1632 cricket::AudioSendParameters parameters;
1642 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 1633 EXPECT_FALSE(channel_->SetSendParameters(parameters));
1643 } 1634 }
1644 1635
1645 // Test that we can set send codecs even with telephone-event codec as the first 1636 // Test that we can set send codecs even with telephone-event codec as the first
1646 // one on the list. 1637 // one on the list.
1647 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) { 1638 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFOnTop) {
1648 EXPECT_TRUE(SetupEngineWithSendStream()); 1639 EXPECT_TRUE(SetupSendStream());
1649 int channel_num = voe_.GetLastChannel(); 1640 int channel_num = voe_.GetLastChannel();
1650 cricket::AudioSendParameters parameters; 1641 cricket::AudioSendParameters parameters;
1651 parameters.codecs.push_back(kTelephoneEventCodec); 1642 parameters.codecs.push_back(kTelephoneEventCodec);
1652 parameters.codecs.push_back(kIsacCodec); 1643 parameters.codecs.push_back(kIsacCodec);
1653 parameters.codecs.push_back(kPcmuCodec); 1644 parameters.codecs.push_back(kPcmuCodec);
1654 parameters.codecs[0].id = 98; // DTMF 1645 parameters.codecs[0].id = 98; // DTMF
1655 parameters.codecs[1].id = 96; 1646 parameters.codecs[1].id = 96;
1656 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1647 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1657 webrtc::CodecInst gcodec; 1648 webrtc::CodecInst gcodec;
1658 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1649 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1659 EXPECT_EQ(96, gcodec.pltype); 1650 EXPECT_EQ(96, gcodec.pltype);
1660 EXPECT_STREQ("ISAC", gcodec.plname); 1651 EXPECT_STREQ("ISAC", gcodec.plname);
1661 EXPECT_TRUE(channel_->CanInsertDtmf()); 1652 EXPECT_TRUE(channel_->CanInsertDtmf());
1662 } 1653 }
1663 1654
1664 // Test that payload type range is limited for telephone-event codec. 1655 // Test that payload type range is limited for telephone-event codec.
1665 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFPayloadTypeOutOfRange) { 1656 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsDTMFPayloadTypeOutOfRange) {
1666 EXPECT_TRUE(SetupEngineWithSendStream()); 1657 EXPECT_TRUE(SetupSendStream());
1667 cricket::AudioSendParameters parameters; 1658 cricket::AudioSendParameters parameters;
1668 parameters.codecs.push_back(kTelephoneEventCodec); 1659 parameters.codecs.push_back(kTelephoneEventCodec);
1669 parameters.codecs.push_back(kIsacCodec); 1660 parameters.codecs.push_back(kIsacCodec);
1670 parameters.codecs[0].id = 0; // DTMF 1661 parameters.codecs[0].id = 0; // DTMF
1671 parameters.codecs[1].id = 96; 1662 parameters.codecs[1].id = 96;
1672 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1663 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1673 EXPECT_TRUE(channel_->CanInsertDtmf()); 1664 EXPECT_TRUE(channel_->CanInsertDtmf());
1674 parameters.codecs[0].id = 128; // DTMF 1665 parameters.codecs[0].id = 128; // DTMF
1675 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 1666 EXPECT_FALSE(channel_->SetSendParameters(parameters));
1676 EXPECT_FALSE(channel_->CanInsertDtmf()); 1667 EXPECT_FALSE(channel_->CanInsertDtmf());
1677 parameters.codecs[0].id = 127; 1668 parameters.codecs[0].id = 127;
1678 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1669 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1679 EXPECT_TRUE(channel_->CanInsertDtmf()); 1670 EXPECT_TRUE(channel_->CanInsertDtmf());
1680 parameters.codecs[0].id = -1; // DTMF 1671 parameters.codecs[0].id = -1; // DTMF
1681 EXPECT_FALSE(channel_->SetSendParameters(parameters)); 1672 EXPECT_FALSE(channel_->SetSendParameters(parameters));
1682 EXPECT_FALSE(channel_->CanInsertDtmf()); 1673 EXPECT_FALSE(channel_->CanInsertDtmf());
1683 } 1674 }
1684 1675
1685 // Test that we can set send codecs even with CN codec as the first 1676 // Test that we can set send codecs even with CN codec as the first
1686 // one on the list. 1677 // one on the list.
1687 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) { 1678 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNOnTop) {
1688 EXPECT_TRUE(SetupEngineWithSendStream()); 1679 EXPECT_TRUE(SetupSendStream());
1689 int channel_num = voe_.GetLastChannel(); 1680 int channel_num = voe_.GetLastChannel();
1690 cricket::AudioSendParameters parameters; 1681 cricket::AudioSendParameters parameters;
1691 parameters.codecs.push_back(kCn16000Codec); 1682 parameters.codecs.push_back(kCn16000Codec);
1692 parameters.codecs.push_back(kIsacCodec); 1683 parameters.codecs.push_back(kIsacCodec);
1693 parameters.codecs.push_back(kPcmuCodec); 1684 parameters.codecs.push_back(kPcmuCodec);
1694 parameters.codecs[0].id = 98; // wideband CN 1685 parameters.codecs[0].id = 98; // wideband CN
1695 parameters.codecs[1].id = 96; 1686 parameters.codecs[1].id = 96;
1696 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1687 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1697 webrtc::CodecInst gcodec; 1688 webrtc::CodecInst gcodec;
1698 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1689 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1699 EXPECT_EQ(96, gcodec.pltype); 1690 EXPECT_EQ(96, gcodec.pltype);
1700 EXPECT_STREQ("ISAC", gcodec.plname); 1691 EXPECT_STREQ("ISAC", gcodec.plname);
1701 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true)); 1692 EXPECT_EQ(98, voe_.GetSendCNPayloadType(channel_num, true));
1702 } 1693 }
1703 1694
1704 // Test that we set VAD and DTMF types correctly as caller. 1695 // Test that we set VAD and DTMF types correctly as caller.
1705 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) { 1696 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCaller) {
1706 EXPECT_TRUE(SetupEngineWithSendStream()); 1697 EXPECT_TRUE(SetupSendStream());
1707 int channel_num = voe_.GetLastChannel(); 1698 int channel_num = voe_.GetLastChannel();
1708 cricket::AudioSendParameters parameters; 1699 cricket::AudioSendParameters parameters;
1709 parameters.codecs.push_back(kIsacCodec); 1700 parameters.codecs.push_back(kIsacCodec);
1710 parameters.codecs.push_back(kPcmuCodec); 1701 parameters.codecs.push_back(kPcmuCodec);
1711 // TODO(juberti): cn 32000 1702 // TODO(juberti): cn 32000
1712 parameters.codecs.push_back(kCn16000Codec); 1703 parameters.codecs.push_back(kCn16000Codec);
1713 parameters.codecs.push_back(kCn8000Codec); 1704 parameters.codecs.push_back(kCn8000Codec);
1714 parameters.codecs.push_back(kTelephoneEventCodec); 1705 parameters.codecs.push_back(kTelephoneEventCodec);
1715 parameters.codecs.push_back(kRedCodec); 1706 parameters.codecs.push_back(kRedCodec);
1716 parameters.codecs[0].id = 96; 1707 parameters.codecs[0].id = 96;
1717 parameters.codecs[2].id = 97; // wideband CN 1708 parameters.codecs[2].id = 97; // wideband CN
1718 parameters.codecs[4].id = 98; // DTMF 1709 parameters.codecs[4].id = 98; // DTMF
1719 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1710 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1720 webrtc::CodecInst gcodec; 1711 webrtc::CodecInst gcodec;
1721 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1712 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1722 EXPECT_EQ(96, gcodec.pltype); 1713 EXPECT_EQ(96, gcodec.pltype);
1723 EXPECT_STREQ("ISAC", gcodec.plname); 1714 EXPECT_STREQ("ISAC", gcodec.plname);
1724 EXPECT_TRUE(voe_.GetVAD(channel_num)); 1715 EXPECT_TRUE(voe_.GetVAD(channel_num));
1725 EXPECT_FALSE(voe_.GetRED(channel_num)); 1716 EXPECT_FALSE(voe_.GetRED(channel_num));
1726 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); 1717 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1727 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); 1718 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1728 EXPECT_TRUE(channel_->CanInsertDtmf()); 1719 EXPECT_TRUE(channel_->CanInsertDtmf());
1729 } 1720 }
1730 1721
1731 // Test that we set VAD and DTMF types correctly as callee. 1722 // Test that we set VAD and DTMF types correctly as callee.
1732 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) { 1723 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNandDTMFAsCallee) {
1733 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 1724 EXPECT_TRUE(SetupChannel());
1734 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(),
1735 cricket::AudioOptions());
1736 EXPECT_TRUE(channel_ != nullptr);
1737
1738 cricket::AudioSendParameters parameters; 1725 cricket::AudioSendParameters parameters;
1739 parameters.codecs.push_back(kIsacCodec); 1726 parameters.codecs.push_back(kIsacCodec);
1740 parameters.codecs.push_back(kPcmuCodec); 1727 parameters.codecs.push_back(kPcmuCodec);
1741 // TODO(juberti): cn 32000 1728 // TODO(juberti): cn 32000
1742 parameters.codecs.push_back(kCn16000Codec); 1729 parameters.codecs.push_back(kCn16000Codec);
1743 parameters.codecs.push_back(kCn8000Codec); 1730 parameters.codecs.push_back(kCn8000Codec);
1744 parameters.codecs.push_back(kTelephoneEventCodec); 1731 parameters.codecs.push_back(kTelephoneEventCodec);
1745 parameters.codecs.push_back(kRedCodec); 1732 parameters.codecs.push_back(kRedCodec);
1746 parameters.codecs[0].id = 96; 1733 parameters.codecs[0].id = 96;
1747 parameters.codecs[2].id = 97; // wideband CN 1734 parameters.codecs[2].id = 97; // wideband CN
(...skipping 10 matching lines...) Expand all
1758 EXPECT_TRUE(voe_.GetVAD(channel_num)); 1745 EXPECT_TRUE(voe_.GetVAD(channel_num));
1759 EXPECT_FALSE(voe_.GetRED(channel_num)); 1746 EXPECT_FALSE(voe_.GetRED(channel_num));
1760 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); 1747 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1761 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); 1748 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1762 EXPECT_TRUE(channel_->CanInsertDtmf()); 1749 EXPECT_TRUE(channel_->CanInsertDtmf());
1763 } 1750 }
1764 1751
1765 // Test that we only apply VAD if we have a CN codec that matches the 1752 // Test that we only apply VAD if we have a CN codec that matches the
1766 // send codec clockrate. 1753 // send codec clockrate.
1767 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) { 1754 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCNNoMatch) {
1768 EXPECT_TRUE(SetupEngineWithSendStream()); 1755 EXPECT_TRUE(SetupSendStream());
1769 int channel_num = voe_.GetLastChannel(); 1756 int channel_num = voe_.GetLastChannel();
1770 cricket::AudioSendParameters parameters; 1757 cricket::AudioSendParameters parameters;
1771 // Set ISAC(16K) and CN(16K). VAD should be activated. 1758 // Set ISAC(16K) and CN(16K). VAD should be activated.
1772 parameters.codecs.push_back(kIsacCodec); 1759 parameters.codecs.push_back(kIsacCodec);
1773 parameters.codecs.push_back(kCn16000Codec); 1760 parameters.codecs.push_back(kCn16000Codec);
1774 parameters.codecs[1].id = 97; 1761 parameters.codecs[1].id = 97;
1775 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1762 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1776 webrtc::CodecInst gcodec; 1763 webrtc::CodecInst gcodec;
1777 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1764 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1778 EXPECT_STREQ("ISAC", gcodec.plname); 1765 EXPECT_STREQ("ISAC", gcodec.plname);
(...skipping 15 matching lines...) Expand all
1794 // Set ISAC(16K) and CN(8K). VAD should not be activated. 1781 // Set ISAC(16K) and CN(8K). VAD should not be activated.
1795 parameters.codecs[0] = kIsacCodec; 1782 parameters.codecs[0] = kIsacCodec;
1796 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1783 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1797 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1784 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1798 EXPECT_STREQ("ISAC", gcodec.plname); 1785 EXPECT_STREQ("ISAC", gcodec.plname);
1799 EXPECT_FALSE(voe_.GetVAD(channel_num)); 1786 EXPECT_FALSE(voe_.GetVAD(channel_num));
1800 } 1787 }
1801 1788
1802 // Test that we perform case-insensitive matching of codec names. 1789 // Test that we perform case-insensitive matching of codec names.
1803 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) { 1790 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsCaseInsensitive) {
1804 EXPECT_TRUE(SetupEngineWithSendStream()); 1791 EXPECT_TRUE(SetupSendStream());
1805 int channel_num = voe_.GetLastChannel(); 1792 int channel_num = voe_.GetLastChannel();
1806 cricket::AudioSendParameters parameters; 1793 cricket::AudioSendParameters parameters;
1807 parameters.codecs.push_back(kIsacCodec); 1794 parameters.codecs.push_back(kIsacCodec);
1808 parameters.codecs.push_back(kPcmuCodec); 1795 parameters.codecs.push_back(kPcmuCodec);
1809 parameters.codecs.push_back(kCn16000Codec); 1796 parameters.codecs.push_back(kCn16000Codec);
1810 parameters.codecs.push_back(kCn8000Codec); 1797 parameters.codecs.push_back(kCn8000Codec);
1811 parameters.codecs.push_back(kTelephoneEventCodec); 1798 parameters.codecs.push_back(kTelephoneEventCodec);
1812 parameters.codecs.push_back(kRedCodec); 1799 parameters.codecs.push_back(kRedCodec);
1813 parameters.codecs[0].name = "iSaC"; 1800 parameters.codecs[0].name = "iSaC";
1814 parameters.codecs[0].id = 96; 1801 parameters.codecs[0].id = 96;
1815 parameters.codecs[2].id = 97; // wideband CN 1802 parameters.codecs[2].id = 97; // wideband CN
1816 parameters.codecs[4].id = 98; // DTMF 1803 parameters.codecs[4].id = 98; // DTMF
1817 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1804 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1818 webrtc::CodecInst gcodec; 1805 webrtc::CodecInst gcodec;
1819 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1806 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1820 EXPECT_EQ(96, gcodec.pltype); 1807 EXPECT_EQ(96, gcodec.pltype);
1821 EXPECT_STREQ("ISAC", gcodec.plname); 1808 EXPECT_STREQ("ISAC", gcodec.plname);
1822 EXPECT_TRUE(voe_.GetVAD(channel_num)); 1809 EXPECT_TRUE(voe_.GetVAD(channel_num));
1823 EXPECT_FALSE(voe_.GetRED(channel_num)); 1810 EXPECT_FALSE(voe_.GetRED(channel_num));
1824 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false)); 1811 EXPECT_EQ(13, voe_.GetSendCNPayloadType(channel_num, false));
1825 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true)); 1812 EXPECT_EQ(97, voe_.GetSendCNPayloadType(channel_num, true));
1826 EXPECT_TRUE(channel_->CanInsertDtmf()); 1813 EXPECT_TRUE(channel_->CanInsertDtmf());
1827 } 1814 }
1828 1815
1829 // Test that we set up RED correctly as caller. 1816 // Test that we set up RED correctly as caller.
1830 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) { 1817 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCaller) {
1831 EXPECT_TRUE(SetupEngineWithSendStream()); 1818 EXPECT_TRUE(SetupSendStream());
1832 int channel_num = voe_.GetLastChannel(); 1819 int channel_num = voe_.GetLastChannel();
1833 cricket::AudioSendParameters parameters; 1820 cricket::AudioSendParameters parameters;
1834 parameters.codecs.push_back(kRedCodec); 1821 parameters.codecs.push_back(kRedCodec);
1835 parameters.codecs.push_back(kIsacCodec); 1822 parameters.codecs.push_back(kIsacCodec);
1836 parameters.codecs.push_back(kPcmuCodec); 1823 parameters.codecs.push_back(kPcmuCodec);
1837 parameters.codecs[0].id = 127; 1824 parameters.codecs[0].id = 127;
1838 parameters.codecs[0].params[""] = "96/96"; 1825 parameters.codecs[0].params[""] = "96/96";
1839 parameters.codecs[1].id = 96; 1826 parameters.codecs[1].id = 96;
1840 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1827 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1841 webrtc::CodecInst gcodec; 1828 webrtc::CodecInst gcodec;
1842 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1829 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1843 EXPECT_EQ(96, gcodec.pltype); 1830 EXPECT_EQ(96, gcodec.pltype);
1844 EXPECT_STREQ("ISAC", gcodec.plname); 1831 EXPECT_STREQ("ISAC", gcodec.plname);
1845 EXPECT_TRUE(voe_.GetRED(channel_num)); 1832 EXPECT_TRUE(voe_.GetRED(channel_num));
1846 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); 1833 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
1847 } 1834 }
1848 1835
1849 // Test that we set up RED correctly as callee. 1836 // Test that we set up RED correctly as callee.
1850 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) { 1837 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDAsCallee) {
1851 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 1838 EXPECT_TRUE(SetupChannel());
1852 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(),
1853 cricket::AudioOptions());
1854 EXPECT_TRUE(channel_ != nullptr);
1855
1856 cricket::AudioSendParameters parameters; 1839 cricket::AudioSendParameters parameters;
1857 parameters.codecs.push_back(kRedCodec); 1840 parameters.codecs.push_back(kRedCodec);
1858 parameters.codecs.push_back(kIsacCodec); 1841 parameters.codecs.push_back(kIsacCodec);
1859 parameters.codecs.push_back(kPcmuCodec); 1842 parameters.codecs.push_back(kPcmuCodec);
1860 parameters.codecs[0].id = 127; 1843 parameters.codecs[0].id = 127;
1861 parameters.codecs[0].params[""] = "96/96"; 1844 parameters.codecs[0].params[""] = "96/96";
1862 parameters.codecs[1].id = 96; 1845 parameters.codecs[1].id = 96;
1863 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1846 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1864 EXPECT_TRUE(channel_->AddSendStream( 1847 EXPECT_TRUE(channel_->AddSendStream(
1865 cricket::StreamParams::CreateLegacy(kSsrc1))); 1848 cricket::StreamParams::CreateLegacy(kSsrc1)));
1866 int channel_num = voe_.GetLastChannel(); 1849 int channel_num = voe_.GetLastChannel();
1867 webrtc::CodecInst gcodec; 1850 webrtc::CodecInst gcodec;
1868 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1851 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1869 EXPECT_EQ(96, gcodec.pltype); 1852 EXPECT_EQ(96, gcodec.pltype);
1870 EXPECT_STREQ("ISAC", gcodec.plname); 1853 EXPECT_STREQ("ISAC", gcodec.plname);
1871 EXPECT_TRUE(voe_.GetRED(channel_num)); 1854 EXPECT_TRUE(voe_.GetRED(channel_num));
1872 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); 1855 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
1873 } 1856 }
1874 1857
1875 // Test that we set up RED correctly if params are omitted. 1858 // Test that we set up RED correctly if params are omitted.
1876 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) { 1859 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsREDNoParams) {
1877 EXPECT_TRUE(SetupEngineWithSendStream()); 1860 EXPECT_TRUE(SetupSendStream());
1878 int channel_num = voe_.GetLastChannel(); 1861 int channel_num = voe_.GetLastChannel();
1879 cricket::AudioSendParameters parameters; 1862 cricket::AudioSendParameters parameters;
1880 parameters.codecs.push_back(kRedCodec); 1863 parameters.codecs.push_back(kRedCodec);
1881 parameters.codecs.push_back(kIsacCodec); 1864 parameters.codecs.push_back(kIsacCodec);
1882 parameters.codecs.push_back(kPcmuCodec); 1865 parameters.codecs.push_back(kPcmuCodec);
1883 parameters.codecs[0].id = 127; 1866 parameters.codecs[0].id = 127;
1884 parameters.codecs[1].id = 96; 1867 parameters.codecs[1].id = 96;
1885 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1868 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1886 webrtc::CodecInst gcodec; 1869 webrtc::CodecInst gcodec;
1887 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1870 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1888 EXPECT_EQ(96, gcodec.pltype); 1871 EXPECT_EQ(96, gcodec.pltype);
1889 EXPECT_STREQ("ISAC", gcodec.plname); 1872 EXPECT_STREQ("ISAC", gcodec.plname);
1890 EXPECT_TRUE(voe_.GetRED(channel_num)); 1873 EXPECT_TRUE(voe_.GetRED(channel_num));
1891 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num)); 1874 EXPECT_EQ(127, voe_.GetSendREDPayloadType(channel_num));
1892 } 1875 }
1893 1876
1894 // Test that we ignore RED if the parameters aren't named the way we expect. 1877 // Test that we ignore RED if the parameters aren't named the way we expect.
1895 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) { 1878 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED1) {
1896 EXPECT_TRUE(SetupEngineWithSendStream()); 1879 EXPECT_TRUE(SetupSendStream());
1897 int channel_num = voe_.GetLastChannel(); 1880 int channel_num = voe_.GetLastChannel();
1898 cricket::AudioSendParameters parameters; 1881 cricket::AudioSendParameters parameters;
1899 parameters.codecs.push_back(kRedCodec); 1882 parameters.codecs.push_back(kRedCodec);
1900 parameters.codecs.push_back(kIsacCodec); 1883 parameters.codecs.push_back(kIsacCodec);
1901 parameters.codecs.push_back(kPcmuCodec); 1884 parameters.codecs.push_back(kPcmuCodec);
1902 parameters.codecs[0].id = 127; 1885 parameters.codecs[0].id = 127;
1903 parameters.codecs[0].params["ABC"] = "96/96"; 1886 parameters.codecs[0].params["ABC"] = "96/96";
1904 parameters.codecs[1].id = 96; 1887 parameters.codecs[1].id = 96;
1905 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1888 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1906 webrtc::CodecInst gcodec; 1889 webrtc::CodecInst gcodec;
1907 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1890 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1908 EXPECT_EQ(96, gcodec.pltype); 1891 EXPECT_EQ(96, gcodec.pltype);
1909 EXPECT_STREQ("ISAC", gcodec.plname); 1892 EXPECT_STREQ("ISAC", gcodec.plname);
1910 EXPECT_FALSE(voe_.GetRED(channel_num)); 1893 EXPECT_FALSE(voe_.GetRED(channel_num));
1911 } 1894 }
1912 1895
1913 // Test that we ignore RED if it uses different primary/secondary encoding. 1896 // Test that we ignore RED if it uses different primary/secondary encoding.
1914 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) { 1897 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED2) {
1915 EXPECT_TRUE(SetupEngineWithSendStream()); 1898 EXPECT_TRUE(SetupSendStream());
1916 int channel_num = voe_.GetLastChannel(); 1899 int channel_num = voe_.GetLastChannel();
1917 cricket::AudioSendParameters parameters; 1900 cricket::AudioSendParameters parameters;
1918 parameters.codecs.push_back(kRedCodec); 1901 parameters.codecs.push_back(kRedCodec);
1919 parameters.codecs.push_back(kIsacCodec); 1902 parameters.codecs.push_back(kIsacCodec);
1920 parameters.codecs.push_back(kPcmuCodec); 1903 parameters.codecs.push_back(kPcmuCodec);
1921 parameters.codecs[0].id = 127; 1904 parameters.codecs[0].id = 127;
1922 parameters.codecs[0].params[""] = "96/0"; 1905 parameters.codecs[0].params[""] = "96/0";
1923 parameters.codecs[1].id = 96; 1906 parameters.codecs[1].id = 96;
1924 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1907 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1925 webrtc::CodecInst gcodec; 1908 webrtc::CodecInst gcodec;
1926 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1909 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1927 EXPECT_EQ(96, gcodec.pltype); 1910 EXPECT_EQ(96, gcodec.pltype);
1928 EXPECT_STREQ("ISAC", gcodec.plname); 1911 EXPECT_STREQ("ISAC", gcodec.plname);
1929 EXPECT_FALSE(voe_.GetRED(channel_num)); 1912 EXPECT_FALSE(voe_.GetRED(channel_num));
1930 } 1913 }
1931 1914
1932 // Test that we ignore RED if it uses more than 2 encodings. 1915 // Test that we ignore RED if it uses more than 2 encodings.
1933 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) { 1916 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED3) {
1934 EXPECT_TRUE(SetupEngineWithSendStream()); 1917 EXPECT_TRUE(SetupSendStream());
1935 int channel_num = voe_.GetLastChannel(); 1918 int channel_num = voe_.GetLastChannel();
1936 cricket::AudioSendParameters parameters; 1919 cricket::AudioSendParameters parameters;
1937 parameters.codecs.push_back(kRedCodec); 1920 parameters.codecs.push_back(kRedCodec);
1938 parameters.codecs.push_back(kIsacCodec); 1921 parameters.codecs.push_back(kIsacCodec);
1939 parameters.codecs.push_back(kPcmuCodec); 1922 parameters.codecs.push_back(kPcmuCodec);
1940 parameters.codecs[0].id = 127; 1923 parameters.codecs[0].id = 127;
1941 parameters.codecs[0].params[""] = "96/96/96"; 1924 parameters.codecs[0].params[""] = "96/96/96";
1942 parameters.codecs[1].id = 96; 1925 parameters.codecs[1].id = 96;
1943 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1926 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1944 webrtc::CodecInst gcodec; 1927 webrtc::CodecInst gcodec;
1945 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1928 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1946 EXPECT_EQ(96, gcodec.pltype); 1929 EXPECT_EQ(96, gcodec.pltype);
1947 EXPECT_STREQ("ISAC", gcodec.plname); 1930 EXPECT_STREQ("ISAC", gcodec.plname);
1948 EXPECT_FALSE(voe_.GetRED(channel_num)); 1931 EXPECT_FALSE(voe_.GetRED(channel_num));
1949 } 1932 }
1950 1933
1951 // Test that we ignore RED if it has bogus codec ids. 1934 // Test that we ignore RED if it has bogus codec ids.
1952 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) { 1935 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED4) {
1953 EXPECT_TRUE(SetupEngineWithSendStream()); 1936 EXPECT_TRUE(SetupSendStream());
1954 int channel_num = voe_.GetLastChannel(); 1937 int channel_num = voe_.GetLastChannel();
1955 cricket::AudioSendParameters parameters; 1938 cricket::AudioSendParameters parameters;
1956 parameters.codecs.push_back(kRedCodec); 1939 parameters.codecs.push_back(kRedCodec);
1957 parameters.codecs.push_back(kIsacCodec); 1940 parameters.codecs.push_back(kIsacCodec);
1958 parameters.codecs.push_back(kPcmuCodec); 1941 parameters.codecs.push_back(kPcmuCodec);
1959 parameters.codecs[0].id = 127; 1942 parameters.codecs[0].id = 127;
1960 parameters.codecs[0].params[""] = "ABC/ABC"; 1943 parameters.codecs[0].params[""] = "ABC/ABC";
1961 parameters.codecs[1].id = 96; 1944 parameters.codecs[1].id = 96;
1962 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1945 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1963 webrtc::CodecInst gcodec; 1946 webrtc::CodecInst gcodec;
1964 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec)); 1947 EXPECT_EQ(0, voe_.GetSendCodec(channel_num, gcodec));
1965 EXPECT_EQ(96, gcodec.pltype); 1948 EXPECT_EQ(96, gcodec.pltype);
1966 EXPECT_STREQ("ISAC", gcodec.plname); 1949 EXPECT_STREQ("ISAC", gcodec.plname);
1967 EXPECT_FALSE(voe_.GetRED(channel_num)); 1950 EXPECT_FALSE(voe_.GetRED(channel_num));
1968 } 1951 }
1969 1952
1970 // Test that we ignore RED if it refers to a codec that is not present. 1953 // Test that we ignore RED if it refers to a codec that is not present.
1971 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) { 1954 TEST_F(WebRtcVoiceEngineTestFake, SetSendCodecsBadRED5) {
1972 EXPECT_TRUE(SetupEngineWithSendStream()); 1955 EXPECT_TRUE(SetupSendStream());
1973 int channel_num = voe_.GetLastChannel(); 1956 int channel_num = voe_.GetLastChannel();
1974 cricket::AudioSendParameters parameters; 1957 cricket::AudioSendParameters parameters;
1975 parameters.codecs.push_back(kRedCodec); 1958 parameters.codecs.push_back(kRedCodec);
1976 parameters.codecs.push_back(kIsacCodec); 1959 parameters.codecs.push_back(kIsacCodec);
1977 parameters.codecs.push_back(kPcmuCodec); 1960 parameters.codecs.push_back(kPcmuCodec);
1978 parameters.codecs[0].id = 127; 1961 parameters.codecs[0].id = 127;
1979 parameters.codecs[0].params[""] = "97/97"; 1962 parameters.codecs[0].params[""] = "97/97";
1980 parameters.codecs[1].id = 96; 1963 parameters.codecs[1].id = 96;
1981 EXPECT_TRUE(channel_->SetSendParameters(parameters)); 1964 EXPECT_TRUE(channel_->SetSendParameters(parameters));
1982 webrtc::CodecInst gcodec; 1965 webrtc::CodecInst gcodec;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
2018 // Test support for absolute send time header extension. 2001 // Test support for absolute send time header extension.
2019 TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) { 2002 TEST_F(WebRtcVoiceEngineTestFake, SendAbsoluteSendTimeHeaderExtensions) {
2020 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension); 2003 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
2021 } 2004 }
2022 TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) { 2005 TEST_F(WebRtcVoiceEngineTestFake, RecvAbsoluteSendTimeHeaderExtensions) {
2023 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension); 2006 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension);
2024 } 2007 }
2025 2008
2026 // Test that we can create a channel and start sending on it. 2009 // Test that we can create a channel and start sending on it.
2027 TEST_F(WebRtcVoiceEngineTestFake, Send) { 2010 TEST_F(WebRtcVoiceEngineTestFake, Send) {
2028 EXPECT_TRUE(SetupEngineWithSendStream()); 2011 EXPECT_TRUE(SetupSendStream());
2029 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2012 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2030 channel_->SetSend(true); 2013 channel_->SetSend(true);
2031 EXPECT_TRUE(GetSendStream(kSsrc1).IsSending()); 2014 EXPECT_TRUE(GetSendStream(kSsrc1).IsSending());
2032 channel_->SetSend(false); 2015 channel_->SetSend(false);
2033 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); 2016 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending());
2034 } 2017 }
2035 2018
2036 // Test that a channel will send if and only if it has a source and is enabled 2019 // Test that a channel will send if and only if it has a source and is enabled
2037 // for sending. 2020 // for sending.
2038 TEST_F(WebRtcVoiceEngineTestFake, SendStateWithAndWithoutSource) { 2021 TEST_F(WebRtcVoiceEngineTestFake, SendStateWithAndWithoutSource) {
2039 EXPECT_TRUE(SetupEngineWithSendStream()); 2022 EXPECT_TRUE(SetupSendStream());
2040 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2023 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2041 EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, nullptr)); 2024 EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2042 channel_->SetSend(true); 2025 channel_->SetSend(true);
2043 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); 2026 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending());
2044 EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, &fake_source_)); 2027 EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, &fake_source_));
2045 EXPECT_TRUE(GetSendStream(kSsrc1).IsSending()); 2028 EXPECT_TRUE(GetSendStream(kSsrc1).IsSending());
2046 EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, nullptr)); 2029 EXPECT_TRUE(channel_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2047 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); 2030 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending());
2048 } 2031 }
2049 2032
2050 // Test that we can create a channel and start playing out on it. 2033 // Test that we can create a channel and start playing out on it.
2051 TEST_F(WebRtcVoiceEngineTestFake, Playout) { 2034 TEST_F(WebRtcVoiceEngineTestFake, Playout) {
2052 EXPECT_TRUE(SetupEngineWithRecvStream()); 2035 EXPECT_TRUE(SetupRecvStream());
2053 int channel_num = voe_.GetLastChannel(); 2036 int channel_num = voe_.GetLastChannel();
2054 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); 2037 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_));
2055 EXPECT_TRUE(channel_->SetPlayout(true)); 2038 EXPECT_TRUE(channel_->SetPlayout(true));
2056 EXPECT_TRUE(voe_.GetPlayout(channel_num)); 2039 EXPECT_TRUE(voe_.GetPlayout(channel_num));
2057 EXPECT_TRUE(channel_->SetPlayout(false)); 2040 EXPECT_TRUE(channel_->SetPlayout(false));
2058 EXPECT_FALSE(voe_.GetPlayout(channel_num)); 2041 EXPECT_FALSE(voe_.GetPlayout(channel_num));
2059 } 2042 }
2060 2043
2061 // Test that we can add and remove send streams. 2044 // Test that we can add and remove send streams.
2062 TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) { 2045 TEST_F(WebRtcVoiceEngineTestFake, CreateAndDeleteMultipleSendStreams) {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
2201 EXPECT_EQ(true, channel_->GetStats(&info)); 2184 EXPECT_EQ(true, channel_->GetStats(&info));
2202 EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size()); 2185 EXPECT_EQ(static_cast<size_t>(arraysize(kSsrcs4)), info.senders.size());
2203 EXPECT_EQ(1u, info.receivers.size()); 2186 EXPECT_EQ(1u, info.receivers.size());
2204 VerifyVoiceReceiverInfo(info.receivers[0]); 2187 VerifyVoiceReceiverInfo(info.receivers[0]);
2205 } 2188 }
2206 } 2189 }
2207 2190
2208 // Test that we can add and remove receive streams, and do proper send/playout. 2191 // Test that we can add and remove receive streams, and do proper send/playout.
2209 // We can receive on multiple streams while sending one stream. 2192 // We can receive on multiple streams while sending one stream.
2210 TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) { 2193 TEST_F(WebRtcVoiceEngineTestFake, PlayoutWithMultipleStreams) {
2211 EXPECT_TRUE(SetupEngineWithSendStream()); 2194 EXPECT_TRUE(SetupSendStream());
2212 int channel_num1 = voe_.GetLastChannel(); 2195 int channel_num1 = voe_.GetLastChannel();
2213 2196
2214 // Start playout without a receive stream. 2197 // Start playout without a receive stream.
2215 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2198 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2216 EXPECT_TRUE(channel_->SetPlayout(true)); 2199 EXPECT_TRUE(channel_->SetPlayout(true));
2217 EXPECT_FALSE(voe_.GetPlayout(channel_num1)); 2200 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2218 2201
2219 // Adding another stream should enable playout on the new stream only. 2202 // Adding another stream should enable playout on the new stream only.
2220 EXPECT_TRUE( 2203 EXPECT_TRUE(
2221 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc2))); 2204 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc2)));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
2253 2236
2254 // Now remove the recv streams and verify that the send stream doesn't play. 2237 // Now remove the recv streams and verify that the send stream doesn't play.
2255 EXPECT_TRUE(channel_->RemoveRecvStream(3)); 2238 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2256 EXPECT_TRUE(channel_->RemoveRecvStream(2)); 2239 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2257 EXPECT_FALSE(voe_.GetPlayout(channel_num1)); 2240 EXPECT_FALSE(voe_.GetPlayout(channel_num1));
2258 } 2241 }
2259 2242
2260 // Test that we can create a channel configured for Codian bridges, 2243 // Test that we can create a channel configured for Codian bridges,
2261 // and start sending on it. 2244 // and start sending on it.
2262 TEST_F(WebRtcVoiceEngineTestFake, CodianSend) { 2245 TEST_F(WebRtcVoiceEngineTestFake, CodianSend) {
2263 EXPECT_TRUE(SetupEngineWithSendStream()); 2246 EXPECT_TRUE(SetupSendStream());
2264 cricket::AudioOptions options_adjust_agc; 2247 cricket::AudioOptions options_adjust_agc;
2265 options_adjust_agc.adjust_agc_delta = rtc::Optional<int>(-10); 2248 options_adjust_agc.adjust_agc_delta = rtc::Optional<int>(-10);
2266 webrtc::AgcConfig agc_config; 2249 webrtc::AgcConfig agc_config;
2267 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2250 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2268 EXPECT_EQ(0, agc_config.targetLeveldBOv); 2251 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2269 send_parameters_.options = options_adjust_agc; 2252 send_parameters_.options = options_adjust_agc;
2270 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2253 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2271 channel_->SetSend(true); 2254 channel_->SetSend(true);
2272 EXPECT_TRUE(GetSendStream(kSsrc1).IsSending()); 2255 EXPECT_TRUE(GetSendStream(kSsrc1).IsSending());
2273 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2256 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2274 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated 2257 EXPECT_EQ(agc_config.targetLeveldBOv, 10); // level was attenuated
2275 channel_->SetSend(false); 2258 channel_->SetSend(false);
2276 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending()); 2259 EXPECT_FALSE(GetSendStream(kSsrc1).IsSending());
2277 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2260 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2278 } 2261 }
2279 2262
2280 TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) { 2263 TEST_F(WebRtcVoiceEngineTestFake, TxAgcConfigViaOptions) {
2281 EXPECT_TRUE(SetupEngineWithSendStream()); 2264 EXPECT_TRUE(SetupSendStream());
2282 webrtc::AgcConfig agc_config; 2265 webrtc::AgcConfig agc_config;
2283 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2266 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2284 EXPECT_EQ(0, agc_config.targetLeveldBOv); 2267 EXPECT_EQ(0, agc_config.targetLeveldBOv);
2285 send_parameters_.options.tx_agc_target_dbov = rtc::Optional<uint16_t>(3); 2268 send_parameters_.options.tx_agc_target_dbov = rtc::Optional<uint16_t>(3);
2286 send_parameters_.options.tx_agc_digital_compression_gain = 2269 send_parameters_.options.tx_agc_digital_compression_gain =
2287 rtc::Optional<uint16_t>(9); 2270 rtc::Optional<uint16_t>(9);
2288 send_parameters_.options.tx_agc_limiter = rtc::Optional<bool>(true); 2271 send_parameters_.options.tx_agc_limiter = rtc::Optional<bool>(true);
2289 send_parameters_.options.auto_gain_control = rtc::Optional<bool>(true); 2272 send_parameters_.options.auto_gain_control = rtc::Optional<bool>(true);
2290 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2273 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2291 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2274 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2292 EXPECT_EQ(3, agc_config.targetLeveldBOv); 2275 EXPECT_EQ(3, agc_config.targetLeveldBOv);
2293 EXPECT_EQ(9, agc_config.digitalCompressionGaindB); 2276 EXPECT_EQ(9, agc_config.digitalCompressionGaindB);
2294 EXPECT_TRUE(agc_config.limiterEnable); 2277 EXPECT_TRUE(agc_config.limiterEnable);
2295 2278
2296 // Check interaction with adjust_agc_delta. Both should be respected, for 2279 // Check interaction with adjust_agc_delta. Both should be respected, for
2297 // backwards compatibility. 2280 // backwards compatibility.
2298 send_parameters_.options.adjust_agc_delta = rtc::Optional<int>(-10); 2281 send_parameters_.options.adjust_agc_delta = rtc::Optional<int>(-10);
2299 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2282 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2300 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config)); 2283 EXPECT_EQ(0, voe_.GetAgcConfig(agc_config));
2301 EXPECT_EQ(13, agc_config.targetLeveldBOv); 2284 EXPECT_EQ(13, agc_config.targetLeveldBOv);
2302 } 2285 }
2303 2286
2304 TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) { 2287 TEST_F(WebRtcVoiceEngineTestFake, SampleRatesViaOptions) {
2305 EXPECT_TRUE(SetupEngineWithSendStream()); 2288 EXPECT_TRUE(SetupSendStream());
2306 send_parameters_.options.recording_sample_rate = 2289 send_parameters_.options.recording_sample_rate =
2307 rtc::Optional<uint32_t>(48000); 2290 rtc::Optional<uint32_t>(48000);
2308 send_parameters_.options.playout_sample_rate = rtc::Optional<uint32_t>(44100); 2291 send_parameters_.options.playout_sample_rate = rtc::Optional<uint32_t>(44100);
2309 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2292 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2310 2293
2311 unsigned int recording_sample_rate, playout_sample_rate; 2294 unsigned int recording_sample_rate, playout_sample_rate;
2312 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate)); 2295 EXPECT_EQ(0, voe_.RecordingSampleRate(&recording_sample_rate));
2313 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate)); 2296 EXPECT_EQ(0, voe_.PlayoutSampleRate(&playout_sample_rate));
2314 EXPECT_EQ(48000u, recording_sample_rate); 2297 EXPECT_EQ(48000u, recording_sample_rate);
2315 EXPECT_EQ(44100u, playout_sample_rate); 2298 EXPECT_EQ(44100u, playout_sample_rate);
2316 } 2299 }
2317 2300
2318 // Test that we can set the outgoing SSRC properly. 2301 // Test that we can set the outgoing SSRC properly.
2319 // SSRC is set in SetupEngine by calling AddSendStream. 2302 // SSRC is set in SetupSendStream() by calling AddSendStream.
2320 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) { 2303 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrc) {
2321 EXPECT_TRUE(SetupEngineWithSendStream()); 2304 EXPECT_TRUE(SetupSendStream());
2322 EXPECT_TRUE(call_.GetAudioSendStream(kSsrc1)); 2305 EXPECT_TRUE(call_.GetAudioSendStream(kSsrc1));
2323 } 2306 }
2324 2307
2325 TEST_F(WebRtcVoiceEngineTestFake, GetStats) { 2308 TEST_F(WebRtcVoiceEngineTestFake, GetStats) {
2326 // Setup. We need send codec to be set to get all stats. 2309 // Setup. We need send codec to be set to get all stats.
2327 EXPECT_TRUE(SetupEngineWithSendStream()); 2310 EXPECT_TRUE(SetupSendStream());
2328 SetAudioSendStreamStats(); 2311 SetAudioSendStreamStats();
2329 // SetupEngineWithSendStream adds a send stream with kSsrc1, so the receive 2312 // SetupSendStream adds a send stream with kSsrc1, so the receive
2330 // stream has to use a different SSRC. 2313 // stream has to use a different SSRC.
2331 EXPECT_TRUE(channel_->AddRecvStream( 2314 EXPECT_TRUE(channel_->AddRecvStream(
2332 cricket::StreamParams::CreateLegacy(kSsrc2))); 2315 cricket::StreamParams::CreateLegacy(kSsrc2)));
2333 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2316 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2334 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); 2317 EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_));
2335 2318
2336 // Check stats for the added streams. 2319 // Check stats for the added streams.
2337 { 2320 {
2338 cricket::VoiceMediaInfo info; 2321 cricket::VoiceMediaInfo info;
2339 EXPECT_EQ(true, channel_->GetStats(&info)); 2322 EXPECT_EQ(true, channel_->GetStats(&info));
(...skipping 30 matching lines...) Expand all
2370 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 2353 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2371 SetAudioReceiveStreamStats(); 2354 SetAudioReceiveStreamStats();
2372 EXPECT_EQ(true, channel_->GetStats(&info)); 2355 EXPECT_EQ(true, channel_->GetStats(&info));
2373 EXPECT_EQ(1u, info.senders.size()); 2356 EXPECT_EQ(1u, info.senders.size());
2374 EXPECT_EQ(1u, info.receivers.size()); 2357 EXPECT_EQ(1u, info.receivers.size());
2375 VerifyVoiceReceiverInfo(info.receivers[0]); 2358 VerifyVoiceReceiverInfo(info.receivers[0]);
2376 } 2359 }
2377 } 2360 }
2378 2361
2379 // Test that we can set the outgoing SSRC properly with multiple streams. 2362 // Test that we can set the outgoing SSRC properly with multiple streams.
2380 // SSRC is set in SetupEngine by calling AddSendStream. 2363 // SSRC is set in SetupSendStream() by calling AddSendStream.
2381 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) { 2364 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcWithMultipleStreams) {
2382 EXPECT_TRUE(SetupEngineWithSendStream()); 2365 EXPECT_TRUE(SetupSendStream());
2383 EXPECT_TRUE(call_.GetAudioSendStream(kSsrc1)); 2366 EXPECT_TRUE(call_.GetAudioSendStream(kSsrc1));
2384 EXPECT_TRUE(channel_->AddRecvStream( 2367 EXPECT_TRUE(channel_->AddRecvStream(
2385 cricket::StreamParams::CreateLegacy(kSsrc2))); 2368 cricket::StreamParams::CreateLegacy(kSsrc2)));
2386 EXPECT_EQ(kSsrc1, GetRecvStreamConfig(kSsrc2).rtp.local_ssrc); 2369 EXPECT_EQ(kSsrc1, GetRecvStreamConfig(kSsrc2).rtp.local_ssrc);
2387 } 2370 }
2388 2371
2389 // Test that the local SSRC is the same on sending and receiving channels if the 2372 // Test that the local SSRC is the same on sending and receiving channels if the
2390 // receive channel is created before the send channel. 2373 // receive channel is created before the send channel.
2391 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) { 2374 TEST_F(WebRtcVoiceEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) {
2392 EXPECT_TRUE(engine_.Init(rtc::Thread::Current())); 2375 EXPECT_TRUE(SetupChannel());
2393 channel_ = engine_.CreateChannel(&call_, cricket::MediaConfig(),
2394 cricket::AudioOptions());
2395
2396 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2376 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2397 int receive_channel_num = voe_.GetLastChannel(); 2377 int receive_channel_num = voe_.GetLastChannel();
2398 EXPECT_TRUE(channel_->AddSendStream( 2378 EXPECT_TRUE(channel_->AddSendStream(
2399 cricket::StreamParams::CreateLegacy(1234))); 2379 cricket::StreamParams::CreateLegacy(1234)));
2400 2380
2401 EXPECT_TRUE(call_.GetAudioSendStream(1234)); 2381 EXPECT_TRUE(call_.GetAudioSendStream(1234));
2402 EXPECT_EQ(1234U, voe_.GetLocalSSRC(receive_channel_num)); 2382 EXPECT_EQ(1234U, voe_.GetLocalSSRC(receive_channel_num));
2403 } 2383 }
2404 2384
2405 // Test that we can properly receive packets. 2385 // Test that we can properly receive packets.
2406 TEST_F(WebRtcVoiceEngineTestFake, Recv) { 2386 TEST_F(WebRtcVoiceEngineTestFake, Recv) {
2407 EXPECT_TRUE(SetupEngine()); 2387 EXPECT_TRUE(SetupChannel());
2408 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2388 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2409 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 2389 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2410 int channel_num = voe_.GetLastChannel(); 2390 int channel_num = voe_.GetLastChannel();
2411 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, sizeof(kPcmuFrame))); 2391 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, sizeof(kPcmuFrame)));
2412 } 2392 }
2413 2393
2414 // Test that we can properly receive packets on multiple streams. 2394 // Test that we can properly receive packets on multiple streams.
2415 TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) { 2395 TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) {
2416 EXPECT_TRUE(SetupEngine()); 2396 EXPECT_TRUE(SetupChannel());
2417 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2397 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2418 int channel_num1 = voe_.GetLastChannel(); 2398 int channel_num1 = voe_.GetLastChannel();
2419 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2399 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2420 int channel_num2 = voe_.GetLastChannel(); 2400 int channel_num2 = voe_.GetLastChannel();
2421 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 2401 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2422 int channel_num3 = voe_.GetLastChannel(); 2402 int channel_num3 = voe_.GetLastChannel();
2423 // Create packets with the right SSRCs. 2403 // Create packets with the right SSRCs.
2424 char packets[4][sizeof(kPcmuFrame)]; 2404 char packets[4][sizeof(kPcmuFrame)];
2425 for (size_t i = 0; i < arraysize(packets); ++i) { 2405 for (size_t i = 0; i < arraysize(packets); ++i) {
2426 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame)); 2406 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame));
(...skipping 24 matching lines...) Expand all
2451 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3], sizeof(packets[3]))); 2431 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3], sizeof(packets[3])));
2452 2432
2453 EXPECT_TRUE(channel_->RemoveRecvStream(3)); 2433 EXPECT_TRUE(channel_->RemoveRecvStream(3));
2454 EXPECT_TRUE(channel_->RemoveRecvStream(2)); 2434 EXPECT_TRUE(channel_->RemoveRecvStream(2));
2455 EXPECT_TRUE(channel_->RemoveRecvStream(1)); 2435 EXPECT_TRUE(channel_->RemoveRecvStream(1));
2456 } 2436 }
2457 2437
2458 // Test that receiving on an unsignalled stream works (default channel will be 2438 // Test that receiving on an unsignalled stream works (default channel will be
2459 // created). 2439 // created).
2460 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalled) { 2440 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalled) {
2461 EXPECT_TRUE(SetupEngine()); 2441 EXPECT_TRUE(SetupChannel());
2462 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 2442 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2463 int channel_num = voe_.GetLastChannel(); 2443 int channel_num = voe_.GetLastChannel();
2464 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, sizeof(kPcmuFrame))); 2444 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, sizeof(kPcmuFrame)));
2465 } 2445 }
2466 2446
2467 // Test that receiving on an unsignalled stream works (default channel will be 2447 // Test that receiving on an unsignalled stream works (default channel will be
2468 // created), and that packets will be forwarded to the default channel 2448 // created), and that packets will be forwarded to the default channel
2469 // regardless of their SSRCs. 2449 // regardless of their SSRCs.
2470 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledWithSsrcSwitch) { 2450 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledWithSsrcSwitch) {
2471 EXPECT_TRUE(SetupEngine()); 2451 EXPECT_TRUE(SetupChannel());
2472 char packet[sizeof(kPcmuFrame)]; 2452 char packet[sizeof(kPcmuFrame)];
2473 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); 2453 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
2474 2454
2475 // Note that the first unknown SSRC cannot be 0, because we only support 2455 // Note that the first unknown SSRC cannot be 0, because we only support
2476 // creating receive streams for SSRC!=0. 2456 // creating receive streams for SSRC!=0.
2477 DeliverPacket(packet, sizeof(packet)); 2457 DeliverPacket(packet, sizeof(packet));
2478 int channel_num = voe_.GetLastChannel(); 2458 int channel_num = voe_.GetLastChannel();
2479 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); 2459 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet)));
2480 // Once we have the default channel, SSRC==0 will be ok. 2460 // Once we have the default channel, SSRC==0 will be ok.
2481 for (uint32_t ssrc = 0; ssrc < 10; ++ssrc) { 2461 for (uint32_t ssrc = 0; ssrc < 10; ++ssrc) {
2482 rtc::SetBE32(&packet[8], ssrc); 2462 rtc::SetBE32(&packet[8], ssrc);
2483 DeliverPacket(packet, sizeof(packet)); 2463 DeliverPacket(packet, sizeof(packet));
2484 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); 2464 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet)));
2485 } 2465 }
2486 } 2466 }
2487 2467
2488 // Test that a default channel is created even after a signalled stream has been 2468 // Test that a default channel is created even after a signalled stream has been
2489 // added, and that this stream will get any packets for unknown SSRCs. 2469 // added, and that this stream will get any packets for unknown SSRCs.
2490 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledAfterSignalled) { 2470 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledAfterSignalled) {
2491 EXPECT_TRUE(SetupEngine()); 2471 EXPECT_TRUE(SetupChannel());
2492 char packet[sizeof(kPcmuFrame)]; 2472 char packet[sizeof(kPcmuFrame)];
2493 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); 2473 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
2494 2474
2495 // Add a known stream, send packet and verify we got it. 2475 // Add a known stream, send packet and verify we got it.
2496 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2476 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2497 int signalled_channel_num = voe_.GetLastChannel(); 2477 int signalled_channel_num = voe_.GetLastChannel();
2498 DeliverPacket(packet, sizeof(packet)); 2478 DeliverPacket(packet, sizeof(packet));
2499 EXPECT_TRUE(voe_.CheckPacket(signalled_channel_num, packet, sizeof(packet))); 2479 EXPECT_TRUE(voe_.CheckPacket(signalled_channel_num, packet, sizeof(packet)));
2500 2480
2501 // Note that the first unknown SSRC cannot be 0, because we only support 2481 // Note that the first unknown SSRC cannot be 0, because we only support
2502 // creating receive streams for SSRC!=0. 2482 // creating receive streams for SSRC!=0.
2503 rtc::SetBE32(&packet[8], 7011); 2483 rtc::SetBE32(&packet[8], 7011);
2504 DeliverPacket(packet, sizeof(packet)); 2484 DeliverPacket(packet, sizeof(packet));
2505 int channel_num = voe_.GetLastChannel(); 2485 int channel_num = voe_.GetLastChannel();
2506 EXPECT_NE(channel_num, signalled_channel_num); 2486 EXPECT_NE(channel_num, signalled_channel_num);
2507 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); 2487 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet)));
2508 // Once we have the default channel, SSRC==0 will be ok. 2488 // Once we have the default channel, SSRC==0 will be ok.
2509 for (uint32_t ssrc = 0; ssrc < 20; ssrc += 2) { 2489 for (uint32_t ssrc = 0; ssrc < 20; ssrc += 2) {
2510 rtc::SetBE32(&packet[8], ssrc); 2490 rtc::SetBE32(&packet[8], ssrc);
2511 DeliverPacket(packet, sizeof(packet)); 2491 DeliverPacket(packet, sizeof(packet));
2512 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); 2492 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet)));
2513 } 2493 }
2514 } 2494 }
2515 2495
2516 // Test that we properly handle failures to add a receive stream. 2496 // Test that we properly handle failures to add a receive stream.
2517 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamFail) { 2497 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamFail) {
2518 EXPECT_TRUE(SetupEngine()); 2498 EXPECT_TRUE(SetupChannel());
2519 voe_.set_fail_create_channel(true); 2499 voe_.set_fail_create_channel(true);
2520 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2500 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2521 } 2501 }
2522 2502
2523 // Test that we properly handle failures to add a send stream. 2503 // Test that we properly handle failures to add a send stream.
2524 TEST_F(WebRtcVoiceEngineTestFake, AddSendStreamFail) { 2504 TEST_F(WebRtcVoiceEngineTestFake, AddSendStreamFail) {
2525 EXPECT_TRUE(SetupEngine()); 2505 EXPECT_TRUE(SetupChannel());
2526 voe_.set_fail_create_channel(true); 2506 voe_.set_fail_create_channel(true);
2527 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2))); 2507 EXPECT_FALSE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
2528 } 2508 }
2529 2509
2530 // Test that AddRecvStream creates new stream. 2510 // Test that AddRecvStream creates new stream.
2531 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream) { 2511 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStream) {
2532 EXPECT_TRUE(SetupEngineWithRecvStream()); 2512 EXPECT_TRUE(SetupRecvStream());
2533 int channel_num = voe_.GetLastChannel(); 2513 int channel_num = voe_.GetLastChannel();
2534 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2514 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2535 EXPECT_NE(channel_num, voe_.GetLastChannel()); 2515 EXPECT_NE(channel_num, voe_.GetLastChannel());
2536 } 2516 }
2537 2517
2538 // Test that after adding a recv stream, we do not decode more codecs than 2518 // Test that after adding a recv stream, we do not decode more codecs than
2539 // those previously passed into SetRecvCodecs. 2519 // those previously passed into SetRecvCodecs.
2540 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) { 2520 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamUnsupportedCodec) {
2541 EXPECT_TRUE(SetupEngineWithSendStream()); 2521 EXPECT_TRUE(SetupSendStream());
2542 cricket::AudioRecvParameters parameters; 2522 cricket::AudioRecvParameters parameters;
2543 parameters.codecs.push_back(kIsacCodec); 2523 parameters.codecs.push_back(kIsacCodec);
2544 parameters.codecs.push_back(kPcmuCodec); 2524 parameters.codecs.push_back(kPcmuCodec);
2545 EXPECT_TRUE(channel_->SetRecvParameters(parameters)); 2525 EXPECT_TRUE(channel_->SetRecvParameters(parameters));
2546 EXPECT_TRUE(channel_->AddRecvStream( 2526 EXPECT_TRUE(channel_->AddRecvStream(
2547 cricket::StreamParams::CreateLegacy(kSsrc1))); 2527 cricket::StreamParams::CreateLegacy(kSsrc1)));
2548 int channel_num2 = voe_.GetLastChannel(); 2528 int channel_num2 = voe_.GetLastChannel();
2549 webrtc::CodecInst gcodec; 2529 webrtc::CodecInst gcodec;
2550 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "opus"); 2530 rtc::strcpyn(gcodec.plname, arraysize(gcodec.plname), "opus");
2551 gcodec.plfreq = 48000; 2531 gcodec.plfreq = 48000;
2552 gcodec.channels = 2; 2532 gcodec.channels = 2;
2553 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec)); 2533 EXPECT_EQ(-1, voe_.GetRecPayloadType(channel_num2, gcodec));
2554 } 2534 }
2555 2535
2556 // Test that we properly clean up any streams that were added, even if 2536 // Test that we properly clean up any streams that were added, even if
2557 // not explicitly removed. 2537 // not explicitly removed.
2558 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) { 2538 TEST_F(WebRtcVoiceEngineTestFake, StreamCleanup) {
2559 EXPECT_TRUE(SetupEngineWithSendStream()); 2539 EXPECT_TRUE(SetupSendStream());
2560 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2540 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2561 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2541 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2562 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2542 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2563 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added 2543 EXPECT_EQ(3, voe_.GetNumChannels()); // default channel + 2 added
2564 delete channel_; 2544 delete channel_;
2565 channel_ = NULL; 2545 channel_ = NULL;
2566 EXPECT_EQ(0, voe_.GetNumChannels()); 2546 EXPECT_EQ(0, voe_.GetNumChannels());
2567 } 2547 }
2568 2548
2569 TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) { 2549 TEST_F(WebRtcVoiceEngineTestFake, TestAddRecvStreamFailWithZeroSsrc) {
2570 EXPECT_TRUE(SetupEngineWithSendStream()); 2550 EXPECT_TRUE(SetupSendStream());
2571 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0))); 2551 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(0)));
2572 } 2552 }
2573 2553
2574 TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) { 2554 TEST_F(WebRtcVoiceEngineTestFake, TestNoLeakingWhenAddRecvStreamFail) {
2575 EXPECT_TRUE(SetupEngine()); 2555 EXPECT_TRUE(SetupChannel());
2576 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 2556 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
2577 // Manually delete channel to simulate a failure. 2557 // Manually delete channel to simulate a failure.
2578 int channel = voe_.GetLastChannel(); 2558 int channel = voe_.GetLastChannel();
2579 EXPECT_EQ(0, voe_.DeleteChannel(channel)); 2559 EXPECT_EQ(0, voe_.DeleteChannel(channel));
2580 // Add recv stream 2 should work. 2560 // Add recv stream 2 should work.
2581 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2561 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2582 int new_channel = voe_.GetLastChannel(); 2562 int new_channel = voe_.GetLastChannel();
2583 EXPECT_NE(channel, new_channel); 2563 EXPECT_NE(channel, new_channel);
2584 // The last created channel is deleted too. 2564 // The last created channel is deleted too.
2585 EXPECT_EQ(0, voe_.DeleteChannel(new_channel)); 2565 EXPECT_EQ(0, voe_.DeleteChannel(new_channel));
(...skipping 13 matching lines...) Expand all
2599 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) { 2579 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCaller) {
2600 TestInsertDtmf(kSsrc1, true); 2580 TestInsertDtmf(kSsrc1, true);
2601 } 2581 }
2602 2582
2603 // Test the InsertDtmf on specified send stream as callee. 2583 // Test the InsertDtmf on specified send stream as callee.
2604 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) { 2584 TEST_F(WebRtcVoiceEngineTestFake, InsertDtmfOnSendStreamAsCallee) {
2605 TestInsertDtmf(kSsrc1, false); 2585 TestInsertDtmf(kSsrc1, false);
2606 } 2586 }
2607 2587
2608 TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) { 2588 TEST_F(WebRtcVoiceEngineTestFake, TestSetPlayoutError) {
2609 EXPECT_TRUE(SetupEngineWithSendStream()); 2589 EXPECT_TRUE(SetupSendStream());
2610 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2590 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2611 channel_->SetSend(true); 2591 channel_->SetSend(true);
2612 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); 2592 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2)));
2613 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 2593 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
2614 EXPECT_TRUE(channel_->SetPlayout(true)); 2594 EXPECT_TRUE(channel_->SetPlayout(true));
2615 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1); 2595 voe_.set_playout_fail_channel(voe_.GetLastChannel() - 1);
2616 EXPECT_TRUE(channel_->SetPlayout(false)); 2596 EXPECT_TRUE(channel_->SetPlayout(false));
2617 EXPECT_FALSE(channel_->SetPlayout(true)); 2597 EXPECT_FALSE(channel_->SetPlayout(true));
2618 } 2598 }
2619 2599
2620 TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) { 2600 TEST_F(WebRtcVoiceEngineTestFake, SetAudioOptions) {
2621 EXPECT_TRUE(SetupEngineWithSendStream()); 2601 EXPECT_TRUE(SetupSendStream());
2622 2602
2623 bool ec_enabled; 2603 bool ec_enabled;
2624 webrtc::EcModes ec_mode; 2604 webrtc::EcModes ec_mode;
2625 webrtc::AecmModes aecm_mode; 2605 webrtc::AecmModes aecm_mode;
2626 bool cng_enabled; 2606 bool cng_enabled;
2627 bool agc_enabled; 2607 bool agc_enabled;
2628 webrtc::AgcModes agc_mode; 2608 webrtc::AgcModes agc_mode;
2629 webrtc::AgcConfig agc_config; 2609 webrtc::AgcConfig agc_config;
2630 bool ns_enabled; 2610 bool ns_enabled;
2631 webrtc::NsModes ns_mode; 2611 webrtc::NsModes ns_mode;
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
2767 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 2747 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
2768 voe_.GetEcStatus(ec_enabled, ec_mode); 2748 voe_.GetEcStatus(ec_enabled, ec_mode);
2769 voe_.GetNsStatus(ns_enabled, ns_mode); 2749 voe_.GetNsStatus(ns_enabled, ns_mode);
2770 EXPECT_TRUE(ec_enabled); 2750 EXPECT_TRUE(ec_enabled);
2771 EXPECT_EQ(webrtc::kEcConference, ec_mode); 2751 EXPECT_EQ(webrtc::kEcConference, ec_mode);
2772 EXPECT_FALSE(ns_enabled); 2752 EXPECT_FALSE(ns_enabled);
2773 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode); 2753 EXPECT_EQ(webrtc::kNsHighSuppression, ns_mode);
2774 } 2754 }
2775 2755
2776 TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) { 2756 TEST_F(WebRtcVoiceEngineTestFake, DefaultOptions) {
2777 EXPECT_TRUE(SetupEngineWithSendStream()); 2757 EXPECT_TRUE(SetupSendStream());
2778 2758
2779 bool ec_enabled; 2759 bool ec_enabled;
2780 webrtc::EcModes ec_mode; 2760 webrtc::EcModes ec_mode;
2781 bool agc_enabled; 2761 bool agc_enabled;
2782 webrtc::AgcModes agc_mode; 2762 webrtc::AgcModes agc_mode;
2783 bool ns_enabled; 2763 bool ns_enabled;
2784 webrtc::NsModes ns_mode; 2764 webrtc::NsModes ns_mode;
2785 bool highpass_filter_enabled; 2765 bool highpass_filter_enabled;
2786 bool stereo_swapping_enabled; 2766 bool stereo_swapping_enabled;
2787 bool typing_detection_enabled; 2767 bool typing_detection_enabled;
(...skipping 11 matching lines...) Expand all
2799 EXPECT_TRUE(typing_detection_enabled); 2779 EXPECT_TRUE(typing_detection_enabled);
2800 EXPECT_FALSE(stereo_swapping_enabled); 2780 EXPECT_FALSE(stereo_swapping_enabled);
2801 } 2781 }
2802 2782
2803 TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) { 2783 TEST_F(WebRtcVoiceEngineTestFake, InitDoesNotOverwriteDefaultAgcConfig) {
2804 webrtc::AgcConfig set_config = {0}; 2784 webrtc::AgcConfig set_config = {0};
2805 set_config.targetLeveldBOv = 3; 2785 set_config.targetLeveldBOv = 3;
2806 set_config.digitalCompressionGaindB = 9; 2786 set_config.digitalCompressionGaindB = 9;
2807 set_config.limiterEnable = true; 2787 set_config.limiterEnable = true;
2808 EXPECT_EQ(0, voe_.SetAgcConfig(set_config)); 2788 EXPECT_EQ(0, voe_.SetAgcConfig(set_config));
2809 EXPECT_TRUE(engine_.Init(rtc::Thread::Current()));
2810 2789
2811 webrtc::AgcConfig config = {0}; 2790 webrtc::AgcConfig config = {0};
2812 EXPECT_EQ(0, voe_.GetAgcConfig(config)); 2791 EXPECT_EQ(0, voe_.GetAgcConfig(config));
2813 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv); 2792 EXPECT_EQ(set_config.targetLeveldBOv, config.targetLeveldBOv);
2814 EXPECT_EQ(set_config.digitalCompressionGaindB, 2793 EXPECT_EQ(set_config.digitalCompressionGaindB,
2815 config.digitalCompressionGaindB); 2794 config.digitalCompressionGaindB);
2816 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable); 2795 EXPECT_EQ(set_config.limiterEnable, config.limiterEnable);
2817 } 2796 }
2818 2797
2819 TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) { 2798 TEST_F(WebRtcVoiceEngineTestFake, SetOptionOverridesViaChannels) {
2820 EXPECT_TRUE(SetupEngineWithSendStream()); 2799 EXPECT_TRUE(SetupSendStream());
2821 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel1( 2800 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel1(
2822 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel( 2801 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel(
2823 &call_, cricket::MediaConfig(), cricket::AudioOptions()))); 2802 &call_, cricket::MediaConfig(), cricket::AudioOptions())));
2824 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel2( 2803 std::unique_ptr<cricket::WebRtcVoiceMediaChannel> channel2(
2825 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel( 2804 static_cast<cricket::WebRtcVoiceMediaChannel*>(engine_.CreateChannel(
2826 &call_, cricket::MediaConfig(), cricket::AudioOptions()))); 2805 &call_, cricket::MediaConfig(), cricket::AudioOptions())));
2827 2806
2828 // Have to add a stream to make SetSend work. 2807 // Have to add a stream to make SetSend work.
2829 cricket::StreamParams stream1; 2808 cricket::StreamParams stream1;
2830 stream1.ssrcs.push_back(1); 2809 stream1.ssrcs.push_back(1);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
2911 voe_.GetEcStatus(ec_enabled, ec_mode); 2890 voe_.GetEcStatus(ec_enabled, ec_mode);
2912 voe_.GetAgcStatus(agc_enabled, agc_mode); 2891 voe_.GetAgcStatus(agc_enabled, agc_mode);
2913 voe_.GetNsStatus(ns_enabled, ns_mode); 2892 voe_.GetNsStatus(ns_enabled, ns_mode);
2914 EXPECT_TRUE(ec_enabled); 2893 EXPECT_TRUE(ec_enabled);
2915 EXPECT_FALSE(agc_enabled); 2894 EXPECT_FALSE(agc_enabled);
2916 EXPECT_FALSE(ns_enabled); 2895 EXPECT_FALSE(ns_enabled);
2917 } 2896 }
2918 2897
2919 // This test verifies DSCP settings are properly applied on voice media channel. 2898 // This test verifies DSCP settings are properly applied on voice media channel.
2920 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) { 2899 TEST_F(WebRtcVoiceEngineTestFake, TestSetDscpOptions) {
2921 EXPECT_TRUE(SetupEngineWithSendStream()); 2900 EXPECT_TRUE(SetupSendStream());
2922 cricket::FakeNetworkInterface network_interface; 2901 cricket::FakeNetworkInterface network_interface;
2923 cricket::MediaConfig config; 2902 cricket::MediaConfig config;
2924 std::unique_ptr<cricket::VoiceMediaChannel> channel; 2903 std::unique_ptr<cricket::VoiceMediaChannel> channel;
2925 2904
2926 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions())); 2905 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions()));
2927 channel->SetInterface(&network_interface); 2906 channel->SetInterface(&network_interface);
2928 // Default value when DSCP is disabled should be DSCP_DEFAULT. 2907 // Default value when DSCP is disabled should be DSCP_DEFAULT.
2929 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp()); 2908 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp());
2930 2909
2931 config.enable_dscp = true; 2910 config.enable_dscp = true;
2932 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions())); 2911 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions()));
2933 channel->SetInterface(&network_interface); 2912 channel->SetInterface(&network_interface);
2934 EXPECT_EQ(rtc::DSCP_EF, network_interface.dscp()); 2913 EXPECT_EQ(rtc::DSCP_EF, network_interface.dscp());
2935 2914
2936 // Verify that setting the option to false resets the 2915 // Verify that setting the option to false resets the
2937 // DiffServCodePoint. 2916 // DiffServCodePoint.
2938 config.enable_dscp = false; 2917 config.enable_dscp = false;
2939 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions())); 2918 channel.reset(engine_.CreateChannel(&call_, config, cricket::AudioOptions()));
2940 channel->SetInterface(&network_interface); 2919 channel->SetInterface(&network_interface);
2941 // Default value when DSCP is disabled should be DSCP_DEFAULT. 2920 // Default value when DSCP is disabled should be DSCP_DEFAULT.
2942 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp()); 2921 EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface.dscp());
2943 2922
2944 channel->SetInterface(nullptr); 2923 channel->SetInterface(nullptr);
2945 } 2924 }
2946 2925
2947 TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelId) { 2926 TEST_F(WebRtcVoiceEngineTestFake, TestGetReceiveChannelId) {
2948 EXPECT_TRUE(SetupEngine()); 2927 EXPECT_TRUE(SetupChannel());
2949 cricket::WebRtcVoiceMediaChannel* media_channel = 2928 cricket::WebRtcVoiceMediaChannel* media_channel =
2950 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 2929 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2951 EXPECT_EQ(-1, media_channel->GetReceiveChannelId(0)); 2930 EXPECT_EQ(-1, media_channel->GetReceiveChannelId(0));
2952 EXPECT_TRUE(channel_->AddRecvStream( 2931 EXPECT_TRUE(channel_->AddRecvStream(
2953 cricket::StreamParams::CreateLegacy(kSsrc1))); 2932 cricket::StreamParams::CreateLegacy(kSsrc1)));
2954 int channel_id = voe_.GetLastChannel(); 2933 int channel_id = voe_.GetLastChannel();
2955 EXPECT_EQ(channel_id, media_channel->GetReceiveChannelId(kSsrc1)); 2934 EXPECT_EQ(channel_id, media_channel->GetReceiveChannelId(kSsrc1));
2956 EXPECT_EQ(-1, media_channel->GetReceiveChannelId(kSsrc2)); 2935 EXPECT_EQ(-1, media_channel->GetReceiveChannelId(kSsrc2));
2957 EXPECT_TRUE(channel_->AddRecvStream( 2936 EXPECT_TRUE(channel_->AddRecvStream(
2958 cricket::StreamParams::CreateLegacy(kSsrc2))); 2937 cricket::StreamParams::CreateLegacy(kSsrc2)));
2959 int channel_id2 = voe_.GetLastChannel(); 2938 int channel_id2 = voe_.GetLastChannel();
2960 EXPECT_EQ(channel_id2, media_channel->GetReceiveChannelId(kSsrc2)); 2939 EXPECT_EQ(channel_id2, media_channel->GetReceiveChannelId(kSsrc2));
2961 } 2940 }
2962 2941
2963 TEST_F(WebRtcVoiceEngineTestFake, TestGetSendChannelId) { 2942 TEST_F(WebRtcVoiceEngineTestFake, TestGetSendChannelId) {
2964 EXPECT_TRUE(SetupEngine()); 2943 EXPECT_TRUE(SetupChannel());
2965 cricket::WebRtcVoiceMediaChannel* media_channel = 2944 cricket::WebRtcVoiceMediaChannel* media_channel =
2966 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 2945 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
2967 EXPECT_EQ(-1, media_channel->GetSendChannelId(0)); 2946 EXPECT_EQ(-1, media_channel->GetSendChannelId(0));
2968 EXPECT_TRUE(channel_->AddSendStream( 2947 EXPECT_TRUE(channel_->AddSendStream(
2969 cricket::StreamParams::CreateLegacy(kSsrc1))); 2948 cricket::StreamParams::CreateLegacy(kSsrc1)));
2970 int channel_id = voe_.GetLastChannel(); 2949 int channel_id = voe_.GetLastChannel();
2971 EXPECT_EQ(channel_id, media_channel->GetSendChannelId(kSsrc1)); 2950 EXPECT_EQ(channel_id, media_channel->GetSendChannelId(kSsrc1));
2972 EXPECT_EQ(-1, media_channel->GetSendChannelId(kSsrc2)); 2951 EXPECT_EQ(-1, media_channel->GetSendChannelId(kSsrc2));
2973 EXPECT_TRUE(channel_->AddSendStream( 2952 EXPECT_TRUE(channel_->AddSendStream(
2974 cricket::StreamParams::CreateLegacy(kSsrc2))); 2953 cricket::StreamParams::CreateLegacy(kSsrc2)));
2975 int channel_id2 = voe_.GetLastChannel(); 2954 int channel_id2 = voe_.GetLastChannel();
2976 EXPECT_EQ(channel_id2, media_channel->GetSendChannelId(kSsrc2)); 2955 EXPECT_EQ(channel_id2, media_channel->GetSendChannelId(kSsrc2));
2977 } 2956 }
2978 2957
2979 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolume) { 2958 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolume) {
2980 EXPECT_TRUE(SetupEngine()); 2959 EXPECT_TRUE(SetupChannel());
2981 EXPECT_FALSE(channel_->SetOutputVolume(kSsrc2, 0.5)); 2960 EXPECT_FALSE(channel_->SetOutputVolume(kSsrc2, 0.5));
2982 cricket::StreamParams stream; 2961 cricket::StreamParams stream;
2983 stream.ssrcs.push_back(kSsrc2); 2962 stream.ssrcs.push_back(kSsrc2);
2984 EXPECT_TRUE(channel_->AddRecvStream(stream)); 2963 EXPECT_TRUE(channel_->AddRecvStream(stream));
2985 int channel_id = voe_.GetLastChannel(); 2964 int channel_id = voe_.GetLastChannel();
2986 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc2, 3)); 2965 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc2, 3));
2987 float scale = 0; 2966 float scale = 0;
2988 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale)); 2967 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale));
2989 EXPECT_DOUBLE_EQ(3, scale); 2968 EXPECT_DOUBLE_EQ(3, scale);
2990 } 2969 }
2991 2970
2992 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolumeDefaultRecvStream) { 2971 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolumeDefaultRecvStream) {
2993 EXPECT_TRUE(SetupEngine()); 2972 EXPECT_TRUE(SetupChannel());
2994 EXPECT_TRUE(channel_->SetOutputVolume(0, 2)); 2973 EXPECT_TRUE(channel_->SetOutputVolume(0, 2));
2995 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 2974 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2996 int channel_id = voe_.GetLastChannel(); 2975 int channel_id = voe_.GetLastChannel();
2997 float scale = 0; 2976 float scale = 0;
2998 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale)); 2977 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale));
2999 EXPECT_DOUBLE_EQ(2, scale); 2978 EXPECT_DOUBLE_EQ(2, scale);
3000 EXPECT_TRUE(channel_->SetOutputVolume(0, 3)); 2979 EXPECT_TRUE(channel_->SetOutputVolume(0, 3));
3001 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale)); 2980 EXPECT_EQ(0, voe_.GetChannelOutputVolumeScaling(channel_id, scale));
3002 EXPECT_DOUBLE_EQ(3, scale); 2981 EXPECT_DOUBLE_EQ(3, scale);
3003 } 2982 }
3004 2983
3005 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) { 2984 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) {
3006 const uint32_t kAudioSsrc = 123; 2985 const uint32_t kAudioSsrc = 123;
3007 const std::string kSyncLabel = "AvSyncLabel"; 2986 const std::string kSyncLabel = "AvSyncLabel";
3008 2987
3009 EXPECT_TRUE(SetupEngineWithSendStream()); 2988 EXPECT_TRUE(SetupSendStream());
3010 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc); 2989 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc);
3011 sp.sync_label = kSyncLabel; 2990 sp.sync_label = kSyncLabel;
3012 // Creating two channels to make sure that sync label is set properly for both 2991 // Creating two channels to make sure that sync label is set properly for both
3013 // the default voice channel and following ones. 2992 // the default voice channel and following ones.
3014 EXPECT_TRUE(channel_->AddRecvStream(sp)); 2993 EXPECT_TRUE(channel_->AddRecvStream(sp));
3015 sp.ssrcs[0] += 1; 2994 sp.ssrcs[0] += 1;
3016 EXPECT_TRUE(channel_->AddRecvStream(sp)); 2995 EXPECT_TRUE(channel_->AddRecvStream(sp));
3017 2996
3018 ASSERT_EQ(2, call_.GetAudioReceiveStreams().size()); 2997 ASSERT_EQ(2, call_.GetAudioReceiveStreams().size());
3019 EXPECT_EQ(kSyncLabel, 2998 EXPECT_EQ(kSyncLabel,
3020 call_.GetAudioReceiveStream(kAudioSsrc)->GetConfig().sync_group) 2999 call_.GetAudioReceiveStream(kAudioSsrc)->GetConfig().sync_group)
3021 << "SyncGroup should be set based on sync_label"; 3000 << "SyncGroup should be set based on sync_label";
3022 EXPECT_EQ(kSyncLabel, 3001 EXPECT_EQ(kSyncLabel,
3023 call_.GetAudioReceiveStream(kAudioSsrc + 1)->GetConfig().sync_group) 3002 call_.GetAudioReceiveStream(kAudioSsrc + 1)->GetConfig().sync_group)
3024 << "SyncGroup should be set based on sync_label"; 3003 << "SyncGroup should be set based on sync_label";
3025 } 3004 }
3026 3005
3027 // TODO(solenberg): Remove, once recv streams are configured through Call. 3006 // TODO(solenberg): Remove, once recv streams are configured through Call.
3028 // (This is then covered by TestSetRecvRtpHeaderExtensions.) 3007 // (This is then covered by TestSetRecvRtpHeaderExtensions.)
3029 TEST_F(WebRtcVoiceEngineTestFake, ConfiguresAudioReceiveStreamRtpExtensions) { 3008 TEST_F(WebRtcVoiceEngineTestFake, ConfiguresAudioReceiveStreamRtpExtensions) {
3030 // Test that setting the header extensions results in the expected state 3009 // Test that setting the header extensions results in the expected state
3031 // changes on an associated Call. 3010 // changes on an associated Call.
3032 std::vector<uint32_t> ssrcs; 3011 std::vector<uint32_t> ssrcs;
3033 ssrcs.push_back(223); 3012 ssrcs.push_back(223);
3034 ssrcs.push_back(224); 3013 ssrcs.push_back(224);
3035 3014
3036 EXPECT_TRUE(SetupEngineWithSendStream()); 3015 EXPECT_TRUE(SetupSendStream());
3037 cricket::WebRtcVoiceMediaChannel* media_channel = 3016 cricket::WebRtcVoiceMediaChannel* media_channel =
3038 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 3017 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3039 EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_)); 3018 EXPECT_TRUE(media_channel->SetSendParameters(send_parameters_));
3040 for (uint32_t ssrc : ssrcs) { 3019 for (uint32_t ssrc : ssrcs) {
3041 EXPECT_TRUE(media_channel->AddRecvStream( 3020 EXPECT_TRUE(media_channel->AddRecvStream(
3042 cricket::StreamParams::CreateLegacy(ssrc))); 3021 cricket::StreamParams::CreateLegacy(ssrc)));
3043 } 3022 }
3044 3023
3045 EXPECT_EQ(2, call_.GetAudioReceiveStreams().size()); 3024 EXPECT_EQ(2, call_.GetAudioReceiveStreams().size());
3046 for (uint32_t ssrc : ssrcs) { 3025 for (uint32_t ssrc : ssrcs) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
3083 const uint32_t kAudioSsrc = 1; 3062 const uint32_t kAudioSsrc = 1;
3084 rtc::CopyOnWriteBuffer kPcmuPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3063 rtc::CopyOnWriteBuffer kPcmuPacket(kPcmuFrame, sizeof(kPcmuFrame));
3085 static const unsigned char kRtcp[] = { 3064 static const unsigned char kRtcp[] = {
3086 0x80, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, 3065 0x80, 0xc9, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02,
3087 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 3066 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
3088 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 3067 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3089 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 3068 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
3090 }; 3069 };
3091 rtc::CopyOnWriteBuffer kRtcpPacket(kRtcp, sizeof(kRtcp)); 3070 rtc::CopyOnWriteBuffer kRtcpPacket(kRtcp, sizeof(kRtcp));
3092 3071
3093 EXPECT_TRUE(SetupEngineWithSendStream()); 3072 EXPECT_TRUE(SetupSendStream());
3094 cricket::WebRtcVoiceMediaChannel* media_channel = 3073 cricket::WebRtcVoiceMediaChannel* media_channel =
3095 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_); 3074 static_cast<cricket::WebRtcVoiceMediaChannel*>(channel_);
3096 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 3075 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
3097 EXPECT_TRUE(media_channel->AddRecvStream( 3076 EXPECT_TRUE(media_channel->AddRecvStream(
3098 cricket::StreamParams::CreateLegacy(kAudioSsrc))); 3077 cricket::StreamParams::CreateLegacy(kAudioSsrc)));
3099 3078
3100 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size()); 3079 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size());
3101 const cricket::FakeAudioReceiveStream* s = 3080 const cricket::FakeAudioReceiveStream* s =
3102 call_.GetAudioReceiveStream(kAudioSsrc); 3081 call_.GetAudioReceiveStream(kAudioSsrc);
3103 EXPECT_EQ(0, s->received_packets()); 3082 EXPECT_EQ(0, s->received_packets());
3104 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime()); 3083 channel_->OnPacketReceived(&kPcmuPacket, rtc::PacketTime());
3105 EXPECT_EQ(1, s->received_packets()); 3084 EXPECT_EQ(1, s->received_packets());
3106 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime()); 3085 channel_->OnRtcpReceived(&kRtcpPacket, rtc::PacketTime());
3107 EXPECT_EQ(2, s->received_packets()); 3086 EXPECT_EQ(2, s->received_packets());
3108 } 3087 }
3109 3088
3110 // All receive channels should be associated with the first send channel, 3089 // All receive channels should be associated with the first send channel,
3111 // since they do not send RTCP SR. 3090 // since they do not send RTCP SR.
3112 TEST_F(WebRtcVoiceEngineTestFake, AssociateFirstSendChannel) { 3091 TEST_F(WebRtcVoiceEngineTestFake, AssociateFirstSendChannel) {
3113 EXPECT_TRUE(SetupEngineWithSendStream()); 3092 EXPECT_TRUE(SetupSendStream());
3114 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 3093 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
3115 int default_channel = voe_.GetLastChannel(); 3094 int default_channel = voe_.GetLastChannel();
3116 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 3095 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3117 int recv_ch = voe_.GetLastChannel(); 3096 int recv_ch = voe_.GetLastChannel();
3118 EXPECT_NE(recv_ch, default_channel); 3097 EXPECT_NE(recv_ch, default_channel);
3119 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel); 3098 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3120 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2))); 3099 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
3121 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel); 3100 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3122 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); 3101 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3)));
3123 recv_ch = voe_.GetLastChannel(); 3102 recv_ch = voe_.GetLastChannel();
3124 EXPECT_NE(recv_ch, default_channel); 3103 EXPECT_NE(recv_ch, default_channel);
3125 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel); 3104 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), default_channel);
3126 } 3105 }
3127 3106
3128 TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelResetUponDeleteChannnel) { 3107 TEST_F(WebRtcVoiceEngineTestFake, AssociateChannelResetUponDeleteChannnel) {
3129 EXPECT_TRUE(SetupEngineWithSendStream()); 3108 EXPECT_TRUE(SetupSendStream());
3130 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); 3109 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_));
3131 3110
3132 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 3111 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1)));
3133 int recv_ch = voe_.GetLastChannel(); 3112 int recv_ch = voe_.GetLastChannel();
3134 3113
3135 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2))); 3114 EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2)));
3136 int send_ch = voe_.GetLastChannel(); 3115 int send_ch = voe_.GetLastChannel();
3137 3116
3138 // Manually associate |recv_ch| to |send_ch|. This test is to verify a 3117 // Manually associate |recv_ch| to |send_ch|. This test is to verify a
3139 // deleting logic, i.e., deleting |send_ch| will reset the associate send 3118 // deleting logic, i.e., deleting |send_ch| will reset the associate send
3140 // channel of |recv_ch|.This is not a common case, since, normally, only the 3119 // channel of |recv_ch|.This is not a common case, since, normally, only the
3141 // default channel can be associated. However, the default is not deletable. 3120 // default channel can be associated. However, the default is not deletable.
3142 // So we force the |recv_ch| to associate with a non-default channel. 3121 // So we force the |recv_ch| to associate with a non-default channel.
3143 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch)); 3122 EXPECT_EQ(0, voe_.AssociateSendChannel(recv_ch, send_ch));
3144 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch); 3123 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), send_ch);
3145 3124
3146 EXPECT_TRUE(channel_->RemoveSendStream(2)); 3125 EXPECT_TRUE(channel_->RemoveSendStream(2));
3147 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1); 3126 EXPECT_EQ(voe_.GetAssociateSendChannel(recv_ch), -1);
3148 } 3127 }
3149 3128
3150 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSink) { 3129 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSink) {
3151 EXPECT_TRUE(SetupEngine()); 3130 EXPECT_TRUE(SetupChannel());
3152 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink()); 3131 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink());
3153 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink()); 3132 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink());
3154 3133
3155 // Setting the sink before a recv stream exists should do nothing. 3134 // Setting the sink before a recv stream exists should do nothing.
3156 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_1)); 3135 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_1));
3157 EXPECT_TRUE( 3136 EXPECT_TRUE(
3158 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1))); 3137 channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc1)));
3159 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); 3138 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink());
3160 3139
3161 // Now try actually setting the sink. 3140 // Now try actually setting the sink.
3162 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_2)); 3141 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_2));
3163 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink()); 3142 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink());
3164 3143
3165 // Now try resetting it. 3144 // Now try resetting it.
3166 channel_->SetRawAudioSink(kSsrc1, nullptr); 3145 channel_->SetRawAudioSink(kSsrc1, nullptr);
3167 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); 3146 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink());
3168 } 3147 }
3169 3148
3170 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) { 3149 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) {
3171 EXPECT_TRUE(SetupEngine()); 3150 EXPECT_TRUE(SetupChannel());
3172 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink()); 3151 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink());
3173 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink()); 3152 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink());
3174 3153
3175 // Should be able to set a default sink even when no stream exists. 3154 // Should be able to set a default sink even when no stream exists.
3176 channel_->SetRawAudioSink(0, std::move(fake_sink_1)); 3155 channel_->SetRawAudioSink(0, std::move(fake_sink_1));
3177 3156
3178 // Create default channel and ensure it's assigned the default sink. 3157 // Create default channel and ensure it's assigned the default sink.
3179 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3158 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3180 EXPECT_NE(nullptr, GetRecvStream(0x01).sink()); 3159 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3181 3160
3182 // Try resetting the default sink. 3161 // Try resetting the default sink.
3183 channel_->SetRawAudioSink(0, nullptr); 3162 channel_->SetRawAudioSink(0, nullptr);
3184 EXPECT_EQ(nullptr, GetRecvStream(0x01).sink()); 3163 EXPECT_EQ(nullptr, GetRecvStream(0x01).sink());
3185 3164
3186 // Try setting the default sink while the default stream exists. 3165 // Try setting the default sink while the default stream exists.
3187 channel_->SetRawAudioSink(0, std::move(fake_sink_2)); 3166 channel_->SetRawAudioSink(0, std::move(fake_sink_2));
3188 EXPECT_NE(nullptr, GetRecvStream(0x01).sink()); 3167 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3189 3168
3190 // If we remove and add a default stream, it should get the same sink. 3169 // If we remove and add a default stream, it should get the same sink.
3191 EXPECT_TRUE(channel_->RemoveRecvStream(0x01)); 3170 EXPECT_TRUE(channel_->RemoveRecvStream(0x01));
3192 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3171 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3193 EXPECT_NE(nullptr, GetRecvStream(0x01).sink()); 3172 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
3194 } 3173 }
3195 3174
3196 // Test that, just like the video channel, the voice channel communicates the 3175 // Test that, just like the video channel, the voice channel communicates the
3197 // network state to the call. 3176 // network state to the call.
3198 TEST_F(WebRtcVoiceEngineTestFake, OnReadyToSendSignalsNetworkState) { 3177 TEST_F(WebRtcVoiceEngineTestFake, OnReadyToSendSignalsNetworkState) {
3199 EXPECT_TRUE(SetupEngine()); 3178 EXPECT_TRUE(SetupChannel());
3200 3179
3201 EXPECT_EQ(webrtc::kNetworkUp, 3180 EXPECT_EQ(webrtc::kNetworkUp,
3202 call_.GetNetworkState(webrtc::MediaType::AUDIO)); 3181 call_.GetNetworkState(webrtc::MediaType::AUDIO));
3203 EXPECT_EQ(webrtc::kNetworkUp, 3182 EXPECT_EQ(webrtc::kNetworkUp,
3204 call_.GetNetworkState(webrtc::MediaType::VIDEO)); 3183 call_.GetNetworkState(webrtc::MediaType::VIDEO));
3205 3184
3206 channel_->OnReadyToSend(false); 3185 channel_->OnReadyToSend(false);
3207 EXPECT_EQ(webrtc::kNetworkDown, 3186 EXPECT_EQ(webrtc::kNetworkDown,
3208 call_.GetNetworkState(webrtc::MediaType::AUDIO)); 3187 call_.GetNetworkState(webrtc::MediaType::AUDIO));
3209 EXPECT_EQ(webrtc::kNetworkUp, 3188 EXPECT_EQ(webrtc::kNetworkUp,
3210 call_.GetNetworkState(webrtc::MediaType::VIDEO)); 3189 call_.GetNetworkState(webrtc::MediaType::VIDEO));
3211 3190
3212 channel_->OnReadyToSend(true); 3191 channel_->OnReadyToSend(true);
3213 EXPECT_EQ(webrtc::kNetworkUp, 3192 EXPECT_EQ(webrtc::kNetworkUp,
3214 call_.GetNetworkState(webrtc::MediaType::AUDIO)); 3193 call_.GetNetworkState(webrtc::MediaType::AUDIO));
3215 EXPECT_EQ(webrtc::kNetworkUp, 3194 EXPECT_EQ(webrtc::kNetworkUp,
3216 call_.GetNetworkState(webrtc::MediaType::VIDEO)); 3195 call_.GetNetworkState(webrtc::MediaType::VIDEO));
3217 } 3196 }
3218 3197
3219 // Tests that the library initializes and shuts down properly. 3198 // Tests that the library initializes and shuts down properly.
3220 TEST(WebRtcVoiceEngineTest, StartupShutdown) { 3199 TEST(WebRtcVoiceEngineTest, StartupShutdown) {
3221 cricket::WebRtcVoiceEngine engine; 3200 cricket::WebRtcVoiceEngine engine(nullptr);
3222 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3223 std::unique_ptr<webrtc::Call> call( 3201 std::unique_ptr<webrtc::Call> call(
3224 webrtc::Call::Create(webrtc::Call::Config())); 3202 webrtc::Call::Create(webrtc::Call::Config()));
3225 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3203 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3226 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3204 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3227 EXPECT_TRUE(channel != nullptr); 3205 EXPECT_TRUE(channel != nullptr);
3228 delete channel; 3206 delete channel;
3229 engine.Terminate(); 3207 }
3230 3208
3231 // Reinit to catch regression where VoiceEngineObserver reference is lost 3209 // Tests that reference counting on the external ADM is correct.
3232 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3210 TEST(WebRtcVoiceEngineTest, StartupShutdownWithExternADM) {
3233 engine.Terminate(); 3211 cricket::FakeAudioDeviceModule adm;
3212 {
3213 cricket::WebRtcVoiceEngine engine(&adm);
3214 std::unique_ptr<webrtc::Call> call(
3215 webrtc::Call::Create(webrtc::Call::Config()));
3216 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3217 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3218 EXPECT_TRUE(channel != nullptr);
3219 delete channel;
3220 }
3234 } 3221 }
3235 3222
3236 // Tests that the library is configured with the codecs we want. 3223 // Tests that the library is configured with the codecs we want.
3237 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) { 3224 TEST(WebRtcVoiceEngineTest, HasCorrectCodecs) {
3238 // Check codecs by name. 3225 // Check codecs by name.
3239 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( 3226 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(
3240 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0), nullptr)); 3227 cricket::AudioCodec(96, "OPUS", 48000, 0, 2, 0), nullptr));
3241 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( 3228 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(
3242 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0), nullptr)); 3229 cricket::AudioCodec(96, "ISAC", 16000, 0, 1, 0), nullptr));
3243 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst( 3230 EXPECT_TRUE(cricket::WebRtcVoiceEngine::ToCodecInst(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
3281 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3268 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3282 cricket::AudioCodec(88, "", 0, 0, 1, 0), nullptr)); 3269 cricket::AudioCodec(88, "", 0, 0, 1, 0), nullptr));
3283 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3270 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3284 cricket::AudioCodec(0, "", 0, 0, 2, 0), nullptr)); 3271 cricket::AudioCodec(0, "", 0, 0, 2, 0), nullptr));
3285 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3272 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3286 cricket::AudioCodec(0, "", 5000, 0, 1, 0), nullptr)); 3273 cricket::AudioCodec(0, "", 5000, 0, 1, 0), nullptr));
3287 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst( 3274 EXPECT_FALSE(cricket::WebRtcVoiceEngine::ToCodecInst(
3288 cricket::AudioCodec(0, "", 0, 5000, 1, 0), nullptr)); 3275 cricket::AudioCodec(0, "", 0, 5000, 1, 0), nullptr));
3289 3276
3290 // Verify the payload id of common audio codecs, including CN, ISAC, and G722. 3277 // Verify the payload id of common audio codecs, including CN, ISAC, and G722.
3291 cricket::WebRtcVoiceEngine engine; 3278 cricket::WebRtcVoiceEngine engine(nullptr);
3292 for (std::vector<cricket::AudioCodec>::const_iterator it = 3279 for (std::vector<cricket::AudioCodec>::const_iterator it =
3293 engine.codecs().begin(); it != engine.codecs().end(); ++it) { 3280 engine.codecs().begin(); it != engine.codecs().end(); ++it) {
3294 if (it->name == "CN" && it->clockrate == 16000) { 3281 if (it->name == "CN" && it->clockrate == 16000) {
3295 EXPECT_EQ(105, it->id); 3282 EXPECT_EQ(105, it->id);
3296 } else if (it->name == "CN" && it->clockrate == 32000) { 3283 } else if (it->name == "CN" && it->clockrate == 32000) {
3297 EXPECT_EQ(106, it->id); 3284 EXPECT_EQ(106, it->id);
3298 } else if (it->name == "ISAC" && it->clockrate == 16000) { 3285 } else if (it->name == "ISAC" && it->clockrate == 16000) {
3299 EXPECT_EQ(103, it->id); 3286 EXPECT_EQ(103, it->id);
3300 } else if (it->name == "ISAC" && it->clockrate == 32000) { 3287 } else if (it->name == "ISAC" && it->clockrate == 32000) {
3301 EXPECT_EQ(104, it->id); 3288 EXPECT_EQ(104, it->id);
3302 } else if (it->name == "G722" && it->clockrate == 8000) { 3289 } else if (it->name == "G722" && it->clockrate == 8000) {
3303 EXPECT_EQ(9, it->id); 3290 EXPECT_EQ(9, it->id);
3304 } else if (it->name == "telephone-event") { 3291 } else if (it->name == "telephone-event") {
3305 EXPECT_EQ(126, it->id); 3292 EXPECT_EQ(126, it->id);
3306 } else if (it->name == "red") { 3293 } else if (it->name == "red") {
3307 EXPECT_EQ(127, it->id); 3294 EXPECT_EQ(127, it->id);
3308 } else if (it->name == "opus") { 3295 } else if (it->name == "opus") {
3309 EXPECT_EQ(111, it->id); 3296 EXPECT_EQ(111, it->id);
3310 ASSERT_TRUE(it->params.find("minptime") != it->params.end()); 3297 ASSERT_TRUE(it->params.find("minptime") != it->params.end());
3311 EXPECT_EQ("10", it->params.find("minptime")->second); 3298 EXPECT_EQ("10", it->params.find("minptime")->second);
3312 ASSERT_TRUE(it->params.find("maxptime") != it->params.end()); 3299 ASSERT_TRUE(it->params.find("maxptime") != it->params.end());
3313 EXPECT_EQ("60", it->params.find("maxptime")->second); 3300 EXPECT_EQ("60", it->params.find("maxptime")->second);
3314 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end()); 3301 ASSERT_TRUE(it->params.find("useinbandfec") != it->params.end());
3315 EXPECT_EQ("1", it->params.find("useinbandfec")->second); 3302 EXPECT_EQ("1", it->params.find("useinbandfec")->second);
3316 } 3303 }
3317 } 3304 }
3318 engine.Terminate();
3319 } 3305 }
3320 3306
3321 // Tests that VoE supports at least 32 channels 3307 // Tests that VoE supports at least 32 channels
3322 TEST(WebRtcVoiceEngineTest, Has32Channels) { 3308 TEST(WebRtcVoiceEngineTest, Has32Channels) {
3323 cricket::WebRtcVoiceEngine engine; 3309 cricket::WebRtcVoiceEngine engine(nullptr);
3324 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3325 std::unique_ptr<webrtc::Call> call( 3310 std::unique_ptr<webrtc::Call> call(
3326 webrtc::Call::Create(webrtc::Call::Config())); 3311 webrtc::Call::Create(webrtc::Call::Config()));
3327 3312
3328 cricket::VoiceMediaChannel* channels[32]; 3313 cricket::VoiceMediaChannel* channels[32];
3329 int num_channels = 0; 3314 int num_channels = 0;
3330 while (num_channels < arraysize(channels)) { 3315 while (num_channels < arraysize(channels)) {
3331 cricket::VoiceMediaChannel* channel = engine.CreateChannel( 3316 cricket::VoiceMediaChannel* channel = engine.CreateChannel(
3332 call.get(), cricket::MediaConfig(), cricket::AudioOptions()); 3317 call.get(), cricket::MediaConfig(), cricket::AudioOptions());
3333 if (!channel) 3318 if (!channel)
3334 break; 3319 break;
3335 channels[num_channels++] = channel; 3320 channels[num_channels++] = channel;
3336 } 3321 }
3337 3322
3338 int expected = arraysize(channels); 3323 int expected = arraysize(channels);
3339 EXPECT_EQ(expected, num_channels); 3324 EXPECT_EQ(expected, num_channels);
3340 3325
3341 while (num_channels > 0) { 3326 while (num_channels > 0) {
3342 delete channels[--num_channels]; 3327 delete channels[--num_channels];
3343 } 3328 }
3344 engine.Terminate();
3345 } 3329 }
3346 3330
3347 // Test that we set our preferred codecs properly. 3331 // Test that we set our preferred codecs properly.
3348 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) { 3332 TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
3349 cricket::WebRtcVoiceEngine engine; 3333 cricket::WebRtcVoiceEngine engine(nullptr);
3350 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3351 std::unique_ptr<webrtc::Call> call( 3334 std::unique_ptr<webrtc::Call> call(
3352 webrtc::Call::Create(webrtc::Call::Config())); 3335 webrtc::Call::Create(webrtc::Call::Config()));
3353 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(), 3336 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::MediaConfig(),
3354 cricket::AudioOptions(), call.get()); 3337 cricket::AudioOptions(), call.get());
3355 cricket::AudioRecvParameters parameters; 3338 cricket::AudioRecvParameters parameters;
3356 parameters.codecs = engine.codecs(); 3339 parameters.codecs = engine.codecs();
3357 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3340 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3358 } 3341 }
OLDNEW
« no previous file with comments | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | webrtc/pc/channelmanager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698