henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2012, Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | |
| 30 | #include <algorithm> |
| 31 | #include <list> |
| 32 | #include <map> |
| 33 | #include <vector> |
| 34 | |
| 35 | #include "talk/app/webrtc/dtmfsender.h" |
| 36 | #include "talk/app/webrtc/fakeportallocatorfactory.h" |
| 37 | #include "talk/app/webrtc/localaudiosource.h" |
| 38 | #include "talk/app/webrtc/mediastreaminterface.h" |
| 39 | #include "talk/app/webrtc/peerconnectionfactory.h" |
| 40 | #include "talk/app/webrtc/peerconnectioninterface.h" |
| 41 | #include "talk/app/webrtc/test/fakeaudiocapturemodule.h" |
| 42 | #include "talk/app/webrtc/test/fakeconstraints.h" |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 43 | #include "talk/app/webrtc/test/fakedtlsidentityservice.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 44 | #include "talk/app/webrtc/test/fakeperiodicvideocapturer.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 45 | #include "talk/app/webrtc/test/fakevideotrackrenderer.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 46 | #include "talk/app/webrtc/test/mockpeerconnectionobservers.h" |
| 47 | #include "talk/app/webrtc/videosourceinterface.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 48 | #include "talk/media/webrtc/fakewebrtcvideoengine.h" |
| 49 | #include "talk/p2p/base/constants.h" |
| 50 | #include "talk/p2p/base/sessiondescription.h" |
| 51 | #include "talk/session/media/mediasession.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 52 | #include "webrtc/base/gunit.h" |
| 53 | #include "webrtc/base/scoped_ptr.h" |
| 54 | #include "webrtc/base/ssladapter.h" |
| 55 | #include "webrtc/base/sslstreamadapter.h" |
| 56 | #include "webrtc/base/thread.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 57 | |
| 58 | #define MAYBE_SKIP_TEST(feature) \ |
| 59 | if (!(feature())) { \ |
| 60 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 61 | return; \ |
| 62 | } |
| 63 | |
| 64 | using cricket::ContentInfo; |
| 65 | using cricket::FakeWebRtcVideoDecoder; |
| 66 | using cricket::FakeWebRtcVideoDecoderFactory; |
| 67 | using cricket::FakeWebRtcVideoEncoder; |
| 68 | using cricket::FakeWebRtcVideoEncoderFactory; |
| 69 | using cricket::MediaContentDescription; |
| 70 | using webrtc::DataBuffer; |
| 71 | using webrtc::DataChannelInterface; |
| 72 | using webrtc::DtmfSender; |
| 73 | using webrtc::DtmfSenderInterface; |
| 74 | using webrtc::DtmfSenderObserverInterface; |
| 75 | using webrtc::FakeConstraints; |
| 76 | using webrtc::MediaConstraintsInterface; |
| 77 | using webrtc::MediaStreamTrackInterface; |
| 78 | using webrtc::MockCreateSessionDescriptionObserver; |
| 79 | using webrtc::MockDataChannelObserver; |
| 80 | using webrtc::MockSetSessionDescriptionObserver; |
| 81 | using webrtc::MockStatsObserver; |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 82 | using webrtc::PeerConnectionInterface; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | using webrtc::SessionDescriptionInterface; |
| 84 | using webrtc::StreamCollectionInterface; |
| 85 | |
jiayl@webrtc.org | 8f88f20 | 2014-04-16 17:14:21 +0000 | [diff] [blame] | 86 | static const int kMaxWaitMs = 2000; |
pbos@webrtc.org | 044bdac | 2014-06-03 09:40:01 +0000 | [diff] [blame] | 87 | // Disable for TSan v2, see |
| 88 | // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| 89 | // This declaration is also #ifdef'd as it causes uninitialized-variable |
| 90 | // warnings. |
| 91 | #if !defined(THREAD_SANITIZER) |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | static const int kMaxWaitForStatsMs = 3000; |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 93 | static const int kMaxWaitForRembMs = 5000; |
pbos@webrtc.org | 044bdac | 2014-06-03 09:40:01 +0000 | [diff] [blame] | 94 | #endif |
buildbot@webrtc.org | 3e01e0b | 2014-05-13 17:54:10 +0000 | [diff] [blame] | 95 | static const int kMaxWaitForFramesMs = 10000; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 96 | static const int kEndAudioFrameCount = 3; |
| 97 | static const int kEndVideoFrameCount = 3; |
| 98 | |
| 99 | static const char kStreamLabelBase[] = "stream_label"; |
| 100 | static const char kVideoTrackLabelBase[] = "video_track"; |
| 101 | static const char kAudioTrackLabelBase[] = "audio_track"; |
| 102 | static const char kDataChannelLabel[] = "data_channel"; |
| 103 | |
| 104 | static void RemoveLinesFromSdp(const std::string& line_start, |
| 105 | std::string* sdp) { |
| 106 | const char kSdpLineEnd[] = "\r\n"; |
| 107 | size_t ssrc_pos = 0; |
| 108 | while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != |
| 109 | std::string::npos) { |
| 110 | size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); |
| 111 | sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | class SignalingMessageReceiver { |
| 116 | public: |
| 117 | protected: |
| 118 | SignalingMessageReceiver() {} |
| 119 | virtual ~SignalingMessageReceiver() {} |
| 120 | }; |
| 121 | |
| 122 | class JsepMessageReceiver : public SignalingMessageReceiver { |
| 123 | public: |
| 124 | virtual void ReceiveSdpMessage(const std::string& type, |
| 125 | std::string& msg) = 0; |
| 126 | virtual void ReceiveIceMessage(const std::string& sdp_mid, |
| 127 | int sdp_mline_index, |
| 128 | const std::string& msg) = 0; |
| 129 | |
| 130 | protected: |
| 131 | JsepMessageReceiver() {} |
| 132 | virtual ~JsepMessageReceiver() {} |
| 133 | }; |
| 134 | |
| 135 | template <typename MessageReceiver> |
| 136 | class PeerConnectionTestClientBase |
| 137 | : public webrtc::PeerConnectionObserver, |
| 138 | public MessageReceiver { |
| 139 | public: |
| 140 | ~PeerConnectionTestClientBase() { |
| 141 | while (!fake_video_renderers_.empty()) { |
| 142 | RenderMap::iterator it = fake_video_renderers_.begin(); |
| 143 | delete it->second; |
| 144 | fake_video_renderers_.erase(it); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | virtual void Negotiate() = 0; |
| 149 | |
| 150 | virtual void Negotiate(bool audio, bool video) = 0; |
| 151 | |
| 152 | virtual void SetVideoConstraints( |
| 153 | const webrtc::FakeConstraints& video_constraint) { |
| 154 | video_constraints_ = video_constraint; |
| 155 | } |
| 156 | |
| 157 | void AddMediaStream(bool audio, bool video) { |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 158 | std::string stream_label = kStreamLabelBase + |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 159 | rtc::ToString<int>( |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 160 | static_cast<int>(peer_connection_->local_streams()->count())); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 161 | rtc::scoped_refptr<webrtc::MediaStreamInterface> stream = |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 162 | peer_connection_factory_->CreateLocalMediaStream(stream_label); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 163 | |
| 164 | if (audio && can_receive_audio()) { |
| 165 | FakeConstraints constraints; |
| 166 | // Disable highpass filter so that we can get all the test audio frames. |
| 167 | constraints.AddMandatory( |
| 168 | MediaConstraintsInterface::kHighpassFilter, false); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 169 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 170 | peer_connection_factory_->CreateAudioSource(&constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 171 | // TODO(perkj): Test audio source when it is implemented. Currently audio |
| 172 | // always use the default input. |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 173 | std::string label = stream_label + kAudioTrackLabelBase; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 174 | rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track( |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 175 | peer_connection_factory_->CreateAudioTrack(label, source)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 176 | stream->AddTrack(audio_track); |
| 177 | } |
| 178 | if (video && can_receive_video()) { |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 179 | stream->AddTrack(CreateLocalVideoTrack(stream_label)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | EXPECT_TRUE(peer_connection_->AddStream(stream, NULL)); |
| 183 | } |
| 184 | |
| 185 | size_t NumberOfLocalMediaStreams() { |
| 186 | return peer_connection_->local_streams()->count(); |
| 187 | } |
| 188 | |
| 189 | bool SessionActive() { |
| 190 | return peer_connection_->signaling_state() == |
| 191 | webrtc::PeerConnectionInterface::kStable; |
| 192 | } |
| 193 | |
| 194 | void set_signaling_message_receiver( |
| 195 | MessageReceiver* signaling_message_receiver) { |
| 196 | signaling_message_receiver_ = signaling_message_receiver; |
| 197 | } |
| 198 | |
| 199 | void EnableVideoDecoderFactory() { |
| 200 | video_decoder_factory_enabled_ = true; |
| 201 | fake_video_decoder_factory_->AddSupportedVideoCodecType( |
| 202 | webrtc::kVideoCodecVP8); |
| 203 | } |
| 204 | |
| 205 | bool AudioFramesReceivedCheck(int number_of_frames) const { |
| 206 | return number_of_frames <= fake_audio_capture_module_->frames_received(); |
| 207 | } |
| 208 | |
| 209 | bool VideoFramesReceivedCheck(int number_of_frames) { |
| 210 | if (video_decoder_factory_enabled_) { |
| 211 | const std::vector<FakeWebRtcVideoDecoder*>& decoders |
| 212 | = fake_video_decoder_factory_->decoders(); |
| 213 | if (decoders.empty()) { |
| 214 | return number_of_frames <= 0; |
| 215 | } |
| 216 | |
| 217 | for (std::vector<FakeWebRtcVideoDecoder*>::const_iterator |
| 218 | it = decoders.begin(); it != decoders.end(); ++it) { |
| 219 | if (number_of_frames > (*it)->GetNumFramesReceived()) { |
| 220 | return false; |
| 221 | } |
| 222 | } |
| 223 | return true; |
| 224 | } else { |
| 225 | if (fake_video_renderers_.empty()) { |
| 226 | return number_of_frames <= 0; |
| 227 | } |
| 228 | |
| 229 | for (RenderMap::const_iterator it = fake_video_renderers_.begin(); |
| 230 | it != fake_video_renderers_.end(); ++it) { |
| 231 | if (number_of_frames > it->second->num_rendered_frames()) { |
| 232 | return false; |
| 233 | } |
| 234 | } |
| 235 | return true; |
| 236 | } |
| 237 | } |
| 238 | // Verify the CreateDtmfSender interface |
| 239 | void VerifyDtmf() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 240 | rtc::scoped_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver()); |
| 241 | rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 242 | |
| 243 | // We can't create a DTMF sender with an invalid audio track or a non local |
| 244 | // track. |
| 245 | EXPECT_TRUE(peer_connection_->CreateDtmfSender(NULL) == NULL); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 246 | rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 247 | peer_connection_factory_->CreateAudioTrack("dummy_track", |
| 248 | NULL)); |
| 249 | EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == NULL); |
| 250 | |
| 251 | // We should be able to create a DTMF sender from a local track. |
| 252 | webrtc::AudioTrackInterface* localtrack = |
| 253 | peer_connection_->local_streams()->at(0)->GetAudioTracks()[0]; |
| 254 | dtmf_sender = peer_connection_->CreateDtmfSender(localtrack); |
| 255 | EXPECT_TRUE(dtmf_sender.get() != NULL); |
| 256 | dtmf_sender->RegisterObserver(observer.get()); |
| 257 | |
| 258 | // Test the DtmfSender object just created. |
| 259 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 260 | EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50)); |
| 261 | |
| 262 | // We don't need to verify that the DTMF tones are actually sent out because |
| 263 | // that is already covered by the tests of the lower level components. |
| 264 | |
| 265 | EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs); |
| 266 | std::vector<std::string> tones; |
| 267 | tones.push_back("1"); |
| 268 | tones.push_back("a"); |
| 269 | tones.push_back(""); |
| 270 | observer->Verify(tones); |
| 271 | |
| 272 | dtmf_sender->UnregisterObserver(); |
| 273 | } |
| 274 | |
| 275 | // Verifies that the SessionDescription have rejected the appropriate media |
| 276 | // content. |
| 277 | void VerifyRejectedMediaInSessionDescription() { |
| 278 | ASSERT_TRUE(peer_connection_->remote_description() != NULL); |
| 279 | ASSERT_TRUE(peer_connection_->local_description() != NULL); |
| 280 | const cricket::SessionDescription* remote_desc = |
| 281 | peer_connection_->remote_description()->description(); |
| 282 | const cricket::SessionDescription* local_desc = |
| 283 | peer_connection_->local_description()->description(); |
| 284 | |
| 285 | const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc); |
| 286 | if (remote_audio_content) { |
| 287 | const ContentInfo* audio_content = |
| 288 | GetFirstAudioContent(local_desc); |
| 289 | EXPECT_EQ(can_receive_audio(), !audio_content->rejected); |
| 290 | } |
| 291 | |
| 292 | const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc); |
| 293 | if (remote_video_content) { |
| 294 | const ContentInfo* video_content = |
| 295 | GetFirstVideoContent(local_desc); |
| 296 | EXPECT_EQ(can_receive_video(), !video_content->rejected); |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | void SetExpectIceRestart(bool expect_restart) { |
| 301 | expect_ice_restart_ = expect_restart; |
| 302 | } |
| 303 | |
| 304 | bool ExpectIceRestart() const { return expect_ice_restart_; } |
| 305 | |
| 306 | void VerifyLocalIceUfragAndPassword() { |
| 307 | ASSERT_TRUE(peer_connection_->local_description() != NULL); |
| 308 | const cricket::SessionDescription* desc = |
| 309 | peer_connection_->local_description()->description(); |
| 310 | const cricket::ContentInfos& contents = desc->contents(); |
| 311 | |
| 312 | for (size_t index = 0; index < contents.size(); ++index) { |
| 313 | if (contents[index].rejected) |
| 314 | continue; |
| 315 | const cricket::TransportDescription* transport_desc = |
| 316 | desc->GetTransportDescriptionByName(contents[index].name); |
| 317 | |
| 318 | std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 319 | ice_ufrag_pwd_.find(static_cast<int>(index)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 320 | if (ufragpair_it == ice_ufrag_pwd_.end()) { |
| 321 | ASSERT_FALSE(ExpectIceRestart()); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 322 | ice_ufrag_pwd_[static_cast<int>(index)] = |
| 323 | IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 324 | } else if (ExpectIceRestart()) { |
| 325 | const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second; |
| 326 | EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag); |
| 327 | EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd); |
| 328 | } else { |
| 329 | const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second; |
| 330 | EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag); |
| 331 | EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd); |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 337 | rtc::scoped_refptr<MockStatsObserver> |
| 338 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 339 | EXPECT_TRUE(peer_connection_->GetStats( |
| 340 | observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 341 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
| 342 | return observer->AudioOutputLevel(); |
| 343 | } |
| 344 | |
| 345 | int GetAudioInputLevelStats() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 346 | rtc::scoped_refptr<MockStatsObserver> |
| 347 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 348 | EXPECT_TRUE(peer_connection_->GetStats( |
| 349 | observer, NULL, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 350 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
| 351 | return observer->AudioInputLevel(); |
| 352 | } |
| 353 | |
| 354 | int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 355 | rtc::scoped_refptr<MockStatsObserver> |
| 356 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 357 | EXPECT_TRUE(peer_connection_->GetStats( |
| 358 | observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 359 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
| 360 | return observer->BytesReceived(); |
| 361 | } |
| 362 | |
| 363 | int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 364 | rtc::scoped_refptr<MockStatsObserver> |
| 365 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
jiayl@webrtc.org | db41b4d | 2014-03-03 21:30:06 +0000 | [diff] [blame] | 366 | EXPECT_TRUE(peer_connection_->GetStats( |
| 367 | observer, track, PeerConnectionInterface::kStatsOutputLevelStandard)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 368 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
| 369 | return observer->BytesSent(); |
| 370 | } |
| 371 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 372 | int GetAvailableReceivedBandwidthStats() { |
| 373 | rtc::scoped_refptr<MockStatsObserver> |
| 374 | observer(new rtc::RefCountedObject<MockStatsObserver>()); |
| 375 | EXPECT_TRUE(peer_connection_->GetStats( |
| 376 | observer, NULL, PeerConnectionInterface::kStatsOutputLevelStandard)); |
| 377 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
| 378 | int bw = observer->AvailableReceiveBandwidth(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 379 | return bw; |
| 380 | } |
| 381 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 382 | int rendered_width() { |
| 383 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 384 | return fake_video_renderers_.empty() ? 1 : |
| 385 | fake_video_renderers_.begin()->second->width(); |
| 386 | } |
| 387 | |
| 388 | int rendered_height() { |
| 389 | EXPECT_FALSE(fake_video_renderers_.empty()); |
| 390 | return fake_video_renderers_.empty() ? 1 : |
| 391 | fake_video_renderers_.begin()->second->height(); |
| 392 | } |
| 393 | |
| 394 | size_t number_of_remote_streams() { |
| 395 | if (!pc()) |
| 396 | return 0; |
| 397 | return pc()->remote_streams()->count(); |
| 398 | } |
| 399 | |
| 400 | StreamCollectionInterface* remote_streams() { |
| 401 | if (!pc()) { |
| 402 | ADD_FAILURE(); |
| 403 | return NULL; |
| 404 | } |
| 405 | return pc()->remote_streams(); |
| 406 | } |
| 407 | |
| 408 | StreamCollectionInterface* local_streams() { |
| 409 | if (!pc()) { |
| 410 | ADD_FAILURE(); |
| 411 | return NULL; |
| 412 | } |
| 413 | return pc()->local_streams(); |
| 414 | } |
| 415 | |
| 416 | webrtc::PeerConnectionInterface::SignalingState signaling_state() { |
| 417 | return pc()->signaling_state(); |
| 418 | } |
| 419 | |
| 420 | webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() { |
| 421 | return pc()->ice_connection_state(); |
| 422 | } |
| 423 | |
| 424 | webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() { |
| 425 | return pc()->ice_gathering_state(); |
| 426 | } |
| 427 | |
| 428 | // PeerConnectionObserver callbacks. |
| 429 | virtual void OnError() {} |
| 430 | virtual void OnMessage(const std::string&) {} |
| 431 | virtual void OnSignalingMessage(const std::string& /*msg*/) {} |
| 432 | virtual void OnSignalingChange( |
| 433 | webrtc::PeerConnectionInterface::SignalingState new_state) { |
| 434 | EXPECT_EQ(peer_connection_->signaling_state(), new_state); |
| 435 | } |
| 436 | virtual void OnAddStream(webrtc::MediaStreamInterface* media_stream) { |
| 437 | for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) { |
| 438 | const std::string id = media_stream->GetVideoTracks()[i]->id(); |
| 439 | ASSERT_TRUE(fake_video_renderers_.find(id) == |
| 440 | fake_video_renderers_.end()); |
| 441 | fake_video_renderers_[id] = new webrtc::FakeVideoTrackRenderer( |
| 442 | media_stream->GetVideoTracks()[i]); |
| 443 | } |
| 444 | } |
| 445 | virtual void OnRemoveStream(webrtc::MediaStreamInterface* media_stream) {} |
| 446 | virtual void OnRenegotiationNeeded() {} |
| 447 | virtual void OnIceConnectionChange( |
| 448 | webrtc::PeerConnectionInterface::IceConnectionState new_state) { |
| 449 | EXPECT_EQ(peer_connection_->ice_connection_state(), new_state); |
| 450 | } |
| 451 | virtual void OnIceGatheringChange( |
| 452 | webrtc::PeerConnectionInterface::IceGatheringState new_state) { |
| 453 | EXPECT_EQ(peer_connection_->ice_gathering_state(), new_state); |
| 454 | } |
| 455 | virtual void OnIceCandidate( |
| 456 | const webrtc::IceCandidateInterface* /*candidate*/) {} |
| 457 | |
| 458 | webrtc::PeerConnectionInterface* pc() { |
| 459 | return peer_connection_.get(); |
| 460 | } |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 461 | void StopVideoCapturers() { |
| 462 | for (std::vector<cricket::VideoCapturer*>::iterator it = |
| 463 | video_capturers_.begin(); it != video_capturers_.end(); ++it) { |
| 464 | (*it)->Stop(); |
| 465 | } |
| 466 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 467 | |
| 468 | protected: |
| 469 | explicit PeerConnectionTestClientBase(const std::string& id) |
| 470 | : id_(id), |
| 471 | expect_ice_restart_(false), |
| 472 | fake_video_decoder_factory_(NULL), |
| 473 | fake_video_encoder_factory_(NULL), |
| 474 | video_decoder_factory_enabled_(false), |
| 475 | signaling_message_receiver_(NULL) { |
| 476 | } |
| 477 | bool Init(const MediaConstraintsInterface* constraints) { |
| 478 | EXPECT_TRUE(!peer_connection_); |
| 479 | EXPECT_TRUE(!peer_connection_factory_); |
| 480 | allocator_factory_ = webrtc::FakePortAllocatorFactory::Create(); |
| 481 | if (!allocator_factory_) { |
| 482 | return false; |
| 483 | } |
| 484 | audio_thread_.Start(); |
| 485 | fake_audio_capture_module_ = FakeAudioCaptureModule::Create( |
| 486 | &audio_thread_); |
| 487 | |
| 488 | if (fake_audio_capture_module_ == NULL) { |
| 489 | return false; |
| 490 | } |
| 491 | fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory(); |
| 492 | fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory(); |
| 493 | peer_connection_factory_ = webrtc::CreatePeerConnectionFactory( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 494 | rtc::Thread::Current(), rtc::Thread::Current(), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 495 | fake_audio_capture_module_, fake_video_encoder_factory_, |
| 496 | fake_video_decoder_factory_); |
| 497 | if (!peer_connection_factory_) { |
| 498 | return false; |
| 499 | } |
| 500 | peer_connection_ = CreatePeerConnection(allocator_factory_.get(), |
| 501 | constraints); |
| 502 | return peer_connection_.get() != NULL; |
| 503 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 504 | virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 505 | CreatePeerConnection(webrtc::PortAllocatorFactoryInterface* factory, |
| 506 | const MediaConstraintsInterface* constraints) = 0; |
| 507 | MessageReceiver* signaling_message_receiver() { |
| 508 | return signaling_message_receiver_; |
| 509 | } |
| 510 | webrtc::PeerConnectionFactoryInterface* peer_connection_factory() { |
| 511 | return peer_connection_factory_.get(); |
| 512 | } |
| 513 | |
| 514 | virtual bool can_receive_audio() = 0; |
| 515 | virtual bool can_receive_video() = 0; |
| 516 | const std::string& id() const { return id_; } |
| 517 | |
| 518 | private: |
| 519 | class DummyDtmfObserver : public DtmfSenderObserverInterface { |
| 520 | public: |
| 521 | DummyDtmfObserver() : completed_(false) {} |
| 522 | |
| 523 | // Implements DtmfSenderObserverInterface. |
| 524 | void OnToneChange(const std::string& tone) { |
| 525 | tones_.push_back(tone); |
| 526 | if (tone.empty()) { |
| 527 | completed_ = true; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | void Verify(const std::vector<std::string>& tones) const { |
| 532 | ASSERT_TRUE(tones_.size() == tones.size()); |
| 533 | EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin())); |
| 534 | } |
| 535 | |
| 536 | bool completed() const { return completed_; } |
| 537 | |
| 538 | private: |
| 539 | bool completed_; |
| 540 | std::vector<std::string> tones_; |
| 541 | }; |
| 542 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 543 | rtc::scoped_refptr<webrtc::VideoTrackInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 544 | CreateLocalVideoTrack(const std::string stream_label) { |
| 545 | // Set max frame rate to 10fps to reduce the risk of the tests to be flaky. |
| 546 | FakeConstraints source_constraints = video_constraints_; |
| 547 | source_constraints.SetMandatoryMaxFrameRate(10); |
| 548 | |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 549 | cricket::FakeVideoCapturer* fake_capturer = |
| 550 | new webrtc::FakePeriodicVideoCapturer(); |
| 551 | video_capturers_.push_back(fake_capturer); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 552 | rtc::scoped_refptr<webrtc::VideoSourceInterface> source = |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 553 | peer_connection_factory_->CreateVideoSource( |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 554 | fake_capturer, &source_constraints); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 555 | std::string label = stream_label + kVideoTrackLabelBase; |
| 556 | return peer_connection_factory_->CreateVideoTrack(label, source); |
| 557 | } |
| 558 | |
| 559 | std::string id_; |
| 560 | // Separate thread for executing |fake_audio_capture_module_| tasks. Audio |
| 561 | // processing must not be performed on the same thread as signaling due to |
| 562 | // signaling time constraints and relative complexity of the audio pipeline. |
| 563 | // This is consistent with the video pipeline that us a a separate thread for |
| 564 | // encoding and decoding. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 565 | rtc::Thread audio_thread_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 566 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 567 | rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 568 | allocator_factory_; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 569 | rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_; |
| 570 | rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 571 | peer_connection_factory_; |
| 572 | |
| 573 | typedef std::pair<std::string, std::string> IceUfragPwdPair; |
| 574 | std::map<int, IceUfragPwdPair> ice_ufrag_pwd_; |
| 575 | bool expect_ice_restart_; |
| 576 | |
| 577 | // Needed to keep track of number of frames send. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 578 | rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 579 | // Needed to keep track of number of frames received. |
| 580 | typedef std::map<std::string, webrtc::FakeVideoTrackRenderer*> RenderMap; |
| 581 | RenderMap fake_video_renderers_; |
| 582 | // Needed to keep track of number of frames received when external decoder |
| 583 | // used. |
| 584 | FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_; |
| 585 | FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_; |
| 586 | bool video_decoder_factory_enabled_; |
| 587 | webrtc::FakeConstraints video_constraints_; |
| 588 | |
| 589 | // For remote peer communication. |
| 590 | MessageReceiver* signaling_message_receiver_; |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 591 | |
| 592 | // Store references to the video capturers we've created, so that we can stop |
| 593 | // them, if required. |
| 594 | std::vector<cricket::VideoCapturer*> video_capturers_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 595 | }; |
| 596 | |
| 597 | class JsepTestClient |
| 598 | : public PeerConnectionTestClientBase<JsepMessageReceiver> { |
| 599 | public: |
| 600 | static JsepTestClient* CreateClient( |
| 601 | const std::string& id, |
| 602 | const MediaConstraintsInterface* constraints) { |
| 603 | JsepTestClient* client(new JsepTestClient(id)); |
| 604 | if (!client->Init(constraints)) { |
| 605 | delete client; |
| 606 | return NULL; |
| 607 | } |
| 608 | return client; |
| 609 | } |
| 610 | ~JsepTestClient() {} |
| 611 | |
| 612 | virtual void Negotiate() { |
| 613 | Negotiate(true, true); |
| 614 | } |
| 615 | virtual void Negotiate(bool audio, bool video) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 616 | rtc::scoped_ptr<SessionDescriptionInterface> offer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 617 | EXPECT_TRUE(DoCreateOffer(offer.use())); |
| 618 | |
| 619 | if (offer->description()->GetContentByName("audio")) { |
| 620 | offer->description()->GetContentByName("audio")->rejected = !audio; |
| 621 | } |
| 622 | if (offer->description()->GetContentByName("video")) { |
| 623 | offer->description()->GetContentByName("video")->rejected = !video; |
| 624 | } |
| 625 | |
| 626 | std::string sdp; |
| 627 | EXPECT_TRUE(offer->ToString(&sdp)); |
| 628 | EXPECT_TRUE(DoSetLocalDescription(offer.release())); |
| 629 | signaling_message_receiver()->ReceiveSdpMessage( |
| 630 | webrtc::SessionDescriptionInterface::kOffer, sdp); |
| 631 | } |
| 632 | // JsepMessageReceiver callback. |
| 633 | virtual void ReceiveSdpMessage(const std::string& type, |
| 634 | std::string& msg) { |
| 635 | FilterIncomingSdpMessage(&msg); |
| 636 | if (type == webrtc::SessionDescriptionInterface::kOffer) { |
| 637 | HandleIncomingOffer(msg); |
| 638 | } else { |
| 639 | HandleIncomingAnswer(msg); |
| 640 | } |
| 641 | } |
| 642 | // JsepMessageReceiver callback. |
| 643 | virtual void ReceiveIceMessage(const std::string& sdp_mid, |
| 644 | int sdp_mline_index, |
| 645 | const std::string& msg) { |
| 646 | LOG(INFO) << id() << "ReceiveIceMessage"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 647 | rtc::scoped_ptr<webrtc::IceCandidateInterface> candidate( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 648 | webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, NULL)); |
| 649 | EXPECT_TRUE(pc()->AddIceCandidate(candidate.get())); |
| 650 | } |
| 651 | // Implements PeerConnectionObserver functions needed by Jsep. |
| 652 | virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) { |
| 653 | LOG(INFO) << id() << "OnIceCandidate"; |
| 654 | |
| 655 | std::string ice_sdp; |
| 656 | EXPECT_TRUE(candidate->ToString(&ice_sdp)); |
| 657 | if (signaling_message_receiver() == NULL) { |
| 658 | // Remote party may be deleted. |
| 659 | return; |
| 660 | } |
| 661 | signaling_message_receiver()->ReceiveIceMessage(candidate->sdp_mid(), |
| 662 | candidate->sdp_mline_index(), ice_sdp); |
| 663 | } |
| 664 | |
| 665 | void IceRestart() { |
| 666 | session_description_constraints_.SetMandatoryIceRestart(true); |
| 667 | SetExpectIceRestart(true); |
| 668 | } |
| 669 | |
| 670 | void SetReceiveAudioVideo(bool audio, bool video) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 671 | SetReceiveAudio(audio); |
| 672 | SetReceiveVideo(video); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 673 | ASSERT_EQ(audio, can_receive_audio()); |
| 674 | ASSERT_EQ(video, can_receive_video()); |
| 675 | } |
| 676 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 677 | void SetReceiveAudio(bool audio) { |
| 678 | if (audio && can_receive_audio()) |
| 679 | return; |
| 680 | session_description_constraints_.SetMandatoryReceiveAudio(audio); |
| 681 | } |
| 682 | |
| 683 | void SetReceiveVideo(bool video) { |
| 684 | if (video && can_receive_video()) |
| 685 | return; |
| 686 | session_description_constraints_.SetMandatoryReceiveVideo(video); |
| 687 | } |
| 688 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 689 | void RemoveMsidFromReceivedSdp(bool remove) { |
| 690 | remove_msid_ = remove; |
| 691 | } |
| 692 | |
| 693 | void RemoveSdesCryptoFromReceivedSdp(bool remove) { |
| 694 | remove_sdes_ = remove; |
| 695 | } |
| 696 | |
| 697 | void RemoveBundleFromReceivedSdp(bool remove) { |
| 698 | remove_bundle_ = remove; |
| 699 | } |
| 700 | |
| 701 | virtual bool can_receive_audio() { |
| 702 | bool value; |
| 703 | if (webrtc::FindConstraint(&session_description_constraints_, |
| 704 | MediaConstraintsInterface::kOfferToReceiveAudio, &value, NULL)) { |
| 705 | return value; |
| 706 | } |
| 707 | return true; |
| 708 | } |
| 709 | |
| 710 | virtual bool can_receive_video() { |
| 711 | bool value; |
| 712 | if (webrtc::FindConstraint(&session_description_constraints_, |
| 713 | MediaConstraintsInterface::kOfferToReceiveVideo, &value, NULL)) { |
| 714 | return value; |
| 715 | } |
| 716 | return true; |
| 717 | } |
| 718 | |
| 719 | virtual void OnIceComplete() { |
| 720 | LOG(INFO) << id() << "OnIceComplete"; |
| 721 | } |
| 722 | |
| 723 | virtual void OnDataChannel(DataChannelInterface* data_channel) { |
| 724 | LOG(INFO) << id() << "OnDataChannel"; |
| 725 | data_channel_ = data_channel; |
| 726 | data_observer_.reset(new MockDataChannelObserver(data_channel)); |
| 727 | } |
| 728 | |
| 729 | void CreateDataChannel() { |
| 730 | data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, |
| 731 | NULL); |
| 732 | ASSERT_TRUE(data_channel_.get() != NULL); |
| 733 | data_observer_.reset(new MockDataChannelObserver(data_channel_)); |
| 734 | } |
| 735 | |
| 736 | DataChannelInterface* data_channel() { return data_channel_; } |
| 737 | const MockDataChannelObserver* data_observer() const { |
| 738 | return data_observer_.get(); |
| 739 | } |
| 740 | |
| 741 | protected: |
| 742 | explicit JsepTestClient(const std::string& id) |
| 743 | : PeerConnectionTestClientBase<JsepMessageReceiver>(id), |
| 744 | remove_msid_(false), |
| 745 | remove_bundle_(false), |
| 746 | remove_sdes_(false) { |
| 747 | } |
| 748 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 749 | virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 750 | CreatePeerConnection(webrtc::PortAllocatorFactoryInterface* factory, |
| 751 | const MediaConstraintsInterface* constraints) { |
| 752 | // CreatePeerConnection with IceServers. |
| 753 | webrtc::PeerConnectionInterface::IceServers ice_servers; |
| 754 | webrtc::PeerConnectionInterface::IceServer ice_server; |
| 755 | ice_server.uri = "stun:stun.l.google.com:19302"; |
| 756 | ice_servers.push_back(ice_server); |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 757 | |
buildbot@webrtc.org | 61c1b8e | 2014-04-09 06:06:38 +0000 | [diff] [blame] | 758 | FakeIdentityService* dtls_service = |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 759 | rtc::SSLStreamAdapter::HaveDtlsSrtp() ? |
buildbot@webrtc.org | 61c1b8e | 2014-04-09 06:06:38 +0000 | [diff] [blame] | 760 | new FakeIdentityService() : NULL; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 761 | return peer_connection_factory()->CreatePeerConnection( |
jiayl@webrtc.org | a576faf | 2014-01-29 17:45:53 +0000 | [diff] [blame] | 762 | ice_servers, constraints, factory, dtls_service, this); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | void HandleIncomingOffer(const std::string& msg) { |
| 766 | LOG(INFO) << id() << "HandleIncomingOffer "; |
| 767 | if (NumberOfLocalMediaStreams() == 0) { |
| 768 | // If we are not sending any streams ourselves it is time to add some. |
| 769 | AddMediaStream(true, true); |
| 770 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 771 | rtc::scoped_ptr<SessionDescriptionInterface> desc( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 772 | webrtc::CreateSessionDescription("offer", msg, NULL)); |
| 773 | EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 774 | rtc::scoped_ptr<SessionDescriptionInterface> answer; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 775 | EXPECT_TRUE(DoCreateAnswer(answer.use())); |
| 776 | std::string sdp; |
| 777 | EXPECT_TRUE(answer->ToString(&sdp)); |
| 778 | EXPECT_TRUE(DoSetLocalDescription(answer.release())); |
| 779 | if (signaling_message_receiver()) { |
| 780 | signaling_message_receiver()->ReceiveSdpMessage( |
| 781 | webrtc::SessionDescriptionInterface::kAnswer, sdp); |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | void HandleIncomingAnswer(const std::string& msg) { |
| 786 | LOG(INFO) << id() << "HandleIncomingAnswer"; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 787 | rtc::scoped_ptr<SessionDescriptionInterface> desc( |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 788 | webrtc::CreateSessionDescription("answer", msg, NULL)); |
| 789 | EXPECT_TRUE(DoSetRemoteDescription(desc.release())); |
| 790 | } |
| 791 | |
| 792 | bool DoCreateOfferAnswer(SessionDescriptionInterface** desc, |
| 793 | bool offer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 794 | rtc::scoped_refptr<MockCreateSessionDescriptionObserver> |
| 795 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 796 | MockCreateSessionDescriptionObserver>()); |
| 797 | if (offer) { |
| 798 | pc()->CreateOffer(observer, &session_description_constraints_); |
| 799 | } else { |
| 800 | pc()->CreateAnswer(observer, &session_description_constraints_); |
| 801 | } |
| 802 | EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs); |
| 803 | *desc = observer->release_desc(); |
| 804 | if (observer->result() && ExpectIceRestart()) { |
| 805 | EXPECT_EQ(0u, (*desc)->candidates(0)->count()); |
| 806 | } |
| 807 | return observer->result(); |
| 808 | } |
| 809 | |
| 810 | bool DoCreateOffer(SessionDescriptionInterface** desc) { |
| 811 | return DoCreateOfferAnswer(desc, true); |
| 812 | } |
| 813 | |
| 814 | bool DoCreateAnswer(SessionDescriptionInterface** desc) { |
| 815 | return DoCreateOfferAnswer(desc, false); |
| 816 | } |
| 817 | |
| 818 | bool DoSetLocalDescription(SessionDescriptionInterface* desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 819 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
| 820 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 821 | MockSetSessionDescriptionObserver>()); |
| 822 | LOG(INFO) << id() << "SetLocalDescription "; |
| 823 | pc()->SetLocalDescription(observer, desc); |
| 824 | // Ignore the observer result. If we wait for the result with |
| 825 | // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer |
| 826 | // before the offer which is an error. |
| 827 | // The reason is that EXPECT_TRUE_WAIT uses |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 828 | // rtc::Thread::Current()->ProcessMessages(1); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 829 | // ProcessMessages waits at least 1ms but processes all messages before |
| 830 | // returning. Since this test is synchronous and send messages to the remote |
| 831 | // peer whenever a callback is invoked, this can lead to messages being |
| 832 | // sent to the remote peer in the wrong order. |
| 833 | // TODO(perkj): Find a way to check the result without risking that the |
| 834 | // order of sent messages are changed. Ex- by posting all messages that are |
| 835 | // sent to the remote peer. |
| 836 | return true; |
| 837 | } |
| 838 | |
| 839 | bool DoSetRemoteDescription(SessionDescriptionInterface* desc) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 840 | rtc::scoped_refptr<MockSetSessionDescriptionObserver> |
| 841 | observer(new rtc::RefCountedObject< |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 842 | MockSetSessionDescriptionObserver>()); |
| 843 | LOG(INFO) << id() << "SetRemoteDescription "; |
| 844 | pc()->SetRemoteDescription(observer, desc); |
| 845 | EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs); |
| 846 | return observer->result(); |
| 847 | } |
| 848 | |
| 849 | // This modifies all received SDP messages before they are processed. |
| 850 | void FilterIncomingSdpMessage(std::string* sdp) { |
| 851 | if (remove_msid_) { |
| 852 | const char kSdpSsrcAttribute[] = "a=ssrc:"; |
| 853 | RemoveLinesFromSdp(kSdpSsrcAttribute, sdp); |
| 854 | const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:"; |
| 855 | RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp); |
| 856 | } |
| 857 | if (remove_bundle_) { |
| 858 | const char kSdpBundleAttribute[] = "a=group:BUNDLE"; |
| 859 | RemoveLinesFromSdp(kSdpBundleAttribute, sdp); |
| 860 | } |
| 861 | if (remove_sdes_) { |
| 862 | const char kSdpSdesCryptoAttribute[] = "a=crypto"; |
| 863 | RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp); |
| 864 | } |
| 865 | } |
| 866 | |
| 867 | private: |
| 868 | webrtc::FakeConstraints session_description_constraints_; |
| 869 | bool remove_msid_; // True if MSID should be removed in received SDP. |
| 870 | bool remove_bundle_; // True if bundle should be removed in received SDP. |
| 871 | bool remove_sdes_; // True if a=crypto should be removed in received SDP. |
| 872 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 873 | rtc::scoped_refptr<DataChannelInterface> data_channel_; |
| 874 | rtc::scoped_ptr<MockDataChannelObserver> data_observer_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 875 | }; |
| 876 | |
| 877 | template <typename SignalingClass> |
| 878 | class P2PTestConductor : public testing::Test { |
| 879 | public: |
| 880 | bool SessionActive() { |
| 881 | return initiating_client_->SessionActive() && |
| 882 | receiving_client_->SessionActive(); |
| 883 | } |
| 884 | // Return true if the number of frames provided have been received or it is |
| 885 | // known that that will never occur (e.g. no frames will be sent or |
| 886 | // captured). |
| 887 | bool FramesNotPending(int audio_frames_to_receive, |
| 888 | int video_frames_to_receive) { |
| 889 | return VideoFramesReceivedCheck(video_frames_to_receive) && |
| 890 | AudioFramesReceivedCheck(audio_frames_to_receive); |
| 891 | } |
| 892 | bool AudioFramesReceivedCheck(int frames_received) { |
| 893 | return initiating_client_->AudioFramesReceivedCheck(frames_received) && |
| 894 | receiving_client_->AudioFramesReceivedCheck(frames_received); |
| 895 | } |
| 896 | bool VideoFramesReceivedCheck(int frames_received) { |
| 897 | return initiating_client_->VideoFramesReceivedCheck(frames_received) && |
| 898 | receiving_client_->VideoFramesReceivedCheck(frames_received); |
| 899 | } |
| 900 | void VerifyDtmf() { |
| 901 | initiating_client_->VerifyDtmf(); |
| 902 | receiving_client_->VerifyDtmf(); |
| 903 | } |
| 904 | |
| 905 | void TestUpdateOfferWithRejectedContent() { |
| 906 | initiating_client_->Negotiate(true, false); |
| 907 | EXPECT_TRUE_WAIT( |
| 908 | FramesNotPending(kEndAudioFrameCount * 2, kEndVideoFrameCount), |
| 909 | kMaxWaitForFramesMs); |
| 910 | // There shouldn't be any more video frame after the new offer is |
| 911 | // negotiated. |
| 912 | EXPECT_FALSE(VideoFramesReceivedCheck(kEndVideoFrameCount + 1)); |
| 913 | } |
| 914 | |
| 915 | void VerifyRenderedSize(int width, int height) { |
| 916 | EXPECT_EQ(width, receiving_client()->rendered_width()); |
| 917 | EXPECT_EQ(height, receiving_client()->rendered_height()); |
| 918 | EXPECT_EQ(width, initializing_client()->rendered_width()); |
| 919 | EXPECT_EQ(height, initializing_client()->rendered_height()); |
| 920 | } |
| 921 | |
| 922 | void VerifySessionDescriptions() { |
| 923 | initiating_client_->VerifyRejectedMediaInSessionDescription(); |
| 924 | receiving_client_->VerifyRejectedMediaInSessionDescription(); |
| 925 | initiating_client_->VerifyLocalIceUfragAndPassword(); |
| 926 | receiving_client_->VerifyLocalIceUfragAndPassword(); |
| 927 | } |
| 928 | |
| 929 | P2PTestConductor() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 930 | rtc::InitializeSSL(NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 931 | } |
| 932 | ~P2PTestConductor() { |
| 933 | if (initiating_client_) { |
| 934 | initiating_client_->set_signaling_message_receiver(NULL); |
| 935 | } |
| 936 | if (receiving_client_) { |
| 937 | receiving_client_->set_signaling_message_receiver(NULL); |
| 938 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 939 | rtc::CleanupSSL(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | bool CreateTestClients() { |
| 943 | return CreateTestClients(NULL, NULL); |
| 944 | } |
| 945 | |
| 946 | bool CreateTestClients(MediaConstraintsInterface* init_constraints, |
| 947 | MediaConstraintsInterface* recv_constraints) { |
| 948 | initiating_client_.reset(SignalingClass::CreateClient("Caller: ", |
| 949 | init_constraints)); |
| 950 | receiving_client_.reset(SignalingClass::CreateClient("Callee: ", |
| 951 | recv_constraints)); |
| 952 | if (!initiating_client_ || !receiving_client_) { |
| 953 | return false; |
| 954 | } |
| 955 | initiating_client_->set_signaling_message_receiver(receiving_client_.get()); |
| 956 | receiving_client_->set_signaling_message_receiver(initiating_client_.get()); |
| 957 | return true; |
| 958 | } |
| 959 | |
| 960 | void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints, |
| 961 | const webrtc::FakeConstraints& recv_constraints) { |
| 962 | initiating_client_->SetVideoConstraints(init_constraints); |
| 963 | receiving_client_->SetVideoConstraints(recv_constraints); |
| 964 | } |
| 965 | |
| 966 | void EnableVideoDecoderFactory() { |
| 967 | initiating_client_->EnableVideoDecoderFactory(); |
| 968 | receiving_client_->EnableVideoDecoderFactory(); |
| 969 | } |
| 970 | |
| 971 | // This test sets up a call between two parties. Both parties send static |
| 972 | // frames to each other. Once the test is finished the number of sent frames |
| 973 | // is compared to the number of received frames. |
| 974 | void LocalP2PTest() { |
| 975 | if (initiating_client_->NumberOfLocalMediaStreams() == 0) { |
| 976 | initiating_client_->AddMediaStream(true, true); |
| 977 | } |
| 978 | initiating_client_->Negotiate(); |
| 979 | const int kMaxWaitForActivationMs = 5000; |
| 980 | // Assert true is used here since next tests are guaranteed to fail and |
| 981 | // would eat up 5 seconds. |
| 982 | ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs); |
| 983 | VerifySessionDescriptions(); |
| 984 | |
| 985 | |
| 986 | int audio_frame_count = kEndAudioFrameCount; |
| 987 | // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly. |
| 988 | if (!initiating_client_->can_receive_audio() || |
| 989 | !receiving_client_->can_receive_audio()) { |
| 990 | audio_frame_count = -1; |
| 991 | } |
| 992 | int video_frame_count = kEndVideoFrameCount; |
| 993 | if (!initiating_client_->can_receive_video() || |
| 994 | !receiving_client_->can_receive_video()) { |
| 995 | video_frame_count = -1; |
| 996 | } |
| 997 | |
| 998 | if (audio_frame_count != -1 || video_frame_count != -1) { |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 999 | // Audio or video is expected to flow, so both clients should reach the |
| 1000 | // Connected state, and the offerer (ICE controller) should proceed to |
| 1001 | // Completed. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1002 | // Note: These tests have been observed to fail under heavy load at |
| 1003 | // shorter timeouts, so they may be flaky. |
| 1004 | EXPECT_EQ_WAIT( |
mallinath@webrtc.org | 385857d | 2014-02-14 00:56:12 +0000 | [diff] [blame] | 1005 | webrtc::PeerConnectionInterface::kIceConnectionCompleted, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1006 | initiating_client_->ice_connection_state(), |
| 1007 | kMaxWaitForFramesMs); |
| 1008 | EXPECT_EQ_WAIT( |
| 1009 | webrtc::PeerConnectionInterface::kIceConnectionConnected, |
| 1010 | receiving_client_->ice_connection_state(), |
| 1011 | kMaxWaitForFramesMs); |
| 1012 | } |
| 1013 | |
| 1014 | if (initiating_client_->can_receive_audio() || |
| 1015 | initiating_client_->can_receive_video()) { |
| 1016 | // The initiating client can receive media, so it must produce candidates |
| 1017 | // that will serve as destinations for that media. |
| 1018 | // TODO(bemasc): Understand why the state is not already Complete here, as |
| 1019 | // seems to be the case for the receiving client. This may indicate a bug |
| 1020 | // in the ICE gathering system. |
| 1021 | EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew, |
| 1022 | initiating_client_->ice_gathering_state()); |
| 1023 | } |
| 1024 | if (receiving_client_->can_receive_audio() || |
| 1025 | receiving_client_->can_receive_video()) { |
| 1026 | EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete, |
| 1027 | receiving_client_->ice_gathering_state(), |
| 1028 | kMaxWaitForFramesMs); |
| 1029 | } |
| 1030 | |
| 1031 | EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count), |
| 1032 | kMaxWaitForFramesMs); |
| 1033 | } |
| 1034 | |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1035 | void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) { |
| 1036 | // Messages may get lost on the unreliable DataChannel, so we send multiple |
| 1037 | // times to avoid test flakiness. |
| 1038 | static const size_t kSendAttempts = 5; |
| 1039 | |
| 1040 | for (size_t i = 0; i < kSendAttempts; ++i) { |
| 1041 | dc->Send(DataBuffer(data)); |
| 1042 | } |
| 1043 | } |
| 1044 | |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1045 | // Wait until 'size' bytes of audio has been seen by the receiver, on the |
| 1046 | // first audio stream. |
| 1047 | void WaitForAudioData(int size) { |
solenberg@webrtc.org | 00f11f5 | 2014-08-27 08:52:17 +0000 | [diff] [blame^] | 1048 | const int kMaxWaitForAudioDataMs = 10000; |
kjellander@webrtc.org | e9bfed0 | 2014-08-25 19:46:26 +0000 | [diff] [blame] | 1049 | |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1050 | StreamCollectionInterface* local_streams = |
| 1051 | initializing_client()->local_streams(); |
| 1052 | ASSERT_GT(local_streams->count(), 0u); |
| 1053 | ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1054 | MediaStreamTrackInterface* local_audio_track = |
| 1055 | local_streams->at(0)->GetAudioTracks()[0]; |
| 1056 | |
| 1057 | // Wait until *any* audio has been received. |
| 1058 | EXPECT_TRUE_WAIT( |
| 1059 | receiving_client()->GetBytesReceivedStats(local_audio_track) > 0, |
| 1060 | kMaxWaitForAudioDataMs); |
| 1061 | |
| 1062 | // Wait until 'size' number of bytes have been received. |
| 1063 | size += receiving_client()->GetBytesReceivedStats(local_audio_track); |
| 1064 | EXPECT_TRUE_WAIT( |
| 1065 | receiving_client()->GetBytesReceivedStats(local_audio_track) > size, |
| 1066 | kMaxWaitForAudioDataMs); |
| 1067 | } |
| 1068 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1069 | SignalingClass* initializing_client() { return initiating_client_.get(); } |
| 1070 | SignalingClass* receiving_client() { return receiving_client_.get(); } |
| 1071 | |
| 1072 | private: |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1073 | rtc::scoped_ptr<SignalingClass> initiating_client_; |
| 1074 | rtc::scoped_ptr<SignalingClass> receiving_client_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1075 | }; |
| 1076 | typedef P2PTestConductor<JsepTestClient> JsepPeerConnectionP2PTestClient; |
| 1077 | |
kjellander@webrtc.org | d1cfa71 | 2013-10-16 16:51:52 +0000 | [diff] [blame] | 1078 | // Disable for TSan v2, see |
| 1079 | // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
| 1080 | #if !defined(THREAD_SANITIZER) |
| 1081 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1082 | // This test sets up a Jsep call between two parties and test Dtmf. |
stefan@webrtc.org | da79008 | 2013-09-17 13:11:38 +0000 | [diff] [blame] | 1083 | // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
| 1084 | // See issue webrtc/2378. |
| 1085 | TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestDtmf) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1086 | ASSERT_TRUE(CreateTestClients()); |
| 1087 | LocalP2PTest(); |
| 1088 | VerifyDtmf(); |
| 1089 | } |
| 1090 | |
| 1091 | // This test sets up a Jsep call between two parties and test that we can get a |
| 1092 | // video aspect ratio of 16:9. |
| 1093 | TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTest16To9) { |
| 1094 | ASSERT_TRUE(CreateTestClients()); |
| 1095 | FakeConstraints constraint; |
| 1096 | double requested_ratio = 640.0/360; |
| 1097 | constraint.SetMandatoryMinAspectRatio(requested_ratio); |
| 1098 | SetVideoConstraints(constraint, constraint); |
| 1099 | LocalP2PTest(); |
| 1100 | |
| 1101 | ASSERT_LE(0, initializing_client()->rendered_height()); |
| 1102 | double initiating_video_ratio = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1103 | static_cast<double>(initializing_client()->rendered_width()) / |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1104 | initializing_client()->rendered_height(); |
| 1105 | EXPECT_LE(requested_ratio, initiating_video_ratio); |
| 1106 | |
| 1107 | ASSERT_LE(0, receiving_client()->rendered_height()); |
| 1108 | double receiving_video_ratio = |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1109 | static_cast<double>(receiving_client()->rendered_width()) / |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1110 | receiving_client()->rendered_height(); |
| 1111 | EXPECT_LE(requested_ratio, receiving_video_ratio); |
| 1112 | } |
| 1113 | |
| 1114 | // This test sets up a Jsep call between two parties and test that the |
| 1115 | // received video has a resolution of 1280*720. |
| 1116 | // TODO(mallinath): Enable when |
| 1117 | // http://code.google.com/p/webrtc/issues/detail?id=981 is fixed. |
| 1118 | TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTest1280By720) { |
| 1119 | ASSERT_TRUE(CreateTestClients()); |
| 1120 | FakeConstraints constraint; |
| 1121 | constraint.SetMandatoryMinWidth(1280); |
| 1122 | constraint.SetMandatoryMinHeight(720); |
| 1123 | SetVideoConstraints(constraint, constraint); |
| 1124 | LocalP2PTest(); |
| 1125 | VerifyRenderedSize(1280, 720); |
| 1126 | } |
| 1127 | |
| 1128 | // This test sets up a call between two endpoints that are configured to use |
| 1129 | // DTLS key agreement. As a result, DTLS is negotiated and used for transport. |
| 1130 | TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtls) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1131 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1132 | FakeConstraints setup_constraints; |
| 1133 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1134 | true); |
| 1135 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1136 | LocalP2PTest(); |
| 1137 | VerifyRenderedSize(640, 480); |
| 1138 | } |
| 1139 | |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1140 | // This test sets up a audio call initially and then upgrades to audio/video, |
| 1141 | // using DTLS. |
mallinath@webrtc.org | 50bc553 | 2013-10-21 17:58:35 +0000 | [diff] [blame] | 1142 | TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsRenegotiate) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1143 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 1144 | FakeConstraints setup_constraints; |
| 1145 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1146 | true); |
| 1147 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1148 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 1149 | LocalP2PTest(); |
| 1150 | receiving_client()->SetReceiveAudioVideo(true, true); |
| 1151 | receiving_client()->Negotiate(); |
| 1152 | } |
| 1153 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1154 | // This test sets up a call between two endpoints that are configured to use |
| 1155 | // DTLS key agreement. The offerer don't support SDES. As a result, DTLS is |
| 1156 | // negotiated and used for transport. |
| 1157 | TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestOfferDtlsButNotSdes) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1158 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1159 | FakeConstraints setup_constraints; |
| 1160 | setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, |
| 1161 | true); |
| 1162 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1163 | receiving_client()->RemoveSdesCryptoFromReceivedSdp(true); |
| 1164 | LocalP2PTest(); |
| 1165 | VerifyRenderedSize(640, 480); |
| 1166 | } |
| 1167 | |
| 1168 | // This test sets up a Jsep call between two parties, and the callee only |
| 1169 | // accept to receive video. |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 1170 | // BUG=https://code.google.com/p/webrtc/issues/detail?id=2288 |
| 1171 | TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestAnswerVideo) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1172 | ASSERT_TRUE(CreateTestClients()); |
| 1173 | receiving_client()->SetReceiveAudioVideo(false, true); |
| 1174 | LocalP2PTest(); |
| 1175 | } |
| 1176 | |
| 1177 | // This test sets up a Jsep call between two parties, and the callee only |
| 1178 | // accept to receive audio. |
henrike@webrtc.org | c0b1a28 | 2013-08-23 14:32:21 +0000 | [diff] [blame] | 1179 | TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestAnswerAudio) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1180 | ASSERT_TRUE(CreateTestClients()); |
| 1181 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 1182 | LocalP2PTest(); |
| 1183 | } |
| 1184 | |
| 1185 | // This test sets up a Jsep call between two parties, and the callee reject both |
| 1186 | // audio and video. |
| 1187 | TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerNone) { |
| 1188 | ASSERT_TRUE(CreateTestClients()); |
| 1189 | receiving_client()->SetReceiveAudioVideo(false, false); |
| 1190 | LocalP2PTest(); |
| 1191 | } |
| 1192 | |
| 1193 | // This test sets up an audio and video call between two parties. After the call |
| 1194 | // runs for a while (10 frames), the caller sends an update offer with video |
| 1195 | // being rejected. Once the re-negotiation is done, the video flow should stop |
| 1196 | // and the audio flow should continue. |
buildbot@webrtc.org | 688ed69 | 2014-05-14 18:26:09 +0000 | [diff] [blame] | 1197 | // Disabled due to b/14955157. |
| 1198 | TEST_F(JsepPeerConnectionP2PTestClient, |
| 1199 | DISABLED_UpdateOfferWithRejectedContent) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1200 | ASSERT_TRUE(CreateTestClients()); |
| 1201 | LocalP2PTest(); |
| 1202 | TestUpdateOfferWithRejectedContent(); |
| 1203 | } |
| 1204 | |
| 1205 | // This test sets up a Jsep call between two parties. The MSID is removed from |
| 1206 | // the SDP strings from the caller. |
buildbot@webrtc.org | 688ed69 | 2014-05-14 18:26:09 +0000 | [diff] [blame] | 1207 | // Disabled due to b/14955157. |
| 1208 | TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestWithoutMsid) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1209 | ASSERT_TRUE(CreateTestClients()); |
| 1210 | receiving_client()->RemoveMsidFromReceivedSdp(true); |
| 1211 | // TODO(perkj): Currently there is a bug that cause audio to stop playing if |
| 1212 | // audio and video is muxed when MSID is disabled. Remove |
| 1213 | // SetRemoveBundleFromSdp once |
| 1214 | // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed. |
| 1215 | receiving_client()->RemoveBundleFromReceivedSdp(true); |
| 1216 | LocalP2PTest(); |
| 1217 | } |
| 1218 | |
| 1219 | // This test sets up a Jsep call between two parties and the initiating peer |
| 1220 | // sends two steams. |
| 1221 | // TODO(perkj): Disabled due to |
| 1222 | // https://code.google.com/p/webrtc/issues/detail?id=1454 |
| 1223 | TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestTwoStreams) { |
| 1224 | ASSERT_TRUE(CreateTestClients()); |
| 1225 | // Set optional video constraint to max 320pixels to decrease CPU usage. |
| 1226 | FakeConstraints constraint; |
| 1227 | constraint.SetOptionalMaxWidth(320); |
| 1228 | SetVideoConstraints(constraint, constraint); |
| 1229 | initializing_client()->AddMediaStream(true, true); |
| 1230 | initializing_client()->AddMediaStream(false, true); |
| 1231 | ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams()); |
| 1232 | LocalP2PTest(); |
| 1233 | EXPECT_EQ(2u, receiving_client()->number_of_remote_streams()); |
| 1234 | } |
| 1235 | |
| 1236 | // Test that we can receive the audio output level from a remote audio track. |
| 1237 | TEST_F(JsepPeerConnectionP2PTestClient, GetAudioOutputLevelStats) { |
| 1238 | ASSERT_TRUE(CreateTestClients()); |
| 1239 | LocalP2PTest(); |
| 1240 | |
| 1241 | StreamCollectionInterface* remote_streams = |
| 1242 | initializing_client()->remote_streams(); |
| 1243 | ASSERT_GT(remote_streams->count(), 0u); |
| 1244 | ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1245 | MediaStreamTrackInterface* remote_audio_track = |
| 1246 | remote_streams->at(0)->GetAudioTracks()[0]; |
| 1247 | |
| 1248 | // Get the audio output level stats. Note that the level is not available |
| 1249 | // until a RTCP packet has been received. |
| 1250 | EXPECT_TRUE_WAIT( |
| 1251 | initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0, |
| 1252 | kMaxWaitForStatsMs); |
| 1253 | } |
| 1254 | |
| 1255 | // Test that an audio input level is reported. |
| 1256 | TEST_F(JsepPeerConnectionP2PTestClient, GetAudioInputLevelStats) { |
| 1257 | ASSERT_TRUE(CreateTestClients()); |
| 1258 | LocalP2PTest(); |
| 1259 | |
| 1260 | // Get the audio input level stats. The level should be available very |
| 1261 | // soon after the test starts. |
| 1262 | EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0, |
| 1263 | kMaxWaitForStatsMs); |
| 1264 | } |
| 1265 | |
| 1266 | // Test that we can get incoming byte counts from both audio and video tracks. |
| 1267 | TEST_F(JsepPeerConnectionP2PTestClient, GetBytesReceivedStats) { |
| 1268 | ASSERT_TRUE(CreateTestClients()); |
| 1269 | LocalP2PTest(); |
| 1270 | |
| 1271 | StreamCollectionInterface* remote_streams = |
| 1272 | initializing_client()->remote_streams(); |
| 1273 | ASSERT_GT(remote_streams->count(), 0u); |
| 1274 | ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1275 | MediaStreamTrackInterface* remote_audio_track = |
| 1276 | remote_streams->at(0)->GetAudioTracks()[0]; |
| 1277 | EXPECT_TRUE_WAIT( |
| 1278 | initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0, |
| 1279 | kMaxWaitForStatsMs); |
| 1280 | |
| 1281 | MediaStreamTrackInterface* remote_video_track = |
| 1282 | remote_streams->at(0)->GetVideoTracks()[0]; |
| 1283 | EXPECT_TRUE_WAIT( |
| 1284 | initializing_client()->GetBytesReceivedStats(remote_video_track) > 0, |
| 1285 | kMaxWaitForStatsMs); |
| 1286 | } |
| 1287 | |
| 1288 | // Test that we can get outgoing byte counts from both audio and video tracks. |
| 1289 | TEST_F(JsepPeerConnectionP2PTestClient, GetBytesSentStats) { |
| 1290 | ASSERT_TRUE(CreateTestClients()); |
| 1291 | LocalP2PTest(); |
| 1292 | |
| 1293 | StreamCollectionInterface* local_streams = |
| 1294 | initializing_client()->local_streams(); |
| 1295 | ASSERT_GT(local_streams->count(), 0u); |
| 1296 | ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u); |
| 1297 | MediaStreamTrackInterface* local_audio_track = |
| 1298 | local_streams->at(0)->GetAudioTracks()[0]; |
| 1299 | EXPECT_TRUE_WAIT( |
| 1300 | initializing_client()->GetBytesSentStats(local_audio_track) > 0, |
| 1301 | kMaxWaitForStatsMs); |
| 1302 | |
| 1303 | MediaStreamTrackInterface* local_video_track = |
| 1304 | local_streams->at(0)->GetVideoTracks()[0]; |
| 1305 | EXPECT_TRUE_WAIT( |
| 1306 | initializing_client()->GetBytesSentStats(local_video_track) > 0, |
| 1307 | kMaxWaitForStatsMs); |
| 1308 | } |
| 1309 | |
| 1310 | // This test sets up a call between two parties with audio, video and data. |
| 1311 | TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDataChannel) { |
| 1312 | FakeConstraints setup_constraints; |
| 1313 | setup_constraints.SetAllowRtpDataChannels(); |
| 1314 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1315 | initializing_client()->CreateDataChannel(); |
| 1316 | LocalP2PTest(); |
| 1317 | ASSERT_TRUE(initializing_client()->data_channel() != NULL); |
| 1318 | ASSERT_TRUE(receiving_client()->data_channel() != NULL); |
| 1319 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1320 | kMaxWaitMs); |
| 1321 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), |
| 1322 | kMaxWaitMs); |
| 1323 | |
| 1324 | std::string data = "hello world"; |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1325 | |
| 1326 | SendRtpData(initializing_client()->data_channel(), data); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1327 | EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(), |
| 1328 | kMaxWaitMs); |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1329 | |
| 1330 | SendRtpData(receiving_client()->data_channel(), data); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1331 | EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(), |
| 1332 | kMaxWaitMs); |
| 1333 | |
| 1334 | receiving_client()->data_channel()->Close(); |
| 1335 | // Send new offer and answer. |
| 1336 | receiving_client()->Negotiate(); |
| 1337 | EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); |
| 1338 | EXPECT_FALSE(receiving_client()->data_observer()->IsOpen()); |
| 1339 | } |
| 1340 | |
| 1341 | // This test sets up a call between two parties and creates a data channel. |
| 1342 | // The test tests that received data is buffered unless an observer has been |
| 1343 | // registered. |
| 1344 | // Rtp data channels can receive data before the underlying |
| 1345 | // transport has detected that a channel is writable and thus data can be |
| 1346 | // received before the data channel state changes to open. That is hard to test |
| 1347 | // but the same buffering is used in that case. |
| 1348 | TEST_F(JsepPeerConnectionP2PTestClient, RegisterDataChannelObserver) { |
| 1349 | FakeConstraints setup_constraints; |
| 1350 | setup_constraints.SetAllowRtpDataChannels(); |
| 1351 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1352 | initializing_client()->CreateDataChannel(); |
| 1353 | initializing_client()->Negotiate(); |
| 1354 | |
| 1355 | ASSERT_TRUE(initializing_client()->data_channel() != NULL); |
| 1356 | ASSERT_TRUE(receiving_client()->data_channel() != NULL); |
| 1357 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1358 | kMaxWaitMs); |
| 1359 | EXPECT_EQ_WAIT(DataChannelInterface::kOpen, |
| 1360 | receiving_client()->data_channel()->state(), kMaxWaitMs); |
| 1361 | |
| 1362 | // Unregister the existing observer. |
| 1363 | receiving_client()->data_channel()->UnregisterObserver(); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1364 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1365 | std::string data = "hello world"; |
jiayl@webrtc.org | 6c6f33b | 2014-06-12 21:05:19 +0000 | [diff] [blame] | 1366 | SendRtpData(initializing_client()->data_channel(), data); |
| 1367 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1368 | // Wait a while to allow the sent data to arrive before an observer is |
| 1369 | // registered.. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1370 | rtc::Thread::Current()->ProcessMessages(100); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1371 | |
| 1372 | MockDataChannelObserver new_observer(receiving_client()->data_channel()); |
| 1373 | EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs); |
| 1374 | } |
| 1375 | |
| 1376 | // This test sets up a call between two parties with audio, video and but only |
| 1377 | // the initiating client support data. |
| 1378 | TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestReceiverDoesntSupportData) { |
buildbot@webrtc.org | 61c1b8e | 2014-04-09 06:06:38 +0000 | [diff] [blame] | 1379 | FakeConstraints setup_constraints_1; |
| 1380 | setup_constraints_1.SetAllowRtpDataChannels(); |
| 1381 | // Must disable DTLS to make negotiation succeed. |
| 1382 | setup_constraints_1.SetMandatory( |
| 1383 | MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 1384 | FakeConstraints setup_constraints_2; |
| 1385 | setup_constraints_2.SetMandatory( |
| 1386 | MediaConstraintsInterface::kEnableDtlsSrtp, false); |
| 1387 | ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1388 | initializing_client()->CreateDataChannel(); |
| 1389 | LocalP2PTest(); |
| 1390 | EXPECT_TRUE(initializing_client()->data_channel() != NULL); |
| 1391 | EXPECT_FALSE(receiving_client()->data_channel()); |
| 1392 | EXPECT_FALSE(initializing_client()->data_observer()->IsOpen()); |
| 1393 | } |
| 1394 | |
| 1395 | // This test sets up a call between two parties with audio, video. When audio |
| 1396 | // and video is setup and flowing and data channel is negotiated. |
| 1397 | TEST_F(JsepPeerConnectionP2PTestClient, AddDataChannelAfterRenegotiation) { |
| 1398 | FakeConstraints setup_constraints; |
| 1399 | setup_constraints.SetAllowRtpDataChannels(); |
| 1400 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1401 | LocalP2PTest(); |
| 1402 | initializing_client()->CreateDataChannel(); |
| 1403 | // Send new offer and answer. |
| 1404 | initializing_client()->Negotiate(); |
| 1405 | ASSERT_TRUE(initializing_client()->data_channel() != NULL); |
| 1406 | ASSERT_TRUE(receiving_client()->data_channel() != NULL); |
| 1407 | EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(), |
| 1408 | kMaxWaitMs); |
| 1409 | EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(), |
| 1410 | kMaxWaitMs); |
| 1411 | } |
| 1412 | |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1413 | // This test sets up a Jsep call with SCTP DataChannel and verifies the |
| 1414 | // negotiation is completed without error. |
| 1415 | #ifdef HAVE_SCTP |
| 1416 | TEST_F(JsepPeerConnectionP2PTestClient, CreateOfferWithSctpDataChannel) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1417 | MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp); |
jiayl@webrtc.org | 9c16c39 | 2014-05-01 18:30:30 +0000 | [diff] [blame] | 1418 | FakeConstraints constraints; |
| 1419 | constraints.SetMandatory( |
| 1420 | MediaConstraintsInterface::kEnableDtlsSrtp, true); |
| 1421 | ASSERT_TRUE(CreateTestClients(&constraints, &constraints)); |
| 1422 | initializing_client()->CreateDataChannel(); |
| 1423 | initializing_client()->Negotiate(false, false); |
| 1424 | } |
| 1425 | #endif |
| 1426 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1427 | // This test sets up a call between two parties with audio, and video. |
| 1428 | // During the call, the initializing side restart ice and the test verifies that |
| 1429 | // new ice candidates are generated and audio and video still can flow. |
| 1430 | TEST_F(JsepPeerConnectionP2PTestClient, IceRestart) { |
| 1431 | ASSERT_TRUE(CreateTestClients()); |
| 1432 | |
| 1433 | // Negotiate and wait for ice completion and make sure audio and video plays. |
| 1434 | LocalP2PTest(); |
| 1435 | |
| 1436 | // Create a SDP string of the first audio candidate for both clients. |
| 1437 | const webrtc::IceCandidateCollection* audio_candidates_initiator = |
| 1438 | initializing_client()->pc()->local_description()->candidates(0); |
| 1439 | const webrtc::IceCandidateCollection* audio_candidates_receiver = |
| 1440 | receiving_client()->pc()->local_description()->candidates(0); |
| 1441 | ASSERT_GT(audio_candidates_initiator->count(), 0u); |
| 1442 | ASSERT_GT(audio_candidates_receiver->count(), 0u); |
| 1443 | std::string initiator_candidate; |
| 1444 | EXPECT_TRUE( |
| 1445 | audio_candidates_initiator->at(0)->ToString(&initiator_candidate)); |
| 1446 | std::string receiver_candidate; |
| 1447 | EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate)); |
| 1448 | |
| 1449 | // Restart ice on the initializing client. |
| 1450 | receiving_client()->SetExpectIceRestart(true); |
| 1451 | initializing_client()->IceRestart(); |
| 1452 | |
| 1453 | // Negotiate and wait for ice completion again and make sure audio and video |
| 1454 | // plays. |
| 1455 | LocalP2PTest(); |
| 1456 | |
| 1457 | // Create a SDP string of the first audio candidate for both clients again. |
| 1458 | const webrtc::IceCandidateCollection* audio_candidates_initiator_restart = |
| 1459 | initializing_client()->pc()->local_description()->candidates(0); |
| 1460 | const webrtc::IceCandidateCollection* audio_candidates_reciever_restart = |
| 1461 | receiving_client()->pc()->local_description()->candidates(0); |
| 1462 | ASSERT_GT(audio_candidates_initiator_restart->count(), 0u); |
| 1463 | ASSERT_GT(audio_candidates_reciever_restart->count(), 0u); |
| 1464 | std::string initiator_candidate_restart; |
| 1465 | EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString( |
| 1466 | &initiator_candidate_restart)); |
| 1467 | std::string receiver_candidate_restart; |
| 1468 | EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString( |
| 1469 | &receiver_candidate_restart)); |
| 1470 | |
| 1471 | // Verify that the first candidates in the local session descriptions has |
| 1472 | // changed. |
| 1473 | EXPECT_NE(initiator_candidate, initiator_candidate_restart); |
| 1474 | EXPECT_NE(receiver_candidate, receiver_candidate_restart); |
| 1475 | } |
| 1476 | |
| 1477 | |
| 1478 | // This test sets up a Jsep call between two parties with external |
| 1479 | // VideoDecoderFactory. |
stefan@webrtc.org | da79008 | 2013-09-17 13:11:38 +0000 | [diff] [blame] | 1480 | // TODO(holmer): Disabled due to sometimes crashing on buildbots. |
| 1481 | // See issue webrtc/2378. |
| 1482 | TEST_F(JsepPeerConnectionP2PTestClient, |
| 1483 | DISABLED_LocalP2PTestWithVideoDecoderFactory) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1484 | ASSERT_TRUE(CreateTestClients()); |
| 1485 | EnableVideoDecoderFactory(); |
| 1486 | LocalP2PTest(); |
| 1487 | } |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1488 | |
| 1489 | // Test receive bandwidth stats with only audio enabled at receiver. |
| 1490 | TEST_F(JsepPeerConnectionP2PTestClient, ReceivedBweStatsAudio) { |
| 1491 | ASSERT_TRUE(CreateTestClients()); |
| 1492 | receiving_client()->SetReceiveAudioVideo(true, false); |
| 1493 | LocalP2PTest(); |
| 1494 | |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1495 | // Wait until we have received some audio data. Following REMB shoud be zero. |
| 1496 | WaitForAudioData(10000); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1497 | EXPECT_EQ_WAIT( |
| 1498 | receiving_client()->GetAvailableReceivedBandwidthStats(), 0, |
| 1499 | kMaxWaitForRembMs); |
| 1500 | } |
| 1501 | |
| 1502 | // Test receive bandwidth stats with combined BWE. |
| 1503 | TEST_F(JsepPeerConnectionP2PTestClient, ReceivedBweStatsCombined) { |
| 1504 | FakeConstraints setup_constraints; |
| 1505 | setup_constraints.AddOptional( |
| 1506 | MediaConstraintsInterface::kCombinedAudioVideoBwe, true); |
| 1507 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1508 | initializing_client()->AddMediaStream(true, true); |
| 1509 | initializing_client()->AddMediaStream(false, true); |
| 1510 | initializing_client()->AddMediaStream(false, true); |
| 1511 | initializing_client()->AddMediaStream(false, true); |
| 1512 | LocalP2PTest(); |
| 1513 | |
| 1514 | // Run until a non-zero bw is reported. |
| 1515 | EXPECT_TRUE_WAIT( |
| 1516 | receiving_client()->GetAvailableReceivedBandwidthStats() > 40000, |
| 1517 | kMaxWaitForRembMs); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1518 | |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1519 | // Halt video capturers, then run until we have gotten some audio. Following |
| 1520 | // REMB should be non-zero. |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1521 | initializing_client()->StopVideoCapturers(); |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1522 | WaitForAudioData(10000); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1523 | EXPECT_TRUE_WAIT( |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1524 | receiving_client()->GetAvailableReceivedBandwidthStats() > 0, |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1525 | kMaxWaitForRembMs); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | // Test receive bandwidth stats with 1 video, 3 audio streams but no combined |
| 1529 | // BWE. |
| 1530 | TEST_F(JsepPeerConnectionP2PTestClient, ReceivedBweStatsNotCombined) { |
| 1531 | FakeConstraints setup_constraints; |
| 1532 | setup_constraints.AddOptional( |
| 1533 | MediaConstraintsInterface::kCombinedAudioVideoBwe, false); |
| 1534 | ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
| 1535 | initializing_client()->AddMediaStream(true, true); |
| 1536 | initializing_client()->AddMediaStream(false, true); |
| 1537 | initializing_client()->AddMediaStream(false, true); |
| 1538 | initializing_client()->AddMediaStream(false, true); |
| 1539 | LocalP2PTest(); |
| 1540 | |
| 1541 | // Run until a non-zero bw is reported. |
| 1542 | EXPECT_TRUE_WAIT( |
| 1543 | receiving_client()->GetAvailableReceivedBandwidthStats() > 40000, |
| 1544 | kMaxWaitForRembMs); |
| 1545 | |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1546 | // Halt video capturers, then run until we have gotten some audio. Following |
| 1547 | // REMB should be zero. |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1548 | initializing_client()->StopVideoCapturers(); |
solenberg@webrtc.org | 6556a59 | 2014-08-25 14:35:40 +0000 | [diff] [blame] | 1549 | WaitForAudioData(10000); |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 1550 | EXPECT_EQ_WAIT( |
| 1551 | receiving_client()->GetAvailableReceivedBandwidthStats(), 0, |
| 1552 | kMaxWaitForRembMs); |
| 1553 | } |
| 1554 | |
kjellander@webrtc.org | d1cfa71 | 2013-10-16 16:51:52 +0000 | [diff] [blame] | 1555 | #endif // if !defined(THREAD_SANITIZER) |