solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 1 | /* |
| 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> |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 12 | #include <memory> |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 13 | |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame^] | 14 | #include "webrtc/call/audio_state.h" |
| 15 | #include "webrtc/call/call.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 16 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 17 | #include "webrtc/modules/audio_coding/codecs/mock/mock_audio_decoder_factory.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame^] | 18 | #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 19 | #include "webrtc/test/gtest.h" |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 20 | #include "webrtc/test/mock_voice_engine.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 21 | |
| 22 | namespace { |
| 23 | |
| 24 | struct CallHelper { |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 25 | explicit CallHelper( |
| 26 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr) |
| 27 | : voice_engine_(decoder_factory) { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 28 | webrtc::AudioState::Config audio_state_config; |
| 29 | audio_state_config.voice_engine = &voice_engine_; |
aleloi | 10111bc | 2016-11-17 06:48:48 -0800 | [diff] [blame] | 30 | audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create(); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 31 | EXPECT_CALL(voice_engine_, audio_device_module()); |
| 32 | EXPECT_CALL(voice_engine_, audio_processing()); |
| 33 | EXPECT_CALL(voice_engine_, audio_transport()); |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 34 | webrtc::Call::Config config(&event_log_); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 35 | config.audio_state = webrtc::AudioState::Create(audio_state_config); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 36 | call_.reset(webrtc::Call::Create(config)); |
| 37 | } |
| 38 | |
| 39 | webrtc::Call* operator->() { return call_.get(); } |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 40 | webrtc::test::MockVoiceEngine* voice_engine() { return &voice_engine_; } |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 41 | |
| 42 | private: |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 43 | testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 44 | webrtc::RtcEventLogNullImpl event_log_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 45 | std::unique_ptr<webrtc::Call> call_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 46 | }; |
| 47 | } // namespace |
| 48 | |
| 49 | namespace webrtc { |
| 50 | |
| 51 | TEST(CallTest, ConstructDestruct) { |
| 52 | CallHelper call; |
| 53 | } |
| 54 | |
| 55 | TEST(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 | |
| 65 | TEST(CallTest, CreateDestroy_AudioReceiveStream) { |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 66 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 67 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 68 | CallHelper call(decoder_factory); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 69 | AudioReceiveStream::Config config; |
| 70 | config.rtp.remote_ssrc = 42; |
| 71 | config.voe_channel_id = 123; |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 72 | config.decoder_factory = decoder_factory; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 73 | AudioReceiveStream* stream = call->CreateAudioReceiveStream(config); |
| 74 | EXPECT_NE(stream, nullptr); |
| 75 | call->DestroyAudioReceiveStream(stream); |
| 76 | } |
| 77 | |
| 78 | TEST(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 | |
| 101 | TEST(CallTest, CreateDestroy_AudioReceiveStreams) { |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 102 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 103 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 104 | CallHelper call(decoder_factory); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 105 | AudioReceiveStream::Config config; |
| 106 | config.voe_channel_id = 123; |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 107 | config.decoder_factory = decoder_factory; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 108 | 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 | } |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 126 | |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 127 | TEST(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 | |
| 174 | TEST(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 | |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 223 | TEST(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 | |
| 235 | TEST(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 | |
| 260 | TEST(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 | |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 293 | } // namespace webrtc |