blob: 00382fab8e44582a561a80a44fa66eaa96a53384 [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::ScreencastId;
38using cricket::StreamParams;
39using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040
Danil Chapovalov33b01f22016-05-11 19:55:27 +020041namespace {
42const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
43const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
44const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
45const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30);
46const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15);
47const cricket::DataCodec kGoogleDataCodec(101, "google-data");
48const uint32_t kSsrc1 = 0x1111;
49const uint32_t kSsrc2 = 0x2222;
50const uint32_t kSsrc3 = 0x3333;
51const int kAudioPts[] = {0, 8};
52const int kVideoPts[] = {97, 99};
53enum class NetworkIsWorker { Yes, No };
54} // 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
274 cricket::FakeTransport* GetTransport1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200275 std::string name = channel1_->content_name();
276 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700277 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200278 [this, name] { return transport_controller1_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 }
280 cricket::FakeTransport* GetTransport2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200281 std::string name = channel2_->content_name();
282 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700283 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200284 [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);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700966 }
967
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 // Test setting up a call.
969 void TestCallSetup() {
970 CreateChannels(0, 0);
971 EXPECT_FALSE(channel1_->secure());
972 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200973 if (verify_playout_) {
974 EXPECT_TRUE(media_channel1_->playout());
975 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 EXPECT_FALSE(media_channel1_->sending());
977 EXPECT_TRUE(SendAccept());
978 EXPECT_FALSE(channel1_->secure());
979 EXPECT_TRUE(media_channel1_->sending());
980 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200981 if (verify_playout_) {
982 EXPECT_TRUE(media_channel2_->playout());
983 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 EXPECT_TRUE(media_channel2_->sending());
985 EXPECT_EQ(1U, media_channel2_->codecs().size());
986 }
987
988 // Test that we don't crash if packets are sent during call teardown
989 // when RTCP mux is enabled. This is a regression test against a specific
990 // race condition that would only occur when a RTCP packet was sent during
991 // teardown of a channel on which RTCP mux was enabled.
992 void TestCallTeardownRtcpMux() {
993 class LastWordMediaChannel : public T::MediaChannel {
994 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200995 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700997 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
998 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1000 }
1001 };
1002 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001003 RTCP | RTCP_MUX, RTCP | RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 EXPECT_TRUE(SendInitiate());
1005 EXPECT_TRUE(SendAccept());
1006 EXPECT_TRUE(SendTerminate());
1007 }
1008
1009 // Send voice RTP data to the other side and ensure it gets there.
1010 void SendRtpToRtp() {
1011 CreateChannels(0, 0);
1012 EXPECT_TRUE(SendInitiate());
1013 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001014 ASSERT_TRUE(GetTransport1());
1015 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 EXPECT_EQ(1U, GetTransport1()->channels().size());
1017 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001018 SendRtp1();
1019 SendRtp2();
1020 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 EXPECT_TRUE(CheckRtp1());
1022 EXPECT_TRUE(CheckRtp2());
1023 EXPECT_TRUE(CheckNoRtp1());
1024 EXPECT_TRUE(CheckNoRtp2());
1025 }
1026
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001027 void TestDeinit() {
1028 CreateChannels(RTCP, RTCP);
1029 EXPECT_TRUE(SendInitiate());
1030 EXPECT_TRUE(SendAccept());
1031 SendRtp1();
1032 SendRtp2();
1033 SendRtcp1();
1034 SendRtcp2();
1035 // Do not wait, destroy channels.
1036 channel1_.reset(nullptr);
1037 channel2_.reset(nullptr);
1038 }
1039
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001040 // Check that RTCP is not transmitted if both sides don't support RTCP.
1041 void SendNoRtcpToNoRtcp() {
1042 CreateChannels(0, 0);
1043 EXPECT_TRUE(SendInitiate());
1044 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001045 ASSERT_TRUE(GetTransport1());
1046 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 EXPECT_EQ(1U, GetTransport1()->channels().size());
1048 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001049 SendRtcp1();
1050 SendRtcp2();
1051 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 EXPECT_TRUE(CheckNoRtcp1());
1053 EXPECT_TRUE(CheckNoRtcp2());
1054 }
1055
1056 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1057 void SendNoRtcpToRtcp() {
1058 CreateChannels(0, RTCP);
1059 EXPECT_TRUE(SendInitiate());
1060 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001061 ASSERT_TRUE(GetTransport1());
1062 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 EXPECT_EQ(1U, GetTransport1()->channels().size());
1064 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001065 SendRtcp1();
1066 SendRtcp2();
1067 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 EXPECT_TRUE(CheckNoRtcp1());
1069 EXPECT_TRUE(CheckNoRtcp2());
1070 }
1071
1072 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1073 void SendRtcpToNoRtcp() {
1074 CreateChannels(RTCP, 0);
1075 EXPECT_TRUE(SendInitiate());
1076 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001077 ASSERT_TRUE(GetTransport1());
1078 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 EXPECT_EQ(2U, GetTransport1()->channels().size());
1080 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001081 SendRtcp1();
1082 SendRtcp2();
1083 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001084 EXPECT_TRUE(CheckNoRtcp1());
1085 EXPECT_TRUE(CheckNoRtcp2());
1086 }
1087
1088 // Check that RTCP is transmitted if both sides support RTCP.
1089 void SendRtcpToRtcp() {
1090 CreateChannels(RTCP, RTCP);
1091 EXPECT_TRUE(SendInitiate());
1092 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001093 ASSERT_TRUE(GetTransport1());
1094 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 EXPECT_EQ(2U, GetTransport1()->channels().size());
1096 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001097 SendRtcp1();
1098 SendRtcp2();
1099 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 EXPECT_TRUE(CheckRtcp1());
1101 EXPECT_TRUE(CheckRtcp2());
1102 EXPECT_TRUE(CheckNoRtcp1());
1103 EXPECT_TRUE(CheckNoRtcp2());
1104 }
1105
1106 // Check that RTCP is transmitted if only the initiator supports mux.
1107 void SendRtcpMuxToRtcp() {
1108 CreateChannels(RTCP | RTCP_MUX, RTCP);
1109 EXPECT_TRUE(SendInitiate());
1110 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001111 ASSERT_TRUE(GetTransport1());
1112 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 EXPECT_EQ(2U, GetTransport1()->channels().size());
1114 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001115 SendRtcp1();
1116 SendRtcp2();
1117 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 EXPECT_TRUE(CheckRtcp1());
1119 EXPECT_TRUE(CheckRtcp2());
1120 EXPECT_TRUE(CheckNoRtcp1());
1121 EXPECT_TRUE(CheckNoRtcp2());
1122 }
1123
1124 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1125 void SendRtcpMuxToRtcpMux() {
1126 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1127 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001128 ASSERT_TRUE(GetTransport1());
1129 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 EXPECT_EQ(2U, GetTransport1()->channels().size());
1131 EXPECT_EQ(1U, GetTransport2()->channels().size());
1132 EXPECT_TRUE(SendAccept());
1133 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001134 SendRtp1();
1135 SendRtp2();
1136 SendRtcp1();
1137 SendRtcp2();
1138 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 EXPECT_TRUE(CheckRtp1());
1140 EXPECT_TRUE(CheckRtp2());
1141 EXPECT_TRUE(CheckNoRtp1());
1142 EXPECT_TRUE(CheckNoRtp2());
1143 EXPECT_TRUE(CheckRtcp1());
1144 EXPECT_TRUE(CheckRtcp2());
1145 EXPECT_TRUE(CheckNoRtcp1());
1146 EXPECT_TRUE(CheckNoRtcp2());
1147 }
1148
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001149 // Check that RTP and RTCP are transmitted ok when both sides
1150 // support mux and one the offerer requires mux.
1151 void SendRequireRtcpMuxToRtcpMux() {
1152 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1153 channel1_->ActivateRtcpMux();
1154 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001155 ASSERT_TRUE(GetTransport1());
1156 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001157 EXPECT_EQ(1U, GetTransport1()->channels().size());
1158 EXPECT_EQ(1U, GetTransport2()->channels().size());
1159 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001160 SendRtp1();
1161 SendRtp2();
1162 SendRtcp1();
1163 SendRtcp2();
1164 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001165 EXPECT_TRUE(CheckRtp1());
1166 EXPECT_TRUE(CheckRtp2());
1167 EXPECT_TRUE(CheckNoRtp1());
1168 EXPECT_TRUE(CheckNoRtp2());
1169 EXPECT_TRUE(CheckRtcp1());
1170 EXPECT_TRUE(CheckRtcp2());
1171 EXPECT_TRUE(CheckNoRtcp1());
1172 EXPECT_TRUE(CheckNoRtcp2());
1173 }
1174
1175 // Check that RTP and RTCP are transmitted ok when both sides
1176 // support mux and one the answerer requires rtcp mux.
1177 void SendRtcpMuxToRequireRtcpMux() {
1178 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1179 channel2_->ActivateRtcpMux();
1180 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001181 ASSERT_TRUE(GetTransport1());
1182 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001183 EXPECT_EQ(2U, GetTransport1()->channels().size());
1184 EXPECT_EQ(1U, GetTransport2()->channels().size());
1185 EXPECT_TRUE(SendAccept());
1186 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001187 SendRtp1();
1188 SendRtp2();
1189 SendRtcp1();
1190 SendRtcp2();
1191 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001192 EXPECT_TRUE(CheckRtp1());
1193 EXPECT_TRUE(CheckRtp2());
1194 EXPECT_TRUE(CheckNoRtp1());
1195 EXPECT_TRUE(CheckNoRtp2());
1196 EXPECT_TRUE(CheckRtcp1());
1197 EXPECT_TRUE(CheckRtcp2());
1198 EXPECT_TRUE(CheckNoRtcp1());
1199 EXPECT_TRUE(CheckNoRtcp2());
1200 }
1201
1202 // Check that RTP and RTCP are transmitted ok when both sides
1203 // require mux.
1204 void SendRequireRtcpMuxToRequireRtcpMux() {
1205 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1206 channel1_->ActivateRtcpMux();
1207 channel2_->ActivateRtcpMux();
1208 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001209 ASSERT_TRUE(GetTransport1());
1210 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001211 EXPECT_EQ(1U, GetTransport1()->channels().size());
1212 EXPECT_EQ(1U, GetTransport2()->channels().size());
1213 EXPECT_TRUE(SendAccept());
1214 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001215 SendRtp1();
1216 SendRtp2();
1217 SendRtcp1();
1218 SendRtcp2();
1219 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001220 EXPECT_TRUE(CheckRtp1());
1221 EXPECT_TRUE(CheckRtp2());
1222 EXPECT_TRUE(CheckNoRtp1());
1223 EXPECT_TRUE(CheckNoRtp2());
1224 EXPECT_TRUE(CheckRtcp1());
1225 EXPECT_TRUE(CheckRtcp2());
1226 EXPECT_TRUE(CheckNoRtcp1());
1227 EXPECT_TRUE(CheckNoRtcp2());
1228 }
1229
1230 // Check that SendAccept fails if the answerer doesn't support mux
1231 // and the offerer requires it.
1232 void SendRequireRtcpMuxToNoRtcpMux() {
1233 CreateChannels(RTCP | RTCP_MUX, RTCP);
1234 channel1_->ActivateRtcpMux();
1235 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001236 ASSERT_TRUE(GetTransport1());
1237 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001238 EXPECT_EQ(1U, GetTransport1()->channels().size());
1239 EXPECT_EQ(2U, GetTransport2()->channels().size());
1240 EXPECT_FALSE(SendAccept());
1241 }
1242
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 // Check that RTCP data sent by the initiator before the accept is not muxed.
1244 void SendEarlyRtcpMuxToRtcp() {
1245 CreateChannels(RTCP | RTCP_MUX, RTCP);
1246 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001247 ASSERT_TRUE(GetTransport1());
1248 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001249 EXPECT_EQ(2U, GetTransport1()->channels().size());
1250 EXPECT_EQ(2U, GetTransport2()->channels().size());
1251
1252 // RTCP can be sent before the call is accepted, if the transport is ready.
1253 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001254 SendRtcp1();
1255 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 EXPECT_TRUE(CheckNoRtp2());
1257 EXPECT_TRUE(CheckRtcp2());
1258
1259 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001260 SendRtcp2();
1261 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001262 EXPECT_TRUE(CheckNoRtp1());
1263 EXPECT_TRUE(CheckRtcp1());
1264
1265 // Complete call setup and ensure everything is still OK.
1266 EXPECT_TRUE(SendAccept());
1267 EXPECT_EQ(2U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001268 SendRtcp1();
1269 SendRtcp2();
1270 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 EXPECT_TRUE(CheckRtcp1());
1273 }
1274
1275
1276 // Check that RTCP data is not muxed until both sides have enabled muxing,
1277 // but that we properly demux before we get the accept message, since there
1278 // is a race between RTP data and the jingle accept.
1279 void SendEarlyRtcpMuxToRtcpMux() {
1280 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1281 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001282 ASSERT_TRUE(GetTransport1());
1283 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 EXPECT_EQ(2U, GetTransport1()->channels().size());
1285 EXPECT_EQ(1U, GetTransport2()->channels().size());
1286
1287 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1288 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001289 SendRtcp1();
1290 WaitForThreads();
1291 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292
1293 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001294 SendRtcp2();
1295 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 EXPECT_TRUE(CheckNoRtp1());
1297 EXPECT_TRUE(CheckRtcp1());
1298
1299 // Complete call setup and ensure everything is still OK.
1300 EXPECT_TRUE(SendAccept());
1301 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001302 SendRtcp1();
1303 SendRtcp2();
1304 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 EXPECT_TRUE(CheckRtcp1());
1307 }
1308
1309 // Test that we properly send SRTP with RTCP in both directions.
1310 // You can pass in DTLS and/or RTCP_MUX as flags.
1311 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
jbauchcb560652016-08-04 05:20:32 -07001312 ASSERT((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1313 ASSERT((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314
1315 int flags1 = RTCP | SECURE | flags1_in;
1316 int flags2 = RTCP | SECURE | flags2_in;
1317 bool dtls1 = !!(flags1_in & DTLS);
1318 bool dtls2 = !!(flags2_in & DTLS);
1319 CreateChannels(flags1, flags2);
1320 EXPECT_FALSE(channel1_->secure());
1321 EXPECT_FALSE(channel2_->secure());
1322 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001323 WaitForThreads();
1324 EXPECT_TRUE(channel1_->writable());
1325 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 EXPECT_TRUE(SendAccept());
1327 EXPECT_TRUE(channel1_->secure());
1328 EXPECT_TRUE(channel2_->secure());
1329 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1330 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001331 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1332 // channels.
1333 if (dtls1 && dtls2) {
1334 // A GCM cipher is only used if both channels support GCM ciphers.
1335 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1336 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1337 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1338 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001339 SendRtp1();
1340 SendRtp2();
1341 SendRtcp1();
1342 SendRtcp2();
1343 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 EXPECT_TRUE(CheckRtp1());
1345 EXPECT_TRUE(CheckRtp2());
1346 EXPECT_TRUE(CheckNoRtp1());
1347 EXPECT_TRUE(CheckNoRtp2());
1348 EXPECT_TRUE(CheckRtcp1());
1349 EXPECT_TRUE(CheckRtcp2());
1350 EXPECT_TRUE(CheckNoRtcp1());
1351 EXPECT_TRUE(CheckNoRtcp2());
1352 }
1353
1354 // Test that we properly handling SRTP negotiating down to RTP.
1355 void SendSrtpToRtp() {
1356 CreateChannels(RTCP | SECURE, RTCP);
1357 EXPECT_FALSE(channel1_->secure());
1358 EXPECT_FALSE(channel2_->secure());
1359 EXPECT_TRUE(SendInitiate());
1360 EXPECT_TRUE(SendAccept());
1361 EXPECT_FALSE(channel1_->secure());
1362 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001363 SendRtp1();
1364 SendRtp2();
1365 SendRtcp1();
1366 SendRtcp2();
1367 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 EXPECT_TRUE(CheckRtp1());
1369 EXPECT_TRUE(CheckRtp2());
1370 EXPECT_TRUE(CheckNoRtp1());
1371 EXPECT_TRUE(CheckNoRtp2());
1372 EXPECT_TRUE(CheckRtcp1());
1373 EXPECT_TRUE(CheckRtcp2());
1374 EXPECT_TRUE(CheckNoRtcp1());
1375 EXPECT_TRUE(CheckNoRtcp2());
1376 }
1377
1378 // Test that we can send and receive early media when a provisional answer is
1379 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1380 void SendEarlyMediaUsingRtcpMuxSrtp() {
1381 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1382
1383 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1384 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1385 EXPECT_TRUE(SendOffer());
1386 EXPECT_TRUE(SendProvisionalAnswer());
1387 EXPECT_TRUE(channel1_->secure());
1388 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001389 ASSERT_TRUE(GetTransport1());
1390 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 EXPECT_EQ(2U, GetTransport1()->channels().size());
1392 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001393 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1394 SendCustomRtcp1(kSsrc1);
1395 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1396 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1399
1400 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001401 SendCustomRtcp2(kSsrc2);
1402 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1403 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1406
1407 // Complete call setup and ensure everything is still OK.
1408 EXPECT_TRUE(SendFinalAnswer());
1409 EXPECT_EQ(1U, GetTransport1()->channels().size());
1410 EXPECT_EQ(1U, GetTransport2()->channels().size());
1411 EXPECT_TRUE(channel1_->secure());
1412 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001413 SendCustomRtcp1(kSsrc1);
1414 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1415 SendCustomRtcp2(kSsrc2);
1416 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1417 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1422 }
1423
1424 // Test that we properly send RTP without SRTP from a thread.
1425 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001426 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 EXPECT_TRUE(SendInitiate());
1428 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001429 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1430 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1431 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1432 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1433 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1434 send_rtcp1.thread(),
1435 send_rtcp2.thread()};
1436 WaitForThreads(involved_threads);
1437 EXPECT_TRUE(CheckRtp1());
1438 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 EXPECT_TRUE(CheckNoRtp1());
1440 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001441 EXPECT_TRUE(CheckRtcp1());
1442 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 EXPECT_TRUE(CheckNoRtcp1());
1444 EXPECT_TRUE(CheckNoRtcp2());
1445 }
1446
1447 // Test that we properly send SRTP with RTCP from a thread.
1448 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1450 EXPECT_TRUE(SendInitiate());
1451 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001452 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1453 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1454 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1455 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1456 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1457 send_rtcp1.thread(),
1458 send_rtcp2.thread()};
1459 WaitForThreads(involved_threads);
1460 EXPECT_TRUE(CheckRtp1());
1461 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_TRUE(CheckNoRtp1());
1463 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001464 EXPECT_TRUE(CheckRtcp1());
1465 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 EXPECT_TRUE(CheckNoRtcp1());
1467 EXPECT_TRUE(CheckNoRtcp2());
1468 }
1469
1470 // Test that the mediachannel retains its sending state after the transport
1471 // becomes non-writable.
1472 void SendWithWritabilityLoss() {
1473 CreateChannels(0, 0);
1474 EXPECT_TRUE(SendInitiate());
1475 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001476 ASSERT_TRUE(GetTransport1());
1477 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001478 EXPECT_EQ(1U, GetTransport1()->channels().size());
1479 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001480 SendRtp1();
1481 SendRtp2();
1482 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 EXPECT_TRUE(CheckRtp1());
1484 EXPECT_TRUE(CheckRtp2());
1485 EXPECT_TRUE(CheckNoRtp1());
1486 EXPECT_TRUE(CheckNoRtp2());
1487
wu@webrtc.org97077a32013-10-25 21:18:33 +00001488 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001489 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001490 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001491 SendRtp1();
1492 SendRtp2();
1493 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_TRUE(CheckRtp1());
1495 EXPECT_TRUE(CheckNoRtp2());
1496
1497 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001498 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001499 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001501 SendRtp1();
1502 SendRtp2();
1503 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 EXPECT_TRUE(CheckRtp1());
1505 EXPECT_TRUE(CheckRtp2());
1506 EXPECT_TRUE(CheckNoRtp1());
1507 EXPECT_TRUE(CheckNoRtp2());
1508
1509 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001510 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001511 RTC_FROM_HERE, [this] { GetTransport1()->SetDestination(NULL); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512 EXPECT_TRUE(media_channel1_->sending());
1513
wu@webrtc.org97077a32013-10-25 21:18:33 +00001514 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001515 SendRtp1();
1516 SendRtp2();
1517 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 EXPECT_TRUE(CheckRtp1());
1519 EXPECT_TRUE(CheckNoRtp2());
1520
1521 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001522 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1523 GetTransport1()->SetDestination(GetTransport2());
1524 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001526 SendRtp1();
1527 SendRtp2();
1528 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 EXPECT_TRUE(CheckRtp1());
1530 EXPECT_TRUE(CheckRtp2());
1531 EXPECT_TRUE(CheckNoRtp1());
1532 EXPECT_TRUE(CheckNoRtp2());
1533 }
1534
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001535 void SendBundleToBundle(
1536 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1537 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001539 // Only pl_type1 was added to the bundle filter for both |channel1_|
1540 // and |channel2_|.
1541 int pl_type1 = pl_types[0];
1542 int pl_type2 = pl_types[1];
1543 int flags = SSRC_MUX | RTCP;
1544 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001545 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001546 if (rtcp_mux) {
1547 flags |= RTCP_MUX;
1548 expected_channels = 1U;
1549 }
1550 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001552 ASSERT_TRUE(GetTransport1());
1553 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001555 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001557 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1558 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1559 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1560 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1561 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1562 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001563
1564 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001565 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1566 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1567 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001568 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001569 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1570 EXPECT_TRUE(CheckNoRtp1());
1571 EXPECT_TRUE(CheckNoRtp2());
1572
1573 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001574 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1575 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1576 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001577 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001578 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1579
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001580 SendCustomRtcp1(kSsrc1);
1581 SendCustomRtcp2(kSsrc2);
1582 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1584 EXPECT_TRUE(CheckNoRtcp1());
1585 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1586 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001588 SendCustomRtcp1(kSsrc2);
1589 SendCustomRtcp2(kSsrc1);
1590 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001591 // Bundle filter shouldn't filter out any RTCP.
1592 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1593 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 }
1595
1596 // Test that the media monitor can be run and gives timely callbacks.
1597 void TestMediaMonitor() {
1598 static const int kTimeout = 500;
1599 CreateChannels(0, 0);
1600 EXPECT_TRUE(SendInitiate());
1601 EXPECT_TRUE(SendAccept());
1602 channel1_->StartMediaMonitor(100);
1603 channel2_->StartMediaMonitor(100);
1604 // Ensure we get callbacks and stop.
1605 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1606 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1607 channel1_->StopMediaMonitor();
1608 channel2_->StopMediaMonitor();
1609 // Ensure a restart of a stopped monitor works.
1610 channel1_->StartMediaMonitor(100);
1611 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1612 channel1_->StopMediaMonitor();
1613 // Ensure stopping a stopped monitor is OK.
1614 channel1_->StopMediaMonitor();
1615 }
1616
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 void TestSetContentFailure() {
1618 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619
Peter Thatchera6d24442015-07-09 21:26:36 -07001620 auto sdesc = cricket::SessionDescription();
1621 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1622 new cricket::AudioContentDescription());
1623 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1624 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625
Peter Thatchera6d24442015-07-09 21:26:36 -07001626 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001628 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1629 &sdesc, cricket::CA_OFFER, &err));
1630 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1631 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001634 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1635 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001637 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1638 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 }
1640
1641 void TestSendTwoOffers() {
1642 CreateChannels(0, 0);
1643
Peter Thatchera6d24442015-07-09 21:26:36 -07001644 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001645 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001646 CreateSessionDescriptionWithStream(1));
1647 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1648 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1650
kwiberg31022942016-03-11 14:18:21 -08001651 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001652 CreateSessionDescriptionWithStream(2));
1653 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1654 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1656 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1657 }
1658
1659 void TestReceiveTwoOffers() {
1660 CreateChannels(0, 0);
1661
Peter Thatchera6d24442015-07-09 21:26:36 -07001662 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001663 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001664 CreateSessionDescriptionWithStream(1));
1665 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1666 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1668
kwiberg31022942016-03-11 14:18:21 -08001669 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001670 CreateSessionDescriptionWithStream(2));
1671 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1672 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1674 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1675 }
1676
1677 void TestSendPrAnswer() {
1678 CreateChannels(0, 0);
1679
Peter Thatchera6d24442015-07-09 21:26:36 -07001680 std::string err;
1681 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001682 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001683 CreateSessionDescriptionWithStream(1));
1684 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1685 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1687
Peter Thatchera6d24442015-07-09 21:26:36 -07001688 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001689 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001690 CreateSessionDescriptionWithStream(2));
1691 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1692 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1694 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1695
Peter Thatchera6d24442015-07-09 21:26:36 -07001696 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001697 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001698 CreateSessionDescriptionWithStream(3));
1699 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1700 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1702 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1703 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1704 }
1705
1706 void TestReceivePrAnswer() {
1707 CreateChannels(0, 0);
1708
Peter Thatchera6d24442015-07-09 21:26:36 -07001709 std::string err;
1710 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001711 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001712 CreateSessionDescriptionWithStream(1));
1713 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1714 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1716
Peter Thatchera6d24442015-07-09 21:26:36 -07001717 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001718 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001719 CreateSessionDescriptionWithStream(2));
1720 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1721 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1723 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1724
Peter Thatchera6d24442015-07-09 21:26:36 -07001725 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001726 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001727 CreateSessionDescriptionWithStream(3));
1728 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1729 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1731 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1732 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1733 }
1734
1735 void TestFlushRtcp() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 CreateChannels(RTCP, RTCP);
1737 EXPECT_TRUE(SendInitiate());
1738 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001739 ASSERT_TRUE(GetTransport1());
1740 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 EXPECT_EQ(2U, GetTransport1()->channels().size());
1742 EXPECT_EQ(2U, GetTransport2()->channels().size());
1743
1744 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001745 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 // The sending message is only posted. channel2_ should be empty.
1747 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001748 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1749 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750
1751 // When channel1_ is deleted, the RTCP packet should be sent out to
1752 // channel2_.
1753 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001754 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 EXPECT_TRUE(CheckRtcp2());
1756 }
1757
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001758 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001759 struct SrtpErrorHandler : public sigslot::has_slots<> {
1760 SrtpErrorHandler() :
1761 mode_(cricket::SrtpFilter::UNPROTECT),
1762 error_(cricket::SrtpFilter::ERROR_NONE) {}
1763 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1764 cricket::SrtpFilter::Error error) {
1765 mode_ = mode;
1766 error_ = error;
1767 }
1768 cricket::SrtpFilter::Mode mode_;
1769 cricket::SrtpFilter::Error error_;
1770 } error_handler;
1771
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001772 // For Audio, only pl_type 0 is added to the bundle filter.
1773 // For Video, only pl_type 97 is added to the bundle filter.
1774 // So we need to pass in pl_type so that the packet can pass through
1775 // the bundle filter before it can be processed by the srtp filter.
1776 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001777 static unsigned const char kBadPacket[] = {
1778 0x84, static_cast<unsigned char>(pl_type),
1779 0x00, 0x01,
1780 0x00, 0x00,
1781 0x00, 0x00,
1782 0x00, 0x00,
1783 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001784
1785 // Using fake clock because this tests that SRTP errors are signaled at
1786 // specific times based on set_signal_silent_time.
1787 rtc::ScopedFakeClock fake_clock;
1788 // Some code uses a time of 0 as a special value, so we must start with
1789 // a non-zero time.
1790 // TODO(deadbeef): Fix this.
1791 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1792
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1794 EXPECT_FALSE(channel1_->secure());
1795 EXPECT_FALSE(channel2_->secure());
1796 EXPECT_TRUE(SendInitiate());
1797 EXPECT_TRUE(SendAccept());
1798 EXPECT_TRUE(channel1_->secure());
1799 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001800 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001801 channel2_->srtp_filter()->SignalSrtpError.connect(
1802 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803
1804 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001805 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1806 rtc::PacketOptions());
1807 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001809 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001810 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1811 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001812 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1813 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001814 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1815 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001817 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001818 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001819 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001820 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1821 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001822 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001823 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1824 rtc::PacketOptions());
1825 WaitForThreads();
1826 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001827 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828
1829 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001830 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001831 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001832
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001833 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001834 cricket::TransportChannel* transport_channel =
1835 channel2_->transport_channel();
1836 transport_channel->SignalReadPacket(
1837 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1838 sizeof(kBadPacket), rtc::PacketTime(), 0);
1839 });
1840 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001841 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001842 // Terminate channels before the fake clock is destroyed.
1843 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 }
1845
1846 void TestOnReadyToSend() {
1847 CreateChannels(RTCP, RTCP);
1848 TransportChannel* rtp = channel1_->transport_channel();
1849 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1850 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001851
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001852 network_thread_->Invoke<void>(RTC_FROM_HERE,
1853 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001854 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001856
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001857 network_thread_->Invoke<void>(RTC_FROM_HERE,
1858 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001859 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1861 // channel are ready to send.
1862 EXPECT_TRUE(media_channel1_->ready_to_send());
1863
1864 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001865 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1866 channel1_->SetTransportChannelReadyToSend(false, false);
1867 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001868 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001870
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001871 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1872 channel1_->SetTransportChannelReadyToSend(false, true);
1873 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001874 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 EXPECT_TRUE(media_channel1_->ready_to_send());
1876
1877 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001878 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1879 channel1_->SetTransportChannelReadyToSend(true, false);
1880 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001881 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001883
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001884 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1885 channel1_->SetTransportChannelReadyToSend(true, true);
1886 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001887 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 EXPECT_TRUE(media_channel1_->ready_to_send());
1889 }
1890
1891 void TestOnReadyToSendWithRtcpMux() {
1892 CreateChannels(RTCP, RTCP);
1893 typename T::Content content;
1894 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1895 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1896 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001897 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1898 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1900 TransportChannel* rtp = channel1_->transport_channel();
1901 EXPECT_FALSE(media_channel1_->ready_to_send());
1902 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1903 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001904 network_thread_->Invoke<void>(RTC_FROM_HERE,
1905 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001906 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001908
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001909 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1910 channel1_->SetTransportChannelReadyToSend(false, false);
1911 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001912 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 EXPECT_FALSE(media_channel1_->ready_to_send());
1914 }
1915
skvladdc1c62c2016-03-16 19:07:43 -07001916 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1917 typename T::Content content;
1918 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1919 content.set_bandwidth(remote_limit);
1920 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1921 }
1922
1923 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1924 webrtc::RtpParameters parameters;
1925 webrtc::RtpEncodingParameters encoding;
1926 encoding.max_bitrate_bps = limit;
1927 parameters.encodings.push_back(encoding);
1928 return parameters;
1929 }
1930
1931 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1932 int expected_bitrate) {
1933 EXPECT_EQ(1UL, parameters.encodings.size());
1934 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1935 }
1936
1937 void DefaultMaxBitrateIsUnlimited() {
1938 CreateChannels(0, 0);
1939 EXPECT_TRUE(
1940 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1941 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001942 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001943 }
1944
1945 void CanChangeMaxBitrate() {
1946 CreateChannels(0, 0);
1947 EXPECT_TRUE(
1948 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1949
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001950 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1951 kSsrc1, BitrateLimitedParameters(1000)));
1952 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1953 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001954 EXPECT_EQ(-1, media_channel1_->max_bps());
1955
1956 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001957 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1958 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1959 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001960 EXPECT_EQ(-1, media_channel1_->max_bps());
1961 }
1962
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001964 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1965 static void ProcessThreadQueue(rtc::Thread* thread) {
1966 RTC_DCHECK(thread->IsCurrent());
1967 while (!thread->empty()) {
1968 thread->ProcessMessages(0);
1969 }
1970 }
1971 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1972 // |threads| and current thread post packets to network thread.
1973 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001974 thread->Invoke<void>(RTC_FROM_HERE,
1975 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001976 }
1977 ProcessThreadQueue(rtc::Thread::Current());
1978 // Network thread move them around and post back to worker = current thread.
1979 if (!network_thread_->IsCurrent()) {
1980 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001981 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001982 }
1983 // Worker thread = current Thread process received messages.
1984 ProcessThreadQueue(rtc::Thread::Current());
1985 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001986 // TODO(pbos): Remove playout from all media channels and let renderers mute
1987 // themselves.
1988 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001989 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1990 rtc::Thread* network_thread_;
1991 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1992 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001993 cricket::FakeMediaEngine media_engine_;
1994 // The media channels are owned by the voice channel objects below.
1995 typename T::MediaChannel* media_channel1_;
1996 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001997 std::unique_ptr<typename T::Channel> channel1_;
1998 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 typename T::Content local_media_content1_;
2000 typename T::Content local_media_content2_;
2001 typename T::Content remote_media_content1_;
2002 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002004 rtc::Buffer rtp_packet_;
2005 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 int media_info_callbacks1_;
2007 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07002008 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009};
2010
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011template<>
2012void ChannelTest<VoiceTraits>::CreateContent(
2013 int flags,
2014 const cricket::AudioCodec& audio_codec,
2015 const cricket::VideoCodec& video_codec,
2016 cricket::AudioContentDescription* audio) {
2017 audio->AddCodec(audio_codec);
2018 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
2019 if (flags & SECURE) {
2020 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002021 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2022 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 }
2024}
2025
2026template<>
2027void ChannelTest<VoiceTraits>::CopyContent(
2028 const cricket::AudioContentDescription& source,
2029 cricket::AudioContentDescription* audio) {
2030 *audio = source;
2031}
2032
2033template<>
2034bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2035 const cricket::AudioCodec& c2) {
2036 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2037 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2038}
2039
Peter Boström0c4e06b2015-10-07 12:23:21 +02002040template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002042 uint32_t ssrc,
2043 int flags,
2044 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 audio->AddLegacyStream(ssrc);
2046}
2047
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002048class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 public:
solenberg1dd98f32015-09-10 01:57:14 -07002050 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002051 VoiceChannelSingleThreadTest()
2052 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2053};
2054
2055class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2056 public:
2057 typedef ChannelTest<VoiceTraits> Base;
2058 VoiceChannelDoubleThreadTest()
2059 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060};
2061
2062// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002063template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002065 rtc::Thread* worker_thread,
2066 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002067 cricket::MediaEngineInterface* engine,
2068 cricket::FakeVideoMediaChannel* ch,
2069 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002070 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002071 cricket::VideoChannel* channel =
2072 new cricket::VideoChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07002073 transport_controller, cricket::CN_VIDEO,
2074 (flags & RTCP) != 0);
2075 rtc::CryptoOptions crypto_options;
2076 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2077 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07002078 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 delete channel;
2080 channel = NULL;
2081 }
2082 return channel;
2083}
2084
2085// override to add 0 parameter
2086template<>
2087bool ChannelTest<VideoTraits>::AddStream1(int id) {
2088 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2089}
2090
2091template<>
2092void ChannelTest<VideoTraits>::CreateContent(
2093 int flags,
2094 const cricket::AudioCodec& audio_codec,
2095 const cricket::VideoCodec& video_codec,
2096 cricket::VideoContentDescription* video) {
2097 video->AddCodec(video_codec);
2098 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2099 if (flags & SECURE) {
2100 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002101 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2102 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 }
2104}
2105
2106template<>
2107void ChannelTest<VideoTraits>::CopyContent(
2108 const cricket::VideoContentDescription& source,
2109 cricket::VideoContentDescription* video) {
2110 *video = source;
2111}
2112
2113template<>
2114bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2115 const cricket::VideoCodec& c2) {
2116 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2117 c1.framerate == c2.framerate;
2118}
2119
Peter Boström0c4e06b2015-10-07 12:23:21 +02002120template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002122 uint32_t ssrc,
2123 int flags,
2124 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 video->AddLegacyStream(ssrc);
2126}
2127
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002128class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 public:
solenberg1dd98f32015-09-10 01:57:14 -07002130 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002131 VideoChannelSingleThreadTest()
2132 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133};
2134
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002135class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2136 public:
2137 typedef ChannelTest<VideoTraits> Base;
2138 VideoChannelDoubleThreadTest()
2139 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2140};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002142// VoiceChannelSingleThreadTest
2143TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 Base::TestInit();
2145 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2146 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2147}
2148
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002149TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2150 Base::TestDeinit();
2151}
2152
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002153TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 Base::TestSetContents();
2155}
2156
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002157TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 Base::TestSetContentsNullOffer();
2159}
2160
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002161TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162 Base::TestSetContentsRtcpMux();
2163}
2164
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002165TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 Base::TestSetContentsRtcpMux();
2167}
2168
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002169TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 Base::TestSetRemoteContentUpdate();
2171}
2172
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002173TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 Base::TestStreams();
2175}
2176
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002177TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 Base::TestUpdateStreamsInLocalContent();
2179}
2180
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002181TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182 Base::TestUpdateStreamsInRemoteContent();
2183}
2184
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002185TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 Base::TestChangeStreamParamsInContent();
2187}
2188
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002189TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 Base::TestPlayoutAndSendingStates();
2191}
2192
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002193TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002194 CreateChannels(0, 0);
2195 // Test that we can Mute the default channel even though the sending SSRC
2196 // is unknown.
2197 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002198 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002199 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2200 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002201 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2202
2203 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002204 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002205
2206 SendInitiate();
2207 // After the local session description has been set, we can mute a stream
2208 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002209 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002210 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2211 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002212 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213}
2214
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002215TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216 Base::TestMediaContentDirection();
2217}
2218
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002219TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002220 Base::TestNetworkRouteChanges();
2221}
2222
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002223TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 Base::TestCallSetup();
2225}
2226
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002227TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 Base::TestCallTeardownRtcpMux();
2229}
2230
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002231TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 Base::SendRtpToRtp();
2233}
2234
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002235TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236 Base::SendNoRtcpToNoRtcp();
2237}
2238
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002239TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240 Base::SendNoRtcpToRtcp();
2241}
2242
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002243TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 Base::SendRtcpToNoRtcp();
2245}
2246
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002247TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 Base::SendRtcpToRtcp();
2249}
2250
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002251TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 Base::SendRtcpMuxToRtcp();
2253}
2254
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002255TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 Base::SendRtcpMuxToRtcpMux();
2257}
2258
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002259TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002260 Base::SendRequireRtcpMuxToRtcpMux();
2261}
2262
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002263TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002264 Base::SendRtcpMuxToRequireRtcpMux();
2265}
2266
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002267TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002268 Base::SendRequireRtcpMuxToRequireRtcpMux();
2269}
2270
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002271TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002272 Base::SendRequireRtcpMuxToNoRtcpMux();
2273}
2274
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002275TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 Base::SendEarlyRtcpMuxToRtcp();
2277}
2278
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002279TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 Base::SendEarlyRtcpMuxToRtcpMux();
2281}
2282
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002283TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2285}
2286
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002287TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 Base::SendSrtpToSrtp();
2289}
2290
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002291TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2293}
2294
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002295TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2297 Base::SendSrtpToSrtp(DTLS, 0);
2298}
2299
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002300TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2302 Base::SendSrtpToSrtp(DTLS, DTLS);
2303}
2304
jbauchcb560652016-08-04 05:20:32 -07002305TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2306 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2307 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2308}
2309
2310TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2311 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2312 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2313}
2314
2315TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2316 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2317 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2318}
2319
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002320TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2322 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2323}
2324
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002325TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2327}
2328
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002329TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 Base::SendRtpToRtpOnThread();
2331}
2332
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002333TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 Base::SendSrtpToSrtpOnThread();
2335}
2336
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002337TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 Base::SendWithWritabilityLoss();
2339}
2340
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002341TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 Base::TestMediaMonitor();
2343}
2344
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002346TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 CreateChannels(0, 0);
2348 EXPECT_TRUE(SendInitiate());
2349 EXPECT_TRUE(SendAccept());
2350 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2351
solenberg1d63dd02015-12-02 12:35:09 -08002352 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2353 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2354 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002356 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002358 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002359 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002360 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002361 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002362 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363}
2364
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002365TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 Base::TestSetContentFailure();
2367}
2368
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002369TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 Base::TestSendTwoOffers();
2371}
2372
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002373TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 Base::TestReceiveTwoOffers();
2375}
2376
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002377TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 Base::TestSendPrAnswer();
2379}
2380
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002381TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 Base::TestReceivePrAnswer();
2383}
2384
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002385TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 Base::TestFlushRtcp();
2387}
2388
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002389TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002390 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391}
2392
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002393TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394 Base::TestOnReadyToSend();
2395}
2396
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002397TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 Base::TestOnReadyToSendWithRtcpMux();
2399}
2400
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002402TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 CreateChannels(RTCP, RTCP);
2404 EXPECT_TRUE(SendInitiate());
2405 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002406 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407
solenberg4bac9c52015-10-09 02:32:53 -07002408 // Default is (1.0).
2409 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2410 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002412 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413
solenberg4bac9c52015-10-09 02:32:53 -07002414 // Set scale to (1.5).
2415 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2416 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2417 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418
solenberg4bac9c52015-10-09 02:32:53 -07002419 // Set scale to (0).
2420 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2421 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2422 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423}
2424
2425// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002426TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 CreateChannels(RTCP, RTCP);
2428 EXPECT_TRUE(SendInitiate());
2429 EXPECT_TRUE(SendAccept());
2430 EXPECT_TRUE(AddStream1(1));
2431 EXPECT_TRUE(AddStream1(2));
2432
solenberg4bac9c52015-10-09 02:32:53 -07002433 double volume;
2434 // Default is (1.0).
2435 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2436 EXPECT_DOUBLE_EQ(1.0, volume);
2437 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2438 EXPECT_DOUBLE_EQ(1.0, volume);
2439 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2440 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002442 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443
solenberg4bac9c52015-10-09 02:32:53 -07002444 // Set scale to (1.5) for ssrc = 1.
2445 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2446 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2447 EXPECT_DOUBLE_EQ(1.5, volume);
2448 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2449 EXPECT_DOUBLE_EQ(1.0, volume);
2450 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2451 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452
solenberg4bac9c52015-10-09 02:32:53 -07002453 // Set scale to (0) for all ssrcs.
2454 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2455 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2456 EXPECT_DOUBLE_EQ(0.0, volume);
2457 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2458 EXPECT_DOUBLE_EQ(0.0, volume);
2459 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2460 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461}
2462
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002463TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002464 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465}
2466
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002467TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002468 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002469}
2470
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002471TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002472 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002473}
2474
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002475TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002476 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477}
2478
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002479TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002480 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002481}
2482
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002483TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002484 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002485}
2486
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002487// VoiceChannelDoubleThreadTest
2488TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002490 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2491 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492}
2493
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002494TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2495 Base::TestDeinit();
2496}
2497
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002498TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 Base::TestSetContents();
2500}
2501
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002502TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 Base::TestSetContentsNullOffer();
2504}
2505
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002506TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507 Base::TestSetContentsRtcpMux();
2508}
2509
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002510TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511 Base::TestSetContentsRtcpMux();
2512}
2513
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002514TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 Base::TestSetRemoteContentUpdate();
2516}
2517
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002518TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 Base::TestStreams();
2520}
2521
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002522TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 Base::TestUpdateStreamsInLocalContent();
2524}
2525
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002526TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 Base::TestUpdateStreamsInRemoteContent();
2528}
2529
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002530TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002531 Base::TestChangeStreamParamsInContent();
2532}
2533
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002534TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 Base::TestPlayoutAndSendingStates();
2536}
2537
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002538TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2539 CreateChannels(0, 0);
2540 // Test that we can Mute the default channel even though the sending SSRC
2541 // is unknown.
2542 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2543 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2544 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2545 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2546 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2547
2548 // Test that we can not mute an unknown SSRC.
2549 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2550
2551 SendInitiate();
2552 // After the local session description has been set, we can mute a stream
2553 // with its SSRC.
2554 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2555 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2556 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2557 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2558}
2559
2560TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2561 Base::TestMediaContentDirection();
2562}
2563
2564TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2565 Base::TestNetworkRouteChanges();
2566}
2567
2568TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2569 Base::TestCallSetup();
2570}
2571
2572TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2573 Base::TestCallTeardownRtcpMux();
2574}
2575
2576TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2577 Base::SendRtpToRtp();
2578}
2579
2580TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2581 Base::SendNoRtcpToNoRtcp();
2582}
2583
2584TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2585 Base::SendNoRtcpToRtcp();
2586}
2587
2588TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2589 Base::SendRtcpToNoRtcp();
2590}
2591
2592TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2593 Base::SendRtcpToRtcp();
2594}
2595
2596TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2597 Base::SendRtcpMuxToRtcp();
2598}
2599
2600TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2601 Base::SendRtcpMuxToRtcpMux();
2602}
2603
2604TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2605 Base::SendRequireRtcpMuxToRtcpMux();
2606}
2607
2608TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2609 Base::SendRtcpMuxToRequireRtcpMux();
2610}
2611
2612TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2613 Base::SendRequireRtcpMuxToRequireRtcpMux();
2614}
2615
2616TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2617 Base::SendRequireRtcpMuxToNoRtcpMux();
2618}
2619
2620TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2621 Base::SendEarlyRtcpMuxToRtcp();
2622}
2623
2624TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2625 Base::SendEarlyRtcpMuxToRtcpMux();
2626}
2627
2628TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2629 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2630}
2631
2632TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2633 Base::SendSrtpToSrtp();
2634}
2635
2636TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2637 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2638}
2639
2640TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2641 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2642 Base::SendSrtpToSrtp(DTLS, 0);
2643}
2644
2645TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2646 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2647 Base::SendSrtpToSrtp(DTLS, DTLS);
2648}
2649
jbauchcb560652016-08-04 05:20:32 -07002650TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2651 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2652 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2656 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2657 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2658}
2659
2660TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2661 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2662 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2663}
2664
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002665TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2666 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2667 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2668}
2669
2670TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2671 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2672}
2673
2674TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2675 Base::SendRtpToRtpOnThread();
2676}
2677
2678TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2679 Base::SendSrtpToSrtpOnThread();
2680}
2681
2682TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2683 Base::SendWithWritabilityLoss();
2684}
2685
2686TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2687 Base::TestMediaMonitor();
2688}
2689
2690// Test that InsertDtmf properly forwards to the media channel.
2691TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2692 CreateChannels(0, 0);
2693 EXPECT_TRUE(SendInitiate());
2694 EXPECT_TRUE(SendAccept());
2695 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2696
2697 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2698 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2699 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2700
2701 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2702 EXPECT_TRUE(
2703 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2704 EXPECT_TRUE(
2705 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2706 EXPECT_TRUE(
2707 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2708}
2709
2710TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2711 Base::TestSetContentFailure();
2712}
2713
2714TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2715 Base::TestSendTwoOffers();
2716}
2717
2718TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2719 Base::TestReceiveTwoOffers();
2720}
2721
2722TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2723 Base::TestSendPrAnswer();
2724}
2725
2726TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2727 Base::TestReceivePrAnswer();
2728}
2729
2730TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2731 Base::TestFlushRtcp();
2732}
2733
2734TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2735 Base::TestSrtpError(kAudioPts[0]);
2736}
2737
2738TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2739 Base::TestOnReadyToSend();
2740}
2741
2742TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2743 Base::TestOnReadyToSendWithRtcpMux();
2744}
2745
2746// Test that we can scale the output volume properly for 1:1 calls.
2747TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2748 CreateChannels(RTCP, RTCP);
2749 EXPECT_TRUE(SendInitiate());
2750 EXPECT_TRUE(SendAccept());
2751 double volume;
2752
2753 // Default is (1.0).
2754 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2755 EXPECT_DOUBLE_EQ(1.0, volume);
2756 // invalid ssrc.
2757 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2758
2759 // Set scale to (1.5).
2760 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2761 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2762 EXPECT_DOUBLE_EQ(1.5, volume);
2763
2764 // Set scale to (0).
2765 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2766 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2767 EXPECT_DOUBLE_EQ(0.0, volume);
2768}
2769
2770// Test that we can scale the output volume properly for multiway calls.
2771TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2772 CreateChannels(RTCP, RTCP);
2773 EXPECT_TRUE(SendInitiate());
2774 EXPECT_TRUE(SendAccept());
2775 EXPECT_TRUE(AddStream1(1));
2776 EXPECT_TRUE(AddStream1(2));
2777
2778 double volume;
2779 // Default is (1.0).
2780 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2781 EXPECT_DOUBLE_EQ(1.0, volume);
2782 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2783 EXPECT_DOUBLE_EQ(1.0, volume);
2784 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2785 EXPECT_DOUBLE_EQ(1.0, volume);
2786 // invalid ssrc.
2787 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2788
2789 // Set scale to (1.5) for ssrc = 1.
2790 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2791 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2792 EXPECT_DOUBLE_EQ(1.5, volume);
2793 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2794 EXPECT_DOUBLE_EQ(1.0, volume);
2795 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2796 EXPECT_DOUBLE_EQ(1.0, volume);
2797
2798 // Set scale to (0) for all ssrcs.
2799 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2800 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2801 EXPECT_DOUBLE_EQ(0.0, volume);
2802 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2803 EXPECT_DOUBLE_EQ(0.0, volume);
2804 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2805 EXPECT_DOUBLE_EQ(0.0, volume);
2806}
2807
2808TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2809 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2810}
2811
2812TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2813 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2814}
2815
2816TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2817 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2818}
2819
2820TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2821 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2822}
2823
2824TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2825 Base::DefaultMaxBitrateIsUnlimited();
2826}
2827
2828TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2829 Base::CanChangeMaxBitrate();
2830}
2831
2832// VideoChannelSingleThreadTest
2833TEST_F(VideoChannelSingleThreadTest, TestInit) {
2834 Base::TestInit();
2835}
2836
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002837TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2838 Base::TestDeinit();
2839}
2840
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002841TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2842 Base::TestSetContents();
2843}
2844
2845TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2846 Base::TestSetContentsNullOffer();
2847}
2848
2849TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2850 Base::TestSetContentsRtcpMux();
2851}
2852
2853TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2854 Base::TestSetContentsRtcpMux();
2855}
2856
2857TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2858 Base::TestSetRemoteContentUpdate();
2859}
2860
2861TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2862 Base::TestStreams();
2863}
2864
2865TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2866 Base::TestUpdateStreamsInLocalContent();
2867}
2868
2869TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2870 Base::TestUpdateStreamsInRemoteContent();
2871}
2872
2873TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2874 Base::TestChangeStreamParamsInContent();
2875}
2876
2877TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2878 Base::TestPlayoutAndSendingStates();
2879}
2880
2881TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002882 CreateChannels(0, 0);
2883 // Test that we can Mute the default channel even though the sending SSRC
2884 // is unknown.
2885 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002886 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002887 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002888 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002889 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2890 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002891 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002892 SendInitiate();
2893 // After the local session description has been set, we can mute a stream
2894 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002895 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002896 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002897 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002898 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899}
2900
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002901TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902 Base::TestMediaContentDirection();
2903}
2904
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002905TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002906 Base::TestNetworkRouteChanges();
2907}
2908
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002909TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910 Base::TestCallSetup();
2911}
2912
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002913TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 Base::TestCallTeardownRtcpMux();
2915}
2916
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002917TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918 Base::SendRtpToRtp();
2919}
2920
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002921TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002922 Base::SendNoRtcpToNoRtcp();
2923}
2924
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002925TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926 Base::SendNoRtcpToRtcp();
2927}
2928
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002929TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 Base::SendRtcpToNoRtcp();
2931}
2932
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002933TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934 Base::SendRtcpToRtcp();
2935}
2936
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002937TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 Base::SendRtcpMuxToRtcp();
2939}
2940
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002941TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002942 Base::SendRtcpMuxToRtcpMux();
2943}
2944
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002945TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002946 Base::SendRequireRtcpMuxToRtcpMux();
2947}
2948
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002949TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002950 Base::SendRtcpMuxToRequireRtcpMux();
2951}
2952
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002953TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002954 Base::SendRequireRtcpMuxToRequireRtcpMux();
2955}
2956
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002957TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002958 Base::SendRequireRtcpMuxToNoRtcpMux();
2959}
2960
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002961TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002962 Base::SendEarlyRtcpMuxToRtcp();
2963}
2964
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002965TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966 Base::SendEarlyRtcpMuxToRtcpMux();
2967}
2968
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002969TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970 Base::SendSrtpToSrtp();
2971}
2972
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002973TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974 Base::SendSrtpToSrtp();
2975}
2976
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002977TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2979 Base::SendSrtpToSrtp(DTLS, 0);
2980}
2981
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002982TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2984 Base::SendSrtpToSrtp(DTLS, DTLS);
2985}
2986
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002987TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2989 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2990}
2991
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002992TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2994}
2995
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002996TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002997 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2998}
2999
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003000TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001 Base::SendRtpToRtpOnThread();
3002}
3003
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003004TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003005 Base::SendSrtpToSrtpOnThread();
3006}
3007
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003008TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003009 Base::SendWithWritabilityLoss();
3010}
3011
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003012TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003013 Base::TestMediaMonitor();
3014}
3015
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003016TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003017 Base::TestSetContentFailure();
3018}
3019
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003020TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003021 Base::TestSendTwoOffers();
3022}
3023
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003024TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003025 Base::TestReceiveTwoOffers();
3026}
3027
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003028TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029 Base::TestSendPrAnswer();
3030}
3031
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003032TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003033 Base::TestReceivePrAnswer();
3034}
3035
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003036TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003037 Base::TestFlushRtcp();
3038}
3039
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003040TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08003041 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003042}
3043
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003044TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003045 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003046}
3047
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003048TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08003049 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003050}
3051
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003052TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003053 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003054}
3055
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003056TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003057 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003058}
3059
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003060TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003061 Base::TestOnReadyToSend();
3062}
3063
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003064TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003065 Base::TestOnReadyToSendWithRtcpMux();
3066}
3067
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003068TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003069 Base::DefaultMaxBitrateIsUnlimited();
3070}
3071
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003072TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003073 Base::CanChangeMaxBitrate();
3074}
3075
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003076// VideoChannelDoubleThreadTest
3077TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3078 Base::TestInit();
3079}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003080
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003081TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3082 Base::TestDeinit();
3083}
3084
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003085TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3086 Base::TestSetContents();
3087}
3088
3089TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3090 Base::TestSetContentsNullOffer();
3091}
3092
3093TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3094 Base::TestSetContentsRtcpMux();
3095}
3096
3097TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3098 Base::TestSetContentsRtcpMux();
3099}
3100
3101TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3102 Base::TestSetRemoteContentUpdate();
3103}
3104
3105TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3106 Base::TestStreams();
3107}
3108
3109TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3110 Base::TestUpdateStreamsInLocalContent();
3111}
3112
3113TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3114 Base::TestUpdateStreamsInRemoteContent();
3115}
3116
3117TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3118 Base::TestChangeStreamParamsInContent();
3119}
3120
3121TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3122 Base::TestPlayoutAndSendingStates();
3123}
3124
3125TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3126 CreateChannels(0, 0);
3127 // Test that we can Mute the default channel even though the sending SSRC
3128 // is unknown.
3129 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003130 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003131 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003132 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003133 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3134 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003135 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003136 SendInitiate();
3137 // After the local session description has been set, we can mute a stream
3138 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003139 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003140 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003141 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003142 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3143}
3144
3145TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3146 Base::TestMediaContentDirection();
3147}
3148
3149TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3150 Base::TestNetworkRouteChanges();
3151}
3152
3153TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3154 Base::TestCallSetup();
3155}
3156
3157TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3158 Base::TestCallTeardownRtcpMux();
3159}
3160
3161TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3162 Base::SendRtpToRtp();
3163}
3164
3165TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3166 Base::SendNoRtcpToNoRtcp();
3167}
3168
3169TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3170 Base::SendNoRtcpToRtcp();
3171}
3172
3173TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3174 Base::SendRtcpToNoRtcp();
3175}
3176
3177TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3178 Base::SendRtcpToRtcp();
3179}
3180
3181TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3182 Base::SendRtcpMuxToRtcp();
3183}
3184
3185TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3186 Base::SendRtcpMuxToRtcpMux();
3187}
3188
3189TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3190 Base::SendRequireRtcpMuxToRtcpMux();
3191}
3192
3193TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3194 Base::SendRtcpMuxToRequireRtcpMux();
3195}
3196
3197TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3198 Base::SendRequireRtcpMuxToRequireRtcpMux();
3199}
3200
3201TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3202 Base::SendRequireRtcpMuxToNoRtcpMux();
3203}
3204
3205TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3206 Base::SendEarlyRtcpMuxToRtcp();
3207}
3208
3209TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3210 Base::SendEarlyRtcpMuxToRtcpMux();
3211}
3212
3213TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3214 Base::SendSrtpToSrtp();
3215}
3216
3217TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3218 Base::SendSrtpToSrtp();
3219}
3220
3221TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3222 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3223 Base::SendSrtpToSrtp(DTLS, 0);
3224}
3225
3226TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3227 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3228 Base::SendSrtpToSrtp(DTLS, DTLS);
3229}
3230
3231TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3232 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3233 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3234}
3235
3236TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3237 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3238}
3239
3240TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3241 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3242}
3243
3244TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3245 Base::SendRtpToRtpOnThread();
3246}
3247
3248TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3249 Base::SendSrtpToSrtpOnThread();
3250}
3251
3252TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3253 Base::SendWithWritabilityLoss();
3254}
3255
3256TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3257 Base::TestMediaMonitor();
3258}
3259
3260TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3261 Base::TestSetContentFailure();
3262}
3263
3264TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3265 Base::TestSendTwoOffers();
3266}
3267
3268TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3269 Base::TestReceiveTwoOffers();
3270}
3271
3272TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3273 Base::TestSendPrAnswer();
3274}
3275
3276TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3277 Base::TestReceivePrAnswer();
3278}
3279
3280TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3281 Base::TestFlushRtcp();
3282}
3283
3284TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3285 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3286}
3287
3288TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3289 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3290}
3291
3292TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3293 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3294}
3295
3296TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3297 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3298}
3299
3300TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3301 Base::TestSrtpError(kVideoPts[0]);
3302}
3303
3304TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3305 Base::TestOnReadyToSend();
3306}
3307
3308TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3309 Base::TestOnReadyToSendWithRtcpMux();
3310}
3311
3312TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3313 Base::DefaultMaxBitrateIsUnlimited();
3314}
3315
3316TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3317 Base::CanChangeMaxBitrate();
3318}
3319
3320// DataChannelSingleThreadTest
3321class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003322 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003323 typedef ChannelTest<DataTraits> Base;
3324 DataChannelSingleThreadTest()
3325 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3326};
3327
3328// DataChannelDoubleThreadTest
3329class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3330 public:
3331 typedef ChannelTest<DataTraits> Base;
3332 DataChannelDoubleThreadTest()
3333 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334};
3335
3336// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003337template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003339 rtc::Thread* worker_thread,
3340 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003341 cricket::MediaEngineInterface* engine,
3342 cricket::FakeDataMediaChannel* ch,
3343 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003344 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003345 cricket::DataChannel* channel =
3346 new cricket::DataChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07003347 transport_controller, cricket::CN_DATA,
3348 (flags & RTCP) != 0);
3349 rtc::CryptoOptions crypto_options;
3350 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3351 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07003352 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003353 delete channel;
3354 channel = NULL;
3355 }
3356 return channel;
3357}
3358
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003359template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360void ChannelTest<DataTraits>::CreateContent(
3361 int flags,
3362 const cricket::AudioCodec& audio_codec,
3363 const cricket::VideoCodec& video_codec,
3364 cricket::DataContentDescription* data) {
3365 data->AddCodec(kGoogleDataCodec);
3366 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3367 if (flags & SECURE) {
3368 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003369 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3370 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003371 }
3372}
3373
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003374template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375void ChannelTest<DataTraits>::CopyContent(
3376 const cricket::DataContentDescription& source,
3377 cricket::DataContentDescription* data) {
3378 *data = source;
3379}
3380
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003381template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3383 const cricket::DataCodec& c2) {
3384 return c1.name == c2.name;
3385}
3386
Peter Boström0c4e06b2015-10-07 12:23:21 +02003387template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003388void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003389 uint32_t ssrc,
3390 int flags,
3391 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392 data->AddLegacyStream(ssrc);
3393}
3394
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003395TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 Base::TestInit();
3397 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3398}
3399
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003400TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3401 Base::TestDeinit();
3402}
3403
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003404TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405 Base::TestSetContents();
3406}
3407
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003408TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003409 Base::TestSetContentsNullOffer();
3410}
3411
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003412TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413 Base::TestSetContentsRtcpMux();
3414}
3415
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003416TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003417 Base::TestSetRemoteContentUpdate();
3418}
3419
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003420TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003421 Base::TestStreams();
3422}
3423
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003424TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425 Base::TestUpdateStreamsInLocalContent();
3426}
3427
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003428TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429 Base::TestUpdateStreamsInRemoteContent();
3430}
3431
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003432TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433 Base::TestChangeStreamParamsInContent();
3434}
3435
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003436TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 Base::TestPlayoutAndSendingStates();
3438}
3439
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003440TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 Base::TestMediaContentDirection();
3442}
3443
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003444TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445 Base::TestCallSetup();
3446}
3447
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003448TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003449 Base::TestCallTeardownRtcpMux();
3450}
3451
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003452TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453 Base::TestOnReadyToSend();
3454}
3455
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003456TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 Base::TestOnReadyToSendWithRtcpMux();
3458}
3459
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003460TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461 Base::SendRtpToRtp();
3462}
3463
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003464TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 Base::SendNoRtcpToNoRtcp();
3466}
3467
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003468TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469 Base::SendNoRtcpToRtcp();
3470}
3471
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003472TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 Base::SendRtcpToNoRtcp();
3474}
3475
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003476TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477 Base::SendRtcpToRtcp();
3478}
3479
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003480TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481 Base::SendRtcpMuxToRtcp();
3482}
3483
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003484TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485 Base::SendRtcpMuxToRtcpMux();
3486}
3487
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003488TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489 Base::SendEarlyRtcpMuxToRtcp();
3490}
3491
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003492TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 Base::SendEarlyRtcpMuxToRtcpMux();
3494}
3495
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003496TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 Base::SendSrtpToSrtp();
3498}
3499
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003500TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 Base::SendSrtpToSrtp();
3502}
3503
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003504TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3506}
3507
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003508TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509 Base::SendRtpToRtpOnThread();
3510}
3511
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003512TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513 Base::SendSrtpToSrtpOnThread();
3514}
3515
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003516TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517 Base::SendWithWritabilityLoss();
3518}
3519
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003520TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521 Base::TestMediaMonitor();
3522}
3523
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003524TEST_F(DataChannelSingleThreadTest, TestSendData) {
3525 CreateChannels(0, 0);
3526 EXPECT_TRUE(SendInitiate());
3527 EXPECT_TRUE(SendAccept());
3528
3529 cricket::SendDataParams params;
3530 params.ssrc = 42;
3531 unsigned char data[] = {'f', 'o', 'o'};
3532 rtc::CopyOnWriteBuffer payload(data, 3);
3533 cricket::SendDataResult result;
3534 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3535 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3536 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3537}
3538
3539TEST_F(DataChannelDoubleThreadTest, TestInit) {
3540 Base::TestInit();
3541 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3542}
3543
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003544TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3545 Base::TestDeinit();
3546}
3547
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003548TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3549 Base::TestSetContents();
3550}
3551
3552TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3553 Base::TestSetContentsNullOffer();
3554}
3555
3556TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3557 Base::TestSetContentsRtcpMux();
3558}
3559
3560TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3561 Base::TestSetRemoteContentUpdate();
3562}
3563
3564TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3565 Base::TestStreams();
3566}
3567
3568TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3569 Base::TestUpdateStreamsInLocalContent();
3570}
3571
3572TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3573 Base::TestUpdateStreamsInRemoteContent();
3574}
3575
3576TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3577 Base::TestChangeStreamParamsInContent();
3578}
3579
3580TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3581 Base::TestPlayoutAndSendingStates();
3582}
3583
3584TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3585 Base::TestMediaContentDirection();
3586}
3587
3588TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3589 Base::TestCallSetup();
3590}
3591
3592TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3593 Base::TestCallTeardownRtcpMux();
3594}
3595
3596TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3597 Base::TestOnReadyToSend();
3598}
3599
3600TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3601 Base::TestOnReadyToSendWithRtcpMux();
3602}
3603
3604TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3605 Base::SendRtpToRtp();
3606}
3607
3608TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3609 Base::SendNoRtcpToNoRtcp();
3610}
3611
3612TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3613 Base::SendNoRtcpToRtcp();
3614}
3615
3616TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3617 Base::SendRtcpToNoRtcp();
3618}
3619
3620TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3621 Base::SendRtcpToRtcp();
3622}
3623
3624TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3625 Base::SendRtcpMuxToRtcp();
3626}
3627
3628TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3629 Base::SendRtcpMuxToRtcpMux();
3630}
3631
3632TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3633 Base::SendEarlyRtcpMuxToRtcp();
3634}
3635
3636TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3637 Base::SendEarlyRtcpMuxToRtcpMux();
3638}
3639
3640TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3641 Base::SendSrtpToSrtp();
3642}
3643
3644TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3645 Base::SendSrtpToSrtp();
3646}
3647
3648TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3649 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3650}
3651
3652TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3653 Base::SendRtpToRtpOnThread();
3654}
3655
3656TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3657 Base::SendSrtpToSrtpOnThread();
3658}
3659
3660TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3661 Base::SendWithWritabilityLoss();
3662}
3663
3664TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3665 Base::TestMediaMonitor();
3666}
3667
3668TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003669 CreateChannels(0, 0);
3670 EXPECT_TRUE(SendInitiate());
3671 EXPECT_TRUE(SendAccept());
3672
3673 cricket::SendDataParams params;
3674 params.ssrc = 42;
3675 unsigned char data[] = {
3676 'f', 'o', 'o'
3677 };
jbaucheec21bd2016-03-20 06:15:43 -07003678 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003679 cricket::SendDataResult result;
3680 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3681 EXPECT_EQ(params.ssrc,
3682 media_channel1_->last_sent_data_params().ssrc);
3683 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3684}
3685
3686// TODO(pthatcher): TestSetReceiver?