blob: 492c7d548c6166d26ccb2fd15b423009a5e4cf6e [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"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000015#include "webrtc/base/gunit.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000016#include "webrtc/base/logging.h"
kjellandera96e2d72016-02-04 23:52:28 -080017#include "webrtc/media/base/fakemediaengine.h"
18#include "webrtc/media/base/fakertp.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/mediachannel.h"
kjellandera96e2d72016-02-04 23:52:28 -080020#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010021#include "webrtc/p2p/base/faketransportcontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010022#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023
24#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000025 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026 LOG(LS_INFO) << "Feature disabled... skipping"; \
27 return; \
28 }
29
30using cricket::CA_OFFER;
31using cricket::CA_PRANSWER;
32using cricket::CA_ANSWER;
33using cricket::CA_UPDATE;
34using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035using cricket::ScreencastId;
36using cricket::StreamParams;
37using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
Danil Chapovalov33b01f22016-05-11 19:55:27 +020039namespace {
40const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
41const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
42const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
43const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30);
44const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15);
45const cricket::DataCodec kGoogleDataCodec(101, "google-data");
46const uint32_t kSsrc1 = 0x1111;
47const uint32_t kSsrc2 = 0x2222;
48const uint32_t kSsrc3 = 0x3333;
49const int kAudioPts[] = {0, 8};
50const int kVideoPts[] = {97, 99};
51enum class NetworkIsWorker { Yes, No };
52} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
deadbeefcbecd352015-09-23 11:50:27 -070054template <class ChannelT,
55 class MediaChannelT,
56 class ContentT,
57 class CodecT,
58 class MediaInfoT,
59 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060class Traits {
61 public:
62 typedef ChannelT Channel;
63 typedef MediaChannelT MediaChannel;
64 typedef ContentT Content;
65 typedef CodecT Codec;
66 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020067 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068};
69
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070class VoiceTraits : public Traits<cricket::VoiceChannel,
71 cricket::FakeVoiceMediaChannel,
72 cricket::AudioContentDescription,
73 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020074 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070075 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
77class VideoTraits : public Traits<cricket::VideoChannel,
78 cricket::FakeVideoMediaChannel,
79 cricket::VideoContentDescription,
80 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020081 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070082 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
84class DataTraits : public Traits<cricket::DataChannel,
85 cricket::FakeDataMediaChannel,
86 cricket::DataContentDescription,
87 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020088 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070089 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
Danil Chapovalov33b01f22016-05-11 19:55:27 +020091// Base class for Voice/Video/DataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092template<class T>
93class ChannelTest : public testing::Test, public sigslot::has_slots<> {
94 public:
95 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
96 DTLS = 0x10 };
97
Peter Boström34fbfff2015-09-24 19:20:30 +020098 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +020099 rtc::ArrayView<const uint8_t> rtp_data,
100 rtc::ArrayView<const uint8_t> rtcp_data,
101 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200102 : verify_playout_(verify_playout),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 media_channel1_(NULL),
104 media_channel2_(NULL),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200105 rtp_packet_(rtp_data.data(), rtp_data.size()),
106 rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 media_info_callbacks1_(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200108 media_info_callbacks2_() {
109 if (network_is_worker == NetworkIsWorker::Yes) {
110 network_thread_ = rtc::Thread::Current();
111 } else {
112 network_thread_keeper_ = rtc::Thread::Create();
113 network_thread_keeper_->SetName("Network", nullptr);
114 network_thread_keeper_->Start();
115 network_thread_ = network_thread_keeper_.get();
116 }
117 transport_controller1_.reset(new cricket::FakeTransportController(
118 network_thread_, cricket::ICEROLE_CONTROLLING));
119 transport_controller2_.reset(new cricket::FakeTransportController(
120 network_thread_, cricket::ICEROLE_CONTROLLED));
121 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200124 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
125 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200126 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200128 void CreateChannels(typename T::MediaChannel* ch1,
129 typename T::MediaChannel* ch2,
130 int flags1,
131 int flags2) {
132 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 media_channel1_ = ch1;
134 media_channel2_ = ch2;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200135 channel1_.reset(
136 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
137 transport_controller1_.get(), (flags1 & RTCP) != 0));
138 channel2_.reset(
139 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
140 transport_controller2_.get(), (flags2 & RTCP) != 0));
141 channel1_->SignalMediaMonitor.connect(this,
142 &ChannelTest<T>::OnMediaMonitor1);
143 channel2_->SignalMediaMonitor.connect(this,
144 &ChannelTest<T>::OnMediaMonitor2);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000145 if ((flags1 & DTLS) && (flags2 & DTLS)) {
146 flags1 = (flags1 & ~SECURE);
147 flags2 = (flags2 & ~SECURE);
148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 CreateContent(flags1, kPcmuCodec, kH264Codec,
150 &local_media_content1_);
151 CreateContent(flags2, kPcmuCodec, kH264Codec,
152 &local_media_content2_);
153 CopyContent(local_media_content1_, &remote_media_content1_);
154 CopyContent(local_media_content2_, &remote_media_content2_);
155
156 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200157 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200158 transport_controller1_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700159 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800160 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 }
162 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200163 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200164 transport_controller2_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700165 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800166 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 }
168
169 // Add stream information (SSRC) to the local content but not to the remote
170 // content. This means that we per default know the SSRC of what we send but
171 // not what we receive.
172 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
173 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
174
175 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
176 if (flags1 & SSRC_MUX) {
177 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
178 }
179 if (flags2 & SSRC_MUX) {
180 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
181 }
182 }
deadbeefcbecd352015-09-23 11:50:27 -0700183 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200184 rtc::Thread* worker_thread,
185 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700186 cricket::MediaEngineInterface* engine,
187 typename T::MediaChannel* ch,
188 cricket::TransportController* transport_controller,
189 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200190 typename T::Channel* channel =
191 new typename T::Channel(worker_thread, network_thread, engine, ch,
192 transport_controller, cricket::CN_AUDIO, rtcp);
skvlad6c87a672016-05-17 17:49:52 -0700193 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 delete channel;
195 channel = NULL;
196 }
197 return channel;
198 }
199
200 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000201 bool result = channel1_->SetLocalContent(&local_media_content1_,
202 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 if (result) {
204 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000205 result = channel2_->SetRemoteContent(&remote_media_content1_,
206 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200208 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000210 result = channel2_->SetLocalContent(&local_media_content2_,
211 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 }
213 }
214 return result;
215 }
216
217 bool SendAccept() {
218 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000219 return channel1_->SetRemoteContent(&remote_media_content2_,
220 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 }
222
223 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000224 bool result = channel1_->SetLocalContent(&local_media_content1_,
225 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 if (result) {
227 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000228 result = channel2_->SetRemoteContent(&remote_media_content1_,
229 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 }
231 return result;
232 }
233
234 bool SendProvisionalAnswer() {
235 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000236 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 if (result) {
238 channel2_->Enable(true);
239 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000240 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200241 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 }
243 return result;
244 }
245
246 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 bool result = channel2_->SetLocalContent(&local_media_content2_,
248 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000250 result = channel1_->SetRemoteContent(&remote_media_content2_,
251 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 return result;
253 }
254
255 bool SendTerminate() {
256 channel1_.reset();
257 channel2_.reset();
258 return true;
259 }
260
261 bool AddStream1(int id) {
262 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
263 }
264 bool RemoveStream1(int id) {
265 return channel1_->RemoveRecvStream(id);
266 }
267
268 cricket::FakeTransport* GetTransport1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200269 std::string name = channel1_->content_name();
270 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700271 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200272 [this, name] { return transport_controller1_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 }
274 cricket::FakeTransport* GetTransport2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200275 std::string name = channel2_->content_name();
276 return network_thread_->Invoke<cricket::FakeTransport*>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700277 RTC_FROM_HERE,
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200278 [this, name] { return transport_controller2_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279 }
280
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200281 void SendRtp1() {
282 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
283 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200285 void SendRtp2() {
286 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
287 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200289 void SendRtcp1() {
290 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200292 void SendRtcp2() {
293 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 }
295 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200296 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
297 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
298 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200300 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
301 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
302 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200304 void SendCustomRtcp1(uint32_t ssrc) {
305 rtc::Buffer data = CreateRtcpData(ssrc);
306 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200308 void SendCustomRtcp2(uint32_t ssrc) {
309 rtc::Buffer data = CreateRtcpData(ssrc);
310 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200312
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200314 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 }
316 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200317 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 }
319 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200320 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
322 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200323 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 }
325 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200326 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200327 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
328 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200330 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200331 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
332 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200334 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200335 rtc::Buffer data = CreateRtcpData(ssrc);
336 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200338 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200339 rtc::Buffer data = CreateRtcpData(ssrc);
340 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200342 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
343 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200345 rtc::SetBE32(data.data() + 8, ssrc);
346 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000347 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200348 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000349 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 return data;
351 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200352 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
353 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200355 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 return data;
357 }
358
359 bool CheckNoRtp1() {
360 return media_channel1_->CheckNoRtp();
361 }
362 bool CheckNoRtp2() {
363 return media_channel2_->CheckNoRtp();
364 }
365 bool CheckNoRtcp1() {
366 return media_channel1_->CheckNoRtcp();
367 }
368 bool CheckNoRtcp2() {
369 return media_channel2_->CheckNoRtcp();
370 }
371
372 void CreateContent(int flags,
373 const cricket::AudioCodec& audio_codec,
374 const cricket::VideoCodec& video_codec,
375 typename T::Content* content) {
376 // overridden in specialized classes
377 }
378 void CopyContent(const typename T::Content& source,
379 typename T::Content* content) {
380 // overridden in specialized classes
381 }
382
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 // Creates a cricket::SessionDescription with one MediaContent and one stream.
384 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200385 cricket::SessionDescription* CreateSessionDescriptionWithStream(
386 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 typename T::Content content;
388 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
389 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
390 AddLegacyStreamInContent(ssrc, 0, &content);
391 sdesc->AddContent("DUMMY_CONTENT_NAME",
392 cricket::NS_JINGLE_RTP, content.Copy());
393 return sdesc;
394 }
395
ossu292d6582016-03-17 02:31:13 -0700396 // Will manage the lifetime of a CallThread, making sure it's
397 // destroyed before this object goes out of scope.
398 class ScopedCallThread {
399 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200400 template <class FunctorT>
401 ScopedCallThread(const FunctorT& functor)
402 : thread_(rtc::Thread::Create()),
403 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700404 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700405 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700406 }
407
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200408 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700409
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200410 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700411
412 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200413 std::unique_ptr<rtc::Thread> thread_;
414 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700415 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
418 return false; // overridden in specialized classes
419 }
420
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200421 void OnMediaMonitor1(typename T::Channel* channel,
422 const typename T::MediaInfo& info) {
423 RTC_DCHECK_EQ(channel, channel1_.get());
424 media_info_callbacks1_++;
425 }
426 void OnMediaMonitor2(typename T::Channel* channel,
427 const typename T::MediaInfo& info) {
428 RTC_DCHECK_EQ(channel, channel2_.get());
429 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 }
431
Honghai Zhangcc411c02016-03-29 17:27:21 -0700432 cricket::CandidatePairInterface* last_selected_candidate_pair() {
433 return last_selected_candidate_pair_;
434 }
435
Peter Boström0c4e06b2015-10-07 12:23:21 +0200436 void AddLegacyStreamInContent(uint32_t ssrc,
437 int flags,
438 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 // Base implementation.
440 }
441
442 // Tests that can be used by derived classes.
443
444 // Basic sanity check.
445 void TestInit() {
446 CreateChannels(0, 0);
447 EXPECT_FALSE(channel1_->secure());
448 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200449 if (verify_playout_) {
450 EXPECT_FALSE(media_channel1_->playout());
451 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 EXPECT_TRUE(media_channel1_->codecs().empty());
453 EXPECT_TRUE(media_channel1_->recv_streams().empty());
454 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
455 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
456 }
457
458 // Test that SetLocalContent and SetRemoteContent properly configure
459 // the codecs.
460 void TestSetContents() {
461 CreateChannels(0, 0);
462 typename T::Content content;
463 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000464 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000466 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000467 ASSERT_EQ(1U, media_channel1_->codecs().size());
468 EXPECT_TRUE(CodecMatches(content.codecs()[0],
469 media_channel1_->codecs()[0]));
470 }
471
472 // Test that SetLocalContent and SetRemoteContent properly deals
473 // with an empty offer.
474 void TestSetContentsNullOffer() {
475 CreateChannels(0, 0);
476 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000477 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000478 CreateContent(0, kPcmuCodec, kH264Codec, &content);
479 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000480 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000481 ASSERT_EQ(1U, media_channel1_->codecs().size());
482 EXPECT_TRUE(CodecMatches(content.codecs()[0],
483 media_channel1_->codecs()[0]));
484 }
485
486 // Test that SetLocalContent and SetRemoteContent properly set RTCP
487 // mux.
488 void TestSetContentsRtcpMux() {
489 CreateChannels(RTCP, RTCP);
490 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
491 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
492 typename T::Content content;
493 CreateContent(0, kPcmuCodec, kH264Codec, &content);
494 // Both sides agree on mux. Should no longer be a separate RTCP channel.
495 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000496 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
497 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
499 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000500 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000502 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
504 }
505
506 // Test that SetLocalContent and SetRemoteContent properly set RTCP
507 // mux when a provisional answer is received.
508 void TestSetContentsRtcpMuxWithPrAnswer() {
509 CreateChannels(RTCP, RTCP);
510 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
511 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
512 typename T::Content content;
513 CreateContent(0, kPcmuCodec, kH264Codec, &content);
514 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000515 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
516 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000518 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 // Both sides agree on mux. Should no longer be a separate RTCP channel.
520 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
521 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000522 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000524 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
525 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
527 }
528
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000529 // Test that SetRemoteContent properly deals with a content update.
530 void TestSetRemoteContentUpdate() {
531 CreateChannels(0, 0);
532 typename T::Content content;
533 CreateContent(RTCP | RTCP_MUX | SECURE,
534 kPcmuCodec, kH264Codec,
535 &content);
536 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000537 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
538 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 ASSERT_EQ(1U, media_channel1_->codecs().size());
540 EXPECT_TRUE(CodecMatches(content.codecs()[0],
541 media_channel1_->codecs()[0]));
542 // Now update with other codecs.
543 typename T::Content update_content;
544 update_content.set_partial(true);
545 CreateContent(0, kIsacCodec, kH264SvcCodec,
546 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000547 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 ASSERT_EQ(1U, media_channel1_->codecs().size());
549 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
550 media_channel1_->codecs()[0]));
551 // Now update without any codecs. This is ignored.
552 typename T::Content empty_content;
553 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000554 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 ASSERT_EQ(1U, media_channel1_->codecs().size());
556 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
557 media_channel1_->codecs()[0]));
558 }
559
560 // Test that Add/RemoveStream properly forward to the media channel.
561 void TestStreams() {
562 CreateChannels(0, 0);
563 EXPECT_TRUE(AddStream1(1));
564 EXPECT_TRUE(AddStream1(2));
565 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
566 EXPECT_TRUE(RemoveStream1(2));
567 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
568 EXPECT_TRUE(RemoveStream1(1));
569 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
570 }
571
572 // Test that SetLocalContent properly handles adding and removing StreamParams
573 // to the local content description.
574 // This test uses the CA_UPDATE action that don't require a full
575 // MediaContentDescription to do an update.
576 void TestUpdateStreamsInLocalContent() {
577 cricket::StreamParams stream1;
578 stream1.groupid = "group1";
579 stream1.id = "stream1";
580 stream1.ssrcs.push_back(kSsrc1);
581 stream1.cname = "stream1_cname";
582
583 cricket::StreamParams stream2;
584 stream2.groupid = "group2";
585 stream2.id = "stream2";
586 stream2.ssrcs.push_back(kSsrc2);
587 stream2.cname = "stream2_cname";
588
589 cricket::StreamParams stream3;
590 stream3.groupid = "group3";
591 stream3.id = "stream3";
592 stream3.ssrcs.push_back(kSsrc3);
593 stream3.cname = "stream3_cname";
594
595 CreateChannels(0, 0);
596 typename T::Content content1;
597 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
598 content1.AddStream(stream1);
599 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000600 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000601
602 ASSERT_EQ(1u, media_channel1_->send_streams().size());
603 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
604
605 // Update the local streams by adding another sending stream.
606 // Use a partial updated session description.
607 typename T::Content content2;
608 content2.AddStream(stream2);
609 content2.AddStream(stream3);
610 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000611 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 ASSERT_EQ(3u, media_channel1_->send_streams().size());
613 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
614 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
615 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
616
617 // Update the local streams by removing the first sending stream.
618 // This is done by removing all SSRCS for this particular stream.
619 typename T::Content content3;
620 stream1.ssrcs.clear();
621 content3.AddStream(stream1);
622 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000623 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 ASSERT_EQ(2u, media_channel1_->send_streams().size());
625 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
626 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
627
628 // Update the local streams with a stream that does not change.
629 // THe update is ignored.
630 typename T::Content content4;
631 content4.AddStream(stream2);
632 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000633 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634 ASSERT_EQ(2u, media_channel1_->send_streams().size());
635 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
636 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
637 }
638
639 // Test that SetRemoteContent properly handles adding and removing
640 // StreamParams to the remote content description.
641 // This test uses the CA_UPDATE action that don't require a full
642 // MediaContentDescription to do an update.
643 void TestUpdateStreamsInRemoteContent() {
644 cricket::StreamParams stream1;
645 stream1.id = "Stream1";
646 stream1.groupid = "1";
647 stream1.ssrcs.push_back(kSsrc1);
648 stream1.cname = "stream1_cname";
649
650 cricket::StreamParams stream2;
651 stream2.id = "Stream2";
652 stream2.groupid = "2";
653 stream2.ssrcs.push_back(kSsrc2);
654 stream2.cname = "stream2_cname";
655
656 cricket::StreamParams stream3;
657 stream3.id = "Stream3";
658 stream3.groupid = "3";
659 stream3.ssrcs.push_back(kSsrc3);
660 stream3.cname = "stream3_cname";
661
662 CreateChannels(0, 0);
663 typename T::Content content1;
664 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
665 content1.AddStream(stream1);
666 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000667 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668
669 ASSERT_EQ(1u, media_channel1_->codecs().size());
670 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
671 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
672
673 // Update the remote streams by adding another sending stream.
674 // Use a partial updated session description.
675 typename T::Content content2;
676 content2.AddStream(stream2);
677 content2.AddStream(stream3);
678 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000679 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
681 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
682 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
683 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
684
685 // Update the remote streams by removing the first stream.
686 // This is done by removing all SSRCS for this particular stream.
687 typename T::Content content3;
688 stream1.ssrcs.clear();
689 content3.AddStream(stream1);
690 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000691 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
693 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
694 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
695
696 // Update the remote streams with a stream that does not change.
697 // The update is ignored.
698 typename T::Content content4;
699 content4.AddStream(stream2);
700 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000701 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
703 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
704 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
705 }
706
707 // Test that SetLocalContent and SetRemoteContent properly
708 // handles adding and removing StreamParams when the action is a full
709 // CA_OFFER / CA_ANSWER.
710 void TestChangeStreamParamsInContent() {
711 cricket::StreamParams stream1;
712 stream1.groupid = "group1";
713 stream1.id = "stream1";
714 stream1.ssrcs.push_back(kSsrc1);
715 stream1.cname = "stream1_cname";
716
717 cricket::StreamParams stream2;
718 stream2.groupid = "group1";
719 stream2.id = "stream2";
720 stream2.ssrcs.push_back(kSsrc2);
721 stream2.cname = "stream2_cname";
722
723 // Setup a call where channel 1 send |stream1| to channel 2.
724 CreateChannels(0, 0);
725 typename T::Content content1;
726 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
727 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 EXPECT_TRUE(channel1_->Enable(true));
730 EXPECT_EQ(1u, media_channel1_->send_streams().size());
731
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000732 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200734 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735
736 // Channel 2 do not send anything.
737 typename T::Content content2;
738 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000739 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000741 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 EXPECT_TRUE(channel2_->Enable(true));
743 EXPECT_EQ(0u, media_channel2_->send_streams().size());
744
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200745 SendCustomRtp1(kSsrc1, 0);
746 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000747 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
748
749 // Let channel 2 update the content by sending |stream2| and enable SRTP.
750 typename T::Content content3;
751 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
752 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000753 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 ASSERT_EQ(1u, media_channel2_->send_streams().size());
755 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
756
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000757 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
759 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
760
761 // Channel 1 replies but stop sending stream1.
762 typename T::Content content4;
763 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000764 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 EXPECT_EQ(0u, media_channel1_->send_streams().size());
766
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000767 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
769
770 EXPECT_TRUE(channel1_->secure());
771 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200772 SendCustomRtp2(kSsrc2, 0);
773 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
775 }
776
777 // Test that we only start playout and sending at the right times.
778 void TestPlayoutAndSendingStates() {
779 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200780 if (verify_playout_) {
781 EXPECT_FALSE(media_channel1_->playout());
782 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200784 if (verify_playout_) {
785 EXPECT_FALSE(media_channel2_->playout());
786 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 EXPECT_FALSE(media_channel2_->sending());
788 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200789 if (verify_playout_) {
790 EXPECT_FALSE(media_channel1_->playout());
791 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
794 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200795 if (verify_playout_) {
796 EXPECT_TRUE(media_channel1_->playout());
797 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000799 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
800 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200801 if (verify_playout_) {
802 EXPECT_FALSE(media_channel2_->playout());
803 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000805 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
806 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200807 if (verify_playout_) {
808 EXPECT_FALSE(media_channel2_->playout());
809 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 EXPECT_FALSE(media_channel2_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200811 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200812 if (verify_playout_) {
813 EXPECT_TRUE(media_channel1_->playout());
814 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200816 if (verify_playout_) {
817 EXPECT_FALSE(media_channel2_->playout());
818 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 EXPECT_FALSE(media_channel2_->sending());
820 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200821 if (verify_playout_) {
822 EXPECT_TRUE(media_channel2_->playout());
823 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000825 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
826 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200827 if (verify_playout_) {
828 EXPECT_TRUE(media_channel1_->playout());
829 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 EXPECT_TRUE(media_channel1_->sending());
831 }
832
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 // Test that changing the MediaContentDirection in the local and remote
834 // session description start playout and sending at the right time.
835 void TestMediaContentDirection() {
836 CreateChannels(0, 0);
837 typename T::Content content1;
838 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
839 typename T::Content content2;
840 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
841 // Set |content2| to be InActive.
842 content2.set_direction(cricket::MD_INACTIVE);
843
844 EXPECT_TRUE(channel1_->Enable(true));
845 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200846 if (verify_playout_) {
847 EXPECT_FALSE(media_channel1_->playout());
848 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200850 if (verify_playout_) {
851 EXPECT_FALSE(media_channel2_->playout());
852 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 EXPECT_FALSE(media_channel2_->sending());
854
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000855 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
856 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
857 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
858 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200859 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860
Peter Boström34fbfff2015-09-24 19:20:30 +0200861 if (verify_playout_) {
862 EXPECT_TRUE(media_channel1_->playout());
863 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200865 if (verify_playout_) {
866 EXPECT_FALSE(media_channel2_->playout()); // local InActive
867 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 EXPECT_FALSE(media_channel2_->sending()); // local InActive
869
870 // Update |content2| to be RecvOnly.
871 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000872 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
873 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874
Peter Boström34fbfff2015-09-24 19:20:30 +0200875 if (verify_playout_) {
876 EXPECT_TRUE(media_channel1_->playout());
877 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200879 if (verify_playout_) {
880 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
881 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
883
884 // Update |content2| to be SendRecv.
885 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000886 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
887 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888
Peter Boström34fbfff2015-09-24 19:20:30 +0200889 if (verify_playout_) {
890 EXPECT_TRUE(media_channel1_->playout());
891 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200893 if (verify_playout_) {
894 EXPECT_TRUE(media_channel2_->playout());
895 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 EXPECT_TRUE(media_channel2_->sending());
897 }
898
Honghai Zhangcc411c02016-03-29 17:27:21 -0700899 // Tests that when the transport channel signals a candidate pair change
900 // event, the media channel will receive a call on the network route change.
901 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200902 constexpr uint16_t kLocalNetId = 1;
903 constexpr uint16_t kRemoteNetId = 2;
904 constexpr int kLastPacketId = 100;
905
Honghai Zhangcc411c02016-03-29 17:27:21 -0700906 CreateChannels(0, 0);
907
908 cricket::TransportChannel* transport_channel1 =
909 channel1_->transport_channel();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200910 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700911 typename T::MediaChannel* media_channel1 =
912 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200913 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700914
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200915 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700916 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200917 // The transport channel becomes disconnected.
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700918 transport_channel1->SignalSelectedCandidatePairChanged(
919 transport_channel1, nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200920 });
921 WaitForThreads();
922 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700923 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200924 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700925
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700926 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
927 media_channel1, kLocalNetId,
928 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200929 // The transport channel becomes connected.
930 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
931 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
932 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
933 transport_controller1_->CreateFakeCandidatePair(
934 local_address, kLocalNetId, remote_address, kRemoteNetId));
935 transport_channel1->SignalSelectedCandidatePairChanged(
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700936 transport_channel1, candidate_pair.get(), kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200937 });
938 WaitForThreads();
939 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700940 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200941 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700942 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200943 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700944 media_channel1->last_network_route().last_sent_packet_id);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700945 }
946
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 // Test setting up a call.
948 void TestCallSetup() {
949 CreateChannels(0, 0);
950 EXPECT_FALSE(channel1_->secure());
951 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200952 if (verify_playout_) {
953 EXPECT_TRUE(media_channel1_->playout());
954 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 EXPECT_FALSE(media_channel1_->sending());
956 EXPECT_TRUE(SendAccept());
957 EXPECT_FALSE(channel1_->secure());
958 EXPECT_TRUE(media_channel1_->sending());
959 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200960 if (verify_playout_) {
961 EXPECT_TRUE(media_channel2_->playout());
962 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 EXPECT_TRUE(media_channel2_->sending());
964 EXPECT_EQ(1U, media_channel2_->codecs().size());
965 }
966
967 // Test that we don't crash if packets are sent during call teardown
968 // when RTCP mux is enabled. This is a regression test against a specific
969 // race condition that would only occur when a RTCP packet was sent during
970 // teardown of a channel on which RTCP mux was enabled.
971 void TestCallTeardownRtcpMux() {
972 class LastWordMediaChannel : public T::MediaChannel {
973 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200974 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700976 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
977 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
979 }
980 };
981 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200982 RTCP | RTCP_MUX, RTCP | RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 EXPECT_TRUE(SendInitiate());
984 EXPECT_TRUE(SendAccept());
985 EXPECT_TRUE(SendTerminate());
986 }
987
988 // Send voice RTP data to the other side and ensure it gets there.
989 void SendRtpToRtp() {
990 CreateChannels(0, 0);
991 EXPECT_TRUE(SendInitiate());
992 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700993 ASSERT_TRUE(GetTransport1());
994 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000995 EXPECT_EQ(1U, GetTransport1()->channels().size());
996 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200997 SendRtp1();
998 SendRtp2();
999 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 EXPECT_TRUE(CheckRtp1());
1001 EXPECT_TRUE(CheckRtp2());
1002 EXPECT_TRUE(CheckNoRtp1());
1003 EXPECT_TRUE(CheckNoRtp2());
1004 }
1005
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001006 void TestDeinit() {
1007 CreateChannels(RTCP, RTCP);
1008 EXPECT_TRUE(SendInitiate());
1009 EXPECT_TRUE(SendAccept());
1010 SendRtp1();
1011 SendRtp2();
1012 SendRtcp1();
1013 SendRtcp2();
1014 // Do not wait, destroy channels.
1015 channel1_.reset(nullptr);
1016 channel2_.reset(nullptr);
1017 }
1018
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 // Check that RTCP is not transmitted if both sides don't support RTCP.
1020 void SendNoRtcpToNoRtcp() {
1021 CreateChannels(0, 0);
1022 EXPECT_TRUE(SendInitiate());
1023 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001024 ASSERT_TRUE(GetTransport1());
1025 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 EXPECT_EQ(1U, GetTransport1()->channels().size());
1027 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001028 SendRtcp1();
1029 SendRtcp2();
1030 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 EXPECT_TRUE(CheckNoRtcp1());
1032 EXPECT_TRUE(CheckNoRtcp2());
1033 }
1034
1035 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1036 void SendNoRtcpToRtcp() {
1037 CreateChannels(0, RTCP);
1038 EXPECT_TRUE(SendInitiate());
1039 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001040 ASSERT_TRUE(GetTransport1());
1041 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042 EXPECT_EQ(1U, GetTransport1()->channels().size());
1043 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001044 SendRtcp1();
1045 SendRtcp2();
1046 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 EXPECT_TRUE(CheckNoRtcp1());
1048 EXPECT_TRUE(CheckNoRtcp2());
1049 }
1050
1051 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1052 void SendRtcpToNoRtcp() {
1053 CreateChannels(RTCP, 0);
1054 EXPECT_TRUE(SendInitiate());
1055 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001056 ASSERT_TRUE(GetTransport1());
1057 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 EXPECT_EQ(2U, GetTransport1()->channels().size());
1059 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001060 SendRtcp1();
1061 SendRtcp2();
1062 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 EXPECT_TRUE(CheckNoRtcp1());
1064 EXPECT_TRUE(CheckNoRtcp2());
1065 }
1066
1067 // Check that RTCP is transmitted if both sides support RTCP.
1068 void SendRtcpToRtcp() {
1069 CreateChannels(RTCP, RTCP);
1070 EXPECT_TRUE(SendInitiate());
1071 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001072 ASSERT_TRUE(GetTransport1());
1073 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 EXPECT_EQ(2U, GetTransport1()->channels().size());
1075 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001076 SendRtcp1();
1077 SendRtcp2();
1078 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001079 EXPECT_TRUE(CheckRtcp1());
1080 EXPECT_TRUE(CheckRtcp2());
1081 EXPECT_TRUE(CheckNoRtcp1());
1082 EXPECT_TRUE(CheckNoRtcp2());
1083 }
1084
1085 // Check that RTCP is transmitted if only the initiator supports mux.
1086 void SendRtcpMuxToRtcp() {
1087 CreateChannels(RTCP | RTCP_MUX, RTCP);
1088 EXPECT_TRUE(SendInitiate());
1089 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001090 ASSERT_TRUE(GetTransport1());
1091 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 EXPECT_EQ(2U, GetTransport1()->channels().size());
1093 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001094 SendRtcp1();
1095 SendRtcp2();
1096 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 EXPECT_TRUE(CheckRtcp1());
1098 EXPECT_TRUE(CheckRtcp2());
1099 EXPECT_TRUE(CheckNoRtcp1());
1100 EXPECT_TRUE(CheckNoRtcp2());
1101 }
1102
1103 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1104 void SendRtcpMuxToRtcpMux() {
1105 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1106 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001107 ASSERT_TRUE(GetTransport1());
1108 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 EXPECT_EQ(2U, GetTransport1()->channels().size());
1110 EXPECT_EQ(1U, GetTransport2()->channels().size());
1111 EXPECT_TRUE(SendAccept());
1112 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001113 SendRtp1();
1114 SendRtp2();
1115 SendRtcp1();
1116 SendRtcp2();
1117 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 EXPECT_TRUE(CheckRtp1());
1119 EXPECT_TRUE(CheckRtp2());
1120 EXPECT_TRUE(CheckNoRtp1());
1121 EXPECT_TRUE(CheckNoRtp2());
1122 EXPECT_TRUE(CheckRtcp1());
1123 EXPECT_TRUE(CheckRtcp2());
1124 EXPECT_TRUE(CheckNoRtcp1());
1125 EXPECT_TRUE(CheckNoRtcp2());
1126 }
1127
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001128 // Check that RTP and RTCP are transmitted ok when both sides
1129 // support mux and one the offerer requires mux.
1130 void SendRequireRtcpMuxToRtcpMux() {
1131 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1132 channel1_->ActivateRtcpMux();
1133 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001134 ASSERT_TRUE(GetTransport1());
1135 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001136 EXPECT_EQ(1U, GetTransport1()->channels().size());
1137 EXPECT_EQ(1U, GetTransport2()->channels().size());
1138 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001139 SendRtp1();
1140 SendRtp2();
1141 SendRtcp1();
1142 SendRtcp2();
1143 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001144 EXPECT_TRUE(CheckRtp1());
1145 EXPECT_TRUE(CheckRtp2());
1146 EXPECT_TRUE(CheckNoRtp1());
1147 EXPECT_TRUE(CheckNoRtp2());
1148 EXPECT_TRUE(CheckRtcp1());
1149 EXPECT_TRUE(CheckRtcp2());
1150 EXPECT_TRUE(CheckNoRtcp1());
1151 EXPECT_TRUE(CheckNoRtcp2());
1152 }
1153
1154 // Check that RTP and RTCP are transmitted ok when both sides
1155 // support mux and one the answerer requires rtcp mux.
1156 void SendRtcpMuxToRequireRtcpMux() {
1157 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1158 channel2_->ActivateRtcpMux();
1159 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001160 ASSERT_TRUE(GetTransport1());
1161 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001162 EXPECT_EQ(2U, GetTransport1()->channels().size());
1163 EXPECT_EQ(1U, GetTransport2()->channels().size());
1164 EXPECT_TRUE(SendAccept());
1165 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001166 SendRtp1();
1167 SendRtp2();
1168 SendRtcp1();
1169 SendRtcp2();
1170 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001171 EXPECT_TRUE(CheckRtp1());
1172 EXPECT_TRUE(CheckRtp2());
1173 EXPECT_TRUE(CheckNoRtp1());
1174 EXPECT_TRUE(CheckNoRtp2());
1175 EXPECT_TRUE(CheckRtcp1());
1176 EXPECT_TRUE(CheckRtcp2());
1177 EXPECT_TRUE(CheckNoRtcp1());
1178 EXPECT_TRUE(CheckNoRtcp2());
1179 }
1180
1181 // Check that RTP and RTCP are transmitted ok when both sides
1182 // require mux.
1183 void SendRequireRtcpMuxToRequireRtcpMux() {
1184 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1185 channel1_->ActivateRtcpMux();
1186 channel2_->ActivateRtcpMux();
1187 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001188 ASSERT_TRUE(GetTransport1());
1189 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001190 EXPECT_EQ(1U, GetTransport1()->channels().size());
1191 EXPECT_EQ(1U, GetTransport2()->channels().size());
1192 EXPECT_TRUE(SendAccept());
1193 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001194 SendRtp1();
1195 SendRtp2();
1196 SendRtcp1();
1197 SendRtcp2();
1198 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001199 EXPECT_TRUE(CheckRtp1());
1200 EXPECT_TRUE(CheckRtp2());
1201 EXPECT_TRUE(CheckNoRtp1());
1202 EXPECT_TRUE(CheckNoRtp2());
1203 EXPECT_TRUE(CheckRtcp1());
1204 EXPECT_TRUE(CheckRtcp2());
1205 EXPECT_TRUE(CheckNoRtcp1());
1206 EXPECT_TRUE(CheckNoRtcp2());
1207 }
1208
1209 // Check that SendAccept fails if the answerer doesn't support mux
1210 // and the offerer requires it.
1211 void SendRequireRtcpMuxToNoRtcpMux() {
1212 CreateChannels(RTCP | RTCP_MUX, RTCP);
1213 channel1_->ActivateRtcpMux();
1214 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001215 ASSERT_TRUE(GetTransport1());
1216 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001217 EXPECT_EQ(1U, GetTransport1()->channels().size());
1218 EXPECT_EQ(2U, GetTransport2()->channels().size());
1219 EXPECT_FALSE(SendAccept());
1220 }
1221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 // Check that RTCP data sent by the initiator before the accept is not muxed.
1223 void SendEarlyRtcpMuxToRtcp() {
1224 CreateChannels(RTCP | RTCP_MUX, RTCP);
1225 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001226 ASSERT_TRUE(GetTransport1());
1227 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228 EXPECT_EQ(2U, GetTransport1()->channels().size());
1229 EXPECT_EQ(2U, GetTransport2()->channels().size());
1230
1231 // RTCP can be sent before the call is accepted, if the transport is ready.
1232 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001233 SendRtcp1();
1234 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 EXPECT_TRUE(CheckNoRtp2());
1236 EXPECT_TRUE(CheckRtcp2());
1237
1238 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001239 SendRtcp2();
1240 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 EXPECT_TRUE(CheckNoRtp1());
1242 EXPECT_TRUE(CheckRtcp1());
1243
1244 // Complete call setup and ensure everything is still OK.
1245 EXPECT_TRUE(SendAccept());
1246 EXPECT_EQ(2U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001247 SendRtcp1();
1248 SendRtcp2();
1249 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251 EXPECT_TRUE(CheckRtcp1());
1252 }
1253
1254
1255 // Check that RTCP data is not muxed until both sides have enabled muxing,
1256 // but that we properly demux before we get the accept message, since there
1257 // is a race between RTP data and the jingle accept.
1258 void SendEarlyRtcpMuxToRtcpMux() {
1259 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1260 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001261 ASSERT_TRUE(GetTransport1());
1262 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263 EXPECT_EQ(2U, GetTransport1()->channels().size());
1264 EXPECT_EQ(1U, GetTransport2()->channels().size());
1265
1266 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1267 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001268 SendRtcp1();
1269 WaitForThreads();
1270 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271
1272 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001273 SendRtcp2();
1274 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 EXPECT_TRUE(CheckNoRtp1());
1276 EXPECT_TRUE(CheckRtcp1());
1277
1278 // Complete call setup and ensure everything is still OK.
1279 EXPECT_TRUE(SendAccept());
1280 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001281 SendRtcp1();
1282 SendRtcp2();
1283 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 EXPECT_TRUE(CheckRtcp1());
1286 }
1287
1288 // Test that we properly send SRTP with RTCP in both directions.
1289 // You can pass in DTLS and/or RTCP_MUX as flags.
1290 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1291 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1292 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1293
1294 int flags1 = RTCP | SECURE | flags1_in;
1295 int flags2 = RTCP | SECURE | flags2_in;
1296 bool dtls1 = !!(flags1_in & DTLS);
1297 bool dtls2 = !!(flags2_in & DTLS);
1298 CreateChannels(flags1, flags2);
1299 EXPECT_FALSE(channel1_->secure());
1300 EXPECT_FALSE(channel2_->secure());
1301 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001302 WaitForThreads();
1303 EXPECT_TRUE(channel1_->writable());
1304 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 EXPECT_TRUE(SendAccept());
1306 EXPECT_TRUE(channel1_->secure());
1307 EXPECT_TRUE(channel2_->secure());
1308 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1309 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001310 SendRtp1();
1311 SendRtp2();
1312 SendRtcp1();
1313 SendRtcp2();
1314 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 EXPECT_TRUE(CheckRtp1());
1316 EXPECT_TRUE(CheckRtp2());
1317 EXPECT_TRUE(CheckNoRtp1());
1318 EXPECT_TRUE(CheckNoRtp2());
1319 EXPECT_TRUE(CheckRtcp1());
1320 EXPECT_TRUE(CheckRtcp2());
1321 EXPECT_TRUE(CheckNoRtcp1());
1322 EXPECT_TRUE(CheckNoRtcp2());
1323 }
1324
1325 // Test that we properly handling SRTP negotiating down to RTP.
1326 void SendSrtpToRtp() {
1327 CreateChannels(RTCP | SECURE, RTCP);
1328 EXPECT_FALSE(channel1_->secure());
1329 EXPECT_FALSE(channel2_->secure());
1330 EXPECT_TRUE(SendInitiate());
1331 EXPECT_TRUE(SendAccept());
1332 EXPECT_FALSE(channel1_->secure());
1333 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001334 SendRtp1();
1335 SendRtp2();
1336 SendRtcp1();
1337 SendRtcp2();
1338 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339 EXPECT_TRUE(CheckRtp1());
1340 EXPECT_TRUE(CheckRtp2());
1341 EXPECT_TRUE(CheckNoRtp1());
1342 EXPECT_TRUE(CheckNoRtp2());
1343 EXPECT_TRUE(CheckRtcp1());
1344 EXPECT_TRUE(CheckRtcp2());
1345 EXPECT_TRUE(CheckNoRtcp1());
1346 EXPECT_TRUE(CheckNoRtcp2());
1347 }
1348
1349 // Test that we can send and receive early media when a provisional answer is
1350 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1351 void SendEarlyMediaUsingRtcpMuxSrtp() {
1352 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1353
1354 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1355 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1356 EXPECT_TRUE(SendOffer());
1357 EXPECT_TRUE(SendProvisionalAnswer());
1358 EXPECT_TRUE(channel1_->secure());
1359 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001360 ASSERT_TRUE(GetTransport1());
1361 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 EXPECT_EQ(2U, GetTransport1()->channels().size());
1363 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001364 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1365 SendCustomRtcp1(kSsrc1);
1366 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1367 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1370
1371 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001372 SendCustomRtcp2(kSsrc2);
1373 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1374 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1377
1378 // Complete call setup and ensure everything is still OK.
1379 EXPECT_TRUE(SendFinalAnswer());
1380 EXPECT_EQ(1U, GetTransport1()->channels().size());
1381 EXPECT_EQ(1U, GetTransport2()->channels().size());
1382 EXPECT_TRUE(channel1_->secure());
1383 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001384 SendCustomRtcp1(kSsrc1);
1385 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1386 SendCustomRtcp2(kSsrc2);
1387 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1388 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1393 }
1394
1395 // Test that we properly send RTP without SRTP from a thread.
1396 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001397 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 EXPECT_TRUE(SendInitiate());
1399 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001400 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1401 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1402 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1403 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1404 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1405 send_rtcp1.thread(),
1406 send_rtcp2.thread()};
1407 WaitForThreads(involved_threads);
1408 EXPECT_TRUE(CheckRtp1());
1409 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 EXPECT_TRUE(CheckNoRtp1());
1411 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001412 EXPECT_TRUE(CheckRtcp1());
1413 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 EXPECT_TRUE(CheckNoRtcp1());
1415 EXPECT_TRUE(CheckNoRtcp2());
1416 }
1417
1418 // Test that we properly send SRTP with RTCP from a thread.
1419 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1421 EXPECT_TRUE(SendInitiate());
1422 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001423 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1424 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1425 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1426 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1427 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1428 send_rtcp1.thread(),
1429 send_rtcp2.thread()};
1430 WaitForThreads(involved_threads);
1431 EXPECT_TRUE(CheckRtp1());
1432 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 EXPECT_TRUE(CheckNoRtp1());
1434 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001435 EXPECT_TRUE(CheckRtcp1());
1436 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 EXPECT_TRUE(CheckNoRtcp1());
1438 EXPECT_TRUE(CheckNoRtcp2());
1439 }
1440
1441 // Test that the mediachannel retains its sending state after the transport
1442 // becomes non-writable.
1443 void SendWithWritabilityLoss() {
1444 CreateChannels(0, 0);
1445 EXPECT_TRUE(SendInitiate());
1446 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001447 ASSERT_TRUE(GetTransport1());
1448 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 EXPECT_EQ(1U, GetTransport1()->channels().size());
1450 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001451 SendRtp1();
1452 SendRtp2();
1453 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 EXPECT_TRUE(CheckRtp1());
1455 EXPECT_TRUE(CheckRtp2());
1456 EXPECT_TRUE(CheckNoRtp1());
1457 EXPECT_TRUE(CheckNoRtp2());
1458
wu@webrtc.org97077a32013-10-25 21:18:33 +00001459 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001460 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001461 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001462 SendRtp1();
1463 SendRtp2();
1464 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 EXPECT_TRUE(CheckRtp1());
1466 EXPECT_TRUE(CheckNoRtp2());
1467
1468 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001469 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001470 RTC_FROM_HERE, [this] { GetTransport1()->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001471 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001472 SendRtp1();
1473 SendRtp2();
1474 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 EXPECT_TRUE(CheckRtp1());
1476 EXPECT_TRUE(CheckRtp2());
1477 EXPECT_TRUE(CheckNoRtp1());
1478 EXPECT_TRUE(CheckNoRtp2());
1479
1480 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001481 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001482 RTC_FROM_HERE, [this] { GetTransport1()->SetDestination(NULL); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 EXPECT_TRUE(media_channel1_->sending());
1484
wu@webrtc.org97077a32013-10-25 21:18:33 +00001485 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001486 SendRtp1();
1487 SendRtp2();
1488 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 EXPECT_TRUE(CheckRtp1());
1490 EXPECT_TRUE(CheckNoRtp2());
1491
1492 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001493 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1494 GetTransport1()->SetDestination(GetTransport2());
1495 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001497 SendRtp1();
1498 SendRtp2();
1499 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 EXPECT_TRUE(CheckRtp1());
1501 EXPECT_TRUE(CheckRtp2());
1502 EXPECT_TRUE(CheckNoRtp1());
1503 EXPECT_TRUE(CheckNoRtp2());
1504 }
1505
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001506 void SendBundleToBundle(
1507 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1508 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001510 // Only pl_type1 was added to the bundle filter for both |channel1_|
1511 // and |channel2_|.
1512 int pl_type1 = pl_types[0];
1513 int pl_type2 = pl_types[1];
1514 int flags = SSRC_MUX | RTCP;
1515 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001516 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001517 if (rtcp_mux) {
1518 flags |= RTCP_MUX;
1519 expected_channels = 1U;
1520 }
1521 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001523 ASSERT_TRUE(GetTransport1());
1524 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001526 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001528 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1529 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1530 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1531 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1532 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1533 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001534
1535 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001536 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1537 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1538 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001539 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001540 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1541 EXPECT_TRUE(CheckNoRtp1());
1542 EXPECT_TRUE(CheckNoRtp2());
1543
1544 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001545 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1546 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1547 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001548 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001549 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1550
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001551 SendCustomRtcp1(kSsrc1);
1552 SendCustomRtcp2(kSsrc2);
1553 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1555 EXPECT_TRUE(CheckNoRtcp1());
1556 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1557 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001559 SendCustomRtcp1(kSsrc2);
1560 SendCustomRtcp2(kSsrc1);
1561 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001562 // Bundle filter shouldn't filter out any RTCP.
1563 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1564 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 }
1566
1567 // Test that the media monitor can be run and gives timely callbacks.
1568 void TestMediaMonitor() {
1569 static const int kTimeout = 500;
1570 CreateChannels(0, 0);
1571 EXPECT_TRUE(SendInitiate());
1572 EXPECT_TRUE(SendAccept());
1573 channel1_->StartMediaMonitor(100);
1574 channel2_->StartMediaMonitor(100);
1575 // Ensure we get callbacks and stop.
1576 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1577 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1578 channel1_->StopMediaMonitor();
1579 channel2_->StopMediaMonitor();
1580 // Ensure a restart of a stopped monitor works.
1581 channel1_->StartMediaMonitor(100);
1582 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1583 channel1_->StopMediaMonitor();
1584 // Ensure stopping a stopped monitor is OK.
1585 channel1_->StopMediaMonitor();
1586 }
1587
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 void TestSetContentFailure() {
1589 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590
Peter Thatchera6d24442015-07-09 21:26:36 -07001591 auto sdesc = cricket::SessionDescription();
1592 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1593 new cricket::AudioContentDescription());
1594 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1595 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596
Peter Thatchera6d24442015-07-09 21:26:36 -07001597 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001599 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1600 &sdesc, cricket::CA_OFFER, &err));
1601 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1602 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001605 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1606 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001608 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1609 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 }
1611
1612 void TestSendTwoOffers() {
1613 CreateChannels(0, 0);
1614
Peter Thatchera6d24442015-07-09 21:26:36 -07001615 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001616 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001617 CreateSessionDescriptionWithStream(1));
1618 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1619 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1621
kwiberg31022942016-03-11 14:18:21 -08001622 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001623 CreateSessionDescriptionWithStream(2));
1624 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1625 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1627 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1628 }
1629
1630 void TestReceiveTwoOffers() {
1631 CreateChannels(0, 0);
1632
Peter Thatchera6d24442015-07-09 21:26:36 -07001633 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001634 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001635 CreateSessionDescriptionWithStream(1));
1636 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1637 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1639
kwiberg31022942016-03-11 14:18:21 -08001640 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001641 CreateSessionDescriptionWithStream(2));
1642 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1643 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1645 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1646 }
1647
1648 void TestSendPrAnswer() {
1649 CreateChannels(0, 0);
1650
Peter Thatchera6d24442015-07-09 21:26:36 -07001651 std::string err;
1652 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001653 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001654 CreateSessionDescriptionWithStream(1));
1655 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1656 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1658
Peter Thatchera6d24442015-07-09 21:26:36 -07001659 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001660 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001661 CreateSessionDescriptionWithStream(2));
1662 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1663 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1665 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1666
Peter Thatchera6d24442015-07-09 21:26:36 -07001667 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001668 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001669 CreateSessionDescriptionWithStream(3));
1670 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1671 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1673 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1674 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1675 }
1676
1677 void TestReceivePrAnswer() {
1678 CreateChannels(0, 0);
1679
Peter Thatchera6d24442015-07-09 21:26:36 -07001680 std::string err;
1681 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001682 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001683 CreateSessionDescriptionWithStream(1));
1684 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1685 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1687
Peter Thatchera6d24442015-07-09 21:26:36 -07001688 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001689 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001690 CreateSessionDescriptionWithStream(2));
1691 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1692 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1694 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1695
Peter Thatchera6d24442015-07-09 21:26:36 -07001696 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001697 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001698 CreateSessionDescriptionWithStream(3));
1699 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1700 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1702 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1703 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1704 }
1705
1706 void TestFlushRtcp() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 CreateChannels(RTCP, RTCP);
1708 EXPECT_TRUE(SendInitiate());
1709 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001710 ASSERT_TRUE(GetTransport1());
1711 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712 EXPECT_EQ(2U, GetTransport1()->channels().size());
1713 EXPECT_EQ(2U, GetTransport2()->channels().size());
1714
1715 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001716 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 // The sending message is only posted. channel2_ should be empty.
1718 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001719 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1720 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721
1722 // When channel1_ is deleted, the RTCP packet should be sent out to
1723 // channel2_.
1724 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001725 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 EXPECT_TRUE(CheckRtcp2());
1727 }
1728
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001729 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001730 struct SrtpErrorHandler : public sigslot::has_slots<> {
1731 SrtpErrorHandler() :
1732 mode_(cricket::SrtpFilter::UNPROTECT),
1733 error_(cricket::SrtpFilter::ERROR_NONE) {}
1734 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1735 cricket::SrtpFilter::Error error) {
1736 mode_ = mode;
1737 error_ = error;
1738 }
1739 cricket::SrtpFilter::Mode mode_;
1740 cricket::SrtpFilter::Error error_;
1741 } error_handler;
1742
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001743 // For Audio, only pl_type 0 is added to the bundle filter.
1744 // For Video, only pl_type 97 is added to the bundle filter.
1745 // So we need to pass in pl_type so that the packet can pass through
1746 // the bundle filter before it can be processed by the srtp filter.
1747 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001748 static unsigned const char kBadPacket[] = {
1749 0x84, static_cast<unsigned char>(pl_type),
1750 0x00, 0x01,
1751 0x00, 0x00,
1752 0x00, 0x00,
1753 0x00, 0x00,
1754 0x00, 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1756 EXPECT_FALSE(channel1_->secure());
1757 EXPECT_FALSE(channel2_->secure());
1758 EXPECT_TRUE(SendInitiate());
1759 EXPECT_TRUE(SendAccept());
1760 EXPECT_TRUE(channel1_->secure());
1761 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001762 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001763 channel2_->srtp_filter()->SignalSrtpError.connect(
1764 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765
1766 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001767 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1768 rtc::PacketOptions());
1769 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001771 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001772 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1773 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001774 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1775 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001776 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1777 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001779 WaitForThreads();
solenberg5629a1d2015-10-01 08:45:57 -07001780 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001781 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001782 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1783 // Wait for a little more - the error will be triggered again.
1784 rtc::Thread::Current()->ProcessMessages(200);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001785 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1786 rtc::PacketOptions());
1787 WaitForThreads();
1788 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001789 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790
1791 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001792 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001793 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001794
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001795 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001796 cricket::TransportChannel* transport_channel =
1797 channel2_->transport_channel();
1798 transport_channel->SignalReadPacket(
1799 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1800 sizeof(kBadPacket), rtc::PacketTime(), 0);
1801 });
1802 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001803 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 }
1805
1806 void TestOnReadyToSend() {
1807 CreateChannels(RTCP, RTCP);
1808 TransportChannel* rtp = channel1_->transport_channel();
1809 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1810 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001811
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001812 network_thread_->Invoke<void>(RTC_FROM_HERE,
1813 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001814 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001816
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001817 network_thread_->Invoke<void>(RTC_FROM_HERE,
1818 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001819 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1821 // channel are ready to send.
1822 EXPECT_TRUE(media_channel1_->ready_to_send());
1823
1824 // rtp channel becomes not ready to send will be propagated to mediachannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001825 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001826 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001827 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001829
1830 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001831 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, true); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001832 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 EXPECT_TRUE(media_channel1_->ready_to_send());
1834
1835 // rtcp channel becomes not ready to send will be propagated to mediachannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001836 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001837 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(true, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001838 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001840
1841 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001842 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(true, true); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001843 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 EXPECT_TRUE(media_channel1_->ready_to_send());
1845 }
1846
1847 void TestOnReadyToSendWithRtcpMux() {
1848 CreateChannels(RTCP, RTCP);
1849 typename T::Content content;
1850 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1851 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1852 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001853 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1854 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1856 TransportChannel* rtp = channel1_->transport_channel();
1857 EXPECT_FALSE(media_channel1_->ready_to_send());
1858 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1859 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001860 network_thread_->Invoke<void>(RTC_FROM_HERE,
1861 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001862 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001864
1865 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001866 RTC_FROM_HERE, [this] { channel1_->SetReadyToSend(false, false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001867 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 EXPECT_FALSE(media_channel1_->ready_to_send());
1869 }
1870
skvladdc1c62c2016-03-16 19:07:43 -07001871 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1872 typename T::Content content;
1873 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1874 content.set_bandwidth(remote_limit);
1875 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1876 }
1877
1878 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1879 webrtc::RtpParameters parameters;
1880 webrtc::RtpEncodingParameters encoding;
1881 encoding.max_bitrate_bps = limit;
1882 parameters.encodings.push_back(encoding);
1883 return parameters;
1884 }
1885
1886 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1887 int expected_bitrate) {
1888 EXPECT_EQ(1UL, parameters.encodings.size());
1889 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1890 }
1891
1892 void DefaultMaxBitrateIsUnlimited() {
1893 CreateChannels(0, 0);
1894 EXPECT_TRUE(
1895 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1896 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001897 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001898 }
1899
1900 void CanChangeMaxBitrate() {
1901 CreateChannels(0, 0);
1902 EXPECT_TRUE(
1903 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1904
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001905 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1906 kSsrc1, BitrateLimitedParameters(1000)));
1907 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1908 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001909 EXPECT_EQ(-1, media_channel1_->max_bps());
1910
1911 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001912 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1913 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1914 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001915 EXPECT_EQ(-1, media_channel1_->max_bps());
1916 }
1917
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001919 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1920 static void ProcessThreadQueue(rtc::Thread* thread) {
1921 RTC_DCHECK(thread->IsCurrent());
1922 while (!thread->empty()) {
1923 thread->ProcessMessages(0);
1924 }
1925 }
1926 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1927 // |threads| and current thread post packets to network thread.
1928 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001929 thread->Invoke<void>(RTC_FROM_HERE,
1930 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001931 }
1932 ProcessThreadQueue(rtc::Thread::Current());
1933 // Network thread move them around and post back to worker = current thread.
1934 if (!network_thread_->IsCurrent()) {
1935 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001936 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001937 }
1938 // Worker thread = current Thread process received messages.
1939 ProcessThreadQueue(rtc::Thread::Current());
1940 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001941 // TODO(pbos): Remove playout from all media channels and let renderers mute
1942 // themselves.
1943 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001944 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1945 rtc::Thread* network_thread_;
1946 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1947 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 cricket::FakeMediaEngine media_engine_;
1949 // The media channels are owned by the voice channel objects below.
1950 typename T::MediaChannel* media_channel1_;
1951 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001952 std::unique_ptr<typename T::Channel> channel1_;
1953 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 typename T::Content local_media_content1_;
1955 typename T::Content local_media_content2_;
1956 typename T::Content remote_media_content1_;
1957 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001959 rtc::Buffer rtp_packet_;
1960 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 int media_info_callbacks1_;
1962 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001963 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964};
1965
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966template<>
1967void ChannelTest<VoiceTraits>::CreateContent(
1968 int flags,
1969 const cricket::AudioCodec& audio_codec,
1970 const cricket::VideoCodec& video_codec,
1971 cricket::AudioContentDescription* audio) {
1972 audio->AddCodec(audio_codec);
1973 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1974 if (flags & SECURE) {
1975 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001976 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1977 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 }
1979}
1980
1981template<>
1982void ChannelTest<VoiceTraits>::CopyContent(
1983 const cricket::AudioContentDescription& source,
1984 cricket::AudioContentDescription* audio) {
1985 *audio = source;
1986}
1987
1988template<>
1989bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1990 const cricket::AudioCodec& c2) {
1991 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1992 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1993}
1994
Peter Boström0c4e06b2015-10-07 12:23:21 +02001995template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001997 uint32_t ssrc,
1998 int flags,
1999 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 audio->AddLegacyStream(ssrc);
2001}
2002
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002003class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 public:
solenberg1dd98f32015-09-10 01:57:14 -07002005 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002006 VoiceChannelSingleThreadTest()
2007 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2008};
2009
2010class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2011 public:
2012 typedef ChannelTest<VoiceTraits> Base;
2013 VoiceChannelDoubleThreadTest()
2014 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015};
2016
2017// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002018template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002019cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002020 rtc::Thread* worker_thread,
2021 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002022 cricket::MediaEngineInterface* engine,
2023 cricket::FakeVideoMediaChannel* ch,
2024 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002025 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002026 cricket::VideoChannel* channel =
2027 new cricket::VideoChannel(worker_thread, network_thread, ch,
2028 transport_controller, cricket::CN_VIDEO, rtcp);
skvlad6c87a672016-05-17 17:49:52 -07002029 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 delete channel;
2031 channel = NULL;
2032 }
2033 return channel;
2034}
2035
2036// override to add 0 parameter
2037template<>
2038bool ChannelTest<VideoTraits>::AddStream1(int id) {
2039 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2040}
2041
2042template<>
2043void ChannelTest<VideoTraits>::CreateContent(
2044 int flags,
2045 const cricket::AudioCodec& audio_codec,
2046 const cricket::VideoCodec& video_codec,
2047 cricket::VideoContentDescription* video) {
2048 video->AddCodec(video_codec);
2049 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2050 if (flags & SECURE) {
2051 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002052 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2053 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054 }
2055}
2056
2057template<>
2058void ChannelTest<VideoTraits>::CopyContent(
2059 const cricket::VideoContentDescription& source,
2060 cricket::VideoContentDescription* video) {
2061 *video = source;
2062}
2063
2064template<>
2065bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2066 const cricket::VideoCodec& c2) {
2067 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2068 c1.framerate == c2.framerate;
2069}
2070
Peter Boström0c4e06b2015-10-07 12:23:21 +02002071template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002073 uint32_t ssrc,
2074 int flags,
2075 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076 video->AddLegacyStream(ssrc);
2077}
2078
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002079class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 public:
solenberg1dd98f32015-09-10 01:57:14 -07002081 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002082 VideoChannelSingleThreadTest()
2083 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084};
2085
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002086class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2087 public:
2088 typedef ChannelTest<VideoTraits> Base;
2089 VideoChannelDoubleThreadTest()
2090 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2091};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002093// VoiceChannelSingleThreadTest
2094TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 Base::TestInit();
2096 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2097 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2098}
2099
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002100TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2101 Base::TestDeinit();
2102}
2103
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002104TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 Base::TestSetContents();
2106}
2107
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002108TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 Base::TestSetContentsNullOffer();
2110}
2111
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002112TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 Base::TestSetContentsRtcpMux();
2114}
2115
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002116TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 Base::TestSetContentsRtcpMux();
2118}
2119
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002120TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 Base::TestSetRemoteContentUpdate();
2122}
2123
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002124TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 Base::TestStreams();
2126}
2127
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002128TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 Base::TestUpdateStreamsInLocalContent();
2130}
2131
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002132TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 Base::TestUpdateStreamsInRemoteContent();
2134}
2135
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002136TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 Base::TestChangeStreamParamsInContent();
2138}
2139
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002140TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 Base::TestPlayoutAndSendingStates();
2142}
2143
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002144TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002145 CreateChannels(0, 0);
2146 // Test that we can Mute the default channel even though the sending SSRC
2147 // is unknown.
2148 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002149 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002150 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2151 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002152 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2153
2154 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002155 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002156
2157 SendInitiate();
2158 // After the local session description has been set, we can mute a stream
2159 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002160 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002161 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2162 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002163 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164}
2165
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002166TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 Base::TestMediaContentDirection();
2168}
2169
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002170TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002171 Base::TestNetworkRouteChanges();
2172}
2173
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002174TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 Base::TestCallSetup();
2176}
2177
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002178TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 Base::TestCallTeardownRtcpMux();
2180}
2181
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002182TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 Base::SendRtpToRtp();
2184}
2185
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002186TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 Base::SendNoRtcpToNoRtcp();
2188}
2189
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002190TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 Base::SendNoRtcpToRtcp();
2192}
2193
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002194TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 Base::SendRtcpToNoRtcp();
2196}
2197
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002198TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 Base::SendRtcpToRtcp();
2200}
2201
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002202TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 Base::SendRtcpMuxToRtcp();
2204}
2205
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002206TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 Base::SendRtcpMuxToRtcpMux();
2208}
2209
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002210TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002211 Base::SendRequireRtcpMuxToRtcpMux();
2212}
2213
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002214TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002215 Base::SendRtcpMuxToRequireRtcpMux();
2216}
2217
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002218TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002219 Base::SendRequireRtcpMuxToRequireRtcpMux();
2220}
2221
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002222TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002223 Base::SendRequireRtcpMuxToNoRtcpMux();
2224}
2225
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002226TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 Base::SendEarlyRtcpMuxToRtcp();
2228}
2229
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002230TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 Base::SendEarlyRtcpMuxToRtcpMux();
2232}
2233
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002234TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2236}
2237
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002238TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 Base::SendSrtpToSrtp();
2240}
2241
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002242TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2244}
2245
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002246TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2248 Base::SendSrtpToSrtp(DTLS, 0);
2249}
2250
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002251TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2253 Base::SendSrtpToSrtp(DTLS, DTLS);
2254}
2255
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002256TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2258 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2259}
2260
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002261TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2263}
2264
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002265TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 Base::SendRtpToRtpOnThread();
2267}
2268
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002269TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270 Base::SendSrtpToSrtpOnThread();
2271}
2272
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002273TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 Base::SendWithWritabilityLoss();
2275}
2276
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002277TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 Base::TestMediaMonitor();
2279}
2280
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002282TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 CreateChannels(0, 0);
2284 EXPECT_TRUE(SendInitiate());
2285 EXPECT_TRUE(SendAccept());
2286 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2287
solenberg1d63dd02015-12-02 12:35:09 -08002288 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2289 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2290 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002292 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002294 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002295 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002296 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002297 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002298 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299}
2300
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002301TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 Base::TestSetContentFailure();
2303}
2304
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002305TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 Base::TestSendTwoOffers();
2307}
2308
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002309TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 Base::TestReceiveTwoOffers();
2311}
2312
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002313TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 Base::TestSendPrAnswer();
2315}
2316
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002317TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 Base::TestReceivePrAnswer();
2319}
2320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002321TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 Base::TestFlushRtcp();
2323}
2324
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002325TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002326 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327}
2328
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002329TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 Base::TestOnReadyToSend();
2331}
2332
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002333TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 Base::TestOnReadyToSendWithRtcpMux();
2335}
2336
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002338TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 CreateChannels(RTCP, RTCP);
2340 EXPECT_TRUE(SendInitiate());
2341 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002342 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343
solenberg4bac9c52015-10-09 02:32:53 -07002344 // Default is (1.0).
2345 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2346 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002348 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349
solenberg4bac9c52015-10-09 02:32:53 -07002350 // Set scale to (1.5).
2351 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2352 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2353 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354
solenberg4bac9c52015-10-09 02:32:53 -07002355 // Set scale to (0).
2356 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2357 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2358 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359}
2360
2361// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002362TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 CreateChannels(RTCP, RTCP);
2364 EXPECT_TRUE(SendInitiate());
2365 EXPECT_TRUE(SendAccept());
2366 EXPECT_TRUE(AddStream1(1));
2367 EXPECT_TRUE(AddStream1(2));
2368
solenberg4bac9c52015-10-09 02:32:53 -07002369 double volume;
2370 // Default is (1.0).
2371 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2372 EXPECT_DOUBLE_EQ(1.0, volume);
2373 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2374 EXPECT_DOUBLE_EQ(1.0, volume);
2375 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2376 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002378 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
solenberg4bac9c52015-10-09 02:32:53 -07002380 // Set scale to (1.5) for ssrc = 1.
2381 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2382 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2383 EXPECT_DOUBLE_EQ(1.5, volume);
2384 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2385 EXPECT_DOUBLE_EQ(1.0, volume);
2386 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2387 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388
solenberg4bac9c52015-10-09 02:32:53 -07002389 // Set scale to (0) for all ssrcs.
2390 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2391 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2392 EXPECT_DOUBLE_EQ(0.0, volume);
2393 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2394 EXPECT_DOUBLE_EQ(0.0, volume);
2395 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2396 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397}
2398
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002399TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002400 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401}
2402
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002403TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002404 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002405}
2406
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002407TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002408 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002409}
2410
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002411TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002412 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413}
2414
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002415TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002416 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002417}
2418
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002419TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002420 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002421}
2422
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002423// VoiceChannelDoubleThreadTest
2424TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002426 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2427 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428}
2429
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002430TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2431 Base::TestDeinit();
2432}
2433
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002434TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 Base::TestSetContents();
2436}
2437
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002438TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 Base::TestSetContentsNullOffer();
2440}
2441
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002442TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 Base::TestSetContentsRtcpMux();
2444}
2445
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002446TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 Base::TestSetContentsRtcpMux();
2448}
2449
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002450TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 Base::TestSetRemoteContentUpdate();
2452}
2453
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002454TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 Base::TestStreams();
2456}
2457
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002458TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 Base::TestUpdateStreamsInLocalContent();
2460}
2461
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002462TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 Base::TestUpdateStreamsInRemoteContent();
2464}
2465
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002466TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 Base::TestChangeStreamParamsInContent();
2468}
2469
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002470TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 Base::TestPlayoutAndSendingStates();
2472}
2473
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002474TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2475 CreateChannels(0, 0);
2476 // Test that we can Mute the default channel even though the sending SSRC
2477 // is unknown.
2478 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2479 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2480 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2481 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2482 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2483
2484 // Test that we can not mute an unknown SSRC.
2485 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2486
2487 SendInitiate();
2488 // After the local session description has been set, we can mute a stream
2489 // with its SSRC.
2490 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2491 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2492 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2493 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2494}
2495
2496TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2497 Base::TestMediaContentDirection();
2498}
2499
2500TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2501 Base::TestNetworkRouteChanges();
2502}
2503
2504TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2505 Base::TestCallSetup();
2506}
2507
2508TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2509 Base::TestCallTeardownRtcpMux();
2510}
2511
2512TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2513 Base::SendRtpToRtp();
2514}
2515
2516TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2517 Base::SendNoRtcpToNoRtcp();
2518}
2519
2520TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2521 Base::SendNoRtcpToRtcp();
2522}
2523
2524TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2525 Base::SendRtcpToNoRtcp();
2526}
2527
2528TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2529 Base::SendRtcpToRtcp();
2530}
2531
2532TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2533 Base::SendRtcpMuxToRtcp();
2534}
2535
2536TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2537 Base::SendRtcpMuxToRtcpMux();
2538}
2539
2540TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2541 Base::SendRequireRtcpMuxToRtcpMux();
2542}
2543
2544TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2545 Base::SendRtcpMuxToRequireRtcpMux();
2546}
2547
2548TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2549 Base::SendRequireRtcpMuxToRequireRtcpMux();
2550}
2551
2552TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2553 Base::SendRequireRtcpMuxToNoRtcpMux();
2554}
2555
2556TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2557 Base::SendEarlyRtcpMuxToRtcp();
2558}
2559
2560TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2561 Base::SendEarlyRtcpMuxToRtcpMux();
2562}
2563
2564TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2565 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2566}
2567
2568TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2569 Base::SendSrtpToSrtp();
2570}
2571
2572TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2573 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2574}
2575
2576TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2577 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2578 Base::SendSrtpToSrtp(DTLS, 0);
2579}
2580
2581TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2582 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2583 Base::SendSrtpToSrtp(DTLS, DTLS);
2584}
2585
2586TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2587 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2588 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2589}
2590
2591TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2592 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2593}
2594
2595TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2596 Base::SendRtpToRtpOnThread();
2597}
2598
2599TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2600 Base::SendSrtpToSrtpOnThread();
2601}
2602
2603TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2604 Base::SendWithWritabilityLoss();
2605}
2606
2607TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2608 Base::TestMediaMonitor();
2609}
2610
2611// Test that InsertDtmf properly forwards to the media channel.
2612TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2613 CreateChannels(0, 0);
2614 EXPECT_TRUE(SendInitiate());
2615 EXPECT_TRUE(SendAccept());
2616 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2617
2618 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2619 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2620 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2621
2622 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2623 EXPECT_TRUE(
2624 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2625 EXPECT_TRUE(
2626 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2627 EXPECT_TRUE(
2628 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2629}
2630
2631TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2632 Base::TestSetContentFailure();
2633}
2634
2635TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2636 Base::TestSendTwoOffers();
2637}
2638
2639TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2640 Base::TestReceiveTwoOffers();
2641}
2642
2643TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2644 Base::TestSendPrAnswer();
2645}
2646
2647TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2648 Base::TestReceivePrAnswer();
2649}
2650
2651TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2652 Base::TestFlushRtcp();
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2656 Base::TestSrtpError(kAudioPts[0]);
2657}
2658
2659TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2660 Base::TestOnReadyToSend();
2661}
2662
2663TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2664 Base::TestOnReadyToSendWithRtcpMux();
2665}
2666
2667// Test that we can scale the output volume properly for 1:1 calls.
2668TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2669 CreateChannels(RTCP, RTCP);
2670 EXPECT_TRUE(SendInitiate());
2671 EXPECT_TRUE(SendAccept());
2672 double volume;
2673
2674 // Default is (1.0).
2675 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2676 EXPECT_DOUBLE_EQ(1.0, volume);
2677 // invalid ssrc.
2678 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2679
2680 // Set scale to (1.5).
2681 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2682 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2683 EXPECT_DOUBLE_EQ(1.5, volume);
2684
2685 // Set scale to (0).
2686 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2687 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2688 EXPECT_DOUBLE_EQ(0.0, volume);
2689}
2690
2691// Test that we can scale the output volume properly for multiway calls.
2692TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2693 CreateChannels(RTCP, RTCP);
2694 EXPECT_TRUE(SendInitiate());
2695 EXPECT_TRUE(SendAccept());
2696 EXPECT_TRUE(AddStream1(1));
2697 EXPECT_TRUE(AddStream1(2));
2698
2699 double volume;
2700 // Default is (1.0).
2701 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2702 EXPECT_DOUBLE_EQ(1.0, volume);
2703 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2704 EXPECT_DOUBLE_EQ(1.0, volume);
2705 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2706 EXPECT_DOUBLE_EQ(1.0, volume);
2707 // invalid ssrc.
2708 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2709
2710 // Set scale to (1.5) for ssrc = 1.
2711 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2712 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2713 EXPECT_DOUBLE_EQ(1.5, volume);
2714 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2715 EXPECT_DOUBLE_EQ(1.0, volume);
2716 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2717 EXPECT_DOUBLE_EQ(1.0, volume);
2718
2719 // Set scale to (0) for all ssrcs.
2720 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2721 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2722 EXPECT_DOUBLE_EQ(0.0, volume);
2723 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2724 EXPECT_DOUBLE_EQ(0.0, volume);
2725 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2726 EXPECT_DOUBLE_EQ(0.0, volume);
2727}
2728
2729TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2730 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2731}
2732
2733TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2734 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2735}
2736
2737TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2738 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2739}
2740
2741TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2742 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2743}
2744
2745TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2746 Base::DefaultMaxBitrateIsUnlimited();
2747}
2748
2749TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2750 Base::CanChangeMaxBitrate();
2751}
2752
2753// VideoChannelSingleThreadTest
2754TEST_F(VideoChannelSingleThreadTest, TestInit) {
2755 Base::TestInit();
2756}
2757
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002758TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2759 Base::TestDeinit();
2760}
2761
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002762TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2763 Base::TestSetContents();
2764}
2765
2766TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2767 Base::TestSetContentsNullOffer();
2768}
2769
2770TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2771 Base::TestSetContentsRtcpMux();
2772}
2773
2774TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2775 Base::TestSetContentsRtcpMux();
2776}
2777
2778TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2779 Base::TestSetRemoteContentUpdate();
2780}
2781
2782TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2783 Base::TestStreams();
2784}
2785
2786TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2787 Base::TestUpdateStreamsInLocalContent();
2788}
2789
2790TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2791 Base::TestUpdateStreamsInRemoteContent();
2792}
2793
2794TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2795 Base::TestChangeStreamParamsInContent();
2796}
2797
2798TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2799 Base::TestPlayoutAndSendingStates();
2800}
2801
2802TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002803 CreateChannels(0, 0);
2804 // Test that we can Mute the default channel even though the sending SSRC
2805 // is unknown.
2806 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002807 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002808 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002809 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002810 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2811 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002812 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002813 SendInitiate();
2814 // After the local session description has been set, we can mute a stream
2815 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002816 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002817 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002818 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002819 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820}
2821
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002822TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823 Base::TestMediaContentDirection();
2824}
2825
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002826TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002827 Base::TestNetworkRouteChanges();
2828}
2829
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002830TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831 Base::TestCallSetup();
2832}
2833
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002834TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 Base::TestCallTeardownRtcpMux();
2836}
2837
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002838TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839 Base::SendRtpToRtp();
2840}
2841
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002842TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002843 Base::SendNoRtcpToNoRtcp();
2844}
2845
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002846TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847 Base::SendNoRtcpToRtcp();
2848}
2849
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002850TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 Base::SendRtcpToNoRtcp();
2852}
2853
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002854TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855 Base::SendRtcpToRtcp();
2856}
2857
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002858TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002859 Base::SendRtcpMuxToRtcp();
2860}
2861
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002862TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 Base::SendRtcpMuxToRtcpMux();
2864}
2865
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002866TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002867 Base::SendRequireRtcpMuxToRtcpMux();
2868}
2869
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002870TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002871 Base::SendRtcpMuxToRequireRtcpMux();
2872}
2873
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002874TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002875 Base::SendRequireRtcpMuxToRequireRtcpMux();
2876}
2877
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002878TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002879 Base::SendRequireRtcpMuxToNoRtcpMux();
2880}
2881
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002882TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883 Base::SendEarlyRtcpMuxToRtcp();
2884}
2885
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002886TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 Base::SendEarlyRtcpMuxToRtcpMux();
2888}
2889
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002890TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891 Base::SendSrtpToSrtp();
2892}
2893
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002894TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 Base::SendSrtpToSrtp();
2896}
2897
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002898TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002899 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2900 Base::SendSrtpToSrtp(DTLS, 0);
2901}
2902
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002903TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002904 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2905 Base::SendSrtpToSrtp(DTLS, DTLS);
2906}
2907
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002908TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2910 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2911}
2912
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002913TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2915}
2916
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002917TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2919}
2920
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002921TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002922 Base::SendRtpToRtpOnThread();
2923}
2924
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002925TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926 Base::SendSrtpToSrtpOnThread();
2927}
2928
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002929TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 Base::SendWithWritabilityLoss();
2931}
2932
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002933TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934 Base::TestMediaMonitor();
2935}
2936
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002937TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 Base::TestSetContentFailure();
2939}
2940
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002941TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002942 Base::TestSendTwoOffers();
2943}
2944
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002945TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002946 Base::TestReceiveTwoOffers();
2947}
2948
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002949TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950 Base::TestSendPrAnswer();
2951}
2952
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002953TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 Base::TestReceivePrAnswer();
2955}
2956
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002957TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002958 Base::TestFlushRtcp();
2959}
2960
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002961TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002962 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002963}
2964
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002965TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002966 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002967}
2968
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002969TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002970 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002971}
2972
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002973TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002974 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975}
2976
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002977TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002978 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979}
2980
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002981TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982 Base::TestOnReadyToSend();
2983}
2984
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002985TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002986 Base::TestOnReadyToSendWithRtcpMux();
2987}
2988
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002989TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07002990 Base::DefaultMaxBitrateIsUnlimited();
2991}
2992
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002993TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07002994 Base::CanChangeMaxBitrate();
2995}
2996
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002997// VideoChannelDoubleThreadTest
2998TEST_F(VideoChannelDoubleThreadTest, TestInit) {
2999 Base::TestInit();
3000}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003002TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3003 Base::TestDeinit();
3004}
3005
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003006TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3007 Base::TestSetContents();
3008}
3009
3010TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3011 Base::TestSetContentsNullOffer();
3012}
3013
3014TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3015 Base::TestSetContentsRtcpMux();
3016}
3017
3018TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3019 Base::TestSetContentsRtcpMux();
3020}
3021
3022TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3023 Base::TestSetRemoteContentUpdate();
3024}
3025
3026TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3027 Base::TestStreams();
3028}
3029
3030TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3031 Base::TestUpdateStreamsInLocalContent();
3032}
3033
3034TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3035 Base::TestUpdateStreamsInRemoteContent();
3036}
3037
3038TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3039 Base::TestChangeStreamParamsInContent();
3040}
3041
3042TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3043 Base::TestPlayoutAndSendingStates();
3044}
3045
3046TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3047 CreateChannels(0, 0);
3048 // Test that we can Mute the default channel even though the sending SSRC
3049 // is unknown.
3050 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003051 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003052 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003053 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003054 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3055 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003056 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003057 SendInitiate();
3058 // After the local session description has been set, we can mute a stream
3059 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003060 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003061 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003062 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003063 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3064}
3065
3066TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3067 Base::TestMediaContentDirection();
3068}
3069
3070TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3071 Base::TestNetworkRouteChanges();
3072}
3073
3074TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3075 Base::TestCallSetup();
3076}
3077
3078TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3079 Base::TestCallTeardownRtcpMux();
3080}
3081
3082TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3083 Base::SendRtpToRtp();
3084}
3085
3086TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3087 Base::SendNoRtcpToNoRtcp();
3088}
3089
3090TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3091 Base::SendNoRtcpToRtcp();
3092}
3093
3094TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3095 Base::SendRtcpToNoRtcp();
3096}
3097
3098TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3099 Base::SendRtcpToRtcp();
3100}
3101
3102TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3103 Base::SendRtcpMuxToRtcp();
3104}
3105
3106TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3107 Base::SendRtcpMuxToRtcpMux();
3108}
3109
3110TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3111 Base::SendRequireRtcpMuxToRtcpMux();
3112}
3113
3114TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3115 Base::SendRtcpMuxToRequireRtcpMux();
3116}
3117
3118TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3119 Base::SendRequireRtcpMuxToRequireRtcpMux();
3120}
3121
3122TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3123 Base::SendRequireRtcpMuxToNoRtcpMux();
3124}
3125
3126TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3127 Base::SendEarlyRtcpMuxToRtcp();
3128}
3129
3130TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3131 Base::SendEarlyRtcpMuxToRtcpMux();
3132}
3133
3134TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3135 Base::SendSrtpToSrtp();
3136}
3137
3138TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3139 Base::SendSrtpToSrtp();
3140}
3141
3142TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3143 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3144 Base::SendSrtpToSrtp(DTLS, 0);
3145}
3146
3147TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3148 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3149 Base::SendSrtpToSrtp(DTLS, DTLS);
3150}
3151
3152TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3153 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3154 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3155}
3156
3157TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3158 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3159}
3160
3161TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3162 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3163}
3164
3165TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3166 Base::SendRtpToRtpOnThread();
3167}
3168
3169TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3170 Base::SendSrtpToSrtpOnThread();
3171}
3172
3173TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3174 Base::SendWithWritabilityLoss();
3175}
3176
3177TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3178 Base::TestMediaMonitor();
3179}
3180
3181TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3182 Base::TestSetContentFailure();
3183}
3184
3185TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3186 Base::TestSendTwoOffers();
3187}
3188
3189TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3190 Base::TestReceiveTwoOffers();
3191}
3192
3193TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3194 Base::TestSendPrAnswer();
3195}
3196
3197TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3198 Base::TestReceivePrAnswer();
3199}
3200
3201TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3202 Base::TestFlushRtcp();
3203}
3204
3205TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3206 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3207}
3208
3209TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3210 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3211}
3212
3213TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3214 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3215}
3216
3217TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3218 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3219}
3220
3221TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3222 Base::TestSrtpError(kVideoPts[0]);
3223}
3224
3225TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3226 Base::TestOnReadyToSend();
3227}
3228
3229TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3230 Base::TestOnReadyToSendWithRtcpMux();
3231}
3232
3233TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3234 Base::DefaultMaxBitrateIsUnlimited();
3235}
3236
3237TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3238 Base::CanChangeMaxBitrate();
3239}
3240
3241// DataChannelSingleThreadTest
3242class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003244 typedef ChannelTest<DataTraits> Base;
3245 DataChannelSingleThreadTest()
3246 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3247};
3248
3249// DataChannelDoubleThreadTest
3250class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3251 public:
3252 typedef ChannelTest<DataTraits> Base;
3253 DataChannelDoubleThreadTest()
3254 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003255};
3256
3257// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003258template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003259cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003260 rtc::Thread* worker_thread,
3261 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003262 cricket::MediaEngineInterface* engine,
3263 cricket::FakeDataMediaChannel* ch,
3264 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003266 cricket::DataChannel* channel =
3267 new cricket::DataChannel(worker_thread, network_thread, ch,
3268 transport_controller, cricket::CN_DATA, rtcp);
skvlad6c87a672016-05-17 17:49:52 -07003269 if (!channel->Init_w(nullptr)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003270 delete channel;
3271 channel = NULL;
3272 }
3273 return channel;
3274}
3275
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003276template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277void ChannelTest<DataTraits>::CreateContent(
3278 int flags,
3279 const cricket::AudioCodec& audio_codec,
3280 const cricket::VideoCodec& video_codec,
3281 cricket::DataContentDescription* data) {
3282 data->AddCodec(kGoogleDataCodec);
3283 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3284 if (flags & SECURE) {
3285 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003286 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3287 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288 }
3289}
3290
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003291template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003292void ChannelTest<DataTraits>::CopyContent(
3293 const cricket::DataContentDescription& source,
3294 cricket::DataContentDescription* data) {
3295 *data = source;
3296}
3297
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003298template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003299bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3300 const cricket::DataCodec& c2) {
3301 return c1.name == c2.name;
3302}
3303
Peter Boström0c4e06b2015-10-07 12:23:21 +02003304template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003305void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003306 uint32_t ssrc,
3307 int flags,
3308 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003309 data->AddLegacyStream(ssrc);
3310}
3311
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003312TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313 Base::TestInit();
3314 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3315}
3316
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003317TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3318 Base::TestDeinit();
3319}
3320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003321TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003322 Base::TestSetContents();
3323}
3324
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003325TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003326 Base::TestSetContentsNullOffer();
3327}
3328
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003329TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 Base::TestSetContentsRtcpMux();
3331}
3332
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003333TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 Base::TestSetRemoteContentUpdate();
3335}
3336
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003337TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 Base::TestStreams();
3339}
3340
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003341TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342 Base::TestUpdateStreamsInLocalContent();
3343}
3344
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003345TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 Base::TestUpdateStreamsInRemoteContent();
3347}
3348
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003349TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 Base::TestChangeStreamParamsInContent();
3351}
3352
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003353TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354 Base::TestPlayoutAndSendingStates();
3355}
3356
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003357TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358 Base::TestMediaContentDirection();
3359}
3360
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003361TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 Base::TestCallSetup();
3363}
3364
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003365TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003366 Base::TestCallTeardownRtcpMux();
3367}
3368
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003369TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370 Base::TestOnReadyToSend();
3371}
3372
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003373TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374 Base::TestOnReadyToSendWithRtcpMux();
3375}
3376
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003377TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378 Base::SendRtpToRtp();
3379}
3380
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003381TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 Base::SendNoRtcpToNoRtcp();
3383}
3384
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003385TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 Base::SendNoRtcpToRtcp();
3387}
3388
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003389TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390 Base::SendRtcpToNoRtcp();
3391}
3392
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003393TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 Base::SendRtcpToRtcp();
3395}
3396
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003397TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398 Base::SendRtcpMuxToRtcp();
3399}
3400
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003401TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 Base::SendRtcpMuxToRtcpMux();
3403}
3404
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003405TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406 Base::SendEarlyRtcpMuxToRtcp();
3407}
3408
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003409TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 Base::SendEarlyRtcpMuxToRtcpMux();
3411}
3412
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003413TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 Base::SendSrtpToSrtp();
3415}
3416
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003417TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 Base::SendSrtpToSrtp();
3419}
3420
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003421TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3423}
3424
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003425TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 Base::SendRtpToRtpOnThread();
3427}
3428
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003429TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 Base::SendSrtpToSrtpOnThread();
3431}
3432
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003433TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003434 Base::SendWithWritabilityLoss();
3435}
3436
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003437TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 Base::TestMediaMonitor();
3439}
3440
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003441TEST_F(DataChannelSingleThreadTest, TestSendData) {
3442 CreateChannels(0, 0);
3443 EXPECT_TRUE(SendInitiate());
3444 EXPECT_TRUE(SendAccept());
3445
3446 cricket::SendDataParams params;
3447 params.ssrc = 42;
3448 unsigned char data[] = {'f', 'o', 'o'};
3449 rtc::CopyOnWriteBuffer payload(data, 3);
3450 cricket::SendDataResult result;
3451 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3452 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3453 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3454}
3455
3456TEST_F(DataChannelDoubleThreadTest, TestInit) {
3457 Base::TestInit();
3458 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3459}
3460
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003461TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3462 Base::TestDeinit();
3463}
3464
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003465TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3466 Base::TestSetContents();
3467}
3468
3469TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3470 Base::TestSetContentsNullOffer();
3471}
3472
3473TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3474 Base::TestSetContentsRtcpMux();
3475}
3476
3477TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3478 Base::TestSetRemoteContentUpdate();
3479}
3480
3481TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3482 Base::TestStreams();
3483}
3484
3485TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3486 Base::TestUpdateStreamsInLocalContent();
3487}
3488
3489TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3490 Base::TestUpdateStreamsInRemoteContent();
3491}
3492
3493TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3494 Base::TestChangeStreamParamsInContent();
3495}
3496
3497TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3498 Base::TestPlayoutAndSendingStates();
3499}
3500
3501TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3502 Base::TestMediaContentDirection();
3503}
3504
3505TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3506 Base::TestCallSetup();
3507}
3508
3509TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3510 Base::TestCallTeardownRtcpMux();
3511}
3512
3513TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3514 Base::TestOnReadyToSend();
3515}
3516
3517TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3518 Base::TestOnReadyToSendWithRtcpMux();
3519}
3520
3521TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3522 Base::SendRtpToRtp();
3523}
3524
3525TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3526 Base::SendNoRtcpToNoRtcp();
3527}
3528
3529TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3530 Base::SendNoRtcpToRtcp();
3531}
3532
3533TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3534 Base::SendRtcpToNoRtcp();
3535}
3536
3537TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3538 Base::SendRtcpToRtcp();
3539}
3540
3541TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3542 Base::SendRtcpMuxToRtcp();
3543}
3544
3545TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3546 Base::SendRtcpMuxToRtcpMux();
3547}
3548
3549TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3550 Base::SendEarlyRtcpMuxToRtcp();
3551}
3552
3553TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3554 Base::SendEarlyRtcpMuxToRtcpMux();
3555}
3556
3557TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3558 Base::SendSrtpToSrtp();
3559}
3560
3561TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3562 Base::SendSrtpToSrtp();
3563}
3564
3565TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3566 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3567}
3568
3569TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3570 Base::SendRtpToRtpOnThread();
3571}
3572
3573TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3574 Base::SendSrtpToSrtpOnThread();
3575}
3576
3577TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3578 Base::SendWithWritabilityLoss();
3579}
3580
3581TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3582 Base::TestMediaMonitor();
3583}
3584
3585TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003586 CreateChannels(0, 0);
3587 EXPECT_TRUE(SendInitiate());
3588 EXPECT_TRUE(SendAccept());
3589
3590 cricket::SendDataParams params;
3591 params.ssrc = 42;
3592 unsigned char data[] = {
3593 'f', 'o', 'o'
3594 };
jbaucheec21bd2016-03-20 06:15:43 -07003595 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003596 cricket::SendDataResult result;
3597 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3598 EXPECT_EQ(params.ssrc,
3599 media_channel1_->last_sent_data_params().ssrc);
3600 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3601}
3602
3603// TODO(pthatcher): TestSetReceiver?