wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
Karl Wiberg | c5bb00b | 2017-10-10 23:17:17 +0200 | [diff] [blame] | 13 | #include "api/audio_codecs/L16/audio_decoder_L16.h" |
| 14 | #include "api/audio_codecs/L16/audio_encoder_L16.h" |
| 15 | #include "api/audio_codecs/audio_decoder_factory_template.h" |
| 16 | #include "api/audio_codecs/audio_encoder_factory_template.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/audio_codecs/builtin_audio_decoder_factory.h" |
| 18 | #include "api/audio_codecs/builtin_audio_encoder_factory.h" |
| 19 | #include "rtc_base/gunit.h" |
| 20 | #include "rtc_base/logging.h" |
| 21 | #include "rtc_base/ptr_util.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "rtc_base/stringencode.h" |
| 23 | #include "rtc_base/stringutils.h" |
Patrik Höglund | 563934e | 2017-09-15 09:04:28 +0200 | [diff] [blame] | 24 | |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 25 | #ifdef WEBRTC_ANDROID |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 26 | #include "pc/test/androidtestinitializer.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 27 | #endif |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "pc/test/peerconnectiontestwrapper.h" |
ossu | 7bb87ee | 2017-01-23 04:56:25 -0800 | [diff] [blame] | 29 | // Notice that mockpeerconnectionobservers.h must be included after the above! |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 30 | #include "pc/test/mockpeerconnectionobservers.h" |
| 31 | #include "test/mock_audio_decoder.h" |
| 32 | #include "test/mock_audio_decoder_factory.h" |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 33 | |
| 34 | using testing::AtLeast; |
| 35 | using testing::Invoke; |
| 36 | using testing::StrictMock; |
| 37 | using testing::_; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 38 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 39 | using webrtc::DataChannelInterface; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 40 | using webrtc::FakeConstraints; |
| 41 | using webrtc::MediaConstraintsInterface; |
| 42 | using webrtc::MediaStreamInterface; |
| 43 | using webrtc::PeerConnectionInterface; |
| 44 | |
| 45 | namespace { |
| 46 | |
Honghai Zhang | 82d7862 | 2016-05-06 11:29:15 -0700 | [diff] [blame] | 47 | const int kMaxWait = 10000; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 48 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 49 | } // namespace |
| 50 | |
| 51 | class PeerConnectionEndToEndTest |
| 52 | : public sigslot::has_slots<>, |
| 53 | public testing::Test { |
| 54 | public: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 55 | typedef std::vector<rtc::scoped_refptr<DataChannelInterface> > |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 56 | DataChannelList; |
| 57 | |
perkj | 57db652 | 2016-04-08 08:16:33 -0700 | [diff] [blame] | 58 | PeerConnectionEndToEndTest() { |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 59 | network_thread_ = rtc::Thread::CreateWithSocketServer(); |
| 60 | worker_thread_ = rtc::Thread::Create(); |
| 61 | RTC_CHECK(network_thread_->Start()); |
| 62 | RTC_CHECK(worker_thread_->Start()); |
perkj | 57db652 | 2016-04-08 08:16:33 -0700 | [diff] [blame] | 63 | caller_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 64 | "caller", network_thread_.get(), worker_thread_.get()); |
perkj | 57db652 | 2016-04-08 08:16:33 -0700 | [diff] [blame] | 65 | callee_ = new rtc::RefCountedObject<PeerConnectionTestWrapper>( |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 66 | "callee", network_thread_.get(), worker_thread_.get()); |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 67 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 68 | ice_server.uri = "stun:stun.l.google.com:19302"; |
| 69 | config_.servers.push_back(ice_server); |
| 70 | |
phoglund | 37ebcf0 | 2016-01-08 05:04:57 -0800 | [diff] [blame] | 71 | #ifdef WEBRTC_ANDROID |
| 72 | webrtc::InitializeAndroidObjects(); |
| 73 | #endif |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 74 | } |
| 75 | |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 76 | void CreatePcs( |
| 77 | const MediaConstraintsInterface* pc_constraints, |
| 78 | rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory, |
| 79 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory) { |
| 80 | EXPECT_TRUE(caller_->CreatePc( |
| 81 | pc_constraints, config_, audio_encoder_factory, audio_decoder_factory)); |
| 82 | EXPECT_TRUE(callee_->CreatePc( |
| 83 | pc_constraints, config_, audio_encoder_factory, audio_decoder_factory)); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 84 | PeerConnectionTestWrapper::Connect(caller_.get(), callee_.get()); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 85 | |
| 86 | caller_->SignalOnDataChannel.connect( |
| 87 | this, &PeerConnectionEndToEndTest::OnCallerAddedDataChanel); |
| 88 | callee_->SignalOnDataChannel.connect( |
| 89 | this, &PeerConnectionEndToEndTest::OnCalleeAddedDataChannel); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void GetAndAddUserMedia() { |
| 93 | FakeConstraints audio_constraints; |
| 94 | FakeConstraints video_constraints; |
| 95 | GetAndAddUserMedia(true, audio_constraints, true, video_constraints); |
| 96 | } |
| 97 | |
| 98 | void GetAndAddUserMedia(bool audio, FakeConstraints audio_constraints, |
| 99 | bool video, FakeConstraints video_constraints) { |
| 100 | caller_->GetAndAddUserMedia(audio, audio_constraints, |
| 101 | video, video_constraints); |
| 102 | callee_->GetAndAddUserMedia(audio, audio_constraints, |
| 103 | video, video_constraints); |
| 104 | } |
| 105 | |
| 106 | void Negotiate() { |
| 107 | caller_->CreateOffer(NULL); |
| 108 | } |
| 109 | |
| 110 | void WaitForCallEstablished() { |
| 111 | caller_->WaitForCallEstablished(); |
| 112 | callee_->WaitForCallEstablished(); |
| 113 | } |
| 114 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 115 | void WaitForConnection() { |
| 116 | caller_->WaitForConnection(); |
| 117 | callee_->WaitForConnection(); |
| 118 | } |
| 119 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 120 | void OnCallerAddedDataChanel(DataChannelInterface* dc) { |
| 121 | caller_signaled_data_channels_.push_back(dc); |
| 122 | } |
| 123 | |
| 124 | void OnCalleeAddedDataChannel(DataChannelInterface* dc) { |
| 125 | callee_signaled_data_channels_.push_back(dc); |
| 126 | } |
| 127 | |
| 128 | // Tests that |dc1| and |dc2| can send to and receive from each other. |
| 129 | void TestDataChannelSendAndReceive( |
| 130 | DataChannelInterface* dc1, DataChannelInterface* dc2) { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 131 | std::unique_ptr<webrtc::MockDataChannelObserver> dc1_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 132 | new webrtc::MockDataChannelObserver(dc1)); |
| 133 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 134 | std::unique_ptr<webrtc::MockDataChannelObserver> dc2_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 135 | new webrtc::MockDataChannelObserver(dc2)); |
| 136 | |
| 137 | static const std::string kDummyData = "abcdefg"; |
| 138 | webrtc::DataBuffer buffer(kDummyData); |
| 139 | EXPECT_TRUE(dc1->Send(buffer)); |
| 140 | EXPECT_EQ_WAIT(kDummyData, dc2_observer->last_message(), kMaxWait); |
| 141 | |
| 142 | EXPECT_TRUE(dc2->Send(buffer)); |
| 143 | EXPECT_EQ_WAIT(kDummyData, dc1_observer->last_message(), kMaxWait); |
| 144 | |
| 145 | EXPECT_EQ(1U, dc1_observer->received_message_count()); |
| 146 | EXPECT_EQ(1U, dc2_observer->received_message_count()); |
| 147 | } |
| 148 | |
| 149 | void WaitForDataChannelsToOpen(DataChannelInterface* local_dc, |
| 150 | const DataChannelList& remote_dc_list, |
| 151 | size_t remote_dc_index) { |
| 152 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, local_dc->state(), kMaxWait); |
| 153 | |
| 154 | EXPECT_TRUE_WAIT(remote_dc_list.size() > remote_dc_index, kMaxWait); |
| 155 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, |
| 156 | remote_dc_list[remote_dc_index]->state(), |
| 157 | kMaxWait); |
| 158 | EXPECT_EQ(local_dc->id(), remote_dc_list[remote_dc_index]->id()); |
| 159 | } |
| 160 | |
| 161 | void CloseDataChannels(DataChannelInterface* local_dc, |
| 162 | const DataChannelList& remote_dc_list, |
| 163 | size_t remote_dc_index) { |
| 164 | local_dc->Close(); |
| 165 | EXPECT_EQ_WAIT(DataChannelInterface::kClosed, local_dc->state(), kMaxWait); |
| 166 | EXPECT_EQ_WAIT(DataChannelInterface::kClosed, |
| 167 | remote_dc_list[remote_dc_index]->state(), |
| 168 | kMaxWait); |
| 169 | } |
| 170 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 171 | protected: |
tommi | e725159 | 2017-07-14 14:44:46 -0700 | [diff] [blame] | 172 | std::unique_ptr<rtc::Thread> network_thread_; |
| 173 | std::unique_ptr<rtc::Thread> worker_thread_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 174 | rtc::scoped_refptr<PeerConnectionTestWrapper> caller_; |
| 175 | rtc::scoped_refptr<PeerConnectionTestWrapper> callee_; |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 176 | DataChannelList caller_signaled_data_channels_; |
| 177 | DataChannelList callee_signaled_data_channels_; |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 178 | webrtc::PeerConnectionInterface::RTCConfiguration config_; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
Karl Wiberg | c5bb00b | 2017-10-10 23:17:17 +0200 | [diff] [blame] | 181 | namespace { |
| 182 | |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 183 | std::unique_ptr<webrtc::AudioDecoder> CreateForwardingMockDecoder( |
| 184 | std::unique_ptr<webrtc::AudioDecoder> real_decoder) { |
| 185 | class ForwardingMockDecoder : public StrictMock<webrtc::MockAudioDecoder> { |
| 186 | public: |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 187 | explicit ForwardingMockDecoder(std::unique_ptr<AudioDecoder> decoder) |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 188 | : decoder_(std::move(decoder)) {} |
| 189 | |
| 190 | private: |
| 191 | std::unique_ptr<AudioDecoder> decoder_; |
| 192 | }; |
| 193 | |
| 194 | const auto dec = real_decoder.get(); // For lambda capturing. |
| 195 | auto mock_decoder = |
| 196 | rtc::MakeUnique<ForwardingMockDecoder>(std::move(real_decoder)); |
| 197 | EXPECT_CALL(*mock_decoder, Channels()) |
| 198 | .Times(AtLeast(1)) |
| 199 | .WillRepeatedly(Invoke([dec] { return dec->Channels(); })); |
| 200 | EXPECT_CALL(*mock_decoder, DecodeInternal(_, _, _, _, _)) |
| 201 | .Times(AtLeast(1)) |
| 202 | .WillRepeatedly( |
| 203 | Invoke([dec](const uint8_t* encoded, size_t encoded_len, |
| 204 | int sample_rate_hz, int16_t* decoded, |
| 205 | webrtc::AudioDecoder::SpeechType* speech_type) { |
| 206 | return dec->Decode(encoded, encoded_len, sample_rate_hz, |
| 207 | std::numeric_limits<size_t>::max(), decoded, |
| 208 | speech_type); |
| 209 | })); |
| 210 | EXPECT_CALL(*mock_decoder, Die()); |
| 211 | EXPECT_CALL(*mock_decoder, HasDecodePlc()).WillRepeatedly(Invoke([dec] { |
| 212 | return dec->HasDecodePlc(); |
| 213 | })); |
| 214 | EXPECT_CALL(*mock_decoder, IncomingPacket(_, _, _, _, _)) |
| 215 | .Times(AtLeast(1)) |
| 216 | .WillRepeatedly(Invoke([dec](const uint8_t* payload, size_t payload_len, |
| 217 | uint16_t rtp_sequence_number, |
| 218 | uint32_t rtp_timestamp, |
| 219 | uint32_t arrival_timestamp) { |
| 220 | return dec->IncomingPacket(payload, payload_len, rtp_sequence_number, |
| 221 | rtp_timestamp, arrival_timestamp); |
| 222 | })); |
| 223 | EXPECT_CALL(*mock_decoder, PacketDuration(_, _)) |
| 224 | .Times(AtLeast(1)) |
| 225 | .WillRepeatedly(Invoke([dec](const uint8_t* encoded, size_t encoded_len) { |
| 226 | return dec->PacketDuration(encoded, encoded_len); |
| 227 | })); |
| 228 | EXPECT_CALL(*mock_decoder, SampleRateHz()) |
| 229 | .Times(AtLeast(1)) |
| 230 | .WillRepeatedly(Invoke([dec] { return dec->SampleRateHz(); })); |
| 231 | |
| 232 | return std::move(mock_decoder); |
| 233 | } |
| 234 | |
| 235 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> |
| 236 | CreateForwardingMockDecoderFactory( |
| 237 | webrtc::AudioDecoderFactory* real_decoder_factory) { |
| 238 | rtc::scoped_refptr<webrtc::MockAudioDecoderFactory> mock_decoder_factory = |
| 239 | new rtc::RefCountedObject<StrictMock<webrtc::MockAudioDecoderFactory>>; |
| 240 | EXPECT_CALL(*mock_decoder_factory, GetSupportedDecoders()) |
| 241 | .Times(AtLeast(1)) |
| 242 | .WillRepeatedly(Invoke([real_decoder_factory] { |
| 243 | return real_decoder_factory->GetSupportedDecoders(); |
| 244 | })); |
| 245 | EXPECT_CALL(*mock_decoder_factory, IsSupportedDecoder(_)) |
| 246 | .Times(AtLeast(1)) |
| 247 | .WillRepeatedly( |
| 248 | Invoke([real_decoder_factory](const webrtc::SdpAudioFormat& format) { |
| 249 | return real_decoder_factory->IsSupportedDecoder(format); |
| 250 | })); |
| 251 | EXPECT_CALL(*mock_decoder_factory, MakeAudioDecoderMock(_, _)) |
| 252 | .Times(AtLeast(2)) |
| 253 | .WillRepeatedly( |
| 254 | Invoke([real_decoder_factory]( |
| 255 | const webrtc::SdpAudioFormat& format, |
| 256 | std::unique_ptr<webrtc::AudioDecoder>* return_value) { |
| 257 | auto real_decoder = real_decoder_factory->MakeAudioDecoder(format); |
| 258 | *return_value = |
| 259 | real_decoder |
| 260 | ? CreateForwardingMockDecoder(std::move(real_decoder)) |
| 261 | : nullptr; |
| 262 | })); |
| 263 | return mock_decoder_factory; |
| 264 | } |
| 265 | |
Karl Wiberg | c5bb00b | 2017-10-10 23:17:17 +0200 | [diff] [blame] | 266 | struct AudioEncoderUnicornSparklesRainbow { |
| 267 | using Config = webrtc::AudioEncoderL16::Config; |
| 268 | static rtc::Optional<Config> SdpToConfig(webrtc::SdpAudioFormat format) { |
| 269 | if (STR_CASE_CMP(format.name.c_str(), "UnicornSparklesRainbow") == 0) { |
| 270 | const webrtc::SdpAudioFormat::Parameters expected_params = { |
| 271 | {"num_horns", "1"}}; |
| 272 | EXPECT_EQ(expected_params, format.parameters); |
| 273 | format.parameters.clear(); |
| 274 | format.name = "L16"; |
| 275 | return webrtc::AudioEncoderL16::SdpToConfig(format); |
| 276 | } else { |
| 277 | return rtc::Optional<Config>(); |
| 278 | } |
| 279 | } |
| 280 | static void AppendSupportedEncoders( |
| 281 | std::vector<webrtc::AudioCodecSpec>* specs) { |
| 282 | std::vector<webrtc::AudioCodecSpec> new_specs; |
| 283 | webrtc::AudioEncoderL16::AppendSupportedEncoders(&new_specs); |
| 284 | for (auto& spec : new_specs) { |
| 285 | spec.format.name = "UnicornSparklesRainbow"; |
| 286 | EXPECT_TRUE(spec.format.parameters.empty()); |
| 287 | spec.format.parameters.emplace("num_horns", "1"); |
| 288 | specs->push_back(spec); |
| 289 | } |
| 290 | } |
| 291 | static webrtc::AudioCodecInfo QueryAudioEncoder(const Config& config) { |
| 292 | return webrtc::AudioEncoderL16::QueryAudioEncoder(config); |
| 293 | } |
| 294 | static std::unique_ptr<webrtc::AudioEncoder> MakeAudioEncoder( |
| 295 | const Config& config, |
| 296 | int payload_type) { |
| 297 | return webrtc::AudioEncoderL16::MakeAudioEncoder(config, payload_type); |
| 298 | } |
| 299 | }; |
| 300 | |
| 301 | struct AudioDecoderUnicornSparklesRainbow { |
| 302 | using Config = webrtc::AudioDecoderL16::Config; |
| 303 | static rtc::Optional<Config> SdpToConfig(webrtc::SdpAudioFormat format) { |
| 304 | if (STR_CASE_CMP(format.name.c_str(), "UnicornSparklesRainbow") == 0) { |
| 305 | const webrtc::SdpAudioFormat::Parameters expected_params = { |
| 306 | {"num_horns", "1"}}; |
| 307 | EXPECT_EQ(expected_params, format.parameters); |
| 308 | format.parameters.clear(); |
| 309 | format.name = "L16"; |
| 310 | return webrtc::AudioDecoderL16::SdpToConfig(format); |
| 311 | } else { |
| 312 | return rtc::Optional<Config>(); |
| 313 | } |
| 314 | } |
| 315 | static void AppendSupportedDecoders( |
| 316 | std::vector<webrtc::AudioCodecSpec>* specs) { |
| 317 | std::vector<webrtc::AudioCodecSpec> new_specs; |
| 318 | webrtc::AudioDecoderL16::AppendSupportedDecoders(&new_specs); |
| 319 | for (auto& spec : new_specs) { |
| 320 | spec.format.name = "UnicornSparklesRainbow"; |
| 321 | EXPECT_TRUE(spec.format.parameters.empty()); |
| 322 | spec.format.parameters.emplace("num_horns", "1"); |
| 323 | specs->push_back(spec); |
| 324 | } |
| 325 | } |
| 326 | static std::unique_ptr<webrtc::AudioDecoder> MakeAudioDecoder( |
| 327 | const Config& config) { |
| 328 | return webrtc::AudioDecoderL16::MakeAudioDecoder(config); |
| 329 | } |
| 330 | }; |
| 331 | |
| 332 | } // namespace |
| 333 | |
kjellander@webrtc.org | 70c0e29 | 2015-11-30 21:45:35 +0100 | [diff] [blame] | 334 | // Disabled for TSan v2, see |
| 335 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=4719 for details. |
kjellander@webrtc.org | 3c28d0d | 2015-12-02 22:53:26 +0100 | [diff] [blame] | 336 | // Disabled for Mac, see |
| 337 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=5231 for details. |
Karl Wiberg | c5bb00b | 2017-10-10 23:17:17 +0200 | [diff] [blame] | 338 | #if defined(THREAD_SANITIZER) || defined(WEBRTC_MAC) |
| 339 | #define MAYBE_Call DISABLED_Call |
| 340 | #else |
| 341 | #define MAYBE_Call Call |
| 342 | #endif |
| 343 | TEST_F(PeerConnectionEndToEndTest, MAYBE_Call) { |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 344 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> real_decoder_factory = |
| 345 | webrtc::CreateBuiltinAudioDecoderFactory(); |
| 346 | CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), |
| 347 | CreateForwardingMockDecoderFactory(real_decoder_factory.get())); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 348 | GetAndAddUserMedia(); |
| 349 | Negotiate(); |
| 350 | WaitForCallEstablished(); |
| 351 | } |
| 352 | |
philipel | 7703b27 | 2016-11-28 16:23:12 +0100 | [diff] [blame] | 353 | #if !defined(ADDRESS_SANITIZER) |
deadbeef | c9be007 | 2015-12-14 18:27:57 -0800 | [diff] [blame] | 354 | TEST_F(PeerConnectionEndToEndTest, CallWithLegacySdp) { |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 355 | FakeConstraints pc_constraints; |
| 356 | pc_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 357 | false); |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 358 | CreatePcs(&pc_constraints, webrtc::CreateBuiltinAudioEncoderFactory(), |
| 359 | webrtc::CreateBuiltinAudioDecoderFactory()); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 360 | GetAndAddUserMedia(); |
| 361 | Negotiate(); |
| 362 | WaitForCallEstablished(); |
| 363 | } |
philipel | 7703b27 | 2016-11-28 16:23:12 +0100 | [diff] [blame] | 364 | #endif // !defined(ADDRESS_SANITIZER) |
wu@webrtc.org | b43202d | 2013-11-22 19:14:25 +0000 | [diff] [blame] | 365 | |
Karl Wiberg | c5bb00b | 2017-10-10 23:17:17 +0200 | [diff] [blame] | 366 | TEST_F(PeerConnectionEndToEndTest, CallWithCustomCodec) { |
| 367 | CreatePcs( |
| 368 | nullptr, |
| 369 | webrtc::CreateAudioEncoderFactory<AudioEncoderUnicornSparklesRainbow>(), |
| 370 | webrtc::CreateAudioDecoderFactory<AudioDecoderUnicornSparklesRainbow>()); |
| 371 | GetAndAddUserMedia(); |
| 372 | Negotiate(); |
| 373 | WaitForCallEstablished(); |
| 374 | } |
| 375 | |
deadbeef | 40610e2 | 2016-12-22 10:53:38 -0800 | [diff] [blame] | 376 | #ifdef HAVE_SCTP |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 377 | // Verifies that a DataChannel created before the negotiation can transition to |
| 378 | // "OPEN" and transfer data. |
| 379 | TEST_F(PeerConnectionEndToEndTest, CreateDataChannelBeforeNegotiate) { |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 380 | CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), |
kwiberg | 7a12b5a | 2017-04-27 03:55:57 -0700 | [diff] [blame] | 381 | webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 382 | |
| 383 | webrtc::DataChannelInit init; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 384 | rtc::scoped_refptr<DataChannelInterface> caller_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 385 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 386 | rtc::scoped_refptr<DataChannelInterface> callee_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 387 | callee_->CreateDataChannel("data", init)); |
| 388 | |
| 389 | Negotiate(); |
| 390 | WaitForConnection(); |
| 391 | |
| 392 | WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 393 | WaitForDataChannelsToOpen(callee_dc, caller_signaled_data_channels_, 0); |
| 394 | |
| 395 | TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[0]); |
| 396 | TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); |
| 397 | |
| 398 | CloseDataChannels(caller_dc, callee_signaled_data_channels_, 0); |
| 399 | CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); |
| 400 | } |
| 401 | |
| 402 | // Verifies that a DataChannel created after the negotiation can transition to |
| 403 | // "OPEN" and transfer data. |
Taylor Brandstetter | bf2f569 | 2016-06-29 11:22:47 -0700 | [diff] [blame] | 404 | TEST_F(PeerConnectionEndToEndTest, CreateDataChannelAfterNegotiate) { |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 405 | CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), |
kwiberg | 7a12b5a | 2017-04-27 03:55:57 -0700 | [diff] [blame] | 406 | webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 407 | |
| 408 | webrtc::DataChannelInit init; |
| 409 | |
| 410 | // This DataChannel is for creating the data content in the negotiation. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 411 | rtc::scoped_refptr<DataChannelInterface> dummy( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 412 | caller_->CreateDataChannel("data", init)); |
| 413 | Negotiate(); |
| 414 | WaitForConnection(); |
| 415 | |
Taylor Brandstetter | bf2f569 | 2016-06-29 11:22:47 -0700 | [diff] [blame] | 416 | // Wait for the data channel created pre-negotiation to be opened. |
| 417 | WaitForDataChannelsToOpen(dummy, callee_signaled_data_channels_, 0); |
| 418 | |
| 419 | // Create new DataChannels after the negotiation and verify their states. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 420 | rtc::scoped_refptr<DataChannelInterface> caller_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 421 | caller_->CreateDataChannel("hello", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 422 | rtc::scoped_refptr<DataChannelInterface> callee_dc( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 423 | callee_->CreateDataChannel("hello", init)); |
| 424 | |
| 425 | WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 1); |
| 426 | WaitForDataChannelsToOpen(callee_dc, caller_signaled_data_channels_, 0); |
| 427 | |
| 428 | TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[1]); |
| 429 | TestDataChannelSendAndReceive(callee_dc, caller_signaled_data_channels_[0]); |
| 430 | |
| 431 | CloseDataChannels(caller_dc, callee_signaled_data_channels_, 1); |
| 432 | CloseDataChannels(callee_dc, caller_signaled_data_channels_, 0); |
| 433 | } |
| 434 | |
| 435 | // Verifies that DataChannel IDs are even/odd based on the DTLS roles. |
| 436 | TEST_F(PeerConnectionEndToEndTest, DataChannelIdAssignment) { |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 437 | CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), |
kwiberg | 7a12b5a | 2017-04-27 03:55:57 -0700 | [diff] [blame] | 438 | webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 439 | |
| 440 | webrtc::DataChannelInit init; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 441 | rtc::scoped_refptr<DataChannelInterface> caller_dc_1( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 442 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 443 | rtc::scoped_refptr<DataChannelInterface> callee_dc_1( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 444 | callee_->CreateDataChannel("data", init)); |
| 445 | |
| 446 | Negotiate(); |
| 447 | WaitForConnection(); |
| 448 | |
| 449 | EXPECT_EQ(1U, caller_dc_1->id() % 2); |
| 450 | EXPECT_EQ(0U, callee_dc_1->id() % 2); |
| 451 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 452 | rtc::scoped_refptr<DataChannelInterface> caller_dc_2( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 453 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 454 | rtc::scoped_refptr<DataChannelInterface> callee_dc_2( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 455 | callee_->CreateDataChannel("data", init)); |
| 456 | |
| 457 | EXPECT_EQ(1U, caller_dc_2->id() % 2); |
| 458 | EXPECT_EQ(0U, callee_dc_2->id() % 2); |
| 459 | } |
| 460 | |
| 461 | // Verifies that the message is received by the right remote DataChannel when |
| 462 | // there are multiple DataChannels. |
| 463 | TEST_F(PeerConnectionEndToEndTest, |
| 464 | MessageTransferBetweenTwoPairsOfDataChannels) { |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 465 | CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), |
kwiberg | 7a12b5a | 2017-04-27 03:55:57 -0700 | [diff] [blame] | 466 | webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 467 | |
| 468 | webrtc::DataChannelInit init; |
| 469 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 470 | rtc::scoped_refptr<DataChannelInterface> caller_dc_1( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 471 | caller_->CreateDataChannel("data", init)); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 472 | rtc::scoped_refptr<DataChannelInterface> caller_dc_2( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 473 | caller_->CreateDataChannel("data", init)); |
| 474 | |
| 475 | Negotiate(); |
| 476 | WaitForConnection(); |
| 477 | WaitForDataChannelsToOpen(caller_dc_1, callee_signaled_data_channels_, 0); |
| 478 | WaitForDataChannelsToOpen(caller_dc_2, callee_signaled_data_channels_, 1); |
| 479 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 480 | std::unique_ptr<webrtc::MockDataChannelObserver> dc_1_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 481 | new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[0])); |
| 482 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 483 | std::unique_ptr<webrtc::MockDataChannelObserver> dc_2_observer( |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 484 | new webrtc::MockDataChannelObserver(callee_signaled_data_channels_[1])); |
| 485 | |
| 486 | const std::string message_1 = "hello 1"; |
| 487 | const std::string message_2 = "hello 2"; |
| 488 | |
| 489 | caller_dc_1->Send(webrtc::DataBuffer(message_1)); |
| 490 | EXPECT_EQ_WAIT(message_1, dc_1_observer->last_message(), kMaxWait); |
| 491 | |
| 492 | caller_dc_2->Send(webrtc::DataBuffer(message_2)); |
| 493 | EXPECT_EQ_WAIT(message_2, dc_2_observer->last_message(), kMaxWait); |
| 494 | |
| 495 | EXPECT_EQ(1U, dc_1_observer->received_message_count()); |
| 496 | EXPECT_EQ(1U, dc_2_observer->received_message_count()); |
| 497 | } |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 498 | |
| 499 | // Verifies that a DataChannel added from an OPEN message functions after |
| 500 | // a channel has been previously closed (webrtc issue 3778). |
| 501 | // This previously failed because the new channel re-uses the ID of the closed |
| 502 | // channel, and the closed channel was incorrectly still assigned to the id. |
| 503 | // TODO(deadbeef): This is disabled because there's currently a race condition |
| 504 | // caused by the fact that a data channel signals that it's closed before it |
| 505 | // really is. Re-enable this test once that's fixed. |
deadbeef | e2213ce | 2016-11-03 16:01:57 -0700 | [diff] [blame] | 506 | // See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4453 |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 507 | TEST_F(PeerConnectionEndToEndTest, |
| 508 | DISABLED_DataChannelFromOpenWorksAfterClose) { |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 509 | CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), |
kwiberg | 7a12b5a | 2017-04-27 03:55:57 -0700 | [diff] [blame] | 510 | webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); |
deadbeef | ab9b2d1 | 2015-10-14 11:33:11 -0700 | [diff] [blame] | 511 | |
| 512 | webrtc::DataChannelInit init; |
| 513 | rtc::scoped_refptr<DataChannelInterface> caller_dc( |
| 514 | caller_->CreateDataChannel("data", init)); |
| 515 | |
| 516 | Negotiate(); |
| 517 | WaitForConnection(); |
| 518 | |
| 519 | WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 520 | CloseDataChannels(caller_dc, callee_signaled_data_channels_, 0); |
| 521 | |
| 522 | // Create a new channel and ensure it works after closing the previous one. |
| 523 | caller_dc = caller_->CreateDataChannel("data2", init); |
| 524 | |
| 525 | WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 1); |
| 526 | TestDataChannelSendAndReceive(caller_dc, callee_signaled_data_channels_[1]); |
| 527 | |
| 528 | CloseDataChannels(caller_dc, callee_signaled_data_channels_, 1); |
| 529 | } |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 530 | |
| 531 | // This tests that if a data channel is closed remotely while not referenced |
| 532 | // by the application (meaning only the PeerConnection contributes to its |
| 533 | // reference count), no memory access violation will occur. |
| 534 | // See: https://code.google.com/p/chromium/issues/detail?id=565048 |
| 535 | TEST_F(PeerConnectionEndToEndTest, CloseDataChannelRemotelyWhileNotReferenced) { |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 536 | CreatePcs(nullptr, webrtc::CreateBuiltinAudioEncoderFactory(), |
kwiberg | 7a12b5a | 2017-04-27 03:55:57 -0700 | [diff] [blame] | 537 | webrtc::MockAudioDecoderFactory::CreateEmptyFactory()); |
deadbeef | bd29246 | 2015-12-14 18:15:29 -0800 | [diff] [blame] | 538 | |
| 539 | webrtc::DataChannelInit init; |
| 540 | rtc::scoped_refptr<DataChannelInterface> caller_dc( |
| 541 | caller_->CreateDataChannel("data", init)); |
| 542 | |
| 543 | Negotiate(); |
| 544 | WaitForConnection(); |
| 545 | |
| 546 | WaitForDataChannelsToOpen(caller_dc, callee_signaled_data_channels_, 0); |
| 547 | // This removes the reference to the remote data channel that we hold. |
| 548 | callee_signaled_data_channels_.clear(); |
| 549 | caller_dc->Close(); |
| 550 | EXPECT_EQ_WAIT(DataChannelInterface::kClosed, caller_dc->state(), kMaxWait); |
| 551 | |
| 552 | // Wait for a bit longer so the remote data channel will receive the |
| 553 | // close message and be destroyed. |
| 554 | rtc::Thread::Current()->ProcessMessages(100); |
| 555 | } |
deadbeef | 40610e2 | 2016-12-22 10:53:38 -0800 | [diff] [blame] | 556 | #endif // HAVE_SCTP |