blob: aeba5a81682cf9350cb2f83f11d2b5e3362a8aab [file] [log] [blame]
solenbergc7a8b082015-10-16 14:35:07 -07001/*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#include <list>
kwiberg1c07c702017-03-27 07:15:49 -070012#include <map>
kwibergb25345e2016-03-12 06:10:44 -080013#include <memory>
zstein7cb69d52017-05-08 11:52:38 -070014#include <utility>
solenbergc7a8b082015-10-16 14:35:07 -070015
Karl Wibergf3850f62017-11-02 13:04:41 +010016#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/test/mock_audio_mixer.h"
18#include "call/audio_state.h"
19#include "call/call.h"
20#include "call/fake_rtp_transport_controller_send.h"
21#include "logging/rtc_event_log/rtc_event_log.h"
22#include "modules/audio_device/include/mock_audio_device.h"
23#include "modules/audio_mixer/audio_mixer_impl.h"
24#include "modules/congestion_controller/include/mock/mock_send_side_congestion_controller.h"
25#include "modules/pacing/mock/mock_paced_sender.h"
26#include "modules/rtp_rtcp/include/rtp_rtcp.h"
27#include "rtc_base/ptr_util.h"
28#include "test/fake_encoder.h"
29#include "test/gtest.h"
30#include "test/mock_audio_decoder_factory.h"
31#include "test/mock_transport.h"
32#include "test/mock_voice_engine.h"
solenbergc7a8b082015-10-16 14:35:07 -070033
34namespace {
35
36struct CallHelper {
ossu29b1a8d2016-06-13 07:34:51 -070037 explicit CallHelper(
38 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
39 : voice_engine_(decoder_factory) {
solenberg566ef242015-11-06 15:34:49 -080040 webrtc::AudioState::Config audio_state_config;
41 audio_state_config.voice_engine = &voice_engine_;
aleloi10111bc2016-11-17 06:48:48 -080042 audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create();
peaha9cc40b2017-06-29 08:32:09 -070043 audio_state_config.audio_processing = webrtc::AudioProcessing::Create();
aleloidd310712016-11-17 06:28:59 -080044 EXPECT_CALL(voice_engine_, audio_device_module());
aleloidd310712016-11-17 06:28:59 -080045 EXPECT_CALL(voice_engine_, audio_transport());
skvlad11a9cbf2016-10-07 11:53:05 -070046 webrtc::Call::Config config(&event_log_);
solenberg566ef242015-11-06 15:34:49 -080047 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070048 call_.reset(webrtc::Call::Create(config));
49 }
50
51 webrtc::Call* operator->() { return call_.get(); }
solenberg7602aab2016-11-14 11:30:07 -080052 webrtc::test::MockVoiceEngine* voice_engine() { return &voice_engine_; }
solenbergc7a8b082015-10-16 14:35:07 -070053
54 private:
solenberg3a941542015-11-16 07:34:50 -080055 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
skvlad11a9cbf2016-10-07 11:53:05 -070056 webrtc::RtcEventLogNullImpl event_log_;
kwibergb25345e2016-03-12 06:10:44 -080057 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 14:35:07 -070058};
59} // namespace
60
61namespace webrtc {
62
63TEST(CallTest, ConstructDestruct) {
64 CallHelper call;
65}
66
67TEST(CallTest, CreateDestroy_AudioSendStream) {
68 CallHelper call;
69 AudioSendStream::Config config(nullptr);
70 config.rtp.ssrc = 42;
71 config.voe_channel_id = 123;
72 AudioSendStream* stream = call->CreateAudioSendStream(config);
73 EXPECT_NE(stream, nullptr);
74 call->DestroyAudioSendStream(stream);
75}
76
77TEST(CallTest, CreateDestroy_AudioReceiveStream) {
ossu29b1a8d2016-06-13 07:34:51 -070078 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
79 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
80 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070081 AudioReceiveStream::Config config;
82 config.rtp.remote_ssrc = 42;
83 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -070084 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -070085 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
86 EXPECT_NE(stream, nullptr);
87 call->DestroyAudioReceiveStream(stream);
88}
89
90TEST(CallTest, CreateDestroy_AudioSendStreams) {
91 CallHelper call;
92 AudioSendStream::Config config(nullptr);
93 config.voe_channel_id = 123;
94 std::list<AudioSendStream*> streams;
95 for (int i = 0; i < 2; ++i) {
96 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
97 config.rtp.ssrc = ssrc;
98 AudioSendStream* stream = call->CreateAudioSendStream(config);
99 EXPECT_NE(stream, nullptr);
100 if (ssrc & 1) {
101 streams.push_back(stream);
102 } else {
103 streams.push_front(stream);
104 }
105 }
106 for (auto s : streams) {
107 call->DestroyAudioSendStream(s);
108 }
109 streams.clear();
110 }
111}
112
113TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
ossu29b1a8d2016-06-13 07:34:51 -0700114 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
115 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
116 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -0700117 AudioReceiveStream::Config config;
118 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -0700119 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -0700120 std::list<AudioReceiveStream*> streams;
121 for (int i = 0; i < 2; ++i) {
122 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
123 config.rtp.remote_ssrc = ssrc;
124 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
125 EXPECT_NE(stream, nullptr);
126 if (ssrc & 1) {
127 streams.push_back(stream);
128 } else {
129 streams.push_front(stream);
130 }
131 }
132 for (auto s : streams) {
133 call->DestroyAudioReceiveStream(s);
134 }
135 streams.clear();
136 }
137}
brandtr25445d32016-10-23 23:37:14 -0700138
solenberg7602aab2016-11-14 11:30:07 -0800139TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) {
140 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
141 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
142 CallHelper call(decoder_factory);
ossuc3d4b482017-05-23 06:07:11 -0700143 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 11:30:07 -0800144
145 constexpr int kRecvChannelId = 101;
146
147 // Set up the mock to create a channel proxy which we know of, so that we can
148 // add our expectations to it.
149 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
150 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
151 .WillRepeatedly(testing::Invoke([&](int channel_id) {
152 test::MockVoEChannelProxy* channel_proxy =
153 new testing::NiceMock<test::MockVoEChannelProxy>();
154 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
155 .WillRepeatedly(testing::ReturnRef(decoder_factory));
kwiberg1c07c702017-03-27 07:15:49 -0700156 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_))
157 .WillRepeatedly(testing::Invoke(
158 [](const std::map<int, SdpAudioFormat>& codecs) {
159 EXPECT_THAT(codecs, testing::IsEmpty());
160 }));
ossuc3d4b482017-05-23 06:07:11 -0700161 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
162 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 11:30:07 -0800163 // If being called for the send channel, save a pointer to the channel
164 // proxy for later.
165 if (channel_id == kRecvChannelId) {
166 EXPECT_FALSE(recv_channel_proxy);
167 recv_channel_proxy = channel_proxy;
168 }
169 return channel_proxy;
170 }));
171
172 AudioReceiveStream::Config recv_config;
173 recv_config.rtp.remote_ssrc = 42;
174 recv_config.rtp.local_ssrc = 777;
175 recv_config.voe_channel_id = kRecvChannelId;
176 recv_config.decoder_factory = decoder_factory;
177 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
178 EXPECT_NE(recv_stream, nullptr);
179
180 EXPECT_CALL(*recv_channel_proxy, AssociateSendChannel(testing::_)).Times(1);
181 AudioSendStream::Config send_config(nullptr);
182 send_config.rtp.ssrc = 777;
183 send_config.voe_channel_id = 123;
184 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
185 EXPECT_NE(send_stream, nullptr);
186
187 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
188 call->DestroyAudioSendStream(send_stream);
189
190 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
191 call->DestroyAudioReceiveStream(recv_stream);
192}
193
194TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) {
195 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
196 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
197 CallHelper call(decoder_factory);
ossuc3d4b482017-05-23 06:07:11 -0700198 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 11:30:07 -0800199
200 constexpr int kRecvChannelId = 101;
201
202 // Set up the mock to create a channel proxy which we know of, so that we can
203 // add our expectations to it.
204 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
205 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
206 .WillRepeatedly(testing::Invoke([&](int channel_id) {
207 test::MockVoEChannelProxy* channel_proxy =
208 new testing::NiceMock<test::MockVoEChannelProxy>();
209 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
210 .WillRepeatedly(testing::ReturnRef(decoder_factory));
kwiberg1c07c702017-03-27 07:15:49 -0700211 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_))
212 .WillRepeatedly(testing::Invoke(
213 [](const std::map<int, SdpAudioFormat>& codecs) {
214 EXPECT_THAT(codecs, testing::IsEmpty());
215 }));
ossuc3d4b482017-05-23 06:07:11 -0700216 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
217 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 11:30:07 -0800218 // If being called for the send channel, save a pointer to the channel
219 // proxy for later.
220 if (channel_id == kRecvChannelId) {
221 EXPECT_FALSE(recv_channel_proxy);
222 recv_channel_proxy = channel_proxy;
223 // We need to set this expectation here since the channel proxy is
224 // created as a side effect of CreateAudioReceiveStream().
225 EXPECT_CALL(*recv_channel_proxy,
226 AssociateSendChannel(testing::_)).Times(1);
227 }
228 return channel_proxy;
229 }));
230
231 AudioSendStream::Config send_config(nullptr);
232 send_config.rtp.ssrc = 777;
233 send_config.voe_channel_id = 123;
234 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
235 EXPECT_NE(send_stream, nullptr);
236
237 AudioReceiveStream::Config recv_config;
238 recv_config.rtp.remote_ssrc = 42;
239 recv_config.rtp.local_ssrc = 777;
240 recv_config.voe_channel_id = kRecvChannelId;
241 recv_config.decoder_factory = decoder_factory;
242 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
243 EXPECT_NE(recv_stream, nullptr);
244
245 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
246 call->DestroyAudioReceiveStream(recv_stream);
247
248 call->DestroyAudioSendStream(send_stream);
249}
250
brandtr25445d32016-10-23 23:37:14 -0700251TEST(CallTest, CreateDestroy_FlexfecReceiveStream) {
252 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800253 MockTransport rtcp_send_transport;
254 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800255 config.payload_type = 118;
256 config.remote_ssrc = 38837212;
brandtr25445d32016-10-23 23:37:14 -0700257 config.protected_media_ssrcs = {27273};
258
259 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
260 EXPECT_NE(stream, nullptr);
261 call->DestroyFlexfecReceiveStream(stream);
262}
263
264TEST(CallTest, CreateDestroy_FlexfecReceiveStreams) {
265 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800266 MockTransport rtcp_send_transport;
267 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800268 config.payload_type = 118;
brandtr25445d32016-10-23 23:37:14 -0700269 std::list<FlexfecReceiveStream*> streams;
270
271 for (int i = 0; i < 2; ++i) {
272 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
brandtr1cfbd602016-12-08 04:17:53 -0800273 config.remote_ssrc = ssrc;
brandtr25445d32016-10-23 23:37:14 -0700274 config.protected_media_ssrcs = {ssrc + 1};
275 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
276 EXPECT_NE(stream, nullptr);
277 if (ssrc & 1) {
278 streams.push_back(stream);
279 } else {
280 streams.push_front(stream);
281 }
282 }
283 for (auto s : streams) {
284 call->DestroyFlexfecReceiveStream(s);
285 }
286 streams.clear();
287 }
288}
289
290TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) {
291 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800292 MockTransport rtcp_send_transport;
293 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800294 config.payload_type = 118;
brandtr25445d32016-10-23 23:37:14 -0700295 config.protected_media_ssrcs = {1324234};
296 FlexfecReceiveStream* stream;
297 std::list<FlexfecReceiveStream*> streams;
298
brandtr1cfbd602016-12-08 04:17:53 -0800299 config.remote_ssrc = 838383;
brandtr25445d32016-10-23 23:37:14 -0700300 stream = call->CreateFlexfecReceiveStream(config);
301 EXPECT_NE(stream, nullptr);
302 streams.push_back(stream);
303
brandtr1cfbd602016-12-08 04:17:53 -0800304 config.remote_ssrc = 424993;
brandtr25445d32016-10-23 23:37:14 -0700305 stream = call->CreateFlexfecReceiveStream(config);
306 EXPECT_NE(stream, nullptr);
307 streams.push_back(stream);
308
brandtr1cfbd602016-12-08 04:17:53 -0800309 config.remote_ssrc = 99383;
brandtr25445d32016-10-23 23:37:14 -0700310 stream = call->CreateFlexfecReceiveStream(config);
311 EXPECT_NE(stream, nullptr);
312 streams.push_back(stream);
313
brandtr1cfbd602016-12-08 04:17:53 -0800314 config.remote_ssrc = 5548;
brandtr25445d32016-10-23 23:37:14 -0700315 stream = call->CreateFlexfecReceiveStream(config);
316 EXPECT_NE(stream, nullptr);
317 streams.push_back(stream);
318
319 for (auto s : streams) {
320 call->DestroyFlexfecReceiveStream(s);
321 }
322}
323
zstein8c96a142017-05-17 11:49:12 -0700324namespace {
325struct CallBitrateHelper {
zstein4b979802017-06-02 14:37:37 -0700326 CallBitrateHelper() : CallBitrateHelper(Call::Config::BitrateConfig()) {}
zstein7cb69d52017-05-08 11:52:38 -0700327
zstein4b979802017-06-02 14:37:37 -0700328 explicit CallBitrateHelper(const Call::Config::BitrateConfig& bitrate_config)
Stefan Holmer5c8942a2017-08-22 16:16:44 +0200329 : mock_cc_(Clock::GetRealTimeClock(), &event_log_, &pacer_) {
zstein4b979802017-06-02 14:37:37 -0700330 Call::Config config(&event_log_);
331 config.bitrate_config = bitrate_config;
332 call_.reset(
333 Call::Create(config, rtc::MakeUnique<FakeRtpTransportControllerSend>(
Stefan Holmer5c8942a2017-08-22 16:16:44 +0200334 &packet_router_, &pacer_, &mock_cc_)));
zstein4b979802017-06-02 14:37:37 -0700335 }
zstein8c96a142017-05-17 11:49:12 -0700336
337 webrtc::Call* operator->() { return call_.get(); }
338 testing::NiceMock<test::MockSendSideCongestionController>& mock_cc() {
339 return mock_cc_;
340 }
341
342 private:
343 webrtc::RtcEventLogNullImpl event_log_;
344 PacketRouter packet_router_;
Stefan Holmer5c8942a2017-08-22 16:16:44 +0200345 testing::NiceMock<MockPacedSender> pacer_;
zstein8c96a142017-05-17 11:49:12 -0700346 testing::NiceMock<test::MockSendSideCongestionController> mock_cc_;
347 std::unique_ptr<Call> call_;
348};
349} // namespace
350
351TEST(CallBitrateTest, SetBitrateConfigWithValidConfigCallsSetBweBitrates) {
352 CallBitrateHelper call;
zstein7cb69d52017-05-08 11:52:38 -0700353
354 Call::Config::BitrateConfig bitrate_config;
355 bitrate_config.min_bitrate_bps = 1;
356 bitrate_config.start_bitrate_bps = 2;
357 bitrate_config.max_bitrate_bps = 3;
358
zstein8c96a142017-05-17 11:49:12 -0700359 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3));
360 call->SetBitrateConfig(bitrate_config);
361}
362
363TEST(CallBitrateTest, SetBitrateConfigWithDifferentMinCallsSetBweBitrates) {
364 CallBitrateHelper call;
365
366 Call::Config::BitrateConfig bitrate_config;
367 bitrate_config.min_bitrate_bps = 10;
368 bitrate_config.start_bitrate_bps = 20;
369 bitrate_config.max_bitrate_bps = 30;
370 call->SetBitrateConfig(bitrate_config);
371
372 bitrate_config.min_bitrate_bps = 11;
zstein4b979802017-06-02 14:37:37 -0700373 EXPECT_CALL(call.mock_cc(), SetBweBitrates(11, -1, 30));
zstein8c96a142017-05-17 11:49:12 -0700374 call->SetBitrateConfig(bitrate_config);
375}
376
377TEST(CallBitrateTest, SetBitrateConfigWithDifferentStartCallsSetBweBitrates) {
378 CallBitrateHelper call;
379
380 Call::Config::BitrateConfig bitrate_config;
381 bitrate_config.min_bitrate_bps = 10;
382 bitrate_config.start_bitrate_bps = 20;
383 bitrate_config.max_bitrate_bps = 30;
384 call->SetBitrateConfig(bitrate_config);
385
386 bitrate_config.start_bitrate_bps = 21;
387 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, 21, 30));
388 call->SetBitrateConfig(bitrate_config);
389}
390
391TEST(CallBitrateTest, SetBitrateConfigWithDifferentMaxCallsSetBweBitrates) {
392 CallBitrateHelper call;
393
394 Call::Config::BitrateConfig bitrate_config;
395 bitrate_config.min_bitrate_bps = 10;
396 bitrate_config.start_bitrate_bps = 20;
397 bitrate_config.max_bitrate_bps = 30;
398 call->SetBitrateConfig(bitrate_config);
399
400 bitrate_config.max_bitrate_bps = 31;
zstein4b979802017-06-02 14:37:37 -0700401 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, -1, 31));
zstein8c96a142017-05-17 11:49:12 -0700402 call->SetBitrateConfig(bitrate_config);
403}
404
405TEST(CallBitrateTest, SetBitrateConfigWithSameConfigElidesSecondCall) {
406 CallBitrateHelper call;
zstein8c96a142017-05-17 11:49:12 -0700407 Call::Config::BitrateConfig bitrate_config;
408 bitrate_config.min_bitrate_bps = 1;
409 bitrate_config.start_bitrate_bps = 2;
410 bitrate_config.max_bitrate_bps = 3;
411
412 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1);
413 call->SetBitrateConfig(bitrate_config);
414 call->SetBitrateConfig(bitrate_config);
415}
416
417TEST(CallBitrateTest,
418 SetBitrateConfigWithSameMinMaxAndNegativeStartElidesSecondCall) {
419 CallBitrateHelper call;
420
421 Call::Config::BitrateConfig bitrate_config;
422 bitrate_config.min_bitrate_bps = 1;
423 bitrate_config.start_bitrate_bps = 2;
424 bitrate_config.max_bitrate_bps = 3;
425
426 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1);
427 call->SetBitrateConfig(bitrate_config);
428
429 bitrate_config.start_bitrate_bps = -1;
zstein7cb69d52017-05-08 11:52:38 -0700430 call->SetBitrateConfig(bitrate_config);
431}
432
ossuc3d4b482017-05-23 06:07:11 -0700433TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) {
434 constexpr uint32_t kSSRC = 12345;
435 testing::NiceMock<test::MockAudioDeviceModule> mock_adm;
ossuc3d4b482017-05-23 06:07:11 -0700436 rtc::scoped_refptr<test::MockAudioMixer> mock_mixer(
437 new rtc::RefCountedObject<test::MockAudioMixer>);
438
439 // There's similar functionality in cricket::VoEWrapper but it's not reachable
440 // from here. Since we're working on removing VoE interfaces, I doubt it's
441 // worth making VoEWrapper more easily available.
442 struct ScopedVoiceEngine {
443 ScopedVoiceEngine()
444 : voe(VoiceEngine::Create()),
445 base(VoEBase::GetInterface(voe)) {}
446 ~ScopedVoiceEngine() {
447 base->Release();
448 EXPECT_TRUE(VoiceEngine::Delete(voe));
449 }
450
451 VoiceEngine* voe;
452 VoEBase* base;
453 };
454 ScopedVoiceEngine voice_engine;
455
ossuc3d4b482017-05-23 06:07:11 -0700456 AudioState::Config audio_state_config;
457 audio_state_config.voice_engine = voice_engine.voe;
458 audio_state_config.audio_mixer = mock_mixer;
peaha9cc40b2017-06-29 08:32:09 -0700459 audio_state_config.audio_processing = AudioProcessing::Create();
Karl Wibergf3850f62017-11-02 13:04:41 +0100460 voice_engine.base->Init(&mock_adm, audio_state_config.audio_processing.get(),
461 CreateBuiltinAudioDecoderFactory());
ossuc3d4b482017-05-23 06:07:11 -0700462 auto audio_state = AudioState::Create(audio_state_config);
peaha9cc40b2017-06-29 08:32:09 -0700463
ossuc3d4b482017-05-23 06:07:11 -0700464 RtcEventLogNullImpl event_log;
465 Call::Config call_config(&event_log);
466 call_config.audio_state = audio_state;
467 std::unique_ptr<Call> call(Call::Create(call_config));
468
469 auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) {
470 AudioSendStream::Config config(nullptr);
471 config.rtp.ssrc = ssrc;
472 config.voe_channel_id = voice_engine.base->CreateChannel();
473 AudioSendStream* stream = call->CreateAudioSendStream(config);
474 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine.voe);
475 auto channel_proxy = voe_impl->GetChannelProxy(config.voe_channel_id);
476 RtpRtcp* rtp_rtcp = nullptr;
477 RtpReceiver* rtp_receiver = nullptr; // Unused but required for call.
478 channel_proxy->GetRtpRtcp(&rtp_rtcp, &rtp_receiver);
479 const RtpState rtp_state = rtp_rtcp->GetRtpState();
480 call->DestroyAudioSendStream(stream);
481 voice_engine.base->DeleteChannel(config.voe_channel_id);
482 return rtp_state;
483 };
484
485 const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC);
486 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC);
487
488 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number);
489 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp);
490 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp);
491 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms);
492 EXPECT_EQ(rtp_state1.last_timestamp_time_ms,
493 rtp_state2.last_timestamp_time_ms);
494 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent);
495}
zstein4b979802017-06-02 14:37:37 -0700496TEST(CallBitrateTest, BiggerMaskMinUsed) {
497 CallBitrateHelper call;
498 Call::Config::BitrateConfigMask mask;
499 mask.min_bitrate_bps = rtc::Optional<int>(1234);
500
501 EXPECT_CALL(call.mock_cc(),
502 SetBweBitrates(*mask.min_bitrate_bps, testing::_, testing::_));
503 call->SetBitrateConfigMask(mask);
504}
505
506TEST(CallBitrateTest, BiggerConfigMinUsed) {
507 CallBitrateHelper call;
508 Call::Config::BitrateConfigMask mask;
509 mask.min_bitrate_bps = rtc::Optional<int>(1000);
510 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, testing::_));
511 call->SetBitrateConfigMask(mask);
512
513 Call::Config::BitrateConfig config;
514 config.min_bitrate_bps = 1234;
515
516 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1234, testing::_, testing::_));
517 call->SetBitrateConfig(config);
518}
519
520// The last call to set start should be used.
521TEST(CallBitrateTest, LatestStartMaskPreferred) {
522 CallBitrateHelper call;
523 Call::Config::BitrateConfigMask mask;
524 mask.start_bitrate_bps = rtc::Optional<int>(1300);
525
526 EXPECT_CALL(call.mock_cc(),
527 SetBweBitrates(testing::_, *mask.start_bitrate_bps, testing::_));
528 call->SetBitrateConfigMask(mask);
529
530 Call::Config::BitrateConfig bitrate_config;
531 bitrate_config.start_bitrate_bps = 1200;
532
533 EXPECT_CALL(
534 call.mock_cc(),
535 SetBweBitrates(testing::_, bitrate_config.start_bitrate_bps, testing::_));
536 call->SetBitrateConfig(bitrate_config);
537}
538
539TEST(CallBitrateTest, SmallerMaskMaxUsed) {
540 Call::Config::BitrateConfig bitrate_config;
541 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 2000;
542 CallBitrateHelper call(bitrate_config);
543
544 Call::Config::BitrateConfigMask mask;
545 mask.max_bitrate_bps =
546 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 1000);
547
548 EXPECT_CALL(call.mock_cc(),
549 SetBweBitrates(testing::_, testing::_, *mask.max_bitrate_bps));
550 call->SetBitrateConfigMask(mask);
551}
552
553TEST(CallBitrateTest, SmallerConfigMaxUsed) {
554 Call::Config::BitrateConfig bitrate_config;
555 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 1000;
556 CallBitrateHelper call(bitrate_config);
557
558 Call::Config::BitrateConfigMask mask;
559 mask.max_bitrate_bps =
560 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 2000);
561
562 // Expect no calls because nothing changes
563 EXPECT_CALL(call.mock_cc(),
564 SetBweBitrates(testing::_, testing::_, testing::_))
565 .Times(0);
566 call->SetBitrateConfigMask(mask);
567}
568
569TEST(CallBitrateTest, MaskStartLessThanConfigMinClamped) {
570 Call::Config::BitrateConfig bitrate_config;
571 bitrate_config.min_bitrate_bps = 2000;
572 CallBitrateHelper call(bitrate_config);
573
574 Call::Config::BitrateConfigMask mask;
575 mask.start_bitrate_bps = rtc::Optional<int>(1000);
576
577 EXPECT_CALL(call.mock_cc(), SetBweBitrates(2000, 2000, testing::_));
578 call->SetBitrateConfigMask(mask);
579}
580
581TEST(CallBitrateTest, MaskStartGreaterThanConfigMaxClamped) {
582 Call::Config::BitrateConfig bitrate_config;
583 bitrate_config.start_bitrate_bps = 2000;
584 CallBitrateHelper call(bitrate_config);
585
586 Call::Config::BitrateConfigMask mask;
587 mask.max_bitrate_bps = rtc::Optional<int>(1000);
588
589 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, -1, 1000));
590 call->SetBitrateConfigMask(mask);
591}
592
593TEST(CallBitrateTest, MaskMinGreaterThanConfigMaxClamped) {
594 Call::Config::BitrateConfig bitrate_config;
595 bitrate_config.min_bitrate_bps = 2000;
596 CallBitrateHelper call(bitrate_config);
597
598 Call::Config::BitrateConfigMask mask;
599 mask.max_bitrate_bps = rtc::Optional<int>(1000);
600
601 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, 1000));
602 call->SetBitrateConfigMask(mask);
603}
604
605TEST(CallBitrateTest, SettingMaskStartForcesUpdate) {
606 CallBitrateHelper call;
607
608 Call::Config::BitrateConfigMask mask;
609 mask.start_bitrate_bps = rtc::Optional<int>(1000);
610
611 // SetBweBitrates should be called twice with the same params since
612 // start_bitrate_bps is set.
613 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, 1000, testing::_))
614 .Times(2);
615 call->SetBitrateConfigMask(mask);
616 call->SetBitrateConfigMask(mask);
617}
618
619TEST(CallBitrateTest, SetBitrateConfigWithNoChangesDoesNotCallSetBweBitrates) {
620 CallBitrateHelper call;
621
622 Call::Config::BitrateConfig config1;
623 config1.min_bitrate_bps = 0;
624 config1.start_bitrate_bps = 1000;
625 config1.max_bitrate_bps = -1;
626
627 Call::Config::BitrateConfig config2;
628 config2.min_bitrate_bps = 0;
629 config2.start_bitrate_bps = -1;
630 config2.max_bitrate_bps = -1;
631
632 // The second call should not call SetBweBitrates because it doesn't
633 // change any values.
634 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
635 call->SetBitrateConfig(config1);
636 call->SetBitrateConfig(config2);
637}
638
639// If SetBitrateConfig changes the max, but not the effective max,
640// SetBweBitrates shouldn't be called, to avoid unnecessary encoder
641// reconfigurations.
642TEST(CallBitrateTest, SetBweBitratesNotCalledWhenEffectiveMaxUnchanged) {
643 CallBitrateHelper call;
644
645 Call::Config::BitrateConfig config;
646 config.min_bitrate_bps = 0;
647 config.start_bitrate_bps = -1;
648 config.max_bitrate_bps = 2000;
649 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 2000));
650 call->SetBitrateConfig(config);
651
652 // Reduce effective max to 1000 with the mask.
653 Call::Config::BitrateConfigMask mask;
654 mask.max_bitrate_bps = rtc::Optional<int>(1000);
655 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 1000));
656 call->SetBitrateConfigMask(mask);
657
658 // This leaves the effective max unchanged, so SetBweBitrates shouldn't be
659 // called again.
660 config.max_bitrate_bps = 1000;
661 call->SetBitrateConfig(config);
662}
663
664// When the "start bitrate" mask is removed, SetBweBitrates shouldn't be called
665// again, since nothing's changing.
666TEST(CallBitrateTest, SetBweBitratesNotCalledWhenStartMaskRemoved) {
667 CallBitrateHelper call;
668
669 Call::Config::BitrateConfigMask mask;
670 mask.start_bitrate_bps = rtc::Optional<int>(1000);
671 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
672 call->SetBitrateConfigMask(mask);
673
674 mask.start_bitrate_bps.reset();
675 call->SetBitrateConfigMask(mask);
676}
677
678// Test that if SetBitrateConfig is called after SetBitrateConfigMask applies a
679// "start" value, the SetBitrateConfig call won't apply that start value a
680// second time.
681TEST(CallBitrateTest, SetBitrateConfigAfterSetBitrateConfigMaskWithStart) {
682 CallBitrateHelper call;
683
684 Call::Config::BitrateConfigMask mask;
685 mask.start_bitrate_bps = rtc::Optional<int>(1000);
686 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
687 call->SetBitrateConfigMask(mask);
688
689 Call::Config::BitrateConfig config;
690 config.min_bitrate_bps = 0;
691 config.start_bitrate_bps = -1;
692 config.max_bitrate_bps = 5000;
693 // The start value isn't changing, so SetBweBitrates should be called with
694 // -1.
695 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, -1, 5000));
696 call->SetBitrateConfig(config);
697}
698
699TEST(CallBitrateTest, SetBweBitratesNotCalledWhenClampedMinUnchanged) {
700 Call::Config::BitrateConfig bitrate_config;
701 bitrate_config.start_bitrate_bps = 500;
702 bitrate_config.max_bitrate_bps = 1000;
703 CallBitrateHelper call(bitrate_config);
704
705 // Set min to 2000; it is clamped to the max (1000).
706 Call::Config::BitrateConfigMask mask;
707 mask.min_bitrate_bps = rtc::Optional<int>(2000);
708 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, -1, 1000));
709 call->SetBitrateConfigMask(mask);
710
711 // Set min to 3000; the clamped value stays the same so nothing happens.
712 mask.min_bitrate_bps = rtc::Optional<int>(3000);
713 call->SetBitrateConfigMask(mask);
714}
ossuc3d4b482017-05-23 06:07:11 -0700715
solenbergc7a8b082015-10-16 14:35:07 -0700716} // namespace webrtc