blob: b395a315a0d470d9b9e79cef12ec3ae4c4ba91a1 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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.orga576faf2014-01-29 17:45:53 +000043#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044#include "talk/app/webrtc/test/fakeperiodicvideocapturer.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "talk/app/webrtc/test/fakevideotrackrenderer.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046#include "talk/app/webrtc/test/mockpeerconnectionobservers.h"
47#include "talk/app/webrtc/videosourceinterface.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000048#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.orgd4e598d2014-07-29 17:36:52 +000052#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.org28e20752013-07-10 00:45:36 +000057
58#define MAYBE_SKIP_TEST(feature) \
59 if (!(feature())) { \
60 LOG(LS_INFO) << "Feature disabled... skipping"; \
61 return; \
62 }
63
64using cricket::ContentInfo;
65using cricket::FakeWebRtcVideoDecoder;
66using cricket::FakeWebRtcVideoDecoderFactory;
67using cricket::FakeWebRtcVideoEncoder;
68using cricket::FakeWebRtcVideoEncoderFactory;
69using cricket::MediaContentDescription;
70using webrtc::DataBuffer;
71using webrtc::DataChannelInterface;
72using webrtc::DtmfSender;
73using webrtc::DtmfSenderInterface;
74using webrtc::DtmfSenderObserverInterface;
75using webrtc::FakeConstraints;
76using webrtc::MediaConstraintsInterface;
77using webrtc::MediaStreamTrackInterface;
78using webrtc::MockCreateSessionDescriptionObserver;
79using webrtc::MockDataChannelObserver;
80using webrtc::MockSetSessionDescriptionObserver;
81using webrtc::MockStatsObserver;
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +000082using webrtc::PeerConnectionInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::SessionDescriptionInterface;
84using webrtc::StreamCollectionInterface;
85
jiayl@webrtc.org8f88f202014-04-16 17:14:21 +000086static const int kMaxWaitMs = 2000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000087// 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.org28e20752013-07-10 00:45:36 +000092static const int kMaxWaitForStatsMs = 3000;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000093static const int kMaxWaitForAudioDataMs = 10000;
94static const int kMaxWaitForRembMs = 5000;
pbos@webrtc.org044bdac2014-06-03 09:40:01 +000095#endif
buildbot@webrtc.org3e01e0b2014-05-13 17:54:10 +000096static const int kMaxWaitForFramesMs = 10000;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097static const int kEndAudioFrameCount = 3;
98static const int kEndVideoFrameCount = 3;
99
100static const char kStreamLabelBase[] = "stream_label";
101static const char kVideoTrackLabelBase[] = "video_track";
102static const char kAudioTrackLabelBase[] = "audio_track";
103static const char kDataChannelLabel[] = "data_channel";
104
105static void RemoveLinesFromSdp(const std::string& line_start,
106 std::string* sdp) {
107 const char kSdpLineEnd[] = "\r\n";
108 size_t ssrc_pos = 0;
109 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
110 std::string::npos) {
111 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
112 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
113 }
114}
115
116class SignalingMessageReceiver {
117 public:
118 protected:
119 SignalingMessageReceiver() {}
120 virtual ~SignalingMessageReceiver() {}
121};
122
123class JsepMessageReceiver : public SignalingMessageReceiver {
124 public:
125 virtual void ReceiveSdpMessage(const std::string& type,
126 std::string& msg) = 0;
127 virtual void ReceiveIceMessage(const std::string& sdp_mid,
128 int sdp_mline_index,
129 const std::string& msg) = 0;
130
131 protected:
132 JsepMessageReceiver() {}
133 virtual ~JsepMessageReceiver() {}
134};
135
136template <typename MessageReceiver>
137class PeerConnectionTestClientBase
138 : public webrtc::PeerConnectionObserver,
139 public MessageReceiver {
140 public:
141 ~PeerConnectionTestClientBase() {
142 while (!fake_video_renderers_.empty()) {
143 RenderMap::iterator it = fake_video_renderers_.begin();
144 delete it->second;
145 fake_video_renderers_.erase(it);
146 }
147 }
148
149 virtual void Negotiate() = 0;
150
151 virtual void Negotiate(bool audio, bool video) = 0;
152
153 virtual void SetVideoConstraints(
154 const webrtc::FakeConstraints& video_constraint) {
155 video_constraints_ = video_constraint;
156 }
157
158 void AddMediaStream(bool audio, bool video) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000159 std::string stream_label = kStreamLabelBase +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000160 rtc::ToString<int>(
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000161 static_cast<int>(peer_connection_->local_streams()->count()));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000162 rtc::scoped_refptr<webrtc::MediaStreamInterface> stream =
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000163 peer_connection_factory_->CreateLocalMediaStream(stream_label);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164
165 if (audio && can_receive_audio()) {
166 FakeConstraints constraints;
167 // Disable highpass filter so that we can get all the test audio frames.
168 constraints.AddMandatory(
169 MediaConstraintsInterface::kHighpassFilter, false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000170 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
wu@webrtc.org97077a32013-10-25 21:18:33 +0000171 peer_connection_factory_->CreateAudioSource(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 // TODO(perkj): Test audio source when it is implemented. Currently audio
173 // always use the default input.
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000174 std::string label = stream_label + kAudioTrackLabelBase;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000175 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio_track(
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000176 peer_connection_factory_->CreateAudioTrack(label, source));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 stream->AddTrack(audio_track);
178 }
179 if (video && can_receive_video()) {
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000180 stream->AddTrack(CreateLocalVideoTrack(stream_label));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 }
182
183 EXPECT_TRUE(peer_connection_->AddStream(stream, NULL));
184 }
185
186 size_t NumberOfLocalMediaStreams() {
187 return peer_connection_->local_streams()->count();
188 }
189
190 bool SessionActive() {
191 return peer_connection_->signaling_state() ==
192 webrtc::PeerConnectionInterface::kStable;
193 }
194
195 void set_signaling_message_receiver(
196 MessageReceiver* signaling_message_receiver) {
197 signaling_message_receiver_ = signaling_message_receiver;
198 }
199
200 void EnableVideoDecoderFactory() {
201 video_decoder_factory_enabled_ = true;
202 fake_video_decoder_factory_->AddSupportedVideoCodecType(
203 webrtc::kVideoCodecVP8);
204 }
205
206 bool AudioFramesReceivedCheck(int number_of_frames) const {
207 return number_of_frames <= fake_audio_capture_module_->frames_received();
208 }
209
210 bool VideoFramesReceivedCheck(int number_of_frames) {
211 if (video_decoder_factory_enabled_) {
212 const std::vector<FakeWebRtcVideoDecoder*>& decoders
213 = fake_video_decoder_factory_->decoders();
214 if (decoders.empty()) {
215 return number_of_frames <= 0;
216 }
217
218 for (std::vector<FakeWebRtcVideoDecoder*>::const_iterator
219 it = decoders.begin(); it != decoders.end(); ++it) {
220 if (number_of_frames > (*it)->GetNumFramesReceived()) {
221 return false;
222 }
223 }
224 return true;
225 } else {
226 if (fake_video_renderers_.empty()) {
227 return number_of_frames <= 0;
228 }
229
230 for (RenderMap::const_iterator it = fake_video_renderers_.begin();
231 it != fake_video_renderers_.end(); ++it) {
232 if (number_of_frames > it->second->num_rendered_frames()) {
233 return false;
234 }
235 }
236 return true;
237 }
238 }
239 // Verify the CreateDtmfSender interface
240 void VerifyDtmf() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000241 rtc::scoped_ptr<DummyDtmfObserver> observer(new DummyDtmfObserver());
242 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243
244 // We can't create a DTMF sender with an invalid audio track or a non local
245 // track.
246 EXPECT_TRUE(peer_connection_->CreateDtmfSender(NULL) == NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000247 rtc::scoped_refptr<webrtc::AudioTrackInterface> non_localtrack(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 peer_connection_factory_->CreateAudioTrack("dummy_track",
249 NULL));
250 EXPECT_TRUE(peer_connection_->CreateDtmfSender(non_localtrack) == NULL);
251
252 // We should be able to create a DTMF sender from a local track.
253 webrtc::AudioTrackInterface* localtrack =
254 peer_connection_->local_streams()->at(0)->GetAudioTracks()[0];
255 dtmf_sender = peer_connection_->CreateDtmfSender(localtrack);
256 EXPECT_TRUE(dtmf_sender.get() != NULL);
257 dtmf_sender->RegisterObserver(observer.get());
258
259 // Test the DtmfSender object just created.
260 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
261 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
262
263 // We don't need to verify that the DTMF tones are actually sent out because
264 // that is already covered by the tests of the lower level components.
265
266 EXPECT_TRUE_WAIT(observer->completed(), kMaxWaitMs);
267 std::vector<std::string> tones;
268 tones.push_back("1");
269 tones.push_back("a");
270 tones.push_back("");
271 observer->Verify(tones);
272
273 dtmf_sender->UnregisterObserver();
274 }
275
276 // Verifies that the SessionDescription have rejected the appropriate media
277 // content.
278 void VerifyRejectedMediaInSessionDescription() {
279 ASSERT_TRUE(peer_connection_->remote_description() != NULL);
280 ASSERT_TRUE(peer_connection_->local_description() != NULL);
281 const cricket::SessionDescription* remote_desc =
282 peer_connection_->remote_description()->description();
283 const cricket::SessionDescription* local_desc =
284 peer_connection_->local_description()->description();
285
286 const ContentInfo* remote_audio_content = GetFirstAudioContent(remote_desc);
287 if (remote_audio_content) {
288 const ContentInfo* audio_content =
289 GetFirstAudioContent(local_desc);
290 EXPECT_EQ(can_receive_audio(), !audio_content->rejected);
291 }
292
293 const ContentInfo* remote_video_content = GetFirstVideoContent(remote_desc);
294 if (remote_video_content) {
295 const ContentInfo* video_content =
296 GetFirstVideoContent(local_desc);
297 EXPECT_EQ(can_receive_video(), !video_content->rejected);
298 }
299 }
300
301 void SetExpectIceRestart(bool expect_restart) {
302 expect_ice_restart_ = expect_restart;
303 }
304
305 bool ExpectIceRestart() const { return expect_ice_restart_; }
306
307 void VerifyLocalIceUfragAndPassword() {
308 ASSERT_TRUE(peer_connection_->local_description() != NULL);
309 const cricket::SessionDescription* desc =
310 peer_connection_->local_description()->description();
311 const cricket::ContentInfos& contents = desc->contents();
312
313 for (size_t index = 0; index < contents.size(); ++index) {
314 if (contents[index].rejected)
315 continue;
316 const cricket::TransportDescription* transport_desc =
317 desc->GetTransportDescriptionByName(contents[index].name);
318
319 std::map<int, IceUfragPwdPair>::const_iterator ufragpair_it =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000320 ice_ufrag_pwd_.find(static_cast<int>(index));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 if (ufragpair_it == ice_ufrag_pwd_.end()) {
322 ASSERT_FALSE(ExpectIceRestart());
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000323 ice_ufrag_pwd_[static_cast<int>(index)] =
324 IceUfragPwdPair(transport_desc->ice_ufrag, transport_desc->ice_pwd);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 } else if (ExpectIceRestart()) {
326 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
327 EXPECT_NE(ufrag_pwd.first, transport_desc->ice_ufrag);
328 EXPECT_NE(ufrag_pwd.second, transport_desc->ice_pwd);
329 } else {
330 const IceUfragPwdPair& ufrag_pwd = ufragpair_it->second;
331 EXPECT_EQ(ufrag_pwd.first, transport_desc->ice_ufrag);
332 EXPECT_EQ(ufrag_pwd.second, transport_desc->ice_pwd);
333 }
334 }
335 }
336
337 int GetAudioOutputLevelStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000338 rtc::scoped_refptr<MockStatsObserver>
339 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000340 EXPECT_TRUE(peer_connection_->GetStats(
341 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
343 return observer->AudioOutputLevel();
344 }
345
346 int GetAudioInputLevelStats() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000347 rtc::scoped_refptr<MockStatsObserver>
348 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000349 EXPECT_TRUE(peer_connection_->GetStats(
350 observer, NULL, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
352 return observer->AudioInputLevel();
353 }
354
355 int GetBytesReceivedStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000356 rtc::scoped_refptr<MockStatsObserver>
357 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000358 EXPECT_TRUE(peer_connection_->GetStats(
359 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
361 return observer->BytesReceived();
362 }
363
364 int GetBytesSentStats(webrtc::MediaStreamTrackInterface* track) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 rtc::scoped_refptr<MockStatsObserver>
366 observer(new rtc::RefCountedObject<MockStatsObserver>());
jiayl@webrtc.orgdb41b4d2014-03-03 21:30:06 +0000367 EXPECT_TRUE(peer_connection_->GetStats(
368 observer, track, PeerConnectionInterface::kStatsOutputLevelStandard));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
370 return observer->BytesSent();
371 }
372
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000373 int GetAvailableReceivedBandwidthStats() {
374 rtc::scoped_refptr<MockStatsObserver>
375 observer(new rtc::RefCountedObject<MockStatsObserver>());
376 EXPECT_TRUE(peer_connection_->GetStats(
377 observer, NULL, PeerConnectionInterface::kStatsOutputLevelStandard));
378 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
379 int bw = observer->AvailableReceiveBandwidth();
380 LOG(INFO) << "Available Receive Bandwidth: " << bw;
381 return bw;
382 }
383
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 int rendered_width() {
385 EXPECT_FALSE(fake_video_renderers_.empty());
386 return fake_video_renderers_.empty() ? 1 :
387 fake_video_renderers_.begin()->second->width();
388 }
389
390 int rendered_height() {
391 EXPECT_FALSE(fake_video_renderers_.empty());
392 return fake_video_renderers_.empty() ? 1 :
393 fake_video_renderers_.begin()->second->height();
394 }
395
396 size_t number_of_remote_streams() {
397 if (!pc())
398 return 0;
399 return pc()->remote_streams()->count();
400 }
401
402 StreamCollectionInterface* remote_streams() {
403 if (!pc()) {
404 ADD_FAILURE();
405 return NULL;
406 }
407 return pc()->remote_streams();
408 }
409
410 StreamCollectionInterface* local_streams() {
411 if (!pc()) {
412 ADD_FAILURE();
413 return NULL;
414 }
415 return pc()->local_streams();
416 }
417
418 webrtc::PeerConnectionInterface::SignalingState signaling_state() {
419 return pc()->signaling_state();
420 }
421
422 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
423 return pc()->ice_connection_state();
424 }
425
426 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
427 return pc()->ice_gathering_state();
428 }
429
430 // PeerConnectionObserver callbacks.
431 virtual void OnError() {}
432 virtual void OnMessage(const std::string&) {}
433 virtual void OnSignalingMessage(const std::string& /*msg*/) {}
434 virtual void OnSignalingChange(
435 webrtc::PeerConnectionInterface::SignalingState new_state) {
436 EXPECT_EQ(peer_connection_->signaling_state(), new_state);
437 }
438 virtual void OnAddStream(webrtc::MediaStreamInterface* media_stream) {
439 for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) {
440 const std::string id = media_stream->GetVideoTracks()[i]->id();
441 ASSERT_TRUE(fake_video_renderers_.find(id) ==
442 fake_video_renderers_.end());
443 fake_video_renderers_[id] = new webrtc::FakeVideoTrackRenderer(
444 media_stream->GetVideoTracks()[i]);
445 }
446 }
447 virtual void OnRemoveStream(webrtc::MediaStreamInterface* media_stream) {}
448 virtual void OnRenegotiationNeeded() {}
449 virtual void OnIceConnectionChange(
450 webrtc::PeerConnectionInterface::IceConnectionState new_state) {
451 EXPECT_EQ(peer_connection_->ice_connection_state(), new_state);
452 }
453 virtual void OnIceGatheringChange(
454 webrtc::PeerConnectionInterface::IceGatheringState new_state) {
455 EXPECT_EQ(peer_connection_->ice_gathering_state(), new_state);
456 }
457 virtual void OnIceCandidate(
458 const webrtc::IceCandidateInterface* /*candidate*/) {}
459
460 webrtc::PeerConnectionInterface* pc() {
461 return peer_connection_.get();
462 }
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000463 void StopVideoCapturers() {
464 for (std::vector<cricket::VideoCapturer*>::iterator it =
465 video_capturers_.begin(); it != video_capturers_.end(); ++it) {
466 (*it)->Stop();
467 }
468 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469
470 protected:
471 explicit PeerConnectionTestClientBase(const std::string& id)
472 : id_(id),
473 expect_ice_restart_(false),
474 fake_video_decoder_factory_(NULL),
475 fake_video_encoder_factory_(NULL),
476 video_decoder_factory_enabled_(false),
477 signaling_message_receiver_(NULL) {
478 }
479 bool Init(const MediaConstraintsInterface* constraints) {
480 EXPECT_TRUE(!peer_connection_);
481 EXPECT_TRUE(!peer_connection_factory_);
482 allocator_factory_ = webrtc::FakePortAllocatorFactory::Create();
483 if (!allocator_factory_) {
484 return false;
485 }
486 audio_thread_.Start();
487 fake_audio_capture_module_ = FakeAudioCaptureModule::Create(
488 &audio_thread_);
489
490 if (fake_audio_capture_module_ == NULL) {
491 return false;
492 }
493 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
494 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
495 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000496 rtc::Thread::Current(), rtc::Thread::Current(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000497 fake_audio_capture_module_, fake_video_encoder_factory_,
498 fake_video_decoder_factory_);
499 if (!peer_connection_factory_) {
500 return false;
501 }
502 peer_connection_ = CreatePeerConnection(allocator_factory_.get(),
503 constraints);
504 return peer_connection_.get() != NULL;
505 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000506 virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507 CreatePeerConnection(webrtc::PortAllocatorFactoryInterface* factory,
508 const MediaConstraintsInterface* constraints) = 0;
509 MessageReceiver* signaling_message_receiver() {
510 return signaling_message_receiver_;
511 }
512 webrtc::PeerConnectionFactoryInterface* peer_connection_factory() {
513 return peer_connection_factory_.get();
514 }
515
516 virtual bool can_receive_audio() = 0;
517 virtual bool can_receive_video() = 0;
518 const std::string& id() const { return id_; }
519
520 private:
521 class DummyDtmfObserver : public DtmfSenderObserverInterface {
522 public:
523 DummyDtmfObserver() : completed_(false) {}
524
525 // Implements DtmfSenderObserverInterface.
526 void OnToneChange(const std::string& tone) {
527 tones_.push_back(tone);
528 if (tone.empty()) {
529 completed_ = true;
530 }
531 }
532
533 void Verify(const std::vector<std::string>& tones) const {
534 ASSERT_TRUE(tones_.size() == tones.size());
535 EXPECT_TRUE(std::equal(tones.begin(), tones.end(), tones_.begin()));
536 }
537
538 bool completed() const { return completed_; }
539
540 private:
541 bool completed_;
542 std::vector<std::string> tones_;
543 };
544
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000545 rtc::scoped_refptr<webrtc::VideoTrackInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 CreateLocalVideoTrack(const std::string stream_label) {
547 // Set max frame rate to 10fps to reduce the risk of the tests to be flaky.
548 FakeConstraints source_constraints = video_constraints_;
549 source_constraints.SetMandatoryMaxFrameRate(10);
550
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000551 cricket::FakeVideoCapturer* fake_capturer =
552 new webrtc::FakePeriodicVideoCapturer();
553 video_capturers_.push_back(fake_capturer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000554 rtc::scoped_refptr<webrtc::VideoSourceInterface> source =
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 peer_connection_factory_->CreateVideoSource(
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000556 fake_capturer, &source_constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 std::string label = stream_label + kVideoTrackLabelBase;
558 return peer_connection_factory_->CreateVideoTrack(label, source);
559 }
560
561 std::string id_;
562 // Separate thread for executing |fake_audio_capture_module_| tasks. Audio
563 // processing must not be performed on the same thread as signaling due to
564 // signaling time constraints and relative complexity of the audio pipeline.
565 // This is consistent with the video pipeline that us a a separate thread for
566 // encoding and decoding.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000567 rtc::Thread audio_thread_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000569 rtc::scoped_refptr<webrtc::PortAllocatorFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 allocator_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000571 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
572 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 peer_connection_factory_;
574
575 typedef std::pair<std::string, std::string> IceUfragPwdPair;
576 std::map<int, IceUfragPwdPair> ice_ufrag_pwd_;
577 bool expect_ice_restart_;
578
579 // Needed to keep track of number of frames send.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000580 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 // Needed to keep track of number of frames received.
582 typedef std::map<std::string, webrtc::FakeVideoTrackRenderer*> RenderMap;
583 RenderMap fake_video_renderers_;
584 // Needed to keep track of number of frames received when external decoder
585 // used.
586 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_;
587 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_;
588 bool video_decoder_factory_enabled_;
589 webrtc::FakeConstraints video_constraints_;
590
591 // For remote peer communication.
592 MessageReceiver* signaling_message_receiver_;
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000593
594 // Store references to the video capturers we've created, so that we can stop
595 // them, if required.
596 std::vector<cricket::VideoCapturer*> video_capturers_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597};
598
599class JsepTestClient
600 : public PeerConnectionTestClientBase<JsepMessageReceiver> {
601 public:
602 static JsepTestClient* CreateClient(
603 const std::string& id,
604 const MediaConstraintsInterface* constraints) {
605 JsepTestClient* client(new JsepTestClient(id));
606 if (!client->Init(constraints)) {
607 delete client;
608 return NULL;
609 }
610 return client;
611 }
612 ~JsepTestClient() {}
613
614 virtual void Negotiate() {
615 Negotiate(true, true);
616 }
617 virtual void Negotiate(bool audio, bool video) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000618 rtc::scoped_ptr<SessionDescriptionInterface> offer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 EXPECT_TRUE(DoCreateOffer(offer.use()));
620
621 if (offer->description()->GetContentByName("audio")) {
622 offer->description()->GetContentByName("audio")->rejected = !audio;
623 }
624 if (offer->description()->GetContentByName("video")) {
625 offer->description()->GetContentByName("video")->rejected = !video;
626 }
627
628 std::string sdp;
629 EXPECT_TRUE(offer->ToString(&sdp));
630 EXPECT_TRUE(DoSetLocalDescription(offer.release()));
631 signaling_message_receiver()->ReceiveSdpMessage(
632 webrtc::SessionDescriptionInterface::kOffer, sdp);
633 }
634 // JsepMessageReceiver callback.
635 virtual void ReceiveSdpMessage(const std::string& type,
636 std::string& msg) {
637 FilterIncomingSdpMessage(&msg);
638 if (type == webrtc::SessionDescriptionInterface::kOffer) {
639 HandleIncomingOffer(msg);
640 } else {
641 HandleIncomingAnswer(msg);
642 }
643 }
644 // JsepMessageReceiver callback.
645 virtual void ReceiveIceMessage(const std::string& sdp_mid,
646 int sdp_mline_index,
647 const std::string& msg) {
648 LOG(INFO) << id() << "ReceiveIceMessage";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 rtc::scoped_ptr<webrtc::IceCandidateInterface> candidate(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, NULL));
651 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
652 }
653 // Implements PeerConnectionObserver functions needed by Jsep.
654 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
655 LOG(INFO) << id() << "OnIceCandidate";
656
657 std::string ice_sdp;
658 EXPECT_TRUE(candidate->ToString(&ice_sdp));
659 if (signaling_message_receiver() == NULL) {
660 // Remote party may be deleted.
661 return;
662 }
663 signaling_message_receiver()->ReceiveIceMessage(candidate->sdp_mid(),
664 candidate->sdp_mline_index(), ice_sdp);
665 }
666
667 void IceRestart() {
668 session_description_constraints_.SetMandatoryIceRestart(true);
669 SetExpectIceRestart(true);
670 }
671
672 void SetReceiveAudioVideo(bool audio, bool video) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000673 SetReceiveAudio(audio);
674 SetReceiveVideo(video);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 ASSERT_EQ(audio, can_receive_audio());
676 ASSERT_EQ(video, can_receive_video());
677 }
678
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000679 void SetReceiveAudio(bool audio) {
680 if (audio && can_receive_audio())
681 return;
682 session_description_constraints_.SetMandatoryReceiveAudio(audio);
683 }
684
685 void SetReceiveVideo(bool video) {
686 if (video && can_receive_video())
687 return;
688 session_description_constraints_.SetMandatoryReceiveVideo(video);
689 }
690
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 void RemoveMsidFromReceivedSdp(bool remove) {
692 remove_msid_ = remove;
693 }
694
695 void RemoveSdesCryptoFromReceivedSdp(bool remove) {
696 remove_sdes_ = remove;
697 }
698
699 void RemoveBundleFromReceivedSdp(bool remove) {
700 remove_bundle_ = remove;
701 }
702
703 virtual bool can_receive_audio() {
704 bool value;
705 if (webrtc::FindConstraint(&session_description_constraints_,
706 MediaConstraintsInterface::kOfferToReceiveAudio, &value, NULL)) {
707 return value;
708 }
709 return true;
710 }
711
712 virtual bool can_receive_video() {
713 bool value;
714 if (webrtc::FindConstraint(&session_description_constraints_,
715 MediaConstraintsInterface::kOfferToReceiveVideo, &value, NULL)) {
716 return value;
717 }
718 return true;
719 }
720
721 virtual void OnIceComplete() {
722 LOG(INFO) << id() << "OnIceComplete";
723 }
724
725 virtual void OnDataChannel(DataChannelInterface* data_channel) {
726 LOG(INFO) << id() << "OnDataChannel";
727 data_channel_ = data_channel;
728 data_observer_.reset(new MockDataChannelObserver(data_channel));
729 }
730
731 void CreateDataChannel() {
732 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel,
733 NULL);
734 ASSERT_TRUE(data_channel_.get() != NULL);
735 data_observer_.reset(new MockDataChannelObserver(data_channel_));
736 }
737
738 DataChannelInterface* data_channel() { return data_channel_; }
739 const MockDataChannelObserver* data_observer() const {
740 return data_observer_.get();
741 }
742
743 protected:
744 explicit JsepTestClient(const std::string& id)
745 : PeerConnectionTestClientBase<JsepMessageReceiver>(id),
746 remove_msid_(false),
747 remove_bundle_(false),
748 remove_sdes_(false) {
749 }
750
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000751 virtual rtc::scoped_refptr<webrtc::PeerConnectionInterface>
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 CreatePeerConnection(webrtc::PortAllocatorFactoryInterface* factory,
753 const MediaConstraintsInterface* constraints) {
754 // CreatePeerConnection with IceServers.
755 webrtc::PeerConnectionInterface::IceServers ice_servers;
756 webrtc::PeerConnectionInterface::IceServer ice_server;
757 ice_server.uri = "stun:stun.l.google.com:19302";
758 ice_servers.push_back(ice_server);
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000759
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +0000760 FakeIdentityService* dtls_service =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000761 rtc::SSLStreamAdapter::HaveDtlsSrtp() ?
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +0000762 new FakeIdentityService() : NULL;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 return peer_connection_factory()->CreatePeerConnection(
jiayl@webrtc.orga576faf2014-01-29 17:45:53 +0000764 ice_servers, constraints, factory, dtls_service, this);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 }
766
767 void HandleIncomingOffer(const std::string& msg) {
768 LOG(INFO) << id() << "HandleIncomingOffer ";
769 if (NumberOfLocalMediaStreams() == 0) {
770 // If we are not sending any streams ourselves it is time to add some.
771 AddMediaStream(true, true);
772 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000773 rtc::scoped_ptr<SessionDescriptionInterface> desc(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 webrtc::CreateSessionDescription("offer", msg, NULL));
775 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000776 rtc::scoped_ptr<SessionDescriptionInterface> answer;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 EXPECT_TRUE(DoCreateAnswer(answer.use()));
778 std::string sdp;
779 EXPECT_TRUE(answer->ToString(&sdp));
780 EXPECT_TRUE(DoSetLocalDescription(answer.release()));
781 if (signaling_message_receiver()) {
782 signaling_message_receiver()->ReceiveSdpMessage(
783 webrtc::SessionDescriptionInterface::kAnswer, sdp);
784 }
785 }
786
787 void HandleIncomingAnswer(const std::string& msg) {
788 LOG(INFO) << id() << "HandleIncomingAnswer";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000789 rtc::scoped_ptr<SessionDescriptionInterface> desc(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 webrtc::CreateSessionDescription("answer", msg, NULL));
791 EXPECT_TRUE(DoSetRemoteDescription(desc.release()));
792 }
793
794 bool DoCreateOfferAnswer(SessionDescriptionInterface** desc,
795 bool offer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000796 rtc::scoped_refptr<MockCreateSessionDescriptionObserver>
797 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 MockCreateSessionDescriptionObserver>());
799 if (offer) {
800 pc()->CreateOffer(observer, &session_description_constraints_);
801 } else {
802 pc()->CreateAnswer(observer, &session_description_constraints_);
803 }
804 EXPECT_EQ_WAIT(true, observer->called(), kMaxWaitMs);
805 *desc = observer->release_desc();
806 if (observer->result() && ExpectIceRestart()) {
807 EXPECT_EQ(0u, (*desc)->candidates(0)->count());
808 }
809 return observer->result();
810 }
811
812 bool DoCreateOffer(SessionDescriptionInterface** desc) {
813 return DoCreateOfferAnswer(desc, true);
814 }
815
816 bool DoCreateAnswer(SessionDescriptionInterface** desc) {
817 return DoCreateOfferAnswer(desc, false);
818 }
819
820 bool DoSetLocalDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000821 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
822 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 MockSetSessionDescriptionObserver>());
824 LOG(INFO) << id() << "SetLocalDescription ";
825 pc()->SetLocalDescription(observer, desc);
826 // Ignore the observer result. If we wait for the result with
827 // EXPECT_TRUE_WAIT, local ice candidates might be sent to the remote peer
828 // before the offer which is an error.
829 // The reason is that EXPECT_TRUE_WAIT uses
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000830 // rtc::Thread::Current()->ProcessMessages(1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 // ProcessMessages waits at least 1ms but processes all messages before
832 // returning. Since this test is synchronous and send messages to the remote
833 // peer whenever a callback is invoked, this can lead to messages being
834 // sent to the remote peer in the wrong order.
835 // TODO(perkj): Find a way to check the result without risking that the
836 // order of sent messages are changed. Ex- by posting all messages that are
837 // sent to the remote peer.
838 return true;
839 }
840
841 bool DoSetRemoteDescription(SessionDescriptionInterface* desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000842 rtc::scoped_refptr<MockSetSessionDescriptionObserver>
843 observer(new rtc::RefCountedObject<
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 MockSetSessionDescriptionObserver>());
845 LOG(INFO) << id() << "SetRemoteDescription ";
846 pc()->SetRemoteDescription(observer, desc);
847 EXPECT_TRUE_WAIT(observer->called(), kMaxWaitMs);
848 return observer->result();
849 }
850
851 // This modifies all received SDP messages before they are processed.
852 void FilterIncomingSdpMessage(std::string* sdp) {
853 if (remove_msid_) {
854 const char kSdpSsrcAttribute[] = "a=ssrc:";
855 RemoveLinesFromSdp(kSdpSsrcAttribute, sdp);
856 const char kSdpMsidSupportedAttribute[] = "a=msid-semantic:";
857 RemoveLinesFromSdp(kSdpMsidSupportedAttribute, sdp);
858 }
859 if (remove_bundle_) {
860 const char kSdpBundleAttribute[] = "a=group:BUNDLE";
861 RemoveLinesFromSdp(kSdpBundleAttribute, sdp);
862 }
863 if (remove_sdes_) {
864 const char kSdpSdesCryptoAttribute[] = "a=crypto";
865 RemoveLinesFromSdp(kSdpSdesCryptoAttribute, sdp);
866 }
867 }
868
869 private:
870 webrtc::FakeConstraints session_description_constraints_;
871 bool remove_msid_; // True if MSID should be removed in received SDP.
872 bool remove_bundle_; // True if bundle should be removed in received SDP.
873 bool remove_sdes_; // True if a=crypto should be removed in received SDP.
874
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000875 rtc::scoped_refptr<DataChannelInterface> data_channel_;
876 rtc::scoped_ptr<MockDataChannelObserver> data_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877};
878
879template <typename SignalingClass>
880class P2PTestConductor : public testing::Test {
881 public:
882 bool SessionActive() {
883 return initiating_client_->SessionActive() &&
884 receiving_client_->SessionActive();
885 }
886 // Return true if the number of frames provided have been received or it is
887 // known that that will never occur (e.g. no frames will be sent or
888 // captured).
889 bool FramesNotPending(int audio_frames_to_receive,
890 int video_frames_to_receive) {
891 return VideoFramesReceivedCheck(video_frames_to_receive) &&
892 AudioFramesReceivedCheck(audio_frames_to_receive);
893 }
894 bool AudioFramesReceivedCheck(int frames_received) {
895 return initiating_client_->AudioFramesReceivedCheck(frames_received) &&
896 receiving_client_->AudioFramesReceivedCheck(frames_received);
897 }
898 bool VideoFramesReceivedCheck(int frames_received) {
899 return initiating_client_->VideoFramesReceivedCheck(frames_received) &&
900 receiving_client_->VideoFramesReceivedCheck(frames_received);
901 }
902 void VerifyDtmf() {
903 initiating_client_->VerifyDtmf();
904 receiving_client_->VerifyDtmf();
905 }
906
907 void TestUpdateOfferWithRejectedContent() {
908 initiating_client_->Negotiate(true, false);
909 EXPECT_TRUE_WAIT(
910 FramesNotPending(kEndAudioFrameCount * 2, kEndVideoFrameCount),
911 kMaxWaitForFramesMs);
912 // There shouldn't be any more video frame after the new offer is
913 // negotiated.
914 EXPECT_FALSE(VideoFramesReceivedCheck(kEndVideoFrameCount + 1));
915 }
916
917 void VerifyRenderedSize(int width, int height) {
918 EXPECT_EQ(width, receiving_client()->rendered_width());
919 EXPECT_EQ(height, receiving_client()->rendered_height());
920 EXPECT_EQ(width, initializing_client()->rendered_width());
921 EXPECT_EQ(height, initializing_client()->rendered_height());
922 }
923
924 void VerifySessionDescriptions() {
925 initiating_client_->VerifyRejectedMediaInSessionDescription();
926 receiving_client_->VerifyRejectedMediaInSessionDescription();
927 initiating_client_->VerifyLocalIceUfragAndPassword();
928 receiving_client_->VerifyLocalIceUfragAndPassword();
929 }
930
931 P2PTestConductor() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000932 rtc::InitializeSSL(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 }
934 ~P2PTestConductor() {
935 if (initiating_client_) {
936 initiating_client_->set_signaling_message_receiver(NULL);
937 }
938 if (receiving_client_) {
939 receiving_client_->set_signaling_message_receiver(NULL);
940 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000941 rtc::CleanupSSL();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 }
943
944 bool CreateTestClients() {
945 return CreateTestClients(NULL, NULL);
946 }
947
948 bool CreateTestClients(MediaConstraintsInterface* init_constraints,
949 MediaConstraintsInterface* recv_constraints) {
950 initiating_client_.reset(SignalingClass::CreateClient("Caller: ",
951 init_constraints));
952 receiving_client_.reset(SignalingClass::CreateClient("Callee: ",
953 recv_constraints));
954 if (!initiating_client_ || !receiving_client_) {
955 return false;
956 }
957 initiating_client_->set_signaling_message_receiver(receiving_client_.get());
958 receiving_client_->set_signaling_message_receiver(initiating_client_.get());
959 return true;
960 }
961
962 void SetVideoConstraints(const webrtc::FakeConstraints& init_constraints,
963 const webrtc::FakeConstraints& recv_constraints) {
964 initiating_client_->SetVideoConstraints(init_constraints);
965 receiving_client_->SetVideoConstraints(recv_constraints);
966 }
967
968 void EnableVideoDecoderFactory() {
969 initiating_client_->EnableVideoDecoderFactory();
970 receiving_client_->EnableVideoDecoderFactory();
971 }
972
973 // This test sets up a call between two parties. Both parties send static
974 // frames to each other. Once the test is finished the number of sent frames
975 // is compared to the number of received frames.
976 void LocalP2PTest() {
977 if (initiating_client_->NumberOfLocalMediaStreams() == 0) {
978 initiating_client_->AddMediaStream(true, true);
979 }
980 initiating_client_->Negotiate();
981 const int kMaxWaitForActivationMs = 5000;
982 // Assert true is used here since next tests are guaranteed to fail and
983 // would eat up 5 seconds.
984 ASSERT_TRUE_WAIT(SessionActive(), kMaxWaitForActivationMs);
985 VerifySessionDescriptions();
986
987
988 int audio_frame_count = kEndAudioFrameCount;
989 // TODO(ronghuawu): Add test to cover the case of sendonly and recvonly.
990 if (!initiating_client_->can_receive_audio() ||
991 !receiving_client_->can_receive_audio()) {
992 audio_frame_count = -1;
993 }
994 int video_frame_count = kEndVideoFrameCount;
995 if (!initiating_client_->can_receive_video() ||
996 !receiving_client_->can_receive_video()) {
997 video_frame_count = -1;
998 }
999
1000 if (audio_frame_count != -1 || video_frame_count != -1) {
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001001 // Audio or video is expected to flow, so both clients should reach the
1002 // Connected state, and the offerer (ICE controller) should proceed to
1003 // Completed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 // Note: These tests have been observed to fail under heavy load at
1005 // shorter timeouts, so they may be flaky.
1006 EXPECT_EQ_WAIT(
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001007 webrtc::PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 initiating_client_->ice_connection_state(),
1009 kMaxWaitForFramesMs);
1010 EXPECT_EQ_WAIT(
1011 webrtc::PeerConnectionInterface::kIceConnectionConnected,
1012 receiving_client_->ice_connection_state(),
1013 kMaxWaitForFramesMs);
1014 }
1015
1016 if (initiating_client_->can_receive_audio() ||
1017 initiating_client_->can_receive_video()) {
1018 // The initiating client can receive media, so it must produce candidates
1019 // that will serve as destinations for that media.
1020 // TODO(bemasc): Understand why the state is not already Complete here, as
1021 // seems to be the case for the receiving client. This may indicate a bug
1022 // in the ICE gathering system.
1023 EXPECT_NE(webrtc::PeerConnectionInterface::kIceGatheringNew,
1024 initiating_client_->ice_gathering_state());
1025 }
1026 if (receiving_client_->can_receive_audio() ||
1027 receiving_client_->can_receive_video()) {
1028 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
1029 receiving_client_->ice_gathering_state(),
1030 kMaxWaitForFramesMs);
1031 }
1032
1033 EXPECT_TRUE_WAIT(FramesNotPending(audio_frame_count, video_frame_count),
1034 kMaxWaitForFramesMs);
1035 }
1036
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001037 void SendRtpData(webrtc::DataChannelInterface* dc, const std::string& data) {
1038 // Messages may get lost on the unreliable DataChannel, so we send multiple
1039 // times to avoid test flakiness.
1040 static const size_t kSendAttempts = 5;
1041
1042 for (size_t i = 0; i < kSendAttempts; ++i) {
1043 dc->Send(DataBuffer(data));
1044 }
1045 }
1046
solenberg@webrtc.org6556a592014-08-25 14:35:40 +00001047 // Wait until 'size' bytes of audio has been seen by the receiver, on the
1048 // first audio stream.
1049 void WaitForAudioData(int size) {
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.org28e20752013-07-10 00:45:36 +00001069 SignalingClass* initializing_client() { return initiating_client_.get(); }
1070 SignalingClass* receiving_client() { return receiving_client_.get(); }
1071
1072 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001073 rtc::scoped_ptr<SignalingClass> initiating_client_;
1074 rtc::scoped_ptr<SignalingClass> receiving_client_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075};
1076typedef P2PTestConductor<JsepTestClient> JsepPeerConnectionP2PTestClient;
1077
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001078// 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.org28e20752013-07-10 00:45:36 +00001082// This test sets up a Jsep call between two parties and test Dtmf.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001083// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1084// See issue webrtc/2378.
1085TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 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.
1093TEST_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.org28654cb2013-07-22 21:07:49 +00001103 static_cast<double>(initializing_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 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.org28654cb2013-07-22 21:07:49 +00001109 static_cast<double>(receiving_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 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.
1118TEST_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.
1130TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001131 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 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.org19f27e62013-10-13 17:18:27 +00001140// This test sets up a audio call initially and then upgrades to audio/video,
1141// using DTLS.
mallinath@webrtc.org50bc5532013-10-21 17:58:35 +00001142TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsRenegotiate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001143 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001144 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.org28e20752013-07-10 00:45:36 +00001154// 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.
1157TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestOfferDtlsButNotSdes) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001158 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159 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.orga59696b2013-09-13 23:48:58 +00001170// BUG=https://code.google.com/p/webrtc/issues/detail?id=2288
1171TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestAnswerVideo) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172 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.orgc0b1a282013-08-23 14:32:21 +00001179TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestAnswerAudio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 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.
1187TEST_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.org688ed692014-05-14 18:26:09 +00001197// Disabled due to b/14955157.
1198TEST_F(JsepPeerConnectionP2PTestClient,
1199 DISABLED_UpdateOfferWithRejectedContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 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.org688ed692014-05-14 18:26:09 +00001207// Disabled due to b/14955157.
1208TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestWithoutMsid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 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
1223TEST_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.
1237TEST_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.
1256TEST_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.
1267TEST_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.
1289TEST_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.
1311TEST_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.org6c6f33b2014-06-12 21:05:19 +00001325
1326 SendRtpData(initializing_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
1328 kMaxWaitMs);
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001329
1330 SendRtpData(receiving_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 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.
1348TEST_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.orgb4c7b092014-08-25 12:11:58 +00001364
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001366 SendRtpData(initializing_client()->data_channel(), data);
1367
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 // Wait a while to allow the sent data to arrive before an observer is
1369 // registered..
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001370 rtc::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371
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.
1378TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestReceiverDoesntSupportData) {
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +00001379 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.org28e20752013-07-10 00:45:36 +00001388 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.
1397TEST_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.org9c16c392014-05-01 18:30:30 +00001413// This test sets up a Jsep call with SCTP DataChannel and verifies the
1414// negotiation is completed without error.
1415#ifdef HAVE_SCTP
1416TEST_F(JsepPeerConnectionP2PTestClient, CreateOfferWithSctpDataChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001417 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001418 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.org28e20752013-07-10 00:45:36 +00001427// 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.
1430TEST_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.orgda790082013-09-17 13:11:38 +00001480// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1481// See issue webrtc/2378.
1482TEST_F(JsepPeerConnectionP2PTestClient,
1483 DISABLED_LocalP2PTestWithVideoDecoderFactory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 ASSERT_TRUE(CreateTestClients());
1485 EnableVideoDecoderFactory();
1486 LocalP2PTest();
1487}
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001488
1489// Test receive bandwidth stats with only audio enabled at receiver.
1490TEST_F(JsepPeerConnectionP2PTestClient, ReceivedBweStatsAudio) {
1491 ASSERT_TRUE(CreateTestClients());
1492 receiving_client()->SetReceiveAudioVideo(true, false);
1493 LocalP2PTest();
1494
solenberg@webrtc.org6556a592014-08-25 14:35:40 +00001495 // Wait until we have received some audio data. Following REMB shoud be zero.
1496 WaitForAudioData(10000);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001497 EXPECT_EQ_WAIT(
1498 receiving_client()->GetAvailableReceivedBandwidthStats(), 0,
1499 kMaxWaitForRembMs);
1500}
1501
1502// Test receive bandwidth stats with combined BWE.
1503TEST_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.orgb4c7b092014-08-25 12:11:58 +00001518
solenberg@webrtc.org6556a592014-08-25 14:35:40 +00001519 // Halt video capturers, then run until we have gotten some audio. Following
1520 // REMB should be non-zero.
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001521 initializing_client()->StopVideoCapturers();
solenberg@webrtc.org6556a592014-08-25 14:35:40 +00001522 WaitForAudioData(10000);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001523 EXPECT_TRUE_WAIT(
solenberg@webrtc.org6556a592014-08-25 14:35:40 +00001524 receiving_client()->GetAvailableReceivedBandwidthStats() > 0,
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001525 kMaxWaitForRembMs);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001526}
1527
1528// Test receive bandwidth stats with 1 video, 3 audio streams but no combined
1529// BWE.
1530TEST_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.org6556a592014-08-25 14:35:40 +00001546 // Halt video capturers, then run until we have gotten some audio. Following
1547 // REMB should be zero.
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001548 initializing_client()->StopVideoCapturers();
solenberg@webrtc.org6556a592014-08-25 14:35:40 +00001549 WaitForAudioData(10000);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001550 EXPECT_EQ_WAIT(
1551 receiving_client()->GetAvailableReceivedBandwidthStats(), 0,
1552 kMaxWaitForRembMs);
1553}
1554
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001555#endif // if !defined(THREAD_SANITIZER)