blob: b1ebb823a8e5c1dfb4e23e0087405e50ca643734 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "api/test/mock_audio_mixer.h"
17#include "call/audio_state.h"
18#include "call/call.h"
19#include "call/fake_rtp_transport_controller_send.h"
20#include "logging/rtc_event_log/rtc_event_log.h"
21#include "modules/audio_device/include/mock_audio_device.h"
22#include "modules/audio_mixer/audio_mixer_impl.h"
23#include "modules/congestion_controller/include/mock/mock_send_side_congestion_controller.h"
24#include "modules/pacing/mock/mock_paced_sender.h"
25#include "modules/rtp_rtcp/include/rtp_rtcp.h"
26#include "rtc_base/ptr_util.h"
27#include "test/fake_encoder.h"
28#include "test/gtest.h"
29#include "test/mock_audio_decoder_factory.h"
30#include "test/mock_transport.h"
31#include "test/mock_voice_engine.h"
solenbergc7a8b082015-10-16 14:35:07 -070032
33namespace {
34
35struct CallHelper {
ossu29b1a8d2016-06-13 07:34:51 -070036 explicit CallHelper(
37 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
38 : voice_engine_(decoder_factory) {
solenberg566ef242015-11-06 15:34:49 -080039 webrtc::AudioState::Config audio_state_config;
40 audio_state_config.voice_engine = &voice_engine_;
aleloi10111bc2016-11-17 06:48:48 -080041 audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create();
peaha9cc40b2017-06-29 08:32:09 -070042 audio_state_config.audio_processing = webrtc::AudioProcessing::Create();
aleloidd310712016-11-17 06:28:59 -080043 EXPECT_CALL(voice_engine_, audio_device_module());
aleloidd310712016-11-17 06:28:59 -080044 EXPECT_CALL(voice_engine_, audio_transport());
skvlad11a9cbf2016-10-07 11:53:05 -070045 webrtc::Call::Config config(&event_log_);
solenberg566ef242015-11-06 15:34:49 -080046 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070047 call_.reset(webrtc::Call::Create(config));
48 }
49
50 webrtc::Call* operator->() { return call_.get(); }
solenberg7602aab2016-11-14 11:30:07 -080051 webrtc::test::MockVoiceEngine* voice_engine() { return &voice_engine_; }
solenbergc7a8b082015-10-16 14:35:07 -070052
53 private:
solenberg3a941542015-11-16 07:34:50 -080054 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
skvlad11a9cbf2016-10-07 11:53:05 -070055 webrtc::RtcEventLogNullImpl event_log_;
kwibergb25345e2016-03-12 06:10:44 -080056 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 14:35:07 -070057};
58} // namespace
59
60namespace webrtc {
61
62TEST(CallTest, ConstructDestruct) {
63 CallHelper call;
64}
65
66TEST(CallTest, CreateDestroy_AudioSendStream) {
67 CallHelper call;
68 AudioSendStream::Config config(nullptr);
69 config.rtp.ssrc = 42;
70 config.voe_channel_id = 123;
71 AudioSendStream* stream = call->CreateAudioSendStream(config);
72 EXPECT_NE(stream, nullptr);
73 call->DestroyAudioSendStream(stream);
74}
75
76TEST(CallTest, CreateDestroy_AudioReceiveStream) {
ossu29b1a8d2016-06-13 07:34:51 -070077 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
78 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
79 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070080 AudioReceiveStream::Config config;
81 config.rtp.remote_ssrc = 42;
82 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -070083 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -070084 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
85 EXPECT_NE(stream, nullptr);
86 call->DestroyAudioReceiveStream(stream);
87}
88
89TEST(CallTest, CreateDestroy_AudioSendStreams) {
90 CallHelper call;
91 AudioSendStream::Config config(nullptr);
92 config.voe_channel_id = 123;
93 std::list<AudioSendStream*> streams;
94 for (int i = 0; i < 2; ++i) {
95 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
96 config.rtp.ssrc = ssrc;
97 AudioSendStream* stream = call->CreateAudioSendStream(config);
98 EXPECT_NE(stream, nullptr);
99 if (ssrc & 1) {
100 streams.push_back(stream);
101 } else {
102 streams.push_front(stream);
103 }
104 }
105 for (auto s : streams) {
106 call->DestroyAudioSendStream(s);
107 }
108 streams.clear();
109 }
110}
111
112TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
ossu29b1a8d2016-06-13 07:34:51 -0700113 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
114 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
115 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -0700116 AudioReceiveStream::Config config;
117 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -0700118 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -0700119 std::list<AudioReceiveStream*> streams;
120 for (int i = 0; i < 2; ++i) {
121 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
122 config.rtp.remote_ssrc = ssrc;
123 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
124 EXPECT_NE(stream, nullptr);
125 if (ssrc & 1) {
126 streams.push_back(stream);
127 } else {
128 streams.push_front(stream);
129 }
130 }
131 for (auto s : streams) {
132 call->DestroyAudioReceiveStream(s);
133 }
134 streams.clear();
135 }
136}
brandtr25445d32016-10-23 23:37:14 -0700137
solenberg7602aab2016-11-14 11:30:07 -0800138TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) {
139 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
140 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
141 CallHelper call(decoder_factory);
ossuc3d4b482017-05-23 06:07:11 -0700142 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 11:30:07 -0800143
144 constexpr int kRecvChannelId = 101;
145
146 // Set up the mock to create a channel proxy which we know of, so that we can
147 // add our expectations to it.
148 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
149 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
150 .WillRepeatedly(testing::Invoke([&](int channel_id) {
151 test::MockVoEChannelProxy* channel_proxy =
152 new testing::NiceMock<test::MockVoEChannelProxy>();
153 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
154 .WillRepeatedly(testing::ReturnRef(decoder_factory));
kwiberg1c07c702017-03-27 07:15:49 -0700155 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_))
156 .WillRepeatedly(testing::Invoke(
157 [](const std::map<int, SdpAudioFormat>& codecs) {
158 EXPECT_THAT(codecs, testing::IsEmpty());
159 }));
ossuc3d4b482017-05-23 06:07:11 -0700160 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
161 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 11:30:07 -0800162 // If being called for the send channel, save a pointer to the channel
163 // proxy for later.
164 if (channel_id == kRecvChannelId) {
165 EXPECT_FALSE(recv_channel_proxy);
166 recv_channel_proxy = channel_proxy;
167 }
168 return channel_proxy;
169 }));
170
171 AudioReceiveStream::Config recv_config;
172 recv_config.rtp.remote_ssrc = 42;
173 recv_config.rtp.local_ssrc = 777;
174 recv_config.voe_channel_id = kRecvChannelId;
175 recv_config.decoder_factory = decoder_factory;
176 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
177 EXPECT_NE(recv_stream, nullptr);
178
179 EXPECT_CALL(*recv_channel_proxy, AssociateSendChannel(testing::_)).Times(1);
180 AudioSendStream::Config send_config(nullptr);
181 send_config.rtp.ssrc = 777;
182 send_config.voe_channel_id = 123;
183 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
184 EXPECT_NE(send_stream, nullptr);
185
186 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
187 call->DestroyAudioSendStream(send_stream);
188
189 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
190 call->DestroyAudioReceiveStream(recv_stream);
191}
192
193TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) {
194 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
195 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
196 CallHelper call(decoder_factory);
ossuc3d4b482017-05-23 06:07:11 -0700197 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 11:30:07 -0800198
199 constexpr int kRecvChannelId = 101;
200
201 // Set up the mock to create a channel proxy which we know of, so that we can
202 // add our expectations to it.
203 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
204 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
205 .WillRepeatedly(testing::Invoke([&](int channel_id) {
206 test::MockVoEChannelProxy* channel_proxy =
207 new testing::NiceMock<test::MockVoEChannelProxy>();
208 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
209 .WillRepeatedly(testing::ReturnRef(decoder_factory));
kwiberg1c07c702017-03-27 07:15:49 -0700210 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_))
211 .WillRepeatedly(testing::Invoke(
212 [](const std::map<int, SdpAudioFormat>& codecs) {
213 EXPECT_THAT(codecs, testing::IsEmpty());
214 }));
ossuc3d4b482017-05-23 06:07:11 -0700215 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
216 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 11:30:07 -0800217 // If being called for the send channel, save a pointer to the channel
218 // proxy for later.
219 if (channel_id == kRecvChannelId) {
220 EXPECT_FALSE(recv_channel_proxy);
221 recv_channel_proxy = channel_proxy;
222 // We need to set this expectation here since the channel proxy is
223 // created as a side effect of CreateAudioReceiveStream().
224 EXPECT_CALL(*recv_channel_proxy,
225 AssociateSendChannel(testing::_)).Times(1);
226 }
227 return channel_proxy;
228 }));
229
230 AudioSendStream::Config send_config(nullptr);
231 send_config.rtp.ssrc = 777;
232 send_config.voe_channel_id = 123;
233 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
234 EXPECT_NE(send_stream, nullptr);
235
236 AudioReceiveStream::Config recv_config;
237 recv_config.rtp.remote_ssrc = 42;
238 recv_config.rtp.local_ssrc = 777;
239 recv_config.voe_channel_id = kRecvChannelId;
240 recv_config.decoder_factory = decoder_factory;
241 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
242 EXPECT_NE(recv_stream, nullptr);
243
244 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
245 call->DestroyAudioReceiveStream(recv_stream);
246
247 call->DestroyAudioSendStream(send_stream);
248}
249
brandtr25445d32016-10-23 23:37:14 -0700250TEST(CallTest, CreateDestroy_FlexfecReceiveStream) {
251 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800252 MockTransport rtcp_send_transport;
253 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800254 config.payload_type = 118;
255 config.remote_ssrc = 38837212;
brandtr25445d32016-10-23 23:37:14 -0700256 config.protected_media_ssrcs = {27273};
257
258 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
259 EXPECT_NE(stream, nullptr);
260 call->DestroyFlexfecReceiveStream(stream);
261}
262
263TEST(CallTest, CreateDestroy_FlexfecReceiveStreams) {
264 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800265 MockTransport rtcp_send_transport;
266 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800267 config.payload_type = 118;
brandtr25445d32016-10-23 23:37:14 -0700268 std::list<FlexfecReceiveStream*> streams;
269
270 for (int i = 0; i < 2; ++i) {
271 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
brandtr1cfbd602016-12-08 04:17:53 -0800272 config.remote_ssrc = ssrc;
brandtr25445d32016-10-23 23:37:14 -0700273 config.protected_media_ssrcs = {ssrc + 1};
274 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
275 EXPECT_NE(stream, nullptr);
276 if (ssrc & 1) {
277 streams.push_back(stream);
278 } else {
279 streams.push_front(stream);
280 }
281 }
282 for (auto s : streams) {
283 call->DestroyFlexfecReceiveStream(s);
284 }
285 streams.clear();
286 }
287}
288
289TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) {
290 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800291 MockTransport rtcp_send_transport;
292 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800293 config.payload_type = 118;
brandtr25445d32016-10-23 23:37:14 -0700294 config.protected_media_ssrcs = {1324234};
295 FlexfecReceiveStream* stream;
296 std::list<FlexfecReceiveStream*> streams;
297
brandtr1cfbd602016-12-08 04:17:53 -0800298 config.remote_ssrc = 838383;
brandtr25445d32016-10-23 23:37:14 -0700299 stream = call->CreateFlexfecReceiveStream(config);
300 EXPECT_NE(stream, nullptr);
301 streams.push_back(stream);
302
brandtr1cfbd602016-12-08 04:17:53 -0800303 config.remote_ssrc = 424993;
brandtr25445d32016-10-23 23:37:14 -0700304 stream = call->CreateFlexfecReceiveStream(config);
305 EXPECT_NE(stream, nullptr);
306 streams.push_back(stream);
307
brandtr1cfbd602016-12-08 04:17:53 -0800308 config.remote_ssrc = 99383;
brandtr25445d32016-10-23 23:37:14 -0700309 stream = call->CreateFlexfecReceiveStream(config);
310 EXPECT_NE(stream, nullptr);
311 streams.push_back(stream);
312
brandtr1cfbd602016-12-08 04:17:53 -0800313 config.remote_ssrc = 5548;
brandtr25445d32016-10-23 23:37:14 -0700314 stream = call->CreateFlexfecReceiveStream(config);
315 EXPECT_NE(stream, nullptr);
316 streams.push_back(stream);
317
318 for (auto s : streams) {
319 call->DestroyFlexfecReceiveStream(s);
320 }
321}
322
zstein8c96a142017-05-17 11:49:12 -0700323namespace {
324struct CallBitrateHelper {
zstein4b979802017-06-02 14:37:37 -0700325 CallBitrateHelper() : CallBitrateHelper(Call::Config::BitrateConfig()) {}
zstein7cb69d52017-05-08 11:52:38 -0700326
zstein4b979802017-06-02 14:37:37 -0700327 explicit CallBitrateHelper(const Call::Config::BitrateConfig& bitrate_config)
Stefan Holmer5c8942a2017-08-22 16:16:44 +0200328 : mock_cc_(Clock::GetRealTimeClock(), &event_log_, &pacer_) {
zstein4b979802017-06-02 14:37:37 -0700329 Call::Config config(&event_log_);
330 config.bitrate_config = bitrate_config;
331 call_.reset(
332 Call::Create(config, rtc::MakeUnique<FakeRtpTransportControllerSend>(
Stefan Holmer5c8942a2017-08-22 16:16:44 +0200333 &packet_router_, &pacer_, &mock_cc_)));
zstein4b979802017-06-02 14:37:37 -0700334 }
zstein8c96a142017-05-17 11:49:12 -0700335
336 webrtc::Call* operator->() { return call_.get(); }
337 testing::NiceMock<test::MockSendSideCongestionController>& mock_cc() {
338 return mock_cc_;
339 }
340
341 private:
342 webrtc::RtcEventLogNullImpl event_log_;
343 PacketRouter packet_router_;
Stefan Holmer5c8942a2017-08-22 16:16:44 +0200344 testing::NiceMock<MockPacedSender> pacer_;
zstein8c96a142017-05-17 11:49:12 -0700345 testing::NiceMock<test::MockSendSideCongestionController> mock_cc_;
346 std::unique_ptr<Call> call_;
347};
348} // namespace
349
350TEST(CallBitrateTest, SetBitrateConfigWithValidConfigCallsSetBweBitrates) {
351 CallBitrateHelper call;
zstein7cb69d52017-05-08 11:52:38 -0700352
353 Call::Config::BitrateConfig bitrate_config;
354 bitrate_config.min_bitrate_bps = 1;
355 bitrate_config.start_bitrate_bps = 2;
356 bitrate_config.max_bitrate_bps = 3;
357
zstein8c96a142017-05-17 11:49:12 -0700358 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3));
359 call->SetBitrateConfig(bitrate_config);
360}
361
362TEST(CallBitrateTest, SetBitrateConfigWithDifferentMinCallsSetBweBitrates) {
363 CallBitrateHelper call;
364
365 Call::Config::BitrateConfig bitrate_config;
366 bitrate_config.min_bitrate_bps = 10;
367 bitrate_config.start_bitrate_bps = 20;
368 bitrate_config.max_bitrate_bps = 30;
369 call->SetBitrateConfig(bitrate_config);
370
371 bitrate_config.min_bitrate_bps = 11;
zstein4b979802017-06-02 14:37:37 -0700372 EXPECT_CALL(call.mock_cc(), SetBweBitrates(11, -1, 30));
zstein8c96a142017-05-17 11:49:12 -0700373 call->SetBitrateConfig(bitrate_config);
374}
375
376TEST(CallBitrateTest, SetBitrateConfigWithDifferentStartCallsSetBweBitrates) {
377 CallBitrateHelper call;
378
379 Call::Config::BitrateConfig bitrate_config;
380 bitrate_config.min_bitrate_bps = 10;
381 bitrate_config.start_bitrate_bps = 20;
382 bitrate_config.max_bitrate_bps = 30;
383 call->SetBitrateConfig(bitrate_config);
384
385 bitrate_config.start_bitrate_bps = 21;
386 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, 21, 30));
387 call->SetBitrateConfig(bitrate_config);
388}
389
390TEST(CallBitrateTest, SetBitrateConfigWithDifferentMaxCallsSetBweBitrates) {
391 CallBitrateHelper call;
392
393 Call::Config::BitrateConfig bitrate_config;
394 bitrate_config.min_bitrate_bps = 10;
395 bitrate_config.start_bitrate_bps = 20;
396 bitrate_config.max_bitrate_bps = 30;
397 call->SetBitrateConfig(bitrate_config);
398
399 bitrate_config.max_bitrate_bps = 31;
zstein4b979802017-06-02 14:37:37 -0700400 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, -1, 31));
zstein8c96a142017-05-17 11:49:12 -0700401 call->SetBitrateConfig(bitrate_config);
402}
403
404TEST(CallBitrateTest, SetBitrateConfigWithSameConfigElidesSecondCall) {
405 CallBitrateHelper call;
zstein8c96a142017-05-17 11:49:12 -0700406 Call::Config::BitrateConfig bitrate_config;
407 bitrate_config.min_bitrate_bps = 1;
408 bitrate_config.start_bitrate_bps = 2;
409 bitrate_config.max_bitrate_bps = 3;
410
411 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1);
412 call->SetBitrateConfig(bitrate_config);
413 call->SetBitrateConfig(bitrate_config);
414}
415
416TEST(CallBitrateTest,
417 SetBitrateConfigWithSameMinMaxAndNegativeStartElidesSecondCall) {
418 CallBitrateHelper call;
419
420 Call::Config::BitrateConfig bitrate_config;
421 bitrate_config.min_bitrate_bps = 1;
422 bitrate_config.start_bitrate_bps = 2;
423 bitrate_config.max_bitrate_bps = 3;
424
425 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1);
426 call->SetBitrateConfig(bitrate_config);
427
428 bitrate_config.start_bitrate_bps = -1;
zstein7cb69d52017-05-08 11:52:38 -0700429 call->SetBitrateConfig(bitrate_config);
430}
431
ossuc3d4b482017-05-23 06:07:11 -0700432TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) {
433 constexpr uint32_t kSSRC = 12345;
434 testing::NiceMock<test::MockAudioDeviceModule> mock_adm;
435 // Reply with a 10ms timer every time TimeUntilNextProcess is called to
436 // avoid entering a tight loop on the process thread.
437 EXPECT_CALL(mock_adm, TimeUntilNextProcess())
438 .WillRepeatedly(testing::Return(10));
439 rtc::scoped_refptr<test::MockAudioMixer> mock_mixer(
440 new rtc::RefCountedObject<test::MockAudioMixer>);
441
442 // There's similar functionality in cricket::VoEWrapper but it's not reachable
443 // from here. Since we're working on removing VoE interfaces, I doubt it's
444 // worth making VoEWrapper more easily available.
445 struct ScopedVoiceEngine {
446 ScopedVoiceEngine()
447 : voe(VoiceEngine::Create()),
448 base(VoEBase::GetInterface(voe)) {}
449 ~ScopedVoiceEngine() {
450 base->Release();
451 EXPECT_TRUE(VoiceEngine::Delete(voe));
452 }
453
454 VoiceEngine* voe;
455 VoEBase* base;
456 };
457 ScopedVoiceEngine voice_engine;
458
ossuc3d4b482017-05-23 06:07:11 -0700459 AudioState::Config audio_state_config;
460 audio_state_config.voice_engine = voice_engine.voe;
461 audio_state_config.audio_mixer = mock_mixer;
peaha9cc40b2017-06-29 08:32:09 -0700462 audio_state_config.audio_processing = AudioProcessing::Create();
463 voice_engine.base->Init(&mock_adm, audio_state_config.audio_processing.get());
ossuc3d4b482017-05-23 06:07:11 -0700464 auto audio_state = AudioState::Create(audio_state_config);
peaha9cc40b2017-06-29 08:32:09 -0700465
ossuc3d4b482017-05-23 06:07:11 -0700466 RtcEventLogNullImpl event_log;
467 Call::Config call_config(&event_log);
468 call_config.audio_state = audio_state;
469 std::unique_ptr<Call> call(Call::Create(call_config));
470
471 auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) {
472 AudioSendStream::Config config(nullptr);
473 config.rtp.ssrc = ssrc;
474 config.voe_channel_id = voice_engine.base->CreateChannel();
475 AudioSendStream* stream = call->CreateAudioSendStream(config);
476 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine.voe);
477 auto channel_proxy = voe_impl->GetChannelProxy(config.voe_channel_id);
478 RtpRtcp* rtp_rtcp = nullptr;
479 RtpReceiver* rtp_receiver = nullptr; // Unused but required for call.
480 channel_proxy->GetRtpRtcp(&rtp_rtcp, &rtp_receiver);
481 const RtpState rtp_state = rtp_rtcp->GetRtpState();
482 call->DestroyAudioSendStream(stream);
483 voice_engine.base->DeleteChannel(config.voe_channel_id);
484 return rtp_state;
485 };
486
487 const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC);
488 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC);
489
490 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number);
491 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp);
492 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp);
493 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms);
494 EXPECT_EQ(rtp_state1.last_timestamp_time_ms,
495 rtp_state2.last_timestamp_time_ms);
496 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent);
497}
zstein4b979802017-06-02 14:37:37 -0700498TEST(CallBitrateTest, BiggerMaskMinUsed) {
499 CallBitrateHelper call;
500 Call::Config::BitrateConfigMask mask;
501 mask.min_bitrate_bps = rtc::Optional<int>(1234);
502
503 EXPECT_CALL(call.mock_cc(),
504 SetBweBitrates(*mask.min_bitrate_bps, testing::_, testing::_));
505 call->SetBitrateConfigMask(mask);
506}
507
508TEST(CallBitrateTest, BiggerConfigMinUsed) {
509 CallBitrateHelper call;
510 Call::Config::BitrateConfigMask mask;
511 mask.min_bitrate_bps = rtc::Optional<int>(1000);
512 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, testing::_));
513 call->SetBitrateConfigMask(mask);
514
515 Call::Config::BitrateConfig config;
516 config.min_bitrate_bps = 1234;
517
518 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1234, testing::_, testing::_));
519 call->SetBitrateConfig(config);
520}
521
522// The last call to set start should be used.
523TEST(CallBitrateTest, LatestStartMaskPreferred) {
524 CallBitrateHelper call;
525 Call::Config::BitrateConfigMask mask;
526 mask.start_bitrate_bps = rtc::Optional<int>(1300);
527
528 EXPECT_CALL(call.mock_cc(),
529 SetBweBitrates(testing::_, *mask.start_bitrate_bps, testing::_));
530 call->SetBitrateConfigMask(mask);
531
532 Call::Config::BitrateConfig bitrate_config;
533 bitrate_config.start_bitrate_bps = 1200;
534
535 EXPECT_CALL(
536 call.mock_cc(),
537 SetBweBitrates(testing::_, bitrate_config.start_bitrate_bps, testing::_));
538 call->SetBitrateConfig(bitrate_config);
539}
540
541TEST(CallBitrateTest, SmallerMaskMaxUsed) {
542 Call::Config::BitrateConfig bitrate_config;
543 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 2000;
544 CallBitrateHelper call(bitrate_config);
545
546 Call::Config::BitrateConfigMask mask;
547 mask.max_bitrate_bps =
548 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 1000);
549
550 EXPECT_CALL(call.mock_cc(),
551 SetBweBitrates(testing::_, testing::_, *mask.max_bitrate_bps));
552 call->SetBitrateConfigMask(mask);
553}
554
555TEST(CallBitrateTest, SmallerConfigMaxUsed) {
556 Call::Config::BitrateConfig bitrate_config;
557 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 1000;
558 CallBitrateHelper call(bitrate_config);
559
560 Call::Config::BitrateConfigMask mask;
561 mask.max_bitrate_bps =
562 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 2000);
563
564 // Expect no calls because nothing changes
565 EXPECT_CALL(call.mock_cc(),
566 SetBweBitrates(testing::_, testing::_, testing::_))
567 .Times(0);
568 call->SetBitrateConfigMask(mask);
569}
570
571TEST(CallBitrateTest, MaskStartLessThanConfigMinClamped) {
572 Call::Config::BitrateConfig bitrate_config;
573 bitrate_config.min_bitrate_bps = 2000;
574 CallBitrateHelper call(bitrate_config);
575
576 Call::Config::BitrateConfigMask mask;
577 mask.start_bitrate_bps = rtc::Optional<int>(1000);
578
579 EXPECT_CALL(call.mock_cc(), SetBweBitrates(2000, 2000, testing::_));
580 call->SetBitrateConfigMask(mask);
581}
582
583TEST(CallBitrateTest, MaskStartGreaterThanConfigMaxClamped) {
584 Call::Config::BitrateConfig bitrate_config;
585 bitrate_config.start_bitrate_bps = 2000;
586 CallBitrateHelper call(bitrate_config);
587
588 Call::Config::BitrateConfigMask mask;
589 mask.max_bitrate_bps = rtc::Optional<int>(1000);
590
591 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, -1, 1000));
592 call->SetBitrateConfigMask(mask);
593}
594
595TEST(CallBitrateTest, MaskMinGreaterThanConfigMaxClamped) {
596 Call::Config::BitrateConfig bitrate_config;
597 bitrate_config.min_bitrate_bps = 2000;
598 CallBitrateHelper call(bitrate_config);
599
600 Call::Config::BitrateConfigMask mask;
601 mask.max_bitrate_bps = rtc::Optional<int>(1000);
602
603 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, 1000));
604 call->SetBitrateConfigMask(mask);
605}
606
607TEST(CallBitrateTest, SettingMaskStartForcesUpdate) {
608 CallBitrateHelper call;
609
610 Call::Config::BitrateConfigMask mask;
611 mask.start_bitrate_bps = rtc::Optional<int>(1000);
612
613 // SetBweBitrates should be called twice with the same params since
614 // start_bitrate_bps is set.
615 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, 1000, testing::_))
616 .Times(2);
617 call->SetBitrateConfigMask(mask);
618 call->SetBitrateConfigMask(mask);
619}
620
621TEST(CallBitrateTest, SetBitrateConfigWithNoChangesDoesNotCallSetBweBitrates) {
622 CallBitrateHelper call;
623
624 Call::Config::BitrateConfig config1;
625 config1.min_bitrate_bps = 0;
626 config1.start_bitrate_bps = 1000;
627 config1.max_bitrate_bps = -1;
628
629 Call::Config::BitrateConfig config2;
630 config2.min_bitrate_bps = 0;
631 config2.start_bitrate_bps = -1;
632 config2.max_bitrate_bps = -1;
633
634 // The second call should not call SetBweBitrates because it doesn't
635 // change any values.
636 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
637 call->SetBitrateConfig(config1);
638 call->SetBitrateConfig(config2);
639}
640
641// If SetBitrateConfig changes the max, but not the effective max,
642// SetBweBitrates shouldn't be called, to avoid unnecessary encoder
643// reconfigurations.
644TEST(CallBitrateTest, SetBweBitratesNotCalledWhenEffectiveMaxUnchanged) {
645 CallBitrateHelper call;
646
647 Call::Config::BitrateConfig config;
648 config.min_bitrate_bps = 0;
649 config.start_bitrate_bps = -1;
650 config.max_bitrate_bps = 2000;
651 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 2000));
652 call->SetBitrateConfig(config);
653
654 // Reduce effective max to 1000 with the mask.
655 Call::Config::BitrateConfigMask mask;
656 mask.max_bitrate_bps = rtc::Optional<int>(1000);
657 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 1000));
658 call->SetBitrateConfigMask(mask);
659
660 // This leaves the effective max unchanged, so SetBweBitrates shouldn't be
661 // called again.
662 config.max_bitrate_bps = 1000;
663 call->SetBitrateConfig(config);
664}
665
666// When the "start bitrate" mask is removed, SetBweBitrates shouldn't be called
667// again, since nothing's changing.
668TEST(CallBitrateTest, SetBweBitratesNotCalledWhenStartMaskRemoved) {
669 CallBitrateHelper call;
670
671 Call::Config::BitrateConfigMask mask;
672 mask.start_bitrate_bps = rtc::Optional<int>(1000);
673 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
674 call->SetBitrateConfigMask(mask);
675
676 mask.start_bitrate_bps.reset();
677 call->SetBitrateConfigMask(mask);
678}
679
680// Test that if SetBitrateConfig is called after SetBitrateConfigMask applies a
681// "start" value, the SetBitrateConfig call won't apply that start value a
682// second time.
683TEST(CallBitrateTest, SetBitrateConfigAfterSetBitrateConfigMaskWithStart) {
684 CallBitrateHelper call;
685
686 Call::Config::BitrateConfigMask mask;
687 mask.start_bitrate_bps = rtc::Optional<int>(1000);
688 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
689 call->SetBitrateConfigMask(mask);
690
691 Call::Config::BitrateConfig config;
692 config.min_bitrate_bps = 0;
693 config.start_bitrate_bps = -1;
694 config.max_bitrate_bps = 5000;
695 // The start value isn't changing, so SetBweBitrates should be called with
696 // -1.
697 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, -1, 5000));
698 call->SetBitrateConfig(config);
699}
700
701TEST(CallBitrateTest, SetBweBitratesNotCalledWhenClampedMinUnchanged) {
702 Call::Config::BitrateConfig bitrate_config;
703 bitrate_config.start_bitrate_bps = 500;
704 bitrate_config.max_bitrate_bps = 1000;
705 CallBitrateHelper call(bitrate_config);
706
707 // Set min to 2000; it is clamped to the max (1000).
708 Call::Config::BitrateConfigMask mask;
709 mask.min_bitrate_bps = rtc::Optional<int>(2000);
710 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, -1, 1000));
711 call->SetBitrateConfigMask(mask);
712
713 // Set min to 3000; the clamped value stays the same so nothing happens.
714 mask.min_bitrate_bps = rtc::Optional<int>(3000);
715 call->SetBitrateConfigMask(mask);
716}
ossuc3d4b482017-05-23 06:07:11 -0700717
solenbergc7a8b082015-10-16 14:35:07 -0700718} // namespace webrtc