blob: 06ee2005b1953dac90b724fe5f1f2e47f64610ca [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
ossuc3d4b482017-05-23 06:07:11 -070016#include "webrtc/api/test/mock_audio_mixer.h"
zstein7cb69d52017-05-08 11:52:38 -070017#include "webrtc/base/ptr_util.h"
ossuf515ab82016-12-07 04:52:58 -080018#include "webrtc/call/audio_state.h"
19#include "webrtc/call/call.h"
zstein7cb69d52017-05-08 11:52:38 -070020#include "webrtc/call/fake_rtp_transport_controller_send.h"
skvlad11a9cbf2016-10-07 11:53:05 -070021#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
ossuc3d4b482017-05-23 06:07:11 -070022#include "webrtc/modules/audio_device/include/mock_audio_device.h"
ossuf515ab82016-12-07 04:52:58 -080023#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
zstein7cb69d52017-05-08 11:52:38 -070024#include "webrtc/modules/congestion_controller/include/mock/mock_send_side_congestion_controller.h"
ossuc3d4b482017-05-23 06:07:11 -070025#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
kwibergac9f8762016-09-30 22:29:43 -070026#include "webrtc/test/gtest.h"
kwiberg37e99fd2017-04-10 05:15:48 -070027#include "webrtc/test/mock_audio_decoder_factory.h"
brandtr8313a6f2017-01-13 07:41:19 -080028#include "webrtc/test/mock_transport.h"
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010029#include "webrtc/test/mock_voice_engine.h"
solenbergc7a8b082015-10-16 14:35:07 -070030
31namespace {
32
33struct CallHelper {
ossu29b1a8d2016-06-13 07:34:51 -070034 explicit CallHelper(
35 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
36 : voice_engine_(decoder_factory) {
solenberg566ef242015-11-06 15:34:49 -080037 webrtc::AudioState::Config audio_state_config;
38 audio_state_config.voice_engine = &voice_engine_;
aleloi10111bc2016-11-17 06:48:48 -080039 audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create();
aleloidd310712016-11-17 06:28:59 -080040 EXPECT_CALL(voice_engine_, audio_device_module());
41 EXPECT_CALL(voice_engine_, audio_processing());
42 EXPECT_CALL(voice_engine_, audio_transport());
skvlad11a9cbf2016-10-07 11:53:05 -070043 webrtc::Call::Config config(&event_log_);
solenberg566ef242015-11-06 15:34:49 -080044 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070045 call_.reset(webrtc::Call::Create(config));
46 }
47
48 webrtc::Call* operator->() { return call_.get(); }
solenberg7602aab2016-11-14 11:30:07 -080049 webrtc::test::MockVoiceEngine* voice_engine() { return &voice_engine_; }
solenbergc7a8b082015-10-16 14:35:07 -070050
51 private:
solenberg3a941542015-11-16 07:34:50 -080052 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
skvlad11a9cbf2016-10-07 11:53:05 -070053 webrtc::RtcEventLogNullImpl event_log_;
kwibergb25345e2016-03-12 06:10:44 -080054 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 14:35:07 -070055};
56} // namespace
57
58namespace webrtc {
59
60TEST(CallTest, ConstructDestruct) {
61 CallHelper call;
62}
63
64TEST(CallTest, CreateDestroy_AudioSendStream) {
65 CallHelper call;
66 AudioSendStream::Config config(nullptr);
67 config.rtp.ssrc = 42;
68 config.voe_channel_id = 123;
69 AudioSendStream* stream = call->CreateAudioSendStream(config);
70 EXPECT_NE(stream, nullptr);
71 call->DestroyAudioSendStream(stream);
72}
73
74TEST(CallTest, CreateDestroy_AudioReceiveStream) {
ossu29b1a8d2016-06-13 07:34:51 -070075 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
76 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
77 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070078 AudioReceiveStream::Config config;
79 config.rtp.remote_ssrc = 42;
80 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -070081 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -070082 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
83 EXPECT_NE(stream, nullptr);
84 call->DestroyAudioReceiveStream(stream);
85}
86
87TEST(CallTest, CreateDestroy_AudioSendStreams) {
88 CallHelper call;
89 AudioSendStream::Config config(nullptr);
90 config.voe_channel_id = 123;
91 std::list<AudioSendStream*> streams;
92 for (int i = 0; i < 2; ++i) {
93 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
94 config.rtp.ssrc = ssrc;
95 AudioSendStream* stream = call->CreateAudioSendStream(config);
96 EXPECT_NE(stream, nullptr);
97 if (ssrc & 1) {
98 streams.push_back(stream);
99 } else {
100 streams.push_front(stream);
101 }
102 }
103 for (auto s : streams) {
104 call->DestroyAudioSendStream(s);
105 }
106 streams.clear();
107 }
108}
109
110TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
ossu29b1a8d2016-06-13 07:34:51 -0700111 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
112 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
113 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -0700114 AudioReceiveStream::Config config;
115 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -0700116 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -0700117 std::list<AudioReceiveStream*> streams;
118 for (int i = 0; i < 2; ++i) {
119 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
120 config.rtp.remote_ssrc = ssrc;
121 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
122 EXPECT_NE(stream, nullptr);
123 if (ssrc & 1) {
124 streams.push_back(stream);
125 } else {
126 streams.push_front(stream);
127 }
128 }
129 for (auto s : streams) {
130 call->DestroyAudioReceiveStream(s);
131 }
132 streams.clear();
133 }
134}
brandtr25445d32016-10-23 23:37:14 -0700135
solenberg7602aab2016-11-14 11:30:07 -0800136TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) {
137 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
138 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
139 CallHelper call(decoder_factory);
ossuc3d4b482017-05-23 06:07:11 -0700140 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 11:30:07 -0800141
142 constexpr int kRecvChannelId = 101;
143
144 // Set up the mock to create a channel proxy which we know of, so that we can
145 // add our expectations to it.
146 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
147 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
148 .WillRepeatedly(testing::Invoke([&](int channel_id) {
149 test::MockVoEChannelProxy* channel_proxy =
150 new testing::NiceMock<test::MockVoEChannelProxy>();
151 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
152 .WillRepeatedly(testing::ReturnRef(decoder_factory));
kwiberg1c07c702017-03-27 07:15:49 -0700153 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_))
154 .WillRepeatedly(testing::Invoke(
155 [](const std::map<int, SdpAudioFormat>& codecs) {
156 EXPECT_THAT(codecs, testing::IsEmpty());
157 }));
ossuc3d4b482017-05-23 06:07:11 -0700158 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
159 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 11:30:07 -0800160 // If being called for the send channel, save a pointer to the channel
161 // proxy for later.
162 if (channel_id == kRecvChannelId) {
163 EXPECT_FALSE(recv_channel_proxy);
164 recv_channel_proxy = channel_proxy;
165 }
166 return channel_proxy;
167 }));
168
169 AudioReceiveStream::Config recv_config;
170 recv_config.rtp.remote_ssrc = 42;
171 recv_config.rtp.local_ssrc = 777;
172 recv_config.voe_channel_id = kRecvChannelId;
173 recv_config.decoder_factory = decoder_factory;
174 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
175 EXPECT_NE(recv_stream, nullptr);
176
177 EXPECT_CALL(*recv_channel_proxy, AssociateSendChannel(testing::_)).Times(1);
178 AudioSendStream::Config send_config(nullptr);
179 send_config.rtp.ssrc = 777;
180 send_config.voe_channel_id = 123;
181 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
182 EXPECT_NE(send_stream, nullptr);
183
184 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
185 call->DestroyAudioSendStream(send_stream);
186
187 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
188 call->DestroyAudioReceiveStream(recv_stream);
189}
190
191TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) {
192 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
193 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
194 CallHelper call(decoder_factory);
ossuc3d4b482017-05-23 06:07:11 -0700195 ::testing::NiceMock<MockRtpRtcp> mock_rtp_rtcp;
solenberg7602aab2016-11-14 11:30:07 -0800196
197 constexpr int kRecvChannelId = 101;
198
199 // Set up the mock to create a channel proxy which we know of, so that we can
200 // add our expectations to it.
201 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
202 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
203 .WillRepeatedly(testing::Invoke([&](int channel_id) {
204 test::MockVoEChannelProxy* channel_proxy =
205 new testing::NiceMock<test::MockVoEChannelProxy>();
206 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
207 .WillRepeatedly(testing::ReturnRef(decoder_factory));
kwiberg1c07c702017-03-27 07:15:49 -0700208 EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_))
209 .WillRepeatedly(testing::Invoke(
210 [](const std::map<int, SdpAudioFormat>& codecs) {
211 EXPECT_THAT(codecs, testing::IsEmpty());
212 }));
ossuc3d4b482017-05-23 06:07:11 -0700213 EXPECT_CALL(*channel_proxy, GetRtpRtcp(testing::_, testing::_))
214 .WillRepeatedly(testing::SetArgPointee<0>(&mock_rtp_rtcp));
solenberg7602aab2016-11-14 11:30:07 -0800215 // If being called for the send channel, save a pointer to the channel
216 // proxy for later.
217 if (channel_id == kRecvChannelId) {
218 EXPECT_FALSE(recv_channel_proxy);
219 recv_channel_proxy = channel_proxy;
220 // We need to set this expectation here since the channel proxy is
221 // created as a side effect of CreateAudioReceiveStream().
222 EXPECT_CALL(*recv_channel_proxy,
223 AssociateSendChannel(testing::_)).Times(1);
224 }
225 return channel_proxy;
226 }));
227
228 AudioSendStream::Config send_config(nullptr);
229 send_config.rtp.ssrc = 777;
230 send_config.voe_channel_id = 123;
231 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
232 EXPECT_NE(send_stream, nullptr);
233
234 AudioReceiveStream::Config recv_config;
235 recv_config.rtp.remote_ssrc = 42;
236 recv_config.rtp.local_ssrc = 777;
237 recv_config.voe_channel_id = kRecvChannelId;
238 recv_config.decoder_factory = decoder_factory;
239 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
240 EXPECT_NE(recv_stream, nullptr);
241
242 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
243 call->DestroyAudioReceiveStream(recv_stream);
244
245 call->DestroyAudioSendStream(send_stream);
246}
247
brandtr25445d32016-10-23 23:37:14 -0700248TEST(CallTest, CreateDestroy_FlexfecReceiveStream) {
249 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800250 MockTransport rtcp_send_transport;
251 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800252 config.payload_type = 118;
253 config.remote_ssrc = 38837212;
brandtr25445d32016-10-23 23:37:14 -0700254 config.protected_media_ssrcs = {27273};
255
256 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
257 EXPECT_NE(stream, nullptr);
258 call->DestroyFlexfecReceiveStream(stream);
259}
260
261TEST(CallTest, CreateDestroy_FlexfecReceiveStreams) {
262 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800263 MockTransport rtcp_send_transport;
264 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800265 config.payload_type = 118;
brandtr25445d32016-10-23 23:37:14 -0700266 std::list<FlexfecReceiveStream*> streams;
267
268 for (int i = 0; i < 2; ++i) {
269 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
brandtr1cfbd602016-12-08 04:17:53 -0800270 config.remote_ssrc = ssrc;
brandtr25445d32016-10-23 23:37:14 -0700271 config.protected_media_ssrcs = {ssrc + 1};
272 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
273 EXPECT_NE(stream, nullptr);
274 if (ssrc & 1) {
275 streams.push_back(stream);
276 } else {
277 streams.push_front(stream);
278 }
279 }
280 for (auto s : streams) {
281 call->DestroyFlexfecReceiveStream(s);
282 }
283 streams.clear();
284 }
285}
286
287TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) {
288 CallHelper call;
brandtr8313a6f2017-01-13 07:41:19 -0800289 MockTransport rtcp_send_transport;
290 FlexfecReceiveStream::Config config(&rtcp_send_transport);
brandtr1cfbd602016-12-08 04:17:53 -0800291 config.payload_type = 118;
brandtr25445d32016-10-23 23:37:14 -0700292 config.protected_media_ssrcs = {1324234};
293 FlexfecReceiveStream* stream;
294 std::list<FlexfecReceiveStream*> streams;
295
brandtr1cfbd602016-12-08 04:17:53 -0800296 config.remote_ssrc = 838383;
brandtr25445d32016-10-23 23:37:14 -0700297 stream = call->CreateFlexfecReceiveStream(config);
298 EXPECT_NE(stream, nullptr);
299 streams.push_back(stream);
300
brandtr1cfbd602016-12-08 04:17:53 -0800301 config.remote_ssrc = 424993;
brandtr25445d32016-10-23 23:37:14 -0700302 stream = call->CreateFlexfecReceiveStream(config);
303 EXPECT_NE(stream, nullptr);
304 streams.push_back(stream);
305
brandtr1cfbd602016-12-08 04:17:53 -0800306 config.remote_ssrc = 99383;
brandtr25445d32016-10-23 23:37:14 -0700307 stream = call->CreateFlexfecReceiveStream(config);
308 EXPECT_NE(stream, nullptr);
309 streams.push_back(stream);
310
brandtr1cfbd602016-12-08 04:17:53 -0800311 config.remote_ssrc = 5548;
brandtr25445d32016-10-23 23:37:14 -0700312 stream = call->CreateFlexfecReceiveStream(config);
313 EXPECT_NE(stream, nullptr);
314 streams.push_back(stream);
315
316 for (auto s : streams) {
317 call->DestroyFlexfecReceiveStream(s);
318 }
319}
320
zstein8c96a142017-05-17 11:49:12 -0700321namespace {
322struct CallBitrateHelper {
323 CallBitrateHelper() : CallBitrateHelper(Call::Config(&event_log_)) {}
zstein7cb69d52017-05-08 11:52:38 -0700324
zstein8c96a142017-05-17 11:49:12 -0700325 explicit CallBitrateHelper(const Call::Config& config)
326 : mock_cc_(Clock::GetRealTimeClock(), &event_log_, &packet_router_),
327 call_(Call::Create(
328 config,
329 rtc::MakeUnique<FakeRtpTransportControllerSend>(&packet_router_,
330 &mock_cc_))) {}
331
332 webrtc::Call* operator->() { return call_.get(); }
333 testing::NiceMock<test::MockSendSideCongestionController>& mock_cc() {
334 return mock_cc_;
335 }
336
337 private:
338 webrtc::RtcEventLogNullImpl event_log_;
339 PacketRouter packet_router_;
340 testing::NiceMock<test::MockSendSideCongestionController> mock_cc_;
341 std::unique_ptr<Call> call_;
342};
343} // namespace
344
345TEST(CallBitrateTest, SetBitrateConfigWithValidConfigCallsSetBweBitrates) {
346 CallBitrateHelper call;
zstein7cb69d52017-05-08 11:52:38 -0700347
348 Call::Config::BitrateConfig bitrate_config;
349 bitrate_config.min_bitrate_bps = 1;
350 bitrate_config.start_bitrate_bps = 2;
351 bitrate_config.max_bitrate_bps = 3;
352
zstein8c96a142017-05-17 11:49:12 -0700353 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3));
354 call->SetBitrateConfig(bitrate_config);
355}
356
357TEST(CallBitrateTest, SetBitrateConfigWithDifferentMinCallsSetBweBitrates) {
358 CallBitrateHelper call;
359
360 Call::Config::BitrateConfig bitrate_config;
361 bitrate_config.min_bitrate_bps = 10;
362 bitrate_config.start_bitrate_bps = 20;
363 bitrate_config.max_bitrate_bps = 30;
364 call->SetBitrateConfig(bitrate_config);
365
366 bitrate_config.min_bitrate_bps = 11;
367 EXPECT_CALL(call.mock_cc(), SetBweBitrates(11, 20, 30));
368 call->SetBitrateConfig(bitrate_config);
369}
370
371TEST(CallBitrateTest, SetBitrateConfigWithDifferentStartCallsSetBweBitrates) {
372 CallBitrateHelper call;
373
374 Call::Config::BitrateConfig bitrate_config;
375 bitrate_config.min_bitrate_bps = 10;
376 bitrate_config.start_bitrate_bps = 20;
377 bitrate_config.max_bitrate_bps = 30;
378 call->SetBitrateConfig(bitrate_config);
379
380 bitrate_config.start_bitrate_bps = 21;
381 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, 21, 30));
382 call->SetBitrateConfig(bitrate_config);
383}
384
385TEST(CallBitrateTest, SetBitrateConfigWithDifferentMaxCallsSetBweBitrates) {
386 CallBitrateHelper call;
387
388 Call::Config::BitrateConfig bitrate_config;
389 bitrate_config.min_bitrate_bps = 10;
390 bitrate_config.start_bitrate_bps = 20;
391 bitrate_config.max_bitrate_bps = 30;
392 call->SetBitrateConfig(bitrate_config);
393
394 bitrate_config.max_bitrate_bps = 31;
395 EXPECT_CALL(call.mock_cc(), SetBweBitrates(10, 20, 31));
396 call->SetBitrateConfig(bitrate_config);
397}
398
399TEST(CallBitrateTest, SetBitrateConfigWithSameConfigElidesSecondCall) {
400 CallBitrateHelper call;
401
402 Call::Config::BitrateConfig bitrate_config;
403 bitrate_config.min_bitrate_bps = 1;
404 bitrate_config.start_bitrate_bps = 2;
405 bitrate_config.max_bitrate_bps = 3;
406
407 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1);
408 call->SetBitrateConfig(bitrate_config);
409 call->SetBitrateConfig(bitrate_config);
410}
411
412TEST(CallBitrateTest,
413 SetBitrateConfigWithSameMinMaxAndNegativeStartElidesSecondCall) {
414 CallBitrateHelper call;
415
416 Call::Config::BitrateConfig bitrate_config;
417 bitrate_config.min_bitrate_bps = 1;
418 bitrate_config.start_bitrate_bps = 2;
419 bitrate_config.max_bitrate_bps = 3;
420
421 EXPECT_CALL(call.mock_cc(), SetBweBitrates(1, 2, 3)).Times(1);
422 call->SetBitrateConfig(bitrate_config);
423
424 bitrate_config.start_bitrate_bps = -1;
zstein7cb69d52017-05-08 11:52:38 -0700425 call->SetBitrateConfig(bitrate_config);
426}
427
ossuc3d4b482017-05-23 06:07:11 -0700428TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) {
429 constexpr uint32_t kSSRC = 12345;
430 testing::NiceMock<test::MockAudioDeviceModule> mock_adm;
431 // Reply with a 10ms timer every time TimeUntilNextProcess is called to
432 // avoid entering a tight loop on the process thread.
433 EXPECT_CALL(mock_adm, TimeUntilNextProcess())
434 .WillRepeatedly(testing::Return(10));
435 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
455 voice_engine.base->Init(&mock_adm);
456 AudioState::Config audio_state_config;
457 audio_state_config.voice_engine = voice_engine.voe;
458 audio_state_config.audio_mixer = mock_mixer;
459 auto audio_state = AudioState::Create(audio_state_config);
460 RtcEventLogNullImpl event_log;
461 Call::Config call_config(&event_log);
462 call_config.audio_state = audio_state;
463 std::unique_ptr<Call> call(Call::Create(call_config));
464
465 auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) {
466 AudioSendStream::Config config(nullptr);
467 config.rtp.ssrc = ssrc;
468 config.voe_channel_id = voice_engine.base->CreateChannel();
469 AudioSendStream* stream = call->CreateAudioSendStream(config);
470 VoiceEngineImpl* voe_impl = static_cast<VoiceEngineImpl*>(voice_engine.voe);
471 auto channel_proxy = voe_impl->GetChannelProxy(config.voe_channel_id);
472 RtpRtcp* rtp_rtcp = nullptr;
473 RtpReceiver* rtp_receiver = nullptr; // Unused but required for call.
474 channel_proxy->GetRtpRtcp(&rtp_rtcp, &rtp_receiver);
475 const RtpState rtp_state = rtp_rtcp->GetRtpState();
476 call->DestroyAudioSendStream(stream);
477 voice_engine.base->DeleteChannel(config.voe_channel_id);
478 return rtp_state;
479 };
480
481 const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC);
482 const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC);
483
484 EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number);
485 EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp);
486 EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp);
487 EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms);
488 EXPECT_EQ(rtp_state1.last_timestamp_time_ms,
489 rtp_state2.last_timestamp_time_ms);
490 EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent);
491}
492
solenbergc7a8b082015-10-16 14:35:07 -0700493} // namespace webrtc