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 | |
Steve Anton | 36b29d1 | 2017-10-30 09:57:42 -0700 | [diff] [blame] | 11 | #include <string> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 12 | #include <utility> |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 13 | #include <vector> |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 14 | |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 15 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 16 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
| 17 | #include "modules/audio_processing/include/audio_processing.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "p2p/base/fakeportallocator.h" |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 19 | #include "pc/sdputils.h" |
Niels Möller | a1cc73f | 2018-05-28 16:20:42 +0200 | [diff] [blame] | 20 | #include "pc/test/fakeperiodicvideotracksource.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "pc/test/fakertccertificategenerator.h" |
| 22 | #include "pc/test/mockpeerconnectionobservers.h" |
| 23 | #include "pc/test/peerconnectiontestwrapper.h" |
| 24 | #include "rtc_base/gunit.h" |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 25 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 26 | using webrtc::FakeConstraints; |
| 27 | using webrtc::FakeVideoTrackRenderer; |
| 28 | using webrtc::IceCandidateInterface; |
| 29 | using webrtc::MediaConstraintsInterface; |
| 30 | using webrtc::MediaStreamInterface; |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 31 | using webrtc::MediaStreamTrackInterface; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 32 | using webrtc::MockSetSessionDescriptionObserver; |
| 33 | using webrtc::PeerConnectionInterface; |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 34 | using webrtc::RtpReceiverInterface; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 35 | using webrtc::SdpType; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 36 | using webrtc::SessionDescriptionInterface; |
| 37 | using webrtc::VideoTrackInterface; |
| 38 | |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 39 | namespace { |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 40 | const char kStreamIdBase[] = "stream_id"; |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 41 | const char kVideoTrackLabelBase[] = "video_track"; |
| 42 | const char kAudioTrackLabelBase[] = "audio_track"; |
| 43 | constexpr int kMaxWait = 10000; |
| 44 | constexpr int kTestAudioFrameCount = 3; |
| 45 | constexpr int kTestVideoFrameCount = 3; |
| 46 | } // namespace |
| 47 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 48 | void PeerConnectionTestWrapper::Connect(PeerConnectionTestWrapper* caller, |
| 49 | PeerConnectionTestWrapper* callee) { |
| 50 | caller->SignalOnIceCandidateReady.connect( |
| 51 | callee, &PeerConnectionTestWrapper::AddIceCandidate); |
| 52 | callee->SignalOnIceCandidateReady.connect( |
| 53 | caller, &PeerConnectionTestWrapper::AddIceCandidate); |
| 54 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 55 | caller->SignalOnSdpReady.connect(callee, |
| 56 | &PeerConnectionTestWrapper::ReceiveOfferSdp); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 57 | callee->SignalOnSdpReady.connect( |
| 58 | caller, &PeerConnectionTestWrapper::ReceiveAnswerSdp); |
| 59 | } |
| 60 | |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 61 | PeerConnectionTestWrapper::PeerConnectionTestWrapper( |
| 62 | const std::string& name, |
| 63 | rtc::Thread* network_thread, |
| 64 | rtc::Thread* worker_thread) |
| 65 | : name_(name), |
| 66 | network_thread_(network_thread), |
| 67 | worker_thread_(worker_thread) {} |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 68 | |
| 69 | PeerConnectionTestWrapper::~PeerConnectionTestWrapper() {} |
| 70 | |
| 71 | bool PeerConnectionTestWrapper::CreatePc( |
zhihuang | 9763d56 | 2016-08-05 11:14:50 -0700 | [diff] [blame] | 72 | const MediaConstraintsInterface* constraints, |
kwiberg | 9e5b11e | 2017-04-19 03:47:57 -0700 | [diff] [blame] | 73 | const webrtc::PeerConnectionInterface::RTCConfiguration& config, |
| 74 | rtc::scoped_refptr<webrtc::AudioEncoderFactory> audio_encoder_factory, |
| 75 | rtc::scoped_refptr<webrtc::AudioDecoderFactory> audio_decoder_factory) { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 76 | std::unique_ptr<cricket::PortAllocator> port_allocator( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 77 | new cricket::FakePortAllocator(network_thread_, nullptr)); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 78 | |
deadbeef | ee8c6d3 | 2015-08-13 14:27:18 -0700 | [diff] [blame] | 79 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create(); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 80 | if (fake_audio_capture_module_ == NULL) { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
danilchap | e9021a3 | 2016-05-17 01:52:02 -0700 | [diff] [blame] | 85 | network_thread_, worker_thread_, rtc::Thread::Current(), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 86 | rtc::scoped_refptr<webrtc::AudioDeviceModule>(fake_audio_capture_module_), |
| 87 | audio_encoder_factory, audio_decoder_factory, |
| 88 | webrtc::CreateBuiltinVideoEncoderFactory(), |
| 89 | webrtc::CreateBuiltinVideoDecoderFactory(), nullptr /* audio_mixer */, |
| 90 | nullptr /* audio_processing */); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 91 | if (!peer_connection_factory_) { |
| 92 | return false; |
| 93 | } |
| 94 | |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 95 | std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator( |
deadbeef | 1b54a5f | 2017-01-23 19:39:57 -0800 | [diff] [blame] | 96 | new FakeRTCCertificateGenerator()); |
Henrik Boström | d79599d | 2016-06-01 13:58:50 +0200 | [diff] [blame] | 97 | peer_connection_ = peer_connection_factory_->CreatePeerConnection( |
| 98 | config, constraints, std::move(port_allocator), std::move(cert_generator), |
| 99 | this); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 100 | |
| 101 | return peer_connection_.get() != NULL; |
| 102 | } |
| 103 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 104 | rtc::scoped_refptr<webrtc::DataChannelInterface> |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 105 | PeerConnectionTestWrapper::CreateDataChannel( |
| 106 | const std::string& label, |
| 107 | const webrtc::DataChannelInit& init) { |
| 108 | return peer_connection_->CreateDataChannel(label, &init); |
| 109 | } |
| 110 | |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 111 | void PeerConnectionTestWrapper::OnAddTrack( |
| 112 | rtc::scoped_refptr<RtpReceiverInterface> receiver, |
| 113 | const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) { |
| 114 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": OnAddTrack"; |
| 115 | if (receiver->track()->kind() == MediaStreamTrackInterface::kVideoKind) { |
| 116 | auto* video_track = |
| 117 | static_cast<VideoTrackInterface*>(receiver->track().get()); |
Karl Wiberg | 918f50c | 2018-07-05 11:40:33 +0200 | [diff] [blame] | 118 | renderer_ = absl::make_unique<FakeVideoTrackRenderer>(video_track); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 119 | } |
| 120 | } |
| 121 | |
| 122 | void PeerConnectionTestWrapper::OnIceCandidate( |
| 123 | const IceCandidateInterface* candidate) { |
| 124 | std::string sdp; |
| 125 | EXPECT_TRUE(candidate->ToString(&sdp)); |
| 126 | // Give the user a chance to modify sdp for testing. |
| 127 | SignalOnIceCandidateCreated(&sdp); |
| 128 | SignalOnIceCandidateReady(candidate->sdp_mid(), candidate->sdp_mline_index(), |
| 129 | sdp); |
| 130 | } |
| 131 | |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 132 | void PeerConnectionTestWrapper::OnDataChannel( |
Taylor Brandstetter | 98cde26 | 2016-05-31 13:02:21 -0700 | [diff] [blame] | 133 | rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) { |
jiayl@webrtc.org | 1a6c628 | 2014-06-12 21:59:29 +0000 | [diff] [blame] | 134 | SignalOnDataChannel(data_channel); |
| 135 | } |
| 136 | |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 137 | void PeerConnectionTestWrapper::OnSuccess(SessionDescriptionInterface* desc) { |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 138 | // This callback should take the ownership of |desc|. |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 139 | std::unique_ptr<SessionDescriptionInterface> owned_desc(desc); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 140 | std::string sdp; |
| 141 | EXPECT_TRUE(desc->ToString(&sdp)); |
| 142 | |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 143 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": " |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 144 | << webrtc::SdpTypeToString(desc->GetType()) |
| 145 | << " sdp created: " << sdp; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 146 | |
| 147 | // Give the user a chance to modify sdp for testing. |
| 148 | SignalOnSdpCreated(&sdp); |
| 149 | |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 150 | SetLocalDescription(desc->GetType(), sdp); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 151 | |
| 152 | SignalOnSdpReady(sdp); |
| 153 | } |
| 154 | |
| 155 | void PeerConnectionTestWrapper::CreateOffer( |
| 156 | const MediaConstraintsInterface* constraints) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 157 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": CreateOffer."; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 158 | peer_connection_->CreateOffer(this, constraints); |
| 159 | } |
| 160 | |
| 161 | void PeerConnectionTestWrapper::CreateAnswer( |
| 162 | const MediaConstraintsInterface* constraints) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 163 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ |
| 164 | << ": CreateAnswer."; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 165 | peer_connection_->CreateAnswer(this, constraints); |
| 166 | } |
| 167 | |
| 168 | void PeerConnectionTestWrapper::ReceiveOfferSdp(const std::string& sdp) { |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 169 | SetRemoteDescription(SdpType::kOffer, sdp); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 170 | CreateAnswer(NULL); |
| 171 | } |
| 172 | |
| 173 | void PeerConnectionTestWrapper::ReceiveAnswerSdp(const std::string& sdp) { |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 174 | SetRemoteDescription(SdpType::kAnswer, sdp); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 177 | void PeerConnectionTestWrapper::SetLocalDescription(SdpType type, |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 178 | const std::string& sdp) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 179 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 180 | << ": SetLocalDescription " << webrtc::SdpTypeToString(type) |
| 181 | << " " << sdp; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 182 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 183 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 184 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 185 | peer_connection_->SetLocalDescription( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 186 | observer, webrtc::CreateSessionDescription(type, sdp).release()); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 189 | void PeerConnectionTestWrapper::SetRemoteDescription(SdpType type, |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 190 | const std::string& sdp) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 191 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 192 | << ": SetRemoteDescription " << webrtc::SdpTypeToString(type) |
| 193 | << " " << sdp; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 194 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 195 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer( |
| 196 | new rtc::RefCountedObject<MockSetSessionDescriptionObserver>()); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 197 | peer_connection_->SetRemoteDescription( |
Steve Anton | a3a92c2 | 2017-12-07 10:27:41 -0800 | [diff] [blame] | 198 | observer, webrtc::CreateSessionDescription(type, sdp).release()); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | void PeerConnectionTestWrapper::AddIceCandidate(const std::string& sdp_mid, |
| 202 | int sdp_mline_index, |
| 203 | const std::string& candidate) { |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 204 | std::unique_ptr<webrtc::IceCandidateInterface> owned_candidate( |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 205 | webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, candidate, NULL)); |
| 206 | EXPECT_TRUE(peer_connection_->AddIceCandidate(owned_candidate.get())); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | void PeerConnectionTestWrapper::WaitForCallEstablished() { |
| 210 | WaitForConnection(); |
| 211 | WaitForAudio(); |
| 212 | WaitForVideo(); |
| 213 | } |
| 214 | |
| 215 | void PeerConnectionTestWrapper::WaitForConnection() { |
| 216 | EXPECT_TRUE_WAIT(CheckForConnection(), kMaxWait); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 217 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ << ": Connected."; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | bool PeerConnectionTestWrapper::CheckForConnection() { |
| 221 | return (peer_connection_->ice_connection_state() == |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 222 | PeerConnectionInterface::kIceConnectionConnected) || |
| 223 | (peer_connection_->ice_connection_state() == |
| 224 | PeerConnectionInterface::kIceConnectionCompleted); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | void PeerConnectionTestWrapper::WaitForAudio() { |
| 228 | EXPECT_TRUE_WAIT(CheckForAudio(), kMaxWait); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 229 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ |
| 230 | << ": Got enough audio frames."; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | bool PeerConnectionTestWrapper::CheckForAudio() { |
| 234 | return (fake_audio_capture_module_->frames_received() >= |
| 235 | kTestAudioFrameCount); |
| 236 | } |
| 237 | |
| 238 | void PeerConnectionTestWrapper::WaitForVideo() { |
| 239 | EXPECT_TRUE_WAIT(CheckForVideo(), kMaxWait); |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 240 | RTC_LOG(LS_INFO) << "PeerConnectionTestWrapper " << name_ |
| 241 | << ": Got enough video frames."; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | bool PeerConnectionTestWrapper::CheckForVideo() { |
| 245 | if (!renderer_) { |
| 246 | return false; |
| 247 | } |
| 248 | return (renderer_->num_rendered_frames() >= kTestVideoFrameCount); |
| 249 | } |
| 250 | |
| 251 | void PeerConnectionTestWrapper::GetAndAddUserMedia( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 252 | bool audio, |
| 253 | const cricket::AudioOptions& audio_options, |
| 254 | bool video, |
| 255 | const webrtc::FakeConstraints& video_constraints) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 256 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 257 | GetUserMedia(audio, audio_options, video, video_constraints); |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 258 | for (auto audio_track : stream->GetAudioTracks()) { |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 259 | EXPECT_TRUE(peer_connection_->AddTrack(audio_track, {stream->id()}).ok()); |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 260 | } |
| 261 | for (auto video_track : stream->GetVideoTracks()) { |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 262 | EXPECT_TRUE(peer_connection_->AddTrack(video_track, {stream->id()}).ok()); |
Steve Anton | 191c39f | 2018-01-24 19:35:55 -0800 | [diff] [blame] | 263 | } |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 264 | } |
| 265 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 266 | rtc::scoped_refptr<webrtc::MediaStreamInterface> |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 267 | PeerConnectionTestWrapper::GetUserMedia( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 268 | bool audio, |
| 269 | const cricket::AudioOptions& audio_options, |
| 270 | bool video, |
| 271 | const webrtc::FakeConstraints& video_constraints) { |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 272 | std::string stream_id = |
| 273 | kStreamIdBase + rtc::ToString(num_get_user_media_calls_++); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 274 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 275 | peer_connection_factory_->CreateLocalMediaStream(stream_id); |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 276 | |
| 277 | if (audio) { |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 278 | cricket::AudioOptions options = audio_options; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 279 | // Disable highpass filter so that we can get all the test audio frames. |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 280 | options.highpass_filter = false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 281 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
Niels Möller | 2d02e08 | 2018-05-21 11:23:35 +0200 | [diff] [blame] | 282 | peer_connection_factory_->CreateAudioSource(options); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 283 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 284 | peer_connection_factory_->CreateAudioTrack(kAudioTrackLabelBase, |
| 285 | source)); |
| 286 | stream->AddTrack(audio_track); |
| 287 | } |
| 288 | |
| 289 | if (video) { |
| 290 | // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. |
Niels Möller | a1cc73f | 2018-05-28 16:20:42 +0200 | [diff] [blame] | 291 | webrtc::FakePeriodicVideoSource::Config config; |
| 292 | config.frame_interval_ms = 100; |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 293 | |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 294 | rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source = |
Niels Möller | a1cc73f | 2018-05-28 16:20:42 +0200 | [diff] [blame] | 295 | new rtc::RefCountedObject<webrtc::FakePeriodicVideoTrackSource>( |
| 296 | config, /* remote */ false); |
| 297 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 298 | std::string videotrack_label = stream_id + kVideoTrackLabelBase; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 299 | rtc::scoped_refptr<webrtc::VideoTrackInterface> video_track( |
wu@webrtc.org | 364f204 | 2013-11-20 21:49:41 +0000 | [diff] [blame] | 300 | peer_connection_factory_->CreateVideoTrack(videotrack_label, source)); |
| 301 | |
| 302 | stream->AddTrack(video_track); |
| 303 | } |
| 304 | return stream; |
| 305 | } |