blob: 580bfd44678a1a5888a0be639c2dc2e840fccc8a [file] [log] [blame]
deadbeef1dcb1642017-03-29 21:08:16 -07001/*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11// Disable for TSan v2, see
12// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
13#if !defined(THREAD_SANITIZER)
14
15#include <stdio.h>
16
17#include <algorithm>
18#include <functional>
19#include <list>
20#include <map>
21#include <memory>
22#include <utility>
23#include <vector>
24
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020025#include "api/fakemetricsobserver.h"
26#include "api/mediastreaminterface.h"
27#include "api/peerconnectioninterface.h"
Steve Anton8c0f7a72017-10-03 10:03:10 -070028#include "api/peerconnectionproxy.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "api/test/fakeconstraints.h"
30#include "media/engine/fakewebrtcvideoengine.h"
31#include "p2p/base/p2pconstants.h"
32#include "p2p/base/portinterface.h"
33#include "p2p/base/sessiondescription.h"
Jonas Orelandbdcee282017-10-10 14:01:40 +020034#include "p2p/base/testturncustomizer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020035#include "p2p/base/testturnserver.h"
36#include "p2p/client/basicportallocator.h"
37#include "pc/dtmfsender.h"
38#include "pc/localaudiosource.h"
39#include "pc/mediasession.h"
40#include "pc/peerconnection.h"
41#include "pc/peerconnectionfactory.h"
42#include "pc/test/fakeaudiocapturemodule.h"
43#include "pc/test/fakeperiodicvideocapturer.h"
44#include "pc/test/fakertccertificategenerator.h"
45#include "pc/test/fakevideotrackrenderer.h"
46#include "pc/test/mockpeerconnectionobservers.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020047#include "rtc_base/fakenetwork.h"
48#include "rtc_base/gunit.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020049#include "rtc_base/virtualsocketserver.h"
deadbeef1dcb1642017-03-29 21:08:16 -070050
51using cricket::ContentInfo;
52using cricket::FakeWebRtcVideoDecoder;
53using cricket::FakeWebRtcVideoDecoderFactory;
54using cricket::FakeWebRtcVideoEncoder;
55using cricket::FakeWebRtcVideoEncoderFactory;
56using cricket::MediaContentDescription;
57using webrtc::DataBuffer;
58using webrtc::DataChannelInterface;
59using webrtc::DtmfSender;
60using webrtc::DtmfSenderInterface;
61using webrtc::DtmfSenderObserverInterface;
62using webrtc::FakeConstraints;
63using webrtc::MediaConstraintsInterface;
64using webrtc::MediaStreamInterface;
65using webrtc::MediaStreamTrackInterface;
66using webrtc::MockCreateSessionDescriptionObserver;
67using webrtc::MockDataChannelObserver;
68using webrtc::MockSetSessionDescriptionObserver;
69using webrtc::MockStatsObserver;
70using webrtc::ObserverInterface;
Steve Anton8c0f7a72017-10-03 10:03:10 -070071using webrtc::PeerConnection;
deadbeef1dcb1642017-03-29 21:08:16 -070072using webrtc::PeerConnectionInterface;
73using webrtc::PeerConnectionFactory;
Steve Anton8c0f7a72017-10-03 10:03:10 -070074using webrtc::PeerConnectionProxy;
deadbeef1dcb1642017-03-29 21:08:16 -070075using webrtc::SessionDescriptionInterface;
76using webrtc::StreamCollectionInterface;
77
78namespace {
79
80static const int kDefaultTimeout = 10000;
81static const int kMaxWaitForStatsMs = 3000;
82static const int kMaxWaitForActivationMs = 5000;
83static const int kMaxWaitForFramesMs = 10000;
84// Default number of audio/video frames to wait for before considering a test
85// successful.
86static const int kDefaultExpectedAudioFrameCount = 3;
87static const int kDefaultExpectedVideoFrameCount = 3;
88
deadbeef1dcb1642017-03-29 21:08:16 -070089static const char kDataChannelLabel[] = "data_channel";
90
91// SRTP cipher name negotiated by the tests. This must be updated if the
92// default changes.
93static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
94static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
95
96// Helper function for constructing offer/answer options to initiate an ICE
97// restart.
98PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() {
99 PeerConnectionInterface::RTCOfferAnswerOptions options;
100 options.ice_restart = true;
101 return options;
102}
103
deadbeefd8ad7882017-04-18 16:01:17 -0700104// Remove all stream information (SSRCs, track IDs, etc.) and "msid-semantic"
105// attribute from received SDP, simulating a legacy endpoint.
106void RemoveSsrcsAndMsids(cricket::SessionDescription* desc) {
107 for (ContentInfo& content : desc->contents()) {
108 MediaContentDescription* media_desc =
109 static_cast<MediaContentDescription*>(content.description);
110 media_desc->mutable_streams().clear();
111 }
112 desc->set_msid_supported(false);
113}
114
zhihuangf8164932017-05-19 13:09:47 -0700115int FindFirstMediaStatsIndexByKind(
116 const std::string& kind,
117 const std::vector<const webrtc::RTCMediaStreamTrackStats*>&
118 media_stats_vec) {
119 for (size_t i = 0; i < media_stats_vec.size(); i++) {
120 if (media_stats_vec[i]->kind.ValueToString() == kind) {
121 return i;
122 }
123 }
124 return -1;
125}
126
deadbeef1dcb1642017-03-29 21:08:16 -0700127class SignalingMessageReceiver {
128 public:
129 virtual void ReceiveSdpMessage(const std::string& type,
130 const std::string& msg) = 0;
131 virtual void ReceiveIceMessage(const std::string& sdp_mid,
132 int sdp_mline_index,
133 const std::string& msg) = 0;
134
135 protected:
136 SignalingMessageReceiver() {}
137 virtual ~SignalingMessageReceiver() {}
138};
139
140class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface {
141 public:
142 explicit MockRtpReceiverObserver(cricket::MediaType media_type)
143 : expected_media_type_(media_type) {}
144
145 void OnFirstPacketReceived(cricket::MediaType media_type) override {
146 ASSERT_EQ(expected_media_type_, media_type);
147 first_packet_received_ = true;
148 }
149
150 bool first_packet_received() const { return first_packet_received_; }
151
152 virtual ~MockRtpReceiverObserver() {}
153
154 private:
155 bool first_packet_received_ = false;
156 cricket::MediaType expected_media_type_;
157};
158
159// Helper class that wraps a peer connection, observes it, and can accept
160// signaling messages from another wrapper.
161//
162// Uses a fake network, fake A/V capture, and optionally fake
163// encoders/decoders, though they aren't used by default since they don't
164// advertise support of any codecs.
Steve Anton94286cb2017-09-26 16:20:19 -0700165// TODO(steveanton): See how this could become a subclass of
166// PeerConnectionWrapper defined in peerconnectionwrapper.h .
deadbeef1dcb1642017-03-29 21:08:16 -0700167class PeerConnectionWrapper : public webrtc::PeerConnectionObserver,
168 public SignalingMessageReceiver,
169 public ObserverInterface {
170 public:
171 // Different factory methods for convenience.
172 // TODO(deadbeef): Could use the pattern of:
173 //
174 // PeerConnectionWrapper =
175 // WrapperBuilder.WithConfig(...).WithOptions(...).build();
176 //
177 // To reduce some code duplication.
178 static PeerConnectionWrapper* CreateWithDtlsIdentityStore(
179 const std::string& debug_name,
180 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
181 rtc::Thread* network_thread,
182 rtc::Thread* worker_thread) {
183 PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name));
184 if (!client->Init(nullptr, nullptr, nullptr, std::move(cert_generator),
185 network_thread, worker_thread)) {
186 delete client;
187 return nullptr;
188 }
189 return client;
190 }
191
192 static PeerConnectionWrapper* CreateWithConfig(
193 const std::string& debug_name,
194 const PeerConnectionInterface::RTCConfiguration& config,
195 rtc::Thread* network_thread,
196 rtc::Thread* worker_thread) {
197 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
198 new FakeRTCCertificateGenerator());
199 PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name));
200 if (!client->Init(nullptr, nullptr, &config, std::move(cert_generator),
201 network_thread, worker_thread)) {
202 delete client;
203 return nullptr;
204 }
205 return client;
206 }
207
208 static PeerConnectionWrapper* CreateWithOptions(
209 const std::string& debug_name,
210 const PeerConnectionFactory::Options& options,
211 rtc::Thread* network_thread,
212 rtc::Thread* worker_thread) {
213 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
214 new FakeRTCCertificateGenerator());
215 PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name));
216 if (!client->Init(nullptr, &options, nullptr, std::move(cert_generator),
217 network_thread, worker_thread)) {
218 delete client;
219 return nullptr;
220 }
221 return client;
222 }
223
224 static PeerConnectionWrapper* CreateWithConstraints(
225 const std::string& debug_name,
226 const MediaConstraintsInterface* constraints,
227 rtc::Thread* network_thread,
228 rtc::Thread* worker_thread) {
229 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
230 new FakeRTCCertificateGenerator());
231 PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name));
232 if (!client->Init(constraints, nullptr, nullptr, std::move(cert_generator),
233 network_thread, worker_thread)) {
234 delete client;
235 return nullptr;
236 }
237 return client;
238 }
239
deadbeef2f425aa2017-04-14 10:41:32 -0700240 webrtc::PeerConnectionFactoryInterface* pc_factory() const {
241 return peer_connection_factory_.get();
242 }
243
deadbeef1dcb1642017-03-29 21:08:16 -0700244 webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); }
245
246 // If a signaling message receiver is set (via ConnectFakeSignaling), this
247 // will set the whole offer/answer exchange in motion. Just need to wait for
248 // the signaling state to reach "stable".
249 void CreateAndSetAndSignalOffer() {
250 auto offer = CreateOffer();
251 ASSERT_NE(nullptr, offer);
252 EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(offer)));
253 }
254
255 // Sets the options to be used when CreateAndSetAndSignalOffer is called, or
256 // when a remote offer is received (via fake signaling) and an answer is
257 // generated. By default, uses default options.
258 void SetOfferAnswerOptions(
259 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
260 offer_answer_options_ = options;
261 }
262
263 // Set a callback to be invoked when SDP is received via the fake signaling
264 // channel, which provides an opportunity to munge (modify) the SDP. This is
265 // used to test SDP being applied that a PeerConnection would normally not
266 // generate, but a non-JSEP endpoint might.
267 void SetReceivedSdpMunger(
268 std::function<void(cricket::SessionDescription*)> munger) {
269 received_sdp_munger_ = munger;
270 }
271
deadbeefc964d0b2017-04-03 10:03:35 -0700272 // Similar to the above, but this is run on SDP immediately after it's
deadbeef1dcb1642017-03-29 21:08:16 -0700273 // generated.
274 void SetGeneratedSdpMunger(
275 std::function<void(cricket::SessionDescription*)> munger) {
276 generated_sdp_munger_ = munger;
277 }
278
279 // Number of times the gathering state has transitioned to "gathering".
280 // Useful for telling if an ICE restart occurred as expected.
281 int transitions_to_gathering_state() const {
282 return transitions_to_gathering_state_;
283 }
284
285 // TODO(deadbeef): Switch the majority of these tests to use AddTrack instead
286 // of AddStream since AddStream is deprecated.
287 void AddAudioVideoMediaStream() {
288 AddMediaStreamFromTracks(CreateLocalAudioTrack(), CreateLocalVideoTrack());
289 }
290
291 void AddAudioOnlyMediaStream() {
292 AddMediaStreamFromTracks(CreateLocalAudioTrack(), nullptr);
293 }
294
295 void AddVideoOnlyMediaStream() {
296 AddMediaStreamFromTracks(nullptr, CreateLocalVideoTrack());
297 }
298
299 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack() {
300 FakeConstraints constraints;
301 // Disable highpass filter so that we can get all the test audio frames.
302 constraints.AddMandatory(MediaConstraintsInterface::kHighpassFilter, false);
303 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
304 peer_connection_factory_->CreateAudioSource(&constraints);
305 // TODO(perkj): Test audio source when it is implemented. Currently audio
306 // always use the default input.
deadbeefb1a15d72017-09-07 14:12:05 -0700307 return peer_connection_factory_->CreateAudioTrack(rtc::CreateRandomUuid(),
deadbeef1dcb1642017-03-29 21:08:16 -0700308 source);
309 }
310
311 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack() {
deadbeefb1a15d72017-09-07 14:12:05 -0700312 return CreateLocalVideoTrackInternal(FakeConstraints(),
313 webrtc::kVideoRotation_0);
deadbeef1dcb1642017-03-29 21:08:16 -0700314 }
315
316 rtc::scoped_refptr<webrtc::VideoTrackInterface>
317 CreateLocalVideoTrackWithConstraints(const FakeConstraints& constraints) {
deadbeefb1a15d72017-09-07 14:12:05 -0700318 return CreateLocalVideoTrackInternal(constraints, webrtc::kVideoRotation_0);
deadbeef1dcb1642017-03-29 21:08:16 -0700319 }
320
321 rtc::scoped_refptr<webrtc::VideoTrackInterface>
322 CreateLocalVideoTrackWithRotation(webrtc::VideoRotation rotation) {
deadbeefb1a15d72017-09-07 14:12:05 -0700323 return CreateLocalVideoTrackInternal(FakeConstraints(), rotation);
deadbeef1dcb1642017-03-29 21:08:16 -0700324 }
325
326 void AddMediaStreamFromTracks(
327 rtc::scoped_refptr<webrtc::AudioTrackInterface> audio,
328 rtc::scoped_refptr<webrtc::VideoTrackInterface> video) {
deadbeef1dcb1642017-03-29 21:08:16 -0700329 rtc::scoped_refptr<MediaStreamInterface> stream =
deadbeefb1a15d72017-09-07 14:12:05 -0700330 peer_connection_factory_->CreateLocalMediaStream(
331 rtc::CreateRandomUuid());
deadbeef1dcb1642017-03-29 21:08:16 -0700332 if (audio) {
333 stream->AddTrack(audio);
334 }
335 if (video) {
336 stream->AddTrack(video);
337 }
338 EXPECT_TRUE(pc()->AddStream(stream));
339 }
340
341 bool SignalingStateStable() {
342 return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable;
343 }
344
345 void CreateDataChannel() { CreateDataChannel(nullptr); }
346
347 void CreateDataChannel(const webrtc::DataChannelInit* init) {
348 data_channel_ = pc()->CreateDataChannel(kDataChannelLabel, init);
349 ASSERT_TRUE(data_channel_.get() != nullptr);
350 data_observer_.reset(new MockDataChannelObserver(data_channel_));
351 }
352
353 DataChannelInterface* data_channel() { return data_channel_; }
354 const MockDataChannelObserver* data_observer() const {
355 return data_observer_.get();
356 }
357
358 int audio_frames_received() const {
359 return fake_audio_capture_module_->frames_received();
360 }
361
362 // Takes minimum of video frames received for each track.
363 //
364 // Can be used like:
365 // EXPECT_GE(expected_frames, min_video_frames_received_per_track());
366 //
367 // To ensure that all video tracks received at least a certain number of
368 // frames.
369 int min_video_frames_received_per_track() const {
370 int min_frames = INT_MAX;
371 if (video_decoder_factory_enabled_) {
372 const std::vector<FakeWebRtcVideoDecoder*>& decoders =
373 fake_video_decoder_factory_->decoders();
374 if (decoders.empty()) {
375 return 0;
376 }
377 for (FakeWebRtcVideoDecoder* decoder : decoders) {
378 min_frames = std::min(min_frames, decoder->GetNumFramesReceived());
379 }
380 return min_frames;
381 } else {
382 if (fake_video_renderers_.empty()) {
383 return 0;
384 }
385
386 for (const auto& pair : fake_video_renderers_) {
387 min_frames = std::min(min_frames, pair.second->num_rendered_frames());
388 }
389 return min_frames;
390 }
391 }
392
393 // In contrast to the above, sums the video frames received for all tracks.
394 // Can be used to verify that no video frames were received, or that the
395 // counts didn't increase.
396 int total_video_frames_received() const {
397 int total = 0;
398 if (video_decoder_factory_enabled_) {
399 const std::vector<FakeWebRtcVideoDecoder*>& decoders =
400 fake_video_decoder_factory_->decoders();
401 for (const FakeWebRtcVideoDecoder* decoder : decoders) {
402 total += decoder->GetNumFramesReceived();
403 }
404 } else {
405 for (const auto& pair : fake_video_renderers_) {
406 total += pair.second->num_rendered_frames();
407 }
408 for (const auto& renderer : removed_fake_video_renderers_) {
409 total += renderer->num_rendered_frames();
410 }
411 }
412 return total;
413 }
414
415 // Returns a MockStatsObserver in a state after stats gathering finished,
416 // which can be used to access the gathered stats.
deadbeefd8ad7882017-04-18 16:01:17 -0700417 rtc::scoped_refptr<MockStatsObserver> OldGetStatsForTrack(
deadbeef1dcb1642017-03-29 21:08:16 -0700418 webrtc::MediaStreamTrackInterface* track) {
419 rtc::scoped_refptr<MockStatsObserver> observer(
420 new rtc::RefCountedObject<MockStatsObserver>());
421 EXPECT_TRUE(peer_connection_->GetStats(
422 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
423 EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
424 return observer;
425 }
426
427 // Version that doesn't take a track "filter", and gathers all stats.
deadbeefd8ad7882017-04-18 16:01:17 -0700428 rtc::scoped_refptr<MockStatsObserver> OldGetStats() {
429 return OldGetStatsForTrack(nullptr);
430 }
431
432 // Synchronously gets stats and returns them. If it times out, fails the test
433 // and returns null.
434 rtc::scoped_refptr<const webrtc::RTCStatsReport> NewGetStats() {
435 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
436 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
437 peer_connection_->GetStats(callback);
438 EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout);
439 return callback->report();
deadbeef1dcb1642017-03-29 21:08:16 -0700440 }
441
442 int rendered_width() {
443 EXPECT_FALSE(fake_video_renderers_.empty());
444 return fake_video_renderers_.empty()
445 ? 0
446 : fake_video_renderers_.begin()->second->width();
447 }
448
449 int rendered_height() {
450 EXPECT_FALSE(fake_video_renderers_.empty());
451 return fake_video_renderers_.empty()
452 ? 0
453 : fake_video_renderers_.begin()->second->height();
454 }
455
456 double rendered_aspect_ratio() {
457 if (rendered_height() == 0) {
458 return 0.0;
459 }
460 return static_cast<double>(rendered_width()) / rendered_height();
461 }
462
463 webrtc::VideoRotation rendered_rotation() {
464 EXPECT_FALSE(fake_video_renderers_.empty());
465 return fake_video_renderers_.empty()
466 ? webrtc::kVideoRotation_0
467 : fake_video_renderers_.begin()->second->rotation();
468 }
469
470 int local_rendered_width() {
471 return local_video_renderer_ ? local_video_renderer_->width() : 0;
472 }
473
474 int local_rendered_height() {
475 return local_video_renderer_ ? local_video_renderer_->height() : 0;
476 }
477
478 double local_rendered_aspect_ratio() {
479 if (local_rendered_height() == 0) {
480 return 0.0;
481 }
482 return static_cast<double>(local_rendered_width()) /
483 local_rendered_height();
484 }
485
486 size_t number_of_remote_streams() {
487 if (!pc()) {
488 return 0;
489 }
490 return pc()->remote_streams()->count();
491 }
492
493 StreamCollectionInterface* remote_streams() const {
494 if (!pc()) {
495 ADD_FAILURE();
496 return nullptr;
497 }
498 return pc()->remote_streams();
499 }
500
501 StreamCollectionInterface* local_streams() {
502 if (!pc()) {
503 ADD_FAILURE();
504 return nullptr;
505 }
506 return pc()->local_streams();
507 }
508
509 webrtc::PeerConnectionInterface::SignalingState signaling_state() {
510 return pc()->signaling_state();
511 }
512
513 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
514 return pc()->ice_connection_state();
515 }
516
517 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
518 return pc()->ice_gathering_state();
519 }
520
521 // Returns a MockRtpReceiverObserver for each RtpReceiver returned by
522 // GetReceivers. They're updated automatically when a remote offer/answer
523 // from the fake signaling channel is applied, or when
524 // ResetRtpReceiverObservers below is called.
525 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>&
526 rtp_receiver_observers() {
527 return rtp_receiver_observers_;
528 }
529
530 void ResetRtpReceiverObservers() {
531 rtp_receiver_observers_.clear();
532 for (auto receiver : pc()->GetReceivers()) {
533 std::unique_ptr<MockRtpReceiverObserver> observer(
534 new MockRtpReceiverObserver(receiver->media_type()));
535 receiver->SetObserver(observer.get());
536 rtp_receiver_observers_.push_back(std::move(observer));
537 }
538 }
539
540 private:
541 explicit PeerConnectionWrapper(const std::string& debug_name)
542 : debug_name_(debug_name) {}
543
544 bool Init(
545 const MediaConstraintsInterface* constraints,
546 const PeerConnectionFactory::Options* options,
547 const PeerConnectionInterface::RTCConfiguration* config,
548 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
549 rtc::Thread* network_thread,
550 rtc::Thread* worker_thread) {
551 // There's an error in this test code if Init ends up being called twice.
552 RTC_DCHECK(!peer_connection_);
553 RTC_DCHECK(!peer_connection_factory_);
554
555 fake_network_manager_.reset(new rtc::FakeNetworkManager());
556 fake_network_manager_->AddInterface(rtc::SocketAddress("192.168.1.1", 0));
557
558 std::unique_ptr<cricket::PortAllocator> port_allocator(
559 new cricket::BasicPortAllocator(fake_network_manager_.get()));
560 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
561 if (!fake_audio_capture_module_) {
562 return false;
563 }
564 // Note that these factories don't end up getting used unless supported
565 // codecs are added to them.
566 fake_video_decoder_factory_ = new FakeWebRtcVideoDecoderFactory();
567 fake_video_encoder_factory_ = new FakeWebRtcVideoEncoderFactory();
568 rtc::Thread* const signaling_thread = rtc::Thread::Current();
569 peer_connection_factory_ = webrtc::CreatePeerConnectionFactory(
570 network_thread, worker_thread, signaling_thread,
571 fake_audio_capture_module_, fake_video_encoder_factory_,
572 fake_video_decoder_factory_);
573 if (!peer_connection_factory_) {
574 return false;
575 }
576 if (options) {
577 peer_connection_factory_->SetOptions(*options);
578 }
579 peer_connection_ =
580 CreatePeerConnection(std::move(port_allocator), constraints, config,
581 std::move(cert_generator));
582 return peer_connection_.get() != nullptr;
583 }
584
585 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
586 std::unique_ptr<cricket::PortAllocator> port_allocator,
587 const MediaConstraintsInterface* constraints,
588 const PeerConnectionInterface::RTCConfiguration* config,
589 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
590 PeerConnectionInterface::RTCConfiguration modified_config;
591 // If |config| is null, this will result in a default configuration being
592 // used.
593 if (config) {
594 modified_config = *config;
595 }
596 // Disable resolution adaptation; we don't want it interfering with the
597 // test results.
598 // TODO(deadbeef): Do something more robust. Since we're testing for aspect
599 // ratios and not specific resolutions, is this even necessary?
600 modified_config.set_cpu_adaptation(false);
601
602 return peer_connection_factory_->CreatePeerConnection(
603 modified_config, constraints, std::move(port_allocator),
604 std::move(cert_generator), this);
605 }
606
607 void set_signaling_message_receiver(
608 SignalingMessageReceiver* signaling_message_receiver) {
609 signaling_message_receiver_ = signaling_message_receiver;
610 }
611
612 void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; }
613
614 void EnableVideoDecoderFactory() {
615 video_decoder_factory_enabled_ = true;
616 fake_video_decoder_factory_->AddSupportedVideoCodecType(
617 webrtc::kVideoCodecVP8);
618 }
619
620 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrackInternal(
deadbeef1dcb1642017-03-29 21:08:16 -0700621 const FakeConstraints& constraints,
622 webrtc::VideoRotation rotation) {
623 // Set max frame rate to 10fps to reduce the risk of test flakiness.
624 // TODO(deadbeef): Do something more robust.
625 FakeConstraints source_constraints = constraints;
626 source_constraints.SetMandatoryMaxFrameRate(10);
627
628 cricket::FakeVideoCapturer* fake_capturer =
629 new webrtc::FakePeriodicVideoCapturer();
630 fake_capturer->SetRotation(rotation);
631 video_capturers_.push_back(fake_capturer);
632 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> source =
633 peer_connection_factory_->CreateVideoSource(fake_capturer,
634 &source_constraints);
635 rtc::scoped_refptr<webrtc::VideoTrackInterface> track(
deadbeefb1a15d72017-09-07 14:12:05 -0700636 peer_connection_factory_->CreateVideoTrack(rtc::CreateRandomUuid(),
637 source));
deadbeef1dcb1642017-03-29 21:08:16 -0700638 if (!local_video_renderer_) {
639 local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track));
640 }
641 return track;
642 }
643
644 void HandleIncomingOffer(const std::string& msg) {
645 LOG(LS_INFO) << debug_name_ << ": HandleIncomingOffer";
646 std::unique_ptr<SessionDescriptionInterface> desc(
647 webrtc::CreateSessionDescription("offer", msg, nullptr));
648 if (received_sdp_munger_) {
649 received_sdp_munger_(desc->description());
650 }
651
652 EXPECT_TRUE(SetRemoteDescription(std::move(desc)));
653 // Setting a remote description may have changed the number of receivers,
654 // so reset the receiver observers.
655 ResetRtpReceiverObservers();
656 auto answer = CreateAnswer();
657 ASSERT_NE(nullptr, answer);
658 EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(answer)));
659 }
660
661 void HandleIncomingAnswer(const std::string& msg) {
662 LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer";
663 std::unique_ptr<SessionDescriptionInterface> desc(
664 webrtc::CreateSessionDescription("answer", msg, nullptr));
665 if (received_sdp_munger_) {
666 received_sdp_munger_(desc->description());
667 }
668
669 EXPECT_TRUE(SetRemoteDescription(std::move(desc)));
670 // Set the RtpReceiverObserver after receivers are created.
671 ResetRtpReceiverObservers();
672 }
673
674 // Returns null on failure.
675 std::unique_ptr<SessionDescriptionInterface> CreateOffer() {
676 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
677 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
678 pc()->CreateOffer(observer, offer_answer_options_);
679 return WaitForDescriptionFromObserver(observer);
680 }
681
682 // Returns null on failure.
683 std::unique_ptr<SessionDescriptionInterface> CreateAnswer() {
684 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
685 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
686 pc()->CreateAnswer(observer, offer_answer_options_);
687 return WaitForDescriptionFromObserver(observer);
688 }
689
690 std::unique_ptr<SessionDescriptionInterface> WaitForDescriptionFromObserver(
691 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer) {
692 EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout);
693 if (!observer->result()) {
694 return nullptr;
695 }
696 auto description = observer->MoveDescription();
697 if (generated_sdp_munger_) {
698 generated_sdp_munger_(description->description());
699 }
700 return description;
701 }
702
703 // Setting the local description and sending the SDP message over the fake
704 // signaling channel are combined into the same method because the SDP
705 // message needs to be sent as soon as SetLocalDescription finishes, without
706 // waiting for the observer to be called. This ensures that ICE candidates
707 // don't outrace the description.
708 bool SetLocalDescriptionAndSendSdpMessage(
709 std::unique_ptr<SessionDescriptionInterface> desc) {
710 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
711 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
712 LOG(LS_INFO) << debug_name_ << ": SetLocalDescriptionAndSendSdpMessage";
713 std::string type = desc->type();
714 std::string sdp;
715 EXPECT_TRUE(desc->ToString(&sdp));
716 pc()->SetLocalDescription(observer, desc.release());
717 // As mentioned above, we need to send the message immediately after
718 // SetLocalDescription.
719 SendSdpMessage(type, sdp);
720 EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
721 return true;
722 }
723
724 bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc) {
725 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
726 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
727 LOG(LS_INFO) << debug_name_ << ": SetRemoteDescription";
728 pc()->SetRemoteDescription(observer, desc.release());
729 EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
730 return observer->result();
731 }
732
733 // Simulate sending a blob of SDP with delay |signaling_delay_ms_| (0 by
734 // default).
735 void SendSdpMessage(const std::string& type, const std::string& msg) {
736 if (signaling_delay_ms_ == 0) {
737 RelaySdpMessageIfReceiverExists(type, msg);
738 } else {
739 invoker_.AsyncInvokeDelayed<void>(
740 RTC_FROM_HERE, rtc::Thread::Current(),
741 rtc::Bind(&PeerConnectionWrapper::RelaySdpMessageIfReceiverExists,
742 this, type, msg),
743 signaling_delay_ms_);
744 }
745 }
746
747 void RelaySdpMessageIfReceiverExists(const std::string& type,
748 const std::string& msg) {
749 if (signaling_message_receiver_) {
750 signaling_message_receiver_->ReceiveSdpMessage(type, msg);
751 }
752 }
753
754 // Simulate trickling an ICE candidate with delay |signaling_delay_ms_| (0 by
755 // default).
756 void SendIceMessage(const std::string& sdp_mid,
757 int sdp_mline_index,
758 const std::string& msg) {
759 if (signaling_delay_ms_ == 0) {
760 RelayIceMessageIfReceiverExists(sdp_mid, sdp_mline_index, msg);
761 } else {
762 invoker_.AsyncInvokeDelayed<void>(
763 RTC_FROM_HERE, rtc::Thread::Current(),
764 rtc::Bind(&PeerConnectionWrapper::RelayIceMessageIfReceiverExists,
765 this, sdp_mid, sdp_mline_index, msg),
766 signaling_delay_ms_);
767 }
768 }
769
770 void RelayIceMessageIfReceiverExists(const std::string& sdp_mid,
771 int sdp_mline_index,
772 const std::string& msg) {
773 if (signaling_message_receiver_) {
774 signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index,
775 msg);
776 }
777 }
778
779 // SignalingMessageReceiver callbacks.
780 void ReceiveSdpMessage(const std::string& type,
781 const std::string& msg) override {
782 if (type == webrtc::SessionDescriptionInterface::kOffer) {
783 HandleIncomingOffer(msg);
784 } else {
785 HandleIncomingAnswer(msg);
786 }
787 }
788
789 void ReceiveIceMessage(const std::string& sdp_mid,
790 int sdp_mline_index,
791 const std::string& msg) override {
792 LOG(LS_INFO) << debug_name_ << ": ReceiveIceMessage";
793 std::unique_ptr<webrtc::IceCandidateInterface> candidate(
794 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr));
795 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
796 }
797
798 // PeerConnectionObserver callbacks.
799 void OnSignalingChange(
800 webrtc::PeerConnectionInterface::SignalingState new_state) override {
801 EXPECT_EQ(pc()->signaling_state(), new_state);
802 }
803 void OnAddStream(
804 rtc::scoped_refptr<MediaStreamInterface> media_stream) override {
805 media_stream->RegisterObserver(this);
806 for (size_t i = 0; i < media_stream->GetVideoTracks().size(); ++i) {
807 const std::string id = media_stream->GetVideoTracks()[i]->id();
808 ASSERT_TRUE(fake_video_renderers_.find(id) ==
809 fake_video_renderers_.end());
810 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
811 media_stream->GetVideoTracks()[i]));
812 }
813 }
814 void OnRemoveStream(
815 rtc::scoped_refptr<MediaStreamInterface> media_stream) override {}
816 void OnRenegotiationNeeded() override {}
817 void OnIceConnectionChange(
818 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {
819 EXPECT_EQ(pc()->ice_connection_state(), new_state);
820 }
821 void OnIceGatheringChange(
822 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {
823 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
824 ++transitions_to_gathering_state_;
825 }
826 EXPECT_EQ(pc()->ice_gathering_state(), new_state);
827 }
828 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
829 LOG(LS_INFO) << debug_name_ << ": OnIceCandidate";
830
831 std::string ice_sdp;
832 EXPECT_TRUE(candidate->ToString(&ice_sdp));
833 if (signaling_message_receiver_ == nullptr) {
834 // Remote party may be deleted.
835 return;
836 }
837 SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
838 }
839 void OnDataChannel(
840 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
841 LOG(LS_INFO) << debug_name_ << ": OnDataChannel";
842 data_channel_ = data_channel;
843 data_observer_.reset(new MockDataChannelObserver(data_channel));
844 }
845
846 // MediaStreamInterface callback
847 void OnChanged() override {
848 // Track added or removed from MediaStream, so update our renderers.
849 rtc::scoped_refptr<StreamCollectionInterface> remote_streams =
850 pc()->remote_streams();
851 // Remove renderers for tracks that were removed.
852 for (auto it = fake_video_renderers_.begin();
853 it != fake_video_renderers_.end();) {
854 if (remote_streams->FindVideoTrack(it->first) == nullptr) {
855 auto to_remove = it++;
856 removed_fake_video_renderers_.push_back(std::move(to_remove->second));
857 fake_video_renderers_.erase(to_remove);
858 } else {
859 ++it;
860 }
861 }
862 // Create renderers for new video tracks.
863 for (size_t stream_index = 0; stream_index < remote_streams->count();
864 ++stream_index) {
865 MediaStreamInterface* remote_stream = remote_streams->at(stream_index);
866 for (size_t track_index = 0;
867 track_index < remote_stream->GetVideoTracks().size();
868 ++track_index) {
869 const std::string id =
870 remote_stream->GetVideoTracks()[track_index]->id();
871 if (fake_video_renderers_.find(id) != fake_video_renderers_.end()) {
872 continue;
873 }
874 fake_video_renderers_[id].reset(new webrtc::FakeVideoTrackRenderer(
875 remote_stream->GetVideoTracks()[track_index]));
876 }
877 }
878 }
879
880 std::string debug_name_;
881
882 std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_;
883
884 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
885 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
886 peer_connection_factory_;
887
888 // Needed to keep track of number of frames sent.
889 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
890 // Needed to keep track of number of frames received.
891 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
892 fake_video_renderers_;
893 // Needed to ensure frames aren't received for removed tracks.
894 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
895 removed_fake_video_renderers_;
896 // Needed to keep track of number of frames received when external decoder
897 // used.
898 FakeWebRtcVideoDecoderFactory* fake_video_decoder_factory_ = nullptr;
899 FakeWebRtcVideoEncoderFactory* fake_video_encoder_factory_ = nullptr;
900 bool video_decoder_factory_enabled_ = false;
901
902 // For remote peer communication.
903 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
904 int signaling_delay_ms_ = 0;
905
906 // Store references to the video capturers we've created, so that we can stop
907 // them, if required.
908 std::vector<cricket::FakeVideoCapturer*> video_capturers_;
909 // |local_video_renderer_| attached to the first created local video track.
910 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_;
911
912 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_;
913 std::function<void(cricket::SessionDescription*)> received_sdp_munger_;
914 std::function<void(cricket::SessionDescription*)> generated_sdp_munger_;
915
916 rtc::scoped_refptr<DataChannelInterface> data_channel_;
917 std::unique_ptr<MockDataChannelObserver> data_observer_;
918
919 std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_;
920
921 int transitions_to_gathering_state_ = 0;
922
923 rtc::AsyncInvoker invoker_;
924
925 friend class PeerConnectionIntegrationTest;
926};
927
928// Tests two PeerConnections connecting to each other end-to-end, using a
929// virtual network, fake A/V capture and fake encoder/decoders. The
930// PeerConnections share the threads/socket servers, but use separate versions
931// of everything else (including "PeerConnectionFactory"s).
932class PeerConnectionIntegrationTest : public testing::Test {
933 public:
934 PeerConnectionIntegrationTest()
deadbeef98e186c2017-05-16 18:00:06 -0700935 : ss_(new rtc::VirtualSocketServer()),
deadbeef1dcb1642017-03-29 21:08:16 -0700936 network_thread_(new rtc::Thread(ss_.get())),
937 worker_thread_(rtc::Thread::Create()) {
938 RTC_CHECK(network_thread_->Start());
939 RTC_CHECK(worker_thread_->Start());
940 }
941
942 ~PeerConnectionIntegrationTest() {
943 if (caller_) {
944 caller_->set_signaling_message_receiver(nullptr);
945 }
946 if (callee_) {
947 callee_->set_signaling_message_receiver(nullptr);
948 }
949 }
950
951 bool SignalingStateStable() {
952 return caller_->SignalingStateStable() && callee_->SignalingStateStable();
953 }
954
deadbeef71452802017-05-07 17:21:01 -0700955 bool DtlsConnected() {
956 // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS
957 // are connected. This is an important distinction. Once we have separate
958 // ICE and DTLS state, this check needs to use the DTLS state.
959 return (callee()->ice_connection_state() ==
960 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
961 callee()->ice_connection_state() ==
962 webrtc::PeerConnectionInterface::kIceConnectionCompleted) &&
963 (caller()->ice_connection_state() ==
964 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
965 caller()->ice_connection_state() ==
966 webrtc::PeerConnectionInterface::kIceConnectionCompleted);
967 }
968
deadbeef1dcb1642017-03-29 21:08:16 -0700969 bool CreatePeerConnectionWrappers() {
970 return CreatePeerConnectionWrappersWithConfig(
971 PeerConnectionInterface::RTCConfiguration(),
972 PeerConnectionInterface::RTCConfiguration());
973 }
974
975 bool CreatePeerConnectionWrappersWithConstraints(
976 MediaConstraintsInterface* caller_constraints,
977 MediaConstraintsInterface* callee_constraints) {
978 caller_.reset(PeerConnectionWrapper::CreateWithConstraints(
979 "Caller", caller_constraints, network_thread_.get(),
980 worker_thread_.get()));
981 callee_.reset(PeerConnectionWrapper::CreateWithConstraints(
982 "Callee", callee_constraints, network_thread_.get(),
983 worker_thread_.get()));
984 return caller_ && callee_;
985 }
986
987 bool CreatePeerConnectionWrappersWithConfig(
988 const PeerConnectionInterface::RTCConfiguration& caller_config,
989 const PeerConnectionInterface::RTCConfiguration& callee_config) {
990 caller_.reset(PeerConnectionWrapper::CreateWithConfig(
991 "Caller", caller_config, network_thread_.get(), worker_thread_.get()));
992 callee_.reset(PeerConnectionWrapper::CreateWithConfig(
993 "Callee", callee_config, network_thread_.get(), worker_thread_.get()));
994 return caller_ && callee_;
995 }
996
997 bool CreatePeerConnectionWrappersWithOptions(
998 const PeerConnectionFactory::Options& caller_options,
999 const PeerConnectionFactory::Options& callee_options) {
1000 caller_.reset(PeerConnectionWrapper::CreateWithOptions(
1001 "Caller", caller_options, network_thread_.get(), worker_thread_.get()));
1002 callee_.reset(PeerConnectionWrapper::CreateWithOptions(
1003 "Callee", callee_options, network_thread_.get(), worker_thread_.get()));
1004 return caller_ && callee_;
1005 }
1006
1007 PeerConnectionWrapper* CreatePeerConnectionWrapperWithAlternateKey() {
1008 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
1009 new FakeRTCCertificateGenerator());
1010 cert_generator->use_alternate_key();
1011
1012 // Make sure the new client is using a different certificate.
1013 return PeerConnectionWrapper::CreateWithDtlsIdentityStore(
1014 "New Peer", std::move(cert_generator), network_thread_.get(),
1015 worker_thread_.get());
1016 }
1017
1018 // Once called, SDP blobs and ICE candidates will be automatically signaled
1019 // between PeerConnections.
1020 void ConnectFakeSignaling() {
1021 caller_->set_signaling_message_receiver(callee_.get());
1022 callee_->set_signaling_message_receiver(caller_.get());
1023 }
1024
1025 void SetSignalingDelayMs(int delay_ms) {
1026 caller_->set_signaling_delay_ms(delay_ms);
1027 callee_->set_signaling_delay_ms(delay_ms);
1028 }
1029
1030 void EnableVideoDecoderFactory() {
1031 caller_->EnableVideoDecoderFactory();
1032 callee_->EnableVideoDecoderFactory();
1033 }
1034
1035 // Messages may get lost on the unreliable DataChannel, so we send multiple
1036 // times to avoid test flakiness.
1037 void SendRtpDataWithRetries(webrtc::DataChannelInterface* dc,
1038 const std::string& data,
1039 int retries) {
1040 for (int i = 0; i < retries; ++i) {
1041 dc->Send(DataBuffer(data));
1042 }
1043 }
1044
1045 rtc::Thread* network_thread() { return network_thread_.get(); }
1046
1047 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); }
1048
1049 PeerConnectionWrapper* caller() { return caller_.get(); }
1050
1051 // Set the |caller_| to the |wrapper| passed in and return the
1052 // original |caller_|.
1053 PeerConnectionWrapper* SetCallerPcWrapperAndReturnCurrent(
1054 PeerConnectionWrapper* wrapper) {
1055 PeerConnectionWrapper* old = caller_.release();
1056 caller_.reset(wrapper);
1057 return old;
1058 }
1059
1060 PeerConnectionWrapper* callee() { return callee_.get(); }
1061
1062 // Set the |callee_| to the |wrapper| passed in and return the
1063 // original |callee_|.
1064 PeerConnectionWrapper* SetCalleePcWrapperAndReturnCurrent(
1065 PeerConnectionWrapper* wrapper) {
1066 PeerConnectionWrapper* old = callee_.release();
1067 callee_.reset(wrapper);
1068 return old;
1069 }
1070
1071 // Expects the provided number of new frames to be received within |wait_ms|.
1072 // "New frames" meaning that it waits for the current frame counts to
1073 // *increase* by the provided values. For video, uses
1074 // RecievedVideoFramesForEachTrack for the case of multiple video tracks
1075 // being received.
1076 void ExpectNewFramesReceivedWithWait(
1077 int expected_caller_received_audio_frames,
1078 int expected_caller_received_video_frames,
1079 int expected_callee_received_audio_frames,
1080 int expected_callee_received_video_frames,
1081 int wait_ms) {
1082 // Add current frame counts to the provided values, in order to wait for
1083 // the frame count to increase.
1084 expected_caller_received_audio_frames += caller()->audio_frames_received();
1085 expected_caller_received_video_frames +=
1086 caller()->min_video_frames_received_per_track();
1087 expected_callee_received_audio_frames += callee()->audio_frames_received();
1088 expected_callee_received_video_frames +=
1089 callee()->min_video_frames_received_per_track();
1090
1091 EXPECT_TRUE_WAIT(caller()->audio_frames_received() >=
1092 expected_caller_received_audio_frames &&
1093 caller()->min_video_frames_received_per_track() >=
1094 expected_caller_received_video_frames &&
1095 callee()->audio_frames_received() >=
1096 expected_callee_received_audio_frames &&
1097 callee()->min_video_frames_received_per_track() >=
1098 expected_callee_received_video_frames,
1099 wait_ms);
1100
1101 // After the combined wait, do an "expect" for each individual count, to
1102 // print out a more detailed message upon failure.
1103 EXPECT_GE(caller()->audio_frames_received(),
1104 expected_caller_received_audio_frames);
1105 EXPECT_GE(caller()->min_video_frames_received_per_track(),
1106 expected_caller_received_video_frames);
1107 EXPECT_GE(callee()->audio_frames_received(),
1108 expected_callee_received_audio_frames);
1109 EXPECT_GE(callee()->min_video_frames_received_per_track(),
1110 expected_callee_received_video_frames);
1111 }
1112
1113 void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled,
1114 bool remote_gcm_enabled,
1115 int expected_cipher_suite) {
1116 PeerConnectionFactory::Options caller_options;
1117 caller_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled;
1118 PeerConnectionFactory::Options callee_options;
1119 callee_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled;
1120 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(caller_options,
1121 callee_options));
1122 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
1123 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1124 caller()->pc()->RegisterUMAObserver(caller_observer);
1125 ConnectFakeSignaling();
1126 caller()->AddAudioVideoMediaStream();
1127 callee()->AddAudioVideoMediaStream();
1128 caller()->CreateAndSetAndSignalOffer();
1129 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1130 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
deadbeefd8ad7882017-04-18 16:01:17 -07001131 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07001132 EXPECT_EQ(
1133 1, caller_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1134 expected_cipher_suite));
1135 caller()->pc()->RegisterUMAObserver(nullptr);
1136 }
1137
1138 private:
1139 // |ss_| is used by |network_thread_| so it must be destroyed later.
deadbeef1dcb1642017-03-29 21:08:16 -07001140 std::unique_ptr<rtc::VirtualSocketServer> ss_;
1141 // |network_thread_| and |worker_thread_| are used by both
1142 // |caller_| and |callee_| so they must be destroyed
1143 // later.
1144 std::unique_ptr<rtc::Thread> network_thread_;
1145 std::unique_ptr<rtc::Thread> worker_thread_;
1146 std::unique_ptr<PeerConnectionWrapper> caller_;
1147 std::unique_ptr<PeerConnectionWrapper> callee_;
1148};
1149
1150// Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This
1151// includes testing that the callback is invoked if an observer is connected
1152// after the first packet has already been received.
1153TEST_F(PeerConnectionIntegrationTest,
1154 RtpReceiverObserverOnFirstPacketReceived) {
1155 ASSERT_TRUE(CreatePeerConnectionWrappers());
1156 ConnectFakeSignaling();
1157 caller()->AddAudioVideoMediaStream();
1158 callee()->AddAudioVideoMediaStream();
1159 // Start offer/answer exchange and wait for it to complete.
1160 caller()->CreateAndSetAndSignalOffer();
1161 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1162 // Should be one receiver each for audio/video.
1163 EXPECT_EQ(2, caller()->rtp_receiver_observers().size());
1164 EXPECT_EQ(2, callee()->rtp_receiver_observers().size());
1165 // Wait for all "first packet received" callbacks to be fired.
1166 EXPECT_TRUE_WAIT(
1167 std::all_of(caller()->rtp_receiver_observers().begin(),
1168 caller()->rtp_receiver_observers().end(),
1169 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1170 return o->first_packet_received();
1171 }),
1172 kMaxWaitForFramesMs);
1173 EXPECT_TRUE_WAIT(
1174 std::all_of(callee()->rtp_receiver_observers().begin(),
1175 callee()->rtp_receiver_observers().end(),
1176 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1177 return o->first_packet_received();
1178 }),
1179 kMaxWaitForFramesMs);
1180 // If new observers are set after the first packet was already received, the
1181 // callback should still be invoked.
1182 caller()->ResetRtpReceiverObservers();
1183 callee()->ResetRtpReceiverObservers();
1184 EXPECT_EQ(2, caller()->rtp_receiver_observers().size());
1185 EXPECT_EQ(2, callee()->rtp_receiver_observers().size());
1186 EXPECT_TRUE(
1187 std::all_of(caller()->rtp_receiver_observers().begin(),
1188 caller()->rtp_receiver_observers().end(),
1189 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1190 return o->first_packet_received();
1191 }));
1192 EXPECT_TRUE(
1193 std::all_of(callee()->rtp_receiver_observers().begin(),
1194 callee()->rtp_receiver_observers().end(),
1195 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1196 return o->first_packet_received();
1197 }));
1198}
1199
1200class DummyDtmfObserver : public DtmfSenderObserverInterface {
1201 public:
1202 DummyDtmfObserver() : completed_(false) {}
1203
1204 // Implements DtmfSenderObserverInterface.
1205 void OnToneChange(const std::string& tone) override {
1206 tones_.push_back(tone);
1207 if (tone.empty()) {
1208 completed_ = true;
1209 }
1210 }
1211
1212 const std::vector<std::string>& tones() const { return tones_; }
1213 bool completed() const { return completed_; }
1214
1215 private:
1216 bool completed_;
1217 std::vector<std::string> tones_;
1218};
1219
1220// Assumes |sender| already has an audio track added and the offer/answer
1221// exchange is done.
1222void TestDtmfFromSenderToReceiver(PeerConnectionWrapper* sender,
1223 PeerConnectionWrapper* receiver) {
1224 DummyDtmfObserver observer;
1225 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender;
1226
1227 // We should be able to create a DTMF sender from a local track.
1228 webrtc::AudioTrackInterface* localtrack =
1229 sender->local_streams()->at(0)->GetAudioTracks()[0];
1230 dtmf_sender = sender->pc()->CreateDtmfSender(localtrack);
1231 ASSERT_NE(nullptr, dtmf_sender.get());
1232 dtmf_sender->RegisterObserver(&observer);
1233
1234 // Test the DtmfSender object just created.
1235 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
1236 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
1237
1238 EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout);
1239 std::vector<std::string> tones = {"1", "a", ""};
1240 EXPECT_EQ(tones, observer.tones());
1241 dtmf_sender->UnregisterObserver();
1242 // TODO(deadbeef): Verify the tones were actually received end-to-end.
1243}
1244
1245// Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each
1246// direction).
1247TEST_F(PeerConnectionIntegrationTest, DtmfSenderObserver) {
1248 ASSERT_TRUE(CreatePeerConnectionWrappers());
1249 ConnectFakeSignaling();
1250 // Only need audio for DTMF.
1251 caller()->AddAudioOnlyMediaStream();
1252 callee()->AddAudioOnlyMediaStream();
1253 caller()->CreateAndSetAndSignalOffer();
1254 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
deadbeef71452802017-05-07 17:21:01 -07001255 // DTLS must finish before the DTMF sender can be used reliably.
1256 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07001257 TestDtmfFromSenderToReceiver(caller(), callee());
1258 TestDtmfFromSenderToReceiver(callee(), caller());
1259}
1260
1261// Basic end-to-end test, verifying media can be encoded/transmitted/decoded
1262// between two connections, using DTLS-SRTP.
1263TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithDtls) {
1264 ASSERT_TRUE(CreatePeerConnectionWrappers());
1265 ConnectFakeSignaling();
1266 // Do normal offer/answer and wait for some frames to be received in each
1267 // direction.
1268 caller()->AddAudioVideoMediaStream();
1269 callee()->AddAudioVideoMediaStream();
1270 caller()->CreateAndSetAndSignalOffer();
1271 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1272 ExpectNewFramesReceivedWithWait(
1273 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1274 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1275 kMaxWaitForFramesMs);
1276}
1277
1278// Uses SDES instead of DTLS for key agreement.
1279TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithSdes) {
1280 PeerConnectionInterface::RTCConfiguration sdes_config;
1281 sdes_config.enable_dtls_srtp.emplace(false);
1282 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config));
1283 ConnectFakeSignaling();
1284
1285 // Do normal offer/answer and wait for some frames to be received in each
1286 // direction.
1287 caller()->AddAudioVideoMediaStream();
1288 callee()->AddAudioVideoMediaStream();
1289 caller()->CreateAndSetAndSignalOffer();
1290 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1291 ExpectNewFramesReceivedWithWait(
1292 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1293 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1294 kMaxWaitForFramesMs);
1295}
1296
Steve Anton8c0f7a72017-10-03 10:03:10 -07001297// Tests that the GetRemoteAudioSSLCertificate method returns the remote DTLS
1298// certificate once the DTLS handshake has finished.
1299TEST_F(PeerConnectionIntegrationTest,
1300 GetRemoteAudioSSLCertificateReturnsExchangedCertificate) {
1301 auto GetRemoteAudioSSLCertificate = [](PeerConnectionWrapper* wrapper) {
1302 auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc());
1303 auto pc = reinterpret_cast<PeerConnection*>(pci->internal());
1304 return pc->GetRemoteAudioSSLCertificate();
1305 };
1306
1307 auto caller_cert = rtc::RTCCertificate::FromPEM(kRsaPems[0]);
1308 auto callee_cert = rtc::RTCCertificate::FromPEM(kRsaPems[1]);
1309
1310 // Configure each side with a known certificate so they can be compared later.
1311 PeerConnectionInterface::RTCConfiguration caller_config;
1312 caller_config.enable_dtls_srtp.emplace(true);
1313 caller_config.certificates.push_back(caller_cert);
1314 PeerConnectionInterface::RTCConfiguration callee_config;
1315 callee_config.enable_dtls_srtp.emplace(true);
1316 callee_config.certificates.push_back(callee_cert);
1317 ASSERT_TRUE(
1318 CreatePeerConnectionWrappersWithConfig(caller_config, callee_config));
1319 ConnectFakeSignaling();
1320
1321 // When first initialized, there should not be a remote SSL certificate (and
1322 // calling this method should not crash).
1323 EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(caller()));
1324 EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(callee()));
1325
1326 caller()->AddAudioOnlyMediaStream();
1327 callee()->AddAudioOnlyMediaStream();
1328 caller()->CreateAndSetAndSignalOffer();
1329 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1330 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
1331
1332 // Once DTLS has been connected, each side should return the other's SSL
1333 // certificate when calling GetRemoteAudioSSLCertificate.
1334
1335 auto caller_remote_cert = GetRemoteAudioSSLCertificate(caller());
1336 ASSERT_TRUE(caller_remote_cert);
1337 EXPECT_EQ(callee_cert->ssl_certificate().ToPEMString(),
1338 caller_remote_cert->ToPEMString());
1339
1340 auto callee_remote_cert = GetRemoteAudioSSLCertificate(callee());
1341 ASSERT_TRUE(callee_remote_cert);
1342 EXPECT_EQ(caller_cert->ssl_certificate().ToPEMString(),
1343 callee_remote_cert->ToPEMString());
1344}
1345
deadbeef1dcb1642017-03-29 21:08:16 -07001346// This test sets up a call between two parties (using DTLS) and tests that we
1347// can get a video aspect ratio of 16:9.
1348TEST_F(PeerConnectionIntegrationTest, SendAndReceive16To9AspectRatio) {
1349 ASSERT_TRUE(CreatePeerConnectionWrappers());
1350 ConnectFakeSignaling();
1351
1352 // Add video tracks with 16:9 constraint.
1353 FakeConstraints constraints;
1354 double requested_ratio = 16.0 / 9;
1355 constraints.SetMandatoryMinAspectRatio(requested_ratio);
1356 caller()->AddMediaStreamFromTracks(
1357 nullptr, caller()->CreateLocalVideoTrackWithConstraints(constraints));
1358 callee()->AddMediaStreamFromTracks(
1359 nullptr, callee()->CreateLocalVideoTrackWithConstraints(constraints));
1360
1361 // Do normal offer/answer and wait for at least one frame to be received in
1362 // each direction.
1363 caller()->CreateAndSetAndSignalOffer();
1364 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
1365 callee()->min_video_frames_received_per_track() > 0,
1366 kMaxWaitForFramesMs);
1367
1368 // Check rendered aspect ratio.
1369 EXPECT_EQ(requested_ratio, caller()->local_rendered_aspect_ratio());
1370 EXPECT_EQ(requested_ratio, caller()->rendered_aspect_ratio());
1371 EXPECT_EQ(requested_ratio, callee()->local_rendered_aspect_ratio());
1372 EXPECT_EQ(requested_ratio, callee()->rendered_aspect_ratio());
1373}
1374
1375// This test sets up a call between two parties with a source resolution of
1376// 1280x720 and verifies that a 16:9 aspect ratio is received.
1377TEST_F(PeerConnectionIntegrationTest,
1378 Send1280By720ResolutionAndReceive16To9AspectRatio) {
1379 ASSERT_TRUE(CreatePeerConnectionWrappers());
1380 ConnectFakeSignaling();
1381
1382 // Similar to above test, but uses MandatoryMin[Width/Height] constraint
1383 // instead of aspect ratio constraint.
1384 FakeConstraints constraints;
1385 constraints.SetMandatoryMinWidth(1280);
1386 constraints.SetMandatoryMinHeight(720);
1387 caller()->AddMediaStreamFromTracks(
1388 nullptr, caller()->CreateLocalVideoTrackWithConstraints(constraints));
1389 callee()->AddMediaStreamFromTracks(
1390 nullptr, callee()->CreateLocalVideoTrackWithConstraints(constraints));
1391
1392 // Do normal offer/answer and wait for at least one frame to be received in
1393 // each direction.
1394 caller()->CreateAndSetAndSignalOffer();
1395 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
1396 callee()->min_video_frames_received_per_track() > 0,
1397 kMaxWaitForFramesMs);
1398
1399 // Check rendered aspect ratio.
1400 EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio());
1401 EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio());
1402 EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio());
1403 EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio());
1404}
1405
1406// This test sets up an one-way call, with media only from caller to
1407// callee.
1408TEST_F(PeerConnectionIntegrationTest, OneWayMediaCall) {
1409 ASSERT_TRUE(CreatePeerConnectionWrappers());
1410 ConnectFakeSignaling();
1411 caller()->AddAudioVideoMediaStream();
1412 caller()->CreateAndSetAndSignalOffer();
1413 int caller_received_frames = 0;
1414 ExpectNewFramesReceivedWithWait(
1415 caller_received_frames, caller_received_frames,
1416 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1417 kMaxWaitForFramesMs);
1418}
1419
1420// This test sets up a audio call initially, with the callee rejecting video
1421// initially. Then later the callee decides to upgrade to audio/video, and
1422// initiates a new offer/answer exchange.
1423TEST_F(PeerConnectionIntegrationTest, AudioToVideoUpgrade) {
1424 ASSERT_TRUE(CreatePeerConnectionWrappers());
1425 ConnectFakeSignaling();
1426 // Initially, offer an audio/video stream from the caller, but refuse to
1427 // send/receive video on the callee side.
1428 caller()->AddAudioVideoMediaStream();
deadbeef4389b4d2017-09-07 09:07:36 -07001429 callee()->AddAudioOnlyMediaStream();
deadbeef1dcb1642017-03-29 21:08:16 -07001430 PeerConnectionInterface::RTCOfferAnswerOptions options;
1431 options.offer_to_receive_video = 0;
1432 callee()->SetOfferAnswerOptions(options);
1433 // Do offer/answer and make sure audio is still received end-to-end.
1434 caller()->CreateAndSetAndSignalOffer();
1435 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1436 ExpectNewFramesReceivedWithWait(kDefaultExpectedAudioFrameCount, 0,
1437 kDefaultExpectedAudioFrameCount, 0,
1438 kMaxWaitForFramesMs);
1439 // Sanity check that the callee's description has a rejected video section.
1440 ASSERT_NE(nullptr, callee()->pc()->local_description());
1441 const ContentInfo* callee_video_content =
1442 GetFirstVideoContent(callee()->pc()->local_description()->description());
1443 ASSERT_NE(nullptr, callee_video_content);
1444 EXPECT_TRUE(callee_video_content->rejected);
1445 // Now negotiate with video and ensure negotiation succeeds, with video
1446 // frames and additional audio frames being received.
deadbeefb1a15d72017-09-07 14:12:05 -07001447 callee()->AddVideoOnlyMediaStream();
deadbeef1dcb1642017-03-29 21:08:16 -07001448 options.offer_to_receive_video = 1;
1449 callee()->SetOfferAnswerOptions(options);
1450 callee()->CreateAndSetAndSignalOffer();
1451 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1452 // Expect additional audio frames to be received after the upgrade.
1453 ExpectNewFramesReceivedWithWait(
1454 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1455 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1456 kMaxWaitForFramesMs);
1457}
1458
deadbeef4389b4d2017-09-07 09:07:36 -07001459// Simpler than the above test; just add an audio track to an established
1460// video-only connection.
1461TEST_F(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) {
1462 ASSERT_TRUE(CreatePeerConnectionWrappers());
1463 ConnectFakeSignaling();
1464 // Do initial offer/answer with just a video track.
1465 caller()->AddVideoOnlyMediaStream();
1466 callee()->AddVideoOnlyMediaStream();
1467 caller()->CreateAndSetAndSignalOffer();
1468 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1469 // Now add an audio track and do another offer/answer.
deadbeefb1a15d72017-09-07 14:12:05 -07001470 caller()->AddAudioOnlyMediaStream();
1471 callee()->AddAudioOnlyMediaStream();
deadbeef4389b4d2017-09-07 09:07:36 -07001472 caller()->CreateAndSetAndSignalOffer();
1473 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1474 // Ensure both audio and video frames are received end-to-end.
1475 ExpectNewFramesReceivedWithWait(
1476 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1477 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1478 kMaxWaitForFramesMs);
1479}
1480
deadbeef1dcb1642017-03-29 21:08:16 -07001481// This test sets up a call that's transferred to a new caller with a different
1482// DTLS fingerprint.
1483TEST_F(PeerConnectionIntegrationTest, CallTransferredForCallee) {
1484 ASSERT_TRUE(CreatePeerConnectionWrappers());
1485 ConnectFakeSignaling();
1486 caller()->AddAudioVideoMediaStream();
1487 callee()->AddAudioVideoMediaStream();
1488 caller()->CreateAndSetAndSignalOffer();
1489 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1490
1491 // Keep the original peer around which will still send packets to the
1492 // receiving client. These SRTP packets will be dropped.
1493 std::unique_ptr<PeerConnectionWrapper> original_peer(
1494 SetCallerPcWrapperAndReturnCurrent(
1495 CreatePeerConnectionWrapperWithAlternateKey()));
1496 // TODO(deadbeef): Why do we call Close here? That goes against the comment
1497 // directly above.
1498 original_peer->pc()->Close();
1499
1500 ConnectFakeSignaling();
1501 caller()->AddAudioVideoMediaStream();
1502 caller()->CreateAndSetAndSignalOffer();
1503 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1504 // Wait for some additional frames to be transmitted end-to-end.
1505 ExpectNewFramesReceivedWithWait(
1506 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1507 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1508 kMaxWaitForFramesMs);
1509}
1510
1511// This test sets up a call that's transferred to a new callee with a different
1512// DTLS fingerprint.
1513TEST_F(PeerConnectionIntegrationTest, CallTransferredForCaller) {
1514 ASSERT_TRUE(CreatePeerConnectionWrappers());
1515 ConnectFakeSignaling();
1516 caller()->AddAudioVideoMediaStream();
1517 callee()->AddAudioVideoMediaStream();
1518 caller()->CreateAndSetAndSignalOffer();
1519 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1520
1521 // Keep the original peer around which will still send packets to the
1522 // receiving client. These SRTP packets will be dropped.
1523 std::unique_ptr<PeerConnectionWrapper> original_peer(
1524 SetCalleePcWrapperAndReturnCurrent(
1525 CreatePeerConnectionWrapperWithAlternateKey()));
1526 // TODO(deadbeef): Why do we call Close here? That goes against the comment
1527 // directly above.
1528 original_peer->pc()->Close();
1529
1530 ConnectFakeSignaling();
1531 callee()->AddAudioVideoMediaStream();
1532 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
1533 caller()->CreateAndSetAndSignalOffer();
1534 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1535 // Wait for some additional frames to be transmitted end-to-end.
1536 ExpectNewFramesReceivedWithWait(
1537 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1538 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1539 kMaxWaitForFramesMs);
1540}
1541
1542// This test sets up a non-bundled call and negotiates bundling at the same
1543// time as starting an ICE restart. When bundling is in effect in the restart,
1544// the DTLS-SRTP context should be successfully reset.
1545TEST_F(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) {
1546 ASSERT_TRUE(CreatePeerConnectionWrappers());
1547 ConnectFakeSignaling();
1548
1549 caller()->AddAudioVideoMediaStream();
1550 callee()->AddAudioVideoMediaStream();
1551 // Remove the bundle group from the SDP received by the callee.
1552 callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) {
1553 desc->RemoveGroupByName("BUNDLE");
1554 });
1555 caller()->CreateAndSetAndSignalOffer();
1556 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1557 ExpectNewFramesReceivedWithWait(
1558 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1559 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1560 kMaxWaitForFramesMs);
1561
1562 // Now stop removing the BUNDLE group, and trigger an ICE restart.
1563 callee()->SetReceivedSdpMunger(nullptr);
1564 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
1565 caller()->CreateAndSetAndSignalOffer();
1566 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1567
1568 // Expect additional frames to be received after the ICE restart.
1569 ExpectNewFramesReceivedWithWait(
1570 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1571 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1572 kMaxWaitForFramesMs);
1573}
1574
1575// Test CVO (Coordination of Video Orientation). If a video source is rotated
1576// and both peers support the CVO RTP header extension, the actual video frames
1577// don't need to be encoded in different resolutions, since the rotation is
1578// communicated through the RTP header extension.
1579TEST_F(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) {
1580 ASSERT_TRUE(CreatePeerConnectionWrappers());
1581 ConnectFakeSignaling();
1582 // Add rotated video tracks.
1583 caller()->AddMediaStreamFromTracks(
1584 nullptr,
1585 caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90));
1586 callee()->AddMediaStreamFromTracks(
1587 nullptr,
1588 callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270));
1589
1590 // Wait for video frames to be received by both sides.
1591 caller()->CreateAndSetAndSignalOffer();
1592 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1593 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
1594 callee()->min_video_frames_received_per_track() > 0,
1595 kMaxWaitForFramesMs);
1596
1597 // Ensure that the aspect ratio is unmodified.
1598 // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test,
1599 // not just assumed.
1600 EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio());
1601 EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio());
1602 EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio());
1603 EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio());
1604 // Ensure that the CVO bits were surfaced to the renderer.
1605 EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation());
1606 EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation());
1607}
1608
1609// Test that when the CVO extension isn't supported, video is rotated the
1610// old-fashioned way, by encoding rotated frames.
1611TEST_F(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) {
1612 ASSERT_TRUE(CreatePeerConnectionWrappers());
1613 ConnectFakeSignaling();
1614 // Add rotated video tracks.
1615 caller()->AddMediaStreamFromTracks(
1616 nullptr,
1617 caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90));
1618 callee()->AddMediaStreamFromTracks(
1619 nullptr,
1620 callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270));
1621
1622 // Remove the CVO extension from the offered SDP.
1623 callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) {
1624 cricket::VideoContentDescription* video =
1625 GetFirstVideoContentDescription(desc);
1626 video->ClearRtpHeaderExtensions();
1627 });
1628 // Wait for video frames to be received by both sides.
1629 caller()->CreateAndSetAndSignalOffer();
1630 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1631 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
1632 callee()->min_video_frames_received_per_track() > 0,
1633 kMaxWaitForFramesMs);
1634
1635 // Expect that the aspect ratio is inversed to account for the 90/270 degree
1636 // rotation.
1637 // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test,
1638 // not just assumed.
1639 EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio());
1640 EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio());
1641 EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio());
1642 EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio());
1643 // Expect that each endpoint is unaware of the rotation of the other endpoint.
1644 EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation());
1645 EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation());
1646}
1647
1648// TODO(deadbeef): The tests below rely on RTCOfferAnswerOptions to reject an
1649// m= section. When we implement Unified Plan SDP, the right way to do this
1650// would be by stopping an RtpTransceiver.
1651
1652// Test that if the answerer rejects the audio m= section, no audio is sent or
1653// received, but video still can be.
1654TEST_F(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) {
1655 ASSERT_TRUE(CreatePeerConnectionWrappers());
1656 ConnectFakeSignaling();
1657 caller()->AddAudioVideoMediaStream();
1658 // Only add video track for callee, and set offer_to_receive_audio to 0, so
1659 // it will reject the audio m= section completely.
1660 PeerConnectionInterface::RTCOfferAnswerOptions options;
1661 options.offer_to_receive_audio = 0;
1662 callee()->SetOfferAnswerOptions(options);
1663 callee()->AddMediaStreamFromTracks(nullptr,
1664 callee()->CreateLocalVideoTrack());
1665 // Do offer/answer and wait for successful end-to-end video frames.
1666 caller()->CreateAndSetAndSignalOffer();
1667 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1668 ExpectNewFramesReceivedWithWait(0, kDefaultExpectedVideoFrameCount, 0,
1669 kDefaultExpectedVideoFrameCount,
1670 kMaxWaitForFramesMs);
1671 // Shouldn't have received audio frames at any point.
1672 EXPECT_EQ(0, caller()->audio_frames_received());
1673 EXPECT_EQ(0, callee()->audio_frames_received());
1674 // Sanity check that the callee's description has a rejected audio section.
1675 ASSERT_NE(nullptr, callee()->pc()->local_description());
1676 const ContentInfo* callee_audio_content =
1677 GetFirstAudioContent(callee()->pc()->local_description()->description());
1678 ASSERT_NE(nullptr, callee_audio_content);
1679 EXPECT_TRUE(callee_audio_content->rejected);
1680}
1681
1682// Test that if the answerer rejects the video m= section, no video is sent or
1683// received, but audio still can be.
1684TEST_F(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) {
1685 ASSERT_TRUE(CreatePeerConnectionWrappers());
1686 ConnectFakeSignaling();
1687 caller()->AddAudioVideoMediaStream();
1688 // Only add audio track for callee, and set offer_to_receive_video to 0, so
1689 // it will reject the video m= section completely.
1690 PeerConnectionInterface::RTCOfferAnswerOptions options;
1691 options.offer_to_receive_video = 0;
1692 callee()->SetOfferAnswerOptions(options);
1693 callee()->AddMediaStreamFromTracks(callee()->CreateLocalAudioTrack(),
1694 nullptr);
1695 // Do offer/answer and wait for successful end-to-end audio frames.
1696 caller()->CreateAndSetAndSignalOffer();
1697 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1698 ExpectNewFramesReceivedWithWait(kDefaultExpectedAudioFrameCount, 0,
1699 kDefaultExpectedAudioFrameCount, 0,
1700 kMaxWaitForFramesMs);
1701 // Shouldn't have received video frames at any point.
1702 EXPECT_EQ(0, caller()->total_video_frames_received());
1703 EXPECT_EQ(0, callee()->total_video_frames_received());
1704 // Sanity check that the callee's description has a rejected video section.
1705 ASSERT_NE(nullptr, callee()->pc()->local_description());
1706 const ContentInfo* callee_video_content =
1707 GetFirstVideoContent(callee()->pc()->local_description()->description());
1708 ASSERT_NE(nullptr, callee_video_content);
1709 EXPECT_TRUE(callee_video_content->rejected);
1710}
1711
1712// Test that if the answerer rejects both audio and video m= sections, nothing
1713// bad happens.
1714// TODO(deadbeef): Test that a data channel still works. Currently this doesn't
1715// test anything but the fact that negotiation succeeds, which doesn't mean
1716// much.
1717TEST_F(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) {
1718 ASSERT_TRUE(CreatePeerConnectionWrappers());
1719 ConnectFakeSignaling();
1720 caller()->AddAudioVideoMediaStream();
1721 // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it
1722 // will reject both audio and video m= sections.
1723 PeerConnectionInterface::RTCOfferAnswerOptions options;
1724 options.offer_to_receive_audio = 0;
1725 options.offer_to_receive_video = 0;
1726 callee()->SetOfferAnswerOptions(options);
1727 // Do offer/answer and wait for stable signaling state.
1728 caller()->CreateAndSetAndSignalOffer();
1729 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1730 // Sanity check that the callee's description has rejected m= sections.
1731 ASSERT_NE(nullptr, callee()->pc()->local_description());
1732 const ContentInfo* callee_audio_content =
1733 GetFirstAudioContent(callee()->pc()->local_description()->description());
1734 ASSERT_NE(nullptr, callee_audio_content);
1735 EXPECT_TRUE(callee_audio_content->rejected);
1736 const ContentInfo* callee_video_content =
1737 GetFirstVideoContent(callee()->pc()->local_description()->description());
1738 ASSERT_NE(nullptr, callee_video_content);
1739 EXPECT_TRUE(callee_video_content->rejected);
1740}
1741
1742// This test sets up an audio and video call between two parties. After the
1743// call runs for a while, the caller sends an updated offer with video being
1744// rejected. Once the re-negotiation is done, the video flow should stop and
1745// the audio flow should continue.
1746TEST_F(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) {
1747 ASSERT_TRUE(CreatePeerConnectionWrappers());
1748 ConnectFakeSignaling();
1749 caller()->AddAudioVideoMediaStream();
1750 callee()->AddAudioVideoMediaStream();
1751 caller()->CreateAndSetAndSignalOffer();
1752 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1753 ExpectNewFramesReceivedWithWait(
1754 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1755 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1756 kMaxWaitForFramesMs);
1757
1758 // Renegotiate, rejecting the video m= section.
1759 // TODO(deadbeef): When an RtpTransceiver API is available, use that to
1760 // reject the video m= section.
1761 caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) {
1762 for (cricket::ContentInfo& content : description->contents()) {
1763 if (cricket::IsVideoContent(&content)) {
1764 content.rejected = true;
1765 }
1766 }
1767 });
1768 caller()->CreateAndSetAndSignalOffer();
1769 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
1770
1771 // Sanity check that the caller's description has a rejected video section.
1772 ASSERT_NE(nullptr, caller()->pc()->local_description());
1773 const ContentInfo* caller_video_content =
1774 GetFirstVideoContent(caller()->pc()->local_description()->description());
1775 ASSERT_NE(nullptr, caller_video_content);
1776 EXPECT_TRUE(caller_video_content->rejected);
1777
1778 int caller_video_received = caller()->total_video_frames_received();
1779 int callee_video_received = callee()->total_video_frames_received();
1780
1781 // Wait for some additional audio frames to be received.
1782 ExpectNewFramesReceivedWithWait(kDefaultExpectedAudioFrameCount, 0,
1783 kDefaultExpectedAudioFrameCount, 0,
1784 kMaxWaitForFramesMs);
1785
1786 // During this time, we shouldn't have received any additional video frames
1787 // for the rejected video tracks.
1788 EXPECT_EQ(caller_video_received, caller()->total_video_frames_received());
1789 EXPECT_EQ(callee_video_received, callee()->total_video_frames_received());
1790}
1791
1792// Basic end-to-end test, but without SSRC/MSID signaling. This functionality
1793// is needed to support legacy endpoints.
1794// TODO(deadbeef): When we support the MID extension and demuxing on MID, also
1795// add a test for an end-to-end test without MID signaling either (basically,
1796// the minimum acceptable SDP).
1797TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) {
1798 ASSERT_TRUE(CreatePeerConnectionWrappers());
1799 ConnectFakeSignaling();
1800 // Add audio and video, testing that packets can be demuxed on payload type.
1801 caller()->AddAudioVideoMediaStream();
1802 callee()->AddAudioVideoMediaStream();
deadbeefd8ad7882017-04-18 16:01:17 -07001803 // Remove SSRCs and MSIDs from the received offer SDP.
1804 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
deadbeef1dcb1642017-03-29 21:08:16 -07001805 caller()->CreateAndSetAndSignalOffer();
1806 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1807 ExpectNewFramesReceivedWithWait(
1808 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1809 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1810 kMaxWaitForFramesMs);
1811}
1812
1813// Test that if two video tracks are sent (from caller to callee, in this test),
1814// they're transmitted correctly end-to-end.
1815TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) {
1816 ASSERT_TRUE(CreatePeerConnectionWrappers());
1817 ConnectFakeSignaling();
1818 // Add one audio/video stream, and one video-only stream.
1819 caller()->AddAudioVideoMediaStream();
deadbeefb1a15d72017-09-07 14:12:05 -07001820 caller()->AddVideoOnlyMediaStream();
deadbeef1dcb1642017-03-29 21:08:16 -07001821 caller()->CreateAndSetAndSignalOffer();
1822 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1823 ASSERT_EQ(2u, callee()->number_of_remote_streams());
1824 int expected_callee_received_frames = kDefaultExpectedVideoFrameCount;
1825 ExpectNewFramesReceivedWithWait(0, 0, 0, expected_callee_received_frames,
1826 kMaxWaitForFramesMs);
1827}
1828
1829static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) {
1830 bool first = true;
1831 for (cricket::ContentInfo& content : desc->contents()) {
1832 if (first) {
1833 first = false;
1834 continue;
1835 }
1836 content.bundle_only = true;
1837 }
1838 first = true;
1839 for (cricket::TransportInfo& transport : desc->transport_infos()) {
1840 if (first) {
1841 first = false;
1842 continue;
1843 }
1844 transport.description.ice_ufrag.clear();
1845 transport.description.ice_pwd.clear();
1846 transport.description.connection_role = cricket::CONNECTIONROLE_NONE;
1847 transport.description.identity_fingerprint.reset(nullptr);
1848 }
1849}
1850
1851// Test that if applying a true "max bundle" offer, which uses ports of 0,
1852// "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and
1853// "a=ice-pwd" for all but the audio "m=" section, negotiation still completes
1854// successfully and media flows.
1855// TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works.
1856// TODO(deadbeef): Won't need this test once we start generating actual
1857// standards-compliant SDP.
1858TEST_F(PeerConnectionIntegrationTest,
1859 EndToEndCallWithSpecCompliantMaxBundleOffer) {
1860 ASSERT_TRUE(CreatePeerConnectionWrappers());
1861 ConnectFakeSignaling();
1862 caller()->AddAudioVideoMediaStream();
1863 callee()->AddAudioVideoMediaStream();
1864 // Do the equivalent of setting the port to 0, adding a=bundle-only, and
1865 // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all
1866 // but the first m= section.
1867 callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer);
1868 caller()->CreateAndSetAndSignalOffer();
1869 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1870 ExpectNewFramesReceivedWithWait(
1871 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1872 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1873 kMaxWaitForFramesMs);
1874}
1875
1876// Test that we can receive the audio output level from a remote audio track.
1877// TODO(deadbeef): Use a fake audio source and verify that the output level is
1878// exactly what the source on the other side was configured with.
deadbeefd8ad7882017-04-18 16:01:17 -07001879TEST_F(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001880 ASSERT_TRUE(CreatePeerConnectionWrappers());
1881 ConnectFakeSignaling();
1882 // Just add an audio track.
1883 caller()->AddMediaStreamFromTracks(caller()->CreateLocalAudioTrack(),
1884 nullptr);
1885 caller()->CreateAndSetAndSignalOffer();
1886 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1887
1888 // Get the audio output level stats. Note that the level is not available
1889 // until an RTCP packet has been received.
deadbeefd8ad7882017-04-18 16:01:17 -07001890 EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0,
deadbeef1dcb1642017-03-29 21:08:16 -07001891 kMaxWaitForFramesMs);
1892}
1893
1894// Test that an audio input level is reported.
1895// TODO(deadbeef): Use a fake audio source and verify that the input level is
1896// exactly what the source was configured with.
deadbeefd8ad7882017-04-18 16:01:17 -07001897TEST_F(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001898 ASSERT_TRUE(CreatePeerConnectionWrappers());
1899 ConnectFakeSignaling();
1900 // Just add an audio track.
1901 caller()->AddMediaStreamFromTracks(caller()->CreateLocalAudioTrack(),
1902 nullptr);
1903 caller()->CreateAndSetAndSignalOffer();
1904 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1905
1906 // Get the audio input level stats. The level should be available very
1907 // soon after the test starts.
deadbeefd8ad7882017-04-18 16:01:17 -07001908 EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0,
deadbeef1dcb1642017-03-29 21:08:16 -07001909 kMaxWaitForStatsMs);
1910}
1911
1912// Test that we can get incoming byte counts from both audio and video tracks.
deadbeefd8ad7882017-04-18 16:01:17 -07001913TEST_F(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001914 ASSERT_TRUE(CreatePeerConnectionWrappers());
1915 ConnectFakeSignaling();
1916 caller()->AddAudioVideoMediaStream();
1917 // Do offer/answer, wait for the callee to receive some frames.
1918 caller()->CreateAndSetAndSignalOffer();
1919 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1920 int expected_caller_received_frames = 0;
1921 ExpectNewFramesReceivedWithWait(
1922 expected_caller_received_frames, expected_caller_received_frames,
1923 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1924 kMaxWaitForFramesMs);
1925
1926 // Get a handle to the remote tracks created, so they can be used as GetStats
1927 // filters.
1928 StreamCollectionInterface* remote_streams = callee()->remote_streams();
1929 ASSERT_EQ(1u, remote_streams->count());
1930 ASSERT_EQ(1u, remote_streams->at(0)->GetAudioTracks().size());
1931 ASSERT_EQ(1u, remote_streams->at(0)->GetVideoTracks().size());
1932 MediaStreamTrackInterface* remote_audio_track =
1933 remote_streams->at(0)->GetAudioTracks()[0];
1934 MediaStreamTrackInterface* remote_video_track =
1935 remote_streams->at(0)->GetVideoTracks()[0];
1936
1937 // We received frames, so we definitely should have nonzero "received bytes"
1938 // stats at this point.
deadbeefd8ad7882017-04-18 16:01:17 -07001939 EXPECT_GT(callee()->OldGetStatsForTrack(remote_audio_track)->BytesReceived(),
1940 0);
1941 EXPECT_GT(callee()->OldGetStatsForTrack(remote_video_track)->BytesReceived(),
1942 0);
deadbeef1dcb1642017-03-29 21:08:16 -07001943}
1944
1945// Test that we can get outgoing byte counts from both audio and video tracks.
deadbeefd8ad7882017-04-18 16:01:17 -07001946TEST_F(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07001947 ASSERT_TRUE(CreatePeerConnectionWrappers());
1948 ConnectFakeSignaling();
1949 auto audio_track = caller()->CreateLocalAudioTrack();
1950 auto video_track = caller()->CreateLocalVideoTrack();
1951 caller()->AddMediaStreamFromTracks(audio_track, video_track);
1952 // Do offer/answer, wait for the callee to receive some frames.
1953 caller()->CreateAndSetAndSignalOffer();
1954 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1955 int expected_caller_received_frames = 0;
1956 ExpectNewFramesReceivedWithWait(
1957 expected_caller_received_frames, expected_caller_received_frames,
1958 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
1959 kMaxWaitForFramesMs);
1960
1961 // The callee received frames, so we definitely should have nonzero "sent
1962 // bytes" stats at this point.
deadbeefd8ad7882017-04-18 16:01:17 -07001963 EXPECT_GT(caller()->OldGetStatsForTrack(audio_track)->BytesSent(), 0);
1964 EXPECT_GT(caller()->OldGetStatsForTrack(video_track)->BytesSent(), 0);
1965}
1966
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02001967// Test that we can get capture start ntp time.
1968TEST_F(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) {
1969 ASSERT_TRUE(CreatePeerConnectionWrappers());
1970 ConnectFakeSignaling();
1971 caller()->AddAudioOnlyMediaStream();
1972
1973 auto audio_track = callee()->CreateLocalAudioTrack();
1974 callee()->AddMediaStreamFromTracks(audio_track, nullptr);
1975
1976 // Do offer/answer, wait for the callee to receive some frames.
1977 caller()->CreateAndSetAndSignalOffer();
1978 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1979
1980 // Get the remote audio track created on the receiver, so they can be used as
1981 // GetStats filters.
1982 StreamCollectionInterface* remote_streams = callee()->remote_streams();
1983 ASSERT_EQ(1u, remote_streams->count());
1984 ASSERT_EQ(1u, remote_streams->at(0)->GetAudioTracks().size());
1985 MediaStreamTrackInterface* remote_audio_track =
1986 remote_streams->at(0)->GetAudioTracks()[0];
1987
1988 // Get the audio output level stats. Note that the level is not available
1989 // until an RTCP packet has been received.
1990 EXPECT_TRUE_WAIT(callee()->OldGetStatsForTrack(remote_audio_track)->
1991 CaptureStartNtpTime() > 0, 2 * kMaxWaitForFramesMs);
1992}
1993
deadbeefd8ad7882017-04-18 16:01:17 -07001994// Test that we can get stats (using the new stats implemnetation) for
1995// unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in
1996// SDP.
1997TEST_F(PeerConnectionIntegrationTest,
1998 GetStatsForUnsignaledStreamWithNewStatsApi) {
1999 ASSERT_TRUE(CreatePeerConnectionWrappers());
2000 ConnectFakeSignaling();
2001 caller()->AddAudioOnlyMediaStream();
2002 // Remove SSRCs and MSIDs from the received offer SDP.
2003 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
2004 caller()->CreateAndSetAndSignalOffer();
2005 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2006 // Wait for one audio frame to be received by the callee.
2007 ExpectNewFramesReceivedWithWait(0, 0, 1, 0, kMaxWaitForFramesMs);
2008
2009 // We received a frame, so we should have nonzero "bytes received" stats for
2010 // the unsignaled stream, if stats are working for it.
2011 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
2012 callee()->NewGetStats();
2013 ASSERT_NE(nullptr, report);
2014 auto inbound_stream_stats =
2015 report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
2016 ASSERT_EQ(1U, inbound_stream_stats.size());
2017 ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined());
2018 ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U);
zhihuangf8164932017-05-19 13:09:47 -07002019 ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined());
2020}
2021
2022// Test that we can successfully get the media related stats (audio level
2023// etc.) for the unsignaled stream.
2024TEST_F(PeerConnectionIntegrationTest,
2025 GetMediaStatsForUnsignaledStreamWithNewStatsApi) {
2026 ASSERT_TRUE(CreatePeerConnectionWrappers());
2027 ConnectFakeSignaling();
2028 caller()->AddAudioVideoMediaStream();
2029 // Remove SSRCs and MSIDs from the received offer SDP.
2030 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
2031 caller()->CreateAndSetAndSignalOffer();
2032 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2033 // Wait for one audio frame to be received by the callee.
2034 ExpectNewFramesReceivedWithWait(0, 0, 1, 1, kMaxWaitForFramesMs);
2035
2036 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
2037 callee()->NewGetStats();
2038 ASSERT_NE(nullptr, report);
2039
2040 auto media_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>();
2041 auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats);
2042 ASSERT_GE(audio_index, 0);
2043 EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined());
deadbeef1dcb1642017-03-29 21:08:16 -07002044}
2045
deadbeef4e2deab2017-09-20 13:56:21 -07002046// Helper for test below.
2047void ModifySsrcs(cricket::SessionDescription* desc) {
2048 for (ContentInfo& content : desc->contents()) {
2049 MediaContentDescription* media_desc =
2050 static_cast<MediaContentDescription*>(content.description);
2051 for (cricket::StreamParams& stream : media_desc->mutable_streams()) {
2052 for (uint32_t& ssrc : stream.ssrcs) {
2053 ssrc = rtc::CreateRandomId();
2054 }
2055 }
2056 }
2057}
2058
2059// Test that the "RTCMediaSteamTrackStats" object is updated correctly when
2060// SSRCs are unsignaled, and the SSRC of the received (audio) stream changes.
2061// This should result in two "RTCInboundRTPStreamStats", but only one
2062// "RTCMediaStreamTrackStats", whose counters go up continuously rather than
2063// being reset to 0 once the SSRC change occurs.
2064//
2065// Regression test for this bug:
2066// https://bugs.chromium.org/p/webrtc/issues/detail?id=8158
2067//
2068// The bug causes the track stats to only represent one of the two streams:
2069// whichever one has the higher SSRC. So with this bug, there was a 50% chance
2070// that the track stat counters would reset to 0 when the new stream is
2071// received, and a 50% chance that they'll stop updating (while
2072// "concealed_samples" continues increasing, due to silence being generated for
2073// the inactive stream).
2074TEST_F(PeerConnectionIntegrationTest,
2075 TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) {
2076 ASSERT_TRUE(CreatePeerConnectionWrappers());
2077 ConnectFakeSignaling();
2078 caller()->AddAudioOnlyMediaStream();
2079 // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint
2080 // that doesn't signal SSRCs (from the callee's perspective).
2081 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
2082 caller()->CreateAndSetAndSignalOffer();
2083 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2084 // Wait for 50 audio frames (500ms of audio) to be received by the callee.
2085 ExpectNewFramesReceivedWithWait(0, 0, 25, 0, kMaxWaitForFramesMs);
2086
2087 // Some audio frames were received, so we should have nonzero "samples
2088 // received" for the track.
2089 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
2090 callee()->NewGetStats();
2091 ASSERT_NE(nullptr, report);
2092 auto track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>();
2093 ASSERT_EQ(1U, track_stats.size());
2094 ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined());
2095 ASSERT_GT(*track_stats[0]->total_samples_received, 0U);
2096 // uint64_t prev_samples_received = *track_stats[0]->total_samples_received;
2097
2098 // Create a new offer and munge it to cause the caller to use a new SSRC.
2099 caller()->SetGeneratedSdpMunger(ModifySsrcs);
2100 caller()->CreateAndSetAndSignalOffer();
2101 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2102 // Wait for 25 more audio frames (250ms of audio) to be received, from the new
2103 // SSRC.
2104 ExpectNewFramesReceivedWithWait(0, 0, 25, 0, kMaxWaitForFramesMs);
2105
2106 report = callee()->NewGetStats();
2107 ASSERT_NE(nullptr, report);
2108 track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>();
2109 ASSERT_EQ(1U, track_stats.size());
2110 ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined());
2111 // The "total samples received" stat should only be greater than it was
2112 // before.
2113 // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed.
2114 // Right now, the new SSRC will cause the counters to reset to 0.
2115 // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received);
2116
2117 // Additionally, the percentage of concealed samples (samples generated to
2118 // conceal packet loss) should be less than 25%%. If it's greater, that's a
2119 // good sign that we're seeing stats from the old stream that's no longer
2120 // receiving packets, and is generating concealed samples of silence.
2121 constexpr double kAcceptableConcealedSamplesPercentage = 0.25;
2122 ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined());
2123 EXPECT_LT(*track_stats[0]->concealed_samples,
2124 *track_stats[0]->total_samples_received *
2125 kAcceptableConcealedSamplesPercentage);
2126
2127 // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a
2128 // sanity check that the SSRC really changed.
2129 // TODO(deadbeef): This isn't working right now, because we're not returning
2130 // *any* stats for the inactive stream. Uncomment when the bug is completely
2131 // fixed.
2132 // auto inbound_stream_stats =
2133 // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
2134 // ASSERT_EQ(2U, inbound_stream_stats.size());
2135}
2136
deadbeef1dcb1642017-03-29 21:08:16 -07002137// Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
2138TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) {
2139 PeerConnectionFactory::Options dtls_10_options;
2140 dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2141 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options,
2142 dtls_10_options));
2143 ConnectFakeSignaling();
2144 // Do normal offer/answer and wait for some frames to be received in each
2145 // direction.
2146 caller()->AddAudioVideoMediaStream();
2147 callee()->AddAudioVideoMediaStream();
2148 caller()->CreateAndSetAndSignalOffer();
2149 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2150 ExpectNewFramesReceivedWithWait(
2151 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2152 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2153 kMaxWaitForFramesMs);
2154}
2155
2156// Test getting cipher stats and UMA metrics when DTLS 1.0 is negotiated.
2157TEST_F(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) {
2158 PeerConnectionFactory::Options dtls_10_options;
2159 dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2160 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options,
2161 dtls_10_options));
2162 ConnectFakeSignaling();
2163 // Register UMA observer before signaling begins.
2164 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
2165 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
2166 caller()->pc()->RegisterUMAObserver(caller_observer);
2167 caller()->AddAudioVideoMediaStream();
2168 callee()->AddAudioVideoMediaStream();
2169 caller()->CreateAndSetAndSignalOffer();
2170 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2171 EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher(
deadbeefd8ad7882017-04-18 16:01:17 -07002172 caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT),
deadbeef1dcb1642017-03-29 21:08:16 -07002173 kDefaultTimeout);
2174 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
deadbeefd8ad7882017-04-18 16:01:17 -07002175 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07002176 EXPECT_EQ(1,
2177 caller_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
2178 kDefaultSrtpCryptoSuite));
2179}
2180
2181// Test getting cipher stats and UMA metrics when DTLS 1.2 is negotiated.
2182TEST_F(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) {
2183 PeerConnectionFactory::Options dtls_12_options;
2184 dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
2185 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options,
2186 dtls_12_options));
2187 ConnectFakeSignaling();
2188 // Register UMA observer before signaling begins.
2189 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
2190 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
2191 caller()->pc()->RegisterUMAObserver(caller_observer);
2192 caller()->AddAudioVideoMediaStream();
2193 callee()->AddAudioVideoMediaStream();
2194 caller()->CreateAndSetAndSignalOffer();
2195 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2196 EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher(
deadbeefd8ad7882017-04-18 16:01:17 -07002197 caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT),
deadbeef1dcb1642017-03-29 21:08:16 -07002198 kDefaultTimeout);
2199 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
deadbeefd8ad7882017-04-18 16:01:17 -07002200 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07002201 EXPECT_EQ(1,
2202 caller_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
2203 kDefaultSrtpCryptoSuite));
2204}
2205
2206// Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the
2207// callee only supports 1.0.
2208TEST_F(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) {
2209 PeerConnectionFactory::Options caller_options;
2210 caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
2211 PeerConnectionFactory::Options callee_options;
2212 callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2213 ASSERT_TRUE(
2214 CreatePeerConnectionWrappersWithOptions(caller_options, callee_options));
2215 ConnectFakeSignaling();
2216 // Do normal offer/answer and wait for some frames to be received in each
2217 // direction.
2218 caller()->AddAudioVideoMediaStream();
2219 callee()->AddAudioVideoMediaStream();
2220 caller()->CreateAndSetAndSignalOffer();
2221 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2222 ExpectNewFramesReceivedWithWait(
2223 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2224 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2225 kMaxWaitForFramesMs);
2226}
2227
2228// Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the
2229// callee supports 1.2.
2230TEST_F(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) {
2231 PeerConnectionFactory::Options caller_options;
2232 caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2233 PeerConnectionFactory::Options callee_options;
2234 callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
2235 ASSERT_TRUE(
2236 CreatePeerConnectionWrappersWithOptions(caller_options, callee_options));
2237 ConnectFakeSignaling();
2238 // Do normal offer/answer and wait for some frames to be received in each
2239 // direction.
2240 caller()->AddAudioVideoMediaStream();
2241 callee()->AddAudioVideoMediaStream();
2242 caller()->CreateAndSetAndSignalOffer();
2243 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2244 ExpectNewFramesReceivedWithWait(
2245 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2246 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2247 kMaxWaitForFramesMs);
2248}
2249
2250// Test that a non-GCM cipher is used if both sides only support non-GCM.
2251TEST_F(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) {
2252 bool local_gcm_enabled = false;
2253 bool remote_gcm_enabled = false;
2254 int expected_cipher_suite = kDefaultSrtpCryptoSuite;
2255 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2256 expected_cipher_suite);
2257}
2258
2259// Test that a GCM cipher is used if both ends support it.
2260TEST_F(PeerConnectionIntegrationTest, GcmCipherUsedWhenGcmSupported) {
2261 bool local_gcm_enabled = true;
2262 bool remote_gcm_enabled = true;
2263 int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm;
2264 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2265 expected_cipher_suite);
2266}
2267
2268// Test that GCM isn't used if only the offerer supports it.
2269TEST_F(PeerConnectionIntegrationTest,
2270 NonGcmCipherUsedWhenOnlyCallerSupportsGcm) {
2271 bool local_gcm_enabled = true;
2272 bool remote_gcm_enabled = false;
2273 int expected_cipher_suite = kDefaultSrtpCryptoSuite;
2274 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2275 expected_cipher_suite);
2276}
2277
2278// Test that GCM isn't used if only the answerer supports it.
2279TEST_F(PeerConnectionIntegrationTest,
2280 NonGcmCipherUsedWhenOnlyCalleeSupportsGcm) {
2281 bool local_gcm_enabled = false;
2282 bool remote_gcm_enabled = true;
2283 int expected_cipher_suite = kDefaultSrtpCryptoSuite;
2284 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2285 expected_cipher_suite);
2286}
2287
deadbeef7914b8c2017-04-21 03:23:33 -07002288// Verify that media can be transmitted end-to-end when GCM crypto suites are
2289// enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported,
2290// only verify that a GCM cipher is negotiated, and not necessarily that SRTP
2291// works with it.
2292TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) {
2293 PeerConnectionFactory::Options gcm_options;
2294 gcm_options.crypto_options.enable_gcm_crypto_suites = true;
2295 ASSERT_TRUE(
2296 CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options));
2297 ConnectFakeSignaling();
2298 // Do normal offer/answer and wait for some frames to be received in each
2299 // direction.
2300 caller()->AddAudioVideoMediaStream();
2301 callee()->AddAudioVideoMediaStream();
2302 caller()->CreateAndSetAndSignalOffer();
2303 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2304 ExpectNewFramesReceivedWithWait(
2305 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2306 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2307 kMaxWaitForFramesMs);
2308}
2309
deadbeef1dcb1642017-03-29 21:08:16 -07002310// This test sets up a call between two parties with audio, video and an RTP
2311// data channel.
2312TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithRtpDataChannel) {
2313 FakeConstraints setup_constraints;
2314 setup_constraints.SetAllowRtpDataChannels();
2315 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(&setup_constraints,
2316 &setup_constraints));
2317 ConnectFakeSignaling();
2318 // Expect that data channel created on caller side will show up for callee as
2319 // well.
2320 caller()->CreateDataChannel();
2321 caller()->AddAudioVideoMediaStream();
2322 callee()->AddAudioVideoMediaStream();
2323 caller()->CreateAndSetAndSignalOffer();
2324 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2325 // Ensure the existence of the RTP data channel didn't impede audio/video.
2326 ExpectNewFramesReceivedWithWait(
2327 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2328 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2329 kMaxWaitForFramesMs);
2330 ASSERT_NE(nullptr, caller()->data_channel());
2331 ASSERT_NE(nullptr, callee()->data_channel());
2332 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2333 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2334
2335 // Ensure data can be sent in both directions.
2336 std::string data = "hello world";
2337 SendRtpDataWithRetries(caller()->data_channel(), data, 5);
2338 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
2339 kDefaultTimeout);
2340 SendRtpDataWithRetries(callee()->data_channel(), data, 5);
2341 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
2342 kDefaultTimeout);
2343}
2344
2345// Ensure that an RTP data channel is signaled as closed for the caller when
2346// the callee rejects it in a subsequent offer.
2347TEST_F(PeerConnectionIntegrationTest,
2348 RtpDataChannelSignaledClosedInCalleeOffer) {
2349 // Same procedure as above test.
2350 FakeConstraints setup_constraints;
2351 setup_constraints.SetAllowRtpDataChannels();
2352 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(&setup_constraints,
2353 &setup_constraints));
2354 ConnectFakeSignaling();
2355 caller()->CreateDataChannel();
2356 caller()->AddAudioVideoMediaStream();
2357 callee()->AddAudioVideoMediaStream();
2358 caller()->CreateAndSetAndSignalOffer();
2359 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2360 ASSERT_NE(nullptr, caller()->data_channel());
2361 ASSERT_NE(nullptr, callee()->data_channel());
2362 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2363 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2364
2365 // Close the data channel on the callee, and do an updated offer/answer.
2366 callee()->data_channel()->Close();
2367 callee()->CreateAndSetAndSignalOffer();
2368 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2369 EXPECT_FALSE(caller()->data_observer()->IsOpen());
2370 EXPECT_FALSE(callee()->data_observer()->IsOpen());
2371}
2372
2373// Tests that data is buffered in an RTP data channel until an observer is
2374// registered for it.
2375//
2376// NOTE: RTP data channels can receive data before the underlying
2377// transport has detected that a channel is writable and thus data can be
2378// received before the data channel state changes to open. That is hard to test
2379// but the same buffering is expected to be used in that case.
2380TEST_F(PeerConnectionIntegrationTest,
2381 DataBufferedUntilRtpDataChannelObserverRegistered) {
2382 // Use fake clock and simulated network delay so that we predictably can wait
2383 // until an SCTP message has been delivered without "sleep()"ing.
2384 rtc::ScopedFakeClock fake_clock;
2385 // Some things use a time of "0" as a special value, so we need to start out
2386 // the fake clock at a nonzero time.
2387 // TODO(deadbeef): Fix this.
2388 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
2389 virtual_socket_server()->set_delay_mean(5); // 5 ms per hop.
2390 virtual_socket_server()->UpdateDelayDistribution();
2391
2392 FakeConstraints constraints;
2393 constraints.SetAllowRtpDataChannels();
2394 ASSERT_TRUE(
2395 CreatePeerConnectionWrappersWithConstraints(&constraints, &constraints));
2396 ConnectFakeSignaling();
2397 caller()->CreateDataChannel();
2398 caller()->CreateAndSetAndSignalOffer();
2399 ASSERT_TRUE(caller()->data_channel() != nullptr);
2400 ASSERT_TRUE_SIMULATED_WAIT(callee()->data_channel() != nullptr,
2401 kDefaultTimeout, fake_clock);
2402 ASSERT_TRUE_SIMULATED_WAIT(caller()->data_observer()->IsOpen(),
2403 kDefaultTimeout, fake_clock);
2404 ASSERT_EQ_SIMULATED_WAIT(DataChannelInterface::kOpen,
2405 callee()->data_channel()->state(), kDefaultTimeout,
2406 fake_clock);
2407
2408 // Unregister the observer which is normally automatically registered.
2409 callee()->data_channel()->UnregisterObserver();
2410 // Send data and advance fake clock until it should have been received.
2411 std::string data = "hello world";
2412 caller()->data_channel()->Send(DataBuffer(data));
2413 SIMULATED_WAIT(false, 50, fake_clock);
2414
2415 // Attach data channel and expect data to be received immediately. Note that
2416 // EXPECT_EQ_WAIT is used, such that the simulated clock is not advanced any
2417 // further, but data can be received even if the callback is asynchronous.
2418 MockDataChannelObserver new_observer(callee()->data_channel());
2419 EXPECT_EQ_SIMULATED_WAIT(data, new_observer.last_message(), kDefaultTimeout,
2420 fake_clock);
2421}
2422
2423// This test sets up a call between two parties with audio, video and but only
2424// the caller client supports RTP data channels.
2425TEST_F(PeerConnectionIntegrationTest, RtpDataChannelsRejectedByCallee) {
2426 FakeConstraints setup_constraints_1;
2427 setup_constraints_1.SetAllowRtpDataChannels();
2428 // Must disable DTLS to make negotiation succeed.
2429 setup_constraints_1.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
2430 false);
2431 FakeConstraints setup_constraints_2;
2432 setup_constraints_2.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
2433 false);
2434 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(
2435 &setup_constraints_1, &setup_constraints_2));
2436 ConnectFakeSignaling();
2437 caller()->CreateDataChannel();
2438 caller()->AddAudioVideoMediaStream();
2439 callee()->AddAudioVideoMediaStream();
2440 caller()->CreateAndSetAndSignalOffer();
2441 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2442 // The caller should still have a data channel, but it should be closed, and
2443 // one should ever have been created for the callee.
2444 EXPECT_TRUE(caller()->data_channel() != nullptr);
2445 EXPECT_FALSE(caller()->data_observer()->IsOpen());
2446 EXPECT_EQ(nullptr, callee()->data_channel());
2447}
2448
2449// This test sets up a call between two parties with audio, and video. When
2450// audio and video is setup and flowing, an RTP data channel is negotiated.
2451TEST_F(PeerConnectionIntegrationTest, AddRtpDataChannelInSubsequentOffer) {
2452 FakeConstraints setup_constraints;
2453 setup_constraints.SetAllowRtpDataChannels();
2454 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(&setup_constraints,
2455 &setup_constraints));
2456 ConnectFakeSignaling();
2457 // Do initial offer/answer with audio/video.
2458 caller()->AddAudioVideoMediaStream();
2459 callee()->AddAudioVideoMediaStream();
2460 caller()->CreateAndSetAndSignalOffer();
2461 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2462 // Create data channel and do new offer and answer.
2463 caller()->CreateDataChannel();
2464 caller()->CreateAndSetAndSignalOffer();
2465 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2466 ASSERT_NE(nullptr, caller()->data_channel());
2467 ASSERT_NE(nullptr, callee()->data_channel());
2468 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2469 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2470 // Ensure data can be sent in both directions.
2471 std::string data = "hello world";
2472 SendRtpDataWithRetries(caller()->data_channel(), data, 5);
2473 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
2474 kDefaultTimeout);
2475 SendRtpDataWithRetries(callee()->data_channel(), data, 5);
2476 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
2477 kDefaultTimeout);
2478}
2479
2480#ifdef HAVE_SCTP
2481
2482// This test sets up a call between two parties with audio, video and an SCTP
2483// data channel.
2484TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithSctpDataChannel) {
2485 ASSERT_TRUE(CreatePeerConnectionWrappers());
2486 ConnectFakeSignaling();
2487 // Expect that data channel created on caller side will show up for callee as
2488 // well.
2489 caller()->CreateDataChannel();
2490 caller()->AddAudioVideoMediaStream();
2491 callee()->AddAudioVideoMediaStream();
2492 caller()->CreateAndSetAndSignalOffer();
2493 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2494 // Ensure the existence of the SCTP data channel didn't impede audio/video.
2495 ExpectNewFramesReceivedWithWait(
2496 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2497 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2498 kMaxWaitForFramesMs);
2499 // Caller data channel should already exist (it created one). Callee data
2500 // channel may not exist yet, since negotiation happens in-band, not in SDP.
2501 ASSERT_NE(nullptr, caller()->data_channel());
2502 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
2503 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2504 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2505
2506 // Ensure data can be sent in both directions.
2507 std::string data = "hello world";
2508 caller()->data_channel()->Send(DataBuffer(data));
2509 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
2510 kDefaultTimeout);
2511 callee()->data_channel()->Send(DataBuffer(data));
2512 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
2513 kDefaultTimeout);
2514}
2515
2516// Ensure that when the callee closes an SCTP data channel, the closing
2517// procedure results in the data channel being closed for the caller as well.
2518TEST_F(PeerConnectionIntegrationTest, CalleeClosesSctpDataChannel) {
2519 // Same procedure as above test.
2520 ASSERT_TRUE(CreatePeerConnectionWrappers());
2521 ConnectFakeSignaling();
2522 caller()->CreateDataChannel();
2523 caller()->AddAudioVideoMediaStream();
2524 callee()->AddAudioVideoMediaStream();
2525 caller()->CreateAndSetAndSignalOffer();
2526 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2527 ASSERT_NE(nullptr, caller()->data_channel());
2528 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
2529 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2530 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2531
2532 // Close the data channel on the callee side, and wait for it to reach the
2533 // "closed" state on both sides.
2534 callee()->data_channel()->Close();
2535 EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout);
2536 EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout);
2537}
2538
2539// Test usrsctp's ability to process unordered data stream, where data actually
2540// arrives out of order using simulated delays. Previously there have been some
2541// bugs in this area.
2542TEST_F(PeerConnectionIntegrationTest, StressTestUnorderedSctpDataChannel) {
2543 // Introduce random network delays.
2544 // Otherwise it's not a true "unordered" test.
2545 virtual_socket_server()->set_delay_mean(20);
2546 virtual_socket_server()->set_delay_stddev(5);
2547 virtual_socket_server()->UpdateDelayDistribution();
2548 // Normal procedure, but with unordered data channel config.
2549 ASSERT_TRUE(CreatePeerConnectionWrappers());
2550 ConnectFakeSignaling();
2551 webrtc::DataChannelInit init;
2552 init.ordered = false;
2553 caller()->CreateDataChannel(&init);
2554 caller()->CreateAndSetAndSignalOffer();
2555 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2556 ASSERT_NE(nullptr, caller()->data_channel());
2557 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
2558 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2559 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2560
2561 static constexpr int kNumMessages = 100;
2562 // Deliberately chosen to be larger than the MTU so messages get fragmented.
2563 static constexpr size_t kMaxMessageSize = 4096;
2564 // Create and send random messages.
2565 std::vector<std::string> sent_messages;
2566 for (int i = 0; i < kNumMessages; ++i) {
2567 size_t length =
2568 (rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand)
2569 std::string message;
2570 ASSERT_TRUE(rtc::CreateRandomString(length, &message));
2571 caller()->data_channel()->Send(DataBuffer(message));
2572 callee()->data_channel()->Send(DataBuffer(message));
2573 sent_messages.push_back(message);
2574 }
2575
2576 // Wait for all messages to be received.
2577 EXPECT_EQ_WAIT(kNumMessages,
2578 caller()->data_observer()->received_message_count(),
2579 kDefaultTimeout);
2580 EXPECT_EQ_WAIT(kNumMessages,
2581 callee()->data_observer()->received_message_count(),
2582 kDefaultTimeout);
2583
2584 // Sort and compare to make sure none of the messages were corrupted.
2585 std::vector<std::string> caller_received_messages =
2586 caller()->data_observer()->messages();
2587 std::vector<std::string> callee_received_messages =
2588 callee()->data_observer()->messages();
2589 std::sort(sent_messages.begin(), sent_messages.end());
2590 std::sort(caller_received_messages.begin(), caller_received_messages.end());
2591 std::sort(callee_received_messages.begin(), callee_received_messages.end());
2592 EXPECT_EQ(sent_messages, caller_received_messages);
2593 EXPECT_EQ(sent_messages, callee_received_messages);
2594}
2595
2596// This test sets up a call between two parties with audio, and video. When
2597// audio and video are setup and flowing, an SCTP data channel is negotiated.
2598TEST_F(PeerConnectionIntegrationTest, AddSctpDataChannelInSubsequentOffer) {
2599 ASSERT_TRUE(CreatePeerConnectionWrappers());
2600 ConnectFakeSignaling();
2601 // Do initial offer/answer with audio/video.
2602 caller()->AddAudioVideoMediaStream();
2603 callee()->AddAudioVideoMediaStream();
2604 caller()->CreateAndSetAndSignalOffer();
2605 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2606 // Create data channel and do new offer and answer.
2607 caller()->CreateDataChannel();
2608 caller()->CreateAndSetAndSignalOffer();
2609 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2610 // Caller data channel should already exist (it created one). Callee data
2611 // channel may not exist yet, since negotiation happens in-band, not in SDP.
2612 ASSERT_NE(nullptr, caller()->data_channel());
2613 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
2614 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2615 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2616 // Ensure data can be sent in both directions.
2617 std::string data = "hello world";
2618 caller()->data_channel()->Send(DataBuffer(data));
2619 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
2620 kDefaultTimeout);
2621 callee()->data_channel()->Send(DataBuffer(data));
2622 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
2623 kDefaultTimeout);
2624}
2625
deadbeef7914b8c2017-04-21 03:23:33 -07002626// Set up a connection initially just using SCTP data channels, later upgrading
2627// to audio/video, ensuring frames are received end-to-end. Effectively the
2628// inverse of the test above.
2629// This was broken in M57; see https://crbug.com/711243
2630TEST_F(PeerConnectionIntegrationTest, SctpDataChannelToAudioVideoUpgrade) {
2631 ASSERT_TRUE(CreatePeerConnectionWrappers());
2632 ConnectFakeSignaling();
2633 // Do initial offer/answer with just data channel.
2634 caller()->CreateDataChannel();
2635 caller()->CreateAndSetAndSignalOffer();
2636 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2637 // Wait until data can be sent over the data channel.
2638 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
2639 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2640 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2641
2642 // Do subsequent offer/answer with two-way audio and video. Audio and video
2643 // should end up bundled on the DTLS/ICE transport already used for data.
2644 caller()->AddAudioVideoMediaStream();
2645 callee()->AddAudioVideoMediaStream();
2646 caller()->CreateAndSetAndSignalOffer();
2647 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2648 ExpectNewFramesReceivedWithWait(
2649 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2650 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2651 kMaxWaitForFramesMs);
2652}
2653
deadbeef8b7e9ad2017-05-25 09:38:55 -07002654static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) {
2655 const ContentInfo* dc_offer = GetFirstDataContent(desc);
2656 ASSERT_NE(nullptr, dc_offer);
2657 cricket::DataContentDescription* dcd_offer =
2658 static_cast<cricket::DataContentDescription*>(dc_offer->description);
2659 dcd_offer->set_use_sctpmap(false);
2660 dcd_offer->set_protocol("UDP/DTLS/SCTP");
2661}
2662
2663// Test that the data channel works when a spec-compliant SCTP m= section is
2664// offered (using "a=sctp-port" instead of "a=sctpmap", and using
2665// "UDP/DTLS/SCTP" as the protocol).
2666TEST_F(PeerConnectionIntegrationTest,
2667 DataChannelWorksWhenSpecCompliantSctpOfferReceived) {
2668 ASSERT_TRUE(CreatePeerConnectionWrappers());
2669 ConnectFakeSignaling();
2670 caller()->CreateDataChannel();
2671 caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer);
2672 caller()->CreateAndSetAndSignalOffer();
2673 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2674 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
2675 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2676 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2677
2678 // Ensure data can be sent in both directions.
2679 std::string data = "hello world";
2680 caller()->data_channel()->Send(DataBuffer(data));
2681 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
2682 kDefaultTimeout);
2683 callee()->data_channel()->Send(DataBuffer(data));
2684 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
2685 kDefaultTimeout);
2686}
2687
deadbeef1dcb1642017-03-29 21:08:16 -07002688#endif // HAVE_SCTP
2689
2690// Test that the ICE connection and gathering states eventually reach
2691// "complete".
2692TEST_F(PeerConnectionIntegrationTest, IceStatesReachCompletion) {
2693 ASSERT_TRUE(CreatePeerConnectionWrappers());
2694 ConnectFakeSignaling();
2695 // Do normal offer/answer.
2696 caller()->AddAudioVideoMediaStream();
2697 callee()->AddAudioVideoMediaStream();
2698 caller()->CreateAndSetAndSignalOffer();
2699 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2700 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
2701 caller()->ice_gathering_state(), kMaxWaitForFramesMs);
2702 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
2703 callee()->ice_gathering_state(), kMaxWaitForFramesMs);
2704 // After the best candidate pair is selected and all candidates are signaled,
2705 // the ICE connection state should reach "complete".
2706 // TODO(deadbeef): Currently, the ICE "controlled" agent (the
2707 // answerer/"callee" by default) only reaches "connected". When this is
2708 // fixed, this test should be updated.
2709 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2710 caller()->ice_connection_state(), kDefaultTimeout);
2711 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2712 callee()->ice_connection_state(), kDefaultTimeout);
2713}
2714
2715// This test sets up a call between two parties with audio and video.
2716// During the call, the caller restarts ICE and the test verifies that
2717// new ICE candidates are generated and audio and video still can flow, and the
2718// ICE state reaches completed again.
2719TEST_F(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) {
2720 ASSERT_TRUE(CreatePeerConnectionWrappers());
2721 ConnectFakeSignaling();
2722 // Do normal offer/answer and wait for ICE to complete.
2723 caller()->AddAudioVideoMediaStream();
2724 callee()->AddAudioVideoMediaStream();
2725 caller()->CreateAndSetAndSignalOffer();
2726 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2727 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2728 caller()->ice_connection_state(), kMaxWaitForFramesMs);
2729 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2730 callee()->ice_connection_state(), kMaxWaitForFramesMs);
2731
2732 // To verify that the ICE restart actually occurs, get
2733 // ufrag/password/candidates before and after restart.
2734 // Create an SDP string of the first audio candidate for both clients.
2735 const webrtc::IceCandidateCollection* audio_candidates_caller =
2736 caller()->pc()->local_description()->candidates(0);
2737 const webrtc::IceCandidateCollection* audio_candidates_callee =
2738 callee()->pc()->local_description()->candidates(0);
2739 ASSERT_GT(audio_candidates_caller->count(), 0u);
2740 ASSERT_GT(audio_candidates_callee->count(), 0u);
2741 std::string caller_candidate_pre_restart;
2742 ASSERT_TRUE(
2743 audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart));
2744 std::string callee_candidate_pre_restart;
2745 ASSERT_TRUE(
2746 audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart));
2747 const cricket::SessionDescription* desc =
2748 caller()->pc()->local_description()->description();
2749 std::string caller_ufrag_pre_restart =
2750 desc->transport_infos()[0].description.ice_ufrag;
2751 desc = callee()->pc()->local_description()->description();
2752 std::string callee_ufrag_pre_restart =
2753 desc->transport_infos()[0].description.ice_ufrag;
2754
2755 // Have the caller initiate an ICE restart.
2756 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
2757 caller()->CreateAndSetAndSignalOffer();
2758 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2759 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2760 caller()->ice_connection_state(), kMaxWaitForFramesMs);
2761 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2762 callee()->ice_connection_state(), kMaxWaitForFramesMs);
2763
2764 // Grab the ufrags/candidates again.
2765 audio_candidates_caller = caller()->pc()->local_description()->candidates(0);
2766 audio_candidates_callee = callee()->pc()->local_description()->candidates(0);
2767 ASSERT_GT(audio_candidates_caller->count(), 0u);
2768 ASSERT_GT(audio_candidates_callee->count(), 0u);
2769 std::string caller_candidate_post_restart;
2770 ASSERT_TRUE(
2771 audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart));
2772 std::string callee_candidate_post_restart;
2773 ASSERT_TRUE(
2774 audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart));
2775 desc = caller()->pc()->local_description()->description();
2776 std::string caller_ufrag_post_restart =
2777 desc->transport_infos()[0].description.ice_ufrag;
2778 desc = callee()->pc()->local_description()->description();
2779 std::string callee_ufrag_post_restart =
2780 desc->transport_infos()[0].description.ice_ufrag;
2781 // Sanity check that an ICE restart was actually negotiated in SDP.
2782 ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart);
2783 ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart);
2784 ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart);
2785 ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart);
2786
2787 // Ensure that additional frames are received after the ICE restart.
2788 ExpectNewFramesReceivedWithWait(
2789 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2790 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2791 kMaxWaitForFramesMs);
2792}
2793
2794// Verify that audio/video can be received end-to-end when ICE renomination is
2795// enabled.
2796TEST_F(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) {
2797 PeerConnectionInterface::RTCConfiguration config;
2798 config.enable_ice_renomination = true;
2799 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
2800 ConnectFakeSignaling();
2801 // Do normal offer/answer and wait for some frames to be received in each
2802 // direction.
2803 caller()->AddAudioVideoMediaStream();
2804 callee()->AddAudioVideoMediaStream();
2805 caller()->CreateAndSetAndSignalOffer();
2806 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2807 // Sanity check that ICE renomination was actually negotiated.
2808 const cricket::SessionDescription* desc =
2809 caller()->pc()->local_description()->description();
2810 for (const cricket::TransportInfo& info : desc->transport_infos()) {
deadbeef30952b42017-04-21 02:41:29 -07002811 ASSERT_NE(
2812 info.description.transport_options.end(),
2813 std::find(info.description.transport_options.begin(),
2814 info.description.transport_options.end(), "renomination"));
deadbeef1dcb1642017-03-29 21:08:16 -07002815 }
2816 desc = callee()->pc()->local_description()->description();
2817 for (const cricket::TransportInfo& info : desc->transport_infos()) {
deadbeef30952b42017-04-21 02:41:29 -07002818 ASSERT_NE(
2819 info.description.transport_options.end(),
2820 std::find(info.description.transport_options.begin(),
2821 info.description.transport_options.end(), "renomination"));
deadbeef1dcb1642017-03-29 21:08:16 -07002822 }
2823 ExpectNewFramesReceivedWithWait(
2824 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2825 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2826 kMaxWaitForFramesMs);
2827}
2828
2829// This test sets up a call between two parties with audio and video. It then
2830// renegotiates setting the video m-line to "port 0", then later renegotiates
2831// again, enabling video.
2832TEST_F(PeerConnectionIntegrationTest,
2833 VideoFlowsAfterMediaSectionIsRejectedAndRecycled) {
2834 ASSERT_TRUE(CreatePeerConnectionWrappers());
2835 ConnectFakeSignaling();
2836
2837 // Do initial negotiation, only sending media from the caller. Will result in
2838 // video and audio recvonly "m=" sections.
2839 caller()->AddAudioVideoMediaStream();
2840 caller()->CreateAndSetAndSignalOffer();
2841 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2842
2843 // Negotiate again, disabling the video "m=" section (the callee will set the
2844 // port to 0 due to offer_to_receive_video = 0).
2845 PeerConnectionInterface::RTCOfferAnswerOptions options;
2846 options.offer_to_receive_video = 0;
2847 callee()->SetOfferAnswerOptions(options);
2848 caller()->CreateAndSetAndSignalOffer();
2849 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2850 // Sanity check that video "m=" section was actually rejected.
2851 const ContentInfo* answer_video_content = cricket::GetFirstVideoContent(
2852 callee()->pc()->local_description()->description());
2853 ASSERT_NE(nullptr, answer_video_content);
2854 ASSERT_TRUE(answer_video_content->rejected);
2855
2856 // Enable video and do negotiation again, making sure video is received
2857 // end-to-end, also adding media stream to callee.
2858 options.offer_to_receive_video = 1;
2859 callee()->SetOfferAnswerOptions(options);
2860 callee()->AddAudioVideoMediaStream();
2861 caller()->CreateAndSetAndSignalOffer();
2862 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2863 // Verify the caller receives frames from the newly added stream, and the
2864 // callee receives additional frames from the re-enabled video m= section.
2865 ExpectNewFramesReceivedWithWait(
2866 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2867 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2868 kMaxWaitForFramesMs);
2869}
2870
2871// This test sets up a Jsep call between two parties with external
2872// VideoDecoderFactory.
2873// TODO(holmer): Disabled due to sometimes crashing on buildbots.
2874// See issue webrtc/2378.
2875TEST_F(PeerConnectionIntegrationTest,
2876 DISABLED_EndToEndCallWithVideoDecoderFactory) {
2877 ASSERT_TRUE(CreatePeerConnectionWrappers());
2878 EnableVideoDecoderFactory();
2879 ConnectFakeSignaling();
2880 caller()->AddAudioVideoMediaStream();
2881 callee()->AddAudioVideoMediaStream();
2882 caller()->CreateAndSetAndSignalOffer();
2883 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2884 ExpectNewFramesReceivedWithWait(
2885 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2886 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2887 kMaxWaitForFramesMs);
2888}
2889
2890// This tests that if we negotiate after calling CreateSender but before we
2891// have a track, then set a track later, frames from the newly-set track are
2892// received end-to-end.
2893// TODO(deadbeef): Change this test to use AddTransceiver, once that's
2894// implemented.
2895TEST_F(PeerConnectionIntegrationTest,
2896 MediaFlowsAfterEarlyWarmupWithCreateSender) {
2897 ASSERT_TRUE(CreatePeerConnectionWrappers());
2898 ConnectFakeSignaling();
2899 auto caller_audio_sender =
2900 caller()->pc()->CreateSender("audio", "caller_stream");
2901 auto caller_video_sender =
2902 caller()->pc()->CreateSender("video", "caller_stream");
2903 auto callee_audio_sender =
2904 callee()->pc()->CreateSender("audio", "callee_stream");
2905 auto callee_video_sender =
2906 callee()->pc()->CreateSender("video", "callee_stream");
2907 caller()->CreateAndSetAndSignalOffer();
2908 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
2909 // Wait for ICE to complete, without any tracks being set.
2910 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
2911 caller()->ice_connection_state(), kMaxWaitForFramesMs);
2912 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
2913 callee()->ice_connection_state(), kMaxWaitForFramesMs);
2914 // Now set the tracks, and expect frames to immediately start flowing.
2915 EXPECT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack()));
2916 EXPECT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack()));
2917 EXPECT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack()));
2918 EXPECT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack()));
2919 ExpectNewFramesReceivedWithWait(
2920 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2921 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
2922 kMaxWaitForFramesMs);
2923}
2924
2925// This test verifies that a remote video track can be added via AddStream,
2926// and sent end-to-end. For this particular test, it's simply echoed back
2927// from the caller to the callee, rather than being forwarded to a third
2928// PeerConnection.
2929TEST_F(PeerConnectionIntegrationTest, CanSendRemoteVideoTrack) {
2930 ASSERT_TRUE(CreatePeerConnectionWrappers());
2931 ConnectFakeSignaling();
2932 // Just send a video track from the caller.
2933 caller()->AddMediaStreamFromTracks(nullptr,
2934 caller()->CreateLocalVideoTrack());
2935 caller()->CreateAndSetAndSignalOffer();
2936 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
2937 ASSERT_EQ(1, callee()->remote_streams()->count());
2938
2939 // Echo the stream back, and do a new offer/anwer (initiated by callee this
2940 // time).
2941 callee()->pc()->AddStream(callee()->remote_streams()->at(0));
2942 callee()->CreateAndSetAndSignalOffer();
2943 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
2944
2945 int expected_caller_received_video_frames = kDefaultExpectedVideoFrameCount;
2946 ExpectNewFramesReceivedWithWait(0, expected_caller_received_video_frames, 0,
2947 0, kMaxWaitForFramesMs);
2948}
2949
2950// Test that we achieve the expected end-to-end connection time, using a
2951// fake clock and simulated latency on the media and signaling paths.
2952// We use a TURN<->TURN connection because this is usually the quickest to
2953// set up initially, especially when we're confident the connection will work
2954// and can start sending media before we get a STUN response.
2955//
2956// With various optimizations enabled, here are the network delays we expect to
2957// be on the critical path:
2958// 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then
2959// signaling answer (with DTLS fingerprint).
2960// 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when
2961// using TURN<->TURN pair, and DTLS exchange is 4 packets,
2962// the first of which should have arrived before the answer.
2963TEST_F(PeerConnectionIntegrationTest, EndToEndConnectionTimeWithTurnTurnPair) {
2964 rtc::ScopedFakeClock fake_clock;
2965 // Some things use a time of "0" as a special value, so we need to start out
2966 // the fake clock at a nonzero time.
2967 // TODO(deadbeef): Fix this.
2968 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
2969
2970 static constexpr int media_hop_delay_ms = 50;
2971 static constexpr int signaling_trip_delay_ms = 500;
2972 // For explanation of these values, see comment above.
2973 static constexpr int required_media_hops = 9;
2974 static constexpr int required_signaling_trips = 2;
2975 // For internal delays (such as posting an event asychronously).
2976 static constexpr int allowed_internal_delay_ms = 20;
2977 static constexpr int total_connection_time_ms =
2978 media_hop_delay_ms * required_media_hops +
2979 signaling_trip_delay_ms * required_signaling_trips +
2980 allowed_internal_delay_ms;
2981
2982 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
2983 3478};
2984 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
2985 0};
2986 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
2987 3478};
2988 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
2989 0};
2990 cricket::TestTurnServer turn_server_1(network_thread(),
2991 turn_server_1_internal_address,
2992 turn_server_1_external_address);
2993 cricket::TestTurnServer turn_server_2(network_thread(),
2994 turn_server_2_internal_address,
2995 turn_server_2_external_address);
Jonas Orelandbdcee282017-10-10 14:01:40 +02002996
deadbeef1dcb1642017-03-29 21:08:16 -07002997 // Bypass permission check on received packets so media can be sent before
2998 // the candidate is signaled.
2999 turn_server_1.set_enable_permission_checks(false);
3000 turn_server_2.set_enable_permission_checks(false);
3001
3002 PeerConnectionInterface::RTCConfiguration client_1_config;
3003 webrtc::PeerConnectionInterface::IceServer ice_server_1;
3004 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
3005 ice_server_1.username = "test";
3006 ice_server_1.password = "test";
3007 client_1_config.servers.push_back(ice_server_1);
3008 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
3009 client_1_config.presume_writable_when_fully_relayed = true;
3010
3011 PeerConnectionInterface::RTCConfiguration client_2_config;
3012 webrtc::PeerConnectionInterface::IceServer ice_server_2;
3013 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
3014 ice_server_2.username = "test";
3015 ice_server_2.password = "test";
3016 client_2_config.servers.push_back(ice_server_2);
3017 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
3018 client_2_config.presume_writable_when_fully_relayed = true;
3019
3020 ASSERT_TRUE(
3021 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
3022 // Set up the simulated delays.
3023 SetSignalingDelayMs(signaling_trip_delay_ms);
3024 ConnectFakeSignaling();
3025 virtual_socket_server()->set_delay_mean(media_hop_delay_ms);
3026 virtual_socket_server()->UpdateDelayDistribution();
3027
3028 // Set "offer to receive audio/video" without adding any tracks, so we just
3029 // set up ICE/DTLS with no media.
3030 PeerConnectionInterface::RTCOfferAnswerOptions options;
3031 options.offer_to_receive_audio = 1;
3032 options.offer_to_receive_video = 1;
3033 caller()->SetOfferAnswerOptions(options);
3034 caller()->CreateAndSetAndSignalOffer();
deadbeef71452802017-05-07 17:21:01 -07003035 EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms,
3036 fake_clock);
deadbeef1dcb1642017-03-29 21:08:16 -07003037 // Need to free the clients here since they're using things we created on
3038 // the stack.
3039 delete SetCallerPcWrapperAndReturnCurrent(nullptr);
3040 delete SetCalleePcWrapperAndReturnCurrent(nullptr);
3041}
3042
Jonas Orelandbdcee282017-10-10 14:01:40 +02003043// Verify that a TurnCustomizer passed in through RTCConfiguration
3044// is actually used by the underlying TURN candidate pair.
3045// Note that turnport_unittest.cc contains more detailed, lower-level tests.
3046TEST_F(PeerConnectionIntegrationTest, \
3047 TurnCustomizerUsedForTurnConnections) {
3048 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
3049 3478};
3050 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
3051 0};
3052 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
3053 3478};
3054 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
3055 0};
3056 cricket::TestTurnServer turn_server_1(network_thread(),
3057 turn_server_1_internal_address,
3058 turn_server_1_external_address);
3059 cricket::TestTurnServer turn_server_2(network_thread(),
3060 turn_server_2_internal_address,
3061 turn_server_2_external_address);
3062
3063 PeerConnectionInterface::RTCConfiguration client_1_config;
3064 webrtc::PeerConnectionInterface::IceServer ice_server_1;
3065 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
3066 ice_server_1.username = "test";
3067 ice_server_1.password = "test";
3068 client_1_config.servers.push_back(ice_server_1);
3069 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
3070 auto customizer1 = rtc::MakeUnique<cricket::TestTurnCustomizer>();
3071 client_1_config.turn_customizer = customizer1.get();
3072
3073 PeerConnectionInterface::RTCConfiguration client_2_config;
3074 webrtc::PeerConnectionInterface::IceServer ice_server_2;
3075 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
3076 ice_server_2.username = "test";
3077 ice_server_2.password = "test";
3078 client_2_config.servers.push_back(ice_server_2);
3079 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
3080 auto customizer2 = rtc::MakeUnique<cricket::TestTurnCustomizer>();
3081 client_2_config.turn_customizer = customizer2.get();
3082
3083 ASSERT_TRUE(
3084 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
3085 ConnectFakeSignaling();
3086
3087 // Set "offer to receive audio/video" without adding any tracks, so we just
3088 // set up ICE/DTLS with no media.
3089 PeerConnectionInterface::RTCOfferAnswerOptions options;
3090 options.offer_to_receive_audio = 1;
3091 options.offer_to_receive_video = 1;
3092 caller()->SetOfferAnswerOptions(options);
3093 caller()->CreateAndSetAndSignalOffer();
3094 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
3095
3096 EXPECT_GT(customizer1->allow_channel_data_cnt_, 0u);
3097 EXPECT_GT(customizer1->modify_cnt_, 0u);
3098
3099 EXPECT_GT(customizer2->allow_channel_data_cnt_, 0u);
3100 EXPECT_GT(customizer2->modify_cnt_, 0u);
3101
3102 // Need to free the clients here since they're using things we created on
3103 // the stack.
3104 delete SetCallerPcWrapperAndReturnCurrent(nullptr);
3105 delete SetCalleePcWrapperAndReturnCurrent(nullptr);
3106}
3107
deadbeefc964d0b2017-04-03 10:03:35 -07003108// Test that audio and video flow end-to-end when codec names don't use the
3109// expected casing, given that they're supposed to be case insensitive. To test
3110// this, all but one codec is removed from each media description, and its
3111// casing is changed.
3112//
3113// In the past, this has regressed and caused crashes/black video, due to the
3114// fact that code at some layers was doing case-insensitive comparisons and
3115// code at other layers was not.
3116TEST_F(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) {
3117 ASSERT_TRUE(CreatePeerConnectionWrappers());
3118 ConnectFakeSignaling();
3119 caller()->AddAudioVideoMediaStream();
3120 callee()->AddAudioVideoMediaStream();
3121
3122 // Remove all but one audio/video codec (opus and VP8), and change the
3123 // casing of the caller's generated offer.
3124 caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) {
3125 cricket::AudioContentDescription* audio =
3126 GetFirstAudioContentDescription(description);
3127 ASSERT_NE(nullptr, audio);
3128 auto audio_codecs = audio->codecs();
3129 audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(),
3130 [](const cricket::AudioCodec& codec) {
3131 return codec.name != "opus";
3132 }),
3133 audio_codecs.end());
3134 ASSERT_EQ(1u, audio_codecs.size());
3135 audio_codecs[0].name = "OpUs";
3136 audio->set_codecs(audio_codecs);
3137
3138 cricket::VideoContentDescription* video =
3139 GetFirstVideoContentDescription(description);
3140 ASSERT_NE(nullptr, video);
3141 auto video_codecs = video->codecs();
3142 video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(),
3143 [](const cricket::VideoCodec& codec) {
3144 return codec.name != "VP8";
3145 }),
3146 video_codecs.end());
3147 ASSERT_EQ(1u, video_codecs.size());
3148 video_codecs[0].name = "vP8";
3149 video->set_codecs(video_codecs);
3150 });
3151
3152 caller()->CreateAndSetAndSignalOffer();
3153 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3154
3155 // Verify frames are still received end-to-end.
3156 ExpectNewFramesReceivedWithWait(
3157 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
3158 kDefaultExpectedAudioFrameCount, kDefaultExpectedVideoFrameCount,
3159 kMaxWaitForFramesMs);
3160}
3161
hbos8d609f62017-04-10 07:39:05 -07003162TEST_F(PeerConnectionIntegrationTest, GetSources) {
3163 ASSERT_TRUE(CreatePeerConnectionWrappers());
3164 ConnectFakeSignaling();
3165 caller()->AddAudioOnlyMediaStream();
3166 caller()->CreateAndSetAndSignalOffer();
3167 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
deadbeefd8ad7882017-04-18 16:01:17 -07003168 // Wait for one audio frame to be received by the callee.
hbos8d609f62017-04-10 07:39:05 -07003169 ExpectNewFramesReceivedWithWait(0, 0, 1, 0, kMaxWaitForFramesMs);
3170 ASSERT_GT(callee()->pc()->GetReceivers().size(), 0u);
3171 auto receiver = callee()->pc()->GetReceivers()[0];
3172 ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO);
3173
3174 auto contributing_sources = receiver->GetSources();
3175 ASSERT_GT(receiver->GetParameters().encodings.size(), 0u);
3176 EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc,
3177 contributing_sources[0].source_id());
3178}
3179
deadbeef2f425aa2017-04-14 10:41:32 -07003180// Test that if a track is removed and added again with a different stream ID,
3181// the new stream ID is successfully communicated in SDP and media continues to
3182// flow end-to-end.
3183TEST_F(PeerConnectionIntegrationTest, RemoveAndAddTrackWithNewStreamId) {
3184 ASSERT_TRUE(CreatePeerConnectionWrappers());
3185 ConnectFakeSignaling();
3186
3187 rtc::scoped_refptr<MediaStreamInterface> stream_1 =
3188 caller()->pc_factory()->CreateLocalMediaStream("stream_1");
3189 rtc::scoped_refptr<MediaStreamInterface> stream_2 =
3190 caller()->pc_factory()->CreateLocalMediaStream("stream_2");
3191
3192 // Add track using stream 1, do offer/answer.
3193 rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
3194 caller()->CreateLocalAudioTrack();
3195 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender =
3196 caller()->pc()->AddTrack(track, {stream_1.get()});
3197 caller()->CreateAndSetAndSignalOffer();
3198 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3199 // Wait for one audio frame to be received by the callee.
3200 ExpectNewFramesReceivedWithWait(0, 0, 1, 0, kMaxWaitForFramesMs);
3201
3202 // Remove the sender, and create a new one with the new stream.
3203 caller()->pc()->RemoveTrack(sender);
3204 sender = caller()->pc()->AddTrack(track, {stream_2.get()});
3205 caller()->CreateAndSetAndSignalOffer();
3206 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3207 // Wait for additional audio frames to be received by the callee.
3208 ExpectNewFramesReceivedWithWait(0, 0, kDefaultExpectedAudioFrameCount, 0,
3209 kMaxWaitForFramesMs);
3210}
3211
deadbeef1dcb1642017-03-29 21:08:16 -07003212} // namespace
3213
3214#endif // if !defined(THREAD_SANITIZER)