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