blob: a001d757df850f5591e932720b6d390e8045873f [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
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 SignalingClass* initializing_client() { return initiating_client_.get(); }
1048 SignalingClass* receiving_client() { return receiving_client_.get(); }
1049
1050 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001051 rtc::scoped_ptr<SignalingClass> initiating_client_;
1052 rtc::scoped_ptr<SignalingClass> receiving_client_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053};
1054typedef P2PTestConductor<JsepTestClient> JsepPeerConnectionP2PTestClient;
1055
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001056// Disable for TSan v2, see
1057// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
1058#if !defined(THREAD_SANITIZER)
1059
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060// This test sets up a Jsep call between two parties and test Dtmf.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001061// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1062// See issue webrtc/2378.
1063TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 ASSERT_TRUE(CreateTestClients());
1065 LocalP2PTest();
1066 VerifyDtmf();
1067}
1068
1069// This test sets up a Jsep call between two parties and test that we can get a
1070// video aspect ratio of 16:9.
1071TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTest16To9) {
1072 ASSERT_TRUE(CreateTestClients());
1073 FakeConstraints constraint;
1074 double requested_ratio = 640.0/360;
1075 constraint.SetMandatoryMinAspectRatio(requested_ratio);
1076 SetVideoConstraints(constraint, constraint);
1077 LocalP2PTest();
1078
1079 ASSERT_LE(0, initializing_client()->rendered_height());
1080 double initiating_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001081 static_cast<double>(initializing_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 initializing_client()->rendered_height();
1083 EXPECT_LE(requested_ratio, initiating_video_ratio);
1084
1085 ASSERT_LE(0, receiving_client()->rendered_height());
1086 double receiving_video_ratio =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001087 static_cast<double>(receiving_client()->rendered_width()) /
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 receiving_client()->rendered_height();
1089 EXPECT_LE(requested_ratio, receiving_video_ratio);
1090}
1091
1092// This test sets up a Jsep call between two parties and test that the
1093// received video has a resolution of 1280*720.
1094// TODO(mallinath): Enable when
1095// http://code.google.com/p/webrtc/issues/detail?id=981 is fixed.
1096TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTest1280By720) {
1097 ASSERT_TRUE(CreateTestClients());
1098 FakeConstraints constraint;
1099 constraint.SetMandatoryMinWidth(1280);
1100 constraint.SetMandatoryMinHeight(720);
1101 SetVideoConstraints(constraint, constraint);
1102 LocalP2PTest();
1103 VerifyRenderedSize(1280, 720);
1104}
1105
1106// This test sets up a call between two endpoints that are configured to use
1107// DTLS key agreement. As a result, DTLS is negotiated and used for transport.
1108TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001109 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 FakeConstraints setup_constraints;
1111 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1112 true);
1113 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1114 LocalP2PTest();
1115 VerifyRenderedSize(640, 480);
1116}
1117
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001118// This test sets up a audio call initially and then upgrades to audio/video,
1119// using DTLS.
mallinath@webrtc.org50bc5532013-10-21 17:58:35 +00001120TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDtlsRenegotiate) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001121 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001122 FakeConstraints setup_constraints;
1123 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1124 true);
1125 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1126 receiving_client()->SetReceiveAudioVideo(true, false);
1127 LocalP2PTest();
1128 receiving_client()->SetReceiveAudioVideo(true, true);
1129 receiving_client()->Negotiate();
1130}
1131
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132// This test sets up a call between two endpoints that are configured to use
1133// DTLS key agreement. The offerer don't support SDES. As a result, DTLS is
1134// negotiated and used for transport.
1135TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestOfferDtlsButNotSdes) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001136 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 FakeConstraints setup_constraints;
1138 setup_constraints.AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
1139 true);
1140 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1141 receiving_client()->RemoveSdesCryptoFromReceivedSdp(true);
1142 LocalP2PTest();
1143 VerifyRenderedSize(640, 480);
1144}
1145
1146// This test sets up a Jsep call between two parties, and the callee only
1147// accept to receive video.
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00001148// BUG=https://code.google.com/p/webrtc/issues/detail?id=2288
1149TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestAnswerVideo) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150 ASSERT_TRUE(CreateTestClients());
1151 receiving_client()->SetReceiveAudioVideo(false, true);
1152 LocalP2PTest();
1153}
1154
1155// This test sets up a Jsep call between two parties, and the callee only
1156// accept to receive audio.
henrike@webrtc.orgc0b1a282013-08-23 14:32:21 +00001157TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestAnswerAudio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 ASSERT_TRUE(CreateTestClients());
1159 receiving_client()->SetReceiveAudioVideo(true, false);
1160 LocalP2PTest();
1161}
1162
1163// This test sets up a Jsep call between two parties, and the callee reject both
1164// audio and video.
1165TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestAnswerNone) {
1166 ASSERT_TRUE(CreateTestClients());
1167 receiving_client()->SetReceiveAudioVideo(false, false);
1168 LocalP2PTest();
1169}
1170
1171// This test sets up an audio and video call between two parties. After the call
1172// runs for a while (10 frames), the caller sends an update offer with video
1173// being rejected. Once the re-negotiation is done, the video flow should stop
1174// and the audio flow should continue.
buildbot@webrtc.org688ed692014-05-14 18:26:09 +00001175// Disabled due to b/14955157.
1176TEST_F(JsepPeerConnectionP2PTestClient,
1177 DISABLED_UpdateOfferWithRejectedContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001178 ASSERT_TRUE(CreateTestClients());
1179 LocalP2PTest();
1180 TestUpdateOfferWithRejectedContent();
1181}
1182
1183// This test sets up a Jsep call between two parties. The MSID is removed from
1184// the SDP strings from the caller.
buildbot@webrtc.org688ed692014-05-14 18:26:09 +00001185// Disabled due to b/14955157.
1186TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestWithoutMsid) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 ASSERT_TRUE(CreateTestClients());
1188 receiving_client()->RemoveMsidFromReceivedSdp(true);
1189 // TODO(perkj): Currently there is a bug that cause audio to stop playing if
1190 // audio and video is muxed when MSID is disabled. Remove
1191 // SetRemoveBundleFromSdp once
1192 // https://code.google.com/p/webrtc/issues/detail?id=1193 is fixed.
1193 receiving_client()->RemoveBundleFromReceivedSdp(true);
1194 LocalP2PTest();
1195}
1196
1197// This test sets up a Jsep call between two parties and the initiating peer
1198// sends two steams.
1199// TODO(perkj): Disabled due to
1200// https://code.google.com/p/webrtc/issues/detail?id=1454
1201TEST_F(JsepPeerConnectionP2PTestClient, DISABLED_LocalP2PTestTwoStreams) {
1202 ASSERT_TRUE(CreateTestClients());
1203 // Set optional video constraint to max 320pixels to decrease CPU usage.
1204 FakeConstraints constraint;
1205 constraint.SetOptionalMaxWidth(320);
1206 SetVideoConstraints(constraint, constraint);
1207 initializing_client()->AddMediaStream(true, true);
1208 initializing_client()->AddMediaStream(false, true);
1209 ASSERT_EQ(2u, initializing_client()->NumberOfLocalMediaStreams());
1210 LocalP2PTest();
1211 EXPECT_EQ(2u, receiving_client()->number_of_remote_streams());
1212}
1213
1214// Test that we can receive the audio output level from a remote audio track.
1215TEST_F(JsepPeerConnectionP2PTestClient, GetAudioOutputLevelStats) {
1216 ASSERT_TRUE(CreateTestClients());
1217 LocalP2PTest();
1218
1219 StreamCollectionInterface* remote_streams =
1220 initializing_client()->remote_streams();
1221 ASSERT_GT(remote_streams->count(), 0u);
1222 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1223 MediaStreamTrackInterface* remote_audio_track =
1224 remote_streams->at(0)->GetAudioTracks()[0];
1225
1226 // Get the audio output level stats. Note that the level is not available
1227 // until a RTCP packet has been received.
1228 EXPECT_TRUE_WAIT(
1229 initializing_client()->GetAudioOutputLevelStats(remote_audio_track) > 0,
1230 kMaxWaitForStatsMs);
1231}
1232
1233// Test that an audio input level is reported.
1234TEST_F(JsepPeerConnectionP2PTestClient, GetAudioInputLevelStats) {
1235 ASSERT_TRUE(CreateTestClients());
1236 LocalP2PTest();
1237
1238 // Get the audio input level stats. The level should be available very
1239 // soon after the test starts.
1240 EXPECT_TRUE_WAIT(initializing_client()->GetAudioInputLevelStats() > 0,
1241 kMaxWaitForStatsMs);
1242}
1243
1244// Test that we can get incoming byte counts from both audio and video tracks.
1245TEST_F(JsepPeerConnectionP2PTestClient, GetBytesReceivedStats) {
1246 ASSERT_TRUE(CreateTestClients());
1247 LocalP2PTest();
1248
1249 StreamCollectionInterface* remote_streams =
1250 initializing_client()->remote_streams();
1251 ASSERT_GT(remote_streams->count(), 0u);
1252 ASSERT_GT(remote_streams->at(0)->GetAudioTracks().size(), 0u);
1253 MediaStreamTrackInterface* remote_audio_track =
1254 remote_streams->at(0)->GetAudioTracks()[0];
1255 EXPECT_TRUE_WAIT(
1256 initializing_client()->GetBytesReceivedStats(remote_audio_track) > 0,
1257 kMaxWaitForStatsMs);
1258
1259 MediaStreamTrackInterface* remote_video_track =
1260 remote_streams->at(0)->GetVideoTracks()[0];
1261 EXPECT_TRUE_WAIT(
1262 initializing_client()->GetBytesReceivedStats(remote_video_track) > 0,
1263 kMaxWaitForStatsMs);
1264}
1265
1266// Test that we can get outgoing byte counts from both audio and video tracks.
1267TEST_F(JsepPeerConnectionP2PTestClient, GetBytesSentStats) {
1268 ASSERT_TRUE(CreateTestClients());
1269 LocalP2PTest();
1270
1271 StreamCollectionInterface* local_streams =
1272 initializing_client()->local_streams();
1273 ASSERT_GT(local_streams->count(), 0u);
1274 ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u);
1275 MediaStreamTrackInterface* local_audio_track =
1276 local_streams->at(0)->GetAudioTracks()[0];
1277 EXPECT_TRUE_WAIT(
1278 initializing_client()->GetBytesSentStats(local_audio_track) > 0,
1279 kMaxWaitForStatsMs);
1280
1281 MediaStreamTrackInterface* local_video_track =
1282 local_streams->at(0)->GetVideoTracks()[0];
1283 EXPECT_TRUE_WAIT(
1284 initializing_client()->GetBytesSentStats(local_video_track) > 0,
1285 kMaxWaitForStatsMs);
1286}
1287
1288// This test sets up a call between two parties with audio, video and data.
1289TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestDataChannel) {
1290 FakeConstraints setup_constraints;
1291 setup_constraints.SetAllowRtpDataChannels();
1292 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1293 initializing_client()->CreateDataChannel();
1294 LocalP2PTest();
1295 ASSERT_TRUE(initializing_client()->data_channel() != NULL);
1296 ASSERT_TRUE(receiving_client()->data_channel() != NULL);
1297 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1298 kMaxWaitMs);
1299 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1300 kMaxWaitMs);
1301
1302 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001303
1304 SendRtpData(initializing_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 EXPECT_EQ_WAIT(data, receiving_client()->data_observer()->last_message(),
1306 kMaxWaitMs);
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001307
1308 SendRtpData(receiving_client()->data_channel(), data);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 EXPECT_EQ_WAIT(data, initializing_client()->data_observer()->last_message(),
1310 kMaxWaitMs);
1311
1312 receiving_client()->data_channel()->Close();
1313 // Send new offer and answer.
1314 receiving_client()->Negotiate();
1315 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1316 EXPECT_FALSE(receiving_client()->data_observer()->IsOpen());
1317}
1318
1319// This test sets up a call between two parties and creates a data channel.
1320// The test tests that received data is buffered unless an observer has been
1321// registered.
1322// Rtp data channels can receive data before the underlying
1323// transport has detected that a channel is writable and thus data can be
1324// received before the data channel state changes to open. That is hard to test
1325// but the same buffering is used in that case.
1326TEST_F(JsepPeerConnectionP2PTestClient, RegisterDataChannelObserver) {
1327 FakeConstraints setup_constraints;
1328 setup_constraints.SetAllowRtpDataChannels();
1329 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1330 initializing_client()->CreateDataChannel();
1331 initializing_client()->Negotiate();
1332
1333 ASSERT_TRUE(initializing_client()->data_channel() != NULL);
1334 ASSERT_TRUE(receiving_client()->data_channel() != NULL);
1335 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1336 kMaxWaitMs);
1337 EXPECT_EQ_WAIT(DataChannelInterface::kOpen,
1338 receiving_client()->data_channel()->state(), kMaxWaitMs);
1339
1340 // Unregister the existing observer.
1341 receiving_client()->data_channel()->UnregisterObserver();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001342
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 std::string data = "hello world";
jiayl@webrtc.org6c6f33b2014-06-12 21:05:19 +00001344 SendRtpData(initializing_client()->data_channel(), data);
1345
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 // Wait a while to allow the sent data to arrive before an observer is
1347 // registered..
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001348 rtc::Thread::Current()->ProcessMessages(100);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349
1350 MockDataChannelObserver new_observer(receiving_client()->data_channel());
1351 EXPECT_EQ_WAIT(data, new_observer.last_message(), kMaxWaitMs);
1352}
1353
1354// This test sets up a call between two parties with audio, video and but only
1355// the initiating client support data.
1356TEST_F(JsepPeerConnectionP2PTestClient, LocalP2PTestReceiverDoesntSupportData) {
buildbot@webrtc.org61c1b8e2014-04-09 06:06:38 +00001357 FakeConstraints setup_constraints_1;
1358 setup_constraints_1.SetAllowRtpDataChannels();
1359 // Must disable DTLS to make negotiation succeed.
1360 setup_constraints_1.SetMandatory(
1361 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1362 FakeConstraints setup_constraints_2;
1363 setup_constraints_2.SetMandatory(
1364 MediaConstraintsInterface::kEnableDtlsSrtp, false);
1365 ASSERT_TRUE(CreateTestClients(&setup_constraints_1, &setup_constraints_2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366 initializing_client()->CreateDataChannel();
1367 LocalP2PTest();
1368 EXPECT_TRUE(initializing_client()->data_channel() != NULL);
1369 EXPECT_FALSE(receiving_client()->data_channel());
1370 EXPECT_FALSE(initializing_client()->data_observer()->IsOpen());
1371}
1372
1373// This test sets up a call between two parties with audio, video. When audio
1374// and video is setup and flowing and data channel is negotiated.
1375TEST_F(JsepPeerConnectionP2PTestClient, AddDataChannelAfterRenegotiation) {
1376 FakeConstraints setup_constraints;
1377 setup_constraints.SetAllowRtpDataChannels();
1378 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1379 LocalP2PTest();
1380 initializing_client()->CreateDataChannel();
1381 // Send new offer and answer.
1382 initializing_client()->Negotiate();
1383 ASSERT_TRUE(initializing_client()->data_channel() != NULL);
1384 ASSERT_TRUE(receiving_client()->data_channel() != NULL);
1385 EXPECT_TRUE_WAIT(initializing_client()->data_observer()->IsOpen(),
1386 kMaxWaitMs);
1387 EXPECT_TRUE_WAIT(receiving_client()->data_observer()->IsOpen(),
1388 kMaxWaitMs);
1389}
1390
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001391// This test sets up a Jsep call with SCTP DataChannel and verifies the
1392// negotiation is completed without error.
1393#ifdef HAVE_SCTP
1394TEST_F(JsepPeerConnectionP2PTestClient, CreateOfferWithSctpDataChannel) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001395 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.org9c16c392014-05-01 18:30:30 +00001396 FakeConstraints constraints;
1397 constraints.SetMandatory(
1398 MediaConstraintsInterface::kEnableDtlsSrtp, true);
1399 ASSERT_TRUE(CreateTestClients(&constraints, &constraints));
1400 initializing_client()->CreateDataChannel();
1401 initializing_client()->Negotiate(false, false);
1402}
1403#endif
1404
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405// This test sets up a call between two parties with audio, and video.
1406// During the call, the initializing side restart ice and the test verifies that
1407// new ice candidates are generated and audio and video still can flow.
1408TEST_F(JsepPeerConnectionP2PTestClient, IceRestart) {
1409 ASSERT_TRUE(CreateTestClients());
1410
1411 // Negotiate and wait for ice completion and make sure audio and video plays.
1412 LocalP2PTest();
1413
1414 // Create a SDP string of the first audio candidate for both clients.
1415 const webrtc::IceCandidateCollection* audio_candidates_initiator =
1416 initializing_client()->pc()->local_description()->candidates(0);
1417 const webrtc::IceCandidateCollection* audio_candidates_receiver =
1418 receiving_client()->pc()->local_description()->candidates(0);
1419 ASSERT_GT(audio_candidates_initiator->count(), 0u);
1420 ASSERT_GT(audio_candidates_receiver->count(), 0u);
1421 std::string initiator_candidate;
1422 EXPECT_TRUE(
1423 audio_candidates_initiator->at(0)->ToString(&initiator_candidate));
1424 std::string receiver_candidate;
1425 EXPECT_TRUE(audio_candidates_receiver->at(0)->ToString(&receiver_candidate));
1426
1427 // Restart ice on the initializing client.
1428 receiving_client()->SetExpectIceRestart(true);
1429 initializing_client()->IceRestart();
1430
1431 // Negotiate and wait for ice completion again and make sure audio and video
1432 // plays.
1433 LocalP2PTest();
1434
1435 // Create a SDP string of the first audio candidate for both clients again.
1436 const webrtc::IceCandidateCollection* audio_candidates_initiator_restart =
1437 initializing_client()->pc()->local_description()->candidates(0);
1438 const webrtc::IceCandidateCollection* audio_candidates_reciever_restart =
1439 receiving_client()->pc()->local_description()->candidates(0);
1440 ASSERT_GT(audio_candidates_initiator_restart->count(), 0u);
1441 ASSERT_GT(audio_candidates_reciever_restart->count(), 0u);
1442 std::string initiator_candidate_restart;
1443 EXPECT_TRUE(audio_candidates_initiator_restart->at(0)->ToString(
1444 &initiator_candidate_restart));
1445 std::string receiver_candidate_restart;
1446 EXPECT_TRUE(audio_candidates_reciever_restart->at(0)->ToString(
1447 &receiver_candidate_restart));
1448
1449 // Verify that the first candidates in the local session descriptions has
1450 // changed.
1451 EXPECT_NE(initiator_candidate, initiator_candidate_restart);
1452 EXPECT_NE(receiver_candidate, receiver_candidate_restart);
1453}
1454
1455
1456// This test sets up a Jsep call between two parties with external
1457// VideoDecoderFactory.
stefan@webrtc.orgda790082013-09-17 13:11:38 +00001458// TODO(holmer): Disabled due to sometimes crashing on buildbots.
1459// See issue webrtc/2378.
1460TEST_F(JsepPeerConnectionP2PTestClient,
1461 DISABLED_LocalP2PTestWithVideoDecoderFactory) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 ASSERT_TRUE(CreateTestClients());
1463 EnableVideoDecoderFactory();
1464 LocalP2PTest();
1465}
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00001466
1467// Test receive bandwidth stats with only audio enabled at receiver.
1468TEST_F(JsepPeerConnectionP2PTestClient, ReceivedBweStatsAudio) {
1469 ASSERT_TRUE(CreateTestClients());
1470 receiving_client()->SetReceiveAudioVideo(true, false);
1471 LocalP2PTest();
1472
1473 // Wait until we have received some audio data.
1474 StreamCollectionInterface* local_streams =
1475 initializing_client()->local_streams();
1476 ASSERT_GT(local_streams->count(), 0u);
1477 ASSERT_GT(local_streams->at(0)->GetAudioTracks().size(), 0u);
1478 MediaStreamTrackInterface* local_audio_track =
1479 local_streams->at(0)->GetAudioTracks()[0];
1480 EXPECT_TRUE_WAIT(
1481 receiving_client()->GetBytesReceivedStats(local_audio_track) > 10000,
1482 kMaxWaitForAudioDataMs);
1483
1484 // Then wait for REMB.
1485 EXPECT_EQ_WAIT(
1486 receiving_client()->GetAvailableReceivedBandwidthStats(), 0,
1487 kMaxWaitForRembMs);
1488}
1489
1490// Test receive bandwidth stats with combined BWE.
1491TEST_F(JsepPeerConnectionP2PTestClient, ReceivedBweStatsCombined) {
1492 FakeConstraints setup_constraints;
1493 setup_constraints.AddOptional(
1494 MediaConstraintsInterface::kCombinedAudioVideoBwe, true);
1495 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1496 initializing_client()->AddMediaStream(true, true);
1497 initializing_client()->AddMediaStream(false, true);
1498 initializing_client()->AddMediaStream(false, true);
1499 initializing_client()->AddMediaStream(false, true);
1500 LocalP2PTest();
1501
1502 // Run until a non-zero bw is reported.
1503 EXPECT_TRUE_WAIT(
1504 receiving_client()->GetAvailableReceivedBandwidthStats() > 40000,
1505 kMaxWaitForRembMs);
1506 int video_bw = receiving_client()->GetAvailableReceivedBandwidthStats();
1507
1508 // Halt video capturers, then run until we get a new non-zero bw which is
1509 // lower than the previous value.
1510 initializing_client()->StopVideoCapturers();
1511 EXPECT_TRUE_WAIT(
1512 receiving_client()->GetAvailableReceivedBandwidthStats() < video_bw,
1513 kMaxWaitForRembMs);
1514 EXPECT_GT(receiving_client()->GetAvailableReceivedBandwidthStats(), 0);
1515}
1516
1517// Test receive bandwidth stats with 1 video, 3 audio streams but no combined
1518// BWE.
1519TEST_F(JsepPeerConnectionP2PTestClient, ReceivedBweStatsNotCombined) {
1520 FakeConstraints setup_constraints;
1521 setup_constraints.AddOptional(
1522 MediaConstraintsInterface::kCombinedAudioVideoBwe, false);
1523 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1524 initializing_client()->AddMediaStream(true, true);
1525 initializing_client()->AddMediaStream(false, true);
1526 initializing_client()->AddMediaStream(false, true);
1527 initializing_client()->AddMediaStream(false, true);
1528 LocalP2PTest();
1529
1530 // Run until a non-zero bw is reported.
1531 EXPECT_TRUE_WAIT(
1532 receiving_client()->GetAvailableReceivedBandwidthStats() > 40000,
1533 kMaxWaitForRembMs);
1534
1535 // Halt video capturers, then run until we get a new bw which is zero.
1536 initializing_client()->StopVideoCapturers();
1537 EXPECT_EQ_WAIT(
1538 receiving_client()->GetAvailableReceivedBandwidthStats(), 0,
1539 kMaxWaitForRembMs);
1540}
1541
kjellander@webrtc.orgd1cfa712013-10-16 16:51:52 +00001542#endif // if !defined(THREAD_SANITIZER)