blob: 0bea6dcad2ffd3cdfc6cebfa3bea112a806cf3f1 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2009 The WebRTC project authors. All Rights Reserved.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00009 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000010
kwiberg31022942016-03-11 14:18:21 -080011#include <memory>
12
Danil Chapovalov33b01f22016-05-11 19:55:27 +020013#include "webrtc/base/array_view.h"
14#include "webrtc/base/buffer.h"
Taylor Brandstetter88532892016-08-01 14:17:27 -070015#include "webrtc/base/fakeclock.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000016#include "webrtc/base/gunit.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000017#include "webrtc/base/logging.h"
jbauchcb560652016-08-04 05:20:32 -070018#include "webrtc/base/sslstreamadapter.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/fakemediaengine.h"
20#include "webrtc/media/base/fakertp.h"
kjellandera96e2d72016-02-04 23:52:28 -080021#include "webrtc/media/base/mediachannel.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010023#include "webrtc/p2p/base/faketransportcontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010024#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
26#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028 LOG(LS_INFO) << "Feature disabled... skipping"; \
29 return; \
30 }
31
32using cricket::CA_OFFER;
33using cricket::CA_PRANSWER;
34using cricket::CA_ANSWER;
35using cricket::CA_UPDATE;
36using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037using cricket::StreamParams;
38using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039
Danil Chapovalov33b01f22016-05-11 19:55:27 +020040namespace {
41const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
42const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
43const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
perkj26752742016-10-24 01:21:16 -070044const cricket::VideoCodec kH264Codec(97, "H264");
45const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
Danil Chapovalov33b01f22016-05-11 19:55:27 +020046const cricket::DataCodec kGoogleDataCodec(101, "google-data");
47const uint32_t kSsrc1 = 0x1111;
48const uint32_t kSsrc2 = 0x2222;
49const uint32_t kSsrc3 = 0x3333;
50const int kAudioPts[] = {0, 8};
51const int kVideoPts[] = {97, 99};
52enum class NetworkIsWorker { Yes, No };
53} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054
deadbeefcbecd352015-09-23 11:50:27 -070055template <class ChannelT,
56 class MediaChannelT,
57 class ContentT,
58 class CodecT,
59 class MediaInfoT,
60 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061class Traits {
62 public:
63 typedef ChannelT Channel;
64 typedef MediaChannelT MediaChannel;
65 typedef ContentT Content;
66 typedef CodecT Codec;
67 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020068 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069};
70
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071class VoiceTraits : public Traits<cricket::VoiceChannel,
72 cricket::FakeVoiceMediaChannel,
73 cricket::AudioContentDescription,
74 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020075 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070076 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
78class VideoTraits : public Traits<cricket::VideoChannel,
79 cricket::FakeVideoMediaChannel,
80 cricket::VideoContentDescription,
81 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020082 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070083 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084
85class DataTraits : public Traits<cricket::DataChannel,
86 cricket::FakeDataMediaChannel,
87 cricket::DataContentDescription,
88 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020089 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070090 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091
Danil Chapovalov33b01f22016-05-11 19:55:27 +020092// Base class for Voice/Video/DataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093template<class T>
94class ChannelTest : public testing::Test, public sigslot::has_slots<> {
95 public:
96 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
jbauchcb560652016-08-04 05:20:32 -070097 DTLS = 0x10, GCM_CIPHER = 0x20 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098
Peter Boström34fbfff2015-09-24 19:20:30 +020099 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200100 rtc::ArrayView<const uint8_t> rtp_data,
101 rtc::ArrayView<const uint8_t> rtcp_data,
102 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200103 : verify_playout_(verify_playout),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104 media_channel1_(NULL),
105 media_channel2_(NULL),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200106 rtp_packet_(rtp_data.data(), rtp_data.size()),
107 rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108 media_info_callbacks1_(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200109 media_info_callbacks2_() {
110 if (network_is_worker == NetworkIsWorker::Yes) {
111 network_thread_ = rtc::Thread::Current();
112 } else {
113 network_thread_keeper_ = rtc::Thread::Create();
114 network_thread_keeper_->SetName("Network", nullptr);
115 network_thread_keeper_->Start();
116 network_thread_ = network_thread_keeper_.get();
117 }
118 transport_controller1_.reset(new cricket::FakeTransportController(
119 network_thread_, cricket::ICEROLE_CONTROLLING));
120 transport_controller2_.reset(new cricket::FakeTransportController(
121 network_thread_, cricket::ICEROLE_CONTROLLED));
122 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200125 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
126 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200127 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200129 void CreateChannels(typename T::MediaChannel* ch1,
130 typename T::MediaChannel* ch2,
131 int flags1,
132 int flags2) {
133 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 media_channel1_ = ch1;
135 media_channel2_ = ch2;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200136 channel1_.reset(
137 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
jbauchcb560652016-08-04 05:20:32 -0700138 transport_controller1_.get(), flags1));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200139 channel2_.reset(
140 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
jbauchcb560652016-08-04 05:20:32 -0700141 transport_controller2_.get(), flags2));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200142 channel1_->SignalMediaMonitor.connect(this,
143 &ChannelTest<T>::OnMediaMonitor1);
144 channel2_->SignalMediaMonitor.connect(this,
145 &ChannelTest<T>::OnMediaMonitor2);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000146 if ((flags1 & DTLS) && (flags2 & DTLS)) {
147 flags1 = (flags1 & ~SECURE);
148 flags2 = (flags2 & ~SECURE);
149 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 CreateContent(flags1, kPcmuCodec, kH264Codec,
151 &local_media_content1_);
152 CreateContent(flags2, kPcmuCodec, kH264Codec,
153 &local_media_content2_);
154 CopyContent(local_media_content1_, &remote_media_content1_);
155 CopyContent(local_media_content2_, &remote_media_content2_);
156
157 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200158 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200159 transport_controller1_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700160 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800161 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 }
163 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200164 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200165 transport_controller2_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700166 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800167 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 }
169
170 // Add stream information (SSRC) to the local content but not to the remote
171 // content. This means that we per default know the SSRC of what we send but
172 // not what we receive.
173 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
174 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
175
176 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
177 if (flags1 & SSRC_MUX) {
178 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
179 }
180 if (flags2 & SSRC_MUX) {
181 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
182 }
183 }
deadbeefcbecd352015-09-23 11:50:27 -0700184 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200185 rtc::Thread* worker_thread,
186 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700187 cricket::MediaEngineInterface* engine,
188 typename T::MediaChannel* ch,
189 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -0700190 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200191 typename T::Channel* channel =
192 new typename T::Channel(worker_thread, network_thread, engine, ch,
jbauchcb560652016-08-04 05:20:32 -0700193 transport_controller, cricket::CN_AUDIO,
194 (flags & RTCP) != 0);
195 rtc::CryptoOptions crypto_options;
196 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
197 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -0700198 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 delete channel;
200 channel = NULL;
201 }
202 return channel;
203 }
204
205 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000206 bool result = channel1_->SetLocalContent(&local_media_content1_,
207 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 if (result) {
209 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000210 result = channel2_->SetRemoteContent(&remote_media_content1_,
211 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200213 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000215 result = channel2_->SetLocalContent(&local_media_content2_,
216 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000217 }
218 }
219 return result;
220 }
221
222 bool SendAccept() {
223 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000224 return channel1_->SetRemoteContent(&remote_media_content2_,
225 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 }
227
228 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000229 bool result = channel1_->SetLocalContent(&local_media_content1_,
230 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 if (result) {
232 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000233 result = channel2_->SetRemoteContent(&remote_media_content1_,
234 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000235 }
236 return result;
237 }
238
239 bool SendProvisionalAnswer() {
240 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000241 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 if (result) {
243 channel2_->Enable(true);
244 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000245 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200246 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 }
248 return result;
249 }
250
251 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000252 bool result = channel2_->SetLocalContent(&local_media_content2_,
253 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000255 result = channel1_->SetRemoteContent(&remote_media_content2_,
256 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 return result;
258 }
259
260 bool SendTerminate() {
261 channel1_.reset();
262 channel2_.reset();
263 return true;
264 }
265
266 bool AddStream1(int id) {
267 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
268 }
269 bool RemoveStream1(int id) {
270 return channel1_->RemoveRecvStream(id);
271 }
272
273 cricket::FakeTransport* GetTransport1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200274 std::string name = channel1_->content_name();
275 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700276 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200277 [this, name] { return transport_controller1_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 }
279 cricket::FakeTransport* GetTransport2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200280 std::string name = channel2_->content_name();
281 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700282 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200283 [this, name] { return transport_controller2_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 }
285
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200286 void SendRtp1() {
287 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
288 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200290 void SendRtp2() {
291 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
292 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200294 void SendRtcp1() {
295 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200297 void SendRtcp2() {
298 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200301 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
302 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
303 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200305 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
306 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
307 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200309 void SendCustomRtcp1(uint32_t ssrc) {
310 rtc::Buffer data = CreateRtcpData(ssrc);
311 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200313 void SendCustomRtcp2(uint32_t ssrc) {
314 rtc::Buffer data = CreateRtcpData(ssrc);
315 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200317
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200319 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 }
321 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200322 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 }
324 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200325 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 }
327 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200328 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
330 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200331 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200332 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
333 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200335 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200336 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
337 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200339 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200340 rtc::Buffer data = CreateRtcpData(ssrc);
341 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200343 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200344 rtc::Buffer data = CreateRtcpData(ssrc);
345 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200347 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
348 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200350 rtc::SetBE32(data.data() + 8, ssrc);
351 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000352 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200353 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000354 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 return data;
356 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200357 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
358 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200360 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 return data;
362 }
363
364 bool CheckNoRtp1() {
365 return media_channel1_->CheckNoRtp();
366 }
367 bool CheckNoRtp2() {
368 return media_channel2_->CheckNoRtp();
369 }
370 bool CheckNoRtcp1() {
371 return media_channel1_->CheckNoRtcp();
372 }
373 bool CheckNoRtcp2() {
374 return media_channel2_->CheckNoRtcp();
375 }
jbauchcb560652016-08-04 05:20:32 -0700376 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags.
377 // Returns true if so.
378 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
379 int suite;
380 if (!channel->transport_channel()->GetSrtpCryptoSuite(&suite)) {
381 return false;
382 }
383
384 if (flags & GCM_CIPHER) {
385 return rtc::IsGcmCryptoSuite(suite);
386 } else {
387 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
388 !rtc::IsGcmCryptoSuite(suite));
389 }
390 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391
392 void CreateContent(int flags,
393 const cricket::AudioCodec& audio_codec,
394 const cricket::VideoCodec& video_codec,
395 typename T::Content* content) {
396 // overridden in specialized classes
397 }
398 void CopyContent(const typename T::Content& source,
399 typename T::Content* content) {
400 // overridden in specialized classes
401 }
402
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 // Creates a cricket::SessionDescription with one MediaContent and one stream.
404 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200405 cricket::SessionDescription* CreateSessionDescriptionWithStream(
406 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 typename T::Content content;
408 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
409 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
410 AddLegacyStreamInContent(ssrc, 0, &content);
411 sdesc->AddContent("DUMMY_CONTENT_NAME",
412 cricket::NS_JINGLE_RTP, content.Copy());
413 return sdesc;
414 }
415
ossu292d6582016-03-17 02:31:13 -0700416 // Will manage the lifetime of a CallThread, making sure it's
417 // destroyed before this object goes out of scope.
418 class ScopedCallThread {
419 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200420 template <class FunctorT>
421 ScopedCallThread(const FunctorT& functor)
422 : thread_(rtc::Thread::Create()),
423 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700424 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700425 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700426 }
427
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200428 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700429
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200430 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700431
432 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200433 std::unique_ptr<rtc::Thread> thread_;
434 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700435 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
438 return false; // overridden in specialized classes
439 }
440
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200441 void OnMediaMonitor1(typename T::Channel* channel,
442 const typename T::MediaInfo& info) {
443 RTC_DCHECK_EQ(channel, channel1_.get());
444 media_info_callbacks1_++;
445 }
446 void OnMediaMonitor2(typename T::Channel* channel,
447 const typename T::MediaInfo& info) {
448 RTC_DCHECK_EQ(channel, channel2_.get());
449 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 }
451
Honghai Zhangcc411c02016-03-29 17:27:21 -0700452 cricket::CandidatePairInterface* last_selected_candidate_pair() {
453 return last_selected_candidate_pair_;
454 }
455
Peter Boström0c4e06b2015-10-07 12:23:21 +0200456 void AddLegacyStreamInContent(uint32_t ssrc,
457 int flags,
458 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 // Base implementation.
460 }
461
462 // Tests that can be used by derived classes.
463
464 // Basic sanity check.
465 void TestInit() {
466 CreateChannels(0, 0);
467 EXPECT_FALSE(channel1_->secure());
468 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200469 if (verify_playout_) {
470 EXPECT_FALSE(media_channel1_->playout());
471 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 EXPECT_TRUE(media_channel1_->codecs().empty());
473 EXPECT_TRUE(media_channel1_->recv_streams().empty());
474 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
475 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
476 }
477
478 // Test that SetLocalContent and SetRemoteContent properly configure
479 // the codecs.
480 void TestSetContents() {
481 CreateChannels(0, 0);
482 typename T::Content content;
483 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000484 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000485 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000486 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 ASSERT_EQ(1U, media_channel1_->codecs().size());
488 EXPECT_TRUE(CodecMatches(content.codecs()[0],
489 media_channel1_->codecs()[0]));
490 }
491
492 // Test that SetLocalContent and SetRemoteContent properly deals
493 // with an empty offer.
494 void TestSetContentsNullOffer() {
495 CreateChannels(0, 0);
496 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000497 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498 CreateContent(0, kPcmuCodec, kH264Codec, &content);
499 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000500 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 ASSERT_EQ(1U, media_channel1_->codecs().size());
502 EXPECT_TRUE(CodecMatches(content.codecs()[0],
503 media_channel1_->codecs()[0]));
504 }
505
506 // Test that SetLocalContent and SetRemoteContent properly set RTCP
507 // mux.
508 void TestSetContentsRtcpMux() {
509 CreateChannels(RTCP, RTCP);
510 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
511 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
512 typename T::Content content;
513 CreateContent(0, kPcmuCodec, kH264Codec, &content);
514 // Both sides agree on mux. Should no longer be a separate RTCP channel.
515 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000516 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
517 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
519 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000520 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000522 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
524 }
525
526 // Test that SetLocalContent and SetRemoteContent properly set RTCP
527 // mux when a provisional answer is received.
528 void TestSetContentsRtcpMuxWithPrAnswer() {
529 CreateChannels(RTCP, RTCP);
530 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
531 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
532 typename T::Content content;
533 CreateContent(0, kPcmuCodec, kH264Codec, &content);
534 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000535 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
536 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000538 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 // Both sides agree on mux. Should no longer be a separate RTCP channel.
540 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
541 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000542 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000544 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
545 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
547 }
548
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 // Test that SetRemoteContent properly deals with a content update.
550 void TestSetRemoteContentUpdate() {
551 CreateChannels(0, 0);
552 typename T::Content content;
553 CreateContent(RTCP | RTCP_MUX | SECURE,
554 kPcmuCodec, kH264Codec,
555 &content);
556 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000557 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
558 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 ASSERT_EQ(1U, media_channel1_->codecs().size());
560 EXPECT_TRUE(CodecMatches(content.codecs()[0],
561 media_channel1_->codecs()[0]));
562 // Now update with other codecs.
563 typename T::Content update_content;
564 update_content.set_partial(true);
565 CreateContent(0, kIsacCodec, kH264SvcCodec,
566 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000567 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 ASSERT_EQ(1U, media_channel1_->codecs().size());
569 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
570 media_channel1_->codecs()[0]));
571 // Now update without any codecs. This is ignored.
572 typename T::Content empty_content;
573 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000574 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 ASSERT_EQ(1U, media_channel1_->codecs().size());
576 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
577 media_channel1_->codecs()[0]));
578 }
579
580 // Test that Add/RemoveStream properly forward to the media channel.
581 void TestStreams() {
582 CreateChannels(0, 0);
583 EXPECT_TRUE(AddStream1(1));
584 EXPECT_TRUE(AddStream1(2));
585 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
586 EXPECT_TRUE(RemoveStream1(2));
587 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
588 EXPECT_TRUE(RemoveStream1(1));
589 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
590 }
591
592 // Test that SetLocalContent properly handles adding and removing StreamParams
593 // to the local content description.
594 // This test uses the CA_UPDATE action that don't require a full
595 // MediaContentDescription to do an update.
596 void TestUpdateStreamsInLocalContent() {
597 cricket::StreamParams stream1;
598 stream1.groupid = "group1";
599 stream1.id = "stream1";
600 stream1.ssrcs.push_back(kSsrc1);
601 stream1.cname = "stream1_cname";
602
603 cricket::StreamParams stream2;
604 stream2.groupid = "group2";
605 stream2.id = "stream2";
606 stream2.ssrcs.push_back(kSsrc2);
607 stream2.cname = "stream2_cname";
608
609 cricket::StreamParams stream3;
610 stream3.groupid = "group3";
611 stream3.id = "stream3";
612 stream3.ssrcs.push_back(kSsrc3);
613 stream3.cname = "stream3_cname";
614
615 CreateChannels(0, 0);
616 typename T::Content content1;
617 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
618 content1.AddStream(stream1);
619 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000620 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621
622 ASSERT_EQ(1u, media_channel1_->send_streams().size());
623 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
624
625 // Update the local streams by adding another sending stream.
626 // Use a partial updated session description.
627 typename T::Content content2;
628 content2.AddStream(stream2);
629 content2.AddStream(stream3);
630 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000631 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 ASSERT_EQ(3u, media_channel1_->send_streams().size());
633 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
634 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
635 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
636
637 // Update the local streams by removing the first sending stream.
638 // This is done by removing all SSRCS for this particular stream.
639 typename T::Content content3;
640 stream1.ssrcs.clear();
641 content3.AddStream(stream1);
642 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000643 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 ASSERT_EQ(2u, media_channel1_->send_streams().size());
645 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
646 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
647
648 // Update the local streams with a stream that does not change.
649 // THe update is ignored.
650 typename T::Content content4;
651 content4.AddStream(stream2);
652 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000653 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 ASSERT_EQ(2u, media_channel1_->send_streams().size());
655 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
656 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
657 }
658
659 // Test that SetRemoteContent properly handles adding and removing
660 // StreamParams to the remote content description.
661 // This test uses the CA_UPDATE action that don't require a full
662 // MediaContentDescription to do an update.
663 void TestUpdateStreamsInRemoteContent() {
664 cricket::StreamParams stream1;
665 stream1.id = "Stream1";
666 stream1.groupid = "1";
667 stream1.ssrcs.push_back(kSsrc1);
668 stream1.cname = "stream1_cname";
669
670 cricket::StreamParams stream2;
671 stream2.id = "Stream2";
672 stream2.groupid = "2";
673 stream2.ssrcs.push_back(kSsrc2);
674 stream2.cname = "stream2_cname";
675
676 cricket::StreamParams stream3;
677 stream3.id = "Stream3";
678 stream3.groupid = "3";
679 stream3.ssrcs.push_back(kSsrc3);
680 stream3.cname = "stream3_cname";
681
682 CreateChannels(0, 0);
683 typename T::Content content1;
684 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
685 content1.AddStream(stream1);
686 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000687 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688
689 ASSERT_EQ(1u, media_channel1_->codecs().size());
690 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
691 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
692
693 // Update the remote streams by adding another sending stream.
694 // Use a partial updated session description.
695 typename T::Content content2;
696 content2.AddStream(stream2);
697 content2.AddStream(stream3);
698 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
701 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
702 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
703 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
704
705 // Update the remote streams by removing the first stream.
706 // This is done by removing all SSRCS for this particular stream.
707 typename T::Content content3;
708 stream1.ssrcs.clear();
709 content3.AddStream(stream1);
710 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000711 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
713 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
714 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
715
716 // Update the remote streams with a stream that does not change.
717 // The update is ignored.
718 typename T::Content content4;
719 content4.AddStream(stream2);
720 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000721 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
723 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
724 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
725 }
726
727 // Test that SetLocalContent and SetRemoteContent properly
728 // handles adding and removing StreamParams when the action is a full
729 // CA_OFFER / CA_ANSWER.
730 void TestChangeStreamParamsInContent() {
731 cricket::StreamParams stream1;
732 stream1.groupid = "group1";
733 stream1.id = "stream1";
734 stream1.ssrcs.push_back(kSsrc1);
735 stream1.cname = "stream1_cname";
736
737 cricket::StreamParams stream2;
738 stream2.groupid = "group1";
739 stream2.id = "stream2";
740 stream2.ssrcs.push_back(kSsrc2);
741 stream2.cname = "stream2_cname";
742
743 // Setup a call where channel 1 send |stream1| to channel 2.
744 CreateChannels(0, 0);
745 typename T::Content content1;
746 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
747 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000748 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 EXPECT_TRUE(channel1_->Enable(true));
750 EXPECT_EQ(1u, media_channel1_->send_streams().size());
751
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000752 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200754 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755
756 // Channel 2 do not send anything.
757 typename T::Content content2;
758 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000759 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000761 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 EXPECT_TRUE(channel2_->Enable(true));
763 EXPECT_EQ(0u, media_channel2_->send_streams().size());
764
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200765 SendCustomRtp1(kSsrc1, 0);
766 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
768
769 // Let channel 2 update the content by sending |stream2| and enable SRTP.
770 typename T::Content content3;
771 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
772 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000773 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 ASSERT_EQ(1u, media_channel2_->send_streams().size());
775 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
776
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000777 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
779 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
780
781 // Channel 1 replies but stop sending stream1.
782 typename T::Content content4;
783 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000784 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 EXPECT_EQ(0u, media_channel1_->send_streams().size());
786
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000787 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
789
790 EXPECT_TRUE(channel1_->secure());
791 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200792 SendCustomRtp2(kSsrc2, 0);
793 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
795 }
796
797 // Test that we only start playout and sending at the right times.
798 void TestPlayoutAndSendingStates() {
799 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200800 if (verify_playout_) {
801 EXPECT_FALSE(media_channel1_->playout());
802 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200804 if (verify_playout_) {
805 EXPECT_FALSE(media_channel2_->playout());
806 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000807 EXPECT_FALSE(media_channel2_->sending());
808 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200809 if (verify_playout_) {
810 EXPECT_FALSE(media_channel1_->playout());
811 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000813 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
814 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200815 if (verify_playout_) {
816 EXPECT_TRUE(media_channel1_->playout());
817 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000819 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
820 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200821 if (verify_playout_) {
822 EXPECT_FALSE(media_channel2_->playout());
823 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000825 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
826 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200827 if (verify_playout_) {
828 EXPECT_FALSE(media_channel2_->playout());
829 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 EXPECT_FALSE(media_channel2_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200831 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200832 if (verify_playout_) {
833 EXPECT_TRUE(media_channel1_->playout());
834 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200836 if (verify_playout_) {
837 EXPECT_FALSE(media_channel2_->playout());
838 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 EXPECT_FALSE(media_channel2_->sending());
840 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200841 if (verify_playout_) {
842 EXPECT_TRUE(media_channel2_->playout());
843 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000845 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
846 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200847 if (verify_playout_) {
848 EXPECT_TRUE(media_channel1_->playout());
849 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 EXPECT_TRUE(media_channel1_->sending());
851 }
852
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 // Test that changing the MediaContentDirection in the local and remote
854 // session description start playout and sending at the right time.
855 void TestMediaContentDirection() {
856 CreateChannels(0, 0);
857 typename T::Content content1;
858 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
859 typename T::Content content2;
860 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
861 // Set |content2| to be InActive.
862 content2.set_direction(cricket::MD_INACTIVE);
863
864 EXPECT_TRUE(channel1_->Enable(true));
865 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200866 if (verify_playout_) {
867 EXPECT_FALSE(media_channel1_->playout());
868 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200870 if (verify_playout_) {
871 EXPECT_FALSE(media_channel2_->playout());
872 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 EXPECT_FALSE(media_channel2_->sending());
874
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000875 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
876 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
877 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
878 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200879 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880
Peter Boström34fbfff2015-09-24 19:20:30 +0200881 if (verify_playout_) {
882 EXPECT_TRUE(media_channel1_->playout());
883 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200885 if (verify_playout_) {
886 EXPECT_FALSE(media_channel2_->playout()); // local InActive
887 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 EXPECT_FALSE(media_channel2_->sending()); // local InActive
889
890 // Update |content2| to be RecvOnly.
891 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000892 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
893 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894
Peter Boström34fbfff2015-09-24 19:20:30 +0200895 if (verify_playout_) {
896 EXPECT_TRUE(media_channel1_->playout());
897 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200899 if (verify_playout_) {
900 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
901 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
903
904 // Update |content2| to be SendRecv.
905 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000906 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
907 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908
Peter Boström34fbfff2015-09-24 19:20:30 +0200909 if (verify_playout_) {
910 EXPECT_TRUE(media_channel1_->playout());
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200913 if (verify_playout_) {
914 EXPECT_TRUE(media_channel2_->playout());
915 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 EXPECT_TRUE(media_channel2_->sending());
917 }
918
Honghai Zhangcc411c02016-03-29 17:27:21 -0700919 // Tests that when the transport channel signals a candidate pair change
920 // event, the media channel will receive a call on the network route change.
921 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200922 constexpr uint16_t kLocalNetId = 1;
923 constexpr uint16_t kRemoteNetId = 2;
924 constexpr int kLastPacketId = 100;
925
Honghai Zhangcc411c02016-03-29 17:27:21 -0700926 CreateChannels(0, 0);
927
928 cricket::TransportChannel* transport_channel1 =
929 channel1_->transport_channel();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200930 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700931 typename T::MediaChannel* media_channel1 =
932 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200933 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700934
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200935 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700936 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200937 // The transport channel becomes disconnected.
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700938 transport_channel1->SignalSelectedCandidatePairChanged(
939 transport_channel1, nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200940 });
941 WaitForThreads();
942 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700943 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200944 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700945
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700946 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
947 media_channel1, kLocalNetId,
948 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200949 // The transport channel becomes connected.
950 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
951 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
952 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
953 transport_controller1_->CreateFakeCandidatePair(
954 local_address, kLocalNetId, remote_address, kRemoteNetId));
955 transport_channel1->SignalSelectedCandidatePairChanged(
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700956 transport_channel1, candidate_pair.get(), kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200957 });
958 WaitForThreads();
959 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700960 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200961 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700962 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200963 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700964 media_channel1->last_network_route().last_sent_packet_id);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700965 }
966
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 // Test setting up a call.
968 void TestCallSetup() {
969 CreateChannels(0, 0);
970 EXPECT_FALSE(channel1_->secure());
971 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200972 if (verify_playout_) {
973 EXPECT_TRUE(media_channel1_->playout());
974 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 EXPECT_FALSE(media_channel1_->sending());
976 EXPECT_TRUE(SendAccept());
977 EXPECT_FALSE(channel1_->secure());
978 EXPECT_TRUE(media_channel1_->sending());
979 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200980 if (verify_playout_) {
981 EXPECT_TRUE(media_channel2_->playout());
982 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 EXPECT_TRUE(media_channel2_->sending());
984 EXPECT_EQ(1U, media_channel2_->codecs().size());
985 }
986
987 // Test that we don't crash if packets are sent during call teardown
988 // when RTCP mux is enabled. This is a regression test against a specific
989 // race condition that would only occur when a RTCP packet was sent during
990 // teardown of a channel on which RTCP mux was enabled.
991 void TestCallTeardownRtcpMux() {
992 class LastWordMediaChannel : public T::MediaChannel {
993 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200994 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700996 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
997 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
999 }
1000 };
1001 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001002 RTCP | RTCP_MUX, RTCP | RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 EXPECT_TRUE(SendInitiate());
1004 EXPECT_TRUE(SendAccept());
1005 EXPECT_TRUE(SendTerminate());
1006 }
1007
1008 // Send voice RTP data to the other side and ensure it gets there.
1009 void SendRtpToRtp() {
1010 CreateChannels(0, 0);
1011 EXPECT_TRUE(SendInitiate());
1012 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001013 ASSERT_TRUE(GetTransport1());
1014 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 EXPECT_EQ(1U, GetTransport1()->channels().size());
1016 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001017 SendRtp1();
1018 SendRtp2();
1019 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 EXPECT_TRUE(CheckRtp1());
1021 EXPECT_TRUE(CheckRtp2());
1022 EXPECT_TRUE(CheckNoRtp1());
1023 EXPECT_TRUE(CheckNoRtp2());
1024 }
1025
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001026 void TestDeinit() {
1027 CreateChannels(RTCP, RTCP);
1028 EXPECT_TRUE(SendInitiate());
1029 EXPECT_TRUE(SendAccept());
1030 SendRtp1();
1031 SendRtp2();
1032 SendRtcp1();
1033 SendRtcp2();
1034 // Do not wait, destroy channels.
1035 channel1_.reset(nullptr);
1036 channel2_.reset(nullptr);
1037 }
1038
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 // Check that RTCP is not transmitted if both sides don't support RTCP.
1040 void SendNoRtcpToNoRtcp() {
1041 CreateChannels(0, 0);
1042 EXPECT_TRUE(SendInitiate());
1043 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001044 ASSERT_TRUE(GetTransport1());
1045 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 EXPECT_EQ(1U, GetTransport1()->channels().size());
1047 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001048 SendRtcp1();
1049 SendRtcp2();
1050 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 EXPECT_TRUE(CheckNoRtcp1());
1052 EXPECT_TRUE(CheckNoRtcp2());
1053 }
1054
1055 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1056 void SendNoRtcpToRtcp() {
1057 CreateChannels(0, RTCP);
1058 EXPECT_TRUE(SendInitiate());
1059 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001060 ASSERT_TRUE(GetTransport1());
1061 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 EXPECT_EQ(1U, GetTransport1()->channels().size());
1063 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001064 SendRtcp1();
1065 SendRtcp2();
1066 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 EXPECT_TRUE(CheckNoRtcp1());
1068 EXPECT_TRUE(CheckNoRtcp2());
1069 }
1070
1071 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1072 void SendRtcpToNoRtcp() {
1073 CreateChannels(RTCP, 0);
1074 EXPECT_TRUE(SendInitiate());
1075 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001076 ASSERT_TRUE(GetTransport1());
1077 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 EXPECT_EQ(2U, GetTransport1()->channels().size());
1079 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001080 SendRtcp1();
1081 SendRtcp2();
1082 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 EXPECT_TRUE(CheckNoRtcp1());
1084 EXPECT_TRUE(CheckNoRtcp2());
1085 }
1086
1087 // Check that RTCP is transmitted if both sides support RTCP.
1088 void SendRtcpToRtcp() {
1089 CreateChannels(RTCP, RTCP);
1090 EXPECT_TRUE(SendInitiate());
1091 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001092 ASSERT_TRUE(GetTransport1());
1093 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 EXPECT_EQ(2U, GetTransport1()->channels().size());
1095 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001096 SendRtcp1();
1097 SendRtcp2();
1098 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 EXPECT_TRUE(CheckRtcp1());
1100 EXPECT_TRUE(CheckRtcp2());
1101 EXPECT_TRUE(CheckNoRtcp1());
1102 EXPECT_TRUE(CheckNoRtcp2());
1103 }
1104
1105 // Check that RTCP is transmitted if only the initiator supports mux.
1106 void SendRtcpMuxToRtcp() {
1107 CreateChannels(RTCP | RTCP_MUX, RTCP);
1108 EXPECT_TRUE(SendInitiate());
1109 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001110 ASSERT_TRUE(GetTransport1());
1111 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 EXPECT_EQ(2U, GetTransport1()->channels().size());
1113 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001114 SendRtcp1();
1115 SendRtcp2();
1116 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 EXPECT_TRUE(CheckRtcp1());
1118 EXPECT_TRUE(CheckRtcp2());
1119 EXPECT_TRUE(CheckNoRtcp1());
1120 EXPECT_TRUE(CheckNoRtcp2());
1121 }
1122
1123 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1124 void SendRtcpMuxToRtcpMux() {
1125 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1126 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001127 ASSERT_TRUE(GetTransport1());
1128 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 EXPECT_EQ(2U, GetTransport1()->channels().size());
1130 EXPECT_EQ(1U, GetTransport2()->channels().size());
1131 EXPECT_TRUE(SendAccept());
1132 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001133 SendRtp1();
1134 SendRtp2();
1135 SendRtcp1();
1136 SendRtcp2();
1137 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 EXPECT_TRUE(CheckRtp1());
1139 EXPECT_TRUE(CheckRtp2());
1140 EXPECT_TRUE(CheckNoRtp1());
1141 EXPECT_TRUE(CheckNoRtp2());
1142 EXPECT_TRUE(CheckRtcp1());
1143 EXPECT_TRUE(CheckRtcp2());
1144 EXPECT_TRUE(CheckNoRtcp1());
1145 EXPECT_TRUE(CheckNoRtcp2());
1146 }
1147
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001148 // Check that RTP and RTCP are transmitted ok when both sides
1149 // support mux and one the offerer requires mux.
1150 void SendRequireRtcpMuxToRtcpMux() {
1151 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1152 channel1_->ActivateRtcpMux();
1153 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001154 ASSERT_TRUE(GetTransport1());
1155 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001156 EXPECT_EQ(1U, GetTransport1()->channels().size());
1157 EXPECT_EQ(1U, GetTransport2()->channels().size());
1158 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001159 SendRtp1();
1160 SendRtp2();
1161 SendRtcp1();
1162 SendRtcp2();
1163 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001164 EXPECT_TRUE(CheckRtp1());
1165 EXPECT_TRUE(CheckRtp2());
1166 EXPECT_TRUE(CheckNoRtp1());
1167 EXPECT_TRUE(CheckNoRtp2());
1168 EXPECT_TRUE(CheckRtcp1());
1169 EXPECT_TRUE(CheckRtcp2());
1170 EXPECT_TRUE(CheckNoRtcp1());
1171 EXPECT_TRUE(CheckNoRtcp2());
1172 }
1173
1174 // Check that RTP and RTCP are transmitted ok when both sides
1175 // support mux and one the answerer requires rtcp mux.
1176 void SendRtcpMuxToRequireRtcpMux() {
1177 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1178 channel2_->ActivateRtcpMux();
1179 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001180 ASSERT_TRUE(GetTransport1());
1181 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001182 EXPECT_EQ(2U, GetTransport1()->channels().size());
1183 EXPECT_EQ(1U, GetTransport2()->channels().size());
1184 EXPECT_TRUE(SendAccept());
1185 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001186 SendRtp1();
1187 SendRtp2();
1188 SendRtcp1();
1189 SendRtcp2();
1190 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001191 EXPECT_TRUE(CheckRtp1());
1192 EXPECT_TRUE(CheckRtp2());
1193 EXPECT_TRUE(CheckNoRtp1());
1194 EXPECT_TRUE(CheckNoRtp2());
1195 EXPECT_TRUE(CheckRtcp1());
1196 EXPECT_TRUE(CheckRtcp2());
1197 EXPECT_TRUE(CheckNoRtcp1());
1198 EXPECT_TRUE(CheckNoRtcp2());
1199 }
1200
1201 // Check that RTP and RTCP are transmitted ok when both sides
1202 // require mux.
1203 void SendRequireRtcpMuxToRequireRtcpMux() {
1204 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1205 channel1_->ActivateRtcpMux();
1206 channel2_->ActivateRtcpMux();
1207 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001208 ASSERT_TRUE(GetTransport1());
1209 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001210 EXPECT_EQ(1U, GetTransport1()->channels().size());
1211 EXPECT_EQ(1U, GetTransport2()->channels().size());
1212 EXPECT_TRUE(SendAccept());
1213 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001214 SendRtp1();
1215 SendRtp2();
1216 SendRtcp1();
1217 SendRtcp2();
1218 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001219 EXPECT_TRUE(CheckRtp1());
1220 EXPECT_TRUE(CheckRtp2());
1221 EXPECT_TRUE(CheckNoRtp1());
1222 EXPECT_TRUE(CheckNoRtp2());
1223 EXPECT_TRUE(CheckRtcp1());
1224 EXPECT_TRUE(CheckRtcp2());
1225 EXPECT_TRUE(CheckNoRtcp1());
1226 EXPECT_TRUE(CheckNoRtcp2());
1227 }
1228
1229 // Check that SendAccept fails if the answerer doesn't support mux
1230 // and the offerer requires it.
1231 void SendRequireRtcpMuxToNoRtcpMux() {
1232 CreateChannels(RTCP | RTCP_MUX, RTCP);
1233 channel1_->ActivateRtcpMux();
1234 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001235 ASSERT_TRUE(GetTransport1());
1236 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001237 EXPECT_EQ(1U, GetTransport1()->channels().size());
1238 EXPECT_EQ(2U, GetTransport2()->channels().size());
1239 EXPECT_FALSE(SendAccept());
1240 }
1241
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242 // Check that RTCP data sent by the initiator before the accept is not muxed.
1243 void SendEarlyRtcpMuxToRtcp() {
1244 CreateChannels(RTCP | RTCP_MUX, RTCP);
1245 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001246 ASSERT_TRUE(GetTransport1());
1247 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 EXPECT_EQ(2U, GetTransport1()->channels().size());
1249 EXPECT_EQ(2U, GetTransport2()->channels().size());
1250
1251 // RTCP can be sent before the call is accepted, if the transport is ready.
1252 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001253 SendRtcp1();
1254 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 EXPECT_TRUE(CheckNoRtp2());
1256 EXPECT_TRUE(CheckRtcp2());
1257
1258 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001259 SendRtcp2();
1260 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 EXPECT_TRUE(CheckNoRtp1());
1262 EXPECT_TRUE(CheckRtcp1());
1263
1264 // Complete call setup and ensure everything is still OK.
1265 EXPECT_TRUE(SendAccept());
1266 EXPECT_EQ(2U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001267 SendRtcp1();
1268 SendRtcp2();
1269 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 EXPECT_TRUE(CheckRtcp1());
1272 }
1273
1274
1275 // Check that RTCP data is not muxed until both sides have enabled muxing,
1276 // but that we properly demux before we get the accept message, since there
1277 // is a race between RTP data and the jingle accept.
1278 void SendEarlyRtcpMuxToRtcpMux() {
1279 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1280 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001281 ASSERT_TRUE(GetTransport1());
1282 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 EXPECT_EQ(2U, GetTransport1()->channels().size());
1284 EXPECT_EQ(1U, GetTransport2()->channels().size());
1285
1286 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1287 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001288 SendRtcp1();
1289 WaitForThreads();
1290 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291
1292 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001293 SendRtcp2();
1294 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 EXPECT_TRUE(CheckNoRtp1());
1296 EXPECT_TRUE(CheckRtcp1());
1297
1298 // Complete call setup and ensure everything is still OK.
1299 EXPECT_TRUE(SendAccept());
1300 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001301 SendRtcp1();
1302 SendRtcp2();
1303 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 EXPECT_TRUE(CheckRtcp1());
1306 }
1307
1308 // Test that we properly send SRTP with RTCP in both directions.
1309 // You can pass in DTLS and/or RTCP_MUX as flags.
1310 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
jbauchcb560652016-08-04 05:20:32 -07001311 ASSERT((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1312 ASSERT((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313
1314 int flags1 = RTCP | SECURE | flags1_in;
1315 int flags2 = RTCP | SECURE | flags2_in;
1316 bool dtls1 = !!(flags1_in & DTLS);
1317 bool dtls2 = !!(flags2_in & DTLS);
1318 CreateChannels(flags1, flags2);
1319 EXPECT_FALSE(channel1_->secure());
1320 EXPECT_FALSE(channel2_->secure());
1321 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001322 WaitForThreads();
1323 EXPECT_TRUE(channel1_->writable());
1324 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325 EXPECT_TRUE(SendAccept());
1326 EXPECT_TRUE(channel1_->secure());
1327 EXPECT_TRUE(channel2_->secure());
1328 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1329 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001330 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1331 // channels.
1332 if (dtls1 && dtls2) {
1333 // A GCM cipher is only used if both channels support GCM ciphers.
1334 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1335 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1336 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1337 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001338 SendRtp1();
1339 SendRtp2();
1340 SendRtcp1();
1341 SendRtcp2();
1342 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 EXPECT_TRUE(CheckRtp1());
1344 EXPECT_TRUE(CheckRtp2());
1345 EXPECT_TRUE(CheckNoRtp1());
1346 EXPECT_TRUE(CheckNoRtp2());
1347 EXPECT_TRUE(CheckRtcp1());
1348 EXPECT_TRUE(CheckRtcp2());
1349 EXPECT_TRUE(CheckNoRtcp1());
1350 EXPECT_TRUE(CheckNoRtcp2());
1351 }
1352
1353 // Test that we properly handling SRTP negotiating down to RTP.
1354 void SendSrtpToRtp() {
1355 CreateChannels(RTCP | SECURE, RTCP);
1356 EXPECT_FALSE(channel1_->secure());
1357 EXPECT_FALSE(channel2_->secure());
1358 EXPECT_TRUE(SendInitiate());
1359 EXPECT_TRUE(SendAccept());
1360 EXPECT_FALSE(channel1_->secure());
1361 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001362 SendRtp1();
1363 SendRtp2();
1364 SendRtcp1();
1365 SendRtcp2();
1366 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367 EXPECT_TRUE(CheckRtp1());
1368 EXPECT_TRUE(CheckRtp2());
1369 EXPECT_TRUE(CheckNoRtp1());
1370 EXPECT_TRUE(CheckNoRtp2());
1371 EXPECT_TRUE(CheckRtcp1());
1372 EXPECT_TRUE(CheckRtcp2());
1373 EXPECT_TRUE(CheckNoRtcp1());
1374 EXPECT_TRUE(CheckNoRtcp2());
1375 }
1376
1377 // Test that we can send and receive early media when a provisional answer is
1378 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1379 void SendEarlyMediaUsingRtcpMuxSrtp() {
1380 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1381
1382 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1383 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1384 EXPECT_TRUE(SendOffer());
1385 EXPECT_TRUE(SendProvisionalAnswer());
1386 EXPECT_TRUE(channel1_->secure());
1387 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001388 ASSERT_TRUE(GetTransport1());
1389 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 EXPECT_EQ(2U, GetTransport1()->channels().size());
1391 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001392 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1393 SendCustomRtcp1(kSsrc1);
1394 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1395 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1398
1399 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001400 SendCustomRtcp2(kSsrc2);
1401 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1402 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1405
1406 // Complete call setup and ensure everything is still OK.
1407 EXPECT_TRUE(SendFinalAnswer());
1408 EXPECT_EQ(1U, GetTransport1()->channels().size());
1409 EXPECT_EQ(1U, GetTransport2()->channels().size());
1410 EXPECT_TRUE(channel1_->secure());
1411 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001412 SendCustomRtcp1(kSsrc1);
1413 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1414 SendCustomRtcp2(kSsrc2);
1415 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1416 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1421 }
1422
1423 // Test that we properly send RTP without SRTP from a thread.
1424 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001425 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 EXPECT_TRUE(SendInitiate());
1427 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001428 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1429 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1430 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1431 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1432 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1433 send_rtcp1.thread(),
1434 send_rtcp2.thread()};
1435 WaitForThreads(involved_threads);
1436 EXPECT_TRUE(CheckRtp1());
1437 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 EXPECT_TRUE(CheckNoRtp1());
1439 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001440 EXPECT_TRUE(CheckRtcp1());
1441 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 EXPECT_TRUE(CheckNoRtcp1());
1443 EXPECT_TRUE(CheckNoRtcp2());
1444 }
1445
1446 // Test that we properly send SRTP with RTCP from a thread.
1447 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1449 EXPECT_TRUE(SendInitiate());
1450 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001451 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1452 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1453 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1454 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1455 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1456 send_rtcp1.thread(),
1457 send_rtcp2.thread()};
1458 WaitForThreads(involved_threads);
1459 EXPECT_TRUE(CheckRtp1());
1460 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 EXPECT_TRUE(CheckNoRtp1());
1462 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001463 EXPECT_TRUE(CheckRtcp1());
1464 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 EXPECT_TRUE(CheckNoRtcp1());
1466 EXPECT_TRUE(CheckNoRtcp2());
1467 }
1468
1469 // Test that the mediachannel retains its sending state after the transport
1470 // becomes non-writable.
1471 void SendWithWritabilityLoss() {
1472 CreateChannels(0, 0);
1473 EXPECT_TRUE(SendInitiate());
1474 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001475 ASSERT_TRUE(GetTransport1());
1476 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 EXPECT_EQ(1U, GetTransport1()->channels().size());
1478 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001479 SendRtp1();
1480 SendRtp2();
1481 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 EXPECT_TRUE(CheckRtp1());
1483 EXPECT_TRUE(CheckRtp2());
1484 EXPECT_TRUE(CheckNoRtp1());
1485 EXPECT_TRUE(CheckNoRtp2());
1486
wu@webrtc.org97077a32013-10-25 21:18:33 +00001487 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001488 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001489 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001490 SendRtp1();
1491 SendRtp2();
1492 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 EXPECT_TRUE(CheckRtp1());
1494 EXPECT_TRUE(CheckNoRtp2());
1495
1496 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001497 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001498 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001500 SendRtp1();
1501 SendRtp2();
1502 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 EXPECT_TRUE(CheckRtp1());
1504 EXPECT_TRUE(CheckRtp2());
1505 EXPECT_TRUE(CheckNoRtp1());
1506 EXPECT_TRUE(CheckNoRtp2());
1507
1508 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001509 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001510 RTC_FROM_HERE, [this] { GetTransport1()->SetDestination(NULL); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 EXPECT_TRUE(media_channel1_->sending());
1512
wu@webrtc.org97077a32013-10-25 21:18:33 +00001513 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001514 SendRtp1();
1515 SendRtp2();
1516 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 EXPECT_TRUE(CheckRtp1());
1518 EXPECT_TRUE(CheckNoRtp2());
1519
1520 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001521 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1522 GetTransport1()->SetDestination(GetTransport2());
1523 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001525 SendRtp1();
1526 SendRtp2();
1527 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 EXPECT_TRUE(CheckRtp1());
1529 EXPECT_TRUE(CheckRtp2());
1530 EXPECT_TRUE(CheckNoRtp1());
1531 EXPECT_TRUE(CheckNoRtp2());
1532 }
1533
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001534 void SendBundleToBundle(
1535 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1536 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001538 // Only pl_type1 was added to the bundle filter for both |channel1_|
1539 // and |channel2_|.
1540 int pl_type1 = pl_types[0];
1541 int pl_type2 = pl_types[1];
1542 int flags = SSRC_MUX | RTCP;
1543 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001544 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001545 if (rtcp_mux) {
1546 flags |= RTCP_MUX;
1547 expected_channels = 1U;
1548 }
1549 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001551 ASSERT_TRUE(GetTransport1());
1552 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001554 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001556 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1557 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1558 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1559 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1560 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1561 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001562
1563 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001564 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1565 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1566 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001567 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001568 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1569 EXPECT_TRUE(CheckNoRtp1());
1570 EXPECT_TRUE(CheckNoRtp2());
1571
1572 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001573 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1574 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1575 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001576 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001577 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1578
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001579 SendCustomRtcp1(kSsrc1);
1580 SendCustomRtcp2(kSsrc2);
1581 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1583 EXPECT_TRUE(CheckNoRtcp1());
1584 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1585 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001587 SendCustomRtcp1(kSsrc2);
1588 SendCustomRtcp2(kSsrc1);
1589 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001590 // Bundle filter shouldn't filter out any RTCP.
1591 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1592 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 }
1594
1595 // Test that the media monitor can be run and gives timely callbacks.
1596 void TestMediaMonitor() {
1597 static const int kTimeout = 500;
1598 CreateChannels(0, 0);
1599 EXPECT_TRUE(SendInitiate());
1600 EXPECT_TRUE(SendAccept());
1601 channel1_->StartMediaMonitor(100);
1602 channel2_->StartMediaMonitor(100);
1603 // Ensure we get callbacks and stop.
1604 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1605 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1606 channel1_->StopMediaMonitor();
1607 channel2_->StopMediaMonitor();
1608 // Ensure a restart of a stopped monitor works.
1609 channel1_->StartMediaMonitor(100);
1610 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1611 channel1_->StopMediaMonitor();
1612 // Ensure stopping a stopped monitor is OK.
1613 channel1_->StopMediaMonitor();
1614 }
1615
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 void TestSetContentFailure() {
1617 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618
Peter Thatchera6d24442015-07-09 21:26:36 -07001619 auto sdesc = cricket::SessionDescription();
1620 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1621 new cricket::AudioContentDescription());
1622 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1623 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624
Peter Thatchera6d24442015-07-09 21:26:36 -07001625 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001627 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1628 &sdesc, cricket::CA_OFFER, &err));
1629 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1630 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001633 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1634 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001636 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1637 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 }
1639
1640 void TestSendTwoOffers() {
1641 CreateChannels(0, 0);
1642
Peter Thatchera6d24442015-07-09 21:26:36 -07001643 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001644 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001645 CreateSessionDescriptionWithStream(1));
1646 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1647 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1649
kwiberg31022942016-03-11 14:18:21 -08001650 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001651 CreateSessionDescriptionWithStream(2));
1652 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1653 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1655 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1656 }
1657
1658 void TestReceiveTwoOffers() {
1659 CreateChannels(0, 0);
1660
Peter Thatchera6d24442015-07-09 21:26:36 -07001661 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001662 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001663 CreateSessionDescriptionWithStream(1));
1664 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1665 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1667
kwiberg31022942016-03-11 14:18:21 -08001668 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001669 CreateSessionDescriptionWithStream(2));
1670 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1671 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1673 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1674 }
1675
1676 void TestSendPrAnswer() {
1677 CreateChannels(0, 0);
1678
Peter Thatchera6d24442015-07-09 21:26:36 -07001679 std::string err;
1680 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001681 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001682 CreateSessionDescriptionWithStream(1));
1683 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1684 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1686
Peter Thatchera6d24442015-07-09 21:26:36 -07001687 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001688 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001689 CreateSessionDescriptionWithStream(2));
1690 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1691 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1693 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1694
Peter Thatchera6d24442015-07-09 21:26:36 -07001695 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001696 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001697 CreateSessionDescriptionWithStream(3));
1698 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1699 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1701 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1702 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1703 }
1704
1705 void TestReceivePrAnswer() {
1706 CreateChannels(0, 0);
1707
Peter Thatchera6d24442015-07-09 21:26:36 -07001708 std::string err;
1709 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001710 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001711 CreateSessionDescriptionWithStream(1));
1712 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1713 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1715
Peter Thatchera6d24442015-07-09 21:26:36 -07001716 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001717 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001718 CreateSessionDescriptionWithStream(2));
1719 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1720 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1722 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1723
Peter Thatchera6d24442015-07-09 21:26:36 -07001724 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001725 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001726 CreateSessionDescriptionWithStream(3));
1727 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1728 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1730 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1731 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1732 }
1733
1734 void TestFlushRtcp() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 CreateChannels(RTCP, RTCP);
1736 EXPECT_TRUE(SendInitiate());
1737 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001738 ASSERT_TRUE(GetTransport1());
1739 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 EXPECT_EQ(2U, GetTransport1()->channels().size());
1741 EXPECT_EQ(2U, GetTransport2()->channels().size());
1742
1743 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001744 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 // The sending message is only posted. channel2_ should be empty.
1746 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001747 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1748 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749
1750 // When channel1_ is deleted, the RTCP packet should be sent out to
1751 // channel2_.
1752 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001753 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 EXPECT_TRUE(CheckRtcp2());
1755 }
1756
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001757 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001758 struct SrtpErrorHandler : public sigslot::has_slots<> {
1759 SrtpErrorHandler() :
1760 mode_(cricket::SrtpFilter::UNPROTECT),
1761 error_(cricket::SrtpFilter::ERROR_NONE) {}
1762 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1763 cricket::SrtpFilter::Error error) {
1764 mode_ = mode;
1765 error_ = error;
1766 }
1767 cricket::SrtpFilter::Mode mode_;
1768 cricket::SrtpFilter::Error error_;
1769 } error_handler;
1770
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001771 // For Audio, only pl_type 0 is added to the bundle filter.
1772 // For Video, only pl_type 97 is added to the bundle filter.
1773 // So we need to pass in pl_type so that the packet can pass through
1774 // the bundle filter before it can be processed by the srtp filter.
1775 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001776 static unsigned const char kBadPacket[] = {
1777 0x84, static_cast<unsigned char>(pl_type),
1778 0x00, 0x01,
1779 0x00, 0x00,
1780 0x00, 0x00,
1781 0x00, 0x00,
1782 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001783
1784 // Using fake clock because this tests that SRTP errors are signaled at
1785 // specific times based on set_signal_silent_time.
1786 rtc::ScopedFakeClock fake_clock;
1787 // Some code uses a time of 0 as a special value, so we must start with
1788 // a non-zero time.
1789 // TODO(deadbeef): Fix this.
1790 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1791
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1793 EXPECT_FALSE(channel1_->secure());
1794 EXPECT_FALSE(channel2_->secure());
1795 EXPECT_TRUE(SendInitiate());
1796 EXPECT_TRUE(SendAccept());
1797 EXPECT_TRUE(channel1_->secure());
1798 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001799 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001800 channel2_->srtp_filter()->SignalSrtpError.connect(
1801 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802
1803 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001804 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1805 rtc::PacketOptions());
1806 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001808 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001809 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1810 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001811 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1812 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001813 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1814 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001816 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001817 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001818 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001819 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1820 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001821 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001822 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1823 rtc::PacketOptions());
1824 WaitForThreads();
1825 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001826 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827
1828 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001829 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001830 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001831
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001832 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001833 cricket::TransportChannel* transport_channel =
1834 channel2_->transport_channel();
1835 transport_channel->SignalReadPacket(
1836 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1837 sizeof(kBadPacket), rtc::PacketTime(), 0);
1838 });
1839 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001840 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001841 // Terminate channels before the fake clock is destroyed.
1842 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 }
1844
1845 void TestOnReadyToSend() {
1846 CreateChannels(RTCP, RTCP);
1847 TransportChannel* rtp = channel1_->transport_channel();
1848 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1849 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001850
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001851 network_thread_->Invoke<void>(RTC_FROM_HERE,
1852 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001853 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001855
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001856 network_thread_->Invoke<void>(RTC_FROM_HERE,
1857 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001858 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1860 // channel are ready to send.
1861 EXPECT_TRUE(media_channel1_->ready_to_send());
1862
1863 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001864 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1865 channel1_->SetTransportChannelReadyToSend(false, false);
1866 });
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
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001870 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1871 channel1_->SetTransportChannelReadyToSend(false, true);
1872 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001873 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 EXPECT_TRUE(media_channel1_->ready_to_send());
1875
1876 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001877 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1878 channel1_->SetTransportChannelReadyToSend(true, false);
1879 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001880 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001882
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001883 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1884 channel1_->SetTransportChannelReadyToSend(true, true);
1885 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001886 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 EXPECT_TRUE(media_channel1_->ready_to_send());
1888 }
1889
1890 void TestOnReadyToSendWithRtcpMux() {
1891 CreateChannels(RTCP, RTCP);
1892 typename T::Content content;
1893 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1894 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1895 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001896 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1897 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1899 TransportChannel* rtp = channel1_->transport_channel();
1900 EXPECT_FALSE(media_channel1_->ready_to_send());
1901 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1902 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001903 network_thread_->Invoke<void>(RTC_FROM_HERE,
1904 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001905 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001907
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001908 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1909 channel1_->SetTransportChannelReadyToSend(false, false);
1910 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001911 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 EXPECT_FALSE(media_channel1_->ready_to_send());
1913 }
1914
skvladdc1c62c2016-03-16 19:07:43 -07001915 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1916 typename T::Content content;
1917 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1918 content.set_bandwidth(remote_limit);
1919 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1920 }
1921
1922 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1923 webrtc::RtpParameters parameters;
1924 webrtc::RtpEncodingParameters encoding;
1925 encoding.max_bitrate_bps = limit;
1926 parameters.encodings.push_back(encoding);
1927 return parameters;
1928 }
1929
1930 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1931 int expected_bitrate) {
1932 EXPECT_EQ(1UL, parameters.encodings.size());
1933 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1934 }
1935
1936 void DefaultMaxBitrateIsUnlimited() {
1937 CreateChannels(0, 0);
1938 EXPECT_TRUE(
1939 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1940 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001941 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001942 }
1943
1944 void CanChangeMaxBitrate() {
1945 CreateChannels(0, 0);
1946 EXPECT_TRUE(
1947 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1948
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001949 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1950 kSsrc1, BitrateLimitedParameters(1000)));
1951 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1952 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001953 EXPECT_EQ(-1, media_channel1_->max_bps());
1954
1955 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001956 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1957 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1958 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001959 EXPECT_EQ(-1, media_channel1_->max_bps());
1960 }
1961
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001962 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001963 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1964 static void ProcessThreadQueue(rtc::Thread* thread) {
1965 RTC_DCHECK(thread->IsCurrent());
1966 while (!thread->empty()) {
1967 thread->ProcessMessages(0);
1968 }
1969 }
1970 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1971 // |threads| and current thread post packets to network thread.
1972 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001973 thread->Invoke<void>(RTC_FROM_HERE,
1974 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001975 }
1976 ProcessThreadQueue(rtc::Thread::Current());
1977 // Network thread move them around and post back to worker = current thread.
1978 if (!network_thread_->IsCurrent()) {
1979 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001980 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001981 }
1982 // Worker thread = current Thread process received messages.
1983 ProcessThreadQueue(rtc::Thread::Current());
1984 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001985 // TODO(pbos): Remove playout from all media channels and let renderers mute
1986 // themselves.
1987 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001988 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1989 rtc::Thread* network_thread_;
1990 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1991 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 cricket::FakeMediaEngine media_engine_;
1993 // The media channels are owned by the voice channel objects below.
1994 typename T::MediaChannel* media_channel1_;
1995 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001996 std::unique_ptr<typename T::Channel> channel1_;
1997 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 typename T::Content local_media_content1_;
1999 typename T::Content local_media_content2_;
2000 typename T::Content remote_media_content1_;
2001 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002003 rtc::Buffer rtp_packet_;
2004 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002005 int media_info_callbacks1_;
2006 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07002007 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008};
2009
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010template<>
2011void ChannelTest<VoiceTraits>::CreateContent(
2012 int flags,
2013 const cricket::AudioCodec& audio_codec,
2014 const cricket::VideoCodec& video_codec,
2015 cricket::AudioContentDescription* audio) {
2016 audio->AddCodec(audio_codec);
2017 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
2018 if (flags & SECURE) {
2019 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002020 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2021 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 }
2023}
2024
2025template<>
2026void ChannelTest<VoiceTraits>::CopyContent(
2027 const cricket::AudioContentDescription& source,
2028 cricket::AudioContentDescription* audio) {
2029 *audio = source;
2030}
2031
2032template<>
2033bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2034 const cricket::AudioCodec& c2) {
2035 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2036 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2037}
2038
Peter Boström0c4e06b2015-10-07 12:23:21 +02002039template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002041 uint32_t ssrc,
2042 int flags,
2043 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 audio->AddLegacyStream(ssrc);
2045}
2046
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002047class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 public:
solenberg1dd98f32015-09-10 01:57:14 -07002049 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002050 VoiceChannelSingleThreadTest()
2051 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2052};
2053
2054class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2055 public:
2056 typedef ChannelTest<VoiceTraits> Base;
2057 VoiceChannelDoubleThreadTest()
2058 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059};
2060
2061// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002062template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002064 rtc::Thread* worker_thread,
2065 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002066 cricket::MediaEngineInterface* engine,
2067 cricket::FakeVideoMediaChannel* ch,
2068 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002069 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002070 cricket::VideoChannel* channel =
2071 new cricket::VideoChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07002072 transport_controller, cricket::CN_VIDEO,
2073 (flags & RTCP) != 0);
2074 rtc::CryptoOptions crypto_options;
2075 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2076 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07002077 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 delete channel;
2079 channel = NULL;
2080 }
2081 return channel;
2082}
2083
2084// override to add 0 parameter
2085template<>
2086bool ChannelTest<VideoTraits>::AddStream1(int id) {
2087 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2088}
2089
2090template<>
2091void ChannelTest<VideoTraits>::CreateContent(
2092 int flags,
2093 const cricket::AudioCodec& audio_codec,
2094 const cricket::VideoCodec& video_codec,
2095 cricket::VideoContentDescription* video) {
2096 video->AddCodec(video_codec);
2097 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2098 if (flags & SECURE) {
2099 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002100 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2101 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 }
2103}
2104
2105template<>
2106void ChannelTest<VideoTraits>::CopyContent(
2107 const cricket::VideoContentDescription& source,
2108 cricket::VideoContentDescription* video) {
2109 *video = source;
2110}
2111
2112template<>
2113bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2114 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002115 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116}
2117
Peter Boström0c4e06b2015-10-07 12:23:21 +02002118template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002120 uint32_t ssrc,
2121 int flags,
2122 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 video->AddLegacyStream(ssrc);
2124}
2125
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002126class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 public:
solenberg1dd98f32015-09-10 01:57:14 -07002128 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002129 VideoChannelSingleThreadTest()
2130 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131};
2132
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002133class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2134 public:
2135 typedef ChannelTest<VideoTraits> Base;
2136 VideoChannelDoubleThreadTest()
2137 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2138};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002140// VoiceChannelSingleThreadTest
2141TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 Base::TestInit();
2143 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2144 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2145}
2146
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002147TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2148 Base::TestDeinit();
2149}
2150
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002151TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 Base::TestSetContents();
2153}
2154
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002155TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 Base::TestSetContentsNullOffer();
2157}
2158
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002159TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 Base::TestSetContentsRtcpMux();
2161}
2162
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002163TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 Base::TestSetContentsRtcpMux();
2165}
2166
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002167TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 Base::TestSetRemoteContentUpdate();
2169}
2170
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002171TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 Base::TestStreams();
2173}
2174
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002175TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 Base::TestUpdateStreamsInLocalContent();
2177}
2178
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002179TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 Base::TestUpdateStreamsInRemoteContent();
2181}
2182
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002183TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 Base::TestChangeStreamParamsInContent();
2185}
2186
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002187TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 Base::TestPlayoutAndSendingStates();
2189}
2190
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002191TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002192 CreateChannels(0, 0);
2193 // Test that we can Mute the default channel even though the sending SSRC
2194 // is unknown.
2195 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002196 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002197 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2198 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002199 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2200
2201 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002202 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002203
2204 SendInitiate();
2205 // After the local session description has been set, we can mute a stream
2206 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002207 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002208 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2209 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002210 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211}
2212
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002213TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 Base::TestMediaContentDirection();
2215}
2216
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002217TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002218 Base::TestNetworkRouteChanges();
2219}
2220
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002221TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222 Base::TestCallSetup();
2223}
2224
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002225TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 Base::TestCallTeardownRtcpMux();
2227}
2228
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002229TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 Base::SendRtpToRtp();
2231}
2232
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002233TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 Base::SendNoRtcpToNoRtcp();
2235}
2236
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002237TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 Base::SendNoRtcpToRtcp();
2239}
2240
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002241TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 Base::SendRtcpToNoRtcp();
2243}
2244
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002245TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 Base::SendRtcpToRtcp();
2247}
2248
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002249TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 Base::SendRtcpMuxToRtcp();
2251}
2252
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002253TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 Base::SendRtcpMuxToRtcpMux();
2255}
2256
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002257TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002258 Base::SendRequireRtcpMuxToRtcpMux();
2259}
2260
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002261TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002262 Base::SendRtcpMuxToRequireRtcpMux();
2263}
2264
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002265TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002266 Base::SendRequireRtcpMuxToRequireRtcpMux();
2267}
2268
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002269TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002270 Base::SendRequireRtcpMuxToNoRtcpMux();
2271}
2272
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002273TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 Base::SendEarlyRtcpMuxToRtcp();
2275}
2276
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002277TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 Base::SendEarlyRtcpMuxToRtcpMux();
2279}
2280
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002281TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2283}
2284
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002285TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 Base::SendSrtpToSrtp();
2287}
2288
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002289TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2291}
2292
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002293TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2295 Base::SendSrtpToSrtp(DTLS, 0);
2296}
2297
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002298TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2300 Base::SendSrtpToSrtp(DTLS, DTLS);
2301}
2302
jbauchcb560652016-08-04 05:20:32 -07002303TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2304 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2305 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2306}
2307
2308TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2309 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2310 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2311}
2312
2313TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2314 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2315 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2316}
2317
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002318TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2320 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2321}
2322
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002323TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2325}
2326
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002327TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 Base::SendRtpToRtpOnThread();
2329}
2330
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002331TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 Base::SendSrtpToSrtpOnThread();
2333}
2334
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002335TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 Base::SendWithWritabilityLoss();
2337}
2338
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002339TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 Base::TestMediaMonitor();
2341}
2342
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002344TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 CreateChannels(0, 0);
2346 EXPECT_TRUE(SendInitiate());
2347 EXPECT_TRUE(SendAccept());
2348 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2349
solenberg1d63dd02015-12-02 12:35:09 -08002350 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2351 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2352 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002354 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002356 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002357 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002358 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002359 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002360 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361}
2362
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002363TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 Base::TestSetContentFailure();
2365}
2366
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002367TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 Base::TestSendTwoOffers();
2369}
2370
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002371TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 Base::TestReceiveTwoOffers();
2373}
2374
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002375TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 Base::TestSendPrAnswer();
2377}
2378
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002379TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 Base::TestReceivePrAnswer();
2381}
2382
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002383TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 Base::TestFlushRtcp();
2385}
2386
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002387TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002388 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389}
2390
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002391TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392 Base::TestOnReadyToSend();
2393}
2394
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002395TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 Base::TestOnReadyToSendWithRtcpMux();
2397}
2398
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002400TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401 CreateChannels(RTCP, RTCP);
2402 EXPECT_TRUE(SendInitiate());
2403 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002404 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405
solenberg4bac9c52015-10-09 02:32:53 -07002406 // Default is (1.0).
2407 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2408 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002410 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411
solenberg4bac9c52015-10-09 02:32:53 -07002412 // Set scale to (1.5).
2413 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2414 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2415 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416
solenberg4bac9c52015-10-09 02:32:53 -07002417 // Set scale to (0).
2418 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2419 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2420 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421}
2422
2423// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002424TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 CreateChannels(RTCP, RTCP);
2426 EXPECT_TRUE(SendInitiate());
2427 EXPECT_TRUE(SendAccept());
2428 EXPECT_TRUE(AddStream1(1));
2429 EXPECT_TRUE(AddStream1(2));
2430
solenberg4bac9c52015-10-09 02:32:53 -07002431 double volume;
2432 // Default is (1.0).
2433 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2434 EXPECT_DOUBLE_EQ(1.0, volume);
2435 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2436 EXPECT_DOUBLE_EQ(1.0, volume);
2437 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2438 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002440 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441
solenberg4bac9c52015-10-09 02:32:53 -07002442 // Set scale to (1.5) for ssrc = 1.
2443 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2444 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2445 EXPECT_DOUBLE_EQ(1.5, volume);
2446 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2447 EXPECT_DOUBLE_EQ(1.0, volume);
2448 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2449 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450
solenberg4bac9c52015-10-09 02:32:53 -07002451 // Set scale to (0) for all ssrcs.
2452 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2453 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2454 EXPECT_DOUBLE_EQ(0.0, volume);
2455 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2456 EXPECT_DOUBLE_EQ(0.0, volume);
2457 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2458 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459}
2460
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002461TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002462 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463}
2464
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002465TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002466 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002467}
2468
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002469TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002470 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002471}
2472
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002473TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002474 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475}
2476
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002477TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002478 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002479}
2480
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002481TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002482 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002483}
2484
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002485// VoiceChannelDoubleThreadTest
2486TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002488 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2489 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490}
2491
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002492TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2493 Base::TestDeinit();
2494}
2495
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002496TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 Base::TestSetContents();
2498}
2499
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002500TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 Base::TestSetContentsNullOffer();
2502}
2503
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002504TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 Base::TestSetContentsRtcpMux();
2506}
2507
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002508TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 Base::TestSetContentsRtcpMux();
2510}
2511
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002512TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 Base::TestSetRemoteContentUpdate();
2514}
2515
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002516TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517 Base::TestStreams();
2518}
2519
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002520TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 Base::TestUpdateStreamsInLocalContent();
2522}
2523
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002524TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 Base::TestUpdateStreamsInRemoteContent();
2526}
2527
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002528TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529 Base::TestChangeStreamParamsInContent();
2530}
2531
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002532TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002533 Base::TestPlayoutAndSendingStates();
2534}
2535
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002536TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2537 CreateChannels(0, 0);
2538 // Test that we can Mute the default channel even though the sending SSRC
2539 // is unknown.
2540 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2541 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2542 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2543 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2544 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2545
2546 // Test that we can not mute an unknown SSRC.
2547 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2548
2549 SendInitiate();
2550 // After the local session description has been set, we can mute a stream
2551 // with its SSRC.
2552 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2553 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2554 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2555 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2556}
2557
2558TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2559 Base::TestMediaContentDirection();
2560}
2561
2562TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2563 Base::TestNetworkRouteChanges();
2564}
2565
2566TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2567 Base::TestCallSetup();
2568}
2569
2570TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2571 Base::TestCallTeardownRtcpMux();
2572}
2573
2574TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2575 Base::SendRtpToRtp();
2576}
2577
2578TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2579 Base::SendNoRtcpToNoRtcp();
2580}
2581
2582TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2583 Base::SendNoRtcpToRtcp();
2584}
2585
2586TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2587 Base::SendRtcpToNoRtcp();
2588}
2589
2590TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2591 Base::SendRtcpToRtcp();
2592}
2593
2594TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2595 Base::SendRtcpMuxToRtcp();
2596}
2597
2598TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2599 Base::SendRtcpMuxToRtcpMux();
2600}
2601
2602TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2603 Base::SendRequireRtcpMuxToRtcpMux();
2604}
2605
2606TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2607 Base::SendRtcpMuxToRequireRtcpMux();
2608}
2609
2610TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2611 Base::SendRequireRtcpMuxToRequireRtcpMux();
2612}
2613
2614TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2615 Base::SendRequireRtcpMuxToNoRtcpMux();
2616}
2617
2618TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2619 Base::SendEarlyRtcpMuxToRtcp();
2620}
2621
2622TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2623 Base::SendEarlyRtcpMuxToRtcpMux();
2624}
2625
2626TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2627 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2628}
2629
2630TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2631 Base::SendSrtpToSrtp();
2632}
2633
2634TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2635 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2636}
2637
2638TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2639 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2640 Base::SendSrtpToSrtp(DTLS, 0);
2641}
2642
2643TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2644 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2645 Base::SendSrtpToSrtp(DTLS, DTLS);
2646}
2647
jbauchcb560652016-08-04 05:20:32 -07002648TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2649 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2650 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2651}
2652
2653TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2654 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2655 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2656}
2657
2658TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2659 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2660 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2661}
2662
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002663TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2664 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2665 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2666}
2667
2668TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2669 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2670}
2671
2672TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2673 Base::SendRtpToRtpOnThread();
2674}
2675
2676TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2677 Base::SendSrtpToSrtpOnThread();
2678}
2679
2680TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2681 Base::SendWithWritabilityLoss();
2682}
2683
2684TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2685 Base::TestMediaMonitor();
2686}
2687
2688// Test that InsertDtmf properly forwards to the media channel.
2689TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2690 CreateChannels(0, 0);
2691 EXPECT_TRUE(SendInitiate());
2692 EXPECT_TRUE(SendAccept());
2693 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2694
2695 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2696 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2697 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2698
2699 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2700 EXPECT_TRUE(
2701 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2702 EXPECT_TRUE(
2703 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2704 EXPECT_TRUE(
2705 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2706}
2707
2708TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2709 Base::TestSetContentFailure();
2710}
2711
2712TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2713 Base::TestSendTwoOffers();
2714}
2715
2716TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2717 Base::TestReceiveTwoOffers();
2718}
2719
2720TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2721 Base::TestSendPrAnswer();
2722}
2723
2724TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2725 Base::TestReceivePrAnswer();
2726}
2727
2728TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2729 Base::TestFlushRtcp();
2730}
2731
2732TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2733 Base::TestSrtpError(kAudioPts[0]);
2734}
2735
2736TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2737 Base::TestOnReadyToSend();
2738}
2739
2740TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2741 Base::TestOnReadyToSendWithRtcpMux();
2742}
2743
2744// Test that we can scale the output volume properly for 1:1 calls.
2745TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2746 CreateChannels(RTCP, RTCP);
2747 EXPECT_TRUE(SendInitiate());
2748 EXPECT_TRUE(SendAccept());
2749 double volume;
2750
2751 // Default is (1.0).
2752 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2753 EXPECT_DOUBLE_EQ(1.0, volume);
2754 // invalid ssrc.
2755 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2756
2757 // Set scale to (1.5).
2758 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2759 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2760 EXPECT_DOUBLE_EQ(1.5, volume);
2761
2762 // Set scale to (0).
2763 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2764 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2765 EXPECT_DOUBLE_EQ(0.0, volume);
2766}
2767
2768// Test that we can scale the output volume properly for multiway calls.
2769TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2770 CreateChannels(RTCP, RTCP);
2771 EXPECT_TRUE(SendInitiate());
2772 EXPECT_TRUE(SendAccept());
2773 EXPECT_TRUE(AddStream1(1));
2774 EXPECT_TRUE(AddStream1(2));
2775
2776 double volume;
2777 // Default is (1.0).
2778 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2779 EXPECT_DOUBLE_EQ(1.0, volume);
2780 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2781 EXPECT_DOUBLE_EQ(1.0, volume);
2782 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2783 EXPECT_DOUBLE_EQ(1.0, volume);
2784 // invalid ssrc.
2785 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2786
2787 // Set scale to (1.5) for ssrc = 1.
2788 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2789 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2790 EXPECT_DOUBLE_EQ(1.5, volume);
2791 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2792 EXPECT_DOUBLE_EQ(1.0, volume);
2793 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2794 EXPECT_DOUBLE_EQ(1.0, volume);
2795
2796 // Set scale to (0) for all ssrcs.
2797 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2798 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2799 EXPECT_DOUBLE_EQ(0.0, volume);
2800 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2801 EXPECT_DOUBLE_EQ(0.0, volume);
2802 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2803 EXPECT_DOUBLE_EQ(0.0, volume);
2804}
2805
2806TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2807 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2808}
2809
2810TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2811 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2812}
2813
2814TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2815 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2816}
2817
2818TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2819 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2820}
2821
2822TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2823 Base::DefaultMaxBitrateIsUnlimited();
2824}
2825
2826TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2827 Base::CanChangeMaxBitrate();
2828}
2829
2830// VideoChannelSingleThreadTest
2831TEST_F(VideoChannelSingleThreadTest, TestInit) {
2832 Base::TestInit();
2833}
2834
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002835TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2836 Base::TestDeinit();
2837}
2838
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002839TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2840 Base::TestSetContents();
2841}
2842
2843TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2844 Base::TestSetContentsNullOffer();
2845}
2846
2847TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2848 Base::TestSetContentsRtcpMux();
2849}
2850
2851TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2852 Base::TestSetContentsRtcpMux();
2853}
2854
2855TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2856 Base::TestSetRemoteContentUpdate();
2857}
2858
2859TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2860 Base::TestStreams();
2861}
2862
2863TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2864 Base::TestUpdateStreamsInLocalContent();
2865}
2866
2867TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2868 Base::TestUpdateStreamsInRemoteContent();
2869}
2870
2871TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2872 Base::TestChangeStreamParamsInContent();
2873}
2874
2875TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2876 Base::TestPlayoutAndSendingStates();
2877}
2878
2879TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002880 CreateChannels(0, 0);
2881 // Test that we can Mute the default channel even though the sending SSRC
2882 // is unknown.
2883 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002884 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002885 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002886 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002887 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2888 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002889 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002890 SendInitiate();
2891 // After the local session description has been set, we can mute a stream
2892 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002893 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002894 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002895 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002896 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897}
2898
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002899TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002900 Base::TestMediaContentDirection();
2901}
2902
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002903TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002904 Base::TestNetworkRouteChanges();
2905}
2906
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002907TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 Base::TestCallSetup();
2909}
2910
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002911TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002912 Base::TestCallTeardownRtcpMux();
2913}
2914
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002915TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916 Base::SendRtpToRtp();
2917}
2918
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002919TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920 Base::SendNoRtcpToNoRtcp();
2921}
2922
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002923TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002924 Base::SendNoRtcpToRtcp();
2925}
2926
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002927TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928 Base::SendRtcpToNoRtcp();
2929}
2930
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002931TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002932 Base::SendRtcpToRtcp();
2933}
2934
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002935TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002936 Base::SendRtcpMuxToRtcp();
2937}
2938
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002939TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002940 Base::SendRtcpMuxToRtcpMux();
2941}
2942
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002943TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002944 Base::SendRequireRtcpMuxToRtcpMux();
2945}
2946
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002947TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002948 Base::SendRtcpMuxToRequireRtcpMux();
2949}
2950
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002951TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002952 Base::SendRequireRtcpMuxToRequireRtcpMux();
2953}
2954
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002955TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002956 Base::SendRequireRtcpMuxToNoRtcpMux();
2957}
2958
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002959TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002960 Base::SendEarlyRtcpMuxToRtcp();
2961}
2962
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002963TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964 Base::SendEarlyRtcpMuxToRtcpMux();
2965}
2966
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002967TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002968 Base::SendSrtpToSrtp();
2969}
2970
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002971TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002972 Base::SendSrtpToSrtp();
2973}
2974
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002975TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2977 Base::SendSrtpToSrtp(DTLS, 0);
2978}
2979
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002980TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002981 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2982 Base::SendSrtpToSrtp(DTLS, DTLS);
2983}
2984
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002985TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002986 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2987 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2988}
2989
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002990TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2992}
2993
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002994TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002995 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2996}
2997
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002998TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002999 Base::SendRtpToRtpOnThread();
3000}
3001
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003002TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003 Base::SendSrtpToSrtpOnThread();
3004}
3005
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003006TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003007 Base::SendWithWritabilityLoss();
3008}
3009
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003010TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003011 Base::TestMediaMonitor();
3012}
3013
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003014TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015 Base::TestSetContentFailure();
3016}
3017
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003018TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003019 Base::TestSendTwoOffers();
3020}
3021
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003022TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023 Base::TestReceiveTwoOffers();
3024}
3025
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003026TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003027 Base::TestSendPrAnswer();
3028}
3029
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003030TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031 Base::TestReceivePrAnswer();
3032}
3033
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003034TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035 Base::TestFlushRtcp();
3036}
3037
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003038TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08003039 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003040}
3041
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003042TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003043 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003044}
3045
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003046TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08003047 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003048}
3049
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003050TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003051 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052}
3053
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003054TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003055 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003056}
3057
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003058TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059 Base::TestOnReadyToSend();
3060}
3061
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003062TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003063 Base::TestOnReadyToSendWithRtcpMux();
3064}
3065
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003066TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003067 Base::DefaultMaxBitrateIsUnlimited();
3068}
3069
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003070TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003071 Base::CanChangeMaxBitrate();
3072}
3073
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003074// VideoChannelDoubleThreadTest
3075TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3076 Base::TestInit();
3077}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003079TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3080 Base::TestDeinit();
3081}
3082
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003083TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3084 Base::TestSetContents();
3085}
3086
3087TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3088 Base::TestSetContentsNullOffer();
3089}
3090
3091TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3092 Base::TestSetContentsRtcpMux();
3093}
3094
3095TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3096 Base::TestSetContentsRtcpMux();
3097}
3098
3099TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3100 Base::TestSetRemoteContentUpdate();
3101}
3102
3103TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3104 Base::TestStreams();
3105}
3106
3107TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3108 Base::TestUpdateStreamsInLocalContent();
3109}
3110
3111TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3112 Base::TestUpdateStreamsInRemoteContent();
3113}
3114
3115TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3116 Base::TestChangeStreamParamsInContent();
3117}
3118
3119TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3120 Base::TestPlayoutAndSendingStates();
3121}
3122
3123TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3124 CreateChannels(0, 0);
3125 // Test that we can Mute the default channel even though the sending SSRC
3126 // is unknown.
3127 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003128 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003129 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003130 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003131 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3132 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003133 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003134 SendInitiate();
3135 // After the local session description has been set, we can mute a stream
3136 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003137 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003138 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003139 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003140 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3141}
3142
3143TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3144 Base::TestMediaContentDirection();
3145}
3146
3147TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3148 Base::TestNetworkRouteChanges();
3149}
3150
3151TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3152 Base::TestCallSetup();
3153}
3154
3155TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3156 Base::TestCallTeardownRtcpMux();
3157}
3158
3159TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3160 Base::SendRtpToRtp();
3161}
3162
3163TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3164 Base::SendNoRtcpToNoRtcp();
3165}
3166
3167TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3168 Base::SendNoRtcpToRtcp();
3169}
3170
3171TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3172 Base::SendRtcpToNoRtcp();
3173}
3174
3175TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3176 Base::SendRtcpToRtcp();
3177}
3178
3179TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3180 Base::SendRtcpMuxToRtcp();
3181}
3182
3183TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3184 Base::SendRtcpMuxToRtcpMux();
3185}
3186
3187TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3188 Base::SendRequireRtcpMuxToRtcpMux();
3189}
3190
3191TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3192 Base::SendRtcpMuxToRequireRtcpMux();
3193}
3194
3195TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3196 Base::SendRequireRtcpMuxToRequireRtcpMux();
3197}
3198
3199TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3200 Base::SendRequireRtcpMuxToNoRtcpMux();
3201}
3202
3203TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3204 Base::SendEarlyRtcpMuxToRtcp();
3205}
3206
3207TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3208 Base::SendEarlyRtcpMuxToRtcpMux();
3209}
3210
3211TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3212 Base::SendSrtpToSrtp();
3213}
3214
3215TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3216 Base::SendSrtpToSrtp();
3217}
3218
3219TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3220 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3221 Base::SendSrtpToSrtp(DTLS, 0);
3222}
3223
3224TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3225 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3226 Base::SendSrtpToSrtp(DTLS, DTLS);
3227}
3228
3229TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3230 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3231 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3232}
3233
3234TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3235 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3236}
3237
3238TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3239 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3240}
3241
3242TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3243 Base::SendRtpToRtpOnThread();
3244}
3245
3246TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3247 Base::SendSrtpToSrtpOnThread();
3248}
3249
3250TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3251 Base::SendWithWritabilityLoss();
3252}
3253
3254TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3255 Base::TestMediaMonitor();
3256}
3257
3258TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3259 Base::TestSetContentFailure();
3260}
3261
3262TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3263 Base::TestSendTwoOffers();
3264}
3265
3266TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3267 Base::TestReceiveTwoOffers();
3268}
3269
3270TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3271 Base::TestSendPrAnswer();
3272}
3273
3274TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3275 Base::TestReceivePrAnswer();
3276}
3277
3278TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3279 Base::TestFlushRtcp();
3280}
3281
3282TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3283 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3284}
3285
3286TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3287 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3288}
3289
3290TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3291 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3292}
3293
3294TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3295 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3296}
3297
3298TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3299 Base::TestSrtpError(kVideoPts[0]);
3300}
3301
3302TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3303 Base::TestOnReadyToSend();
3304}
3305
3306TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3307 Base::TestOnReadyToSendWithRtcpMux();
3308}
3309
3310TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3311 Base::DefaultMaxBitrateIsUnlimited();
3312}
3313
3314TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3315 Base::CanChangeMaxBitrate();
3316}
3317
3318// DataChannelSingleThreadTest
3319class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003321 typedef ChannelTest<DataTraits> Base;
3322 DataChannelSingleThreadTest()
3323 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3324};
3325
3326// DataChannelDoubleThreadTest
3327class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3328 public:
3329 typedef ChannelTest<DataTraits> Base;
3330 DataChannelDoubleThreadTest()
3331 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003332};
3333
3334// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003335template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003337 rtc::Thread* worker_thread,
3338 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003339 cricket::MediaEngineInterface* engine,
3340 cricket::FakeDataMediaChannel* ch,
3341 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003342 int flags) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003343 cricket::DataChannel* channel =
3344 new cricket::DataChannel(worker_thread, network_thread, ch,
jbauchcb560652016-08-04 05:20:32 -07003345 transport_controller, cricket::CN_DATA,
3346 (flags & RTCP) != 0);
3347 rtc::CryptoOptions crypto_options;
3348 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3349 channel->SetCryptoOptions(crypto_options);
skvlad6c87a672016-05-17 17:49:52 -07003350 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351 delete channel;
3352 channel = NULL;
3353 }
3354 return channel;
3355}
3356
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003357template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358void ChannelTest<DataTraits>::CreateContent(
3359 int flags,
3360 const cricket::AudioCodec& audio_codec,
3361 const cricket::VideoCodec& video_codec,
3362 cricket::DataContentDescription* data) {
3363 data->AddCodec(kGoogleDataCodec);
3364 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3365 if (flags & SECURE) {
3366 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003367 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3368 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003369 }
3370}
3371
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003372template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003373void ChannelTest<DataTraits>::CopyContent(
3374 const cricket::DataContentDescription& source,
3375 cricket::DataContentDescription* data) {
3376 *data = source;
3377}
3378
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003379template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3381 const cricket::DataCodec& c2) {
3382 return c1.name == c2.name;
3383}
3384
Peter Boström0c4e06b2015-10-07 12:23:21 +02003385template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003387 uint32_t ssrc,
3388 int flags,
3389 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390 data->AddLegacyStream(ssrc);
3391}
3392
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003393TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 Base::TestInit();
3395 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3396}
3397
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003398TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3399 Base::TestDeinit();
3400}
3401
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003402TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003403 Base::TestSetContents();
3404}
3405
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003406TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003407 Base::TestSetContentsNullOffer();
3408}
3409
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003410TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411 Base::TestSetContentsRtcpMux();
3412}
3413
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003414TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415 Base::TestSetRemoteContentUpdate();
3416}
3417
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003418TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003419 Base::TestStreams();
3420}
3421
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003422TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423 Base::TestUpdateStreamsInLocalContent();
3424}
3425
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003426TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427 Base::TestUpdateStreamsInRemoteContent();
3428}
3429
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003430TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431 Base::TestChangeStreamParamsInContent();
3432}
3433
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003434TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 Base::TestPlayoutAndSendingStates();
3436}
3437
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003438TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003439 Base::TestMediaContentDirection();
3440}
3441
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003442TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 Base::TestCallSetup();
3444}
3445
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003446TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003447 Base::TestCallTeardownRtcpMux();
3448}
3449
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003450TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 Base::TestOnReadyToSend();
3452}
3453
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003454TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455 Base::TestOnReadyToSendWithRtcpMux();
3456}
3457
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003458TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 Base::SendRtpToRtp();
3460}
3461
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003462TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003463 Base::SendNoRtcpToNoRtcp();
3464}
3465
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003466TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003467 Base::SendNoRtcpToRtcp();
3468}
3469
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003470TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003471 Base::SendRtcpToNoRtcp();
3472}
3473
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003474TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475 Base::SendRtcpToRtcp();
3476}
3477
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003478TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003479 Base::SendRtcpMuxToRtcp();
3480}
3481
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003482TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483 Base::SendRtcpMuxToRtcpMux();
3484}
3485
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003486TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003487 Base::SendEarlyRtcpMuxToRtcp();
3488}
3489
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003490TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491 Base::SendEarlyRtcpMuxToRtcpMux();
3492}
3493
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003494TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 Base::SendSrtpToSrtp();
3496}
3497
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003498TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499 Base::SendSrtpToSrtp();
3500}
3501
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003502TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3504}
3505
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003506TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507 Base::SendRtpToRtpOnThread();
3508}
3509
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003510TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511 Base::SendSrtpToSrtpOnThread();
3512}
3513
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003514TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515 Base::SendWithWritabilityLoss();
3516}
3517
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003518TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003519 Base::TestMediaMonitor();
3520}
3521
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003522TEST_F(DataChannelSingleThreadTest, TestSendData) {
3523 CreateChannels(0, 0);
3524 EXPECT_TRUE(SendInitiate());
3525 EXPECT_TRUE(SendAccept());
3526
3527 cricket::SendDataParams params;
3528 params.ssrc = 42;
3529 unsigned char data[] = {'f', 'o', 'o'};
3530 rtc::CopyOnWriteBuffer payload(data, 3);
3531 cricket::SendDataResult result;
3532 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3533 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3534 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3535}
3536
3537TEST_F(DataChannelDoubleThreadTest, TestInit) {
3538 Base::TestInit();
3539 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3540}
3541
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003542TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3543 Base::TestDeinit();
3544}
3545
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003546TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3547 Base::TestSetContents();
3548}
3549
3550TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3551 Base::TestSetContentsNullOffer();
3552}
3553
3554TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3555 Base::TestSetContentsRtcpMux();
3556}
3557
3558TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3559 Base::TestSetRemoteContentUpdate();
3560}
3561
3562TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3563 Base::TestStreams();
3564}
3565
3566TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3567 Base::TestUpdateStreamsInLocalContent();
3568}
3569
3570TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3571 Base::TestUpdateStreamsInRemoteContent();
3572}
3573
3574TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3575 Base::TestChangeStreamParamsInContent();
3576}
3577
3578TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3579 Base::TestPlayoutAndSendingStates();
3580}
3581
3582TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3583 Base::TestMediaContentDirection();
3584}
3585
3586TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3587 Base::TestCallSetup();
3588}
3589
3590TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3591 Base::TestCallTeardownRtcpMux();
3592}
3593
3594TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3595 Base::TestOnReadyToSend();
3596}
3597
3598TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3599 Base::TestOnReadyToSendWithRtcpMux();
3600}
3601
3602TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3603 Base::SendRtpToRtp();
3604}
3605
3606TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3607 Base::SendNoRtcpToNoRtcp();
3608}
3609
3610TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3611 Base::SendNoRtcpToRtcp();
3612}
3613
3614TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3615 Base::SendRtcpToNoRtcp();
3616}
3617
3618TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3619 Base::SendRtcpToRtcp();
3620}
3621
3622TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3623 Base::SendRtcpMuxToRtcp();
3624}
3625
3626TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3627 Base::SendRtcpMuxToRtcpMux();
3628}
3629
3630TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3631 Base::SendEarlyRtcpMuxToRtcp();
3632}
3633
3634TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3635 Base::SendEarlyRtcpMuxToRtcpMux();
3636}
3637
3638TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3639 Base::SendSrtpToSrtp();
3640}
3641
3642TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3643 Base::SendSrtpToSrtp();
3644}
3645
3646TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3647 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3648}
3649
3650TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3651 Base::SendRtpToRtpOnThread();
3652}
3653
3654TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3655 Base::SendSrtpToSrtpOnThread();
3656}
3657
3658TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3659 Base::SendWithWritabilityLoss();
3660}
3661
3662TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3663 Base::TestMediaMonitor();
3664}
3665
3666TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667 CreateChannels(0, 0);
3668 EXPECT_TRUE(SendInitiate());
3669 EXPECT_TRUE(SendAccept());
3670
3671 cricket::SendDataParams params;
3672 params.ssrc = 42;
3673 unsigned char data[] = {
3674 'f', 'o', 'o'
3675 };
jbaucheec21bd2016-03-20 06:15:43 -07003676 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003677 cricket::SendDataResult result;
3678 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3679 EXPECT_EQ(params.ssrc,
3680 media_channel1_->last_sent_data_params().ssrc);
3681 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3682}
3683
3684// TODO(pthatcher): TestSetReceiver?