blob: 7b30547a7e241a86c64aa1e3fc01ba9e5ca0f332 [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
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001865 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001866 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001867 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001869
1870 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001871 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, true); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001872 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 EXPECT_TRUE(media_channel1_->ready_to_send());
1874
1875 // rtcp channel becomes not ready to send will be propagated to mediachannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001876 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001877 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(true, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001878 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001880
1881 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001882 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(true, true); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001883 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 EXPECT_TRUE(media_channel1_->ready_to_send());
1885 }
1886
1887 void TestOnReadyToSendWithRtcpMux() {
1888 CreateChannels(RTCP, RTCP);
1889 typename T::Content content;
1890 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1891 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1892 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001893 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1894 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1896 TransportChannel* rtp = channel1_->transport_channel();
1897 EXPECT_FALSE(media_channel1_->ready_to_send());
1898 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1899 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001900 network_thread_->Invoke<void>(RTC_FROM_HERE,
1901 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001902 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001903 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001904
1905 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001906 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001907 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 EXPECT_FALSE(media_channel1_->ready_to_send());
1909 }
1910
skvladdc1c62c2016-03-16 19:07:43 -07001911 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1912 typename T::Content content;
1913 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1914 content.set_bandwidth(remote_limit);
1915 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1916 }
1917
1918 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1919 webrtc::RtpParameters parameters;
1920 webrtc::RtpEncodingParameters encoding;
1921 encoding.max_bitrate_bps = limit;
1922 parameters.encodings.push_back(encoding);
1923 return parameters;
1924 }
1925
1926 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1927 int expected_bitrate) {
1928 EXPECT_EQ(1UL, parameters.encodings.size());
1929 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1930 }
1931
1932 void DefaultMaxBitrateIsUnlimited() {
1933 CreateChannels(0, 0);
1934 EXPECT_TRUE(
1935 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1936 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001937 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001938 }
1939
1940 void CanChangeMaxBitrate() {
1941 CreateChannels(0, 0);
1942 EXPECT_TRUE(
1943 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1944
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001945 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1946 kSsrc1, BitrateLimitedParameters(1000)));
1947 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1948 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001949 EXPECT_EQ(-1, media_channel1_->max_bps());
1950
1951 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001952 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1953 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1954 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001955 EXPECT_EQ(-1, media_channel1_->max_bps());
1956 }
1957
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001959 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1960 static void ProcessThreadQueue(rtc::Thread* thread) {
1961 RTC_DCHECK(thread->IsCurrent());
1962 while (!thread->empty()) {
1963 thread->ProcessMessages(0);
1964 }
1965 }
1966 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1967 // |threads| and current thread post packets to network thread.
1968 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001969 thread->Invoke<void>(RTC_FROM_HERE,
1970 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001971 }
1972 ProcessThreadQueue(rtc::Thread::Current());
1973 // Network thread move them around and post back to worker = current thread.
1974 if (!network_thread_->IsCurrent()) {
1975 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001976 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001977 }
1978 // Worker thread = current Thread process received messages.
1979 ProcessThreadQueue(rtc::Thread::Current());
1980 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001981 // TODO(pbos): Remove playout from all media channels and let renderers mute
1982 // themselves.
1983 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001984 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1985 rtc::Thread* network_thread_;
1986 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1987 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 cricket::FakeMediaEngine media_engine_;
1989 // The media channels are owned by the voice channel objects below.
1990 typename T::MediaChannel* media_channel1_;
1991 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001992 std::unique_ptr<typename T::Channel> channel1_;
1993 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 typename T::Content local_media_content1_;
1995 typename T::Content local_media_content2_;
1996 typename T::Content remote_media_content1_;
1997 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001999 rtc::Buffer rtp_packet_;
2000 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 int media_info_callbacks1_;
2002 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07002003 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004};
2005
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006template<>
2007void ChannelTest<VoiceTraits>::CreateContent(
2008 int flags,
2009 const cricket::AudioCodec& audio_codec,
2010 const cricket::VideoCodec& video_codec,
2011 cricket::AudioContentDescription* audio) {
2012 audio->AddCodec(audio_codec);
2013 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
2014 if (flags & SECURE) {
2015 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002016 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2017 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018 }
2019}
2020
2021template<>
2022void ChannelTest<VoiceTraits>::CopyContent(
2023 const cricket::AudioContentDescription& source,
2024 cricket::AudioContentDescription* audio) {
2025 *audio = source;
2026}
2027
2028template<>
2029bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2030 const cricket::AudioCodec& c2) {
2031 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2032 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2033}
2034
Peter Boström0c4e06b2015-10-07 12:23:21 +02002035template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002037 uint32_t ssrc,
2038 int flags,
2039 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 audio->AddLegacyStream(ssrc);
2041}
2042
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002043class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 public:
solenberg1dd98f32015-09-10 01:57:14 -07002045 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002046 VoiceChannelSingleThreadTest()
2047 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2048};
2049
2050class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2051 public:
2052 typedef ChannelTest<VoiceTraits> Base;
2053 VoiceChannelDoubleThreadTest()
2054 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055};
2056
2057// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002058template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002060 rtc::Thread* worker_thread,
2061 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002062 cricket::MediaEngineInterface* engine,
2063 cricket::FakeVideoMediaChannel* ch,
2064 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002065 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002066 cricket::VideoChannel* channel =
2067 new cricket::VideoChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07002068 transport_controller, cricket::CN_VIDEO,
2069 (flags & RTCP) != 0);
2070 rtc::CryptoOptions crypto_options;
2071 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2072 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07002073 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 delete channel;
2075 channel = NULL;
2076 }
2077 return channel;
2078}
2079
2080// override to add 0 parameter
2081template<>
2082bool ChannelTest<VideoTraits>::AddStream1(int id) {
2083 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2084}
2085
2086template<>
2087void ChannelTest<VideoTraits>::CreateContent(
2088 int flags,
2089 const cricket::AudioCodec& audio_codec,
2090 const cricket::VideoCodec& video_codec,
2091 cricket::VideoContentDescription* video) {
2092 video->AddCodec(video_codec);
2093 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2094 if (flags & SECURE) {
2095 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002096 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2097 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 }
2099}
2100
2101template<>
2102void ChannelTest<VideoTraits>::CopyContent(
2103 const cricket::VideoContentDescription& source,
2104 cricket::VideoContentDescription* video) {
2105 *video = source;
2106}
2107
2108template<>
2109bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2110 const cricket::VideoCodec& c2) {
2111 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2112 c1.framerate == c2.framerate;
2113}
2114
Peter Boström0c4e06b2015-10-07 12:23:21 +02002115template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002117 uint32_t ssrc,
2118 int flags,
2119 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 video->AddLegacyStream(ssrc);
2121}
2122
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002123class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 public:
solenberg1dd98f32015-09-10 01:57:14 -07002125 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002126 VideoChannelSingleThreadTest()
2127 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128};
2129
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002130class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2131 public:
2132 typedef ChannelTest<VideoTraits> Base;
2133 VideoChannelDoubleThreadTest()
2134 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2135};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002137// VoiceChannelSingleThreadTest
2138TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 Base::TestInit();
2140 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2141 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2142}
2143
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002144TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2145 Base::TestDeinit();
2146}
2147
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002148TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 Base::TestSetContents();
2150}
2151
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002152TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 Base::TestSetContentsNullOffer();
2154}
2155
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002156TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 Base::TestSetContentsRtcpMux();
2158}
2159
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002160TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 Base::TestSetContentsRtcpMux();
2162}
2163
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002164TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 Base::TestSetRemoteContentUpdate();
2166}
2167
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002168TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 Base::TestStreams();
2170}
2171
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002172TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 Base::TestUpdateStreamsInLocalContent();
2174}
2175
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002176TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 Base::TestUpdateStreamsInRemoteContent();
2178}
2179
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002180TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 Base::TestChangeStreamParamsInContent();
2182}
2183
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002184TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 Base::TestPlayoutAndSendingStates();
2186}
2187
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002188TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002189 CreateChannels(0, 0);
2190 // Test that we can Mute the default channel even though the sending SSRC
2191 // is unknown.
2192 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002193 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002194 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2195 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002196 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2197
2198 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002199 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002200
2201 SendInitiate();
2202 // After the local session description has been set, we can mute a stream
2203 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002204 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002205 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2206 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002207 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208}
2209
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002210TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 Base::TestMediaContentDirection();
2212}
2213
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002214TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002215 Base::TestNetworkRouteChanges();
2216}
2217
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002218TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 Base::TestCallSetup();
2220}
2221
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002222TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 Base::TestCallTeardownRtcpMux();
2224}
2225
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002226TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 Base::SendRtpToRtp();
2228}
2229
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002230TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 Base::SendNoRtcpToNoRtcp();
2232}
2233
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002234TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 Base::SendNoRtcpToRtcp();
2236}
2237
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002238TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 Base::SendRtcpToNoRtcp();
2240}
2241
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002242TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 Base::SendRtcpToRtcp();
2244}
2245
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002246TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 Base::SendRtcpMuxToRtcp();
2248}
2249
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002250TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 Base::SendRtcpMuxToRtcpMux();
2252}
2253
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002254TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002255 Base::SendRequireRtcpMuxToRtcpMux();
2256}
2257
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002258TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002259 Base::SendRtcpMuxToRequireRtcpMux();
2260}
2261
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002262TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002263 Base::SendRequireRtcpMuxToRequireRtcpMux();
2264}
2265
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002266TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002267 Base::SendRequireRtcpMuxToNoRtcpMux();
2268}
2269
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002270TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 Base::SendEarlyRtcpMuxToRtcp();
2272}
2273
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002274TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 Base::SendEarlyRtcpMuxToRtcpMux();
2276}
2277
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002278TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2280}
2281
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002282TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 Base::SendSrtpToSrtp();
2284}
2285
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002286TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2288}
2289
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002290TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2292 Base::SendSrtpToSrtp(DTLS, 0);
2293}
2294
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002295TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2297 Base::SendSrtpToSrtp(DTLS, DTLS);
2298}
2299
jbauchcb560652016-08-04 05:20:32 -07002300TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2301 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2302 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2303}
2304
2305TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2306 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2307 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2308}
2309
2310TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2311 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2312 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2313}
2314
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002315TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2317 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2318}
2319
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002320TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2322}
2323
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002324TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 Base::SendRtpToRtpOnThread();
2326}
2327
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002328TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 Base::SendSrtpToSrtpOnThread();
2330}
2331
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002332TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 Base::SendWithWritabilityLoss();
2334}
2335
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002336TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 Base::TestMediaMonitor();
2338}
2339
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002341TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 CreateChannels(0, 0);
2343 EXPECT_TRUE(SendInitiate());
2344 EXPECT_TRUE(SendAccept());
2345 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2346
solenberg1d63dd02015-12-02 12:35:09 -08002347 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2348 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2349 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002351 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002353 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002354 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002355 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002356 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002357 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358}
2359
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002360TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 Base::TestSetContentFailure();
2362}
2363
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002364TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 Base::TestSendTwoOffers();
2366}
2367
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002368TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 Base::TestReceiveTwoOffers();
2370}
2371
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002372TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 Base::TestSendPrAnswer();
2374}
2375
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002376TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 Base::TestReceivePrAnswer();
2378}
2379
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002380TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 Base::TestFlushRtcp();
2382}
2383
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002384TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002385 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386}
2387
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002388TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 Base::TestOnReadyToSend();
2390}
2391
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002392TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 Base::TestOnReadyToSendWithRtcpMux();
2394}
2395
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002397TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 CreateChannels(RTCP, RTCP);
2399 EXPECT_TRUE(SendInitiate());
2400 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002401 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402
solenberg4bac9c52015-10-09 02:32:53 -07002403 // Default is (1.0).
2404 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2405 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002407 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408
solenberg4bac9c52015-10-09 02:32:53 -07002409 // Set scale to (1.5).
2410 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2411 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2412 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413
solenberg4bac9c52015-10-09 02:32:53 -07002414 // Set scale to (0).
2415 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2416 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2417 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418}
2419
2420// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002421TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422 CreateChannels(RTCP, RTCP);
2423 EXPECT_TRUE(SendInitiate());
2424 EXPECT_TRUE(SendAccept());
2425 EXPECT_TRUE(AddStream1(1));
2426 EXPECT_TRUE(AddStream1(2));
2427
solenberg4bac9c52015-10-09 02:32:53 -07002428 double volume;
2429 // Default is (1.0).
2430 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2431 EXPECT_DOUBLE_EQ(1.0, volume);
2432 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2433 EXPECT_DOUBLE_EQ(1.0, volume);
2434 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2435 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002437 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438
solenberg4bac9c52015-10-09 02:32:53 -07002439 // Set scale to (1.5) for ssrc = 1.
2440 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2441 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2442 EXPECT_DOUBLE_EQ(1.5, volume);
2443 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2444 EXPECT_DOUBLE_EQ(1.0, volume);
2445 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2446 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447
solenberg4bac9c52015-10-09 02:32:53 -07002448 // Set scale to (0) for all ssrcs.
2449 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2450 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2451 EXPECT_DOUBLE_EQ(0.0, volume);
2452 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2453 EXPECT_DOUBLE_EQ(0.0, volume);
2454 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2455 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456}
2457
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002458TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002459 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460}
2461
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002462TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002463 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002464}
2465
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002466TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002467 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002468}
2469
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002470TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002471 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472}
2473
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002474TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002475 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002476}
2477
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002478TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002479 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002480}
2481
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002482// VoiceChannelDoubleThreadTest
2483TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002485 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2486 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487}
2488
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002489TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2490 Base::TestDeinit();
2491}
2492
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002493TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 Base::TestSetContents();
2495}
2496
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002497TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 Base::TestSetContentsNullOffer();
2499}
2500
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002501TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 Base::TestSetContentsRtcpMux();
2503}
2504
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002505TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506 Base::TestSetContentsRtcpMux();
2507}
2508
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002509TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 Base::TestSetRemoteContentUpdate();
2511}
2512
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002513TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 Base::TestStreams();
2515}
2516
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002517TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 Base::TestUpdateStreamsInLocalContent();
2519}
2520
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002521TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 Base::TestUpdateStreamsInRemoteContent();
2523}
2524
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002525TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526 Base::TestChangeStreamParamsInContent();
2527}
2528
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002529TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 Base::TestPlayoutAndSendingStates();
2531}
2532
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002533TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2534 CreateChannels(0, 0);
2535 // Test that we can Mute the default channel even though the sending SSRC
2536 // is unknown.
2537 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2538 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2539 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2540 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2541 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2542
2543 // Test that we can not mute an unknown SSRC.
2544 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2545
2546 SendInitiate();
2547 // After the local session description has been set, we can mute a stream
2548 // with its SSRC.
2549 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2550 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2551 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2552 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2553}
2554
2555TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2556 Base::TestMediaContentDirection();
2557}
2558
2559TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2560 Base::TestNetworkRouteChanges();
2561}
2562
2563TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2564 Base::TestCallSetup();
2565}
2566
2567TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2568 Base::TestCallTeardownRtcpMux();
2569}
2570
2571TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2572 Base::SendRtpToRtp();
2573}
2574
2575TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2576 Base::SendNoRtcpToNoRtcp();
2577}
2578
2579TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2580 Base::SendNoRtcpToRtcp();
2581}
2582
2583TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2584 Base::SendRtcpToNoRtcp();
2585}
2586
2587TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2588 Base::SendRtcpToRtcp();
2589}
2590
2591TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2592 Base::SendRtcpMuxToRtcp();
2593}
2594
2595TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2596 Base::SendRtcpMuxToRtcpMux();
2597}
2598
2599TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2600 Base::SendRequireRtcpMuxToRtcpMux();
2601}
2602
2603TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2604 Base::SendRtcpMuxToRequireRtcpMux();
2605}
2606
2607TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2608 Base::SendRequireRtcpMuxToRequireRtcpMux();
2609}
2610
2611TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2612 Base::SendRequireRtcpMuxToNoRtcpMux();
2613}
2614
2615TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2616 Base::SendEarlyRtcpMuxToRtcp();
2617}
2618
2619TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2620 Base::SendEarlyRtcpMuxToRtcpMux();
2621}
2622
2623TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2624 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2625}
2626
2627TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2628 Base::SendSrtpToSrtp();
2629}
2630
2631TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2632 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2633}
2634
2635TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2636 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2637 Base::SendSrtpToSrtp(DTLS, 0);
2638}
2639
2640TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2641 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2642 Base::SendSrtpToSrtp(DTLS, DTLS);
2643}
2644
jbauchcb560652016-08-04 05:20:32 -07002645TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2646 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2647 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2648}
2649
2650TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2651 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2652 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2656 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2657 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2658}
2659
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002660TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2661 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2662 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2663}
2664
2665TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2666 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2667}
2668
2669TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2670 Base::SendRtpToRtpOnThread();
2671}
2672
2673TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2674 Base::SendSrtpToSrtpOnThread();
2675}
2676
2677TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2678 Base::SendWithWritabilityLoss();
2679}
2680
2681TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2682 Base::TestMediaMonitor();
2683}
2684
2685// Test that InsertDtmf properly forwards to the media channel.
2686TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2687 CreateChannels(0, 0);
2688 EXPECT_TRUE(SendInitiate());
2689 EXPECT_TRUE(SendAccept());
2690 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2691
2692 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2693 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2694 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2695
2696 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2697 EXPECT_TRUE(
2698 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2699 EXPECT_TRUE(
2700 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2701 EXPECT_TRUE(
2702 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2703}
2704
2705TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2706 Base::TestSetContentFailure();
2707}
2708
2709TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2710 Base::TestSendTwoOffers();
2711}
2712
2713TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2714 Base::TestReceiveTwoOffers();
2715}
2716
2717TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2718 Base::TestSendPrAnswer();
2719}
2720
2721TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2722 Base::TestReceivePrAnswer();
2723}
2724
2725TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2726 Base::TestFlushRtcp();
2727}
2728
2729TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2730 Base::TestSrtpError(kAudioPts[0]);
2731}
2732
2733TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2734 Base::TestOnReadyToSend();
2735}
2736
2737TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2738 Base::TestOnReadyToSendWithRtcpMux();
2739}
2740
2741// Test that we can scale the output volume properly for 1:1 calls.
2742TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2743 CreateChannels(RTCP, RTCP);
2744 EXPECT_TRUE(SendInitiate());
2745 EXPECT_TRUE(SendAccept());
2746 double volume;
2747
2748 // Default is (1.0).
2749 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2750 EXPECT_DOUBLE_EQ(1.0, volume);
2751 // invalid ssrc.
2752 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2753
2754 // Set scale to (1.5).
2755 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2756 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2757 EXPECT_DOUBLE_EQ(1.5, volume);
2758
2759 // Set scale to (0).
2760 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2761 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2762 EXPECT_DOUBLE_EQ(0.0, volume);
2763}
2764
2765// Test that we can scale the output volume properly for multiway calls.
2766TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2767 CreateChannels(RTCP, RTCP);
2768 EXPECT_TRUE(SendInitiate());
2769 EXPECT_TRUE(SendAccept());
2770 EXPECT_TRUE(AddStream1(1));
2771 EXPECT_TRUE(AddStream1(2));
2772
2773 double volume;
2774 // Default is (1.0).
2775 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2776 EXPECT_DOUBLE_EQ(1.0, volume);
2777 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2778 EXPECT_DOUBLE_EQ(1.0, volume);
2779 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2780 EXPECT_DOUBLE_EQ(1.0, volume);
2781 // invalid ssrc.
2782 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2783
2784 // Set scale to (1.5) for ssrc = 1.
2785 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2786 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2787 EXPECT_DOUBLE_EQ(1.5, volume);
2788 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2789 EXPECT_DOUBLE_EQ(1.0, volume);
2790 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2791 EXPECT_DOUBLE_EQ(1.0, volume);
2792
2793 // Set scale to (0) for all ssrcs.
2794 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2795 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2796 EXPECT_DOUBLE_EQ(0.0, volume);
2797 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2798 EXPECT_DOUBLE_EQ(0.0, volume);
2799 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2800 EXPECT_DOUBLE_EQ(0.0, volume);
2801}
2802
2803TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2804 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2805}
2806
2807TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2808 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2809}
2810
2811TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2812 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2813}
2814
2815TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2816 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2817}
2818
2819TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2820 Base::DefaultMaxBitrateIsUnlimited();
2821}
2822
2823TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2824 Base::CanChangeMaxBitrate();
2825}
2826
2827// VideoChannelSingleThreadTest
2828TEST_F(VideoChannelSingleThreadTest, TestInit) {
2829 Base::TestInit();
2830}
2831
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002832TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2833 Base::TestDeinit();
2834}
2835
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002836TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2837 Base::TestSetContents();
2838}
2839
2840TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2841 Base::TestSetContentsNullOffer();
2842}
2843
2844TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2845 Base::TestSetContentsRtcpMux();
2846}
2847
2848TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2849 Base::TestSetContentsRtcpMux();
2850}
2851
2852TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2853 Base::TestSetRemoteContentUpdate();
2854}
2855
2856TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2857 Base::TestStreams();
2858}
2859
2860TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2861 Base::TestUpdateStreamsInLocalContent();
2862}
2863
2864TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2865 Base::TestUpdateStreamsInRemoteContent();
2866}
2867
2868TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2869 Base::TestChangeStreamParamsInContent();
2870}
2871
2872TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2873 Base::TestPlayoutAndSendingStates();
2874}
2875
2876TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002877 CreateChannels(0, 0);
2878 // Test that we can Mute the default channel even though the sending SSRC
2879 // is unknown.
2880 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002881 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002882 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002883 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002884 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2885 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002886 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002887 SendInitiate();
2888 // After the local session description has been set, we can mute a stream
2889 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002890 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002891 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002892 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002893 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894}
2895
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002896TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897 Base::TestMediaContentDirection();
2898}
2899
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002900TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002901 Base::TestNetworkRouteChanges();
2902}
2903
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002904TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 Base::TestCallSetup();
2906}
2907
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002908TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 Base::TestCallTeardownRtcpMux();
2910}
2911
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002912TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002913 Base::SendRtpToRtp();
2914}
2915
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002916TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002917 Base::SendNoRtcpToNoRtcp();
2918}
2919
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002920TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002921 Base::SendNoRtcpToRtcp();
2922}
2923
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002924TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002925 Base::SendRtcpToNoRtcp();
2926}
2927
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002928TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002929 Base::SendRtcpToRtcp();
2930}
2931
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002932TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002933 Base::SendRtcpMuxToRtcp();
2934}
2935
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002936TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002937 Base::SendRtcpMuxToRtcpMux();
2938}
2939
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002940TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002941 Base::SendRequireRtcpMuxToRtcpMux();
2942}
2943
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002944TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002945 Base::SendRtcpMuxToRequireRtcpMux();
2946}
2947
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002948TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002949 Base::SendRequireRtcpMuxToRequireRtcpMux();
2950}
2951
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002952TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002953 Base::SendRequireRtcpMuxToNoRtcpMux();
2954}
2955
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002956TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002957 Base::SendEarlyRtcpMuxToRtcp();
2958}
2959
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002960TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002961 Base::SendEarlyRtcpMuxToRtcpMux();
2962}
2963
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002964TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002965 Base::SendSrtpToSrtp();
2966}
2967
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002968TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002969 Base::SendSrtpToSrtp();
2970}
2971
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002972TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2974 Base::SendSrtpToSrtp(DTLS, 0);
2975}
2976
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002977TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2979 Base::SendSrtpToSrtp(DTLS, DTLS);
2980}
2981
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002982TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2984 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2985}
2986
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002987TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2989}
2990
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002991TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002992 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2993}
2994
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002995TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 Base::SendRtpToRtpOnThread();
2997}
2998
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002999TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 Base::SendSrtpToSrtpOnThread();
3001}
3002
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003003TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003004 Base::SendWithWritabilityLoss();
3005}
3006
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003007TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003008 Base::TestMediaMonitor();
3009}
3010
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003011TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003012 Base::TestSetContentFailure();
3013}
3014
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003015TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016 Base::TestSendTwoOffers();
3017}
3018
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003019TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003020 Base::TestReceiveTwoOffers();
3021}
3022
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003023TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003024 Base::TestSendPrAnswer();
3025}
3026
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003027TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003028 Base::TestReceivePrAnswer();
3029}
3030
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003031TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003032 Base::TestFlushRtcp();
3033}
3034
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003035TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08003036 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003037}
3038
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003039TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003040 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003041}
3042
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003043TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08003044 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003045}
3046
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003047TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003048 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003049}
3050
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003051TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003052 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003053}
3054
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003055TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003056 Base::TestOnReadyToSend();
3057}
3058
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003059TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003060 Base::TestOnReadyToSendWithRtcpMux();
3061}
3062
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003063TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003064 Base::DefaultMaxBitrateIsUnlimited();
3065}
3066
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003067TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003068 Base::CanChangeMaxBitrate();
3069}
3070
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003071// VideoChannelDoubleThreadTest
3072TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3073 Base::TestInit();
3074}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003076TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3077 Base::TestDeinit();
3078}
3079
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003080TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3081 Base::TestSetContents();
3082}
3083
3084TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3085 Base::TestSetContentsNullOffer();
3086}
3087
3088TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3089 Base::TestSetContentsRtcpMux();
3090}
3091
3092TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3093 Base::TestSetContentsRtcpMux();
3094}
3095
3096TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3097 Base::TestSetRemoteContentUpdate();
3098}
3099
3100TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3101 Base::TestStreams();
3102}
3103
3104TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3105 Base::TestUpdateStreamsInLocalContent();
3106}
3107
3108TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3109 Base::TestUpdateStreamsInRemoteContent();
3110}
3111
3112TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3113 Base::TestChangeStreamParamsInContent();
3114}
3115
3116TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3117 Base::TestPlayoutAndSendingStates();
3118}
3119
3120TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3121 CreateChannels(0, 0);
3122 // Test that we can Mute the default channel even though the sending SSRC
3123 // is unknown.
3124 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003125 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003126 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003127 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003128 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3129 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003130 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003131 SendInitiate();
3132 // After the local session description has been set, we can mute a stream
3133 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003134 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003135 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003136 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003137 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3138}
3139
3140TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3141 Base::TestMediaContentDirection();
3142}
3143
3144TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3145 Base::TestNetworkRouteChanges();
3146}
3147
3148TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3149 Base::TestCallSetup();
3150}
3151
3152TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3153 Base::TestCallTeardownRtcpMux();
3154}
3155
3156TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3157 Base::SendRtpToRtp();
3158}
3159
3160TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3161 Base::SendNoRtcpToNoRtcp();
3162}
3163
3164TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3165 Base::SendNoRtcpToRtcp();
3166}
3167
3168TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3169 Base::SendRtcpToNoRtcp();
3170}
3171
3172TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3173 Base::SendRtcpToRtcp();
3174}
3175
3176TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3177 Base::SendRtcpMuxToRtcp();
3178}
3179
3180TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3181 Base::SendRtcpMuxToRtcpMux();
3182}
3183
3184TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3185 Base::SendRequireRtcpMuxToRtcpMux();
3186}
3187
3188TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3189 Base::SendRtcpMuxToRequireRtcpMux();
3190}
3191
3192TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3193 Base::SendRequireRtcpMuxToRequireRtcpMux();
3194}
3195
3196TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3197 Base::SendRequireRtcpMuxToNoRtcpMux();
3198}
3199
3200TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3201 Base::SendEarlyRtcpMuxToRtcp();
3202}
3203
3204TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3205 Base::SendEarlyRtcpMuxToRtcpMux();
3206}
3207
3208TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3209 Base::SendSrtpToSrtp();
3210}
3211
3212TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3213 Base::SendSrtpToSrtp();
3214}
3215
3216TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3217 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3218 Base::SendSrtpToSrtp(DTLS, 0);
3219}
3220
3221TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3222 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3223 Base::SendSrtpToSrtp(DTLS, DTLS);
3224}
3225
3226TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3227 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3228 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3229}
3230
3231TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3232 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3233}
3234
3235TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3236 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3237}
3238
3239TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3240 Base::SendRtpToRtpOnThread();
3241}
3242
3243TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3244 Base::SendSrtpToSrtpOnThread();
3245}
3246
3247TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3248 Base::SendWithWritabilityLoss();
3249}
3250
3251TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3252 Base::TestMediaMonitor();
3253}
3254
3255TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3256 Base::TestSetContentFailure();
3257}
3258
3259TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3260 Base::TestSendTwoOffers();
3261}
3262
3263TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3264 Base::TestReceiveTwoOffers();
3265}
3266
3267TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3268 Base::TestSendPrAnswer();
3269}
3270
3271TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3272 Base::TestReceivePrAnswer();
3273}
3274
3275TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3276 Base::TestFlushRtcp();
3277}
3278
3279TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3280 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3281}
3282
3283TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3284 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3285}
3286
3287TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3288 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3289}
3290
3291TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3292 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3293}
3294
3295TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3296 Base::TestSrtpError(kVideoPts[0]);
3297}
3298
3299TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3300 Base::TestOnReadyToSend();
3301}
3302
3303TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3304 Base::TestOnReadyToSendWithRtcpMux();
3305}
3306
3307TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3308 Base::DefaultMaxBitrateIsUnlimited();
3309}
3310
3311TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3312 Base::CanChangeMaxBitrate();
3313}
3314
3315// DataChannelSingleThreadTest
3316class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003318 typedef ChannelTest<DataTraits> Base;
3319 DataChannelSingleThreadTest()
3320 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3321};
3322
3323// DataChannelDoubleThreadTest
3324class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3325 public:
3326 typedef ChannelTest<DataTraits> Base;
3327 DataChannelDoubleThreadTest()
3328 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329};
3330
3331// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003332template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003333cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003334 rtc::Thread* worker_thread,
3335 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003336 cricket::MediaEngineInterface* engine,
3337 cricket::FakeDataMediaChannel* ch,
3338 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003339 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003340 cricket::DataChannel* channel =
3341 new cricket::DataChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07003342 transport_controller, cricket::CN_DATA,
3343 (flags & RTCP) != 0);
3344 rtc::CryptoOptions crypto_options;
3345 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3346 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07003347 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348 delete channel;
3349 channel = NULL;
3350 }
3351 return channel;
3352}
3353
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003354template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003355void ChannelTest<DataTraits>::CreateContent(
3356 int flags,
3357 const cricket::AudioCodec& audio_codec,
3358 const cricket::VideoCodec& video_codec,
3359 cricket::DataContentDescription* data) {
3360 data->AddCodec(kGoogleDataCodec);
3361 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3362 if (flags & SECURE) {
3363 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003364 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3365 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003366 }
3367}
3368
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003369template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370void ChannelTest<DataTraits>::CopyContent(
3371 const cricket::DataContentDescription& source,
3372 cricket::DataContentDescription* data) {
3373 *data = source;
3374}
3375
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003376template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3378 const cricket::DataCodec& c2) {
3379 return c1.name == c2.name;
3380}
3381
Peter Boström0c4e06b2015-10-07 12:23:21 +02003382template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003383void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003384 uint32_t ssrc,
3385 int flags,
3386 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387 data->AddLegacyStream(ssrc);
3388}
3389
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003390TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 Base::TestInit();
3392 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3393}
3394
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003395TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3396 Base::TestDeinit();
3397}
3398
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003399TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400 Base::TestSetContents();
3401}
3402
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003403TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 Base::TestSetContentsNullOffer();
3405}
3406
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003407TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408 Base::TestSetContentsRtcpMux();
3409}
3410
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003411TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412 Base::TestSetRemoteContentUpdate();
3413}
3414
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003415TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 Base::TestStreams();
3417}
3418
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003419TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420 Base::TestUpdateStreamsInLocalContent();
3421}
3422
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003423TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 Base::TestUpdateStreamsInRemoteContent();
3425}
3426
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003427TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 Base::TestChangeStreamParamsInContent();
3429}
3430
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003431TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 Base::TestPlayoutAndSendingStates();
3433}
3434
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003435TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003436 Base::TestMediaContentDirection();
3437}
3438
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003439TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440 Base::TestCallSetup();
3441}
3442
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003443TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444 Base::TestCallTeardownRtcpMux();
3445}
3446
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003447TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448 Base::TestOnReadyToSend();
3449}
3450
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003451TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452 Base::TestOnReadyToSendWithRtcpMux();
3453}
3454
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003455TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456 Base::SendRtpToRtp();
3457}
3458
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003459TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 Base::SendNoRtcpToNoRtcp();
3461}
3462
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003463TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 Base::SendNoRtcpToRtcp();
3465}
3466
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003467TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468 Base::SendRtcpToNoRtcp();
3469}
3470
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003471TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003472 Base::SendRtcpToRtcp();
3473}
3474
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003475TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 Base::SendRtcpMuxToRtcp();
3477}
3478
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003479TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003480 Base::SendRtcpMuxToRtcpMux();
3481}
3482
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003483TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484 Base::SendEarlyRtcpMuxToRtcp();
3485}
3486
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003487TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 Base::SendEarlyRtcpMuxToRtcpMux();
3489}
3490
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003491TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492 Base::SendSrtpToSrtp();
3493}
3494
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003495TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003496 Base::SendSrtpToSrtp();
3497}
3498
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003499TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3501}
3502
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003503TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504 Base::SendRtpToRtpOnThread();
3505}
3506
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003507TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508 Base::SendSrtpToSrtpOnThread();
3509}
3510
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003511TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512 Base::SendWithWritabilityLoss();
3513}
3514
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003515TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516 Base::TestMediaMonitor();
3517}
3518
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003519TEST_F(DataChannelSingleThreadTest, TestSendData) {
3520 CreateChannels(0, 0);
3521 EXPECT_TRUE(SendInitiate());
3522 EXPECT_TRUE(SendAccept());
3523
3524 cricket::SendDataParams params;
3525 params.ssrc = 42;
3526 unsigned char data[] = {'f', 'o', 'o'};
3527 rtc::CopyOnWriteBuffer payload(data, 3);
3528 cricket::SendDataResult result;
3529 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3530 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3531 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3532}
3533
3534TEST_F(DataChannelDoubleThreadTest, TestInit) {
3535 Base::TestInit();
3536 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3537}
3538
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003539TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3540 Base::TestDeinit();
3541}
3542
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003543TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3544 Base::TestSetContents();
3545}
3546
3547TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3548 Base::TestSetContentsNullOffer();
3549}
3550
3551TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3552 Base::TestSetContentsRtcpMux();
3553}
3554
3555TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3556 Base::TestSetRemoteContentUpdate();
3557}
3558
3559TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3560 Base::TestStreams();
3561}
3562
3563TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3564 Base::TestUpdateStreamsInLocalContent();
3565}
3566
3567TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3568 Base::TestUpdateStreamsInRemoteContent();
3569}
3570
3571TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3572 Base::TestChangeStreamParamsInContent();
3573}
3574
3575TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3576 Base::TestPlayoutAndSendingStates();
3577}
3578
3579TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3580 Base::TestMediaContentDirection();
3581}
3582
3583TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3584 Base::TestCallSetup();
3585}
3586
3587TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3588 Base::TestCallTeardownRtcpMux();
3589}
3590
3591TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3592 Base::TestOnReadyToSend();
3593}
3594
3595TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3596 Base::TestOnReadyToSendWithRtcpMux();
3597}
3598
3599TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3600 Base::SendRtpToRtp();
3601}
3602
3603TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3604 Base::SendNoRtcpToNoRtcp();
3605}
3606
3607TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3608 Base::SendNoRtcpToRtcp();
3609}
3610
3611TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3612 Base::SendRtcpToNoRtcp();
3613}
3614
3615TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3616 Base::SendRtcpToRtcp();
3617}
3618
3619TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3620 Base::SendRtcpMuxToRtcp();
3621}
3622
3623TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3624 Base::SendRtcpMuxToRtcpMux();
3625}
3626
3627TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3628 Base::SendEarlyRtcpMuxToRtcp();
3629}
3630
3631TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3632 Base::SendEarlyRtcpMuxToRtcpMux();
3633}
3634
3635TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3636 Base::SendSrtpToSrtp();
3637}
3638
3639TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3640 Base::SendSrtpToSrtp();
3641}
3642
3643TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3644 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3645}
3646
3647TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3648 Base::SendRtpToRtpOnThread();
3649}
3650
3651TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3652 Base::SendSrtpToSrtpOnThread();
3653}
3654
3655TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3656 Base::SendWithWritabilityLoss();
3657}
3658
3659TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3660 Base::TestMediaMonitor();
3661}
3662
3663TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003664 CreateChannels(0, 0);
3665 EXPECT_TRUE(SendInitiate());
3666 EXPECT_TRUE(SendAccept());
3667
3668 cricket::SendDataParams params;
3669 params.ssrc = 42;
3670 unsigned char data[] = {
3671 'f', 'o', 'o'
3672 };
jbaucheec21bd2016-03-20 06:15:43 -07003673 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674 cricket::SendDataResult result;
3675 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3676 EXPECT_EQ(params.ssrc,
3677 media_channel1_->last_sent_data_params().ssrc);
3678 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3679}
3680
3681// TODO(pthatcher): TestSetReceiver?