blob: b36dcd131a31c1dad2415fef1104dbf4aa311ad7 [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"
kjellandera96e2d72016-02-04 23:52:28 -080018#include "webrtc/media/base/fakemediaengine.h"
19#include "webrtc/media/base/fakertp.h"
kjellandera96e2d72016-02-04 23:52:28 -080020#include "webrtc/media/base/mediachannel.h"
kjellandera96e2d72016-02-04 23:52:28 -080021#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010022#include "webrtc/p2p/base/faketransportcontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010023#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000024
25#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027 LOG(LS_INFO) << "Feature disabled... skipping"; \
28 return; \
29 }
30
31using cricket::CA_OFFER;
32using cricket::CA_PRANSWER;
33using cricket::CA_ANSWER;
34using cricket::CA_UPDATE;
35using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036using cricket::ScreencastId;
37using 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);
44const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30);
45const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15);
46const 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,
97 DTLS = 0x10 };
98
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,
138 transport_controller1_.get(), (flags1 & RTCP) != 0));
139 channel2_.reset(
140 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
141 transport_controller2_.get(), (flags2 & RTCP) != 0));
142 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,
190 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200191 typename T::Channel* channel =
192 new typename T::Channel(worker_thread, network_thread, engine, ch,
193 transport_controller, cricket::CN_AUDIO, rtcp);
skvlad6c87a672016-05-17 17:49:52 -0700194 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 delete channel;
196 channel = NULL;
197 }
198 return channel;
199 }
200
201 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000202 bool result = channel1_->SetLocalContent(&local_media_content1_,
203 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 if (result) {
205 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000206 result = channel2_->SetRemoteContent(&remote_media_content1_,
207 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200209 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000211 result = channel2_->SetLocalContent(&local_media_content2_,
212 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 }
214 }
215 return result;
216 }
217
218 bool SendAccept() {
219 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000220 return channel1_->SetRemoteContent(&remote_media_content2_,
221 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 }
223
224 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000225 bool result = channel1_->SetLocalContent(&local_media_content1_,
226 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 if (result) {
228 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000229 result = channel2_->SetRemoteContent(&remote_media_content1_,
230 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 }
232 return result;
233 }
234
235 bool SendProvisionalAnswer() {
236 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000237 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 if (result) {
239 channel2_->Enable(true);
240 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000241 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200242 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 }
244 return result;
245 }
246
247 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000248 bool result = channel2_->SetLocalContent(&local_media_content2_,
249 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000251 result = channel1_->SetRemoteContent(&remote_media_content2_,
252 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 return result;
254 }
255
256 bool SendTerminate() {
257 channel1_.reset();
258 channel2_.reset();
259 return true;
260 }
261
262 bool AddStream1(int id) {
263 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
264 }
265 bool RemoveStream1(int id) {
266 return channel1_->RemoveRecvStream(id);
267 }
268
269 cricket::FakeTransport* GetTransport1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200270 std::string name = channel1_->content_name();
271 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700272 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200273 [this, name] { return transport_controller1_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 }
275 cricket::FakeTransport* GetTransport2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200276 std::string name = channel2_->content_name();
277 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700278 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200279 [this, name] { return transport_controller2_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 }
281
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200282 void SendRtp1() {
283 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
284 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200286 void SendRtp2() {
287 media_channel2_->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 SendRtcp1() {
291 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200293 void SendRtcp2() {
294 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 }
296 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200297 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
298 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
299 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200301 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
302 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
303 media_channel2_->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 SendCustomRtcp1(uint32_t ssrc) {
306 rtc::Buffer data = CreateRtcpData(ssrc);
307 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200309 void SendCustomRtcp2(uint32_t ssrc) {
310 rtc::Buffer data = CreateRtcpData(ssrc);
311 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200313
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200315 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
317 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200318 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 }
320 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200321 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
323 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200324 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 }
326 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200327 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200328 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
329 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200331 bool CheckCustomRtp2(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_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200335 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200336 rtc::Buffer data = CreateRtcpData(ssrc);
337 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200339 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200340 rtc::Buffer data = CreateRtcpData(ssrc);
341 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200343 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
344 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200346 rtc::SetBE32(data.data() + 8, ssrc);
347 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000348 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200349 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000350 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 return data;
352 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200353 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
354 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200356 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 return data;
358 }
359
360 bool CheckNoRtp1() {
361 return media_channel1_->CheckNoRtp();
362 }
363 bool CheckNoRtp2() {
364 return media_channel2_->CheckNoRtp();
365 }
366 bool CheckNoRtcp1() {
367 return media_channel1_->CheckNoRtcp();
368 }
369 bool CheckNoRtcp2() {
370 return media_channel2_->CheckNoRtcp();
371 }
372
373 void CreateContent(int flags,
374 const cricket::AudioCodec& audio_codec,
375 const cricket::VideoCodec& video_codec,
376 typename T::Content* content) {
377 // overridden in specialized classes
378 }
379 void CopyContent(const typename T::Content& source,
380 typename T::Content* content) {
381 // overridden in specialized classes
382 }
383
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 // Creates a cricket::SessionDescription with one MediaContent and one stream.
385 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200386 cricket::SessionDescription* CreateSessionDescriptionWithStream(
387 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 typename T::Content content;
389 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
390 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
391 AddLegacyStreamInContent(ssrc, 0, &content);
392 sdesc->AddContent("DUMMY_CONTENT_NAME",
393 cricket::NS_JINGLE_RTP, content.Copy());
394 return sdesc;
395 }
396
ossu292d6582016-03-17 02:31:13 -0700397 // Will manage the lifetime of a CallThread, making sure it's
398 // destroyed before this object goes out of scope.
399 class ScopedCallThread {
400 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200401 template <class FunctorT>
402 ScopedCallThread(const FunctorT& functor)
403 : thread_(rtc::Thread::Create()),
404 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700405 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700406 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700407 }
408
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200409 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700410
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200411 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700412
413 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200414 std::unique_ptr<rtc::Thread> thread_;
415 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700416 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
419 return false; // overridden in specialized classes
420 }
421
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200422 void OnMediaMonitor1(typename T::Channel* channel,
423 const typename T::MediaInfo& info) {
424 RTC_DCHECK_EQ(channel, channel1_.get());
425 media_info_callbacks1_++;
426 }
427 void OnMediaMonitor2(typename T::Channel* channel,
428 const typename T::MediaInfo& info) {
429 RTC_DCHECK_EQ(channel, channel2_.get());
430 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 }
432
Honghai Zhangcc411c02016-03-29 17:27:21 -0700433 cricket::CandidatePairInterface* last_selected_candidate_pair() {
434 return last_selected_candidate_pair_;
435 }
436
Peter Boström0c4e06b2015-10-07 12:23:21 +0200437 void AddLegacyStreamInContent(uint32_t ssrc,
438 int flags,
439 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 // Base implementation.
441 }
442
443 // Tests that can be used by derived classes.
444
445 // Basic sanity check.
446 void TestInit() {
447 CreateChannels(0, 0);
448 EXPECT_FALSE(channel1_->secure());
449 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200450 if (verify_playout_) {
451 EXPECT_FALSE(media_channel1_->playout());
452 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 EXPECT_TRUE(media_channel1_->codecs().empty());
454 EXPECT_TRUE(media_channel1_->recv_streams().empty());
455 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
456 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
457 }
458
459 // Test that SetLocalContent and SetRemoteContent properly configure
460 // the codecs.
461 void TestSetContents() {
462 CreateChannels(0, 0);
463 typename T::Content content;
464 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000465 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000467 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 ASSERT_EQ(1U, media_channel1_->codecs().size());
469 EXPECT_TRUE(CodecMatches(content.codecs()[0],
470 media_channel1_->codecs()[0]));
471 }
472
473 // Test that SetLocalContent and SetRemoteContent properly deals
474 // with an empty offer.
475 void TestSetContentsNullOffer() {
476 CreateChannels(0, 0);
477 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000478 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 CreateContent(0, kPcmuCodec, kH264Codec, &content);
480 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000481 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 ASSERT_EQ(1U, media_channel1_->codecs().size());
483 EXPECT_TRUE(CodecMatches(content.codecs()[0],
484 media_channel1_->codecs()[0]));
485 }
486
487 // Test that SetLocalContent and SetRemoteContent properly set RTCP
488 // mux.
489 void TestSetContentsRtcpMux() {
490 CreateChannels(RTCP, RTCP);
491 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
492 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
493 typename T::Content content;
494 CreateContent(0, kPcmuCodec, kH264Codec, &content);
495 // Both sides agree on mux. Should no longer be a separate RTCP channel.
496 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000497 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
498 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
500 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000501 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000503 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
505 }
506
507 // Test that SetLocalContent and SetRemoteContent properly set RTCP
508 // mux when a provisional answer is received.
509 void TestSetContentsRtcpMuxWithPrAnswer() {
510 CreateChannels(RTCP, RTCP);
511 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
512 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
513 typename T::Content content;
514 CreateContent(0, kPcmuCodec, kH264Codec, &content);
515 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_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000519 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 // Both sides agree on mux. Should no longer be a separate RTCP channel.
521 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
522 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000523 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000525 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
526 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
528 }
529
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 // Test that SetRemoteContent properly deals with a content update.
531 void TestSetRemoteContentUpdate() {
532 CreateChannels(0, 0);
533 typename T::Content content;
534 CreateContent(RTCP | RTCP_MUX | SECURE,
535 kPcmuCodec, kH264Codec,
536 &content);
537 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000538 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
539 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 ASSERT_EQ(1U, media_channel1_->codecs().size());
541 EXPECT_TRUE(CodecMatches(content.codecs()[0],
542 media_channel1_->codecs()[0]));
543 // Now update with other codecs.
544 typename T::Content update_content;
545 update_content.set_partial(true);
546 CreateContent(0, kIsacCodec, kH264SvcCodec,
547 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000548 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 ASSERT_EQ(1U, media_channel1_->codecs().size());
550 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
551 media_channel1_->codecs()[0]));
552 // Now update without any codecs. This is ignored.
553 typename T::Content empty_content;
554 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000555 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 ASSERT_EQ(1U, media_channel1_->codecs().size());
557 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
558 media_channel1_->codecs()[0]));
559 }
560
561 // Test that Add/RemoveStream properly forward to the media channel.
562 void TestStreams() {
563 CreateChannels(0, 0);
564 EXPECT_TRUE(AddStream1(1));
565 EXPECT_TRUE(AddStream1(2));
566 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
567 EXPECT_TRUE(RemoveStream1(2));
568 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
569 EXPECT_TRUE(RemoveStream1(1));
570 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
571 }
572
573 // Test that SetLocalContent properly handles adding and removing StreamParams
574 // to the local content description.
575 // This test uses the CA_UPDATE action that don't require a full
576 // MediaContentDescription to do an update.
577 void TestUpdateStreamsInLocalContent() {
578 cricket::StreamParams stream1;
579 stream1.groupid = "group1";
580 stream1.id = "stream1";
581 stream1.ssrcs.push_back(kSsrc1);
582 stream1.cname = "stream1_cname";
583
584 cricket::StreamParams stream2;
585 stream2.groupid = "group2";
586 stream2.id = "stream2";
587 stream2.ssrcs.push_back(kSsrc2);
588 stream2.cname = "stream2_cname";
589
590 cricket::StreamParams stream3;
591 stream3.groupid = "group3";
592 stream3.id = "stream3";
593 stream3.ssrcs.push_back(kSsrc3);
594 stream3.cname = "stream3_cname";
595
596 CreateChannels(0, 0);
597 typename T::Content content1;
598 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
599 content1.AddStream(stream1);
600 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000601 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602
603 ASSERT_EQ(1u, media_channel1_->send_streams().size());
604 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
605
606 // Update the local streams by adding another sending stream.
607 // Use a partial updated session description.
608 typename T::Content content2;
609 content2.AddStream(stream2);
610 content2.AddStream(stream3);
611 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000612 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613 ASSERT_EQ(3u, media_channel1_->send_streams().size());
614 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
615 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
616 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
617
618 // Update the local streams by removing the first sending stream.
619 // This is done by removing all SSRCS for this particular stream.
620 typename T::Content content3;
621 stream1.ssrcs.clear();
622 content3.AddStream(stream1);
623 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000624 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000625 ASSERT_EQ(2u, media_channel1_->send_streams().size());
626 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
627 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
628
629 // Update the local streams with a stream that does not change.
630 // THe update is ignored.
631 typename T::Content content4;
632 content4.AddStream(stream2);
633 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000634 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635 ASSERT_EQ(2u, media_channel1_->send_streams().size());
636 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
637 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
638 }
639
640 // Test that SetRemoteContent properly handles adding and removing
641 // StreamParams to the remote content description.
642 // This test uses the CA_UPDATE action that don't require a full
643 // MediaContentDescription to do an update.
644 void TestUpdateStreamsInRemoteContent() {
645 cricket::StreamParams stream1;
646 stream1.id = "Stream1";
647 stream1.groupid = "1";
648 stream1.ssrcs.push_back(kSsrc1);
649 stream1.cname = "stream1_cname";
650
651 cricket::StreamParams stream2;
652 stream2.id = "Stream2";
653 stream2.groupid = "2";
654 stream2.ssrcs.push_back(kSsrc2);
655 stream2.cname = "stream2_cname";
656
657 cricket::StreamParams stream3;
658 stream3.id = "Stream3";
659 stream3.groupid = "3";
660 stream3.ssrcs.push_back(kSsrc3);
661 stream3.cname = "stream3_cname";
662
663 CreateChannels(0, 0);
664 typename T::Content content1;
665 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
666 content1.AddStream(stream1);
667 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669
670 ASSERT_EQ(1u, media_channel1_->codecs().size());
671 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
672 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
673
674 // Update the remote streams by adding another sending stream.
675 // Use a partial updated session description.
676 typename T::Content content2;
677 content2.AddStream(stream2);
678 content2.AddStream(stream3);
679 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000680 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
682 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
683 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
684 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
685
686 // Update the remote streams by removing the first stream.
687 // This is done by removing all SSRCS for this particular stream.
688 typename T::Content content3;
689 stream1.ssrcs.clear();
690 content3.AddStream(stream1);
691 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000692 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
694 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
695 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
696
697 // Update the remote streams with a stream that does not change.
698 // The update is ignored.
699 typename T::Content content4;
700 content4.AddStream(stream2);
701 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000702 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
704 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
705 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
706 }
707
708 // Test that SetLocalContent and SetRemoteContent properly
709 // handles adding and removing StreamParams when the action is a full
710 // CA_OFFER / CA_ANSWER.
711 void TestChangeStreamParamsInContent() {
712 cricket::StreamParams stream1;
713 stream1.groupid = "group1";
714 stream1.id = "stream1";
715 stream1.ssrcs.push_back(kSsrc1);
716 stream1.cname = "stream1_cname";
717
718 cricket::StreamParams stream2;
719 stream2.groupid = "group1";
720 stream2.id = "stream2";
721 stream2.ssrcs.push_back(kSsrc2);
722 stream2.cname = "stream2_cname";
723
724 // Setup a call where channel 1 send |stream1| to channel 2.
725 CreateChannels(0, 0);
726 typename T::Content content1;
727 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
728 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000729 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 EXPECT_TRUE(channel1_->Enable(true));
731 EXPECT_EQ(1u, media_channel1_->send_streams().size());
732
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000733 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200735 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736
737 // Channel 2 do not send anything.
738 typename T::Content content2;
739 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000740 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000742 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 EXPECT_TRUE(channel2_->Enable(true));
744 EXPECT_EQ(0u, media_channel2_->send_streams().size());
745
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200746 SendCustomRtp1(kSsrc1, 0);
747 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
749
750 // Let channel 2 update the content by sending |stream2| and enable SRTP.
751 typename T::Content content3;
752 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
753 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000754 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 ASSERT_EQ(1u, media_channel2_->send_streams().size());
756 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
757
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000758 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
760 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
761
762 // Channel 1 replies but stop sending stream1.
763 typename T::Content content4;
764 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000765 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 EXPECT_EQ(0u, media_channel1_->send_streams().size());
767
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000768 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
770
771 EXPECT_TRUE(channel1_->secure());
772 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200773 SendCustomRtp2(kSsrc2, 0);
774 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
776 }
777
778 // Test that we only start playout and sending at the right times.
779 void TestPlayoutAndSendingStates() {
780 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200781 if (verify_playout_) {
782 EXPECT_FALSE(media_channel1_->playout());
783 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200785 if (verify_playout_) {
786 EXPECT_FALSE(media_channel2_->playout());
787 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 EXPECT_FALSE(media_channel2_->sending());
789 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200790 if (verify_playout_) {
791 EXPECT_FALSE(media_channel1_->playout());
792 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000794 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
795 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200796 if (verify_playout_) {
797 EXPECT_TRUE(media_channel1_->playout());
798 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000800 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
801 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200802 if (verify_playout_) {
803 EXPECT_FALSE(media_channel2_->playout());
804 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000806 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
807 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200808 if (verify_playout_) {
809 EXPECT_FALSE(media_channel2_->playout());
810 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 EXPECT_FALSE(media_channel2_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200812 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200813 if (verify_playout_) {
814 EXPECT_TRUE(media_channel1_->playout());
815 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200817 if (verify_playout_) {
818 EXPECT_FALSE(media_channel2_->playout());
819 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 EXPECT_FALSE(media_channel2_->sending());
821 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200822 if (verify_playout_) {
823 EXPECT_TRUE(media_channel2_->playout());
824 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000826 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
827 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200828 if (verify_playout_) {
829 EXPECT_TRUE(media_channel1_->playout());
830 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 EXPECT_TRUE(media_channel1_->sending());
832 }
833
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 // Test that changing the MediaContentDirection in the local and remote
835 // session description start playout and sending at the right time.
836 void TestMediaContentDirection() {
837 CreateChannels(0, 0);
838 typename T::Content content1;
839 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
840 typename T::Content content2;
841 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
842 // Set |content2| to be InActive.
843 content2.set_direction(cricket::MD_INACTIVE);
844
845 EXPECT_TRUE(channel1_->Enable(true));
846 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200847 if (verify_playout_) {
848 EXPECT_FALSE(media_channel1_->playout());
849 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200851 if (verify_playout_) {
852 EXPECT_FALSE(media_channel2_->playout());
853 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 EXPECT_FALSE(media_channel2_->sending());
855
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000856 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
857 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
858 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
859 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200860 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861
Peter Boström34fbfff2015-09-24 19:20:30 +0200862 if (verify_playout_) {
863 EXPECT_TRUE(media_channel1_->playout());
864 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200866 if (verify_playout_) {
867 EXPECT_FALSE(media_channel2_->playout()); // local InActive
868 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 EXPECT_FALSE(media_channel2_->sending()); // local InActive
870
871 // Update |content2| to be RecvOnly.
872 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000873 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
874 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875
Peter Boström34fbfff2015-09-24 19:20:30 +0200876 if (verify_playout_) {
877 EXPECT_TRUE(media_channel1_->playout());
878 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200880 if (verify_playout_) {
881 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
884
885 // Update |content2| to be SendRecv.
886 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000887 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
888 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889
Peter Boström34fbfff2015-09-24 19:20:30 +0200890 if (verify_playout_) {
891 EXPECT_TRUE(media_channel1_->playout());
892 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200894 if (verify_playout_) {
895 EXPECT_TRUE(media_channel2_->playout());
896 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 EXPECT_TRUE(media_channel2_->sending());
898 }
899
Honghai Zhangcc411c02016-03-29 17:27:21 -0700900 // Tests that when the transport channel signals a candidate pair change
901 // event, the media channel will receive a call on the network route change.
902 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200903 constexpr uint16_t kLocalNetId = 1;
904 constexpr uint16_t kRemoteNetId = 2;
905 constexpr int kLastPacketId = 100;
906
Honghai Zhangcc411c02016-03-29 17:27:21 -0700907 CreateChannels(0, 0);
908
909 cricket::TransportChannel* transport_channel1 =
910 channel1_->transport_channel();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200911 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700912 typename T::MediaChannel* media_channel1 =
913 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200914 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700915
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200916 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700917 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200918 // The transport channel becomes disconnected.
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700919 transport_channel1->SignalSelectedCandidatePairChanged(
920 transport_channel1, nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200921 });
922 WaitForThreads();
923 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700924 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200925 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700926
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700927 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
928 media_channel1, kLocalNetId,
929 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200930 // The transport channel becomes connected.
931 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
932 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
933 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
934 transport_controller1_->CreateFakeCandidatePair(
935 local_address, kLocalNetId, remote_address, kRemoteNetId));
936 transport_channel1->SignalSelectedCandidatePairChanged(
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700937 transport_channel1, candidate_pair.get(), kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200938 });
939 WaitForThreads();
940 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700941 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200942 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700943 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200944 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700945 media_channel1->last_network_route().last_sent_packet_id);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700946 }
947
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 // Test setting up a call.
949 void TestCallSetup() {
950 CreateChannels(0, 0);
951 EXPECT_FALSE(channel1_->secure());
952 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200953 if (verify_playout_) {
954 EXPECT_TRUE(media_channel1_->playout());
955 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000956 EXPECT_FALSE(media_channel1_->sending());
957 EXPECT_TRUE(SendAccept());
958 EXPECT_FALSE(channel1_->secure());
959 EXPECT_TRUE(media_channel1_->sending());
960 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200961 if (verify_playout_) {
962 EXPECT_TRUE(media_channel2_->playout());
963 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 EXPECT_TRUE(media_channel2_->sending());
965 EXPECT_EQ(1U, media_channel2_->codecs().size());
966 }
967
968 // Test that we don't crash if packets are sent during call teardown
969 // when RTCP mux is enabled. This is a regression test against a specific
970 // race condition that would only occur when a RTCP packet was sent during
971 // teardown of a channel on which RTCP mux was enabled.
972 void TestCallTeardownRtcpMux() {
973 class LastWordMediaChannel : public T::MediaChannel {
974 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200975 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700977 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
978 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
980 }
981 };
982 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200983 RTCP | RTCP_MUX, RTCP | RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 EXPECT_TRUE(SendInitiate());
985 EXPECT_TRUE(SendAccept());
986 EXPECT_TRUE(SendTerminate());
987 }
988
989 // Send voice RTP data to the other side and ensure it gets there.
990 void SendRtpToRtp() {
991 CreateChannels(0, 0);
992 EXPECT_TRUE(SendInitiate());
993 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700994 ASSERT_TRUE(GetTransport1());
995 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 EXPECT_EQ(1U, GetTransport1()->channels().size());
997 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200998 SendRtp1();
999 SendRtp2();
1000 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 EXPECT_TRUE(CheckRtp1());
1002 EXPECT_TRUE(CheckRtp2());
1003 EXPECT_TRUE(CheckNoRtp1());
1004 EXPECT_TRUE(CheckNoRtp2());
1005 }
1006
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001007 void TestDeinit() {
1008 CreateChannels(RTCP, RTCP);
1009 EXPECT_TRUE(SendInitiate());
1010 EXPECT_TRUE(SendAccept());
1011 SendRtp1();
1012 SendRtp2();
1013 SendRtcp1();
1014 SendRtcp2();
1015 // Do not wait, destroy channels.
1016 channel1_.reset(nullptr);
1017 channel2_.reset(nullptr);
1018 }
1019
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 // Check that RTCP is not transmitted if both sides don't support RTCP.
1021 void SendNoRtcpToNoRtcp() {
1022 CreateChannels(0, 0);
1023 EXPECT_TRUE(SendInitiate());
1024 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001025 ASSERT_TRUE(GetTransport1());
1026 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001027 EXPECT_EQ(1U, GetTransport1()->channels().size());
1028 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001029 SendRtcp1();
1030 SendRtcp2();
1031 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 EXPECT_TRUE(CheckNoRtcp1());
1033 EXPECT_TRUE(CheckNoRtcp2());
1034 }
1035
1036 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1037 void SendNoRtcpToRtcp() {
1038 CreateChannels(0, RTCP);
1039 EXPECT_TRUE(SendInitiate());
1040 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001041 ASSERT_TRUE(GetTransport1());
1042 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 EXPECT_EQ(1U, GetTransport1()->channels().size());
1044 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001045 SendRtcp1();
1046 SendRtcp2();
1047 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 EXPECT_TRUE(CheckNoRtcp1());
1049 EXPECT_TRUE(CheckNoRtcp2());
1050 }
1051
1052 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1053 void SendRtcpToNoRtcp() {
1054 CreateChannels(RTCP, 0);
1055 EXPECT_TRUE(SendInitiate());
1056 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001057 ASSERT_TRUE(GetTransport1());
1058 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 EXPECT_EQ(2U, GetTransport1()->channels().size());
1060 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001061 SendRtcp1();
1062 SendRtcp2();
1063 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 EXPECT_TRUE(CheckNoRtcp1());
1065 EXPECT_TRUE(CheckNoRtcp2());
1066 }
1067
1068 // Check that RTCP is transmitted if both sides support RTCP.
1069 void SendRtcpToRtcp() {
1070 CreateChannels(RTCP, RTCP);
1071 EXPECT_TRUE(SendInitiate());
1072 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001073 ASSERT_TRUE(GetTransport1());
1074 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 EXPECT_EQ(2U, GetTransport1()->channels().size());
1076 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001077 SendRtcp1();
1078 SendRtcp2();
1079 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 EXPECT_TRUE(CheckRtcp1());
1081 EXPECT_TRUE(CheckRtcp2());
1082 EXPECT_TRUE(CheckNoRtcp1());
1083 EXPECT_TRUE(CheckNoRtcp2());
1084 }
1085
1086 // Check that RTCP is transmitted if only the initiator supports mux.
1087 void SendRtcpMuxToRtcp() {
1088 CreateChannels(RTCP | RTCP_MUX, RTCP);
1089 EXPECT_TRUE(SendInitiate());
1090 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001091 ASSERT_TRUE(GetTransport1());
1092 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 EXPECT_EQ(2U, GetTransport1()->channels().size());
1094 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001095 SendRtcp1();
1096 SendRtcp2();
1097 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 EXPECT_TRUE(CheckRtcp1());
1099 EXPECT_TRUE(CheckRtcp2());
1100 EXPECT_TRUE(CheckNoRtcp1());
1101 EXPECT_TRUE(CheckNoRtcp2());
1102 }
1103
1104 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1105 void SendRtcpMuxToRtcpMux() {
1106 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1107 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001108 ASSERT_TRUE(GetTransport1());
1109 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 EXPECT_EQ(2U, GetTransport1()->channels().size());
1111 EXPECT_EQ(1U, GetTransport2()->channels().size());
1112 EXPECT_TRUE(SendAccept());
1113 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001114 SendRtp1();
1115 SendRtp2();
1116 SendRtcp1();
1117 SendRtcp2();
1118 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 EXPECT_TRUE(CheckRtp1());
1120 EXPECT_TRUE(CheckRtp2());
1121 EXPECT_TRUE(CheckNoRtp1());
1122 EXPECT_TRUE(CheckNoRtp2());
1123 EXPECT_TRUE(CheckRtcp1());
1124 EXPECT_TRUE(CheckRtcp2());
1125 EXPECT_TRUE(CheckNoRtcp1());
1126 EXPECT_TRUE(CheckNoRtcp2());
1127 }
1128
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001129 // Check that RTP and RTCP are transmitted ok when both sides
1130 // support mux and one the offerer requires mux.
1131 void SendRequireRtcpMuxToRtcpMux() {
1132 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1133 channel1_->ActivateRtcpMux();
1134 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001135 ASSERT_TRUE(GetTransport1());
1136 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001137 EXPECT_EQ(1U, GetTransport1()->channels().size());
1138 EXPECT_EQ(1U, GetTransport2()->channels().size());
1139 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001140 SendRtp1();
1141 SendRtp2();
1142 SendRtcp1();
1143 SendRtcp2();
1144 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001145 EXPECT_TRUE(CheckRtp1());
1146 EXPECT_TRUE(CheckRtp2());
1147 EXPECT_TRUE(CheckNoRtp1());
1148 EXPECT_TRUE(CheckNoRtp2());
1149 EXPECT_TRUE(CheckRtcp1());
1150 EXPECT_TRUE(CheckRtcp2());
1151 EXPECT_TRUE(CheckNoRtcp1());
1152 EXPECT_TRUE(CheckNoRtcp2());
1153 }
1154
1155 // Check that RTP and RTCP are transmitted ok when both sides
1156 // support mux and one the answerer requires rtcp mux.
1157 void SendRtcpMuxToRequireRtcpMux() {
1158 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1159 channel2_->ActivateRtcpMux();
1160 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001161 ASSERT_TRUE(GetTransport1());
1162 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001163 EXPECT_EQ(2U, GetTransport1()->channels().size());
1164 EXPECT_EQ(1U, GetTransport2()->channels().size());
1165 EXPECT_TRUE(SendAccept());
1166 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001167 SendRtp1();
1168 SendRtp2();
1169 SendRtcp1();
1170 SendRtcp2();
1171 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001172 EXPECT_TRUE(CheckRtp1());
1173 EXPECT_TRUE(CheckRtp2());
1174 EXPECT_TRUE(CheckNoRtp1());
1175 EXPECT_TRUE(CheckNoRtp2());
1176 EXPECT_TRUE(CheckRtcp1());
1177 EXPECT_TRUE(CheckRtcp2());
1178 EXPECT_TRUE(CheckNoRtcp1());
1179 EXPECT_TRUE(CheckNoRtcp2());
1180 }
1181
1182 // Check that RTP and RTCP are transmitted ok when both sides
1183 // require mux.
1184 void SendRequireRtcpMuxToRequireRtcpMux() {
1185 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1186 channel1_->ActivateRtcpMux();
1187 channel2_->ActivateRtcpMux();
1188 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001189 ASSERT_TRUE(GetTransport1());
1190 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001191 EXPECT_EQ(1U, GetTransport1()->channels().size());
1192 EXPECT_EQ(1U, GetTransport2()->channels().size());
1193 EXPECT_TRUE(SendAccept());
1194 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001195 SendRtp1();
1196 SendRtp2();
1197 SendRtcp1();
1198 SendRtcp2();
1199 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001200 EXPECT_TRUE(CheckRtp1());
1201 EXPECT_TRUE(CheckRtp2());
1202 EXPECT_TRUE(CheckNoRtp1());
1203 EXPECT_TRUE(CheckNoRtp2());
1204 EXPECT_TRUE(CheckRtcp1());
1205 EXPECT_TRUE(CheckRtcp2());
1206 EXPECT_TRUE(CheckNoRtcp1());
1207 EXPECT_TRUE(CheckNoRtcp2());
1208 }
1209
1210 // Check that SendAccept fails if the answerer doesn't support mux
1211 // and the offerer requires it.
1212 void SendRequireRtcpMuxToNoRtcpMux() {
1213 CreateChannels(RTCP | RTCP_MUX, RTCP);
1214 channel1_->ActivateRtcpMux();
1215 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001216 ASSERT_TRUE(GetTransport1());
1217 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001218 EXPECT_EQ(1U, GetTransport1()->channels().size());
1219 EXPECT_EQ(2U, GetTransport2()->channels().size());
1220 EXPECT_FALSE(SendAccept());
1221 }
1222
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223 // Check that RTCP data sent by the initiator before the accept is not muxed.
1224 void SendEarlyRtcpMuxToRtcp() {
1225 CreateChannels(RTCP | RTCP_MUX, RTCP);
1226 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001227 ASSERT_TRUE(GetTransport1());
1228 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001229 EXPECT_EQ(2U, GetTransport1()->channels().size());
1230 EXPECT_EQ(2U, GetTransport2()->channels().size());
1231
1232 // RTCP can be sent before the call is accepted, if the transport is ready.
1233 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001234 SendRtcp1();
1235 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 EXPECT_TRUE(CheckNoRtp2());
1237 EXPECT_TRUE(CheckRtcp2());
1238
1239 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001240 SendRtcp2();
1241 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242 EXPECT_TRUE(CheckNoRtp1());
1243 EXPECT_TRUE(CheckRtcp1());
1244
1245 // Complete call setup and ensure everything is still OK.
1246 EXPECT_TRUE(SendAccept());
1247 EXPECT_EQ(2U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001248 SendRtcp1();
1249 SendRtcp2();
1250 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 EXPECT_TRUE(CheckRtcp1());
1253 }
1254
1255
1256 // Check that RTCP data is not muxed until both sides have enabled muxing,
1257 // but that we properly demux before we get the accept message, since there
1258 // is a race between RTP data and the jingle accept.
1259 void SendEarlyRtcpMuxToRtcpMux() {
1260 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1261 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001262 ASSERT_TRUE(GetTransport1());
1263 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 EXPECT_EQ(2U, GetTransport1()->channels().size());
1265 EXPECT_EQ(1U, GetTransport2()->channels().size());
1266
1267 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1268 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001269 SendRtcp1();
1270 WaitForThreads();
1271 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272
1273 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001274 SendRtcp2();
1275 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 EXPECT_TRUE(CheckNoRtp1());
1277 EXPECT_TRUE(CheckRtcp1());
1278
1279 // Complete call setup and ensure everything is still OK.
1280 EXPECT_TRUE(SendAccept());
1281 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001282 SendRtcp1();
1283 SendRtcp2();
1284 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 EXPECT_TRUE(CheckRtcp1());
1287 }
1288
1289 // Test that we properly send SRTP with RTCP in both directions.
1290 // You can pass in DTLS and/or RTCP_MUX as flags.
1291 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1292 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1293 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1294
1295 int flags1 = RTCP | SECURE | flags1_in;
1296 int flags2 = RTCP | SECURE | flags2_in;
1297 bool dtls1 = !!(flags1_in & DTLS);
1298 bool dtls2 = !!(flags2_in & DTLS);
1299 CreateChannels(flags1, flags2);
1300 EXPECT_FALSE(channel1_->secure());
1301 EXPECT_FALSE(channel2_->secure());
1302 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001303 WaitForThreads();
1304 EXPECT_TRUE(channel1_->writable());
1305 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 EXPECT_TRUE(SendAccept());
1307 EXPECT_TRUE(channel1_->secure());
1308 EXPECT_TRUE(channel2_->secure());
1309 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1310 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001311 SendRtp1();
1312 SendRtp2();
1313 SendRtcp1();
1314 SendRtcp2();
1315 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316 EXPECT_TRUE(CheckRtp1());
1317 EXPECT_TRUE(CheckRtp2());
1318 EXPECT_TRUE(CheckNoRtp1());
1319 EXPECT_TRUE(CheckNoRtp2());
1320 EXPECT_TRUE(CheckRtcp1());
1321 EXPECT_TRUE(CheckRtcp2());
1322 EXPECT_TRUE(CheckNoRtcp1());
1323 EXPECT_TRUE(CheckNoRtcp2());
1324 }
1325
1326 // Test that we properly handling SRTP negotiating down to RTP.
1327 void SendSrtpToRtp() {
1328 CreateChannels(RTCP | SECURE, RTCP);
1329 EXPECT_FALSE(channel1_->secure());
1330 EXPECT_FALSE(channel2_->secure());
1331 EXPECT_TRUE(SendInitiate());
1332 EXPECT_TRUE(SendAccept());
1333 EXPECT_FALSE(channel1_->secure());
1334 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001335 SendRtp1();
1336 SendRtp2();
1337 SendRtcp1();
1338 SendRtcp2();
1339 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 EXPECT_TRUE(CheckRtp1());
1341 EXPECT_TRUE(CheckRtp2());
1342 EXPECT_TRUE(CheckNoRtp1());
1343 EXPECT_TRUE(CheckNoRtp2());
1344 EXPECT_TRUE(CheckRtcp1());
1345 EXPECT_TRUE(CheckRtcp2());
1346 EXPECT_TRUE(CheckNoRtcp1());
1347 EXPECT_TRUE(CheckNoRtcp2());
1348 }
1349
1350 // Test that we can send and receive early media when a provisional answer is
1351 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1352 void SendEarlyMediaUsingRtcpMuxSrtp() {
1353 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1354
1355 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1356 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1357 EXPECT_TRUE(SendOffer());
1358 EXPECT_TRUE(SendProvisionalAnswer());
1359 EXPECT_TRUE(channel1_->secure());
1360 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001361 ASSERT_TRUE(GetTransport1());
1362 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 EXPECT_EQ(2U, GetTransport1()->channels().size());
1364 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001365 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1366 SendCustomRtcp1(kSsrc1);
1367 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1368 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001370 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1371
1372 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001373 SendCustomRtcp2(kSsrc2);
1374 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1375 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1378
1379 // Complete call setup and ensure everything is still OK.
1380 EXPECT_TRUE(SendFinalAnswer());
1381 EXPECT_EQ(1U, GetTransport1()->channels().size());
1382 EXPECT_EQ(1U, GetTransport2()->channels().size());
1383 EXPECT_TRUE(channel1_->secure());
1384 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001385 SendCustomRtcp1(kSsrc1);
1386 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1387 SendCustomRtcp2(kSsrc2);
1388 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1389 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001393 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1394 }
1395
1396 // Test that we properly send RTP without SRTP from a thread.
1397 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001398 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 EXPECT_TRUE(SendInitiate());
1400 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001401 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1402 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1403 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1404 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1405 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1406 send_rtcp1.thread(),
1407 send_rtcp2.thread()};
1408 WaitForThreads(involved_threads);
1409 EXPECT_TRUE(CheckRtp1());
1410 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411 EXPECT_TRUE(CheckNoRtp1());
1412 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001413 EXPECT_TRUE(CheckRtcp1());
1414 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 EXPECT_TRUE(CheckNoRtcp1());
1416 EXPECT_TRUE(CheckNoRtcp2());
1417 }
1418
1419 // Test that we properly send SRTP with RTCP from a thread.
1420 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1422 EXPECT_TRUE(SendInitiate());
1423 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001424 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1425 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1426 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1427 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1428 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1429 send_rtcp1.thread(),
1430 send_rtcp2.thread()};
1431 WaitForThreads(involved_threads);
1432 EXPECT_TRUE(CheckRtp1());
1433 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 EXPECT_TRUE(CheckNoRtp1());
1435 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001436 EXPECT_TRUE(CheckRtcp1());
1437 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 EXPECT_TRUE(CheckNoRtcp1());
1439 EXPECT_TRUE(CheckNoRtcp2());
1440 }
1441
1442 // Test that the mediachannel retains its sending state after the transport
1443 // becomes non-writable.
1444 void SendWithWritabilityLoss() {
1445 CreateChannels(0, 0);
1446 EXPECT_TRUE(SendInitiate());
1447 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001448 ASSERT_TRUE(GetTransport1());
1449 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 EXPECT_EQ(1U, GetTransport1()->channels().size());
1451 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001452 SendRtp1();
1453 SendRtp2();
1454 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 EXPECT_TRUE(CheckRtp1());
1456 EXPECT_TRUE(CheckRtp2());
1457 EXPECT_TRUE(CheckNoRtp1());
1458 EXPECT_TRUE(CheckNoRtp2());
1459
wu@webrtc.org97077a32013-10-25 21:18:33 +00001460 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001461 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001462 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001463 SendRtp1();
1464 SendRtp2();
1465 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 EXPECT_TRUE(CheckRtp1());
1467 EXPECT_TRUE(CheckNoRtp2());
1468
1469 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001470 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001471 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001473 SendRtp1();
1474 SendRtp2();
1475 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 EXPECT_TRUE(CheckRtp1());
1477 EXPECT_TRUE(CheckRtp2());
1478 EXPECT_TRUE(CheckNoRtp1());
1479 EXPECT_TRUE(CheckNoRtp2());
1480
1481 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001482 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001483 RTC_FROM_HERE, [this] { GetTransport1()->SetDestination(NULL); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 EXPECT_TRUE(media_channel1_->sending());
1485
wu@webrtc.org97077a32013-10-25 21:18:33 +00001486 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001487 SendRtp1();
1488 SendRtp2();
1489 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490 EXPECT_TRUE(CheckRtp1());
1491 EXPECT_TRUE(CheckNoRtp2());
1492
1493 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001494 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1495 GetTransport1()->SetDestination(GetTransport2());
1496 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001498 SendRtp1();
1499 SendRtp2();
1500 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 EXPECT_TRUE(CheckRtp1());
1502 EXPECT_TRUE(CheckRtp2());
1503 EXPECT_TRUE(CheckNoRtp1());
1504 EXPECT_TRUE(CheckNoRtp2());
1505 }
1506
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001507 void SendBundleToBundle(
1508 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1509 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001511 // Only pl_type1 was added to the bundle filter for both |channel1_|
1512 // and |channel2_|.
1513 int pl_type1 = pl_types[0];
1514 int pl_type2 = pl_types[1];
1515 int flags = SSRC_MUX | RTCP;
1516 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001517 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001518 if (rtcp_mux) {
1519 flags |= RTCP_MUX;
1520 expected_channels = 1U;
1521 }
1522 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001524 ASSERT_TRUE(GetTransport1());
1525 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001527 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001529 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1530 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1531 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1532 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1533 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1534 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001535
1536 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001537 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1538 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1539 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001540 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001541 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1542 EXPECT_TRUE(CheckNoRtp1());
1543 EXPECT_TRUE(CheckNoRtp2());
1544
1545 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001546 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1547 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1548 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001549 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001550 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1551
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001552 SendCustomRtcp1(kSsrc1);
1553 SendCustomRtcp2(kSsrc2);
1554 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1556 EXPECT_TRUE(CheckNoRtcp1());
1557 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1558 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001560 SendCustomRtcp1(kSsrc2);
1561 SendCustomRtcp2(kSsrc1);
1562 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001563 // Bundle filter shouldn't filter out any RTCP.
1564 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1565 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 }
1567
1568 // Test that the media monitor can be run and gives timely callbacks.
1569 void TestMediaMonitor() {
1570 static const int kTimeout = 500;
1571 CreateChannels(0, 0);
1572 EXPECT_TRUE(SendInitiate());
1573 EXPECT_TRUE(SendAccept());
1574 channel1_->StartMediaMonitor(100);
1575 channel2_->StartMediaMonitor(100);
1576 // Ensure we get callbacks and stop.
1577 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1578 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1579 channel1_->StopMediaMonitor();
1580 channel2_->StopMediaMonitor();
1581 // Ensure a restart of a stopped monitor works.
1582 channel1_->StartMediaMonitor(100);
1583 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1584 channel1_->StopMediaMonitor();
1585 // Ensure stopping a stopped monitor is OK.
1586 channel1_->StopMediaMonitor();
1587 }
1588
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 void TestSetContentFailure() {
1590 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591
Peter Thatchera6d24442015-07-09 21:26:36 -07001592 auto sdesc = cricket::SessionDescription();
1593 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1594 new cricket::AudioContentDescription());
1595 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1596 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597
Peter Thatchera6d24442015-07-09 21:26:36 -07001598 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001600 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1601 &sdesc, cricket::CA_OFFER, &err));
1602 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1603 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001606 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1607 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001609 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1610 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 }
1612
1613 void TestSendTwoOffers() {
1614 CreateChannels(0, 0);
1615
Peter Thatchera6d24442015-07-09 21:26:36 -07001616 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001617 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001618 CreateSessionDescriptionWithStream(1));
1619 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1620 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1622
kwiberg31022942016-03-11 14:18:21 -08001623 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001624 CreateSessionDescriptionWithStream(2));
1625 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1626 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1628 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1629 }
1630
1631 void TestReceiveTwoOffers() {
1632 CreateChannels(0, 0);
1633
Peter Thatchera6d24442015-07-09 21:26:36 -07001634 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001635 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001636 CreateSessionDescriptionWithStream(1));
1637 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1638 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1640
kwiberg31022942016-03-11 14:18:21 -08001641 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001642 CreateSessionDescriptionWithStream(2));
1643 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1644 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1646 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1647 }
1648
1649 void TestSendPrAnswer() {
1650 CreateChannels(0, 0);
1651
Peter Thatchera6d24442015-07-09 21:26:36 -07001652 std::string err;
1653 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001654 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001655 CreateSessionDescriptionWithStream(1));
1656 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1657 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1659
Peter Thatchera6d24442015-07-09 21:26:36 -07001660 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001661 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001662 CreateSessionDescriptionWithStream(2));
1663 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1664 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1666 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1667
Peter Thatchera6d24442015-07-09 21:26:36 -07001668 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001669 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001670 CreateSessionDescriptionWithStream(3));
1671 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1672 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1674 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1675 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1676 }
1677
1678 void TestReceivePrAnswer() {
1679 CreateChannels(0, 0);
1680
Peter Thatchera6d24442015-07-09 21:26:36 -07001681 std::string err;
1682 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001683 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001684 CreateSessionDescriptionWithStream(1));
1685 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1686 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001687 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1688
Peter Thatchera6d24442015-07-09 21:26:36 -07001689 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001690 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001691 CreateSessionDescriptionWithStream(2));
1692 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1693 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1695 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1696
Peter Thatchera6d24442015-07-09 21:26:36 -07001697 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001698 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001699 CreateSessionDescriptionWithStream(3));
1700 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1701 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1703 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1704 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1705 }
1706
1707 void TestFlushRtcp() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 CreateChannels(RTCP, RTCP);
1709 EXPECT_TRUE(SendInitiate());
1710 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001711 ASSERT_TRUE(GetTransport1());
1712 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 EXPECT_EQ(2U, GetTransport1()->channels().size());
1714 EXPECT_EQ(2U, GetTransport2()->channels().size());
1715
1716 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001717 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 // The sending message is only posted. channel2_ should be empty.
1719 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001720 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1721 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722
1723 // When channel1_ is deleted, the RTCP packet should be sent out to
1724 // channel2_.
1725 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001726 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 EXPECT_TRUE(CheckRtcp2());
1728 }
1729
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001730 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001731 struct SrtpErrorHandler : public sigslot::has_slots<> {
1732 SrtpErrorHandler() :
1733 mode_(cricket::SrtpFilter::UNPROTECT),
1734 error_(cricket::SrtpFilter::ERROR_NONE) {}
1735 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1736 cricket::SrtpFilter::Error error) {
1737 mode_ = mode;
1738 error_ = error;
1739 }
1740 cricket::SrtpFilter::Mode mode_;
1741 cricket::SrtpFilter::Error error_;
1742 } error_handler;
1743
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001744 // For Audio, only pl_type 0 is added to the bundle filter.
1745 // For Video, only pl_type 97 is added to the bundle filter.
1746 // So we need to pass in pl_type so that the packet can pass through
1747 // the bundle filter before it can be processed by the srtp filter.
1748 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001749 static unsigned const char kBadPacket[] = {
1750 0x84, static_cast<unsigned char>(pl_type),
1751 0x00, 0x01,
1752 0x00, 0x00,
1753 0x00, 0x00,
1754 0x00, 0x00,
1755 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001756
1757 // Using fake clock because this tests that SRTP errors are signaled at
1758 // specific times based on set_signal_silent_time.
1759 rtc::ScopedFakeClock fake_clock;
1760 // Some code uses a time of 0 as a special value, so we must start with
1761 // a non-zero time.
1762 // TODO(deadbeef): Fix this.
1763 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1764
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1766 EXPECT_FALSE(channel1_->secure());
1767 EXPECT_FALSE(channel2_->secure());
1768 EXPECT_TRUE(SendInitiate());
1769 EXPECT_TRUE(SendAccept());
1770 EXPECT_TRUE(channel1_->secure());
1771 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001772 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001773 channel2_->srtp_filter()->SignalSrtpError.connect(
1774 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775
1776 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001777 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1778 rtc::PacketOptions());
1779 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001781 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001782 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1783 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001784 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1785 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001786 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1787 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001789 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001790 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001791 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001792 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1793 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001794 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001795 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1796 rtc::PacketOptions());
1797 WaitForThreads();
1798 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001799 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800
1801 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001802 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001803 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001804
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001805 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001806 cricket::TransportChannel* transport_channel =
1807 channel2_->transport_channel();
1808 transport_channel->SignalReadPacket(
1809 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1810 sizeof(kBadPacket), rtc::PacketTime(), 0);
1811 });
1812 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001813 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001814 // Terminate channels before the fake clock is destroyed.
1815 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 }
1817
1818 void TestOnReadyToSend() {
1819 CreateChannels(RTCP, RTCP);
1820 TransportChannel* rtp = channel1_->transport_channel();
1821 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1822 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001823
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001824 network_thread_->Invoke<void>(RTC_FROM_HERE,
1825 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001826 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001828
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001829 network_thread_->Invoke<void>(RTC_FROM_HERE,
1830 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001831 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1833 // channel are ready to send.
1834 EXPECT_TRUE(media_channel1_->ready_to_send());
1835
1836 // rtp channel becomes not ready to send will be propagated to mediachannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001837 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001838 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001839 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001841
1842 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001843 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, true); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001844 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 EXPECT_TRUE(media_channel1_->ready_to_send());
1846
1847 // rtcp channel becomes not ready to send will be propagated to mediachannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001848 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001849 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(true, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001850 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001852
1853 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001854 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(true, true); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001855 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 EXPECT_TRUE(media_channel1_->ready_to_send());
1857 }
1858
1859 void TestOnReadyToSendWithRtcpMux() {
1860 CreateChannels(RTCP, RTCP);
1861 typename T::Content content;
1862 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1863 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1864 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001865 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1866 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1868 TransportChannel* rtp = channel1_->transport_channel();
1869 EXPECT_FALSE(media_channel1_->ready_to_send());
1870 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1871 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001872 network_thread_->Invoke<void>(RTC_FROM_HERE,
1873 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001874 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001876
1877 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001878 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001879 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 EXPECT_FALSE(media_channel1_->ready_to_send());
1881 }
1882
skvladdc1c62c2016-03-16 19:07:43 -07001883 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1884 typename T::Content content;
1885 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1886 content.set_bandwidth(remote_limit);
1887 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1888 }
1889
1890 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1891 webrtc::RtpParameters parameters;
1892 webrtc::RtpEncodingParameters encoding;
1893 encoding.max_bitrate_bps = limit;
1894 parameters.encodings.push_back(encoding);
1895 return parameters;
1896 }
1897
1898 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1899 int expected_bitrate) {
1900 EXPECT_EQ(1UL, parameters.encodings.size());
1901 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1902 }
1903
1904 void DefaultMaxBitrateIsUnlimited() {
1905 CreateChannels(0, 0);
1906 EXPECT_TRUE(
1907 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1908 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001909 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001910 }
1911
1912 void CanChangeMaxBitrate() {
1913 CreateChannels(0, 0);
1914 EXPECT_TRUE(
1915 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1916
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001917 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1918 kSsrc1, BitrateLimitedParameters(1000)));
1919 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1920 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001921 EXPECT_EQ(-1, media_channel1_->max_bps());
1922
1923 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001924 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1925 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1926 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001927 EXPECT_EQ(-1, media_channel1_->max_bps());
1928 }
1929
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001931 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1932 static void ProcessThreadQueue(rtc::Thread* thread) {
1933 RTC_DCHECK(thread->IsCurrent());
1934 while (!thread->empty()) {
1935 thread->ProcessMessages(0);
1936 }
1937 }
1938 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1939 // |threads| and current thread post packets to network thread.
1940 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001941 thread->Invoke<void>(RTC_FROM_HERE,
1942 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001943 }
1944 ProcessThreadQueue(rtc::Thread::Current());
1945 // Network thread move them around and post back to worker = current thread.
1946 if (!network_thread_->IsCurrent()) {
1947 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001948 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001949 }
1950 // Worker thread = current Thread process received messages.
1951 ProcessThreadQueue(rtc::Thread::Current());
1952 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001953 // TODO(pbos): Remove playout from all media channels and let renderers mute
1954 // themselves.
1955 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001956 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1957 rtc::Thread* network_thread_;
1958 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1959 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 cricket::FakeMediaEngine media_engine_;
1961 // The media channels are owned by the voice channel objects below.
1962 typename T::MediaChannel* media_channel1_;
1963 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001964 std::unique_ptr<typename T::Channel> channel1_;
1965 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 typename T::Content local_media_content1_;
1967 typename T::Content local_media_content2_;
1968 typename T::Content remote_media_content1_;
1969 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001971 rtc::Buffer rtp_packet_;
1972 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 int media_info_callbacks1_;
1974 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001975 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976};
1977
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978template<>
1979void ChannelTest<VoiceTraits>::CreateContent(
1980 int flags,
1981 const cricket::AudioCodec& audio_codec,
1982 const cricket::VideoCodec& video_codec,
1983 cricket::AudioContentDescription* audio) {
1984 audio->AddCodec(audio_codec);
1985 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1986 if (flags & SECURE) {
1987 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001988 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1989 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990 }
1991}
1992
1993template<>
1994void ChannelTest<VoiceTraits>::CopyContent(
1995 const cricket::AudioContentDescription& source,
1996 cricket::AudioContentDescription* audio) {
1997 *audio = source;
1998}
1999
2000template<>
2001bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2002 const cricket::AudioCodec& c2) {
2003 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2004 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2005}
2006
Peter Boström0c4e06b2015-10-07 12:23:21 +02002007template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002009 uint32_t ssrc,
2010 int flags,
2011 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 audio->AddLegacyStream(ssrc);
2013}
2014
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002015class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 public:
solenberg1dd98f32015-09-10 01:57:14 -07002017 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002018 VoiceChannelSingleThreadTest()
2019 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2020};
2021
2022class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2023 public:
2024 typedef ChannelTest<VoiceTraits> Base;
2025 VoiceChannelDoubleThreadTest()
2026 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027};
2028
2029// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002030template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002032 rtc::Thread* worker_thread,
2033 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002034 cricket::MediaEngineInterface* engine,
2035 cricket::FakeVideoMediaChannel* ch,
2036 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002038 cricket::VideoChannel* channel =
2039 new cricket::VideoChannel(worker_thread, network_thread, ch,
2040 transport_controller, cricket::CN_VIDEO, rtcp);
skvlad6c87a672016-05-17 17:49:52 -07002041 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 delete channel;
2043 channel = NULL;
2044 }
2045 return channel;
2046}
2047
2048// override to add 0 parameter
2049template<>
2050bool ChannelTest<VideoTraits>::AddStream1(int id) {
2051 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2052}
2053
2054template<>
2055void ChannelTest<VideoTraits>::CreateContent(
2056 int flags,
2057 const cricket::AudioCodec& audio_codec,
2058 const cricket::VideoCodec& video_codec,
2059 cricket::VideoContentDescription* video) {
2060 video->AddCodec(video_codec);
2061 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2062 if (flags & SECURE) {
2063 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002064 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2065 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 }
2067}
2068
2069template<>
2070void ChannelTest<VideoTraits>::CopyContent(
2071 const cricket::VideoContentDescription& source,
2072 cricket::VideoContentDescription* video) {
2073 *video = source;
2074}
2075
2076template<>
2077bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2078 const cricket::VideoCodec& c2) {
2079 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2080 c1.framerate == c2.framerate;
2081}
2082
Peter Boström0c4e06b2015-10-07 12:23:21 +02002083template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002085 uint32_t ssrc,
2086 int flags,
2087 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088 video->AddLegacyStream(ssrc);
2089}
2090
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002091class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 public:
solenberg1dd98f32015-09-10 01:57:14 -07002093 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002094 VideoChannelSingleThreadTest()
2095 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096};
2097
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002098class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2099 public:
2100 typedef ChannelTest<VideoTraits> Base;
2101 VideoChannelDoubleThreadTest()
2102 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2103};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002105// VoiceChannelSingleThreadTest
2106TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 Base::TestInit();
2108 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2109 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2110}
2111
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002112TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2113 Base::TestDeinit();
2114}
2115
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002116TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 Base::TestSetContents();
2118}
2119
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002120TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 Base::TestSetContentsNullOffer();
2122}
2123
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002124TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 Base::TestSetContentsRtcpMux();
2126}
2127
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002128TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 Base::TestSetContentsRtcpMux();
2130}
2131
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002132TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 Base::TestSetRemoteContentUpdate();
2134}
2135
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002136TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 Base::TestStreams();
2138}
2139
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002140TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 Base::TestUpdateStreamsInLocalContent();
2142}
2143
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002144TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 Base::TestUpdateStreamsInRemoteContent();
2146}
2147
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002148TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 Base::TestChangeStreamParamsInContent();
2150}
2151
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002152TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 Base::TestPlayoutAndSendingStates();
2154}
2155
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002156TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002157 CreateChannels(0, 0);
2158 // Test that we can Mute the default channel even though the sending SSRC
2159 // is unknown.
2160 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002161 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002162 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2163 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002164 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2165
2166 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002167 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002168
2169 SendInitiate();
2170 // After the local session description has been set, we can mute a stream
2171 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002172 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002173 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2174 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002175 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176}
2177
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002178TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 Base::TestMediaContentDirection();
2180}
2181
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002182TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002183 Base::TestNetworkRouteChanges();
2184}
2185
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002186TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 Base::TestCallSetup();
2188}
2189
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002190TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 Base::TestCallTeardownRtcpMux();
2192}
2193
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002194TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 Base::SendRtpToRtp();
2196}
2197
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002198TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 Base::SendNoRtcpToNoRtcp();
2200}
2201
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002202TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 Base::SendNoRtcpToRtcp();
2204}
2205
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002206TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 Base::SendRtcpToNoRtcp();
2208}
2209
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002210TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 Base::SendRtcpToRtcp();
2212}
2213
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002214TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 Base::SendRtcpMuxToRtcp();
2216}
2217
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002218TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 Base::SendRtcpMuxToRtcpMux();
2220}
2221
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002222TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002223 Base::SendRequireRtcpMuxToRtcpMux();
2224}
2225
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002226TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002227 Base::SendRtcpMuxToRequireRtcpMux();
2228}
2229
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002230TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002231 Base::SendRequireRtcpMuxToRequireRtcpMux();
2232}
2233
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002234TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002235 Base::SendRequireRtcpMuxToNoRtcpMux();
2236}
2237
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002238TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 Base::SendEarlyRtcpMuxToRtcp();
2240}
2241
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002242TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 Base::SendEarlyRtcpMuxToRtcpMux();
2244}
2245
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002246TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2248}
2249
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002250TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 Base::SendSrtpToSrtp();
2252}
2253
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002254TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2256}
2257
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002258TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002259 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2260 Base::SendSrtpToSrtp(DTLS, 0);
2261}
2262
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002263TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2265 Base::SendSrtpToSrtp(DTLS, DTLS);
2266}
2267
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002268TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2270 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2271}
2272
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002273TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2275}
2276
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002277TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 Base::SendRtpToRtpOnThread();
2279}
2280
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002281TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 Base::SendSrtpToSrtpOnThread();
2283}
2284
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002285TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 Base::SendWithWritabilityLoss();
2287}
2288
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002289TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290 Base::TestMediaMonitor();
2291}
2292
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002294TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 CreateChannels(0, 0);
2296 EXPECT_TRUE(SendInitiate());
2297 EXPECT_TRUE(SendAccept());
2298 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2299
solenberg1d63dd02015-12-02 12:35:09 -08002300 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2301 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2302 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002304 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002306 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002307 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002308 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002309 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002310 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311}
2312
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002313TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 Base::TestSetContentFailure();
2315}
2316
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002317TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 Base::TestSendTwoOffers();
2319}
2320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002321TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 Base::TestReceiveTwoOffers();
2323}
2324
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002325TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 Base::TestSendPrAnswer();
2327}
2328
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002329TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 Base::TestReceivePrAnswer();
2331}
2332
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002333TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 Base::TestFlushRtcp();
2335}
2336
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002337TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002338 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339}
2340
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002341TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 Base::TestOnReadyToSend();
2343}
2344
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002345TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 Base::TestOnReadyToSendWithRtcpMux();
2347}
2348
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002350TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 CreateChannels(RTCP, RTCP);
2352 EXPECT_TRUE(SendInitiate());
2353 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002354 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355
solenberg4bac9c52015-10-09 02:32:53 -07002356 // Default is (1.0).
2357 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2358 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002360 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361
solenberg4bac9c52015-10-09 02:32:53 -07002362 // Set scale to (1.5).
2363 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2364 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2365 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366
solenberg4bac9c52015-10-09 02:32:53 -07002367 // Set scale to (0).
2368 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2369 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2370 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371}
2372
2373// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002374TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 CreateChannels(RTCP, RTCP);
2376 EXPECT_TRUE(SendInitiate());
2377 EXPECT_TRUE(SendAccept());
2378 EXPECT_TRUE(AddStream1(1));
2379 EXPECT_TRUE(AddStream1(2));
2380
solenberg4bac9c52015-10-09 02:32:53 -07002381 double volume;
2382 // Default is (1.0).
2383 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2384 EXPECT_DOUBLE_EQ(1.0, volume);
2385 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2386 EXPECT_DOUBLE_EQ(1.0, volume);
2387 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2388 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002390 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391
solenberg4bac9c52015-10-09 02:32:53 -07002392 // Set scale to (1.5) for ssrc = 1.
2393 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2394 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2395 EXPECT_DOUBLE_EQ(1.5, volume);
2396 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2397 EXPECT_DOUBLE_EQ(1.0, volume);
2398 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2399 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400
solenberg4bac9c52015-10-09 02:32:53 -07002401 // Set scale to (0) for all ssrcs.
2402 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2403 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2404 EXPECT_DOUBLE_EQ(0.0, volume);
2405 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2406 EXPECT_DOUBLE_EQ(0.0, volume);
2407 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2408 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409}
2410
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002411TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002412 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413}
2414
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002415TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002416 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002417}
2418
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002419TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002420 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002421}
2422
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002423TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002424 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425}
2426
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002427TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002428 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002429}
2430
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002431TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002432 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002433}
2434
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002435// VoiceChannelDoubleThreadTest
2436TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002438 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2439 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440}
2441
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002442TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2443 Base::TestDeinit();
2444}
2445
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002446TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 Base::TestSetContents();
2448}
2449
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002450TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 Base::TestSetContentsNullOffer();
2452}
2453
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002454TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 Base::TestSetContentsRtcpMux();
2456}
2457
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002458TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 Base::TestSetContentsRtcpMux();
2460}
2461
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002462TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 Base::TestSetRemoteContentUpdate();
2464}
2465
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002466TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 Base::TestStreams();
2468}
2469
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002470TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 Base::TestUpdateStreamsInLocalContent();
2472}
2473
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002474TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 Base::TestUpdateStreamsInRemoteContent();
2476}
2477
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002478TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 Base::TestChangeStreamParamsInContent();
2480}
2481
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002482TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 Base::TestPlayoutAndSendingStates();
2484}
2485
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002486TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2487 CreateChannels(0, 0);
2488 // Test that we can Mute the default channel even though the sending SSRC
2489 // is unknown.
2490 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2491 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2492 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2493 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2494 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2495
2496 // Test that we can not mute an unknown SSRC.
2497 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2498
2499 SendInitiate();
2500 // After the local session description has been set, we can mute a stream
2501 // with its SSRC.
2502 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2503 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2504 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2505 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2506}
2507
2508TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2509 Base::TestMediaContentDirection();
2510}
2511
2512TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2513 Base::TestNetworkRouteChanges();
2514}
2515
2516TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2517 Base::TestCallSetup();
2518}
2519
2520TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2521 Base::TestCallTeardownRtcpMux();
2522}
2523
2524TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2525 Base::SendRtpToRtp();
2526}
2527
2528TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2529 Base::SendNoRtcpToNoRtcp();
2530}
2531
2532TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2533 Base::SendNoRtcpToRtcp();
2534}
2535
2536TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2537 Base::SendRtcpToNoRtcp();
2538}
2539
2540TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2541 Base::SendRtcpToRtcp();
2542}
2543
2544TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2545 Base::SendRtcpMuxToRtcp();
2546}
2547
2548TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2549 Base::SendRtcpMuxToRtcpMux();
2550}
2551
2552TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2553 Base::SendRequireRtcpMuxToRtcpMux();
2554}
2555
2556TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2557 Base::SendRtcpMuxToRequireRtcpMux();
2558}
2559
2560TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2561 Base::SendRequireRtcpMuxToRequireRtcpMux();
2562}
2563
2564TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2565 Base::SendRequireRtcpMuxToNoRtcpMux();
2566}
2567
2568TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2569 Base::SendEarlyRtcpMuxToRtcp();
2570}
2571
2572TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2573 Base::SendEarlyRtcpMuxToRtcpMux();
2574}
2575
2576TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2577 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2578}
2579
2580TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2581 Base::SendSrtpToSrtp();
2582}
2583
2584TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2585 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2586}
2587
2588TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2589 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2590 Base::SendSrtpToSrtp(DTLS, 0);
2591}
2592
2593TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2594 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2595 Base::SendSrtpToSrtp(DTLS, DTLS);
2596}
2597
2598TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2599 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2600 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2601}
2602
2603TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2604 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2605}
2606
2607TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2608 Base::SendRtpToRtpOnThread();
2609}
2610
2611TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2612 Base::SendSrtpToSrtpOnThread();
2613}
2614
2615TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2616 Base::SendWithWritabilityLoss();
2617}
2618
2619TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2620 Base::TestMediaMonitor();
2621}
2622
2623// Test that InsertDtmf properly forwards to the media channel.
2624TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2625 CreateChannels(0, 0);
2626 EXPECT_TRUE(SendInitiate());
2627 EXPECT_TRUE(SendAccept());
2628 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2629
2630 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2631 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2632 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2633
2634 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2635 EXPECT_TRUE(
2636 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2637 EXPECT_TRUE(
2638 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2639 EXPECT_TRUE(
2640 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2641}
2642
2643TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2644 Base::TestSetContentFailure();
2645}
2646
2647TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2648 Base::TestSendTwoOffers();
2649}
2650
2651TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2652 Base::TestReceiveTwoOffers();
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2656 Base::TestSendPrAnswer();
2657}
2658
2659TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2660 Base::TestReceivePrAnswer();
2661}
2662
2663TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2664 Base::TestFlushRtcp();
2665}
2666
2667TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2668 Base::TestSrtpError(kAudioPts[0]);
2669}
2670
2671TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2672 Base::TestOnReadyToSend();
2673}
2674
2675TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2676 Base::TestOnReadyToSendWithRtcpMux();
2677}
2678
2679// Test that we can scale the output volume properly for 1:1 calls.
2680TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2681 CreateChannels(RTCP, RTCP);
2682 EXPECT_TRUE(SendInitiate());
2683 EXPECT_TRUE(SendAccept());
2684 double volume;
2685
2686 // Default is (1.0).
2687 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2688 EXPECT_DOUBLE_EQ(1.0, volume);
2689 // invalid ssrc.
2690 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2691
2692 // Set scale to (1.5).
2693 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2694 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2695 EXPECT_DOUBLE_EQ(1.5, volume);
2696
2697 // Set scale to (0).
2698 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2699 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2700 EXPECT_DOUBLE_EQ(0.0, volume);
2701}
2702
2703// Test that we can scale the output volume properly for multiway calls.
2704TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2705 CreateChannels(RTCP, RTCP);
2706 EXPECT_TRUE(SendInitiate());
2707 EXPECT_TRUE(SendAccept());
2708 EXPECT_TRUE(AddStream1(1));
2709 EXPECT_TRUE(AddStream1(2));
2710
2711 double volume;
2712 // Default is (1.0).
2713 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2714 EXPECT_DOUBLE_EQ(1.0, volume);
2715 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2716 EXPECT_DOUBLE_EQ(1.0, volume);
2717 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2718 EXPECT_DOUBLE_EQ(1.0, volume);
2719 // invalid ssrc.
2720 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2721
2722 // Set scale to (1.5) for ssrc = 1.
2723 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2724 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2725 EXPECT_DOUBLE_EQ(1.5, volume);
2726 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2727 EXPECT_DOUBLE_EQ(1.0, volume);
2728 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2729 EXPECT_DOUBLE_EQ(1.0, volume);
2730
2731 // Set scale to (0) for all ssrcs.
2732 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2733 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2734 EXPECT_DOUBLE_EQ(0.0, volume);
2735 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2736 EXPECT_DOUBLE_EQ(0.0, volume);
2737 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2738 EXPECT_DOUBLE_EQ(0.0, volume);
2739}
2740
2741TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2742 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2743}
2744
2745TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2746 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2747}
2748
2749TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2750 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2751}
2752
2753TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2754 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2755}
2756
2757TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2758 Base::DefaultMaxBitrateIsUnlimited();
2759}
2760
2761TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2762 Base::CanChangeMaxBitrate();
2763}
2764
2765// VideoChannelSingleThreadTest
2766TEST_F(VideoChannelSingleThreadTest, TestInit) {
2767 Base::TestInit();
2768}
2769
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002770TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2771 Base::TestDeinit();
2772}
2773
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002774TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2775 Base::TestSetContents();
2776}
2777
2778TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2779 Base::TestSetContentsNullOffer();
2780}
2781
2782TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2783 Base::TestSetContentsRtcpMux();
2784}
2785
2786TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2787 Base::TestSetContentsRtcpMux();
2788}
2789
2790TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2791 Base::TestSetRemoteContentUpdate();
2792}
2793
2794TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2795 Base::TestStreams();
2796}
2797
2798TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2799 Base::TestUpdateStreamsInLocalContent();
2800}
2801
2802TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2803 Base::TestUpdateStreamsInRemoteContent();
2804}
2805
2806TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2807 Base::TestChangeStreamParamsInContent();
2808}
2809
2810TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2811 Base::TestPlayoutAndSendingStates();
2812}
2813
2814TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002815 CreateChannels(0, 0);
2816 // Test that we can Mute the default channel even though the sending SSRC
2817 // is unknown.
2818 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002819 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002820 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002821 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002822 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2823 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002824 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002825 SendInitiate();
2826 // After the local session description has been set, we can mute a stream
2827 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002828 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002829 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002830 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002831 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002832}
2833
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002834TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 Base::TestMediaContentDirection();
2836}
2837
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002838TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002839 Base::TestNetworkRouteChanges();
2840}
2841
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002842TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002843 Base::TestCallSetup();
2844}
2845
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002846TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847 Base::TestCallTeardownRtcpMux();
2848}
2849
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002850TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 Base::SendRtpToRtp();
2852}
2853
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002854TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855 Base::SendNoRtcpToNoRtcp();
2856}
2857
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002858TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002859 Base::SendNoRtcpToRtcp();
2860}
2861
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002862TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 Base::SendRtcpToNoRtcp();
2864}
2865
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002866TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867 Base::SendRtcpToRtcp();
2868}
2869
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002870TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871 Base::SendRtcpMuxToRtcp();
2872}
2873
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002874TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875 Base::SendRtcpMuxToRtcpMux();
2876}
2877
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002878TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002879 Base::SendRequireRtcpMuxToRtcpMux();
2880}
2881
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002882TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002883 Base::SendRtcpMuxToRequireRtcpMux();
2884}
2885
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002886TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002887 Base::SendRequireRtcpMuxToRequireRtcpMux();
2888}
2889
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002890TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002891 Base::SendRequireRtcpMuxToNoRtcpMux();
2892}
2893
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002894TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 Base::SendEarlyRtcpMuxToRtcp();
2896}
2897
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002898TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899 Base::SendEarlyRtcpMuxToRtcpMux();
2900}
2901
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002902TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 Base::SendSrtpToSrtp();
2904}
2905
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002906TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907 Base::SendSrtpToSrtp();
2908}
2909
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002910TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002911 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2912 Base::SendSrtpToSrtp(DTLS, 0);
2913}
2914
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002915TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2917 Base::SendSrtpToSrtp(DTLS, DTLS);
2918}
2919
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002920TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002921 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2922 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2923}
2924
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002925TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2927}
2928
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002929TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2931}
2932
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002933TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934 Base::SendRtpToRtpOnThread();
2935}
2936
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002937TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 Base::SendSrtpToSrtpOnThread();
2939}
2940
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002941TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002942 Base::SendWithWritabilityLoss();
2943}
2944
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002945TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002946 Base::TestMediaMonitor();
2947}
2948
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002949TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950 Base::TestSetContentFailure();
2951}
2952
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002953TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 Base::TestSendTwoOffers();
2955}
2956
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002957TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002958 Base::TestReceiveTwoOffers();
2959}
2960
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002961TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002962 Base::TestSendPrAnswer();
2963}
2964
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002965TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966 Base::TestReceivePrAnswer();
2967}
2968
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002969TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970 Base::TestFlushRtcp();
2971}
2972
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002973TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002974 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975}
2976
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002977TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002978 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002979}
2980
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002981TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002982 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002983}
2984
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002985TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002986 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002987}
2988
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002989TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002990 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991}
2992
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002993TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994 Base::TestOnReadyToSend();
2995}
2996
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002997TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 Base::TestOnReadyToSendWithRtcpMux();
2999}
3000
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003001TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003002 Base::DefaultMaxBitrateIsUnlimited();
3003}
3004
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003005TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003006 Base::CanChangeMaxBitrate();
3007}
3008
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003009// VideoChannelDoubleThreadTest
3010TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3011 Base::TestInit();
3012}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003013
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003014TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3015 Base::TestDeinit();
3016}
3017
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003018TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3019 Base::TestSetContents();
3020}
3021
3022TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3023 Base::TestSetContentsNullOffer();
3024}
3025
3026TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3027 Base::TestSetContentsRtcpMux();
3028}
3029
3030TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3031 Base::TestSetContentsRtcpMux();
3032}
3033
3034TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3035 Base::TestSetRemoteContentUpdate();
3036}
3037
3038TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3039 Base::TestStreams();
3040}
3041
3042TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3043 Base::TestUpdateStreamsInLocalContent();
3044}
3045
3046TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3047 Base::TestUpdateStreamsInRemoteContent();
3048}
3049
3050TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3051 Base::TestChangeStreamParamsInContent();
3052}
3053
3054TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3055 Base::TestPlayoutAndSendingStates();
3056}
3057
3058TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3059 CreateChannels(0, 0);
3060 // Test that we can Mute the default channel even though the sending SSRC
3061 // is unknown.
3062 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003063 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003064 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003065 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003066 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3067 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003068 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003069 SendInitiate();
3070 // After the local session description has been set, we can mute a stream
3071 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003072 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003073 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003074 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003075 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3076}
3077
3078TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3079 Base::TestMediaContentDirection();
3080}
3081
3082TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3083 Base::TestNetworkRouteChanges();
3084}
3085
3086TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3087 Base::TestCallSetup();
3088}
3089
3090TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3091 Base::TestCallTeardownRtcpMux();
3092}
3093
3094TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3095 Base::SendRtpToRtp();
3096}
3097
3098TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3099 Base::SendNoRtcpToNoRtcp();
3100}
3101
3102TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3103 Base::SendNoRtcpToRtcp();
3104}
3105
3106TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3107 Base::SendRtcpToNoRtcp();
3108}
3109
3110TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3111 Base::SendRtcpToRtcp();
3112}
3113
3114TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3115 Base::SendRtcpMuxToRtcp();
3116}
3117
3118TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3119 Base::SendRtcpMuxToRtcpMux();
3120}
3121
3122TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3123 Base::SendRequireRtcpMuxToRtcpMux();
3124}
3125
3126TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3127 Base::SendRtcpMuxToRequireRtcpMux();
3128}
3129
3130TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3131 Base::SendRequireRtcpMuxToRequireRtcpMux();
3132}
3133
3134TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3135 Base::SendRequireRtcpMuxToNoRtcpMux();
3136}
3137
3138TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3139 Base::SendEarlyRtcpMuxToRtcp();
3140}
3141
3142TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3143 Base::SendEarlyRtcpMuxToRtcpMux();
3144}
3145
3146TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3147 Base::SendSrtpToSrtp();
3148}
3149
3150TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3151 Base::SendSrtpToSrtp();
3152}
3153
3154TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3155 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3156 Base::SendSrtpToSrtp(DTLS, 0);
3157}
3158
3159TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3160 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3161 Base::SendSrtpToSrtp(DTLS, DTLS);
3162}
3163
3164TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3165 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3166 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3167}
3168
3169TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3170 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3171}
3172
3173TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3174 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3175}
3176
3177TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3178 Base::SendRtpToRtpOnThread();
3179}
3180
3181TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3182 Base::SendSrtpToSrtpOnThread();
3183}
3184
3185TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3186 Base::SendWithWritabilityLoss();
3187}
3188
3189TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3190 Base::TestMediaMonitor();
3191}
3192
3193TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3194 Base::TestSetContentFailure();
3195}
3196
3197TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3198 Base::TestSendTwoOffers();
3199}
3200
3201TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3202 Base::TestReceiveTwoOffers();
3203}
3204
3205TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3206 Base::TestSendPrAnswer();
3207}
3208
3209TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3210 Base::TestReceivePrAnswer();
3211}
3212
3213TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3214 Base::TestFlushRtcp();
3215}
3216
3217TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3218 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3219}
3220
3221TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3222 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3223}
3224
3225TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3226 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3227}
3228
3229TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3230 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3231}
3232
3233TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3234 Base::TestSrtpError(kVideoPts[0]);
3235}
3236
3237TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3238 Base::TestOnReadyToSend();
3239}
3240
3241TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3242 Base::TestOnReadyToSendWithRtcpMux();
3243}
3244
3245TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3246 Base::DefaultMaxBitrateIsUnlimited();
3247}
3248
3249TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3250 Base::CanChangeMaxBitrate();
3251}
3252
3253// DataChannelSingleThreadTest
3254class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003256 typedef ChannelTest<DataTraits> Base;
3257 DataChannelSingleThreadTest()
3258 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3259};
3260
3261// DataChannelDoubleThreadTest
3262class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3263 public:
3264 typedef ChannelTest<DataTraits> Base;
3265 DataChannelDoubleThreadTest()
3266 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267};
3268
3269// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003270template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003272 rtc::Thread* worker_thread,
3273 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003274 cricket::MediaEngineInterface* engine,
3275 cricket::FakeDataMediaChannel* ch,
3276 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003278 cricket::DataChannel* channel =
3279 new cricket::DataChannel(worker_thread, network_thread, ch,
3280 transport_controller, cricket::CN_DATA, rtcp);
skvlad6c87a672016-05-17 17:49:52 -07003281 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003282 delete channel;
3283 channel = NULL;
3284 }
3285 return channel;
3286}
3287
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003288template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289void ChannelTest<DataTraits>::CreateContent(
3290 int flags,
3291 const cricket::AudioCodec& audio_codec,
3292 const cricket::VideoCodec& video_codec,
3293 cricket::DataContentDescription* data) {
3294 data->AddCodec(kGoogleDataCodec);
3295 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3296 if (flags & SECURE) {
3297 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003298 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3299 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003300 }
3301}
3302
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003303template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304void ChannelTest<DataTraits>::CopyContent(
3305 const cricket::DataContentDescription& source,
3306 cricket::DataContentDescription* data) {
3307 *data = source;
3308}
3309
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003310template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3312 const cricket::DataCodec& c2) {
3313 return c1.name == c2.name;
3314}
3315
Peter Boström0c4e06b2015-10-07 12:23:21 +02003316template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003318 uint32_t ssrc,
3319 int flags,
3320 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003321 data->AddLegacyStream(ssrc);
3322}
3323
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003324TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003325 Base::TestInit();
3326 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3327}
3328
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003329TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3330 Base::TestDeinit();
3331}
3332
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003333TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 Base::TestSetContents();
3335}
3336
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003337TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 Base::TestSetContentsNullOffer();
3339}
3340
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003341TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342 Base::TestSetContentsRtcpMux();
3343}
3344
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003345TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 Base::TestSetRemoteContentUpdate();
3347}
3348
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003349TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 Base::TestStreams();
3351}
3352
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003353TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354 Base::TestUpdateStreamsInLocalContent();
3355}
3356
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003357TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358 Base::TestUpdateStreamsInRemoteContent();
3359}
3360
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003361TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 Base::TestChangeStreamParamsInContent();
3363}
3364
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003365TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003366 Base::TestPlayoutAndSendingStates();
3367}
3368
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003369TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370 Base::TestMediaContentDirection();
3371}
3372
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003373TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374 Base::TestCallSetup();
3375}
3376
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003377TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378 Base::TestCallTeardownRtcpMux();
3379}
3380
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003381TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 Base::TestOnReadyToSend();
3383}
3384
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003385TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 Base::TestOnReadyToSendWithRtcpMux();
3387}
3388
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003389TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390 Base::SendRtpToRtp();
3391}
3392
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003393TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 Base::SendNoRtcpToNoRtcp();
3395}
3396
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003397TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398 Base::SendNoRtcpToRtcp();
3399}
3400
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003401TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 Base::SendRtcpToNoRtcp();
3403}
3404
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003405TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406 Base::SendRtcpToRtcp();
3407}
3408
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003409TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 Base::SendRtcpMuxToRtcp();
3411}
3412
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003413TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 Base::SendRtcpMuxToRtcpMux();
3415}
3416
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003417TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 Base::SendEarlyRtcpMuxToRtcp();
3419}
3420
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003421TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 Base::SendEarlyRtcpMuxToRtcpMux();
3423}
3424
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003425TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 Base::SendSrtpToSrtp();
3427}
3428
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003429TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 Base::SendSrtpToSrtp();
3431}
3432
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003433TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3435}
3436
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003437TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 Base::SendRtpToRtpOnThread();
3439}
3440
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003441TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442 Base::SendSrtpToSrtpOnThread();
3443}
3444
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003445TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446 Base::SendWithWritabilityLoss();
3447}
3448
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003449TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450 Base::TestMediaMonitor();
3451}
3452
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003453TEST_F(DataChannelSingleThreadTest, TestSendData) {
3454 CreateChannels(0, 0);
3455 EXPECT_TRUE(SendInitiate());
3456 EXPECT_TRUE(SendAccept());
3457
3458 cricket::SendDataParams params;
3459 params.ssrc = 42;
3460 unsigned char data[] = {'f', 'o', 'o'};
3461 rtc::CopyOnWriteBuffer payload(data, 3);
3462 cricket::SendDataResult result;
3463 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3464 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3465 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3466}
3467
3468TEST_F(DataChannelDoubleThreadTest, TestInit) {
3469 Base::TestInit();
3470 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3471}
3472
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003473TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3474 Base::TestDeinit();
3475}
3476
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003477TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3478 Base::TestSetContents();
3479}
3480
3481TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3482 Base::TestSetContentsNullOffer();
3483}
3484
3485TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3486 Base::TestSetContentsRtcpMux();
3487}
3488
3489TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3490 Base::TestSetRemoteContentUpdate();
3491}
3492
3493TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3494 Base::TestStreams();
3495}
3496
3497TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3498 Base::TestUpdateStreamsInLocalContent();
3499}
3500
3501TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3502 Base::TestUpdateStreamsInRemoteContent();
3503}
3504
3505TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3506 Base::TestChangeStreamParamsInContent();
3507}
3508
3509TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3510 Base::TestPlayoutAndSendingStates();
3511}
3512
3513TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3514 Base::TestMediaContentDirection();
3515}
3516
3517TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3518 Base::TestCallSetup();
3519}
3520
3521TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3522 Base::TestCallTeardownRtcpMux();
3523}
3524
3525TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3526 Base::TestOnReadyToSend();
3527}
3528
3529TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3530 Base::TestOnReadyToSendWithRtcpMux();
3531}
3532
3533TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3534 Base::SendRtpToRtp();
3535}
3536
3537TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3538 Base::SendNoRtcpToNoRtcp();
3539}
3540
3541TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3542 Base::SendNoRtcpToRtcp();
3543}
3544
3545TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3546 Base::SendRtcpToNoRtcp();
3547}
3548
3549TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3550 Base::SendRtcpToRtcp();
3551}
3552
3553TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3554 Base::SendRtcpMuxToRtcp();
3555}
3556
3557TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3558 Base::SendRtcpMuxToRtcpMux();
3559}
3560
3561TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3562 Base::SendEarlyRtcpMuxToRtcp();
3563}
3564
3565TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3566 Base::SendEarlyRtcpMuxToRtcpMux();
3567}
3568
3569TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3570 Base::SendSrtpToSrtp();
3571}
3572
3573TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3574 Base::SendSrtpToSrtp();
3575}
3576
3577TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3578 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3579}
3580
3581TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3582 Base::SendRtpToRtpOnThread();
3583}
3584
3585TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3586 Base::SendSrtpToSrtpOnThread();
3587}
3588
3589TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3590 Base::SendWithWritabilityLoss();
3591}
3592
3593TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3594 Base::TestMediaMonitor();
3595}
3596
3597TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598 CreateChannels(0, 0);
3599 EXPECT_TRUE(SendInitiate());
3600 EXPECT_TRUE(SendAccept());
3601
3602 cricket::SendDataParams params;
3603 params.ssrc = 42;
3604 unsigned char data[] = {
3605 'f', 'o', 'o'
3606 };
jbaucheec21bd2016-03-20 06:15:43 -07003607 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003608 cricket::SendDataResult result;
3609 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3610 EXPECT_EQ(params.ssrc,
3611 media_channel1_->last_sent_data_params().ssrc);
3612 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3613}
3614
3615// TODO(pthatcher): TestSetReceiver?