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 | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 12 | #include <map> |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 13 | #include <memory> |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame^] | 14 | #include <utility> |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 15 | |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame^] | 16 | #include "webrtc/base/ptr_util.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 17 | #include "webrtc/call/audio_state.h" |
| 18 | #include "webrtc/call/call.h" |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame^] | 19 | #include "webrtc/call/fake_rtp_transport_controller_send.h" |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 20 | #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
ossu | f515ab8 | 2016-12-07 04:52:58 -0800 | [diff] [blame] | 21 | #include "webrtc/modules/audio_mixer/audio_mixer_impl.h" |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame^] | 22 | #include "webrtc/modules/congestion_controller/include/mock/mock_send_side_congestion_controller.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 23 | #include "webrtc/test/gtest.h" |
kwiberg | 37e99fd | 2017-04-10 05:15:48 -0700 | [diff] [blame] | 24 | #include "webrtc/test/mock_audio_decoder_factory.h" |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 25 | #include "webrtc/test/mock_transport.h" |
Fredrik Solenberg | 0ccae13 | 2015-11-03 10:15:49 +0100 | [diff] [blame] | 26 | #include "webrtc/test/mock_voice_engine.h" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 27 | |
| 28 | namespace { |
| 29 | |
| 30 | struct CallHelper { |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 31 | explicit CallHelper( |
| 32 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory = nullptr) |
| 33 | : voice_engine_(decoder_factory) { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 34 | webrtc::AudioState::Config audio_state_config; |
| 35 | audio_state_config.voice_engine = &voice_engine_; |
aleloi | 10111bc | 2016-11-17 06:48:48 -0800 | [diff] [blame] | 36 | audio_state_config.audio_mixer = webrtc::AudioMixerImpl::Create(); |
aleloi | dd31071 | 2016-11-17 06:28:59 -0800 | [diff] [blame] | 37 | EXPECT_CALL(voice_engine_, audio_device_module()); |
| 38 | EXPECT_CALL(voice_engine_, audio_processing()); |
| 39 | EXPECT_CALL(voice_engine_, audio_transport()); |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 40 | webrtc::Call::Config config(&event_log_); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 41 | config.audio_state = webrtc::AudioState::Create(audio_state_config); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 42 | call_.reset(webrtc::Call::Create(config)); |
| 43 | } |
| 44 | |
| 45 | webrtc::Call* operator->() { return call_.get(); } |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 46 | webrtc::test::MockVoiceEngine* voice_engine() { return &voice_engine_; } |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 47 | |
| 48 | private: |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 49 | testing::NiceMock<webrtc::test::MockVoiceEngine> voice_engine_; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 50 | webrtc::RtcEventLogNullImpl event_log_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 51 | std::unique_ptr<webrtc::Call> call_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 52 | }; |
| 53 | } // namespace |
| 54 | |
| 55 | namespace webrtc { |
| 56 | |
| 57 | TEST(CallTest, ConstructDestruct) { |
| 58 | CallHelper call; |
| 59 | } |
| 60 | |
| 61 | TEST(CallTest, CreateDestroy_AudioSendStream) { |
| 62 | CallHelper call; |
| 63 | AudioSendStream::Config config(nullptr); |
| 64 | config.rtp.ssrc = 42; |
| 65 | config.voe_channel_id = 123; |
| 66 | AudioSendStream* stream = call->CreateAudioSendStream(config); |
| 67 | EXPECT_NE(stream, nullptr); |
| 68 | call->DestroyAudioSendStream(stream); |
| 69 | } |
| 70 | |
| 71 | TEST(CallTest, CreateDestroy_AudioReceiveStream) { |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 72 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 73 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 74 | CallHelper call(decoder_factory); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 75 | AudioReceiveStream::Config config; |
| 76 | config.rtp.remote_ssrc = 42; |
| 77 | config.voe_channel_id = 123; |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 78 | config.decoder_factory = decoder_factory; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 79 | AudioReceiveStream* stream = call->CreateAudioReceiveStream(config); |
| 80 | EXPECT_NE(stream, nullptr); |
| 81 | call->DestroyAudioReceiveStream(stream); |
| 82 | } |
| 83 | |
| 84 | TEST(CallTest, CreateDestroy_AudioSendStreams) { |
| 85 | CallHelper call; |
| 86 | AudioSendStream::Config config(nullptr); |
| 87 | config.voe_channel_id = 123; |
| 88 | std::list<AudioSendStream*> streams; |
| 89 | for (int i = 0; i < 2; ++i) { |
| 90 | for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) { |
| 91 | config.rtp.ssrc = ssrc; |
| 92 | AudioSendStream* stream = call->CreateAudioSendStream(config); |
| 93 | EXPECT_NE(stream, nullptr); |
| 94 | if (ssrc & 1) { |
| 95 | streams.push_back(stream); |
| 96 | } else { |
| 97 | streams.push_front(stream); |
| 98 | } |
| 99 | } |
| 100 | for (auto s : streams) { |
| 101 | call->DestroyAudioSendStream(s); |
| 102 | } |
| 103 | streams.clear(); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | TEST(CallTest, CreateDestroy_AudioReceiveStreams) { |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 108 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 109 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 110 | CallHelper call(decoder_factory); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 111 | AudioReceiveStream::Config config; |
| 112 | config.voe_channel_id = 123; |
ossu | 29b1a8d | 2016-06-13 07:34:51 -0700 | [diff] [blame] | 113 | config.decoder_factory = decoder_factory; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 114 | std::list<AudioReceiveStream*> streams; |
| 115 | for (int i = 0; i < 2; ++i) { |
| 116 | for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) { |
| 117 | config.rtp.remote_ssrc = ssrc; |
| 118 | AudioReceiveStream* stream = call->CreateAudioReceiveStream(config); |
| 119 | EXPECT_NE(stream, nullptr); |
| 120 | if (ssrc & 1) { |
| 121 | streams.push_back(stream); |
| 122 | } else { |
| 123 | streams.push_front(stream); |
| 124 | } |
| 125 | } |
| 126 | for (auto s : streams) { |
| 127 | call->DestroyAudioReceiveStream(s); |
| 128 | } |
| 129 | streams.clear(); |
| 130 | } |
| 131 | } |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 132 | |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 133 | TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) { |
| 134 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 135 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 136 | CallHelper call(decoder_factory); |
| 137 | |
| 138 | constexpr int kRecvChannelId = 101; |
| 139 | |
| 140 | // Set up the mock to create a channel proxy which we know of, so that we can |
| 141 | // add our expectations to it. |
| 142 | test::MockVoEChannelProxy* recv_channel_proxy = nullptr; |
| 143 | EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_)) |
| 144 | .WillRepeatedly(testing::Invoke([&](int channel_id) { |
| 145 | test::MockVoEChannelProxy* channel_proxy = |
| 146 | new testing::NiceMock<test::MockVoEChannelProxy>(); |
| 147 | EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory()) |
| 148 | .WillRepeatedly(testing::ReturnRef(decoder_factory)); |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 149 | EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_)) |
| 150 | .WillRepeatedly(testing::Invoke( |
| 151 | [](const std::map<int, SdpAudioFormat>& codecs) { |
| 152 | EXPECT_THAT(codecs, testing::IsEmpty()); |
| 153 | })); |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 154 | // If being called for the send channel, save a pointer to the channel |
| 155 | // proxy for later. |
| 156 | if (channel_id == kRecvChannelId) { |
| 157 | EXPECT_FALSE(recv_channel_proxy); |
| 158 | recv_channel_proxy = channel_proxy; |
| 159 | } |
| 160 | return channel_proxy; |
| 161 | })); |
| 162 | |
| 163 | AudioReceiveStream::Config recv_config; |
| 164 | recv_config.rtp.remote_ssrc = 42; |
| 165 | recv_config.rtp.local_ssrc = 777; |
| 166 | recv_config.voe_channel_id = kRecvChannelId; |
| 167 | recv_config.decoder_factory = decoder_factory; |
| 168 | AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config); |
| 169 | EXPECT_NE(recv_stream, nullptr); |
| 170 | |
| 171 | EXPECT_CALL(*recv_channel_proxy, AssociateSendChannel(testing::_)).Times(1); |
| 172 | AudioSendStream::Config send_config(nullptr); |
| 173 | send_config.rtp.ssrc = 777; |
| 174 | send_config.voe_channel_id = 123; |
| 175 | AudioSendStream* send_stream = call->CreateAudioSendStream(send_config); |
| 176 | EXPECT_NE(send_stream, nullptr); |
| 177 | |
| 178 | EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1); |
| 179 | call->DestroyAudioSendStream(send_stream); |
| 180 | |
| 181 | EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1); |
| 182 | call->DestroyAudioReceiveStream(recv_stream); |
| 183 | } |
| 184 | |
| 185 | TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) { |
| 186 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> decoder_factory( |
| 187 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>); |
| 188 | CallHelper call(decoder_factory); |
| 189 | |
| 190 | constexpr int kRecvChannelId = 101; |
| 191 | |
| 192 | // Set up the mock to create a channel proxy which we know of, so that we can |
| 193 | // add our expectations to it. |
| 194 | test::MockVoEChannelProxy* recv_channel_proxy = nullptr; |
| 195 | EXPECT_CALL(*call.voice_engine(), ChannelProxyFactory(testing::_)) |
| 196 | .WillRepeatedly(testing::Invoke([&](int channel_id) { |
| 197 | test::MockVoEChannelProxy* channel_proxy = |
| 198 | new testing::NiceMock<test::MockVoEChannelProxy>(); |
| 199 | EXPECT_CALL(*channel_proxy, GetAudioDecoderFactory()) |
| 200 | .WillRepeatedly(testing::ReturnRef(decoder_factory)); |
kwiberg | 1c07c70 | 2017-03-27 07:15:49 -0700 | [diff] [blame] | 201 | EXPECT_CALL(*channel_proxy, SetReceiveCodecs(testing::_)) |
| 202 | .WillRepeatedly(testing::Invoke( |
| 203 | [](const std::map<int, SdpAudioFormat>& codecs) { |
| 204 | EXPECT_THAT(codecs, testing::IsEmpty()); |
| 205 | })); |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 206 | // If being called for the send channel, save a pointer to the channel |
| 207 | // proxy for later. |
| 208 | if (channel_id == kRecvChannelId) { |
| 209 | EXPECT_FALSE(recv_channel_proxy); |
| 210 | recv_channel_proxy = channel_proxy; |
| 211 | // We need to set this expectation here since the channel proxy is |
| 212 | // created as a side effect of CreateAudioReceiveStream(). |
| 213 | EXPECT_CALL(*recv_channel_proxy, |
| 214 | AssociateSendChannel(testing::_)).Times(1); |
| 215 | } |
| 216 | return channel_proxy; |
| 217 | })); |
| 218 | |
| 219 | AudioSendStream::Config send_config(nullptr); |
| 220 | send_config.rtp.ssrc = 777; |
| 221 | send_config.voe_channel_id = 123; |
| 222 | AudioSendStream* send_stream = call->CreateAudioSendStream(send_config); |
| 223 | EXPECT_NE(send_stream, nullptr); |
| 224 | |
| 225 | AudioReceiveStream::Config recv_config; |
| 226 | recv_config.rtp.remote_ssrc = 42; |
| 227 | recv_config.rtp.local_ssrc = 777; |
| 228 | recv_config.voe_channel_id = kRecvChannelId; |
| 229 | recv_config.decoder_factory = decoder_factory; |
| 230 | AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config); |
| 231 | EXPECT_NE(recv_stream, nullptr); |
| 232 | |
| 233 | EXPECT_CALL(*recv_channel_proxy, DisassociateSendChannel()).Times(1); |
| 234 | call->DestroyAudioReceiveStream(recv_stream); |
| 235 | |
| 236 | call->DestroyAudioSendStream(send_stream); |
| 237 | } |
| 238 | |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 239 | TEST(CallTest, CreateDestroy_FlexfecReceiveStream) { |
| 240 | CallHelper call; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 241 | MockTransport rtcp_send_transport; |
| 242 | FlexfecReceiveStream::Config config(&rtcp_send_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 243 | config.payload_type = 118; |
| 244 | config.remote_ssrc = 38837212; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 245 | config.protected_media_ssrcs = {27273}; |
| 246 | |
| 247 | FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config); |
| 248 | EXPECT_NE(stream, nullptr); |
| 249 | call->DestroyFlexfecReceiveStream(stream); |
| 250 | } |
| 251 | |
| 252 | TEST(CallTest, CreateDestroy_FlexfecReceiveStreams) { |
| 253 | CallHelper call; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 254 | MockTransport rtcp_send_transport; |
| 255 | FlexfecReceiveStream::Config config(&rtcp_send_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 256 | config.payload_type = 118; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 257 | std::list<FlexfecReceiveStream*> streams; |
| 258 | |
| 259 | for (int i = 0; i < 2; ++i) { |
| 260 | for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) { |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 261 | config.remote_ssrc = ssrc; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 262 | config.protected_media_ssrcs = {ssrc + 1}; |
| 263 | FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config); |
| 264 | EXPECT_NE(stream, nullptr); |
| 265 | if (ssrc & 1) { |
| 266 | streams.push_back(stream); |
| 267 | } else { |
| 268 | streams.push_front(stream); |
| 269 | } |
| 270 | } |
| 271 | for (auto s : streams) { |
| 272 | call->DestroyFlexfecReceiveStream(s); |
| 273 | } |
| 274 | streams.clear(); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) { |
| 279 | CallHelper call; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 280 | MockTransport rtcp_send_transport; |
| 281 | FlexfecReceiveStream::Config config(&rtcp_send_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 282 | config.payload_type = 118; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 283 | config.protected_media_ssrcs = {1324234}; |
| 284 | FlexfecReceiveStream* stream; |
| 285 | std::list<FlexfecReceiveStream*> streams; |
| 286 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 287 | config.remote_ssrc = 838383; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 288 | stream = call->CreateFlexfecReceiveStream(config); |
| 289 | EXPECT_NE(stream, nullptr); |
| 290 | streams.push_back(stream); |
| 291 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 292 | config.remote_ssrc = 424993; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 293 | stream = call->CreateFlexfecReceiveStream(config); |
| 294 | EXPECT_NE(stream, nullptr); |
| 295 | streams.push_back(stream); |
| 296 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 297 | config.remote_ssrc = 99383; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 298 | stream = call->CreateFlexfecReceiveStream(config); |
| 299 | EXPECT_NE(stream, nullptr); |
| 300 | streams.push_back(stream); |
| 301 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 302 | config.remote_ssrc = 5548; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 303 | stream = call->CreateFlexfecReceiveStream(config); |
| 304 | EXPECT_NE(stream, nullptr); |
| 305 | streams.push_back(stream); |
| 306 | |
| 307 | for (auto s : streams) { |
| 308 | call->DestroyFlexfecReceiveStream(s); |
| 309 | } |
| 310 | } |
| 311 | |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame^] | 312 | // TODO(zstein): This is just a motivating example for |
| 313 | // MockSendSideCongestionController. It should be deleted once we have more |
| 314 | // meaningful tests. |
| 315 | TEST(CallTest, MockSendSideCongestionControllerExample) { |
| 316 | RtcEventLogNullImpl event_log; |
| 317 | Call::Config config(&event_log); |
| 318 | |
| 319 | SimulatedClock clock(123456); |
| 320 | PacketRouter packet_router; |
| 321 | testing::NiceMock<test::MockSendSideCongestionController> mock_cc( |
| 322 | &clock, &event_log, &packet_router); |
| 323 | auto transport_send = |
| 324 | rtc::MakeUnique<FakeRtpTransportControllerSend>(&mock_cc); |
| 325 | std::unique_ptr<Call> call(Call::Create(config, std::move(transport_send))); |
| 326 | |
| 327 | Call::Config::BitrateConfig bitrate_config; |
| 328 | bitrate_config.min_bitrate_bps = 1; |
| 329 | bitrate_config.start_bitrate_bps = 2; |
| 330 | bitrate_config.max_bitrate_bps = 3; |
| 331 | |
| 332 | EXPECT_CALL(mock_cc, SetBweBitrates(1, 2, 3)); |
| 333 | call->SetBitrateConfig(bitrate_config); |
| 334 | } |
| 335 | |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 336 | } // namespace webrtc |