blob: 7b1627158416152c4b71ed67ace0f406774ad63b [file] [log] [blame]
solenbergc7a8b082015-10-16 21:35:071/*
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 14:15:4912#include <map>
kwibergb25345e2016-03-12 14:10:4413#include <memory>
zstein7cb69d52017-05-08 18:52:3814#include <utility>
solenbergc7a8b082015-10-16 21:35:0715
Karl Wibergf3850f62017-11-02 12:04:4116#include "api/audio_codecs/builtin_audio_decoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3117#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 21:35:0733
34namespace {
35
36struct CallHelper {
ossu29b1a8d2016-06-13 14:34:5137 explicit CallHelper(
38 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
39 : voice_engine_(decoder_factory) {
solenberg566ef242015-11-06 23:34:4940 webrtc::AudioState::Config audio_state_config;
41 audio_state_config.voice_engine = &voice_engine_;
aleloi10111bc2016-11-17 14:48:4842 audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create();
peaha9cc40b2017-06-29 15:32:0943 audio_state_config.audio_processing = webrtc::AudioProcessing::Create();
aleloidd310712016-11-17 14:28:5944 EXPECT_CALL(voice_engine_, audio_transport());
skvlad11a9cbf2016-10-07 18:53:0545 webrtc::Call::Config config(&event_log_);
solenberg566ef242015-11-06 23:34:4946 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 21:35:0747 call_.reset(webrtc::Call::Create(config));
48 }
49
50 webrtc::Call* operator->() { return call_.get(); }
solenberg7602aab2016-11-14 19:30:0751 webrtc::test::MockVoiceEngine* voice_engine() { return &voice_engine_; }
solenbergc7a8b082015-10-16 21:35:0752
53 private:
solenberg3a941542015-11-16 15:34:5054 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
skvlad11a9cbf2016-10-07 18:53:0555 webrtc::RtcEventLogNullImpl event_log_;
kwibergb25345e2016-03-12 14:10:4456 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 21:35:0757};
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 14:34:5177 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
78 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
79 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 21:35:0780 AudioReceiveStream::Config config;
81 config.rtp.remote_ssrc = 42;
82 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 14:34:5183 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 21:35:0784 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 14:34:51113 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
114 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
115 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 21:35:07116 AudioReceiveStream::Config config;
117 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 14:34:51118 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 21:35:07119 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-24 06:37:14137
solenberg7602aab2016-11-14 19:30:07138TEST(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 13:07:11142 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 19:30:07143
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 14:15:49155 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 13:07:11160 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
161 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 19:30:07162 // 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 13:07:11197 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 19:30:07198
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 14:15:49210 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 13:07:11215 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
216 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 19:30:07217 // 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-24 06:37:14250TEST(CallTest, CreateDestroy_FlexfecReceiveStream) {
251 CallHelper call;
brandtr8313a6f2017-01-13 15:41:19252 MockTransport rtcp_send_transport;
253 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 12:17:53254 config.payload_type = 118;
255 config.remote_ssrc = 38837212;
brandtr25445d32016-10-24 06:37:14256 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 15:41:19265 MockTransport rtcp_send_transport;
266 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 12:17:53267 config.payload_type = 118;
brandtr25445d32016-10-24 06:37:14268 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 12:17:53272 config.remote_ssrc = ssrc;
brandtr25445d32016-10-24 06:37:14273 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 15:41:19291 MockTransport rtcp_send_transport;
292 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 12:17:53293 config.payload_type = 118;
brandtr25445d32016-10-24 06:37:14294 config.protected_media_ssrcs = {1324234};
295 FlexfecReceiveStream* stream;
296 std::list<FlexfecReceiveStream*> streams;
297
brandtr1cfbd602016-12-08 12:17:53298 config.remote_ssrc = 838383;
brandtr25445d32016-10-24 06:37:14299 stream = call->CreateFlexfecReceiveStream(config);
300 EXPECT_NE(stream, nullptr);
301 streams.push_back(stream);
302
brandtr1cfbd602016-12-08 12:17:53303 config.remote_ssrc = 424993;
brandtr25445d32016-10-24 06:37:14304 stream = call->CreateFlexfecReceiveStream(config);
305 EXPECT_NE(stream, nullptr);
306 streams.push_back(stream);
307
brandtr1cfbd602016-12-08 12:17:53308 config.remote_ssrc = 99383;
brandtr25445d32016-10-24 06:37:14309 stream = call->CreateFlexfecReceiveStream(config);
310 EXPECT_NE(stream, nullptr);
311 streams.push_back(stream);
312
brandtr1cfbd602016-12-08 12:17:53313 config.remote_ssrc = 5548;
brandtr25445d32016-10-24 06:37:14314 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 18:49:12323namespace {
324struct CallBitrateHelper {
zstein4b979802017-06-02 21:37:37325 CallBitrateHelper() : CallBitrateHelper(Call::Config::BitrateConfig()) {}
zstein7cb69d52017-05-08 18:52:38326
zstein4b979802017-06-02 21:37:37327 explicit CallBitrateHelper(const Call::Config::BitrateConfig& bitrate_config)
Stefan Holmer5c8942a2017-08-22 14:16:44328 : mock_cc_(Clock::GetRealTimeClock(), &event_log_, &pacer_) {
zstein4b979802017-06-02 21:37:37329 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 14:16:44333 &packet_router_, &pacer_, &mock_cc_)));
zstein4b979802017-06-02 21:37:37334 }
zstein8c96a142017-05-17 18:49:12335
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 14:16:44344 testing::NiceMock<MockPacedSender> pacer_;
zstein8c96a142017-05-17 18:49:12345 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 18:52:38352
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 18:49:12358 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 21:37:37372 EXPECT_CALL(call.mock_cc(), SetBweBitrates(11, -1, 30));
zstein8c96a142017-05-17 18:49:12373 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 21:37:37400 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, -1, 31));
zstein8c96a142017-05-17 18:49:12401 call->SetBitrateConfig(bitrate_config);
402}
403
404TEST(CallBitrateTest, SetBitrateConfigWithSameConfigElidesSecondCall) {
405 CallBitrateHelper call;
zstein8c96a142017-05-17 18:49:12406 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 18:52:38429 call->SetBitrateConfig(bitrate_config);
430}
431
ossuc3d4b482017-05-23 13:07:11432TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) {
433 constexpr uint32_t kSSRC = 12345;
434 testing::NiceMock<test::MockAudioDeviceModule> mock_adm;
ossuc3d4b482017-05-23 13:07:11435 rtc::scoped_refptr<test::MockAudioMixer> mock_mixer(
436 new rtc::RefCountedObject<test::MockAudioMixer>);
437
438 // There's similar functionality in cricket::VoEWrapper but it's not reachable
439 // from here. Since we're working on removing VoE interfaces, I doubt it's
440 // worth making VoEWrapper more easily available.
441 struct ScopedVoiceEngine {
442 ScopedVoiceEngine()
443 : voe(VoiceEngine::Create()),
444 base(VoEBase::GetInterface(voe)) {}
445 ~ScopedVoiceEngine() {
446 base->Release();
447 EXPECT_TRUE(VoiceEngine::Delete(voe));
448 }
449
450 VoiceEngine* voe;
451 VoEBase* base;
452 };
453 ScopedVoiceEngine voice_engine;
454
ossuc3d4b482017-05-23 13:07:11455 AudioState::Config audio_state_config;
456 audio_state_config.voice_engine = voice_engine.voe;
457 audio_state_config.audio_mixer = mock_mixer;
peaha9cc40b2017-06-29 15:32:09458 audio_state_config.audio_processing = AudioProcessing::Create();
Karl Wibergf3850f62017-11-02 12:04:41459 voice_engine.base->Init(&mock_adm, audio_state_config.audio_processing.get(),
460 CreateBuiltinAudioDecoderFactory());
ossuc3d4b482017-05-23 13:07:11461 auto audio_state = AudioState::Create(audio_state_config);
peaha9cc40b2017-06-29 15:32:09462
ossuc3d4b482017-05-23 13:07:11463 RtcEventLogNullImpl event_log;
464 Call::Config call_config(&event_log);
465 call_config.audio_state = audio_state;
466 std::unique_ptr<Call> call(Call::Create(call_config));
467
468 auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) {
469 AudioSendStream::Config config(nullptr);
470 config.rtp.ssrc = ssrc;
471 config.voe_channel_id = voice_engine.base->CreateChannel();
472 AudioSendStream* stream = call->CreateAudioSendStream(config);
473 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine.voe);
474 auto channel_proxy = voe_impl->GetChannelProxy(config.voe_channel_id);
475 RtpRtcp* rtp_rtcp = nullptr;
476 RtpReceiver* rtp_receiver = nullptr; // Unused but required for call.
477 channel_proxy->GetRtpRtcp(&rtp_rtcp, &rtp_receiver);
478 const RtpState rtp_state = rtp_rtcp->GetRtpState();
479 call->DestroyAudioSendStream(stream);
480 voice_engine.base->DeleteChannel(config.voe_channel_id);
481 return rtp_state;
482 };
483
484 const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC);
485 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC);
486
487 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number);
488 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp);
489 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp);
490 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms);
491 EXPECT_EQ(rtp_state1.last_timestamp_time_ms,
492 rtp_state2.last_timestamp_time_ms);
493 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent);
494}
zstein4b979802017-06-02 21:37:37495TEST(CallBitrateTest, BiggerMaskMinUsed) {
496 CallBitrateHelper call;
497 Call::Config::BitrateConfigMask mask;
498 mask.min_bitrate_bps = rtc::Optional<int>(1234);
499
500 EXPECT_CALL(call.mock_cc(),
501 SetBweBitrates(*mask.min_bitrate_bps, testing::_, testing::_));
502 call->SetBitrateConfigMask(mask);
503}
504
505TEST(CallBitrateTest, BiggerConfigMinUsed) {
506 CallBitrateHelper call;
507 Call::Config::BitrateConfigMask mask;
508 mask.min_bitrate_bps = rtc::Optional<int>(1000);
509 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, testing::_));
510 call->SetBitrateConfigMask(mask);
511
512 Call::Config::BitrateConfig config;
513 config.min_bitrate_bps = 1234;
514
515 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1234, testing::_, testing::_));
516 call->SetBitrateConfig(config);
517}
518
519// The last call to set start should be used.
520TEST(CallBitrateTest, LatestStartMaskPreferred) {
521 CallBitrateHelper call;
522 Call::Config::BitrateConfigMask mask;
523 mask.start_bitrate_bps = rtc::Optional<int>(1300);
524
525 EXPECT_CALL(call.mock_cc(),
526 SetBweBitrates(testing::_, *mask.start_bitrate_bps, testing::_));
527 call->SetBitrateConfigMask(mask);
528
529 Call::Config::BitrateConfig bitrate_config;
530 bitrate_config.start_bitrate_bps = 1200;
531
532 EXPECT_CALL(
533 call.mock_cc(),
534 SetBweBitrates(testing::_, bitrate_config.start_bitrate_bps, testing::_));
535 call->SetBitrateConfig(bitrate_config);
536}
537
538TEST(CallBitrateTest, SmallerMaskMaxUsed) {
539 Call::Config::BitrateConfig bitrate_config;
540 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 2000;
541 CallBitrateHelper call(bitrate_config);
542
543 Call::Config::BitrateConfigMask mask;
544 mask.max_bitrate_bps =
545 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 1000);
546
547 EXPECT_CALL(call.mock_cc(),
548 SetBweBitrates(testing::_, testing::_, *mask.max_bitrate_bps));
549 call->SetBitrateConfigMask(mask);
550}
551
552TEST(CallBitrateTest, SmallerConfigMaxUsed) {
553 Call::Config::BitrateConfig bitrate_config;
554 bitrate_config.max_bitrate_bps = bitrate_config.start_bitrate_bps + 1000;
555 CallBitrateHelper call(bitrate_config);
556
557 Call::Config::BitrateConfigMask mask;
558 mask.max_bitrate_bps =
559 rtc::Optional<int>(bitrate_config.start_bitrate_bps + 2000);
560
561 // Expect no calls because nothing changes
562 EXPECT_CALL(call.mock_cc(),
563 SetBweBitrates(testing::_, testing::_, testing::_))
564 .Times(0);
565 call->SetBitrateConfigMask(mask);
566}
567
568TEST(CallBitrateTest, MaskStartLessThanConfigMinClamped) {
569 Call::Config::BitrateConfig bitrate_config;
570 bitrate_config.min_bitrate_bps = 2000;
571 CallBitrateHelper call(bitrate_config);
572
573 Call::Config::BitrateConfigMask mask;
574 mask.start_bitrate_bps = rtc::Optional<int>(1000);
575
576 EXPECT_CALL(call.mock_cc(), SetBweBitrates(2000, 2000, testing::_));
577 call->SetBitrateConfigMask(mask);
578}
579
580TEST(CallBitrateTest, MaskStartGreaterThanConfigMaxClamped) {
581 Call::Config::BitrateConfig bitrate_config;
582 bitrate_config.start_bitrate_bps = 2000;
583 CallBitrateHelper call(bitrate_config);
584
585 Call::Config::BitrateConfigMask mask;
586 mask.max_bitrate_bps = rtc::Optional<int>(1000);
587
588 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, -1, 1000));
589 call->SetBitrateConfigMask(mask);
590}
591
592TEST(CallBitrateTest, MaskMinGreaterThanConfigMaxClamped) {
593 Call::Config::BitrateConfig bitrate_config;
594 bitrate_config.min_bitrate_bps = 2000;
595 CallBitrateHelper call(bitrate_config);
596
597 Call::Config::BitrateConfigMask mask;
598 mask.max_bitrate_bps = rtc::Optional<int>(1000);
599
600 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, testing::_, 1000));
601 call->SetBitrateConfigMask(mask);
602}
603
604TEST(CallBitrateTest, SettingMaskStartForcesUpdate) {
605 CallBitrateHelper call;
606
607 Call::Config::BitrateConfigMask mask;
608 mask.start_bitrate_bps = rtc::Optional<int>(1000);
609
610 // SetBweBitrates should be called twice with the same params since
611 // start_bitrate_bps is set.
612 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, 1000, testing::_))
613 .Times(2);
614 call->SetBitrateConfigMask(mask);
615 call->SetBitrateConfigMask(mask);
616}
617
618TEST(CallBitrateTest, SetBitrateConfigWithNoChangesDoesNotCallSetBweBitrates) {
619 CallBitrateHelper call;
620
621 Call::Config::BitrateConfig config1;
622 config1.min_bitrate_bps = 0;
623 config1.start_bitrate_bps = 1000;
624 config1.max_bitrate_bps = -1;
625
626 Call::Config::BitrateConfig config2;
627 config2.min_bitrate_bps = 0;
628 config2.start_bitrate_bps = -1;
629 config2.max_bitrate_bps = -1;
630
631 // The second call should not call SetBweBitrates because it doesn't
632 // change any values.
633 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
634 call->SetBitrateConfig(config1);
635 call->SetBitrateConfig(config2);
636}
637
638// If SetBitrateConfig changes the max, but not the effective max,
639// SetBweBitrates shouldn't be called, to avoid unnecessary encoder
640// reconfigurations.
641TEST(CallBitrateTest, SetBweBitratesNotCalledWhenEffectiveMaxUnchanged) {
642 CallBitrateHelper call;
643
644 Call::Config::BitrateConfig config;
645 config.min_bitrate_bps = 0;
646 config.start_bitrate_bps = -1;
647 config.max_bitrate_bps = 2000;
648 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 2000));
649 call->SetBitrateConfig(config);
650
651 // Reduce effective max to 1000 with the mask.
652 Call::Config::BitrateConfigMask mask;
653 mask.max_bitrate_bps = rtc::Optional<int>(1000);
654 EXPECT_CALL(call.mock_cc(), SetBweBitrates(testing::_, testing::_, 1000));
655 call->SetBitrateConfigMask(mask);
656
657 // This leaves the effective max unchanged, so SetBweBitrates shouldn't be
658 // called again.
659 config.max_bitrate_bps = 1000;
660 call->SetBitrateConfig(config);
661}
662
663// When the "start bitrate" mask is removed, SetBweBitrates shouldn't be called
664// again, since nothing's changing.
665TEST(CallBitrateTest, SetBweBitratesNotCalledWhenStartMaskRemoved) {
666 CallBitrateHelper call;
667
668 Call::Config::BitrateConfigMask mask;
669 mask.start_bitrate_bps = rtc::Optional<int>(1000);
670 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
671 call->SetBitrateConfigMask(mask);
672
673 mask.start_bitrate_bps.reset();
674 call->SetBitrateConfigMask(mask);
675}
676
677// Test that if SetBitrateConfig is called after SetBitrateConfigMask applies a
678// "start" value, the SetBitrateConfig call won't apply that start value a
679// second time.
680TEST(CallBitrateTest, SetBitrateConfigAfterSetBitrateConfigMaskWithStart) {
681 CallBitrateHelper call;
682
683 Call::Config::BitrateConfigMask mask;
684 mask.start_bitrate_bps = rtc::Optional<int>(1000);
685 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, 1000, -1));
686 call->SetBitrateConfigMask(mask);
687
688 Call::Config::BitrateConfig config;
689 config.min_bitrate_bps = 0;
690 config.start_bitrate_bps = -1;
691 config.max_bitrate_bps = 5000;
692 // The start value isn't changing, so SetBweBitrates should be called with
693 // -1.
694 EXPECT_CALL(call.mock_cc(), SetBweBitrates(0, -1, 5000));
695 call->SetBitrateConfig(config);
696}
697
698TEST(CallBitrateTest, SetBweBitratesNotCalledWhenClampedMinUnchanged) {
699 Call::Config::BitrateConfig bitrate_config;
700 bitrate_config.start_bitrate_bps = 500;
701 bitrate_config.max_bitrate_bps = 1000;
702 CallBitrateHelper call(bitrate_config);
703
704 // Set min to 2000; it is clamped to the max (1000).
705 Call::Config::BitrateConfigMask mask;
706 mask.min_bitrate_bps = rtc::Optional<int>(2000);
707 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1000, -1, 1000));
708 call->SetBitrateConfigMask(mask);
709
710 // Set min to 3000; the clamped value stays the same so nothing happens.
711 mask.min_bitrate_bps = rtc::Optional<int>(3000);
712 call->SetBitrateConfigMask(mask);
713}
ossuc3d4b482017-05-23 13:07:11714
solenbergc7a8b082015-10-16 21:35:07715} // namespace webrtc