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 | |
Karl Wiberg | f3850f6 | 2017-11-02 13:04:41 +0100 | [diff] [blame] | 16 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/test/mock_audio_mixer.h" |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 18 | #include "audio/audio_send_stream.h" |
| 19 | #include "audio/audio_receive_stream.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #include "call/audio_state.h" |
| 21 | #include "call/call.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "logging/rtc_event_log/rtc_event_log.h" |
| 23 | #include "modules/audio_device/include/mock_audio_device.h" |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 24 | #include "modules/audio_processing/include/mock_audio_processing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 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" |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 32 | |
| 33 | namespace { |
| 34 | |
| 35 | struct CallHelper { |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 36 | CallHelper() { |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 37 | webrtc::AudioState::Config audio_state_config; |
Fredrik Solenberg | 2a87797 | 2017-12-15 16:42:15 +0100 | [diff] [blame] | 38 | audio_state_config.audio_mixer = |
| 39 | new rtc::RefCountedObject<webrtc::test::MockAudioMixer>(); |
| 40 | audio_state_config.audio_processing = |
| 41 | new rtc::RefCountedObject<webrtc::test::MockAudioProcessing>(); |
| 42 | audio_state_config.audio_device_module = |
| 43 | new rtc::RefCountedObject<webrtc::test::MockAudioDeviceModule>(); |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 44 | webrtc::Call::Config config(&event_log_); |
solenberg | 566ef24 | 2015-11-06 15:34:49 -0800 | [diff] [blame] | 45 | config.audio_state = webrtc::AudioState::Create(audio_state_config); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 46 | call_.reset(webrtc::Call::Create(config)); |
| 47 | } |
| 48 | |
| 49 | webrtc::Call* operator->() { return call_.get(); } |
| 50 | |
| 51 | private: |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 52 | webrtc::RtcEventLogNullImpl event_log_; |
kwiberg | b25345e | 2016-03-12 06:10:44 -0800 | [diff] [blame] | 53 | std::unique_ptr<webrtc::Call> call_; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 54 | }; |
| 55 | } // namespace |
| 56 | |
| 57 | namespace webrtc { |
| 58 | |
| 59 | TEST(CallTest, ConstructDestruct) { |
| 60 | CallHelper call; |
| 61 | } |
| 62 | |
| 63 | TEST(CallTest, CreateDestroy_AudioSendStream) { |
| 64 | CallHelper call; |
| 65 | AudioSendStream::Config config(nullptr); |
| 66 | config.rtp.ssrc = 42; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 67 | AudioSendStream* stream = call->CreateAudioSendStream(config); |
| 68 | EXPECT_NE(stream, nullptr); |
| 69 | call->DestroyAudioSendStream(stream); |
| 70 | } |
| 71 | |
| 72 | TEST(CallTest, CreateDestroy_AudioReceiveStream) { |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 73 | CallHelper call; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 74 | AudioReceiveStream::Config config; |
| 75 | config.rtp.remote_ssrc = 42; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 76 | config.decoder_factory = |
| 77 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>(); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 78 | AudioReceiveStream* stream = call->CreateAudioReceiveStream(config); |
| 79 | EXPECT_NE(stream, nullptr); |
| 80 | call->DestroyAudioReceiveStream(stream); |
| 81 | } |
| 82 | |
| 83 | TEST(CallTest, CreateDestroy_AudioSendStreams) { |
| 84 | CallHelper call; |
| 85 | AudioSendStream::Config config(nullptr); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 86 | std::list<AudioSendStream*> streams; |
| 87 | for (int i = 0; i < 2; ++i) { |
| 88 | for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) { |
| 89 | config.rtp.ssrc = ssrc; |
| 90 | AudioSendStream* stream = call->CreateAudioSendStream(config); |
| 91 | EXPECT_NE(stream, nullptr); |
| 92 | if (ssrc & 1) { |
| 93 | streams.push_back(stream); |
| 94 | } else { |
| 95 | streams.push_front(stream); |
| 96 | } |
| 97 | } |
| 98 | for (auto s : streams) { |
| 99 | call->DestroyAudioSendStream(s); |
| 100 | } |
| 101 | streams.clear(); |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | TEST(CallTest, CreateDestroy_AudioReceiveStreams) { |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 106 | CallHelper call; |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 107 | AudioReceiveStream::Config config; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 108 | config.decoder_factory = |
| 109 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>(); |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 110 | std::list<AudioReceiveStream*> streams; |
| 111 | for (int i = 0; i < 2; ++i) { |
| 112 | for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) { |
| 113 | config.rtp.remote_ssrc = ssrc; |
| 114 | AudioReceiveStream* stream = call->CreateAudioReceiveStream(config); |
| 115 | EXPECT_NE(stream, nullptr); |
| 116 | if (ssrc & 1) { |
| 117 | streams.push_back(stream); |
| 118 | } else { |
| 119 | streams.push_front(stream); |
| 120 | } |
| 121 | } |
| 122 | for (auto s : streams) { |
| 123 | call->DestroyAudioReceiveStream(s); |
| 124 | } |
| 125 | streams.clear(); |
| 126 | } |
| 127 | } |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 128 | |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 129 | TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_RecvFirst) { |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 130 | CallHelper call; |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 131 | AudioReceiveStream::Config recv_config; |
| 132 | recv_config.rtp.remote_ssrc = 42; |
| 133 | recv_config.rtp.local_ssrc = 777; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 134 | recv_config.decoder_factory = |
| 135 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>(); |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 136 | AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config); |
| 137 | EXPECT_NE(recv_stream, nullptr); |
| 138 | |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 139 | AudioSendStream::Config send_config(nullptr); |
| 140 | send_config.rtp.ssrc = 777; |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 141 | AudioSendStream* send_stream = call->CreateAudioSendStream(send_config); |
| 142 | EXPECT_NE(send_stream, nullptr); |
| 143 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 144 | internal::AudioReceiveStream* internal_recv_stream = |
| 145 | static_cast<internal::AudioReceiveStream*>(recv_stream); |
| 146 | EXPECT_EQ(send_stream, |
| 147 | internal_recv_stream->GetAssociatedSendStreamForTesting()); |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 148 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 149 | call->DestroyAudioSendStream(send_stream); |
| 150 | EXPECT_EQ(nullptr, internal_recv_stream->GetAssociatedSendStreamForTesting()); |
| 151 | |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 152 | call->DestroyAudioReceiveStream(recv_stream); |
| 153 | } |
| 154 | |
| 155 | TEST(CallTest, CreateDestroy_AssociateAudioSendReceiveStreams_SendFirst) { |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 156 | CallHelper call; |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 157 | AudioSendStream::Config send_config(nullptr); |
| 158 | send_config.rtp.ssrc = 777; |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 159 | AudioSendStream* send_stream = call->CreateAudioSendStream(send_config); |
| 160 | EXPECT_NE(send_stream, nullptr); |
| 161 | |
| 162 | AudioReceiveStream::Config recv_config; |
| 163 | recv_config.rtp.remote_ssrc = 42; |
| 164 | recv_config.rtp.local_ssrc = 777; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 165 | recv_config.decoder_factory = |
| 166 | new rtc::RefCountedObject<webrtc::MockAudioDecoderFactory>(); |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 167 | AudioReceiveStream* recv_stream = call->CreateAudioReceiveStream(recv_config); |
| 168 | EXPECT_NE(recv_stream, nullptr); |
| 169 | |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 170 | internal::AudioReceiveStream* internal_recv_stream = |
| 171 | static_cast<internal::AudioReceiveStream*>(recv_stream); |
| 172 | EXPECT_EQ(send_stream, |
| 173 | internal_recv_stream->GetAssociatedSendStreamForTesting()); |
| 174 | |
solenberg | 7602aab | 2016-11-14 11:30:07 -0800 | [diff] [blame] | 175 | call->DestroyAudioReceiveStream(recv_stream); |
| 176 | |
| 177 | call->DestroyAudioSendStream(send_stream); |
| 178 | } |
| 179 | |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 180 | TEST(CallTest, CreateDestroy_FlexfecReceiveStream) { |
| 181 | CallHelper call; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 182 | MockTransport rtcp_send_transport; |
| 183 | FlexfecReceiveStream::Config config(&rtcp_send_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 184 | config.payload_type = 118; |
| 185 | config.remote_ssrc = 38837212; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 186 | config.protected_media_ssrcs = {27273}; |
| 187 | |
| 188 | FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config); |
| 189 | EXPECT_NE(stream, nullptr); |
| 190 | call->DestroyFlexfecReceiveStream(stream); |
| 191 | } |
| 192 | |
| 193 | TEST(CallTest, CreateDestroy_FlexfecReceiveStreams) { |
| 194 | CallHelper call; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 195 | MockTransport rtcp_send_transport; |
| 196 | FlexfecReceiveStream::Config config(&rtcp_send_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 197 | config.payload_type = 118; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 198 | std::list<FlexfecReceiveStream*> streams; |
| 199 | |
| 200 | for (int i = 0; i < 2; ++i) { |
| 201 | for (uint32_t ssrc = 0; ssrc < 1234567; ssrc += 34567) { |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 202 | config.remote_ssrc = ssrc; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 203 | config.protected_media_ssrcs = {ssrc + 1}; |
| 204 | FlexfecReceiveStream* stream = call->CreateFlexfecReceiveStream(config); |
| 205 | EXPECT_NE(stream, nullptr); |
| 206 | if (ssrc & 1) { |
| 207 | streams.push_back(stream); |
| 208 | } else { |
| 209 | streams.push_front(stream); |
| 210 | } |
| 211 | } |
| 212 | for (auto s : streams) { |
| 213 | call->DestroyFlexfecReceiveStream(s); |
| 214 | } |
| 215 | streams.clear(); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | TEST(CallTest, MultipleFlexfecReceiveStreamsProtectingSingleVideoStream) { |
| 220 | CallHelper call; |
brandtr | 8313a6f | 2017-01-13 07:41:19 -0800 | [diff] [blame] | 221 | MockTransport rtcp_send_transport; |
| 222 | FlexfecReceiveStream::Config config(&rtcp_send_transport); |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 223 | config.payload_type = 118; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 224 | config.protected_media_ssrcs = {1324234}; |
| 225 | FlexfecReceiveStream* stream; |
| 226 | std::list<FlexfecReceiveStream*> streams; |
| 227 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 228 | config.remote_ssrc = 838383; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 229 | stream = call->CreateFlexfecReceiveStream(config); |
| 230 | EXPECT_NE(stream, nullptr); |
| 231 | streams.push_back(stream); |
| 232 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 233 | config.remote_ssrc = 424993; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 234 | stream = call->CreateFlexfecReceiveStream(config); |
| 235 | EXPECT_NE(stream, nullptr); |
| 236 | streams.push_back(stream); |
| 237 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 238 | config.remote_ssrc = 99383; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 239 | stream = call->CreateFlexfecReceiveStream(config); |
| 240 | EXPECT_NE(stream, nullptr); |
| 241 | streams.push_back(stream); |
| 242 | |
brandtr | 1cfbd60 | 2016-12-08 04:17:53 -0800 | [diff] [blame] | 243 | config.remote_ssrc = 5548; |
brandtr | 25445d3 | 2016-10-23 23:37:14 -0700 | [diff] [blame] | 244 | stream = call->CreateFlexfecReceiveStream(config); |
| 245 | EXPECT_NE(stream, nullptr); |
| 246 | streams.push_back(stream); |
| 247 | |
| 248 | for (auto s : streams) { |
| 249 | call->DestroyFlexfecReceiveStream(s); |
| 250 | } |
| 251 | } |
| 252 | |
zstein | 7cb69d5 | 2017-05-08 11:52:38 -0700 | [diff] [blame] | 253 | |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 254 | TEST(CallTest, RecreatingAudioStreamWithSameSsrcReusesRtpState) { |
| 255 | constexpr uint32_t kSSRC = 12345; |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 256 | CallHelper call; |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 257 | |
| 258 | auto create_stream_and_get_rtp_state = [&](uint32_t ssrc) { |
| 259 | AudioSendStream::Config config(nullptr); |
| 260 | config.rtp.ssrc = ssrc; |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 261 | AudioSendStream* stream = call->CreateAudioSendStream(config); |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 262 | const RtpState rtp_state = |
| 263 | static_cast<internal::AudioSendStream*>(stream)->GetRtpState(); |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 264 | call->DestroyAudioSendStream(stream); |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 265 | return rtp_state; |
| 266 | }; |
| 267 | |
| 268 | const RtpState rtp_state1 = create_stream_and_get_rtp_state(kSSRC); |
| 269 | const RtpState rtp_state2 = create_stream_and_get_rtp_state(kSSRC); |
| 270 | |
| 271 | EXPECT_EQ(rtp_state1.sequence_number, rtp_state2.sequence_number); |
| 272 | EXPECT_EQ(rtp_state1.start_timestamp, rtp_state2.start_timestamp); |
| 273 | EXPECT_EQ(rtp_state1.timestamp, rtp_state2.timestamp); |
| 274 | EXPECT_EQ(rtp_state1.capture_time_ms, rtp_state2.capture_time_ms); |
| 275 | EXPECT_EQ(rtp_state1.last_timestamp_time_ms, |
| 276 | rtp_state2.last_timestamp_time_ms); |
| 277 | EXPECT_EQ(rtp_state1.media_has_been_sent, rtp_state2.media_has_been_sent); |
| 278 | } |
Fredrik Solenberg | 8f5787a | 2018-01-11 13:52:30 +0100 | [diff] [blame] | 279 | |
ossu | c3d4b48 | 2017-05-23 06:07:11 -0700 | [diff] [blame] | 280 | |
solenberg | c7a8b08 | 2015-10-16 14:35:07 -0700 | [diff] [blame] | 281 | } // namespace webrtc |