blob: 15c642fd9117563a1f05e587ff61669e8beee9f7 [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>
kwibergb25345e2016-03-12 06:10:44 -080012#include <memory>
solenbergc7a8b082015-10-16 14:35:07 -070013
ossuf515ab82016-12-07 04:52:58 -080014#include "webrtc/call/audio_state.h"
15#include "webrtc/call/call.h"
skvlad11a9cbf2016-10-07 11:53:05 -070016#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
ossu29b1a8d2016-06-13 07:34:51 -070017#include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h"
ossuf515ab82016-12-07 04:52:58 -080018#include "webrtc/modules/audio_mixer/audio_mixer_impl.h"
kwibergac9f8762016-09-30 22:29:43 -070019#include "webrtc/test/gtest.h"
Fredrik Solenberg0ccae132015-11-03 10:15:49 +010020#include "webrtc/test/mock_voice_engine.h"
solenbergc7a8b082015-10-16 14:35:07 -070021
22namespace {
23
24struct CallHelper {
ossu29b1a8d2016-06-13 07:34:51 -070025 explicit CallHelper(
26 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr)
27 : voice_engine_(decoder_factory) {
solenberg566ef242015-11-06 15:34:49 -080028 webrtc::AudioState::Config audio_state_config;
29 audio_state_config.voice_engine = &voice_engine_;
aleloi10111bc2016-11-17 06:48:48 -080030 audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create();
aleloidd310712016-11-17 06:28:59 -080031 EXPECT_CALL(voice_engine_, audio_device_module());
32 EXPECT_CALL(voice_engine_, audio_processing());
33 EXPECT_CALL(voice_engine_, audio_transport());
skvlad11a9cbf2016-10-07 11:53:05 -070034 webrtc::Call::Config config(&event_log_);
solenberg566ef242015-11-06 15:34:49 -080035 config.audio_state = webrtc::AudioState::Create(audio_state_config);
solenbergc7a8b082015-10-16 14:35:07 -070036 call_.reset(webrtc::Call::Create(config));
37 }
38
39 webrtc::Call* operator->() { return call_.get(); }
solenberg7602aab2016-11-14 11:30:07 -080040 webrtc::test::MockVoiceEngine* voice_engine() { return &voice_engine_; }
solenbergc7a8b082015-10-16 14:35:07 -070041
42 private:
solenberg3a941542015-11-16 07:34:50 -080043 testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_;
skvlad11a9cbf2016-10-07 11:53:05 -070044 webrtc::RtcEventLogNullImpl event_log_;
kwibergb25345e2016-03-12 06:10:44 -080045 std::unique_ptr<webrtc::Call> call_;
solenbergc7a8b082015-10-16 14:35:07 -070046};
47} // namespace
48
49namespace webrtc {
50
51TEST(CallTest, ConstructDestruct) {
52 CallHelper call;
53}
54
55TEST(CallTest, CreateDestroy_AudioSendStream) {
56 CallHelper call;
57 AudioSendStream::Config config(nullptr);
58 config.rtp.ssrc = 42;
59 config.voe_channel_id = 123;
60 AudioSendStream* stream = call->CreateAudioSendStream(config);
61 EXPECT_NE(stream, nullptr);
62 call->DestroyAudioSendStream(stream);
63}
64
65TEST(CallTest, CreateDestroy_AudioReceiveStream) {
ossu29b1a8d2016-06-13 07:34:51 -070066 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
67 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
68 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -070069 AudioReceiveStream::Config config;
70 config.rtp.remote_ssrc = 42;
71 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -070072 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -070073 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
74 EXPECT_NE(stream, nullptr);
75 call->DestroyAudioReceiveStream(stream);
76}
77
78TEST(CallTest, CreateDestroy_AudioSendStreams) {
79 CallHelper call;
80 AudioSendStream::Config config(nullptr);
81 config.voe_channel_id = 123;
82 std::list<AudioSendStream*> streams;
83 for (int i = 0; i < 2; ++i) {
84 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
85 config.rtp.ssrc = ssrc;
86 AudioSendStream* stream = call->CreateAudioSendStream(config);
87 EXPECT_NE(stream, nullptr);
88 if (ssrc & 1) {
89 streams.push_back(stream);
90 } else {
91 streams.push_front(stream);
92 }
93 }
94 for (auto s : streams) {
95 call->DestroyAudioSendStream(s);
96 }
97 streams.clear();
98 }
99}
100
101TEST(CallTest, CreateDestroy_AudioReceiveStreams) {
ossu29b1a8d2016-06-13 07:34:51 -0700102 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
103 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
104 CallHelper call(decoder_factory);
solenbergc7a8b082015-10-16 14:35:07 -0700105 AudioReceiveStream::Config config;
106 config.voe_channel_id = 123;
ossu29b1a8d2016-06-13 07:34:51 -0700107 config.decoder_factory = decoder_factory;
solenbergc7a8b082015-10-16 14:35:07 -0700108 std::list<AudioReceiveStream*> streams;
109 for (int i = 0; i < 2; ++i) {
110 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
111 config.rtp.remote_ssrc = ssrc;
112 AudioReceiveStream* stream = call->CreateAudioReceiveStream(config);
113 EXPECT_NE(stream, nullptr);
114 if (ssrc & 1) {
115 streams.push_back(stream);
116 } else {
117 streams.push_front(stream);
118 }
119 }
120 for (auto s : streams) {
121 call->DestroyAudioReceiveStream(s);
122 }
123 streams.clear();
124 }
125}
brandtr25445d32016-10-23 23:37:14 -0700126
solenberg7602aab2016-11-14 11:30:07 -0800127TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) {
128 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
129 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
130 CallHelper call(decoder_factory);
131
132 constexpr int kRecvChannelId = 101;
133
134 // Set up the mock to create a channel proxy which we know of, so that we can
135 // add our expectations to it.
136 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
137 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
138 .WillRepeatedly(testing::Invoke([&](int channel_id) {
139 test::MockVoEChannelProxy* channel_proxy =
140 new testing::NiceMock<test::MockVoEChannelProxy>();
141 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
142 .WillRepeatedly(testing::ReturnRef(decoder_factory));
143 // If being called for the send channel, save a pointer to the channel
144 // proxy for later.
145 if (channel_id == kRecvChannelId) {
146 EXPECT_FALSE(recv_channel_proxy);
147 recv_channel_proxy = channel_proxy;
148 }
149 return channel_proxy;
150 }));
151
152 AudioReceiveStream::Config recv_config;
153 recv_config.rtp.remote_ssrc = 42;
154 recv_config.rtp.local_ssrc = 777;
155 recv_config.voe_channel_id = kRecvChannelId;
156 recv_config.decoder_factory = decoder_factory;
157 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
158 EXPECT_NE(recv_stream, nullptr);
159
160 EXPECT_CALL(*recv_channel_proxy, AssociateSendChannel(testing::_)).Times(1);
161 AudioSendStream::Config send_config(nullptr);
162 send_config.rtp.ssrc = 777;
163 send_config.voe_channel_id = 123;
164 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
165 EXPECT_NE(send_stream, nullptr);
166
167 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
168 call->DestroyAudioSendStream(send_stream);
169
170 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
171 call->DestroyAudioReceiveStream(recv_stream);
172}
173
174TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) {
175 rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory(
176 new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>);
177 CallHelper call(decoder_factory);
178
179 constexpr int kRecvChannelId = 101;
180
181 // Set up the mock to create a channel proxy which we know of, so that we can
182 // add our expectations to it.
183 test::MockVoEChannelProxy* recv_channel_proxy = nullptr;
184 EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_))
185 .WillRepeatedly(testing::Invoke([&](int channel_id) {
186 test::MockVoEChannelProxy* channel_proxy =
187 new testing::NiceMock<test::MockVoEChannelProxy>();
188 EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory())
189 .WillRepeatedly(testing::ReturnRef(decoder_factory));
190 // If being called for the send channel, save a pointer to the channel
191 // proxy for later.
192 if (channel_id == kRecvChannelId) {
193 EXPECT_FALSE(recv_channel_proxy);
194 recv_channel_proxy = channel_proxy;
195 // We need to set this expectation here since the channel proxy is
196 // created as a side effect of CreateAudioReceiveStream().
197 EXPECT_CALL(*recv_channel_proxy,
198 AssociateSendChannel(testing::_)).Times(1);
199 }
200 return channel_proxy;
201 }));
202
203 AudioSendStream::Config send_config(nullptr);
204 send_config.rtp.ssrc = 777;
205 send_config.voe_channel_id = 123;
206 AudioSendStream* send_stream = call->CreateAudioSendStream(send_config);
207 EXPECT_NE(send_stream, nullptr);
208
209 AudioReceiveStream::Config recv_config;
210 recv_config.rtp.remote_ssrc = 42;
211 recv_config.rtp.local_ssrc = 777;
212 recv_config.voe_channel_id = kRecvChannelId;
213 recv_config.decoder_factory = decoder_factory;
214 AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config);
215 EXPECT_NE(recv_stream, nullptr);
216
217 EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1);
218 call->DestroyAudioReceiveStream(recv_stream);
219
220 call->DestroyAudioSendStream(send_stream);
221}
222
brandtr25445d32016-10-23 23:37:14 -0700223TEST(CallTest, CreateDestroy_FlexfecReceiveStream) {
224 CallHelper call;
225 FlexfecReceiveStream::Config config;
226 config.flexfec_payload_type = 118;
227 config.flexfec_ssrc = 38837212;
228 config.protected_media_ssrcs = {27273};
229
230 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
231 EXPECT_NE(stream, nullptr);
232 call->DestroyFlexfecReceiveStream(stream);
233}
234
235TEST(CallTest, CreateDestroy_FlexfecReceiveStreams) {
236 CallHelper call;
237 FlexfecReceiveStream::Config config;
238 config.flexfec_payload_type = 118;
239 std::list<FlexfecReceiveStream*> streams;
240
241 for (int i = 0; i < 2; ++i) {
242 for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) {
243 config.flexfec_ssrc = ssrc;
244 config.protected_media_ssrcs = {ssrc + 1};
245 FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config);
246 EXPECT_NE(stream, nullptr);
247 if (ssrc & 1) {
248 streams.push_back(stream);
249 } else {
250 streams.push_front(stream);
251 }
252 }
253 for (auto s : streams) {
254 call->DestroyFlexfecReceiveStream(s);
255 }
256 streams.clear();
257 }
258}
259
260TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) {
261 CallHelper call;
262 FlexfecReceiveStream::Config config;
263 config.flexfec_payload_type = 118;
264 config.protected_media_ssrcs = {1324234};
265 FlexfecReceiveStream* stream;
266 std::list<FlexfecReceiveStream*> streams;
267
268 config.flexfec_ssrc = 838383;
269 stream = call->CreateFlexfecReceiveStream(config);
270 EXPECT_NE(stream, nullptr);
271 streams.push_back(stream);
272
273 config.flexfec_ssrc = 424993;
274 stream = call->CreateFlexfecReceiveStream(config);
275 EXPECT_NE(stream, nullptr);
276 streams.push_back(stream);
277
278 config.flexfec_ssrc = 99383;
279 stream = call->CreateFlexfecReceiveStream(config);
280 EXPECT_NE(stream, nullptr);
281 streams.push_back(stream);
282
283 config.flexfec_ssrc = 5548;
284 stream = call->CreateFlexfecReceiveStream(config);
285 EXPECT_NE(stream, nullptr);
286 streams.push_back(stream);
287
288 for (auto s : streams) {
289 call->DestroyFlexfecReceiveStream(s);
290 }
291}
292
solenbergc7a8b082015-10-16 14:35:07 -0700293} // namespace webrtc