blob: 52bf8f53dce0b05a5fa10bf78835bb9a7ef64402 [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"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010024#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
26#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028 LOG(LS_INFO) << "Feature disabled... skipping"; \
29 return; \
30 }
31
32using cricket::CA_OFFER;
33using cricket::CA_PRANSWER;
34using cricket::CA_ANSWER;
35using cricket::CA_UPDATE;
36using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037using cricket::StreamParams;
38using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039
Danil Chapovalov33b01f22016-05-11 19:55:27 +020040namespace {
41const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
42const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
43const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
perkj26752742016-10-24 01:21:16 -070044const cricket::VideoCodec kH264Codec(97, "H264");
45const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
Danil Chapovalov33b01f22016-05-11 19:55:27 +020046const cricket::DataCodec kGoogleDataCodec(101, "google-data");
47const uint32_t kSsrc1 = 0x1111;
48const uint32_t kSsrc2 = 0x2222;
49const uint32_t kSsrc3 = 0x3333;
50const int kAudioPts[] = {0, 8};
51const int kVideoPts[] = {97, 99};
52enum class NetworkIsWorker { Yes, No };
deadbeefc6b6e092016-12-01 12:49:20 -080053const int kDefaultTimeout = 10000; // 10 seconds.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020054} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055
deadbeefcbecd352015-09-23 11:50:27 -070056template <class ChannelT,
57 class MediaChannelT,
58 class ContentT,
59 class CodecT,
60 class MediaInfoT,
61 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062class Traits {
63 public:
64 typedef ChannelT Channel;
65 typedef MediaChannelT MediaChannel;
66 typedef ContentT Content;
67 typedef CodecT Codec;
68 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020069 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070};
71
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072class VoiceTraits : public Traits<cricket::VoiceChannel,
73 cricket::FakeVoiceMediaChannel,
74 cricket::AudioContentDescription,
75 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020076 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070077 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078
79class VideoTraits : public Traits<cricket::VideoChannel,
80 cricket::FakeVideoMediaChannel,
81 cricket::VideoContentDescription,
82 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020083 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070084 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085
86class DataTraits : public Traits<cricket::DataChannel,
87 cricket::FakeDataMediaChannel,
88 cricket::DataContentDescription,
89 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020090 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070091 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092
Danil Chapovalov33b01f22016-05-11 19:55:27 +020093// Base class for Voice/Video/DataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094template<class T>
95class ChannelTest : public testing::Test, public sigslot::has_slots<> {
96 public:
97 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
jbauchcb560652016-08-04 05:20:32 -070098 DTLS = 0x10, GCM_CIPHER = 0x20 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099
Peter Boström34fbfff2015-09-24 19:20:30 +0200100 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200101 rtc::ArrayView<const uint8_t> rtp_data,
102 rtc::ArrayView<const uint8_t> rtcp_data,
103 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200104 : verify_playout_(verify_playout),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105 media_channel1_(NULL),
106 media_channel2_(NULL),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200107 rtp_packet_(rtp_data.data(), rtp_data.size()),
108 rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109 media_info_callbacks1_(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200110 media_info_callbacks2_() {
111 if (network_is_worker == NetworkIsWorker::Yes) {
112 network_thread_ = rtc::Thread::Current();
113 } else {
114 network_thread_keeper_ = rtc::Thread::Create();
115 network_thread_keeper_->SetName("Network", nullptr);
116 network_thread_keeper_->Start();
117 network_thread_ = network_thread_keeper_.get();
118 }
119 transport_controller1_.reset(new cricket::FakeTransportController(
120 network_thread_, cricket::ICEROLE_CONTROLLING));
121 transport_controller2_.reset(new cricket::FakeTransportController(
122 network_thread_, cricket::ICEROLE_CONTROLLED));
123 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200126 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
127 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200128 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200130 void CreateChannels(typename T::MediaChannel* ch1,
131 typename T::MediaChannel* ch2,
132 int flags1,
133 int flags2) {
134 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 media_channel1_ = ch1;
136 media_channel2_ = ch2;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200137 channel1_.reset(
138 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
jbauchcb560652016-08-04 05:20:32 -0700139 transport_controller1_.get(), flags1));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200140 channel2_.reset(
141 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
jbauchcb560652016-08-04 05:20:32 -0700142 transport_controller2_.get(), flags2));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200143 channel1_->SignalMediaMonitor.connect(this,
144 &ChannelTest<T>::OnMediaMonitor1);
145 channel2_->SignalMediaMonitor.connect(this,
146 &ChannelTest<T>::OnMediaMonitor2);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000147 if ((flags1 & DTLS) && (flags2 & DTLS)) {
148 flags1 = (flags1 & ~SECURE);
149 flags2 = (flags2 & ~SECURE);
150 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000151 CreateContent(flags1, kPcmuCodec, kH264Codec,
152 &local_media_content1_);
153 CreateContent(flags2, kPcmuCodec, kH264Codec,
154 &local_media_content2_);
155 CopyContent(local_media_content1_, &remote_media_content1_);
156 CopyContent(local_media_content2_, &remote_media_content2_);
157
158 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200159 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200160 transport_controller1_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700161 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800162 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 }
164 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200165 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200166 transport_controller2_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700167 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800168 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 }
170
171 // Add stream information (SSRC) to the local content but not to the remote
172 // content. This means that we per default know the SSRC of what we send but
173 // not what we receive.
174 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
175 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
176
177 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
178 if (flags1 & SSRC_MUX) {
179 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
180 }
181 if (flags2 & SSRC_MUX) {
182 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
183 }
184 }
deadbeefcbecd352015-09-23 11:50:27 -0700185 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200186 rtc::Thread* worker_thread,
187 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700188 cricket::MediaEngineInterface* engine,
189 typename T::MediaChannel* ch,
190 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -0700191 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200192 typename T::Channel* channel =
193 new typename T::Channel(worker_thread, network_thread, engine, ch,
jbauchcb560652016-08-04 05:20:32 -0700194 transport_controller, cricket::CN_AUDIO,
195 (flags & RTCP) != 0);
196 rtc::CryptoOptions crypto_options;
197 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
198 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -0700199 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 delete channel;
201 channel = NULL;
202 }
203 return channel;
204 }
205
206 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000207 bool result = channel1_->SetLocalContent(&local_media_content1_,
208 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 if (result) {
210 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000211 result = channel2_->SetRemoteContent(&remote_media_content1_,
212 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200214 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000216 result = channel2_->SetLocalContent(&local_media_content2_,
217 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218 }
219 }
220 return result;
221 }
222
223 bool SendAccept() {
224 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000225 return channel1_->SetRemoteContent(&remote_media_content2_,
226 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 }
228
229 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000230 bool result = channel1_->SetLocalContent(&local_media_content1_,
231 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 if (result) {
233 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000234 result = channel2_->SetRemoteContent(&remote_media_content1_,
235 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 }
237 return result;
238 }
239
240 bool SendProvisionalAnswer() {
241 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000242 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 if (result) {
244 channel2_->Enable(true);
245 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000246 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200247 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000248 }
249 return result;
250 }
251
252 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000253 bool result = channel2_->SetLocalContent(&local_media_content2_,
254 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000256 result = channel1_->SetRemoteContent(&remote_media_content2_,
257 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 return result;
259 }
260
261 bool SendTerminate() {
262 channel1_.reset();
263 channel2_.reset();
264 return true;
265 }
266
267 bool AddStream1(int id) {
268 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
269 }
270 bool RemoveStream1(int id) {
271 return channel1_->RemoveRecvStream(id);
272 }
273
deadbeef57fd7262016-12-06 15:28:55 -0800274 cricket::FakeTransport* GetTransport1() {
275 std::string name = channel1_->content_name();
276 return network_thread_->Invoke<cricket::FakeTransport*>(
277 RTC_FROM_HERE,
278 [this, name] { return transport_controller1_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 }
deadbeef57fd7262016-12-06 15:28:55 -0800280 cricket::FakeTransport* GetTransport2() {
281 std::string name = channel2_->content_name();
282 return network_thread_->Invoke<cricket::FakeTransport*>(
283 RTC_FROM_HERE,
284 [this, name] { return transport_controller2_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 }
286
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200287 void SendRtp1() {
288 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
289 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200291 void SendRtp2() {
292 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
293 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200295 void SendRtcp1() {
296 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200298 void SendRtcp2() {
299 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
301 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200302 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
303 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
304 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200306 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
307 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
308 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200310 void SendCustomRtcp1(uint32_t ssrc) {
311 rtc::Buffer data = CreateRtcpData(ssrc);
312 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200314 void SendCustomRtcp2(uint32_t ssrc) {
315 rtc::Buffer data = CreateRtcpData(ssrc);
316 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200318
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200320 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
322 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200323 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 }
325 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200326 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
328 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200329 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
331 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200332 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200333 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
334 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200336 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200337 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
338 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200340 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200341 rtc::Buffer data = CreateRtcpData(ssrc);
342 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200344 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200345 rtc::Buffer data = CreateRtcpData(ssrc);
346 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200348 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
349 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200351 rtc::SetBE32(data.data() + 8, ssrc);
352 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000353 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200354 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000355 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 return data;
357 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200358 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
359 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200361 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 return data;
363 }
364
365 bool CheckNoRtp1() {
366 return media_channel1_->CheckNoRtp();
367 }
368 bool CheckNoRtp2() {
369 return media_channel2_->CheckNoRtp();
370 }
371 bool CheckNoRtcp1() {
372 return media_channel1_->CheckNoRtcp();
373 }
374 bool CheckNoRtcp2() {
375 return media_channel2_->CheckNoRtcp();
376 }
jbauchcb560652016-08-04 05:20:32 -0700377 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags.
378 // Returns true if so.
379 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
380 int suite;
381 if (!channel->transport_channel()->GetSrtpCryptoSuite(&suite)) {
382 return false;
383 }
384
385 if (flags & GCM_CIPHER) {
386 return rtc::IsGcmCryptoSuite(suite);
387 } else {
388 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
389 !rtc::IsGcmCryptoSuite(suite));
390 }
391 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392
393 void CreateContent(int flags,
394 const cricket::AudioCodec& audio_codec,
395 const cricket::VideoCodec& video_codec,
396 typename T::Content* content) {
397 // overridden in specialized classes
398 }
399 void CopyContent(const typename T::Content& source,
400 typename T::Content* content) {
401 // overridden in specialized classes
402 }
403
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 // Creates a cricket::SessionDescription with one MediaContent and one stream.
405 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200406 cricket::SessionDescription* CreateSessionDescriptionWithStream(
407 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 typename T::Content content;
409 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
410 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
411 AddLegacyStreamInContent(ssrc, 0, &content);
412 sdesc->AddContent("DUMMY_CONTENT_NAME",
413 cricket::NS_JINGLE_RTP, content.Copy());
414 return sdesc;
415 }
416
ossu292d6582016-03-17 02:31:13 -0700417 // Will manage the lifetime of a CallThread, making sure it's
418 // destroyed before this object goes out of scope.
419 class ScopedCallThread {
420 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200421 template <class FunctorT>
422 ScopedCallThread(const FunctorT& functor)
423 : thread_(rtc::Thread::Create()),
424 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700425 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700426 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700427 }
428
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200429 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700430
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200431 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700432
433 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200434 std::unique_ptr<rtc::Thread> thread_;
435 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700436 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
439 return false; // overridden in specialized classes
440 }
441
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200442 void OnMediaMonitor1(typename T::Channel* channel,
443 const typename T::MediaInfo& info) {
444 RTC_DCHECK_EQ(channel, channel1_.get());
445 media_info_callbacks1_++;
446 }
447 void OnMediaMonitor2(typename T::Channel* channel,
448 const typename T::MediaInfo& info) {
449 RTC_DCHECK_EQ(channel, channel2_.get());
450 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 }
452
Honghai Zhangcc411c02016-03-29 17:27:21 -0700453 cricket::CandidatePairInterface* last_selected_candidate_pair() {
454 return last_selected_candidate_pair_;
455 }
456
Peter Boström0c4e06b2015-10-07 12:23:21 +0200457 void AddLegacyStreamInContent(uint32_t ssrc,
458 int flags,
459 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000460 // Base implementation.
461 }
462
463 // Tests that can be used by derived classes.
464
465 // Basic sanity check.
466 void TestInit() {
467 CreateChannels(0, 0);
468 EXPECT_FALSE(channel1_->secure());
469 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200470 if (verify_playout_) {
471 EXPECT_FALSE(media_channel1_->playout());
472 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 EXPECT_TRUE(media_channel1_->codecs().empty());
474 EXPECT_TRUE(media_channel1_->recv_streams().empty());
475 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
476 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
477 }
478
479 // Test that SetLocalContent and SetRemoteContent properly configure
480 // the codecs.
481 void TestSetContents() {
482 CreateChannels(0, 0);
483 typename T::Content content;
484 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000485 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000487 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 ASSERT_EQ(1U, media_channel1_->codecs().size());
489 EXPECT_TRUE(CodecMatches(content.codecs()[0],
490 media_channel1_->codecs()[0]));
491 }
492
493 // Test that SetLocalContent and SetRemoteContent properly deals
494 // with an empty offer.
495 void TestSetContentsNullOffer() {
496 CreateChannels(0, 0);
497 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000498 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 CreateContent(0, kPcmuCodec, kH264Codec, &content);
500 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000501 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 ASSERT_EQ(1U, media_channel1_->codecs().size());
503 EXPECT_TRUE(CodecMatches(content.codecs()[0],
504 media_channel1_->codecs()[0]));
505 }
506
507 // Test that SetLocalContent and SetRemoteContent properly set RTCP
508 // mux.
509 void TestSetContentsRtcpMux() {
510 CreateChannels(RTCP, RTCP);
511 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
512 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
513 typename T::Content content;
514 CreateContent(0, kPcmuCodec, kH264Codec, &content);
515 // Both sides agree on mux. Should no longer be a separate RTCP channel.
516 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000517 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
518 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
520 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000521 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000523 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
525 }
526
527 // Test that SetLocalContent and SetRemoteContent properly set RTCP
528 // mux when a provisional answer is received.
529 void TestSetContentsRtcpMuxWithPrAnswer() {
530 CreateChannels(RTCP, RTCP);
531 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
532 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
533 typename T::Content content;
534 CreateContent(0, kPcmuCodec, kH264Codec, &content);
535 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000536 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
537 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000539 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 // Both sides agree on mux. Should no longer be a separate RTCP channel.
541 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
542 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000543 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000544 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000545 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
546 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000547 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
548 }
549
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 // Test that SetRemoteContent properly deals with a content update.
551 void TestSetRemoteContentUpdate() {
552 CreateChannels(0, 0);
553 typename T::Content content;
554 CreateContent(RTCP | RTCP_MUX | SECURE,
555 kPcmuCodec, kH264Codec,
556 &content);
557 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000558 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
559 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 ASSERT_EQ(1U, media_channel1_->codecs().size());
561 EXPECT_TRUE(CodecMatches(content.codecs()[0],
562 media_channel1_->codecs()[0]));
563 // Now update with other codecs.
564 typename T::Content update_content;
565 update_content.set_partial(true);
566 CreateContent(0, kIsacCodec, kH264SvcCodec,
567 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000568 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 ASSERT_EQ(1U, media_channel1_->codecs().size());
570 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
571 media_channel1_->codecs()[0]));
572 // Now update without any codecs. This is ignored.
573 typename T::Content empty_content;
574 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000575 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 ASSERT_EQ(1U, media_channel1_->codecs().size());
577 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
578 media_channel1_->codecs()[0]));
579 }
580
581 // Test that Add/RemoveStream properly forward to the media channel.
582 void TestStreams() {
583 CreateChannels(0, 0);
584 EXPECT_TRUE(AddStream1(1));
585 EXPECT_TRUE(AddStream1(2));
586 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
587 EXPECT_TRUE(RemoveStream1(2));
588 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
589 EXPECT_TRUE(RemoveStream1(1));
590 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
591 }
592
593 // Test that SetLocalContent properly handles adding and removing StreamParams
594 // to the local content description.
595 // This test uses the CA_UPDATE action that don't require a full
596 // MediaContentDescription to do an update.
597 void TestUpdateStreamsInLocalContent() {
598 cricket::StreamParams stream1;
599 stream1.groupid = "group1";
600 stream1.id = "stream1";
601 stream1.ssrcs.push_back(kSsrc1);
602 stream1.cname = "stream1_cname";
603
604 cricket::StreamParams stream2;
605 stream2.groupid = "group2";
606 stream2.id = "stream2";
607 stream2.ssrcs.push_back(kSsrc2);
608 stream2.cname = "stream2_cname";
609
610 cricket::StreamParams stream3;
611 stream3.groupid = "group3";
612 stream3.id = "stream3";
613 stream3.ssrcs.push_back(kSsrc3);
614 stream3.cname = "stream3_cname";
615
616 CreateChannels(0, 0);
617 typename T::Content content1;
618 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
619 content1.AddStream(stream1);
620 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000621 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622
623 ASSERT_EQ(1u, media_channel1_->send_streams().size());
624 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
625
626 // Update the local streams by adding another sending stream.
627 // Use a partial updated session description.
628 typename T::Content content2;
629 content2.AddStream(stream2);
630 content2.AddStream(stream3);
631 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000632 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633 ASSERT_EQ(3u, media_channel1_->send_streams().size());
634 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
635 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
636 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
637
638 // Update the local streams by removing the first sending stream.
639 // This is done by removing all SSRCS for this particular stream.
640 typename T::Content content3;
641 stream1.ssrcs.clear();
642 content3.AddStream(stream1);
643 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000644 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 ASSERT_EQ(2u, media_channel1_->send_streams().size());
646 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
647 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
648
649 // Update the local streams with a stream that does not change.
650 // THe update is ignored.
651 typename T::Content content4;
652 content4.AddStream(stream2);
653 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000654 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 ASSERT_EQ(2u, media_channel1_->send_streams().size());
656 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
657 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
658 }
659
660 // Test that SetRemoteContent properly handles adding and removing
661 // StreamParams to the remote content description.
662 // This test uses the CA_UPDATE action that don't require a full
663 // MediaContentDescription to do an update.
664 void TestUpdateStreamsInRemoteContent() {
665 cricket::StreamParams stream1;
666 stream1.id = "Stream1";
667 stream1.groupid = "1";
668 stream1.ssrcs.push_back(kSsrc1);
669 stream1.cname = "stream1_cname";
670
671 cricket::StreamParams stream2;
672 stream2.id = "Stream2";
673 stream2.groupid = "2";
674 stream2.ssrcs.push_back(kSsrc2);
675 stream2.cname = "stream2_cname";
676
677 cricket::StreamParams stream3;
678 stream3.id = "Stream3";
679 stream3.groupid = "3";
680 stream3.ssrcs.push_back(kSsrc3);
681 stream3.cname = "stream3_cname";
682
683 CreateChannels(0, 0);
684 typename T::Content content1;
685 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
686 content1.AddStream(stream1);
687 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000688 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689
690 ASSERT_EQ(1u, media_channel1_->codecs().size());
691 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
692 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
693
694 // Update the remote streams by adding another sending stream.
695 // Use a partial updated session description.
696 typename T::Content content2;
697 content2.AddStream(stream2);
698 content2.AddStream(stream3);
699 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000700 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
702 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
703 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
704 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
705
706 // Update the remote streams by removing the first stream.
707 // This is done by removing all SSRCS for this particular stream.
708 typename T::Content content3;
709 stream1.ssrcs.clear();
710 content3.AddStream(stream1);
711 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000712 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
714 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
715 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
716
717 // Update the remote streams with a stream that does not change.
718 // The update is ignored.
719 typename T::Content content4;
720 content4.AddStream(stream2);
721 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000722 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000723 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
724 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
725 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
726 }
727
728 // Test that SetLocalContent and SetRemoteContent properly
729 // handles adding and removing StreamParams when the action is a full
730 // CA_OFFER / CA_ANSWER.
731 void TestChangeStreamParamsInContent() {
732 cricket::StreamParams stream1;
733 stream1.groupid = "group1";
734 stream1.id = "stream1";
735 stream1.ssrcs.push_back(kSsrc1);
736 stream1.cname = "stream1_cname";
737
738 cricket::StreamParams stream2;
739 stream2.groupid = "group1";
740 stream2.id = "stream2";
741 stream2.ssrcs.push_back(kSsrc2);
742 stream2.cname = "stream2_cname";
743
744 // Setup a call where channel 1 send |stream1| to channel 2.
745 CreateChannels(0, 0);
746 typename T::Content content1;
747 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
748 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000749 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 EXPECT_TRUE(channel1_->Enable(true));
751 EXPECT_EQ(1u, media_channel1_->send_streams().size());
752
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000753 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200755 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756
757 // Channel 2 do not send anything.
758 typename T::Content content2;
759 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000760 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000762 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 EXPECT_TRUE(channel2_->Enable(true));
764 EXPECT_EQ(0u, media_channel2_->send_streams().size());
765
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200766 SendCustomRtp1(kSsrc1, 0);
767 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
769
770 // Let channel 2 update the content by sending |stream2| and enable SRTP.
771 typename T::Content content3;
772 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
773 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000774 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 ASSERT_EQ(1u, media_channel2_->send_streams().size());
776 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
777
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000778 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
780 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
781
782 // Channel 1 replies but stop sending stream1.
783 typename T::Content content4;
784 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000785 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 EXPECT_EQ(0u, media_channel1_->send_streams().size());
787
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000788 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
790
791 EXPECT_TRUE(channel1_->secure());
792 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200793 SendCustomRtp2(kSsrc2, 0);
794 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
796 }
797
798 // Test that we only start playout and sending at the right times.
799 void TestPlayoutAndSendingStates() {
800 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200801 if (verify_playout_) {
802 EXPECT_FALSE(media_channel1_->playout());
803 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200805 if (verify_playout_) {
806 EXPECT_FALSE(media_channel2_->playout());
807 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_FALSE(media_channel2_->sending());
809 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200810 if (verify_playout_) {
811 EXPECT_FALSE(media_channel1_->playout());
812 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000814 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
815 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200816 if (verify_playout_) {
817 EXPECT_TRUE(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(channel2_->SetRemoteContent(&local_media_content1_,
821 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200822 if (verify_playout_) {
823 EXPECT_FALSE(media_channel2_->playout());
824 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000826 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
827 CA_ANSWER, 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());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200832 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200833 if (verify_playout_) {
834 EXPECT_TRUE(media_channel1_->playout());
835 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200837 if (verify_playout_) {
838 EXPECT_FALSE(media_channel2_->playout());
839 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 EXPECT_FALSE(media_channel2_->sending());
841 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200842 if (verify_playout_) {
843 EXPECT_TRUE(media_channel2_->playout());
844 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000846 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
847 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200848 if (verify_playout_) {
849 EXPECT_TRUE(media_channel1_->playout());
850 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 EXPECT_TRUE(media_channel1_->sending());
852 }
853
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 // Test that changing the MediaContentDirection in the local and remote
855 // session description start playout and sending at the right time.
856 void TestMediaContentDirection() {
857 CreateChannels(0, 0);
858 typename T::Content content1;
859 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
860 typename T::Content content2;
861 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
862 // Set |content2| to be InActive.
863 content2.set_direction(cricket::MD_INACTIVE);
864
865 EXPECT_TRUE(channel1_->Enable(true));
866 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200867 if (verify_playout_) {
868 EXPECT_FALSE(media_channel1_->playout());
869 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200871 if (verify_playout_) {
872 EXPECT_FALSE(media_channel2_->playout());
873 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 EXPECT_FALSE(media_channel2_->sending());
875
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000876 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
877 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
878 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
879 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200880 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881
Peter Boström34fbfff2015-09-24 19:20:30 +0200882 if (verify_playout_) {
883 EXPECT_TRUE(media_channel1_->playout());
884 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200886 if (verify_playout_) {
887 EXPECT_FALSE(media_channel2_->playout()); // local InActive
888 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 EXPECT_FALSE(media_channel2_->sending()); // local InActive
890
891 // Update |content2| to be RecvOnly.
892 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000893 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
894 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895
Peter Boström34fbfff2015-09-24 19:20:30 +0200896 if (verify_playout_) {
897 EXPECT_TRUE(media_channel1_->playout());
898 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200900 if (verify_playout_) {
901 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
902 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
904
905 // Update |content2| to be SendRecv.
906 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000907 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
908 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909
Peter Boström34fbfff2015-09-24 19:20:30 +0200910 if (verify_playout_) {
911 EXPECT_TRUE(media_channel1_->playout());
912 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200914 if (verify_playout_) {
915 EXPECT_TRUE(media_channel2_->playout());
916 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 EXPECT_TRUE(media_channel2_->sending());
918 }
919
Honghai Zhangcc411c02016-03-29 17:27:21 -0700920 // Tests that when the transport channel signals a candidate pair change
921 // event, the media channel will receive a call on the network route change.
922 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200923 constexpr uint16_t kLocalNetId = 1;
924 constexpr uint16_t kRemoteNetId = 2;
925 constexpr int kLastPacketId = 100;
926
Honghai Zhangcc411c02016-03-29 17:27:21 -0700927 CreateChannels(0, 0);
928
929 cricket::TransportChannel* transport_channel1 =
930 channel1_->transport_channel();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200931 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700932 typename T::MediaChannel* media_channel1 =
933 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200934 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700935
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200936 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700937 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200938 // The transport channel becomes disconnected.
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700939 transport_channel1->SignalSelectedCandidatePairChanged(
940 transport_channel1, nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200941 });
942 WaitForThreads();
943 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700944 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200945 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700946
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700947 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
948 media_channel1, kLocalNetId,
949 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200950 // The transport channel becomes connected.
951 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
952 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
953 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
954 transport_controller1_->CreateFakeCandidatePair(
955 local_address, kLocalNetId, remote_address, kRemoteNetId));
956 transport_channel1->SignalSelectedCandidatePairChanged(
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700957 transport_channel1, candidate_pair.get(), kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200958 });
959 WaitForThreads();
960 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700961 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200962 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700963 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200964 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700965 media_channel1->last_network_route().last_sent_packet_id);
michaelt79e05882016-11-08 02:50:09 -0800966 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
967 EXPECT_EQ(kTransportOverheadPerPacket,
968 media_channel1->transport_overhead_per_packet());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700969 }
970
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 // Test setting up a call.
972 void TestCallSetup() {
973 CreateChannels(0, 0);
974 EXPECT_FALSE(channel1_->secure());
975 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200976 if (verify_playout_) {
977 EXPECT_TRUE(media_channel1_->playout());
978 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 EXPECT_FALSE(media_channel1_->sending());
980 EXPECT_TRUE(SendAccept());
981 EXPECT_FALSE(channel1_->secure());
982 EXPECT_TRUE(media_channel1_->sending());
983 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200984 if (verify_playout_) {
985 EXPECT_TRUE(media_channel2_->playout());
986 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 EXPECT_TRUE(media_channel2_->sending());
988 EXPECT_EQ(1U, media_channel2_->codecs().size());
989 }
990
991 // Test that we don't crash if packets are sent during call teardown
992 // when RTCP mux is enabled. This is a regression test against a specific
993 // race condition that would only occur when a RTCP packet was sent during
994 // teardown of a channel on which RTCP mux was enabled.
995 void TestCallTeardownRtcpMux() {
996 class LastWordMediaChannel : public T::MediaChannel {
997 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200998 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001000 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1001 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1003 }
1004 };
1005 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001006 RTCP | RTCP_MUX, RTCP | RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 EXPECT_TRUE(SendInitiate());
1008 EXPECT_TRUE(SendAccept());
1009 EXPECT_TRUE(SendTerminate());
1010 }
1011
1012 // Send voice RTP data to the other side and ensure it gets there.
1013 void SendRtpToRtp() {
1014 CreateChannels(0, 0);
1015 EXPECT_TRUE(SendInitiate());
1016 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001017 ASSERT_TRUE(GetTransport1());
1018 ASSERT_TRUE(GetTransport2());
1019 EXPECT_EQ(1U, GetTransport1()->channels().size());
1020 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001021 SendRtp1();
1022 SendRtp2();
1023 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 EXPECT_TRUE(CheckRtp1());
1025 EXPECT_TRUE(CheckRtp2());
1026 EXPECT_TRUE(CheckNoRtp1());
1027 EXPECT_TRUE(CheckNoRtp2());
1028 }
1029
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001030 void TestDeinit() {
1031 CreateChannels(RTCP, RTCP);
1032 EXPECT_TRUE(SendInitiate());
1033 EXPECT_TRUE(SendAccept());
1034 SendRtp1();
1035 SendRtp2();
1036 SendRtcp1();
1037 SendRtcp2();
1038 // Do not wait, destroy channels.
1039 channel1_.reset(nullptr);
1040 channel2_.reset(nullptr);
1041 }
1042
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 // Check that RTCP is not transmitted if both sides don't support RTCP.
1044 void SendNoRtcpToNoRtcp() {
1045 CreateChannels(0, 0);
1046 EXPECT_TRUE(SendInitiate());
1047 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001048 ASSERT_TRUE(GetTransport1());
1049 ASSERT_TRUE(GetTransport2());
1050 EXPECT_EQ(1U, GetTransport1()->channels().size());
1051 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001052 SendRtcp1();
1053 SendRtcp2();
1054 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 EXPECT_TRUE(CheckNoRtcp1());
1056 EXPECT_TRUE(CheckNoRtcp2());
1057 }
1058
1059 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1060 void SendNoRtcpToRtcp() {
1061 CreateChannels(0, RTCP);
1062 EXPECT_TRUE(SendInitiate());
1063 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001064 ASSERT_TRUE(GetTransport1());
1065 ASSERT_TRUE(GetTransport2());
1066 EXPECT_EQ(1U, GetTransport1()->channels().size());
1067 EXPECT_EQ(2U, GetTransport2()->channels().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());
deadbeef57fd7262016-12-06 15:28:55 -08001080 ASSERT_TRUE(GetTransport1());
1081 ASSERT_TRUE(GetTransport2());
1082 EXPECT_EQ(2U, GetTransport1()->channels().size());
1083 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001084 SendRtcp1();
1085 SendRtcp2();
1086 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 EXPECT_TRUE(CheckNoRtcp1());
1088 EXPECT_TRUE(CheckNoRtcp2());
1089 }
1090
1091 // Check that RTCP is transmitted if both sides support RTCP.
1092 void SendRtcpToRtcp() {
1093 CreateChannels(RTCP, RTCP);
1094 EXPECT_TRUE(SendInitiate());
1095 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001096 ASSERT_TRUE(GetTransport1());
1097 ASSERT_TRUE(GetTransport2());
1098 EXPECT_EQ(2U, GetTransport1()->channels().size());
1099 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001100 SendRtcp1();
1101 SendRtcp2();
1102 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 EXPECT_TRUE(CheckRtcp1());
1104 EXPECT_TRUE(CheckRtcp2());
1105 EXPECT_TRUE(CheckNoRtcp1());
1106 EXPECT_TRUE(CheckNoRtcp2());
1107 }
1108
1109 // Check that RTCP is transmitted if only the initiator supports mux.
1110 void SendRtcpMuxToRtcp() {
1111 CreateChannels(RTCP | RTCP_MUX, RTCP);
1112 EXPECT_TRUE(SendInitiate());
1113 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001114 ASSERT_TRUE(GetTransport1());
1115 ASSERT_TRUE(GetTransport2());
1116 EXPECT_EQ(2U, GetTransport1()->channels().size());
1117 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001118 SendRtcp1();
1119 SendRtcp2();
1120 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 EXPECT_TRUE(CheckRtcp1());
1122 EXPECT_TRUE(CheckRtcp2());
1123 EXPECT_TRUE(CheckNoRtcp1());
1124 EXPECT_TRUE(CheckNoRtcp2());
1125 }
1126
1127 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1128 void SendRtcpMuxToRtcpMux() {
1129 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1130 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001131 ASSERT_TRUE(GetTransport1());
1132 ASSERT_TRUE(GetTransport2());
1133 EXPECT_EQ(2U, GetTransport1()->channels().size());
1134 EXPECT_EQ(1U, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001136 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001137 SendRtp1();
1138 SendRtp2();
1139 SendRtcp1();
1140 SendRtcp2();
1141 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 EXPECT_TRUE(CheckRtp1());
1143 EXPECT_TRUE(CheckRtp2());
1144 EXPECT_TRUE(CheckNoRtp1());
1145 EXPECT_TRUE(CheckNoRtp2());
1146 EXPECT_TRUE(CheckRtcp1());
1147 EXPECT_TRUE(CheckRtcp2());
1148 EXPECT_TRUE(CheckNoRtcp1());
1149 EXPECT_TRUE(CheckNoRtcp2());
1150 }
1151
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001152 // Check that RTP and RTCP are transmitted ok when both sides
1153 // support mux and one the offerer requires mux.
1154 void SendRequireRtcpMuxToRtcpMux() {
1155 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1156 channel1_->ActivateRtcpMux();
1157 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001158 ASSERT_TRUE(GetTransport1());
1159 ASSERT_TRUE(GetTransport2());
1160 EXPECT_EQ(1U, GetTransport1()->channels().size());
1161 EXPECT_EQ(1U, GetTransport2()->channels().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001162 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001163 SendRtp1();
1164 SendRtp2();
1165 SendRtcp1();
1166 SendRtcp2();
1167 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001168 EXPECT_TRUE(CheckRtp1());
1169 EXPECT_TRUE(CheckRtp2());
1170 EXPECT_TRUE(CheckNoRtp1());
1171 EXPECT_TRUE(CheckNoRtp2());
1172 EXPECT_TRUE(CheckRtcp1());
1173 EXPECT_TRUE(CheckRtcp2());
1174 EXPECT_TRUE(CheckNoRtcp1());
1175 EXPECT_TRUE(CheckNoRtcp2());
1176 }
1177
1178 // Check that RTP and RTCP are transmitted ok when both sides
1179 // support mux and one the answerer requires rtcp mux.
1180 void SendRtcpMuxToRequireRtcpMux() {
1181 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1182 channel2_->ActivateRtcpMux();
1183 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001184 ASSERT_TRUE(GetTransport1());
1185 ASSERT_TRUE(GetTransport2());
1186 EXPECT_EQ(2U, GetTransport1()->channels().size());
1187 EXPECT_EQ(1U, GetTransport2()->channels().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001188 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001189 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001190 SendRtp1();
1191 SendRtp2();
1192 SendRtcp1();
1193 SendRtcp2();
1194 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001195 EXPECT_TRUE(CheckRtp1());
1196 EXPECT_TRUE(CheckRtp2());
1197 EXPECT_TRUE(CheckNoRtp1());
1198 EXPECT_TRUE(CheckNoRtp2());
1199 EXPECT_TRUE(CheckRtcp1());
1200 EXPECT_TRUE(CheckRtcp2());
1201 EXPECT_TRUE(CheckNoRtcp1());
1202 EXPECT_TRUE(CheckNoRtcp2());
1203 }
1204
1205 // Check that RTP and RTCP are transmitted ok when both sides
1206 // require mux.
1207 void SendRequireRtcpMuxToRequireRtcpMux() {
1208 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1209 channel1_->ActivateRtcpMux();
1210 channel2_->ActivateRtcpMux();
1211 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001212 ASSERT_TRUE(GetTransport1());
1213 ASSERT_TRUE(GetTransport2());
1214 EXPECT_EQ(1U, GetTransport1()->channels().size());
1215 EXPECT_EQ(1U, GetTransport2()->channels().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001216 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001217 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001218 SendRtp1();
1219 SendRtp2();
1220 SendRtcp1();
1221 SendRtcp2();
1222 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001223 EXPECT_TRUE(CheckRtp1());
1224 EXPECT_TRUE(CheckRtp2());
1225 EXPECT_TRUE(CheckNoRtp1());
1226 EXPECT_TRUE(CheckNoRtp2());
1227 EXPECT_TRUE(CheckRtcp1());
1228 EXPECT_TRUE(CheckRtcp2());
1229 EXPECT_TRUE(CheckNoRtcp1());
1230 EXPECT_TRUE(CheckNoRtcp2());
1231 }
1232
1233 // Check that SendAccept fails if the answerer doesn't support mux
1234 // and the offerer requires it.
1235 void SendRequireRtcpMuxToNoRtcpMux() {
1236 CreateChannels(RTCP | RTCP_MUX, RTCP);
1237 channel1_->ActivateRtcpMux();
1238 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001239 ASSERT_TRUE(GetTransport1());
1240 ASSERT_TRUE(GetTransport2());
1241 EXPECT_EQ(1U, GetTransport1()->channels().size());
1242 EXPECT_EQ(2U, GetTransport2()->channels().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001243 EXPECT_FALSE(SendAccept());
1244 }
1245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 // Check that RTCP data sent by the initiator before the accept is not muxed.
1247 void SendEarlyRtcpMuxToRtcp() {
1248 CreateChannels(RTCP | RTCP_MUX, RTCP);
1249 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001250 ASSERT_TRUE(GetTransport1());
1251 ASSERT_TRUE(GetTransport2());
1252 EXPECT_EQ(2U, GetTransport1()->channels().size());
1253 EXPECT_EQ(2U, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254
1255 // RTCP can be sent before the call is accepted, if the transport is ready.
1256 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001257 SendRtcp1();
1258 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259 EXPECT_TRUE(CheckNoRtp2());
1260 EXPECT_TRUE(CheckRtcp2());
1261
1262 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001263 SendRtcp2();
1264 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 EXPECT_TRUE(CheckNoRtp1());
1266 EXPECT_TRUE(CheckRtcp1());
1267
1268 // Complete call setup and ensure everything is still OK.
1269 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001270 EXPECT_EQ(2U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001271 SendRtcp1();
1272 SendRtcp2();
1273 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 EXPECT_TRUE(CheckRtcp1());
1276 }
1277
1278
1279 // Check that RTCP data is not muxed until both sides have enabled muxing,
1280 // but that we properly demux before we get the accept message, since there
1281 // is a race between RTP data and the jingle accept.
1282 void SendEarlyRtcpMuxToRtcpMux() {
1283 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1284 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001285 ASSERT_TRUE(GetTransport1());
1286 ASSERT_TRUE(GetTransport2());
1287 EXPECT_EQ(2U, GetTransport1()->channels().size());
1288 EXPECT_EQ(1U, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289
1290 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1291 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001292 SendRtcp1();
1293 WaitForThreads();
1294 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295
1296 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001297 SendRtcp2();
1298 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 EXPECT_TRUE(CheckNoRtp1());
1300 EXPECT_TRUE(CheckRtcp1());
1301
1302 // Complete call setup and ensure everything is still OK.
1303 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001304 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001305 SendRtcp1();
1306 SendRtcp2();
1307 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 EXPECT_TRUE(CheckRtcp1());
1310 }
1311
1312 // Test that we properly send SRTP with RTCP in both directions.
1313 // You can pass in DTLS and/or RTCP_MUX as flags.
1314 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
jbauchcb560652016-08-04 05:20:32 -07001315 ASSERT((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1316 ASSERT((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317
1318 int flags1 = RTCP | SECURE | flags1_in;
1319 int flags2 = RTCP | SECURE | flags2_in;
1320 bool dtls1 = !!(flags1_in & DTLS);
1321 bool dtls2 = !!(flags2_in & DTLS);
1322 CreateChannels(flags1, flags2);
1323 EXPECT_FALSE(channel1_->secure());
1324 EXPECT_FALSE(channel2_->secure());
1325 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001326 WaitForThreads();
1327 EXPECT_TRUE(channel1_->writable());
1328 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 EXPECT_TRUE(SendAccept());
1330 EXPECT_TRUE(channel1_->secure());
1331 EXPECT_TRUE(channel2_->secure());
1332 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1333 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001334 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1335 // channels.
1336 if (dtls1 && dtls2) {
1337 // A GCM cipher is only used if both channels support GCM ciphers.
1338 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1339 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1340 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1341 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001342 SendRtp1();
1343 SendRtp2();
1344 SendRtcp1();
1345 SendRtcp2();
1346 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347 EXPECT_TRUE(CheckRtp1());
1348 EXPECT_TRUE(CheckRtp2());
1349 EXPECT_TRUE(CheckNoRtp1());
1350 EXPECT_TRUE(CheckNoRtp2());
1351 EXPECT_TRUE(CheckRtcp1());
1352 EXPECT_TRUE(CheckRtcp2());
1353 EXPECT_TRUE(CheckNoRtcp1());
1354 EXPECT_TRUE(CheckNoRtcp2());
1355 }
1356
1357 // Test that we properly handling SRTP negotiating down to RTP.
1358 void SendSrtpToRtp() {
1359 CreateChannels(RTCP | SECURE, RTCP);
1360 EXPECT_FALSE(channel1_->secure());
1361 EXPECT_FALSE(channel2_->secure());
1362 EXPECT_TRUE(SendInitiate());
1363 EXPECT_TRUE(SendAccept());
1364 EXPECT_FALSE(channel1_->secure());
1365 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001366 SendRtp1();
1367 SendRtp2();
1368 SendRtcp1();
1369 SendRtcp2();
1370 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 EXPECT_TRUE(CheckRtp1());
1372 EXPECT_TRUE(CheckRtp2());
1373 EXPECT_TRUE(CheckNoRtp1());
1374 EXPECT_TRUE(CheckNoRtp2());
1375 EXPECT_TRUE(CheckRtcp1());
1376 EXPECT_TRUE(CheckRtcp2());
1377 EXPECT_TRUE(CheckNoRtcp1());
1378 EXPECT_TRUE(CheckNoRtcp2());
1379 }
1380
1381 // Test that we can send and receive early media when a provisional answer is
1382 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1383 void SendEarlyMediaUsingRtcpMuxSrtp() {
1384 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1385
1386 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1387 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1388 EXPECT_TRUE(SendOffer());
1389 EXPECT_TRUE(SendProvisionalAnswer());
1390 EXPECT_TRUE(channel1_->secure());
1391 EXPECT_TRUE(channel2_->secure());
deadbeef57fd7262016-12-06 15:28:55 -08001392 ASSERT_TRUE(GetTransport1());
1393 ASSERT_TRUE(GetTransport2());
1394 EXPECT_EQ(2U, GetTransport1()->channels().size());
1395 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001396 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1397 SendCustomRtcp1(kSsrc1);
1398 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1399 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1402
1403 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001404 SendCustomRtcp2(kSsrc2);
1405 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1406 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1409
1410 // Complete call setup and ensure everything is still OK.
1411 EXPECT_TRUE(SendFinalAnswer());
deadbeef57fd7262016-12-06 15:28:55 -08001412 EXPECT_EQ(1U, GetTransport1()->channels().size());
1413 EXPECT_EQ(1U, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 EXPECT_TRUE(channel1_->secure());
1415 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001416 SendCustomRtcp1(kSsrc1);
1417 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1418 SendCustomRtcp2(kSsrc2);
1419 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1420 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1425 }
1426
1427 // Test that we properly send RTP without SRTP from a thread.
1428 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001429 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 EXPECT_TRUE(SendInitiate());
1431 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001432 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1433 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1434 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1435 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1436 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1437 send_rtcp1.thread(),
1438 send_rtcp2.thread()};
1439 WaitForThreads(involved_threads);
1440 EXPECT_TRUE(CheckRtp1());
1441 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 EXPECT_TRUE(CheckNoRtp1());
1443 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001444 EXPECT_TRUE(CheckRtcp1());
1445 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 EXPECT_TRUE(CheckNoRtcp1());
1447 EXPECT_TRUE(CheckNoRtcp2());
1448 }
1449
1450 // Test that we properly send SRTP with RTCP from a thread.
1451 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1453 EXPECT_TRUE(SendInitiate());
1454 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001455 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1456 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1457 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1458 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1459 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1460 send_rtcp1.thread(),
1461 send_rtcp2.thread()};
1462 WaitForThreads(involved_threads);
1463 EXPECT_TRUE(CheckRtp1());
1464 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 EXPECT_TRUE(CheckNoRtp1());
1466 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001467 EXPECT_TRUE(CheckRtcp1());
1468 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 EXPECT_TRUE(CheckNoRtcp1());
1470 EXPECT_TRUE(CheckNoRtcp2());
1471 }
1472
1473 // Test that the mediachannel retains its sending state after the transport
1474 // becomes non-writable.
1475 void SendWithWritabilityLoss() {
1476 CreateChannels(0, 0);
1477 EXPECT_TRUE(SendInitiate());
1478 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001479 ASSERT_TRUE(GetTransport1());
1480 ASSERT_TRUE(GetTransport2());
1481 EXPECT_EQ(1U, GetTransport1()->channels().size());
1482 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001483 SendRtp1();
1484 SendRtp2();
1485 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486 EXPECT_TRUE(CheckRtp1());
1487 EXPECT_TRUE(CheckRtp2());
1488 EXPECT_TRUE(CheckNoRtp1());
1489 EXPECT_TRUE(CheckNoRtp2());
1490
wu@webrtc.org97077a32013-10-25 21:18:33 +00001491 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001492 network_thread_->Invoke<void>(
deadbeef57fd7262016-12-06 15:28:55 -08001493 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(false); });
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 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001501 network_thread_->Invoke<void>(
deadbeef57fd7262016-12-06 15:28:55 -08001502 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001504 SendRtp1();
1505 SendRtp2();
1506 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_TRUE(CheckRtp1());
1508 EXPECT_TRUE(CheckRtp2());
1509 EXPECT_TRUE(CheckNoRtp1());
1510 EXPECT_TRUE(CheckNoRtp2());
1511
1512 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001513 network_thread_->Invoke<void>(
deadbeef57fd7262016-12-06 15:28:55 -08001514 RTC_FROM_HERE, [this] { GetTransport1()->SetDestination(NULL); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 EXPECT_TRUE(media_channel1_->sending());
1516
wu@webrtc.org97077a32013-10-25 21:18:33 +00001517 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001518 SendRtp1();
1519 SendRtp2();
1520 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001521 EXPECT_TRUE(CheckRtp1());
1522 EXPECT_TRUE(CheckNoRtp2());
1523
1524 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001525 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeef57fd7262016-12-06 15:28:55 -08001526 GetTransport1()->SetDestination(GetTransport2());
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001527 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001529 SendRtp1();
1530 SendRtp2();
1531 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532 EXPECT_TRUE(CheckRtp1());
1533 EXPECT_TRUE(CheckRtp2());
1534 EXPECT_TRUE(CheckNoRtp1());
1535 EXPECT_TRUE(CheckNoRtp2());
1536 }
1537
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001538 void SendBundleToBundle(
1539 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1540 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001542 // Only pl_type1 was added to the bundle filter for both |channel1_|
1543 // and |channel2_|.
1544 int pl_type1 = pl_types[0];
1545 int pl_type2 = pl_types[1];
1546 int flags = SSRC_MUX | RTCP;
1547 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001548 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001549 if (rtcp_mux) {
1550 flags |= RTCP_MUX;
1551 expected_channels = 1U;
1552 }
1553 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 EXPECT_TRUE(SendInitiate());
deadbeef57fd7262016-12-06 15:28:55 -08001555 ASSERT_TRUE(GetTransport1());
1556 ASSERT_TRUE(GetTransport2());
1557 EXPECT_EQ(2U, GetTransport1()->channels().size());
1558 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001560 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1561 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001562 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1563 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1564 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1565 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001566
1567 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001568 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1569 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1570 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001571 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001572 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1573 EXPECT_TRUE(CheckNoRtp1());
1574 EXPECT_TRUE(CheckNoRtp2());
1575
1576 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001577 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1578 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1579 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001580 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001581 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1582
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001583 SendCustomRtcp1(kSsrc1);
1584 SendCustomRtcp2(kSsrc2);
1585 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1587 EXPECT_TRUE(CheckNoRtcp1());
1588 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1589 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001591 SendCustomRtcp1(kSsrc2);
1592 SendCustomRtcp2(kSsrc1);
1593 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001594 // Bundle filter shouldn't filter out any RTCP.
1595 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1596 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 }
1598
deadbeefc6b6e092016-12-01 12:49:20 -08001599 // Test that the media monitor can be run and gives callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 void TestMediaMonitor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 CreateChannels(0, 0);
1602 EXPECT_TRUE(SendInitiate());
1603 EXPECT_TRUE(SendAccept());
1604 channel1_->StartMediaMonitor(100);
1605 channel2_->StartMediaMonitor(100);
1606 // Ensure we get callbacks and stop.
deadbeefc6b6e092016-12-01 12:49:20 -08001607 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
1608 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 channel1_->StopMediaMonitor();
1610 channel2_->StopMediaMonitor();
1611 // Ensure a restart of a stopped monitor works.
1612 channel1_->StartMediaMonitor(100);
deadbeefc6b6e092016-12-01 12:49:20 -08001613 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 channel1_->StopMediaMonitor();
1615 // Ensure stopping a stopped monitor is OK.
1616 channel1_->StopMediaMonitor();
1617 }
1618
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 void TestSetContentFailure() {
1620 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621
Peter Thatchera6d24442015-07-09 21:26:36 -07001622 auto sdesc = cricket::SessionDescription();
1623 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1624 new cricket::AudioContentDescription());
1625 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1626 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627
Peter Thatchera6d24442015-07-09 21:26:36 -07001628 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001630 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1631 &sdesc, cricket::CA_OFFER, &err));
1632 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1633 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001636 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1637 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001639 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1640 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 }
1642
1643 void TestSendTwoOffers() {
1644 CreateChannels(0, 0);
1645
Peter Thatchera6d24442015-07-09 21:26:36 -07001646 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001647 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001648 CreateSessionDescriptionWithStream(1));
1649 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1650 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1652
kwiberg31022942016-03-11 14:18:21 -08001653 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001654 CreateSessionDescriptionWithStream(2));
1655 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1656 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1658 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1659 }
1660
1661 void TestReceiveTwoOffers() {
1662 CreateChannels(0, 0);
1663
Peter Thatchera6d24442015-07-09 21:26:36 -07001664 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001665 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001666 CreateSessionDescriptionWithStream(1));
1667 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1668 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1670
kwiberg31022942016-03-11 14:18:21 -08001671 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001672 CreateSessionDescriptionWithStream(2));
1673 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1674 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1676 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1677 }
1678
1679 void TestSendPrAnswer() {
1680 CreateChannels(0, 0);
1681
Peter Thatchera6d24442015-07-09 21:26:36 -07001682 std::string err;
1683 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001684 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001685 CreateSessionDescriptionWithStream(1));
1686 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1687 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001688 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1689
Peter Thatchera6d24442015-07-09 21:26:36 -07001690 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001691 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001692 CreateSessionDescriptionWithStream(2));
1693 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1694 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1696 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1697
Peter Thatchera6d24442015-07-09 21:26:36 -07001698 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001699 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001700 CreateSessionDescriptionWithStream(3));
1701 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1702 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1704 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1705 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1706 }
1707
1708 void TestReceivePrAnswer() {
1709 CreateChannels(0, 0);
1710
Peter Thatchera6d24442015-07-09 21:26:36 -07001711 std::string err;
1712 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001713 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001714 CreateSessionDescriptionWithStream(1));
1715 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1716 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1718
Peter Thatchera6d24442015-07-09 21:26:36 -07001719 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001720 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001721 CreateSessionDescriptionWithStream(2));
1722 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1723 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1725 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1726
Peter Thatchera6d24442015-07-09 21:26:36 -07001727 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001728 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001729 CreateSessionDescriptionWithStream(3));
1730 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1731 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1733 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1734 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1735 }
1736
1737 void TestFlushRtcp() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 CreateChannels(RTCP, RTCP);
1739 EXPECT_TRUE(SendInitiate());
1740 EXPECT_TRUE(SendAccept());
deadbeef57fd7262016-12-06 15:28:55 -08001741 ASSERT_TRUE(GetTransport1());
1742 ASSERT_TRUE(GetTransport2());
1743 EXPECT_EQ(2U, GetTransport1()->channels().size());
1744 EXPECT_EQ(2U, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745
1746 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001747 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 // The sending message is only posted. channel2_ should be empty.
1749 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001750 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1751 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752
1753 // When channel1_ is deleted, the RTCP packet should be sent out to
1754 // channel2_.
1755 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001756 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 EXPECT_TRUE(CheckRtcp2());
1758 }
1759
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001760 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001761 struct SrtpErrorHandler : public sigslot::has_slots<> {
1762 SrtpErrorHandler() :
1763 mode_(cricket::SrtpFilter::UNPROTECT),
1764 error_(cricket::SrtpFilter::ERROR_NONE) {}
1765 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1766 cricket::SrtpFilter::Error error) {
1767 mode_ = mode;
1768 error_ = error;
1769 }
1770 cricket::SrtpFilter::Mode mode_;
1771 cricket::SrtpFilter::Error error_;
1772 } error_handler;
1773
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001774 // For Audio, only pl_type 0 is added to the bundle filter.
1775 // For Video, only pl_type 97 is added to the bundle filter.
1776 // So we need to pass in pl_type so that the packet can pass through
1777 // the bundle filter before it can be processed by the srtp filter.
1778 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001779 static unsigned const char kBadPacket[] = {
1780 0x84, static_cast<unsigned char>(pl_type),
1781 0x00, 0x01,
1782 0x00, 0x00,
1783 0x00, 0x00,
1784 0x00, 0x00,
1785 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001786
1787 // Using fake clock because this tests that SRTP errors are signaled at
1788 // specific times based on set_signal_silent_time.
1789 rtc::ScopedFakeClock fake_clock;
1790 // Some code uses a time of 0 as a special value, so we must start with
1791 // a non-zero time.
1792 // TODO(deadbeef): Fix this.
1793 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1794
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1796 EXPECT_FALSE(channel1_->secure());
1797 EXPECT_FALSE(channel2_->secure());
1798 EXPECT_TRUE(SendInitiate());
1799 EXPECT_TRUE(SendAccept());
1800 EXPECT_TRUE(channel1_->secure());
1801 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001802 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001803 channel2_->srtp_filter()->SignalSrtpError.connect(
1804 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805
1806 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001807 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1808 rtc::PacketOptions());
1809 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001811 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001812 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1813 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001814 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1815 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001816 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1817 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001819 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001820 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001821 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001822 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1823 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001824 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001825 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1826 rtc::PacketOptions());
1827 WaitForThreads();
1828 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001829 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830
1831 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001832 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001833 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001834
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001835 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001836 cricket::TransportChannel* transport_channel =
1837 channel2_->transport_channel();
1838 transport_channel->SignalReadPacket(
1839 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1840 sizeof(kBadPacket), rtc::PacketTime(), 0);
1841 });
1842 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001843 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001844 // Terminate channels before the fake clock is destroyed.
1845 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 }
1847
1848 void TestOnReadyToSend() {
1849 CreateChannels(RTCP, RTCP);
1850 TransportChannel* rtp = channel1_->transport_channel();
1851 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1852 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001853
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001854 network_thread_->Invoke<void>(RTC_FROM_HERE,
1855 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001856 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001858
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001859 network_thread_->Invoke<void>(RTC_FROM_HERE,
1860 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001861 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1863 // channel are ready to send.
1864 EXPECT_TRUE(media_channel1_->ready_to_send());
1865
1866 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001867 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1868 channel1_->SetTransportChannelReadyToSend(false, false);
1869 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001870 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001872
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001873 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1874 channel1_->SetTransportChannelReadyToSend(false, true);
1875 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001876 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 EXPECT_TRUE(media_channel1_->ready_to_send());
1878
1879 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001880 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1881 channel1_->SetTransportChannelReadyToSend(true, false);
1882 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001883 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001885
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001886 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1887 channel1_->SetTransportChannelReadyToSend(true, true);
1888 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001889 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 EXPECT_TRUE(media_channel1_->ready_to_send());
1891 }
1892
1893 void TestOnReadyToSendWithRtcpMux() {
1894 CreateChannels(RTCP, RTCP);
1895 typename T::Content content;
1896 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1897 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1898 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001899 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1900 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1902 TransportChannel* rtp = channel1_->transport_channel();
1903 EXPECT_FALSE(media_channel1_->ready_to_send());
1904 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1905 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001906 network_thread_->Invoke<void>(RTC_FROM_HERE,
1907 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001908 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001910
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001911 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1912 channel1_->SetTransportChannelReadyToSend(false, false);
1913 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001914 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 EXPECT_FALSE(media_channel1_->ready_to_send());
1916 }
1917
skvladdc1c62c2016-03-16 19:07:43 -07001918 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1919 typename T::Content content;
1920 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1921 content.set_bandwidth(remote_limit);
1922 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1923 }
1924
1925 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1926 webrtc::RtpParameters parameters;
1927 webrtc::RtpEncodingParameters encoding;
1928 encoding.max_bitrate_bps = limit;
1929 parameters.encodings.push_back(encoding);
1930 return parameters;
1931 }
1932
1933 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1934 int expected_bitrate) {
1935 EXPECT_EQ(1UL, parameters.encodings.size());
1936 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1937 }
1938
1939 void DefaultMaxBitrateIsUnlimited() {
1940 CreateChannels(0, 0);
1941 EXPECT_TRUE(
1942 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1943 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001944 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001945 }
1946
1947 void CanChangeMaxBitrate() {
1948 CreateChannels(0, 0);
1949 EXPECT_TRUE(
1950 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1951
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001952 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1953 kSsrc1, BitrateLimitedParameters(1000)));
1954 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1955 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001956 EXPECT_EQ(-1, media_channel1_->max_bps());
1957
1958 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001959 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1960 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1961 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001962 EXPECT_EQ(-1, media_channel1_->max_bps());
1963 }
1964
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001966 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1967 static void ProcessThreadQueue(rtc::Thread* thread) {
1968 RTC_DCHECK(thread->IsCurrent());
1969 while (!thread->empty()) {
1970 thread->ProcessMessages(0);
1971 }
1972 }
1973 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1974 // |threads| and current thread post packets to network thread.
1975 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001976 thread->Invoke<void>(RTC_FROM_HERE,
1977 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001978 }
1979 ProcessThreadQueue(rtc::Thread::Current());
1980 // Network thread move them around and post back to worker = current thread.
1981 if (!network_thread_->IsCurrent()) {
1982 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001983 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001984 }
1985 // Worker thread = current Thread process received messages.
1986 ProcessThreadQueue(rtc::Thread::Current());
1987 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001988 // TODO(pbos): Remove playout from all media channels and let renderers mute
1989 // themselves.
1990 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001991 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1992 rtc::Thread* network_thread_;
1993 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1994 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 cricket::FakeMediaEngine media_engine_;
1996 // The media channels are owned by the voice channel objects below.
1997 typename T::MediaChannel* media_channel1_;
1998 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001999 std::unique_ptr<typename T::Channel> channel1_;
2000 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 typename T::Content local_media_content1_;
2002 typename T::Content local_media_content2_;
2003 typename T::Content remote_media_content1_;
2004 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002006 rtc::Buffer rtp_packet_;
2007 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 int media_info_callbacks1_;
2009 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07002010 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011};
2012
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013template<>
2014void ChannelTest<VoiceTraits>::CreateContent(
2015 int flags,
2016 const cricket::AudioCodec& audio_codec,
2017 const cricket::VideoCodec& video_codec,
2018 cricket::AudioContentDescription* audio) {
2019 audio->AddCodec(audio_codec);
2020 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
2021 if (flags & SECURE) {
2022 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002023 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2024 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 }
2026}
2027
2028template<>
2029void ChannelTest<VoiceTraits>::CopyContent(
2030 const cricket::AudioContentDescription& source,
2031 cricket::AudioContentDescription* audio) {
2032 *audio = source;
2033}
2034
2035template<>
2036bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2037 const cricket::AudioCodec& c2) {
2038 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2039 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2040}
2041
Peter Boström0c4e06b2015-10-07 12:23:21 +02002042template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002044 uint32_t ssrc,
2045 int flags,
2046 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 audio->AddLegacyStream(ssrc);
2048}
2049
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002050class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 public:
solenberg1dd98f32015-09-10 01:57:14 -07002052 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002053 VoiceChannelSingleThreadTest()
2054 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2055};
2056
2057class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2058 public:
2059 typedef ChannelTest<VoiceTraits> Base;
2060 VoiceChannelDoubleThreadTest()
2061 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062};
2063
2064// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002065template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002067 rtc::Thread* worker_thread,
2068 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002069 cricket::MediaEngineInterface* engine,
2070 cricket::FakeVideoMediaChannel* ch,
2071 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002072 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002073 cricket::VideoChannel* channel =
2074 new cricket::VideoChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07002075 transport_controller, cricket::CN_VIDEO,
2076 (flags & RTCP) != 0);
2077 rtc::CryptoOptions crypto_options;
2078 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2079 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07002080 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 delete channel;
2082 channel = NULL;
2083 }
2084 return channel;
2085}
2086
2087// override to add 0 parameter
2088template<>
2089bool ChannelTest<VideoTraits>::AddStream1(int id) {
2090 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2091}
2092
2093template<>
2094void ChannelTest<VideoTraits>::CreateContent(
2095 int flags,
2096 const cricket::AudioCodec& audio_codec,
2097 const cricket::VideoCodec& video_codec,
2098 cricket::VideoContentDescription* video) {
2099 video->AddCodec(video_codec);
2100 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2101 if (flags & SECURE) {
2102 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002103 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2104 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 }
2106}
2107
2108template<>
2109void ChannelTest<VideoTraits>::CopyContent(
2110 const cricket::VideoContentDescription& source,
2111 cricket::VideoContentDescription* video) {
2112 *video = source;
2113}
2114
2115template<>
2116bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2117 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002118 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119}
2120
Peter Boström0c4e06b2015-10-07 12:23:21 +02002121template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002123 uint32_t ssrc,
2124 int flags,
2125 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126 video->AddLegacyStream(ssrc);
2127}
2128
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002129class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 public:
solenberg1dd98f32015-09-10 01:57:14 -07002131 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002132 VideoChannelSingleThreadTest()
2133 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134};
2135
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002136class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2137 public:
2138 typedef ChannelTest<VideoTraits> Base;
2139 VideoChannelDoubleThreadTest()
2140 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2141};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002143// VoiceChannelSingleThreadTest
2144TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 Base::TestInit();
2146 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2147 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2148}
2149
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002150TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2151 Base::TestDeinit();
2152}
2153
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002154TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 Base::TestSetContents();
2156}
2157
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002158TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 Base::TestSetContentsNullOffer();
2160}
2161
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002162TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 Base::TestSetContentsRtcpMux();
2164}
2165
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002166TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 Base::TestSetContentsRtcpMux();
2168}
2169
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002170TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 Base::TestSetRemoteContentUpdate();
2172}
2173
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002174TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 Base::TestStreams();
2176}
2177
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002178TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 Base::TestUpdateStreamsInLocalContent();
2180}
2181
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002182TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 Base::TestUpdateStreamsInRemoteContent();
2184}
2185
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002186TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 Base::TestChangeStreamParamsInContent();
2188}
2189
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002190TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 Base::TestPlayoutAndSendingStates();
2192}
2193
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002194TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002195 CreateChannels(0, 0);
2196 // Test that we can Mute the default channel even though the sending SSRC
2197 // is unknown.
2198 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002199 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002200 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2201 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002202 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2203
2204 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002205 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002206
2207 SendInitiate();
2208 // After the local session description has been set, we can mute a stream
2209 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002210 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002211 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2212 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002213 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214}
2215
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002216TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 Base::TestMediaContentDirection();
2218}
2219
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002220TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002221 Base::TestNetworkRouteChanges();
2222}
2223
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002224TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 Base::TestCallSetup();
2226}
2227
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002228TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 Base::TestCallTeardownRtcpMux();
2230}
2231
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002232TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 Base::SendRtpToRtp();
2234}
2235
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002236TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 Base::SendNoRtcpToNoRtcp();
2238}
2239
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002240TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 Base::SendNoRtcpToRtcp();
2242}
2243
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002244TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 Base::SendRtcpToNoRtcp();
2246}
2247
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002248TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 Base::SendRtcpToRtcp();
2250}
2251
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002252TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 Base::SendRtcpMuxToRtcp();
2254}
2255
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002256TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 Base::SendRtcpMuxToRtcpMux();
2258}
2259
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002260TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002261 Base::SendRequireRtcpMuxToRtcpMux();
2262}
2263
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002264TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002265 Base::SendRtcpMuxToRequireRtcpMux();
2266}
2267
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002268TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002269 Base::SendRequireRtcpMuxToRequireRtcpMux();
2270}
2271
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002272TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002273 Base::SendRequireRtcpMuxToNoRtcpMux();
2274}
2275
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002276TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 Base::SendEarlyRtcpMuxToRtcp();
2278}
2279
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002280TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 Base::SendEarlyRtcpMuxToRtcpMux();
2282}
2283
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002284TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2286}
2287
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002288TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 Base::SendSrtpToSrtp();
2290}
2291
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002292TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2294}
2295
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002296TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2298 Base::SendSrtpToSrtp(DTLS, 0);
2299}
2300
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002301TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2303 Base::SendSrtpToSrtp(DTLS, DTLS);
2304}
2305
jbauchcb560652016-08-04 05:20:32 -07002306TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2307 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2308 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2309}
2310
2311TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2312 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2313 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2314}
2315
2316TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2317 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2318 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2319}
2320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002321TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2323 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2324}
2325
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002326TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2328}
2329
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002330TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 Base::SendRtpToRtpOnThread();
2332}
2333
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002334TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 Base::SendSrtpToSrtpOnThread();
2336}
2337
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002338TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 Base::SendWithWritabilityLoss();
2340}
2341
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002342TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 Base::TestMediaMonitor();
2344}
2345
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002347TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 CreateChannels(0, 0);
2349 EXPECT_TRUE(SendInitiate());
2350 EXPECT_TRUE(SendAccept());
2351 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2352
solenberg1d63dd02015-12-02 12:35:09 -08002353 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2354 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2355 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002357 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002359 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002360 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002361 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002362 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002363 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364}
2365
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002366TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 Base::TestSetContentFailure();
2368}
2369
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002370TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 Base::TestSendTwoOffers();
2372}
2373
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002374TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 Base::TestReceiveTwoOffers();
2376}
2377
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002378TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 Base::TestSendPrAnswer();
2380}
2381
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002382TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 Base::TestReceivePrAnswer();
2384}
2385
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002386TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 Base::TestFlushRtcp();
2388}
2389
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002390TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002391 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392}
2393
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002394TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395 Base::TestOnReadyToSend();
2396}
2397
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002398TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 Base::TestOnReadyToSendWithRtcpMux();
2400}
2401
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002403TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 CreateChannels(RTCP, RTCP);
2405 EXPECT_TRUE(SendInitiate());
2406 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002407 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408
solenberg4bac9c52015-10-09 02:32:53 -07002409 // Default is (1.0).
2410 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2411 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002413 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414
solenberg4bac9c52015-10-09 02:32:53 -07002415 // Set scale to (1.5).
2416 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2417 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2418 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419
solenberg4bac9c52015-10-09 02:32:53 -07002420 // Set scale to (0).
2421 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2422 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2423 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424}
2425
2426// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002427TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428 CreateChannels(RTCP, RTCP);
2429 EXPECT_TRUE(SendInitiate());
2430 EXPECT_TRUE(SendAccept());
2431 EXPECT_TRUE(AddStream1(1));
2432 EXPECT_TRUE(AddStream1(2));
2433
solenberg4bac9c52015-10-09 02:32:53 -07002434 double volume;
2435 // Default is (1.0).
2436 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2437 EXPECT_DOUBLE_EQ(1.0, volume);
2438 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2439 EXPECT_DOUBLE_EQ(1.0, volume);
2440 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2441 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002443 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444
solenberg4bac9c52015-10-09 02:32:53 -07002445 // Set scale to (1.5) for ssrc = 1.
2446 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2447 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2448 EXPECT_DOUBLE_EQ(1.5, volume);
2449 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2450 EXPECT_DOUBLE_EQ(1.0, volume);
2451 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2452 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453
solenberg4bac9c52015-10-09 02:32:53 -07002454 // Set scale to (0) for all ssrcs.
2455 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2456 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2457 EXPECT_DOUBLE_EQ(0.0, volume);
2458 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2459 EXPECT_DOUBLE_EQ(0.0, volume);
2460 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2461 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462}
2463
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002464TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002465 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466}
2467
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002468TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002469 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002470}
2471
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002472TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002473 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002474}
2475
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002476TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002477 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478}
2479
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002480TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002481 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002482}
2483
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002484TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002485 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002486}
2487
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002488// VoiceChannelDoubleThreadTest
2489TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002491 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2492 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493}
2494
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002495TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2496 Base::TestDeinit();
2497}
2498
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002499TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500 Base::TestSetContents();
2501}
2502
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002503TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 Base::TestSetContentsNullOffer();
2505}
2506
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002507TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 Base::TestSetContentsRtcpMux();
2509}
2510
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002511TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512 Base::TestSetContentsRtcpMux();
2513}
2514
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002515TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 Base::TestSetRemoteContentUpdate();
2517}
2518
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002519TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 Base::TestStreams();
2521}
2522
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002523TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 Base::TestUpdateStreamsInLocalContent();
2525}
2526
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002527TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528 Base::TestUpdateStreamsInRemoteContent();
2529}
2530
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002531TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 Base::TestChangeStreamParamsInContent();
2533}
2534
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002535TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 Base::TestPlayoutAndSendingStates();
2537}
2538
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002539TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2540 CreateChannels(0, 0);
2541 // Test that we can Mute the default channel even though the sending SSRC
2542 // is unknown.
2543 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2544 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2545 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2546 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2547 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2548
2549 // Test that we can not mute an unknown SSRC.
2550 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2551
2552 SendInitiate();
2553 // After the local session description has been set, we can mute a stream
2554 // with its SSRC.
2555 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2556 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2557 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2558 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2559}
2560
2561TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2562 Base::TestMediaContentDirection();
2563}
2564
2565TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2566 Base::TestNetworkRouteChanges();
2567}
2568
2569TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2570 Base::TestCallSetup();
2571}
2572
2573TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2574 Base::TestCallTeardownRtcpMux();
2575}
2576
2577TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2578 Base::SendRtpToRtp();
2579}
2580
2581TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2582 Base::SendNoRtcpToNoRtcp();
2583}
2584
2585TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2586 Base::SendNoRtcpToRtcp();
2587}
2588
2589TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2590 Base::SendRtcpToNoRtcp();
2591}
2592
2593TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2594 Base::SendRtcpToRtcp();
2595}
2596
2597TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2598 Base::SendRtcpMuxToRtcp();
2599}
2600
2601TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2602 Base::SendRtcpMuxToRtcpMux();
2603}
2604
2605TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2606 Base::SendRequireRtcpMuxToRtcpMux();
2607}
2608
2609TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2610 Base::SendRtcpMuxToRequireRtcpMux();
2611}
2612
2613TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2614 Base::SendRequireRtcpMuxToRequireRtcpMux();
2615}
2616
2617TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2618 Base::SendRequireRtcpMuxToNoRtcpMux();
2619}
2620
2621TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2622 Base::SendEarlyRtcpMuxToRtcp();
2623}
2624
2625TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2626 Base::SendEarlyRtcpMuxToRtcpMux();
2627}
2628
2629TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2630 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2631}
2632
2633TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2634 Base::SendSrtpToSrtp();
2635}
2636
2637TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2638 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2639}
2640
2641TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2642 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2643 Base::SendSrtpToSrtp(DTLS, 0);
2644}
2645
2646TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2647 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2648 Base::SendSrtpToSrtp(DTLS, DTLS);
2649}
2650
jbauchcb560652016-08-04 05:20:32 -07002651TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2652 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2653 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2654}
2655
2656TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2657 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2658 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2659}
2660
2661TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2662 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2663 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2664}
2665
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002666TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2667 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2668 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2669}
2670
2671TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2672 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2673}
2674
2675TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2676 Base::SendRtpToRtpOnThread();
2677}
2678
2679TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2680 Base::SendSrtpToSrtpOnThread();
2681}
2682
2683TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2684 Base::SendWithWritabilityLoss();
2685}
2686
2687TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2688 Base::TestMediaMonitor();
2689}
2690
2691// Test that InsertDtmf properly forwards to the media channel.
2692TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2693 CreateChannels(0, 0);
2694 EXPECT_TRUE(SendInitiate());
2695 EXPECT_TRUE(SendAccept());
2696 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2697
2698 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2699 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2700 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2701
2702 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2703 EXPECT_TRUE(
2704 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2705 EXPECT_TRUE(
2706 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2707 EXPECT_TRUE(
2708 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2709}
2710
2711TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2712 Base::TestSetContentFailure();
2713}
2714
2715TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2716 Base::TestSendTwoOffers();
2717}
2718
2719TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2720 Base::TestReceiveTwoOffers();
2721}
2722
2723TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2724 Base::TestSendPrAnswer();
2725}
2726
2727TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2728 Base::TestReceivePrAnswer();
2729}
2730
2731TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2732 Base::TestFlushRtcp();
2733}
2734
2735TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2736 Base::TestSrtpError(kAudioPts[0]);
2737}
2738
2739TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2740 Base::TestOnReadyToSend();
2741}
2742
2743TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2744 Base::TestOnReadyToSendWithRtcpMux();
2745}
2746
2747// Test that we can scale the output volume properly for 1:1 calls.
2748TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2749 CreateChannels(RTCP, RTCP);
2750 EXPECT_TRUE(SendInitiate());
2751 EXPECT_TRUE(SendAccept());
2752 double volume;
2753
2754 // Default is (1.0).
2755 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2756 EXPECT_DOUBLE_EQ(1.0, volume);
2757 // invalid ssrc.
2758 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2759
2760 // Set scale to (1.5).
2761 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2762 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2763 EXPECT_DOUBLE_EQ(1.5, volume);
2764
2765 // Set scale to (0).
2766 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2767 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2768 EXPECT_DOUBLE_EQ(0.0, volume);
2769}
2770
2771// Test that we can scale the output volume properly for multiway calls.
2772TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2773 CreateChannels(RTCP, RTCP);
2774 EXPECT_TRUE(SendInitiate());
2775 EXPECT_TRUE(SendAccept());
2776 EXPECT_TRUE(AddStream1(1));
2777 EXPECT_TRUE(AddStream1(2));
2778
2779 double volume;
2780 // Default is (1.0).
2781 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2782 EXPECT_DOUBLE_EQ(1.0, volume);
2783 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2784 EXPECT_DOUBLE_EQ(1.0, volume);
2785 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2786 EXPECT_DOUBLE_EQ(1.0, volume);
2787 // invalid ssrc.
2788 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2789
2790 // Set scale to (1.5) for ssrc = 1.
2791 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2792 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2793 EXPECT_DOUBLE_EQ(1.5, volume);
2794 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2795 EXPECT_DOUBLE_EQ(1.0, volume);
2796 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2797 EXPECT_DOUBLE_EQ(1.0, volume);
2798
2799 // Set scale to (0) for all ssrcs.
2800 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2801 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2802 EXPECT_DOUBLE_EQ(0.0, volume);
2803 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2804 EXPECT_DOUBLE_EQ(0.0, volume);
2805 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2806 EXPECT_DOUBLE_EQ(0.0, volume);
2807}
2808
2809TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2810 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2811}
2812
2813TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2814 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2815}
2816
2817TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2818 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2819}
2820
2821TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2822 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2823}
2824
2825TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2826 Base::DefaultMaxBitrateIsUnlimited();
2827}
2828
2829TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2830 Base::CanChangeMaxBitrate();
2831}
2832
2833// VideoChannelSingleThreadTest
2834TEST_F(VideoChannelSingleThreadTest, TestInit) {
2835 Base::TestInit();
2836}
2837
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002838TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2839 Base::TestDeinit();
2840}
2841
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002842TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2843 Base::TestSetContents();
2844}
2845
2846TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2847 Base::TestSetContentsNullOffer();
2848}
2849
2850TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2851 Base::TestSetContentsRtcpMux();
2852}
2853
2854TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2855 Base::TestSetContentsRtcpMux();
2856}
2857
2858TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2859 Base::TestSetRemoteContentUpdate();
2860}
2861
2862TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2863 Base::TestStreams();
2864}
2865
2866TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2867 Base::TestUpdateStreamsInLocalContent();
2868}
2869
2870TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2871 Base::TestUpdateStreamsInRemoteContent();
2872}
2873
2874TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2875 Base::TestChangeStreamParamsInContent();
2876}
2877
2878TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2879 Base::TestPlayoutAndSendingStates();
2880}
2881
2882TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002883 CreateChannels(0, 0);
2884 // Test that we can Mute the default channel even though the sending SSRC
2885 // is unknown.
2886 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002887 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002888 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002889 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002890 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2891 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002892 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002893 SendInitiate();
2894 // After the local session description has been set, we can mute a stream
2895 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002896 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002897 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002898 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002899 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002900}
2901
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002902TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 Base::TestMediaContentDirection();
2904}
2905
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002906TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002907 Base::TestNetworkRouteChanges();
2908}
2909
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002910TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002911 Base::TestCallSetup();
2912}
2913
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002914TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915 Base::TestCallTeardownRtcpMux();
2916}
2917
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002918TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919 Base::SendRtpToRtp();
2920}
2921
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002922TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923 Base::SendNoRtcpToNoRtcp();
2924}
2925
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002926TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002927 Base::SendNoRtcpToRtcp();
2928}
2929
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002930TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931 Base::SendRtcpToNoRtcp();
2932}
2933
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002934TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002935 Base::SendRtcpToRtcp();
2936}
2937
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002938TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939 Base::SendRtcpMuxToRtcp();
2940}
2941
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002942TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002943 Base::SendRtcpMuxToRtcpMux();
2944}
2945
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002946TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002947 Base::SendRequireRtcpMuxToRtcpMux();
2948}
2949
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002950TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002951 Base::SendRtcpMuxToRequireRtcpMux();
2952}
2953
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002954TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002955 Base::SendRequireRtcpMuxToRequireRtcpMux();
2956}
2957
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002958TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002959 Base::SendRequireRtcpMuxToNoRtcpMux();
2960}
2961
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002962TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002963 Base::SendEarlyRtcpMuxToRtcp();
2964}
2965
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002966TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 Base::SendEarlyRtcpMuxToRtcpMux();
2968}
2969
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002970TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971 Base::SendSrtpToSrtp();
2972}
2973
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002974TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975 Base::SendSrtpToSrtp();
2976}
2977
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002978TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2980 Base::SendSrtpToSrtp(DTLS, 0);
2981}
2982
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002983TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2985 Base::SendSrtpToSrtp(DTLS, DTLS);
2986}
2987
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002988TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2990 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2991}
2992
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002993TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2995}
2996
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002997TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2999}
3000
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003001TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002 Base::SendRtpToRtpOnThread();
3003}
3004
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003005TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006 Base::SendSrtpToSrtpOnThread();
3007}
3008
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003009TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 Base::SendWithWritabilityLoss();
3011}
3012
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003013TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014 Base::TestMediaMonitor();
3015}
3016
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003017TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018 Base::TestSetContentFailure();
3019}
3020
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003021TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003022 Base::TestSendTwoOffers();
3023}
3024
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003025TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026 Base::TestReceiveTwoOffers();
3027}
3028
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003029TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003030 Base::TestSendPrAnswer();
3031}
3032
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003033TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 Base::TestReceivePrAnswer();
3035}
3036
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003037TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038 Base::TestFlushRtcp();
3039}
3040
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003041TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08003042 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003043}
3044
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003045TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003046 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003047}
3048
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003049TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08003050 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003051}
3052
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003053TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003054 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003055}
3056
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003057TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003058 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059}
3060
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003061TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003062 Base::TestOnReadyToSend();
3063}
3064
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003065TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003066 Base::TestOnReadyToSendWithRtcpMux();
3067}
3068
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003069TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003070 Base::DefaultMaxBitrateIsUnlimited();
3071}
3072
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003073TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003074 Base::CanChangeMaxBitrate();
3075}
3076
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003077// VideoChannelDoubleThreadTest
3078TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3079 Base::TestInit();
3080}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003082TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3083 Base::TestDeinit();
3084}
3085
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003086TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3087 Base::TestSetContents();
3088}
3089
3090TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3091 Base::TestSetContentsNullOffer();
3092}
3093
3094TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3095 Base::TestSetContentsRtcpMux();
3096}
3097
3098TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3099 Base::TestSetContentsRtcpMux();
3100}
3101
3102TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3103 Base::TestSetRemoteContentUpdate();
3104}
3105
3106TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3107 Base::TestStreams();
3108}
3109
3110TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3111 Base::TestUpdateStreamsInLocalContent();
3112}
3113
3114TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3115 Base::TestUpdateStreamsInRemoteContent();
3116}
3117
3118TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3119 Base::TestChangeStreamParamsInContent();
3120}
3121
3122TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3123 Base::TestPlayoutAndSendingStates();
3124}
3125
3126TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3127 CreateChannels(0, 0);
3128 // Test that we can Mute the default channel even though the sending SSRC
3129 // is unknown.
3130 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003131 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003132 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003133 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003134 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3135 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003136 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003137 SendInitiate();
3138 // After the local session description has been set, we can mute a stream
3139 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003140 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003141 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003142 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003143 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3144}
3145
3146TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3147 Base::TestMediaContentDirection();
3148}
3149
3150TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3151 Base::TestNetworkRouteChanges();
3152}
3153
3154TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3155 Base::TestCallSetup();
3156}
3157
3158TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3159 Base::TestCallTeardownRtcpMux();
3160}
3161
3162TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3163 Base::SendRtpToRtp();
3164}
3165
3166TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3167 Base::SendNoRtcpToNoRtcp();
3168}
3169
3170TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3171 Base::SendNoRtcpToRtcp();
3172}
3173
3174TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3175 Base::SendRtcpToNoRtcp();
3176}
3177
3178TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3179 Base::SendRtcpToRtcp();
3180}
3181
3182TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3183 Base::SendRtcpMuxToRtcp();
3184}
3185
3186TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3187 Base::SendRtcpMuxToRtcpMux();
3188}
3189
3190TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3191 Base::SendRequireRtcpMuxToRtcpMux();
3192}
3193
3194TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3195 Base::SendRtcpMuxToRequireRtcpMux();
3196}
3197
3198TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3199 Base::SendRequireRtcpMuxToRequireRtcpMux();
3200}
3201
3202TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3203 Base::SendRequireRtcpMuxToNoRtcpMux();
3204}
3205
3206TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3207 Base::SendEarlyRtcpMuxToRtcp();
3208}
3209
3210TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3211 Base::SendEarlyRtcpMuxToRtcpMux();
3212}
3213
3214TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3215 Base::SendSrtpToSrtp();
3216}
3217
3218TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3219 Base::SendSrtpToSrtp();
3220}
3221
3222TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3223 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3224 Base::SendSrtpToSrtp(DTLS, 0);
3225}
3226
3227TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3228 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3229 Base::SendSrtpToSrtp(DTLS, DTLS);
3230}
3231
3232TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3233 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3234 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3235}
3236
3237TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3238 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3239}
3240
3241TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3242 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3243}
3244
3245TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3246 Base::SendRtpToRtpOnThread();
3247}
3248
3249TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3250 Base::SendSrtpToSrtpOnThread();
3251}
3252
3253TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3254 Base::SendWithWritabilityLoss();
3255}
3256
3257TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3258 Base::TestMediaMonitor();
3259}
3260
3261TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3262 Base::TestSetContentFailure();
3263}
3264
3265TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3266 Base::TestSendTwoOffers();
3267}
3268
3269TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3270 Base::TestReceiveTwoOffers();
3271}
3272
3273TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3274 Base::TestSendPrAnswer();
3275}
3276
3277TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3278 Base::TestReceivePrAnswer();
3279}
3280
3281TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3282 Base::TestFlushRtcp();
3283}
3284
3285TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3286 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3287}
3288
3289TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3290 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3291}
3292
3293TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3294 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3295}
3296
3297TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3298 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3299}
3300
3301TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3302 Base::TestSrtpError(kVideoPts[0]);
3303}
3304
3305TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3306 Base::TestOnReadyToSend();
3307}
3308
3309TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3310 Base::TestOnReadyToSendWithRtcpMux();
3311}
3312
3313TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3314 Base::DefaultMaxBitrateIsUnlimited();
3315}
3316
3317TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3318 Base::CanChangeMaxBitrate();
3319}
3320
3321// DataChannelSingleThreadTest
3322class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003324 typedef ChannelTest<DataTraits> Base;
3325 DataChannelSingleThreadTest()
3326 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3327};
3328
3329// DataChannelDoubleThreadTest
3330class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3331 public:
3332 typedef ChannelTest<DataTraits> Base;
3333 DataChannelDoubleThreadTest()
3334 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335};
3336
3337// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003338template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003340 rtc::Thread* worker_thread,
3341 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003342 cricket::MediaEngineInterface* engine,
3343 cricket::FakeDataMediaChannel* ch,
3344 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003345 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003346 cricket::DataChannel* channel =
3347 new cricket::DataChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07003348 transport_controller, cricket::CN_DATA,
3349 (flags & RTCP) != 0);
3350 rtc::CryptoOptions crypto_options;
3351 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3352 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07003353 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354 delete channel;
3355 channel = NULL;
3356 }
3357 return channel;
3358}
3359
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003360template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003361void ChannelTest<DataTraits>::CreateContent(
3362 int flags,
3363 const cricket::AudioCodec& audio_codec,
3364 const cricket::VideoCodec& video_codec,
3365 cricket::DataContentDescription* data) {
3366 data->AddCodec(kGoogleDataCodec);
3367 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3368 if (flags & SECURE) {
3369 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003370 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3371 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003372 }
3373}
3374
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003375template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003376void ChannelTest<DataTraits>::CopyContent(
3377 const cricket::DataContentDescription& source,
3378 cricket::DataContentDescription* data) {
3379 *data = source;
3380}
3381
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003382template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003383bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3384 const cricket::DataCodec& c2) {
3385 return c1.name == c2.name;
3386}
3387
Peter Boström0c4e06b2015-10-07 12:23:21 +02003388template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003389void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003390 uint32_t ssrc,
3391 int flags,
3392 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003393 data->AddLegacyStream(ssrc);
3394}
3395
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003396TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397 Base::TestInit();
3398 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3399}
3400
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003401TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3402 Base::TestDeinit();
3403}
3404
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003405TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406 Base::TestSetContents();
3407}
3408
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003409TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 Base::TestSetContentsNullOffer();
3411}
3412
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003413TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 Base::TestSetContentsRtcpMux();
3415}
3416
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003417TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 Base::TestSetRemoteContentUpdate();
3419}
3420
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003421TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 Base::TestStreams();
3423}
3424
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003425TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 Base::TestUpdateStreamsInLocalContent();
3427}
3428
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003429TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 Base::TestUpdateStreamsInRemoteContent();
3431}
3432
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003433TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 Base::TestChangeStreamParamsInContent();
3435}
3436
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003437TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 Base::TestPlayoutAndSendingStates();
3439}
3440
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003441TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 Base::TestMediaContentDirection();
3443}
3444
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003445TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 Base::TestCallSetup();
3447}
3448
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003449TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 Base::TestCallTeardownRtcpMux();
3451}
3452
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003453TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003454 Base::TestOnReadyToSend();
3455}
3456
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003457TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458 Base::TestOnReadyToSendWithRtcpMux();
3459}
3460
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003461TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462 Base::SendRtpToRtp();
3463}
3464
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003465TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466 Base::SendNoRtcpToNoRtcp();
3467}
3468
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003469TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470 Base::SendNoRtcpToRtcp();
3471}
3472
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003473TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474 Base::SendRtcpToNoRtcp();
3475}
3476
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003477TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 Base::SendRtcpToRtcp();
3479}
3480
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003481TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482 Base::SendRtcpMuxToRtcp();
3483}
3484
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003485TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 Base::SendRtcpMuxToRtcpMux();
3487}
3488
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003489TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 Base::SendEarlyRtcpMuxToRtcp();
3491}
3492
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003493TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003494 Base::SendEarlyRtcpMuxToRtcpMux();
3495}
3496
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003497TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498 Base::SendSrtpToSrtp();
3499}
3500
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003501TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502 Base::SendSrtpToSrtp();
3503}
3504
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003505TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3507}
3508
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003509TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510 Base::SendRtpToRtpOnThread();
3511}
3512
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003513TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 Base::SendSrtpToSrtpOnThread();
3515}
3516
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003517TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518 Base::SendWithWritabilityLoss();
3519}
3520
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003521TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522 Base::TestMediaMonitor();
3523}
3524
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003525TEST_F(DataChannelSingleThreadTest, TestSendData) {
3526 CreateChannels(0, 0);
3527 EXPECT_TRUE(SendInitiate());
3528 EXPECT_TRUE(SendAccept());
3529
3530 cricket::SendDataParams params;
3531 params.ssrc = 42;
3532 unsigned char data[] = {'f', 'o', 'o'};
3533 rtc::CopyOnWriteBuffer payload(data, 3);
3534 cricket::SendDataResult result;
3535 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3536 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3537 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3538}
3539
3540TEST_F(DataChannelDoubleThreadTest, TestInit) {
3541 Base::TestInit();
3542 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3543}
3544
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003545TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3546 Base::TestDeinit();
3547}
3548
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003549TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3550 Base::TestSetContents();
3551}
3552
3553TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3554 Base::TestSetContentsNullOffer();
3555}
3556
3557TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3558 Base::TestSetContentsRtcpMux();
3559}
3560
3561TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3562 Base::TestSetRemoteContentUpdate();
3563}
3564
3565TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3566 Base::TestStreams();
3567}
3568
3569TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3570 Base::TestUpdateStreamsInLocalContent();
3571}
3572
3573TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3574 Base::TestUpdateStreamsInRemoteContent();
3575}
3576
3577TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3578 Base::TestChangeStreamParamsInContent();
3579}
3580
3581TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3582 Base::TestPlayoutAndSendingStates();
3583}
3584
3585TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3586 Base::TestMediaContentDirection();
3587}
3588
3589TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3590 Base::TestCallSetup();
3591}
3592
3593TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3594 Base::TestCallTeardownRtcpMux();
3595}
3596
3597TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3598 Base::TestOnReadyToSend();
3599}
3600
3601TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3602 Base::TestOnReadyToSendWithRtcpMux();
3603}
3604
3605TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3606 Base::SendRtpToRtp();
3607}
3608
3609TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3610 Base::SendNoRtcpToNoRtcp();
3611}
3612
3613TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3614 Base::SendNoRtcpToRtcp();
3615}
3616
3617TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3618 Base::SendRtcpToNoRtcp();
3619}
3620
3621TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3622 Base::SendRtcpToRtcp();
3623}
3624
3625TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3626 Base::SendRtcpMuxToRtcp();
3627}
3628
3629TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3630 Base::SendRtcpMuxToRtcpMux();
3631}
3632
3633TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3634 Base::SendEarlyRtcpMuxToRtcp();
3635}
3636
3637TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3638 Base::SendEarlyRtcpMuxToRtcpMux();
3639}
3640
3641TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3642 Base::SendSrtpToSrtp();
3643}
3644
3645TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3646 Base::SendSrtpToSrtp();
3647}
3648
3649TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3650 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3651}
3652
3653TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3654 Base::SendRtpToRtpOnThread();
3655}
3656
3657TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3658 Base::SendSrtpToSrtpOnThread();
3659}
3660
3661TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3662 Base::SendWithWritabilityLoss();
3663}
3664
3665TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3666 Base::TestMediaMonitor();
3667}
3668
3669TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670 CreateChannels(0, 0);
3671 EXPECT_TRUE(SendInitiate());
3672 EXPECT_TRUE(SendAccept());
3673
3674 cricket::SendDataParams params;
3675 params.ssrc = 42;
3676 unsigned char data[] = {
3677 'f', 'o', 'o'
3678 };
jbaucheec21bd2016-03-20 06:15:43 -07003679 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003680 cricket::SendDataResult result;
3681 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3682 EXPECT_EQ(params.ssrc,
3683 media_channel1_->last_sent_data_params().ssrc);
3684 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3685}
3686
3687// TODO(pthatcher): TestSetReceiver?