blob: 85a7e697a8406323ebace8104872f3b91e65fae9 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2009 The WebRTC project authors. All Rights Reserved.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00009 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000010
kwiberg31022942016-03-11 14:18:21 -080011#include <memory>
12
Danil Chapovalov33b01f22016-05-11 19:55:27 +020013#include "webrtc/base/array_view.h"
14#include "webrtc/base/buffer.h"
Taylor Brandstetter88532892016-08-01 14:17:27 -070015#include "webrtc/base/fakeclock.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000016#include "webrtc/base/gunit.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000017#include "webrtc/base/logging.h"
jbauchcb560652016-08-04 05:20:32 -070018#include "webrtc/base/sslstreamadapter.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/fakemediaengine.h"
20#include "webrtc/media/base/fakertp.h"
kjellandera96e2d72016-02-04 23:52:28 -080021#include "webrtc/media/base/mediachannel.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010023#include "webrtc/p2p/base/faketransportcontroller.h"
deadbeef49f34fd2016-12-06 16:22:06 -080024#include "webrtc/p2p/base/transportchannelimpl.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010025#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026
27#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000028 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029 LOG(LS_INFO) << "Feature disabled... skipping"; \
30 return; \
31 }
32
33using cricket::CA_OFFER;
34using cricket::CA_PRANSWER;
35using cricket::CA_ANSWER;
36using cricket::CA_UPDATE;
37using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038using cricket::StreamParams;
39using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040
Danil Chapovalov33b01f22016-05-11 19:55:27 +020041namespace {
42const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
43const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
44const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
perkj26752742016-10-24 01:21:16 -070045const cricket::VideoCodec kH264Codec(97, "H264");
46const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
Danil Chapovalov33b01f22016-05-11 19:55:27 +020047const cricket::DataCodec kGoogleDataCodec(101, "google-data");
48const uint32_t kSsrc1 = 0x1111;
49const uint32_t kSsrc2 = 0x2222;
50const uint32_t kSsrc3 = 0x3333;
51const int kAudioPts[] = {0, 8};
52const int kVideoPts[] = {97, 99};
53enum class NetworkIsWorker { Yes, No };
deadbeefc6b6e092016-12-01 12:49:20 -080054const int kDefaultTimeout = 10000; // 10 seconds.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020055} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
deadbeefcbecd352015-09-23 11:50:27 -070057template <class ChannelT,
58 class MediaChannelT,
59 class ContentT,
60 class CodecT,
61 class MediaInfoT,
62 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063class Traits {
64 public:
65 typedef ChannelT Channel;
66 typedef MediaChannelT MediaChannel;
67 typedef ContentT Content;
68 typedef CodecT Codec;
69 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020070 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071};
72
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073class VoiceTraits : public Traits<cricket::VoiceChannel,
74 cricket::FakeVoiceMediaChannel,
75 cricket::AudioContentDescription,
76 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020077 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070078 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079
80class VideoTraits : public Traits<cricket::VideoChannel,
81 cricket::FakeVideoMediaChannel,
82 cricket::VideoContentDescription,
83 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020084 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070085 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
87class DataTraits : public Traits<cricket::DataChannel,
88 cricket::FakeDataMediaChannel,
89 cricket::DataContentDescription,
90 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020091 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070092 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093
Danil Chapovalov33b01f22016-05-11 19:55:27 +020094// Base class for Voice/Video/DataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095template<class T>
96class ChannelTest : public testing::Test, public sigslot::has_slots<> {
97 public:
98 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
jbauchcb560652016-08-04 05:20:32 -070099 DTLS = 0x10, GCM_CIPHER = 0x20 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100
Peter Boström34fbfff2015-09-24 19:20:30 +0200101 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200102 rtc::ArrayView<const uint8_t> rtp_data,
103 rtc::ArrayView<const uint8_t> rtcp_data,
104 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200105 : verify_playout_(verify_playout),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106 media_channel1_(NULL),
107 media_channel2_(NULL),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200108 rtp_packet_(rtp_data.data(), rtp_data.size()),
109 rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110 media_info_callbacks1_(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200111 media_info_callbacks2_() {
112 if (network_is_worker == NetworkIsWorker::Yes) {
113 network_thread_ = rtc::Thread::Current();
114 } else {
115 network_thread_keeper_ = rtc::Thread::Create();
116 network_thread_keeper_->SetName("Network", nullptr);
117 network_thread_keeper_->Start();
118 network_thread_ = network_thread_keeper_.get();
119 }
120 transport_controller1_.reset(new cricket::FakeTransportController(
121 network_thread_, cricket::ICEROLE_CONTROLLING));
122 transport_controller2_.reset(new cricket::FakeTransportController(
123 network_thread_, cricket::ICEROLE_CONTROLLED));
124 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200127 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
128 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200129 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200131 void CreateChannels(typename T::MediaChannel* ch1,
132 typename T::MediaChannel* ch2,
133 int flags1,
134 int flags2) {
135 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 media_channel1_ = ch1;
137 media_channel2_ = ch2;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200138 channel1_.reset(
139 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
jbauchcb560652016-08-04 05:20:32 -0700140 transport_controller1_.get(), flags1));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200141 channel2_.reset(
142 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
jbauchcb560652016-08-04 05:20:32 -0700143 transport_controller2_.get(), flags2));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200144 channel1_->SignalMediaMonitor.connect(this,
145 &ChannelTest<T>::OnMediaMonitor1);
146 channel2_->SignalMediaMonitor.connect(this,
147 &ChannelTest<T>::OnMediaMonitor2);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000148 if ((flags1 & DTLS) && (flags2 & DTLS)) {
149 flags1 = (flags1 & ~SECURE);
150 flags2 = (flags2 & ~SECURE);
151 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 CreateContent(flags1, kPcmuCodec, kH264Codec,
153 &local_media_content1_);
154 CreateContent(flags2, kPcmuCodec, kH264Codec,
155 &local_media_content2_);
156 CopyContent(local_media_content1_, &remote_media_content1_);
157 CopyContent(local_media_content2_, &remote_media_content2_);
158
159 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200160 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200161 transport_controller1_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700162 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800163 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 }
165 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200166 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200167 transport_controller2_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700168 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800169 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 }
171
172 // Add stream information (SSRC) to the local content but not to the remote
173 // content. This means that we per default know the SSRC of what we send but
174 // not what we receive.
175 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
176 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
177
178 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
179 if (flags1 & SSRC_MUX) {
180 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
181 }
182 if (flags2 & SSRC_MUX) {
183 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
184 }
185 }
deadbeefcbecd352015-09-23 11:50:27 -0700186 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200187 rtc::Thread* worker_thread,
188 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700189 cricket::MediaEngineInterface* engine,
190 typename T::MediaChannel* ch,
191 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -0700192 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200193 typename T::Channel* channel =
194 new typename T::Channel(worker_thread, network_thread, engine, ch,
jbauchcb560652016-08-04 05:20:32 -0700195 transport_controller, cricket::CN_AUDIO,
196 (flags & RTCP) != 0);
197 rtc::CryptoOptions crypto_options;
198 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
199 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -0700200 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000201 delete channel;
202 channel = NULL;
203 }
204 return channel;
205 }
206
207 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000208 bool result = channel1_->SetLocalContent(&local_media_content1_,
209 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 if (result) {
211 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000212 result = channel2_->SetRemoteContent(&remote_media_content1_,
213 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200215 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000217 result = channel2_->SetLocalContent(&local_media_content2_,
218 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000219 }
220 }
221 return result;
222 }
223
224 bool SendAccept() {
225 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000226 return channel1_->SetRemoteContent(&remote_media_content2_,
227 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 }
229
230 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000231 bool result = channel1_->SetLocalContent(&local_media_content1_,
232 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 if (result) {
234 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000235 result = channel2_->SetRemoteContent(&remote_media_content1_,
236 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 }
238 return result;
239 }
240
241 bool SendProvisionalAnswer() {
242 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000243 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 if (result) {
245 channel2_->Enable(true);
246 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200248 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 }
250 return result;
251 }
252
253 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000254 bool result = channel2_->SetLocalContent(&local_media_content2_,
255 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000257 result = channel1_->SetRemoteContent(&remote_media_content2_,
258 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 return result;
260 }
261
262 bool SendTerminate() {
263 channel1_.reset();
264 channel2_.reset();
265 return true;
266 }
267
268 bool AddStream1(int id) {
269 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
270 }
271 bool RemoveStream1(int id) {
272 return channel1_->RemoveRecvStream(id);
273 }
274
deadbeef49f34fd2016-12-06 16:22:06 -0800275 std::vector<cricket::TransportChannelImpl*> GetChannels1() {
276 return transport_controller1_->channels_for_testing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 }
deadbeef49f34fd2016-12-06 16:22:06 -0800278
279 std::vector<cricket::TransportChannelImpl*> GetChannels2() {
280 return transport_controller2_->channels_for_testing();
281 }
282
283 cricket::FakeTransportChannel* GetFakeChannel1(int component) {
284 return transport_controller1_->GetFakeTransportChannel_n(
285 channel1_->content_name(), component);
286 }
287
288 cricket::FakeTransportChannel* GetFakeChannel2(int component) {
289 return transport_controller2_->GetFakeTransportChannel_n(
290 channel2_->content_name(), component);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 }
292
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200293 void SendRtp1() {
294 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
295 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200297 void SendRtp2() {
298 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
299 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200301 void SendRtcp1() {
302 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200304 void SendRtcp2() {
305 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 }
307 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200308 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
309 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
310 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200312 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
313 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
314 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200316 void SendCustomRtcp1(uint32_t ssrc) {
317 rtc::Buffer data = CreateRtcpData(ssrc);
318 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200320 void SendCustomRtcp2(uint32_t ssrc) {
321 rtc::Buffer data = CreateRtcpData(ssrc);
322 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200324
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200326 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
328 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200329 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
331 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200332 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
334 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200335 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 }
337 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200338 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200339 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
340 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200342 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200343 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
344 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200346 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200347 rtc::Buffer data = CreateRtcpData(ssrc);
348 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200350 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200351 rtc::Buffer data = CreateRtcpData(ssrc);
352 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200354 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
355 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200357 rtc::SetBE32(data.data() + 8, ssrc);
358 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000359 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200360 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000361 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 return data;
363 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200364 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
365 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200367 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 return data;
369 }
370
371 bool CheckNoRtp1() {
372 return media_channel1_->CheckNoRtp();
373 }
374 bool CheckNoRtp2() {
375 return media_channel2_->CheckNoRtp();
376 }
377 bool CheckNoRtcp1() {
378 return media_channel1_->CheckNoRtcp();
379 }
380 bool CheckNoRtcp2() {
381 return media_channel2_->CheckNoRtcp();
382 }
jbauchcb560652016-08-04 05:20:32 -0700383 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags.
384 // Returns true if so.
385 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
386 int suite;
387 if (!channel->transport_channel()->GetSrtpCryptoSuite(&suite)) {
388 return false;
389 }
390
391 if (flags & GCM_CIPHER) {
392 return rtc::IsGcmCryptoSuite(suite);
393 } else {
394 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
395 !rtc::IsGcmCryptoSuite(suite));
396 }
397 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398
399 void CreateContent(int flags,
400 const cricket::AudioCodec& audio_codec,
401 const cricket::VideoCodec& video_codec,
402 typename T::Content* content) {
403 // overridden in specialized classes
404 }
405 void CopyContent(const typename T::Content& source,
406 typename T::Content* content) {
407 // overridden in specialized classes
408 }
409
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 // Creates a cricket::SessionDescription with one MediaContent and one stream.
411 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200412 cricket::SessionDescription* CreateSessionDescriptionWithStream(
413 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 typename T::Content content;
415 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
416 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
417 AddLegacyStreamInContent(ssrc, 0, &content);
418 sdesc->AddContent("DUMMY_CONTENT_NAME",
419 cricket::NS_JINGLE_RTP, content.Copy());
420 return sdesc;
421 }
422
ossu292d6582016-03-17 02:31:13 -0700423 // Will manage the lifetime of a CallThread, making sure it's
424 // destroyed before this object goes out of scope.
425 class ScopedCallThread {
426 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200427 template <class FunctorT>
428 ScopedCallThread(const FunctorT& functor)
429 : thread_(rtc::Thread::Create()),
430 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700431 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700432 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700433 }
434
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200435 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700436
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200437 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700438
439 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200440 std::unique_ptr<rtc::Thread> thread_;
441 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700442 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
445 return false; // overridden in specialized classes
446 }
447
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200448 void OnMediaMonitor1(typename T::Channel* channel,
449 const typename T::MediaInfo& info) {
450 RTC_DCHECK_EQ(channel, channel1_.get());
451 media_info_callbacks1_++;
452 }
453 void OnMediaMonitor2(typename T::Channel* channel,
454 const typename T::MediaInfo& info) {
455 RTC_DCHECK_EQ(channel, channel2_.get());
456 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 }
458
Honghai Zhangcc411c02016-03-29 17:27:21 -0700459 cricket::CandidatePairInterface* last_selected_candidate_pair() {
460 return last_selected_candidate_pair_;
461 }
462
Peter Boström0c4e06b2015-10-07 12:23:21 +0200463 void AddLegacyStreamInContent(uint32_t ssrc,
464 int flags,
465 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 // Base implementation.
467 }
468
469 // Tests that can be used by derived classes.
470
471 // Basic sanity check.
472 void TestInit() {
473 CreateChannels(0, 0);
474 EXPECT_FALSE(channel1_->secure());
475 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200476 if (verify_playout_) {
477 EXPECT_FALSE(media_channel1_->playout());
478 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 EXPECT_TRUE(media_channel1_->codecs().empty());
480 EXPECT_TRUE(media_channel1_->recv_streams().empty());
481 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
482 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
483 }
484
485 // Test that SetLocalContent and SetRemoteContent properly configure
486 // the codecs.
487 void TestSetContents() {
488 CreateChannels(0, 0);
489 typename T::Content content;
490 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000491 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000493 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 ASSERT_EQ(1U, media_channel1_->codecs().size());
495 EXPECT_TRUE(CodecMatches(content.codecs()[0],
496 media_channel1_->codecs()[0]));
497 }
498
499 // Test that SetLocalContent and SetRemoteContent properly deals
500 // with an empty offer.
501 void TestSetContentsNullOffer() {
502 CreateChannels(0, 0);
503 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000504 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 CreateContent(0, kPcmuCodec, kH264Codec, &content);
506 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000507 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000508 ASSERT_EQ(1U, media_channel1_->codecs().size());
509 EXPECT_TRUE(CodecMatches(content.codecs()[0],
510 media_channel1_->codecs()[0]));
511 }
512
513 // Test that SetLocalContent and SetRemoteContent properly set RTCP
514 // mux.
515 void TestSetContentsRtcpMux() {
516 CreateChannels(RTCP, RTCP);
517 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
518 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
519 typename T::Content content;
520 CreateContent(0, kPcmuCodec, kH264Codec, &content);
521 // Both sides agree on mux. Should no longer be a separate RTCP channel.
522 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000523 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
524 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000525 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
526 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000527 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000529 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
531 }
532
533 // Test that SetLocalContent and SetRemoteContent properly set RTCP
534 // mux when a provisional answer is received.
535 void TestSetContentsRtcpMuxWithPrAnswer() {
536 CreateChannels(RTCP, RTCP);
537 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
538 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
539 typename T::Content content;
540 CreateContent(0, kPcmuCodec, kH264Codec, &content);
541 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000542 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
543 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000545 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 // Both sides agree on mux. Should no longer be a separate RTCP channel.
547 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
548 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000549 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000551 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
552 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
554 }
555
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 // Test that SetRemoteContent properly deals with a content update.
557 void TestSetRemoteContentUpdate() {
558 CreateChannels(0, 0);
559 typename T::Content content;
560 CreateContent(RTCP | RTCP_MUX | SECURE,
561 kPcmuCodec, kH264Codec,
562 &content);
563 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000564 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
565 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 ASSERT_EQ(1U, media_channel1_->codecs().size());
567 EXPECT_TRUE(CodecMatches(content.codecs()[0],
568 media_channel1_->codecs()[0]));
569 // Now update with other codecs.
570 typename T::Content update_content;
571 update_content.set_partial(true);
572 CreateContent(0, kIsacCodec, kH264SvcCodec,
573 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000574 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 ASSERT_EQ(1U, media_channel1_->codecs().size());
576 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
577 media_channel1_->codecs()[0]));
578 // Now update without any codecs. This is ignored.
579 typename T::Content empty_content;
580 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000581 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 ASSERT_EQ(1U, media_channel1_->codecs().size());
583 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
584 media_channel1_->codecs()[0]));
585 }
586
587 // Test that Add/RemoveStream properly forward to the media channel.
588 void TestStreams() {
589 CreateChannels(0, 0);
590 EXPECT_TRUE(AddStream1(1));
591 EXPECT_TRUE(AddStream1(2));
592 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
593 EXPECT_TRUE(RemoveStream1(2));
594 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
595 EXPECT_TRUE(RemoveStream1(1));
596 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
597 }
598
599 // Test that SetLocalContent properly handles adding and removing StreamParams
600 // to the local content description.
601 // This test uses the CA_UPDATE action that don't require a full
602 // MediaContentDescription to do an update.
603 void TestUpdateStreamsInLocalContent() {
604 cricket::StreamParams stream1;
605 stream1.groupid = "group1";
606 stream1.id = "stream1";
607 stream1.ssrcs.push_back(kSsrc1);
608 stream1.cname = "stream1_cname";
609
610 cricket::StreamParams stream2;
611 stream2.groupid = "group2";
612 stream2.id = "stream2";
613 stream2.ssrcs.push_back(kSsrc2);
614 stream2.cname = "stream2_cname";
615
616 cricket::StreamParams stream3;
617 stream3.groupid = "group3";
618 stream3.id = "stream3";
619 stream3.ssrcs.push_back(kSsrc3);
620 stream3.cname = "stream3_cname";
621
622 CreateChannels(0, 0);
623 typename T::Content content1;
624 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
625 content1.AddStream(stream1);
626 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000627 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628
629 ASSERT_EQ(1u, media_channel1_->send_streams().size());
630 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
631
632 // Update the local streams by adding another sending stream.
633 // Use a partial updated session description.
634 typename T::Content content2;
635 content2.AddStream(stream2);
636 content2.AddStream(stream3);
637 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000638 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 ASSERT_EQ(3u, media_channel1_->send_streams().size());
640 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
641 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
642 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
643
644 // Update the local streams by removing the first sending stream.
645 // This is done by removing all SSRCS for this particular stream.
646 typename T::Content content3;
647 stream1.ssrcs.clear();
648 content3.AddStream(stream1);
649 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000650 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000651 ASSERT_EQ(2u, media_channel1_->send_streams().size());
652 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
653 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
654
655 // Update the local streams with a stream that does not change.
656 // THe update is ignored.
657 typename T::Content content4;
658 content4.AddStream(stream2);
659 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000660 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 ASSERT_EQ(2u, media_channel1_->send_streams().size());
662 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
663 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
664 }
665
666 // Test that SetRemoteContent properly handles adding and removing
667 // StreamParams to the remote content description.
668 // This test uses the CA_UPDATE action that don't require a full
669 // MediaContentDescription to do an update.
670 void TestUpdateStreamsInRemoteContent() {
671 cricket::StreamParams stream1;
672 stream1.id = "Stream1";
673 stream1.groupid = "1";
674 stream1.ssrcs.push_back(kSsrc1);
675 stream1.cname = "stream1_cname";
676
677 cricket::StreamParams stream2;
678 stream2.id = "Stream2";
679 stream2.groupid = "2";
680 stream2.ssrcs.push_back(kSsrc2);
681 stream2.cname = "stream2_cname";
682
683 cricket::StreamParams stream3;
684 stream3.id = "Stream3";
685 stream3.groupid = "3";
686 stream3.ssrcs.push_back(kSsrc3);
687 stream3.cname = "stream3_cname";
688
689 CreateChannels(0, 0);
690 typename T::Content content1;
691 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
692 content1.AddStream(stream1);
693 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000694 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695
696 ASSERT_EQ(1u, media_channel1_->codecs().size());
697 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
698 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
699
700 // Update the remote streams by adding another sending stream.
701 // Use a partial updated session description.
702 typename T::Content content2;
703 content2.AddStream(stream2);
704 content2.AddStream(stream3);
705 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000706 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
708 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
709 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
710 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
711
712 // Update the remote streams by removing the first stream.
713 // This is done by removing all SSRCS for this particular stream.
714 typename T::Content content3;
715 stream1.ssrcs.clear();
716 content3.AddStream(stream1);
717 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000718 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
720 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
721 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
722
723 // Update the remote streams with a stream that does not change.
724 // The update is ignored.
725 typename T::Content content4;
726 content4.AddStream(stream2);
727 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
730 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
731 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
732 }
733
734 // Test that SetLocalContent and SetRemoteContent properly
735 // handles adding and removing StreamParams when the action is a full
736 // CA_OFFER / CA_ANSWER.
737 void TestChangeStreamParamsInContent() {
738 cricket::StreamParams stream1;
739 stream1.groupid = "group1";
740 stream1.id = "stream1";
741 stream1.ssrcs.push_back(kSsrc1);
742 stream1.cname = "stream1_cname";
743
744 cricket::StreamParams stream2;
745 stream2.groupid = "group1";
746 stream2.id = "stream2";
747 stream2.ssrcs.push_back(kSsrc2);
748 stream2.cname = "stream2_cname";
749
750 // Setup a call where channel 1 send |stream1| to channel 2.
751 CreateChannels(0, 0);
752 typename T::Content content1;
753 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
754 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000755 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 EXPECT_TRUE(channel1_->Enable(true));
757 EXPECT_EQ(1u, media_channel1_->send_streams().size());
758
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000759 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200761 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762
763 // Channel 2 do not send anything.
764 typename T::Content content2;
765 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000766 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000768 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 EXPECT_TRUE(channel2_->Enable(true));
770 EXPECT_EQ(0u, media_channel2_->send_streams().size());
771
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200772 SendCustomRtp1(kSsrc1, 0);
773 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
775
776 // Let channel 2 update the content by sending |stream2| and enable SRTP.
777 typename T::Content content3;
778 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
779 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000780 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 ASSERT_EQ(1u, media_channel2_->send_streams().size());
782 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
783
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000784 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
786 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
787
788 // Channel 1 replies but stop sending stream1.
789 typename T::Content content4;
790 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000791 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 EXPECT_EQ(0u, media_channel1_->send_streams().size());
793
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000794 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
796
797 EXPECT_TRUE(channel1_->secure());
798 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200799 SendCustomRtp2(kSsrc2, 0);
800 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
802 }
803
804 // Test that we only start playout and sending at the right times.
805 void TestPlayoutAndSendingStates() {
806 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200807 if (verify_playout_) {
808 EXPECT_FALSE(media_channel1_->playout());
809 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200811 if (verify_playout_) {
812 EXPECT_FALSE(media_channel2_->playout());
813 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 EXPECT_FALSE(media_channel2_->sending());
815 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200816 if (verify_playout_) {
817 EXPECT_FALSE(media_channel1_->playout());
818 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000820 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
821 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200822 if (verify_playout_) {
823 EXPECT_TRUE(media_channel1_->playout());
824 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000826 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
827 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200828 if (verify_playout_) {
829 EXPECT_FALSE(media_channel2_->playout());
830 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000832 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
833 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200834 if (verify_playout_) {
835 EXPECT_FALSE(media_channel2_->playout());
836 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 EXPECT_FALSE(media_channel2_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200838 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200839 if (verify_playout_) {
840 EXPECT_TRUE(media_channel1_->playout());
841 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200843 if (verify_playout_) {
844 EXPECT_FALSE(media_channel2_->playout());
845 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 EXPECT_FALSE(media_channel2_->sending());
847 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200848 if (verify_playout_) {
849 EXPECT_TRUE(media_channel2_->playout());
850 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000852 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
853 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200854 if (verify_playout_) {
855 EXPECT_TRUE(media_channel1_->playout());
856 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 EXPECT_TRUE(media_channel1_->sending());
858 }
859
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 // Test that changing the MediaContentDirection in the local and remote
861 // session description start playout and sending at the right time.
862 void TestMediaContentDirection() {
863 CreateChannels(0, 0);
864 typename T::Content content1;
865 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
866 typename T::Content content2;
867 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
868 // Set |content2| to be InActive.
869 content2.set_direction(cricket::MD_INACTIVE);
870
871 EXPECT_TRUE(channel1_->Enable(true));
872 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200873 if (verify_playout_) {
874 EXPECT_FALSE(media_channel1_->playout());
875 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200877 if (verify_playout_) {
878 EXPECT_FALSE(media_channel2_->playout());
879 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 EXPECT_FALSE(media_channel2_->sending());
881
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000882 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
883 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
884 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
885 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200886 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887
Peter Boström34fbfff2015-09-24 19:20:30 +0200888 if (verify_playout_) {
889 EXPECT_TRUE(media_channel1_->playout());
890 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200892 if (verify_playout_) {
893 EXPECT_FALSE(media_channel2_->playout()); // local InActive
894 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 EXPECT_FALSE(media_channel2_->sending()); // local InActive
896
897 // Update |content2| to be RecvOnly.
898 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000899 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
900 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901
Peter Boström34fbfff2015-09-24 19:20:30 +0200902 if (verify_playout_) {
903 EXPECT_TRUE(media_channel1_->playout());
904 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200906 if (verify_playout_) {
907 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
908 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
910
911 // Update |content2| to be SendRecv.
912 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000913 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
914 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915
Peter Boström34fbfff2015-09-24 19:20:30 +0200916 if (verify_playout_) {
917 EXPECT_TRUE(media_channel1_->playout());
918 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200920 if (verify_playout_) {
921 EXPECT_TRUE(media_channel2_->playout());
922 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 EXPECT_TRUE(media_channel2_->sending());
924 }
925
Honghai Zhangcc411c02016-03-29 17:27:21 -0700926 // Tests that when the transport channel signals a candidate pair change
927 // event, the media channel will receive a call on the network route change.
928 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200929 constexpr uint16_t kLocalNetId = 1;
930 constexpr uint16_t kRemoteNetId = 2;
931 constexpr int kLastPacketId = 100;
932
Honghai Zhangcc411c02016-03-29 17:27:21 -0700933 CreateChannels(0, 0);
934
935 cricket::TransportChannel* transport_channel1 =
936 channel1_->transport_channel();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200937 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700938 typename T::MediaChannel* media_channel1 =
939 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200940 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700941
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200942 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700943 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200944 // The transport channel becomes disconnected.
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700945 transport_channel1->SignalSelectedCandidatePairChanged(
946 transport_channel1, nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200947 });
948 WaitForThreads();
949 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700950 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200951 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700952
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700953 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
954 media_channel1, kLocalNetId,
955 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200956 // The transport channel becomes connected.
957 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
958 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
959 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
960 transport_controller1_->CreateFakeCandidatePair(
961 local_address, kLocalNetId, remote_address, kRemoteNetId));
962 transport_channel1->SignalSelectedCandidatePairChanged(
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700963 transport_channel1, candidate_pair.get(), kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200964 });
965 WaitForThreads();
966 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700967 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200968 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700969 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200970 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700971 media_channel1->last_network_route().last_sent_packet_id);
michaelt79e05882016-11-08 02:50:09 -0800972 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
973 EXPECT_EQ(kTransportOverheadPerPacket,
974 media_channel1->transport_overhead_per_packet());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700975 }
976
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 // Test setting up a call.
978 void TestCallSetup() {
979 CreateChannels(0, 0);
980 EXPECT_FALSE(channel1_->secure());
981 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200982 if (verify_playout_) {
983 EXPECT_TRUE(media_channel1_->playout());
984 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 EXPECT_FALSE(media_channel1_->sending());
986 EXPECT_TRUE(SendAccept());
987 EXPECT_FALSE(channel1_->secure());
988 EXPECT_TRUE(media_channel1_->sending());
989 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200990 if (verify_playout_) {
991 EXPECT_TRUE(media_channel2_->playout());
992 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 EXPECT_TRUE(media_channel2_->sending());
994 EXPECT_EQ(1U, media_channel2_->codecs().size());
995 }
996
997 // Test that we don't crash if packets are sent during call teardown
998 // when RTCP mux is enabled. This is a regression test against a specific
999 // race condition that would only occur when a RTCP packet was sent during
1000 // teardown of a channel on which RTCP mux was enabled.
1001 void TestCallTeardownRtcpMux() {
1002 class LastWordMediaChannel : public T::MediaChannel {
1003 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001004 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001006 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1007 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1009 }
1010 };
1011 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001012 RTCP | RTCP_MUX, RTCP | RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 EXPECT_TRUE(SendInitiate());
1014 EXPECT_TRUE(SendAccept());
1015 EXPECT_TRUE(SendTerminate());
1016 }
1017
1018 // Send voice RTP data to the other side and ensure it gets there.
1019 void SendRtpToRtp() {
1020 CreateChannels(0, 0);
1021 EXPECT_TRUE(SendInitiate());
1022 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001023 EXPECT_EQ(1U, GetChannels1().size());
1024 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001025 SendRtp1();
1026 SendRtp2();
1027 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 EXPECT_TRUE(CheckRtp1());
1029 EXPECT_TRUE(CheckRtp2());
1030 EXPECT_TRUE(CheckNoRtp1());
1031 EXPECT_TRUE(CheckNoRtp2());
1032 }
1033
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001034 void TestDeinit() {
1035 CreateChannels(RTCP, RTCP);
1036 EXPECT_TRUE(SendInitiate());
1037 EXPECT_TRUE(SendAccept());
1038 SendRtp1();
1039 SendRtp2();
1040 SendRtcp1();
1041 SendRtcp2();
1042 // Do not wait, destroy channels.
1043 channel1_.reset(nullptr);
1044 channel2_.reset(nullptr);
1045 }
1046
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 // Check that RTCP is not transmitted if both sides don't support RTCP.
1048 void SendNoRtcpToNoRtcp() {
1049 CreateChannels(0, 0);
1050 EXPECT_TRUE(SendInitiate());
1051 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001052 EXPECT_EQ(1U, GetChannels1().size());
1053 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001054 SendRtcp1();
1055 SendRtcp2();
1056 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 EXPECT_TRUE(CheckNoRtcp1());
1058 EXPECT_TRUE(CheckNoRtcp2());
1059 }
1060
1061 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1062 void SendNoRtcpToRtcp() {
1063 CreateChannels(0, RTCP);
1064 EXPECT_TRUE(SendInitiate());
1065 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001066 EXPECT_EQ(1U, GetChannels1().size());
1067 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001068 SendRtcp1();
1069 SendRtcp2();
1070 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 EXPECT_TRUE(CheckNoRtcp1());
1072 EXPECT_TRUE(CheckNoRtcp2());
1073 }
1074
1075 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1076 void SendRtcpToNoRtcp() {
1077 CreateChannels(RTCP, 0);
1078 EXPECT_TRUE(SendInitiate());
1079 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001080 EXPECT_EQ(2U, GetChannels1().size());
1081 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001082 SendRtcp1();
1083 SendRtcp2();
1084 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 EXPECT_TRUE(CheckNoRtcp1());
1086 EXPECT_TRUE(CheckNoRtcp2());
1087 }
1088
1089 // Check that RTCP is transmitted if both sides support RTCP.
1090 void SendRtcpToRtcp() {
1091 CreateChannels(RTCP, RTCP);
1092 EXPECT_TRUE(SendInitiate());
1093 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001094 EXPECT_EQ(2U, GetChannels1().size());
1095 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001096 SendRtcp1();
1097 SendRtcp2();
1098 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 EXPECT_TRUE(CheckRtcp1());
1100 EXPECT_TRUE(CheckRtcp2());
1101 EXPECT_TRUE(CheckNoRtcp1());
1102 EXPECT_TRUE(CheckNoRtcp2());
1103 }
1104
1105 // Check that RTCP is transmitted if only the initiator supports mux.
1106 void SendRtcpMuxToRtcp() {
1107 CreateChannels(RTCP | RTCP_MUX, RTCP);
1108 EXPECT_TRUE(SendInitiate());
1109 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001110 EXPECT_EQ(2U, GetChannels1().size());
1111 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001112 SendRtcp1();
1113 SendRtcp2();
1114 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 EXPECT_TRUE(CheckRtcp1());
1116 EXPECT_TRUE(CheckRtcp2());
1117 EXPECT_TRUE(CheckNoRtcp1());
1118 EXPECT_TRUE(CheckNoRtcp2());
1119 }
1120
1121 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1122 void SendRtcpMuxToRtcpMux() {
1123 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1124 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001125 EXPECT_EQ(2U, GetChannels1().size());
1126 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001128 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001129 SendRtp1();
1130 SendRtp2();
1131 SendRtcp1();
1132 SendRtcp2();
1133 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 EXPECT_TRUE(CheckRtp1());
1135 EXPECT_TRUE(CheckRtp2());
1136 EXPECT_TRUE(CheckNoRtp1());
1137 EXPECT_TRUE(CheckNoRtp2());
1138 EXPECT_TRUE(CheckRtcp1());
1139 EXPECT_TRUE(CheckRtcp2());
1140 EXPECT_TRUE(CheckNoRtcp1());
1141 EXPECT_TRUE(CheckNoRtcp2());
1142 }
1143
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001144 // Check that RTP and RTCP are transmitted ok when both sides
1145 // support mux and one the offerer requires mux.
1146 void SendRequireRtcpMuxToRtcpMux() {
1147 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1148 channel1_->ActivateRtcpMux();
1149 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001150 EXPECT_EQ(1U, GetChannels1().size());
1151 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001152 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001153 SendRtp1();
1154 SendRtp2();
1155 SendRtcp1();
1156 SendRtcp2();
1157 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001158 EXPECT_TRUE(CheckRtp1());
1159 EXPECT_TRUE(CheckRtp2());
1160 EXPECT_TRUE(CheckNoRtp1());
1161 EXPECT_TRUE(CheckNoRtp2());
1162 EXPECT_TRUE(CheckRtcp1());
1163 EXPECT_TRUE(CheckRtcp2());
1164 EXPECT_TRUE(CheckNoRtcp1());
1165 EXPECT_TRUE(CheckNoRtcp2());
1166 }
1167
1168 // Check that RTP and RTCP are transmitted ok when both sides
1169 // support mux and one the answerer requires rtcp mux.
1170 void SendRtcpMuxToRequireRtcpMux() {
1171 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1172 channel2_->ActivateRtcpMux();
1173 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001174 EXPECT_EQ(2U, GetChannels1().size());
1175 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001176 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001177 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001178 SendRtp1();
1179 SendRtp2();
1180 SendRtcp1();
1181 SendRtcp2();
1182 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001183 EXPECT_TRUE(CheckRtp1());
1184 EXPECT_TRUE(CheckRtp2());
1185 EXPECT_TRUE(CheckNoRtp1());
1186 EXPECT_TRUE(CheckNoRtp2());
1187 EXPECT_TRUE(CheckRtcp1());
1188 EXPECT_TRUE(CheckRtcp2());
1189 EXPECT_TRUE(CheckNoRtcp1());
1190 EXPECT_TRUE(CheckNoRtcp2());
1191 }
1192
1193 // Check that RTP and RTCP are transmitted ok when both sides
1194 // require mux.
1195 void SendRequireRtcpMuxToRequireRtcpMux() {
1196 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1197 channel1_->ActivateRtcpMux();
1198 channel2_->ActivateRtcpMux();
1199 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001200 EXPECT_EQ(1U, GetChannels1().size());
1201 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001202 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001203 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001204 SendRtp1();
1205 SendRtp2();
1206 SendRtcp1();
1207 SendRtcp2();
1208 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001209 EXPECT_TRUE(CheckRtp1());
1210 EXPECT_TRUE(CheckRtp2());
1211 EXPECT_TRUE(CheckNoRtp1());
1212 EXPECT_TRUE(CheckNoRtp2());
1213 EXPECT_TRUE(CheckRtcp1());
1214 EXPECT_TRUE(CheckRtcp2());
1215 EXPECT_TRUE(CheckNoRtcp1());
1216 EXPECT_TRUE(CheckNoRtcp2());
1217 }
1218
1219 // Check that SendAccept fails if the answerer doesn't support mux
1220 // and the offerer requires it.
1221 void SendRequireRtcpMuxToNoRtcpMux() {
1222 CreateChannels(RTCP | RTCP_MUX, RTCP);
1223 channel1_->ActivateRtcpMux();
1224 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001225 EXPECT_EQ(1U, GetChannels1().size());
1226 EXPECT_EQ(2U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001227 EXPECT_FALSE(SendAccept());
1228 }
1229
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001230 // Check that RTCP data sent by the initiator before the accept is not muxed.
1231 void SendEarlyRtcpMuxToRtcp() {
1232 CreateChannels(RTCP | RTCP_MUX, RTCP);
1233 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001234 EXPECT_EQ(2U, GetChannels1().size());
1235 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236
1237 // RTCP can be sent before the call is accepted, if the transport is ready.
1238 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001239 SendRtcp1();
1240 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 EXPECT_TRUE(CheckNoRtp2());
1242 EXPECT_TRUE(CheckRtcp2());
1243
1244 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001245 SendRtcp2();
1246 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 EXPECT_TRUE(CheckNoRtp1());
1248 EXPECT_TRUE(CheckRtcp1());
1249
1250 // Complete call setup and ensure everything is still OK.
1251 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001252 EXPECT_EQ(2U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001253 SendRtcp1();
1254 SendRtcp2();
1255 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 EXPECT_TRUE(CheckRtcp1());
1258 }
1259
1260
1261 // Check that RTCP data is not muxed until both sides have enabled muxing,
1262 // but that we properly demux before we get the accept message, since there
1263 // is a race between RTP data and the jingle accept.
1264 void SendEarlyRtcpMuxToRtcpMux() {
1265 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1266 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001267 EXPECT_EQ(2U, GetChannels1().size());
1268 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001269
1270 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1271 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001272 SendRtcp1();
1273 WaitForThreads();
1274 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275
1276 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001277 SendRtcp2();
1278 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 EXPECT_TRUE(CheckNoRtp1());
1280 EXPECT_TRUE(CheckRtcp1());
1281
1282 // Complete call setup and ensure everything is still OK.
1283 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001284 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001285 SendRtcp1();
1286 SendRtcp2();
1287 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 EXPECT_TRUE(CheckRtcp1());
1290 }
1291
1292 // Test that we properly send SRTP with RTCP in both directions.
1293 // You can pass in DTLS and/or RTCP_MUX as flags.
1294 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
jbauchcb560652016-08-04 05:20:32 -07001295 ASSERT((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1296 ASSERT((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297
1298 int flags1 = RTCP | SECURE | flags1_in;
1299 int flags2 = RTCP | SECURE | flags2_in;
1300 bool dtls1 = !!(flags1_in & DTLS);
1301 bool dtls2 = !!(flags2_in & DTLS);
1302 CreateChannels(flags1, flags2);
1303 EXPECT_FALSE(channel1_->secure());
1304 EXPECT_FALSE(channel2_->secure());
1305 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001306 WaitForThreads();
1307 EXPECT_TRUE(channel1_->writable());
1308 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 EXPECT_TRUE(SendAccept());
1310 EXPECT_TRUE(channel1_->secure());
1311 EXPECT_TRUE(channel2_->secure());
1312 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1313 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001314 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1315 // channels.
1316 if (dtls1 && dtls2) {
1317 // A GCM cipher is only used if both channels support GCM ciphers.
1318 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1319 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1320 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1321 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001322 SendRtp1();
1323 SendRtp2();
1324 SendRtcp1();
1325 SendRtcp2();
1326 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 EXPECT_TRUE(CheckRtp1());
1328 EXPECT_TRUE(CheckRtp2());
1329 EXPECT_TRUE(CheckNoRtp1());
1330 EXPECT_TRUE(CheckNoRtp2());
1331 EXPECT_TRUE(CheckRtcp1());
1332 EXPECT_TRUE(CheckRtcp2());
1333 EXPECT_TRUE(CheckNoRtcp1());
1334 EXPECT_TRUE(CheckNoRtcp2());
1335 }
1336
1337 // Test that we properly handling SRTP negotiating down to RTP.
1338 void SendSrtpToRtp() {
1339 CreateChannels(RTCP | SECURE, RTCP);
1340 EXPECT_FALSE(channel1_->secure());
1341 EXPECT_FALSE(channel2_->secure());
1342 EXPECT_TRUE(SendInitiate());
1343 EXPECT_TRUE(SendAccept());
1344 EXPECT_FALSE(channel1_->secure());
1345 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001346 SendRtp1();
1347 SendRtp2();
1348 SendRtcp1();
1349 SendRtcp2();
1350 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 EXPECT_TRUE(CheckRtp1());
1352 EXPECT_TRUE(CheckRtp2());
1353 EXPECT_TRUE(CheckNoRtp1());
1354 EXPECT_TRUE(CheckNoRtp2());
1355 EXPECT_TRUE(CheckRtcp1());
1356 EXPECT_TRUE(CheckRtcp2());
1357 EXPECT_TRUE(CheckNoRtcp1());
1358 EXPECT_TRUE(CheckNoRtcp2());
1359 }
1360
1361 // Test that we can send and receive early media when a provisional answer is
1362 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1363 void SendEarlyMediaUsingRtcpMuxSrtp() {
1364 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1365
1366 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1367 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1368 EXPECT_TRUE(SendOffer());
1369 EXPECT_TRUE(SendProvisionalAnswer());
1370 EXPECT_TRUE(channel1_->secure());
1371 EXPECT_TRUE(channel2_->secure());
deadbeef49f34fd2016-12-06 16:22:06 -08001372 EXPECT_EQ(2U, GetChannels1().size());
1373 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001374 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1375 SendCustomRtcp1(kSsrc1);
1376 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1377 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1380
1381 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001382 SendCustomRtcp2(kSsrc2);
1383 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1384 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1387
1388 // Complete call setup and ensure everything is still OK.
1389 EXPECT_TRUE(SendFinalAnswer());
deadbeef49f34fd2016-12-06 16:22:06 -08001390 EXPECT_EQ(1U, GetChannels1().size());
1391 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392 EXPECT_TRUE(channel1_->secure());
1393 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001394 SendCustomRtcp1(kSsrc1);
1395 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1396 SendCustomRtcp2(kSsrc2);
1397 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1398 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1403 }
1404
1405 // Test that we properly send RTP without SRTP from a thread.
1406 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001407 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 EXPECT_TRUE(SendInitiate());
1409 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001410 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1411 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1412 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1413 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1414 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1415 send_rtcp1.thread(),
1416 send_rtcp2.thread()};
1417 WaitForThreads(involved_threads);
1418 EXPECT_TRUE(CheckRtp1());
1419 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 EXPECT_TRUE(CheckNoRtp1());
1421 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001422 EXPECT_TRUE(CheckRtcp1());
1423 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_TRUE(CheckNoRtcp1());
1425 EXPECT_TRUE(CheckNoRtcp2());
1426 }
1427
1428 // Test that we properly send SRTP with RTCP from a thread.
1429 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1431 EXPECT_TRUE(SendInitiate());
1432 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001433 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1434 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1435 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1436 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1437 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1438 send_rtcp1.thread(),
1439 send_rtcp2.thread()};
1440 WaitForThreads(involved_threads);
1441 EXPECT_TRUE(CheckRtp1());
1442 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 EXPECT_TRUE(CheckNoRtp1());
1444 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001445 EXPECT_TRUE(CheckRtcp1());
1446 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 EXPECT_TRUE(CheckNoRtcp1());
1448 EXPECT_TRUE(CheckNoRtcp2());
1449 }
1450
1451 // Test that the mediachannel retains its sending state after the transport
1452 // becomes non-writable.
1453 void SendWithWritabilityLoss() {
1454 CreateChannels(0, 0);
1455 EXPECT_TRUE(SendInitiate());
1456 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001457 EXPECT_EQ(1U, GetChannels1().size());
1458 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001459 SendRtp1();
1460 SendRtp2();
1461 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_TRUE(CheckRtp1());
1463 EXPECT_TRUE(CheckRtp2());
1464 EXPECT_TRUE(CheckNoRtp1());
1465 EXPECT_TRUE(CheckNoRtp2());
1466
wu@webrtc.org97077a32013-10-25 21:18:33 +00001467 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001468 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001469 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001470 SendRtp1();
1471 SendRtp2();
1472 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 EXPECT_TRUE(CheckRtp1());
1474 EXPECT_TRUE(CheckNoRtp2());
1475
1476 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001477 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001478 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001480 SendRtp1();
1481 SendRtp2();
1482 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 EXPECT_TRUE(CheckRtp1());
1484 EXPECT_TRUE(CheckRtp2());
1485 EXPECT_TRUE(CheckNoRtp1());
1486 EXPECT_TRUE(CheckNoRtp2());
1487
1488 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001489 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001490 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetDestination(nullptr); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 EXPECT_TRUE(media_channel1_->sending());
1492
wu@webrtc.org97077a32013-10-25 21:18:33 +00001493 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001494 SendRtp1();
1495 SendRtp2();
1496 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 EXPECT_TRUE(CheckRtp1());
1498 EXPECT_TRUE(CheckNoRtp2());
1499
1500 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001501 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeef49f34fd2016-12-06 16:22:06 -08001502 GetFakeChannel1(1)->SetDestination(GetFakeChannel2(1));
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001503 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001505 SendRtp1();
1506 SendRtp2();
1507 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 EXPECT_TRUE(CheckRtp1());
1509 EXPECT_TRUE(CheckRtp2());
1510 EXPECT_TRUE(CheckNoRtp1());
1511 EXPECT_TRUE(CheckNoRtp2());
1512 }
1513
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001514 void SendBundleToBundle(
1515 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1516 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001518 // Only pl_type1 was added to the bundle filter for both |channel1_|
1519 // and |channel2_|.
1520 int pl_type1 = pl_types[0];
1521 int pl_type2 = pl_types[1];
1522 int flags = SSRC_MUX | RTCP;
1523 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001524 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001525 if (rtcp_mux) {
1526 flags |= RTCP_MUX;
1527 expected_channels = 1U;
1528 }
1529 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001531 EXPECT_EQ(2U, GetChannels1().size());
1532 EXPECT_EQ(expected_channels, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001534 EXPECT_EQ(expected_channels, GetChannels1().size());
1535 EXPECT_EQ(expected_channels, GetChannels2().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001536 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1537 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1538 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1539 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001540
1541 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001542 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1543 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1544 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001545 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001546 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1547 EXPECT_TRUE(CheckNoRtp1());
1548 EXPECT_TRUE(CheckNoRtp2());
1549
1550 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001551 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1552 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1553 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001554 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001555 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1556
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001557 SendCustomRtcp1(kSsrc1);
1558 SendCustomRtcp2(kSsrc2);
1559 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1561 EXPECT_TRUE(CheckNoRtcp1());
1562 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1563 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001565 SendCustomRtcp1(kSsrc2);
1566 SendCustomRtcp2(kSsrc1);
1567 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001568 // Bundle filter shouldn't filter out any RTCP.
1569 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1570 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 }
1572
deadbeefc6b6e092016-12-01 12:49:20 -08001573 // Test that the media monitor can be run and gives callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 void TestMediaMonitor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 CreateChannels(0, 0);
1576 EXPECT_TRUE(SendInitiate());
1577 EXPECT_TRUE(SendAccept());
1578 channel1_->StartMediaMonitor(100);
1579 channel2_->StartMediaMonitor(100);
1580 // Ensure we get callbacks and stop.
deadbeefc6b6e092016-12-01 12:49:20 -08001581 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
1582 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 channel1_->StopMediaMonitor();
1584 channel2_->StopMediaMonitor();
1585 // Ensure a restart of a stopped monitor works.
1586 channel1_->StartMediaMonitor(100);
deadbeefc6b6e092016-12-01 12:49:20 -08001587 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 channel1_->StopMediaMonitor();
1589 // Ensure stopping a stopped monitor is OK.
1590 channel1_->StopMediaMonitor();
1591 }
1592
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 void TestSetContentFailure() {
1594 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595
Peter Thatchera6d24442015-07-09 21:26:36 -07001596 auto sdesc = cricket::SessionDescription();
1597 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1598 new cricket::AudioContentDescription());
1599 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1600 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601
Peter Thatchera6d24442015-07-09 21:26:36 -07001602 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001604 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1605 &sdesc, cricket::CA_OFFER, &err));
1606 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1607 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001610 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1611 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001613 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1614 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 }
1616
1617 void TestSendTwoOffers() {
1618 CreateChannels(0, 0);
1619
Peter Thatchera6d24442015-07-09 21:26:36 -07001620 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001621 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001622 CreateSessionDescriptionWithStream(1));
1623 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1624 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1626
kwiberg31022942016-03-11 14:18:21 -08001627 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001628 CreateSessionDescriptionWithStream(2));
1629 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1630 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1632 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1633 }
1634
1635 void TestReceiveTwoOffers() {
1636 CreateChannels(0, 0);
1637
Peter Thatchera6d24442015-07-09 21:26:36 -07001638 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001639 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001640 CreateSessionDescriptionWithStream(1));
1641 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1642 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1644
kwiberg31022942016-03-11 14:18:21 -08001645 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001646 CreateSessionDescriptionWithStream(2));
1647 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1648 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1650 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1651 }
1652
1653 void TestSendPrAnswer() {
1654 CreateChannels(0, 0);
1655
Peter Thatchera6d24442015-07-09 21:26:36 -07001656 std::string err;
1657 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001658 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001659 CreateSessionDescriptionWithStream(1));
1660 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1661 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1663
Peter Thatchera6d24442015-07-09 21:26:36 -07001664 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001665 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001666 CreateSessionDescriptionWithStream(2));
1667 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1668 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1670 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1671
Peter Thatchera6d24442015-07-09 21:26:36 -07001672 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001673 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001674 CreateSessionDescriptionWithStream(3));
1675 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1676 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1678 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1679 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1680 }
1681
1682 void TestReceivePrAnswer() {
1683 CreateChannels(0, 0);
1684
Peter Thatchera6d24442015-07-09 21:26:36 -07001685 std::string err;
1686 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001687 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001688 CreateSessionDescriptionWithStream(1));
1689 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1690 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1692
Peter Thatchera6d24442015-07-09 21:26:36 -07001693 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001694 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001695 CreateSessionDescriptionWithStream(2));
1696 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1697 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1699 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1700
Peter Thatchera6d24442015-07-09 21:26:36 -07001701 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001702 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001703 CreateSessionDescriptionWithStream(3));
1704 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1705 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1707 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1708 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1709 }
1710
1711 void TestFlushRtcp() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 CreateChannels(RTCP, RTCP);
1713 EXPECT_TRUE(SendInitiate());
1714 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001715 EXPECT_EQ(2U, GetChannels1().size());
1716 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717
1718 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001719 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 // The sending message is only posted. channel2_ should be empty.
1721 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001722 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1723 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724
1725 // When channel1_ is deleted, the RTCP packet should be sent out to
1726 // channel2_.
1727 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001728 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 EXPECT_TRUE(CheckRtcp2());
1730 }
1731
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001732 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001733 struct SrtpErrorHandler : public sigslot::has_slots<> {
1734 SrtpErrorHandler() :
1735 mode_(cricket::SrtpFilter::UNPROTECT),
1736 error_(cricket::SrtpFilter::ERROR_NONE) {}
1737 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1738 cricket::SrtpFilter::Error error) {
1739 mode_ = mode;
1740 error_ = error;
1741 }
1742 cricket::SrtpFilter::Mode mode_;
1743 cricket::SrtpFilter::Error error_;
1744 } error_handler;
1745
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001746 // For Audio, only pl_type 0 is added to the bundle filter.
1747 // For Video, only pl_type 97 is added to the bundle filter.
1748 // So we need to pass in pl_type so that the packet can pass through
1749 // the bundle filter before it can be processed by the srtp filter.
1750 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001751 static unsigned const char kBadPacket[] = {
1752 0x84, static_cast<unsigned char>(pl_type),
1753 0x00, 0x01,
1754 0x00, 0x00,
1755 0x00, 0x00,
1756 0x00, 0x00,
1757 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001758
1759 // Using fake clock because this tests that SRTP errors are signaled at
1760 // specific times based on set_signal_silent_time.
1761 rtc::ScopedFakeClock fake_clock;
1762 // Some code uses a time of 0 as a special value, so we must start with
1763 // a non-zero time.
1764 // TODO(deadbeef): Fix this.
1765 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1766
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1768 EXPECT_FALSE(channel1_->secure());
1769 EXPECT_FALSE(channel2_->secure());
1770 EXPECT_TRUE(SendInitiate());
1771 EXPECT_TRUE(SendAccept());
1772 EXPECT_TRUE(channel1_->secure());
1773 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001774 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001775 channel2_->srtp_filter()->SignalSrtpError.connect(
1776 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777
1778 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001779 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1780 rtc::PacketOptions());
1781 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001783 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001784 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1785 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001786 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1787 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001788 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1789 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001791 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001792 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001793 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001794 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1795 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001796 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001797 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1798 rtc::PacketOptions());
1799 WaitForThreads();
1800 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001801 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802
1803 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001804 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001805 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001806
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001807 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001808 cricket::TransportChannel* transport_channel =
1809 channel2_->transport_channel();
1810 transport_channel->SignalReadPacket(
1811 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1812 sizeof(kBadPacket), rtc::PacketTime(), 0);
1813 });
1814 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001815 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001816 // Terminate channels before the fake clock is destroyed.
1817 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 }
1819
1820 void TestOnReadyToSend() {
1821 CreateChannels(RTCP, RTCP);
1822 TransportChannel* rtp = channel1_->transport_channel();
1823 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1824 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001825
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001826 network_thread_->Invoke<void>(RTC_FROM_HERE,
1827 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001828 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001830
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001831 network_thread_->Invoke<void>(RTC_FROM_HERE,
1832 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001833 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1835 // channel are ready to send.
1836 EXPECT_TRUE(media_channel1_->ready_to_send());
1837
1838 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001839 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1840 channel1_->SetTransportChannelReadyToSend(false, false);
1841 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001842 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001844
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001845 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1846 channel1_->SetTransportChannelReadyToSend(false, true);
1847 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001848 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 EXPECT_TRUE(media_channel1_->ready_to_send());
1850
1851 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001852 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1853 channel1_->SetTransportChannelReadyToSend(true, false);
1854 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001855 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001857
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001858 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1859 channel1_->SetTransportChannelReadyToSend(true, true);
1860 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001861 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 EXPECT_TRUE(media_channel1_->ready_to_send());
1863 }
1864
1865 void TestOnReadyToSendWithRtcpMux() {
1866 CreateChannels(RTCP, RTCP);
1867 typename T::Content content;
1868 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1869 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1870 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001871 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1872 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1874 TransportChannel* rtp = channel1_->transport_channel();
1875 EXPECT_FALSE(media_channel1_->ready_to_send());
1876 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1877 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001878 network_thread_->Invoke<void>(RTC_FROM_HERE,
1879 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001880 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001882
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001883 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1884 channel1_->SetTransportChannelReadyToSend(false, false);
1885 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001886 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 EXPECT_FALSE(media_channel1_->ready_to_send());
1888 }
1889
skvladdc1c62c2016-03-16 19:07:43 -07001890 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1891 typename T::Content content;
1892 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1893 content.set_bandwidth(remote_limit);
1894 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1895 }
1896
1897 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1898 webrtc::RtpParameters parameters;
1899 webrtc::RtpEncodingParameters encoding;
1900 encoding.max_bitrate_bps = limit;
1901 parameters.encodings.push_back(encoding);
1902 return parameters;
1903 }
1904
1905 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1906 int expected_bitrate) {
1907 EXPECT_EQ(1UL, parameters.encodings.size());
1908 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1909 }
1910
1911 void DefaultMaxBitrateIsUnlimited() {
1912 CreateChannels(0, 0);
1913 EXPECT_TRUE(
1914 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1915 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001916 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001917 }
1918
1919 void CanChangeMaxBitrate() {
1920 CreateChannels(0, 0);
1921 EXPECT_TRUE(
1922 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1923
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001924 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1925 kSsrc1, BitrateLimitedParameters(1000)));
1926 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1927 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001928 EXPECT_EQ(-1, media_channel1_->max_bps());
1929
1930 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001931 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1932 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1933 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001934 EXPECT_EQ(-1, media_channel1_->max_bps());
1935 }
1936
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001938 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1939 static void ProcessThreadQueue(rtc::Thread* thread) {
1940 RTC_DCHECK(thread->IsCurrent());
1941 while (!thread->empty()) {
1942 thread->ProcessMessages(0);
1943 }
1944 }
1945 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1946 // |threads| and current thread post packets to network thread.
1947 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001948 thread->Invoke<void>(RTC_FROM_HERE,
1949 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001950 }
1951 ProcessThreadQueue(rtc::Thread::Current());
1952 // Network thread move them around and post back to worker = current thread.
1953 if (!network_thread_->IsCurrent()) {
1954 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001955 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001956 }
1957 // Worker thread = current Thread process received messages.
1958 ProcessThreadQueue(rtc::Thread::Current());
1959 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001960 // TODO(pbos): Remove playout from all media channels and let renderers mute
1961 // themselves.
1962 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001963 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1964 rtc::Thread* network_thread_;
1965 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1966 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 cricket::FakeMediaEngine media_engine_;
1968 // The media channels are owned by the voice channel objects below.
1969 typename T::MediaChannel* media_channel1_;
1970 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001971 std::unique_ptr<typename T::Channel> channel1_;
1972 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 typename T::Content local_media_content1_;
1974 typename T::Content local_media_content2_;
1975 typename T::Content remote_media_content1_;
1976 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001978 rtc::Buffer rtp_packet_;
1979 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 int media_info_callbacks1_;
1981 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001982 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983};
1984
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985template<>
1986void ChannelTest<VoiceTraits>::CreateContent(
1987 int flags,
1988 const cricket::AudioCodec& audio_codec,
1989 const cricket::VideoCodec& video_codec,
1990 cricket::AudioContentDescription* audio) {
1991 audio->AddCodec(audio_codec);
1992 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1993 if (flags & SECURE) {
1994 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001995 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1996 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 }
1998}
1999
2000template<>
2001void ChannelTest<VoiceTraits>::CopyContent(
2002 const cricket::AudioContentDescription& source,
2003 cricket::AudioContentDescription* audio) {
2004 *audio = source;
2005}
2006
2007template<>
2008bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2009 const cricket::AudioCodec& c2) {
2010 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2011 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2012}
2013
Peter Boström0c4e06b2015-10-07 12:23:21 +02002014template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002016 uint32_t ssrc,
2017 int flags,
2018 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019 audio->AddLegacyStream(ssrc);
2020}
2021
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002022class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 public:
solenberg1dd98f32015-09-10 01:57:14 -07002024 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002025 VoiceChannelSingleThreadTest()
2026 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2027};
2028
2029class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2030 public:
2031 typedef ChannelTest<VoiceTraits> Base;
2032 VoiceChannelDoubleThreadTest()
2033 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034};
2035
2036// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002037template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002039 rtc::Thread* worker_thread,
2040 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002041 cricket::MediaEngineInterface* engine,
2042 cricket::FakeVideoMediaChannel* ch,
2043 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002044 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002045 cricket::VideoChannel* channel =
2046 new cricket::VideoChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07002047 transport_controller, cricket::CN_VIDEO,
2048 (flags & RTCP) != 0);
2049 rtc::CryptoOptions crypto_options;
2050 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2051 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07002052 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 delete channel;
2054 channel = NULL;
2055 }
2056 return channel;
2057}
2058
2059// override to add 0 parameter
2060template<>
2061bool ChannelTest<VideoTraits>::AddStream1(int id) {
2062 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2063}
2064
2065template<>
2066void ChannelTest<VideoTraits>::CreateContent(
2067 int flags,
2068 const cricket::AudioCodec& audio_codec,
2069 const cricket::VideoCodec& video_codec,
2070 cricket::VideoContentDescription* video) {
2071 video->AddCodec(video_codec);
2072 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2073 if (flags & SECURE) {
2074 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002075 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2076 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 }
2078}
2079
2080template<>
2081void ChannelTest<VideoTraits>::CopyContent(
2082 const cricket::VideoContentDescription& source,
2083 cricket::VideoContentDescription* video) {
2084 *video = source;
2085}
2086
2087template<>
2088bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2089 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002090 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091}
2092
Peter Boström0c4e06b2015-10-07 12:23:21 +02002093template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002095 uint32_t ssrc,
2096 int flags,
2097 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 video->AddLegacyStream(ssrc);
2099}
2100
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002101class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 public:
solenberg1dd98f32015-09-10 01:57:14 -07002103 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002104 VideoChannelSingleThreadTest()
2105 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106};
2107
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002108class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2109 public:
2110 typedef ChannelTest<VideoTraits> Base;
2111 VideoChannelDoubleThreadTest()
2112 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2113};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002115// VoiceChannelSingleThreadTest
2116TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 Base::TestInit();
2118 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2119 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2120}
2121
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002122TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2123 Base::TestDeinit();
2124}
2125
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002126TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 Base::TestSetContents();
2128}
2129
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002130TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 Base::TestSetContentsNullOffer();
2132}
2133
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002134TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 Base::TestSetContentsRtcpMux();
2136}
2137
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002138TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 Base::TestSetContentsRtcpMux();
2140}
2141
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002142TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 Base::TestSetRemoteContentUpdate();
2144}
2145
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002146TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 Base::TestStreams();
2148}
2149
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002150TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 Base::TestUpdateStreamsInLocalContent();
2152}
2153
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002154TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 Base::TestUpdateStreamsInRemoteContent();
2156}
2157
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002158TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 Base::TestChangeStreamParamsInContent();
2160}
2161
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002162TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 Base::TestPlayoutAndSendingStates();
2164}
2165
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002166TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002167 CreateChannels(0, 0);
2168 // Test that we can Mute the default channel even though the sending SSRC
2169 // is unknown.
2170 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002171 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002172 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2173 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002174 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2175
2176 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002177 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002178
2179 SendInitiate();
2180 // After the local session description has been set, we can mute a stream
2181 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002182 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002183 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2184 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002185 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186}
2187
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002188TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 Base::TestMediaContentDirection();
2190}
2191
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002192TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002193 Base::TestNetworkRouteChanges();
2194}
2195
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002196TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197 Base::TestCallSetup();
2198}
2199
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002200TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 Base::TestCallTeardownRtcpMux();
2202}
2203
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002204TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205 Base::SendRtpToRtp();
2206}
2207
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002208TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 Base::SendNoRtcpToNoRtcp();
2210}
2211
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002212TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 Base::SendNoRtcpToRtcp();
2214}
2215
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002216TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 Base::SendRtcpToNoRtcp();
2218}
2219
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002220TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 Base::SendRtcpToRtcp();
2222}
2223
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002224TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 Base::SendRtcpMuxToRtcp();
2226}
2227
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002228TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 Base::SendRtcpMuxToRtcpMux();
2230}
2231
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002232TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002233 Base::SendRequireRtcpMuxToRtcpMux();
2234}
2235
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002236TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002237 Base::SendRtcpMuxToRequireRtcpMux();
2238}
2239
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002240TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002241 Base::SendRequireRtcpMuxToRequireRtcpMux();
2242}
2243
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002244TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002245 Base::SendRequireRtcpMuxToNoRtcpMux();
2246}
2247
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002248TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 Base::SendEarlyRtcpMuxToRtcp();
2250}
2251
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002252TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 Base::SendEarlyRtcpMuxToRtcpMux();
2254}
2255
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002256TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2258}
2259
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002260TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 Base::SendSrtpToSrtp();
2262}
2263
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002264TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2266}
2267
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002268TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2270 Base::SendSrtpToSrtp(DTLS, 0);
2271}
2272
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002273TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2275 Base::SendSrtpToSrtp(DTLS, DTLS);
2276}
2277
jbauchcb560652016-08-04 05:20:32 -07002278TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2279 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2280 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2281}
2282
2283TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2284 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2285 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2286}
2287
2288TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2289 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2290 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2291}
2292
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002293TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2295 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2296}
2297
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002298TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2300}
2301
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002302TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 Base::SendRtpToRtpOnThread();
2304}
2305
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002306TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 Base::SendSrtpToSrtpOnThread();
2308}
2309
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002310TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 Base::SendWithWritabilityLoss();
2312}
2313
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002314TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 Base::TestMediaMonitor();
2316}
2317
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002319TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 CreateChannels(0, 0);
2321 EXPECT_TRUE(SendInitiate());
2322 EXPECT_TRUE(SendAccept());
2323 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2324
solenberg1d63dd02015-12-02 12:35:09 -08002325 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2326 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2327 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002329 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002331 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002332 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002333 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002334 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002335 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336}
2337
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002338TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 Base::TestSetContentFailure();
2340}
2341
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002342TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 Base::TestSendTwoOffers();
2344}
2345
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002346TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 Base::TestReceiveTwoOffers();
2348}
2349
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002350TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 Base::TestSendPrAnswer();
2352}
2353
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002354TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 Base::TestReceivePrAnswer();
2356}
2357
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002358TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 Base::TestFlushRtcp();
2360}
2361
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002362TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002363 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364}
2365
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002366TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 Base::TestOnReadyToSend();
2368}
2369
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002370TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 Base::TestOnReadyToSendWithRtcpMux();
2372}
2373
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002375TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 CreateChannels(RTCP, RTCP);
2377 EXPECT_TRUE(SendInitiate());
2378 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002379 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380
solenberg4bac9c52015-10-09 02:32:53 -07002381 // Default is (1.0).
2382 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2383 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002385 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386
solenberg4bac9c52015-10-09 02:32:53 -07002387 // Set scale to (1.5).
2388 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2389 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2390 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391
solenberg4bac9c52015-10-09 02:32:53 -07002392 // Set scale to (0).
2393 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2394 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2395 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396}
2397
2398// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002399TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 CreateChannels(RTCP, RTCP);
2401 EXPECT_TRUE(SendInitiate());
2402 EXPECT_TRUE(SendAccept());
2403 EXPECT_TRUE(AddStream1(1));
2404 EXPECT_TRUE(AddStream1(2));
2405
solenberg4bac9c52015-10-09 02:32:53 -07002406 double volume;
2407 // Default is (1.0).
2408 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2409 EXPECT_DOUBLE_EQ(1.0, volume);
2410 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2411 EXPECT_DOUBLE_EQ(1.0, volume);
2412 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2413 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002415 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416
solenberg4bac9c52015-10-09 02:32:53 -07002417 // Set scale to (1.5) for ssrc = 1.
2418 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2419 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2420 EXPECT_DOUBLE_EQ(1.5, volume);
2421 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2422 EXPECT_DOUBLE_EQ(1.0, volume);
2423 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2424 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425
solenberg4bac9c52015-10-09 02:32:53 -07002426 // Set scale to (0) for all ssrcs.
2427 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2428 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2429 EXPECT_DOUBLE_EQ(0.0, volume);
2430 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2431 EXPECT_DOUBLE_EQ(0.0, volume);
2432 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2433 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434}
2435
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002436TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002437 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438}
2439
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002440TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002441 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002442}
2443
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002444TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002445 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002446}
2447
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002448TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002449 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450}
2451
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002452TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002453 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002454}
2455
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002456TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002457 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002458}
2459
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002460// VoiceChannelDoubleThreadTest
2461TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002463 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2464 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465}
2466
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002467TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2468 Base::TestDeinit();
2469}
2470
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002471TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 Base::TestSetContents();
2473}
2474
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002475TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 Base::TestSetContentsNullOffer();
2477}
2478
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002479TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 Base::TestSetContentsRtcpMux();
2481}
2482
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002483TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 Base::TestSetContentsRtcpMux();
2485}
2486
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002487TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488 Base::TestSetRemoteContentUpdate();
2489}
2490
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002491TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 Base::TestStreams();
2493}
2494
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002495TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 Base::TestUpdateStreamsInLocalContent();
2497}
2498
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002499TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500 Base::TestUpdateStreamsInRemoteContent();
2501}
2502
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002503TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 Base::TestChangeStreamParamsInContent();
2505}
2506
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002507TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 Base::TestPlayoutAndSendingStates();
2509}
2510
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002511TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2512 CreateChannels(0, 0);
2513 // Test that we can Mute the default channel even though the sending SSRC
2514 // is unknown.
2515 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2516 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2517 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2518 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2519 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2520
2521 // Test that we can not mute an unknown SSRC.
2522 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2523
2524 SendInitiate();
2525 // After the local session description has been set, we can mute a stream
2526 // with its SSRC.
2527 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2528 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2529 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2530 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2531}
2532
2533TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2534 Base::TestMediaContentDirection();
2535}
2536
2537TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2538 Base::TestNetworkRouteChanges();
2539}
2540
2541TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2542 Base::TestCallSetup();
2543}
2544
2545TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2546 Base::TestCallTeardownRtcpMux();
2547}
2548
2549TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2550 Base::SendRtpToRtp();
2551}
2552
2553TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2554 Base::SendNoRtcpToNoRtcp();
2555}
2556
2557TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2558 Base::SendNoRtcpToRtcp();
2559}
2560
2561TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2562 Base::SendRtcpToNoRtcp();
2563}
2564
2565TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2566 Base::SendRtcpToRtcp();
2567}
2568
2569TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2570 Base::SendRtcpMuxToRtcp();
2571}
2572
2573TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2574 Base::SendRtcpMuxToRtcpMux();
2575}
2576
2577TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2578 Base::SendRequireRtcpMuxToRtcpMux();
2579}
2580
2581TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2582 Base::SendRtcpMuxToRequireRtcpMux();
2583}
2584
2585TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2586 Base::SendRequireRtcpMuxToRequireRtcpMux();
2587}
2588
2589TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2590 Base::SendRequireRtcpMuxToNoRtcpMux();
2591}
2592
2593TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2594 Base::SendEarlyRtcpMuxToRtcp();
2595}
2596
2597TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2598 Base::SendEarlyRtcpMuxToRtcpMux();
2599}
2600
2601TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2602 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2603}
2604
2605TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2606 Base::SendSrtpToSrtp();
2607}
2608
2609TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2610 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2611}
2612
2613TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2614 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2615 Base::SendSrtpToSrtp(DTLS, 0);
2616}
2617
2618TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2619 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2620 Base::SendSrtpToSrtp(DTLS, DTLS);
2621}
2622
jbauchcb560652016-08-04 05:20:32 -07002623TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2624 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2625 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2626}
2627
2628TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2629 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2630 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2631}
2632
2633TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2634 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2635 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2636}
2637
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002638TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2639 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2640 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2641}
2642
2643TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2644 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2645}
2646
2647TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2648 Base::SendRtpToRtpOnThread();
2649}
2650
2651TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2652 Base::SendSrtpToSrtpOnThread();
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2656 Base::SendWithWritabilityLoss();
2657}
2658
2659TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2660 Base::TestMediaMonitor();
2661}
2662
2663// Test that InsertDtmf properly forwards to the media channel.
2664TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2665 CreateChannels(0, 0);
2666 EXPECT_TRUE(SendInitiate());
2667 EXPECT_TRUE(SendAccept());
2668 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2669
2670 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2671 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2672 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2673
2674 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2675 EXPECT_TRUE(
2676 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2677 EXPECT_TRUE(
2678 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2679 EXPECT_TRUE(
2680 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2681}
2682
2683TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2684 Base::TestSetContentFailure();
2685}
2686
2687TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2688 Base::TestSendTwoOffers();
2689}
2690
2691TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2692 Base::TestReceiveTwoOffers();
2693}
2694
2695TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2696 Base::TestSendPrAnswer();
2697}
2698
2699TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2700 Base::TestReceivePrAnswer();
2701}
2702
2703TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2704 Base::TestFlushRtcp();
2705}
2706
2707TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2708 Base::TestSrtpError(kAudioPts[0]);
2709}
2710
2711TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2712 Base::TestOnReadyToSend();
2713}
2714
2715TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2716 Base::TestOnReadyToSendWithRtcpMux();
2717}
2718
2719// Test that we can scale the output volume properly for 1:1 calls.
2720TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2721 CreateChannels(RTCP, RTCP);
2722 EXPECT_TRUE(SendInitiate());
2723 EXPECT_TRUE(SendAccept());
2724 double volume;
2725
2726 // Default is (1.0).
2727 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2728 EXPECT_DOUBLE_EQ(1.0, volume);
2729 // invalid ssrc.
2730 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2731
2732 // Set scale to (1.5).
2733 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2734 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2735 EXPECT_DOUBLE_EQ(1.5, volume);
2736
2737 // Set scale to (0).
2738 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2739 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2740 EXPECT_DOUBLE_EQ(0.0, volume);
2741}
2742
2743// Test that we can scale the output volume properly for multiway calls.
2744TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2745 CreateChannels(RTCP, RTCP);
2746 EXPECT_TRUE(SendInitiate());
2747 EXPECT_TRUE(SendAccept());
2748 EXPECT_TRUE(AddStream1(1));
2749 EXPECT_TRUE(AddStream1(2));
2750
2751 double volume;
2752 // Default is (1.0).
2753 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2754 EXPECT_DOUBLE_EQ(1.0, volume);
2755 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2756 EXPECT_DOUBLE_EQ(1.0, volume);
2757 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2758 EXPECT_DOUBLE_EQ(1.0, volume);
2759 // invalid ssrc.
2760 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2761
2762 // Set scale to (1.5) for ssrc = 1.
2763 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2764 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2765 EXPECT_DOUBLE_EQ(1.5, volume);
2766 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2767 EXPECT_DOUBLE_EQ(1.0, volume);
2768 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2769 EXPECT_DOUBLE_EQ(1.0, volume);
2770
2771 // Set scale to (0) for all ssrcs.
2772 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2773 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2774 EXPECT_DOUBLE_EQ(0.0, volume);
2775 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2776 EXPECT_DOUBLE_EQ(0.0, volume);
2777 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2778 EXPECT_DOUBLE_EQ(0.0, volume);
2779}
2780
2781TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2782 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2783}
2784
2785TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2786 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2787}
2788
2789TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2790 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2791}
2792
2793TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2794 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2795}
2796
2797TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2798 Base::DefaultMaxBitrateIsUnlimited();
2799}
2800
2801TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2802 Base::CanChangeMaxBitrate();
2803}
2804
2805// VideoChannelSingleThreadTest
2806TEST_F(VideoChannelSingleThreadTest, TestInit) {
2807 Base::TestInit();
2808}
2809
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002810TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2811 Base::TestDeinit();
2812}
2813
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002814TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2815 Base::TestSetContents();
2816}
2817
2818TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2819 Base::TestSetContentsNullOffer();
2820}
2821
2822TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2823 Base::TestSetContentsRtcpMux();
2824}
2825
2826TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2827 Base::TestSetContentsRtcpMux();
2828}
2829
2830TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2831 Base::TestSetRemoteContentUpdate();
2832}
2833
2834TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2835 Base::TestStreams();
2836}
2837
2838TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2839 Base::TestUpdateStreamsInLocalContent();
2840}
2841
2842TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2843 Base::TestUpdateStreamsInRemoteContent();
2844}
2845
2846TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2847 Base::TestChangeStreamParamsInContent();
2848}
2849
2850TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2851 Base::TestPlayoutAndSendingStates();
2852}
2853
2854TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002855 CreateChannels(0, 0);
2856 // Test that we can Mute the default channel even though the sending SSRC
2857 // is unknown.
2858 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002859 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002860 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002861 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002862 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2863 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002864 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002865 SendInitiate();
2866 // After the local session description has been set, we can mute a stream
2867 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002868 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002869 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002870 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002871 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002872}
2873
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002874TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875 Base::TestMediaContentDirection();
2876}
2877
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002878TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002879 Base::TestNetworkRouteChanges();
2880}
2881
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002882TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883 Base::TestCallSetup();
2884}
2885
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002886TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 Base::TestCallTeardownRtcpMux();
2888}
2889
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002890TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891 Base::SendRtpToRtp();
2892}
2893
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002894TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 Base::SendNoRtcpToNoRtcp();
2896}
2897
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002898TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899 Base::SendNoRtcpToRtcp();
2900}
2901
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002902TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 Base::SendRtcpToNoRtcp();
2904}
2905
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002906TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907 Base::SendRtcpToRtcp();
2908}
2909
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002910TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002911 Base::SendRtcpMuxToRtcp();
2912}
2913
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002914TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915 Base::SendRtcpMuxToRtcpMux();
2916}
2917
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002918TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002919 Base::SendRequireRtcpMuxToRtcpMux();
2920}
2921
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002922TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002923 Base::SendRtcpMuxToRequireRtcpMux();
2924}
2925
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002926TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002927 Base::SendRequireRtcpMuxToRequireRtcpMux();
2928}
2929
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002930TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002931 Base::SendRequireRtcpMuxToNoRtcpMux();
2932}
2933
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002934TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002935 Base::SendEarlyRtcpMuxToRtcp();
2936}
2937
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002938TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939 Base::SendEarlyRtcpMuxToRtcpMux();
2940}
2941
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002942TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002943 Base::SendSrtpToSrtp();
2944}
2945
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002946TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947 Base::SendSrtpToSrtp();
2948}
2949
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002950TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002951 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2952 Base::SendSrtpToSrtp(DTLS, 0);
2953}
2954
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002955TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2957 Base::SendSrtpToSrtp(DTLS, DTLS);
2958}
2959
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002960TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002961 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2962 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2963}
2964
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002965TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2967}
2968
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002969TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2971}
2972
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002973TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974 Base::SendRtpToRtpOnThread();
2975}
2976
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002977TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 Base::SendSrtpToSrtpOnThread();
2979}
2980
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002981TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982 Base::SendWithWritabilityLoss();
2983}
2984
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002985TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002986 Base::TestMediaMonitor();
2987}
2988
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002989TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002990 Base::TestSetContentFailure();
2991}
2992
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002993TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994 Base::TestSendTwoOffers();
2995}
2996
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002997TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 Base::TestReceiveTwoOffers();
2999}
3000
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003001TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002 Base::TestSendPrAnswer();
3003}
3004
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003005TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006 Base::TestReceivePrAnswer();
3007}
3008
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003009TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 Base::TestFlushRtcp();
3011}
3012
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003013TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08003014 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015}
3016
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003017TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003018 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003019}
3020
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003021TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08003022 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003023}
3024
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003025TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003026 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003027}
3028
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003029TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003030 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031}
3032
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003033TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 Base::TestOnReadyToSend();
3035}
3036
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003037TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038 Base::TestOnReadyToSendWithRtcpMux();
3039}
3040
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003041TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003042 Base::DefaultMaxBitrateIsUnlimited();
3043}
3044
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003045TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003046 Base::CanChangeMaxBitrate();
3047}
3048
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003049// VideoChannelDoubleThreadTest
3050TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3051 Base::TestInit();
3052}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003053
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003054TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3055 Base::TestDeinit();
3056}
3057
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003058TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3059 Base::TestSetContents();
3060}
3061
3062TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3063 Base::TestSetContentsNullOffer();
3064}
3065
3066TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3067 Base::TestSetContentsRtcpMux();
3068}
3069
3070TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3071 Base::TestSetContentsRtcpMux();
3072}
3073
3074TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3075 Base::TestSetRemoteContentUpdate();
3076}
3077
3078TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3079 Base::TestStreams();
3080}
3081
3082TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3083 Base::TestUpdateStreamsInLocalContent();
3084}
3085
3086TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3087 Base::TestUpdateStreamsInRemoteContent();
3088}
3089
3090TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3091 Base::TestChangeStreamParamsInContent();
3092}
3093
3094TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3095 Base::TestPlayoutAndSendingStates();
3096}
3097
3098TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3099 CreateChannels(0, 0);
3100 // Test that we can Mute the default channel even though the sending SSRC
3101 // is unknown.
3102 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003103 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003104 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003105 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003106 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3107 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003108 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003109 SendInitiate();
3110 // After the local session description has been set, we can mute a stream
3111 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003112 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003113 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003114 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003115 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3116}
3117
3118TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3119 Base::TestMediaContentDirection();
3120}
3121
3122TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3123 Base::TestNetworkRouteChanges();
3124}
3125
3126TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3127 Base::TestCallSetup();
3128}
3129
3130TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3131 Base::TestCallTeardownRtcpMux();
3132}
3133
3134TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3135 Base::SendRtpToRtp();
3136}
3137
3138TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3139 Base::SendNoRtcpToNoRtcp();
3140}
3141
3142TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3143 Base::SendNoRtcpToRtcp();
3144}
3145
3146TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3147 Base::SendRtcpToNoRtcp();
3148}
3149
3150TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3151 Base::SendRtcpToRtcp();
3152}
3153
3154TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3155 Base::SendRtcpMuxToRtcp();
3156}
3157
3158TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3159 Base::SendRtcpMuxToRtcpMux();
3160}
3161
3162TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3163 Base::SendRequireRtcpMuxToRtcpMux();
3164}
3165
3166TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3167 Base::SendRtcpMuxToRequireRtcpMux();
3168}
3169
3170TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3171 Base::SendRequireRtcpMuxToRequireRtcpMux();
3172}
3173
3174TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3175 Base::SendRequireRtcpMuxToNoRtcpMux();
3176}
3177
3178TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3179 Base::SendEarlyRtcpMuxToRtcp();
3180}
3181
3182TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3183 Base::SendEarlyRtcpMuxToRtcpMux();
3184}
3185
3186TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3187 Base::SendSrtpToSrtp();
3188}
3189
3190TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3191 Base::SendSrtpToSrtp();
3192}
3193
3194TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3195 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3196 Base::SendSrtpToSrtp(DTLS, 0);
3197}
3198
3199TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3200 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3201 Base::SendSrtpToSrtp(DTLS, DTLS);
3202}
3203
3204TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3205 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3206 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3207}
3208
3209TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3210 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3211}
3212
3213TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3214 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3215}
3216
3217TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3218 Base::SendRtpToRtpOnThread();
3219}
3220
3221TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3222 Base::SendSrtpToSrtpOnThread();
3223}
3224
3225TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3226 Base::SendWithWritabilityLoss();
3227}
3228
3229TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3230 Base::TestMediaMonitor();
3231}
3232
3233TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3234 Base::TestSetContentFailure();
3235}
3236
3237TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3238 Base::TestSendTwoOffers();
3239}
3240
3241TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3242 Base::TestReceiveTwoOffers();
3243}
3244
3245TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3246 Base::TestSendPrAnswer();
3247}
3248
3249TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3250 Base::TestReceivePrAnswer();
3251}
3252
3253TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3254 Base::TestFlushRtcp();
3255}
3256
3257TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3258 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3259}
3260
3261TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3262 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3263}
3264
3265TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3266 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3267}
3268
3269TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3270 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3271}
3272
3273TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3274 Base::TestSrtpError(kVideoPts[0]);
3275}
3276
3277TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3278 Base::TestOnReadyToSend();
3279}
3280
3281TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3282 Base::TestOnReadyToSendWithRtcpMux();
3283}
3284
3285TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3286 Base::DefaultMaxBitrateIsUnlimited();
3287}
3288
3289TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3290 Base::CanChangeMaxBitrate();
3291}
3292
3293// DataChannelSingleThreadTest
3294class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003295 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003296 typedef ChannelTest<DataTraits> Base;
3297 DataChannelSingleThreadTest()
3298 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3299};
3300
3301// DataChannelDoubleThreadTest
3302class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3303 public:
3304 typedef ChannelTest<DataTraits> Base;
3305 DataChannelDoubleThreadTest()
3306 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003307};
3308
3309// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003310template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003312 rtc::Thread* worker_thread,
3313 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003314 cricket::MediaEngineInterface* engine,
3315 cricket::FakeDataMediaChannel* ch,
3316 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003317 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003318 cricket::DataChannel* channel =
3319 new cricket::DataChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07003320 transport_controller, cricket::CN_DATA,
3321 (flags & RTCP) != 0);
3322 rtc::CryptoOptions crypto_options;
3323 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3324 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07003325 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003326 delete channel;
3327 channel = NULL;
3328 }
3329 return channel;
3330}
3331
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003332template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333void ChannelTest<DataTraits>::CreateContent(
3334 int flags,
3335 const cricket::AudioCodec& audio_codec,
3336 const cricket::VideoCodec& video_codec,
3337 cricket::DataContentDescription* data) {
3338 data->AddCodec(kGoogleDataCodec);
3339 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3340 if (flags & SECURE) {
3341 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003342 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3343 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003344 }
3345}
3346
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003347template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348void ChannelTest<DataTraits>::CopyContent(
3349 const cricket::DataContentDescription& source,
3350 cricket::DataContentDescription* data) {
3351 *data = source;
3352}
3353
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003354template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003355bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3356 const cricket::DataCodec& c2) {
3357 return c1.name == c2.name;
3358}
3359
Peter Boström0c4e06b2015-10-07 12:23:21 +02003360template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003361void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003362 uint32_t ssrc,
3363 int flags,
3364 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365 data->AddLegacyStream(ssrc);
3366}
3367
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003368TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003369 Base::TestInit();
3370 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3371}
3372
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003373TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3374 Base::TestDeinit();
3375}
3376
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003377TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378 Base::TestSetContents();
3379}
3380
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003381TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 Base::TestSetContentsNullOffer();
3383}
3384
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003385TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 Base::TestSetContentsRtcpMux();
3387}
3388
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003389TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390 Base::TestSetRemoteContentUpdate();
3391}
3392
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003393TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 Base::TestStreams();
3395}
3396
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003397TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398 Base::TestUpdateStreamsInLocalContent();
3399}
3400
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003401TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 Base::TestUpdateStreamsInRemoteContent();
3403}
3404
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003405TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406 Base::TestChangeStreamParamsInContent();
3407}
3408
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003409TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 Base::TestPlayoutAndSendingStates();
3411}
3412
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003413TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 Base::TestMediaContentDirection();
3415}
3416
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003417TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 Base::TestCallSetup();
3419}
3420
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003421TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 Base::TestCallTeardownRtcpMux();
3423}
3424
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003425TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 Base::TestOnReadyToSend();
3427}
3428
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003429TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 Base::TestOnReadyToSendWithRtcpMux();
3431}
3432
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003433TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 Base::SendRtpToRtp();
3435}
3436
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003437TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 Base::SendNoRtcpToNoRtcp();
3439}
3440
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003441TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 Base::SendNoRtcpToRtcp();
3443}
3444
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003445TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 Base::SendRtcpToNoRtcp();
3447}
3448
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003449TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 Base::SendRtcpToRtcp();
3451}
3452
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003453TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454 Base::SendRtcpMuxToRtcp();
3455}
3456
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003457TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 Base::SendRtcpMuxToRtcpMux();
3459}
3460
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003461TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462 Base::SendEarlyRtcpMuxToRtcp();
3463}
3464
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003465TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466 Base::SendEarlyRtcpMuxToRtcpMux();
3467}
3468
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003469TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470 Base::SendSrtpToSrtp();
3471}
3472
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003473TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474 Base::SendSrtpToSrtp();
3475}
3476
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003477TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3479}
3480
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003481TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482 Base::SendRtpToRtpOnThread();
3483}
3484
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003485TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 Base::SendSrtpToSrtpOnThread();
3487}
3488
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003489TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 Base::SendWithWritabilityLoss();
3491}
3492
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003493TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494 Base::TestMediaMonitor();
3495}
3496
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003497TEST_F(DataChannelSingleThreadTest, TestSendData) {
3498 CreateChannels(0, 0);
3499 EXPECT_TRUE(SendInitiate());
3500 EXPECT_TRUE(SendAccept());
3501
3502 cricket::SendDataParams params;
3503 params.ssrc = 42;
3504 unsigned char data[] = {'f', 'o', 'o'};
3505 rtc::CopyOnWriteBuffer payload(data, 3);
3506 cricket::SendDataResult result;
3507 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3508 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3509 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3510}
3511
3512TEST_F(DataChannelDoubleThreadTest, TestInit) {
3513 Base::TestInit();
3514 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3515}
3516
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003517TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3518 Base::TestDeinit();
3519}
3520
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003521TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3522 Base::TestSetContents();
3523}
3524
3525TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3526 Base::TestSetContentsNullOffer();
3527}
3528
3529TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3530 Base::TestSetContentsRtcpMux();
3531}
3532
3533TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3534 Base::TestSetRemoteContentUpdate();
3535}
3536
3537TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3538 Base::TestStreams();
3539}
3540
3541TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3542 Base::TestUpdateStreamsInLocalContent();
3543}
3544
3545TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3546 Base::TestUpdateStreamsInRemoteContent();
3547}
3548
3549TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3550 Base::TestChangeStreamParamsInContent();
3551}
3552
3553TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3554 Base::TestPlayoutAndSendingStates();
3555}
3556
3557TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3558 Base::TestMediaContentDirection();
3559}
3560
3561TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3562 Base::TestCallSetup();
3563}
3564
3565TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3566 Base::TestCallTeardownRtcpMux();
3567}
3568
3569TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3570 Base::TestOnReadyToSend();
3571}
3572
3573TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3574 Base::TestOnReadyToSendWithRtcpMux();
3575}
3576
3577TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3578 Base::SendRtpToRtp();
3579}
3580
3581TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3582 Base::SendNoRtcpToNoRtcp();
3583}
3584
3585TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3586 Base::SendNoRtcpToRtcp();
3587}
3588
3589TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3590 Base::SendRtcpToNoRtcp();
3591}
3592
3593TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3594 Base::SendRtcpToRtcp();
3595}
3596
3597TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3598 Base::SendRtcpMuxToRtcp();
3599}
3600
3601TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3602 Base::SendRtcpMuxToRtcpMux();
3603}
3604
3605TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3606 Base::SendEarlyRtcpMuxToRtcp();
3607}
3608
3609TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3610 Base::SendEarlyRtcpMuxToRtcpMux();
3611}
3612
3613TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3614 Base::SendSrtpToSrtp();
3615}
3616
3617TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3618 Base::SendSrtpToSrtp();
3619}
3620
3621TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3622 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3623}
3624
3625TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3626 Base::SendRtpToRtpOnThread();
3627}
3628
3629TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3630 Base::SendSrtpToSrtpOnThread();
3631}
3632
3633TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3634 Base::SendWithWritabilityLoss();
3635}
3636
3637TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3638 Base::TestMediaMonitor();
3639}
3640
3641TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642 CreateChannels(0, 0);
3643 EXPECT_TRUE(SendInitiate());
3644 EXPECT_TRUE(SendAccept());
3645
3646 cricket::SendDataParams params;
3647 params.ssrc = 42;
3648 unsigned char data[] = {
3649 'f', 'o', 'o'
3650 };
jbaucheec21bd2016-03-20 06:15:43 -07003651 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003652 cricket::SendDataResult result;
3653 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3654 EXPECT_EQ(params.ssrc,
3655 media_channel1_->last_sent_data_params().ssrc);
3656 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3657}
3658
3659// TODO(pthatcher): TestSetReceiver?