blob: 110ea04b7a94fd9a1163510974b641482ea1e033 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2009 The WebRTC project authors. All Rights Reserved.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00009 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000010
kwiberg31022942016-03-11 14:18:21 -080011#include <memory>
12
Danil Chapovalov33b01f22016-05-11 19:55:27 +020013#include "webrtc/base/array_view.h"
14#include "webrtc/base/buffer.h"
Taylor Brandstetter88532892016-08-01 14:17:27 -070015#include "webrtc/base/fakeclock.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000016#include "webrtc/base/gunit.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000017#include "webrtc/base/logging.h"
jbauchcb560652016-08-04 05:20:32 -070018#include "webrtc/base/sslstreamadapter.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/fakemediaengine.h"
20#include "webrtc/media/base/fakertp.h"
kjellandera96e2d72016-02-04 23:52:28 -080021#include "webrtc/media/base/mediachannel.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010023#include "webrtc/p2p/base/faketransportcontroller.h"
deadbeef49f34fd2016-12-06 16:22:06 -080024#include "webrtc/p2p/base/transportchannelimpl.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010025#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026
27#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000028 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029 LOG(LS_INFO) << "Feature disabled... skipping"; \
30 return; \
31 }
32
33using cricket::CA_OFFER;
34using cricket::CA_PRANSWER;
35using cricket::CA_ANSWER;
36using cricket::CA_UPDATE;
37using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038using cricket::StreamParams;
39using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040
Danil Chapovalov33b01f22016-05-11 19:55:27 +020041namespace {
42const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
43const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
44const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
perkj26752742016-10-24 01:21:16 -070045const cricket::VideoCodec kH264Codec(97, "H264");
46const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
Danil Chapovalov33b01f22016-05-11 19:55:27 +020047const cricket::DataCodec kGoogleDataCodec(101, "google-data");
48const uint32_t kSsrc1 = 0x1111;
49const uint32_t kSsrc2 = 0x2222;
50const uint32_t kSsrc3 = 0x3333;
51const int kAudioPts[] = {0, 8};
52const int kVideoPts[] = {97, 99};
53enum class NetworkIsWorker { Yes, No };
deadbeefc6b6e092016-12-01 12:49:20 -080054const int kDefaultTimeout = 10000; // 10 seconds.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020055} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056
deadbeefcbecd352015-09-23 11:50:27 -070057template <class ChannelT,
58 class MediaChannelT,
59 class ContentT,
60 class CodecT,
61 class MediaInfoT,
62 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063class Traits {
64 public:
65 typedef ChannelT Channel;
66 typedef MediaChannelT MediaChannel;
67 typedef ContentT Content;
68 typedef CodecT Codec;
69 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020070 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071};
72
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073class VoiceTraits : public Traits<cricket::VoiceChannel,
74 cricket::FakeVoiceMediaChannel,
75 cricket::AudioContentDescription,
76 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020077 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070078 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079
80class VideoTraits : public Traits<cricket::VideoChannel,
81 cricket::FakeVideoMediaChannel,
82 cricket::VideoContentDescription,
83 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020084 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070085 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
deadbeef953c2ce2017-01-09 14:53:41 -080087class DataTraits : public Traits<cricket::RtpDataChannel,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 cricket::FakeDataMediaChannel,
89 cricket::DataContentDescription,
90 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020091 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070092 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093
deadbeef953c2ce2017-01-09 14:53:41 -080094// Base class for Voice/Video/RtpDataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095template<class T>
96class ChannelTest : public testing::Test, public sigslot::has_slots<> {
97 public:
deadbeefac22f702017-01-12 21:59:29 -080098 enum Flags {
99 RTCP_MUX = 0x1,
100 RTCP_MUX_REQUIRED = 0x2,
101 SECURE = 0x4,
102 SSRC_MUX = 0x8,
103 DTLS = 0x10,
104 GCM_CIPHER = 0x20
105 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106
Peter Boström34fbfff2015-09-24 19:20:30 +0200107 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200108 rtc::ArrayView<const uint8_t> rtp_data,
109 rtc::ArrayView<const uint8_t> rtcp_data,
110 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200111 : verify_playout_(verify_playout),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000112 media_channel1_(NULL),
113 media_channel2_(NULL),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200114 rtp_packet_(rtp_data.data(), rtp_data.size()),
115 rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 media_info_callbacks1_(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200117 media_info_callbacks2_() {
118 if (network_is_worker == NetworkIsWorker::Yes) {
119 network_thread_ = rtc::Thread::Current();
120 } else {
121 network_thread_keeper_ = rtc::Thread::Create();
122 network_thread_keeper_->SetName("Network", nullptr);
123 network_thread_keeper_->Start();
124 network_thread_ = network_thread_keeper_.get();
125 }
126 transport_controller1_.reset(new cricket::FakeTransportController(
127 network_thread_, cricket::ICEROLE_CONTROLLING));
128 transport_controller2_.reset(new cricket::FakeTransportController(
129 network_thread_, cricket::ICEROLE_CONTROLLED));
130 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200133 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
134 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200135 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200137 void CreateChannels(typename T::MediaChannel* ch1,
138 typename T::MediaChannel* ch2,
139 int flags1,
140 int flags2) {
deadbeefac22f702017-01-12 21:59:29 -0800141 // Make sure RTCP_MUX_REQUIRED isn't set without RTCP_MUX.
142 ASSERT_NE(RTCP_MUX_REQUIRED, flags1 & (RTCP_MUX | RTCP_MUX_REQUIRED));
143 ASSERT_NE(RTCP_MUX_REQUIRED, flags2 & (RTCP_MUX | RTCP_MUX_REQUIRED));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200144 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 media_channel1_ = ch1;
146 media_channel2_ = ch2;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200147 channel1_.reset(
148 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
jbauchcb560652016-08-04 05:20:32 -0700149 transport_controller1_.get(), flags1));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200150 channel2_.reset(
151 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
jbauchcb560652016-08-04 05:20:32 -0700152 transport_controller2_.get(), flags2));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200153 channel1_->SignalMediaMonitor.connect(this,
154 &ChannelTest<T>::OnMediaMonitor1);
155 channel2_->SignalMediaMonitor.connect(this,
156 &ChannelTest<T>::OnMediaMonitor2);
deadbeefac22f702017-01-12 21:59:29 -0800157 channel1_->SignalRtcpMuxFullyActive.connect(
zhihuangf5b251b2017-01-12 19:37:48 -0800158 transport_controller1_.get(),
159 &cricket::FakeTransportController::DestroyRtcpTransport);
deadbeefac22f702017-01-12 21:59:29 -0800160 channel2_->SignalRtcpMuxFullyActive.connect(
zhihuangf5b251b2017-01-12 19:37:48 -0800161 transport_controller2_.get(),
162 &cricket::FakeTransportController::DestroyRtcpTransport);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000163 if ((flags1 & DTLS) && (flags2 & DTLS)) {
164 flags1 = (flags1 & ~SECURE);
165 flags2 = (flags2 & ~SECURE);
166 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 CreateContent(flags1, kPcmuCodec, kH264Codec,
168 &local_media_content1_);
169 CreateContent(flags2, kPcmuCodec, kH264Codec,
170 &local_media_content2_);
171 CopyContent(local_media_content1_, &remote_media_content1_);
172 CopyContent(local_media_content2_, &remote_media_content2_);
173
174 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200175 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200176 transport_controller1_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700177 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800178 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 }
180 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200181 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200182 transport_controller2_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700183 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800184 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185 }
186
187 // Add stream information (SSRC) to the local content but not to the remote
188 // content. This means that we per default know the SSRC of what we send but
189 // not what we receive.
190 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
191 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
192
193 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
194 if (flags1 & SSRC_MUX) {
195 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
196 }
197 if (flags2 & SSRC_MUX) {
198 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
199 }
200 }
deadbeefcbecd352015-09-23 11:50:27 -0700201 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200202 rtc::Thread* worker_thread,
203 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700204 cricket::MediaEngineInterface* engine,
205 typename T::MediaChannel* ch,
206 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -0700207 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -0800208 rtc::Thread* signaling_thread =
209 transport_controller ? transport_controller->signaling_thread()
210 : nullptr;
deadbeef7af91dd2016-12-13 11:29:11 -0800211 typename T::Channel* channel = new typename T::Channel(
zhihuangf5b251b2017-01-12 19:37:48 -0800212 worker_thread, network_thread, signaling_thread, engine, ch,
deadbeefac22f702017-01-12 21:59:29 -0800213 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0,
214 (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -0700215 rtc::CryptoOptions crypto_options;
216 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
217 channel->SetCryptoOptions(crypto_options);
zhihuangf5b251b2017-01-12 19:37:48 -0800218 cricket::TransportChannel* rtp_transport =
219 transport_controller->CreateTransportChannel(
220 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
221 cricket::TransportChannel* rtcp_transport = nullptr;
222 if (channel->NeedsRtcpTransport()) {
223 rtcp_transport = transport_controller->CreateTransportChannel(
224 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
225 }
226 if (!channel->Init_w(rtp_transport, rtcp_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 delete channel;
228 channel = NULL;
229 }
230 return channel;
231 }
232
233 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000234 bool result = channel1_->SetLocalContent(&local_media_content1_,
235 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 if (result) {
237 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000238 result = channel2_->SetRemoteContent(&remote_media_content1_,
239 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200241 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000243 result = channel2_->SetLocalContent(&local_media_content2_,
244 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 }
246 }
247 return result;
248 }
249
250 bool SendAccept() {
251 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000252 return channel1_->SetRemoteContent(&remote_media_content2_,
253 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 }
255
256 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000257 bool result = channel1_->SetLocalContent(&local_media_content1_,
258 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259 if (result) {
260 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000261 result = channel2_->SetRemoteContent(&remote_media_content1_,
262 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 }
264 return result;
265 }
266
267 bool SendProvisionalAnswer() {
268 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000269 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 if (result) {
271 channel2_->Enable(true);
272 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000273 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200274 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 }
276 return result;
277 }
278
279 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000280 bool result = channel2_->SetLocalContent(&local_media_content2_,
281 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000283 result = channel1_->SetRemoteContent(&remote_media_content2_,
284 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285 return result;
286 }
287
288 bool SendTerminate() {
289 channel1_.reset();
290 channel2_.reset();
291 return true;
292 }
293
294 bool AddStream1(int id) {
295 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
296 }
297 bool RemoveStream1(int id) {
298 return channel1_->RemoveRecvStream(id);
299 }
300
deadbeef49f34fd2016-12-06 16:22:06 -0800301 std::vector<cricket::TransportChannelImpl*> GetChannels1() {
302 return transport_controller1_->channels_for_testing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 }
deadbeef49f34fd2016-12-06 16:22:06 -0800304
305 std::vector<cricket::TransportChannelImpl*> GetChannels2() {
306 return transport_controller2_->channels_for_testing();
307 }
308
309 cricket::FakeTransportChannel* GetFakeChannel1(int component) {
310 return transport_controller1_->GetFakeTransportChannel_n(
311 channel1_->content_name(), component);
312 }
313
314 cricket::FakeTransportChannel* GetFakeChannel2(int component) {
315 return transport_controller2_->GetFakeTransportChannel_n(
316 channel2_->content_name(), component);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 }
318
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200319 void SendRtp1() {
320 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
321 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200323 void SendRtp2() {
324 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
325 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200327 void SendRtcp1() {
328 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200330 void SendRtcp2() {
331 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 }
333 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200334 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
335 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
336 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200338 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
339 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
340 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200342 void SendCustomRtcp1(uint32_t ssrc) {
343 rtc::Buffer data = CreateRtcpData(ssrc);
344 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200346 void SendCustomRtcp2(uint32_t ssrc) {
347 rtc::Buffer data = CreateRtcpData(ssrc);
348 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200350
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200352 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 }
354 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200355 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
357 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200358 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 }
360 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200361 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 }
363 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200364 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200365 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
366 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200368 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200369 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
370 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200372 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200373 rtc::Buffer data = CreateRtcpData(ssrc);
374 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200376 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200377 rtc::Buffer data = CreateRtcpData(ssrc);
378 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200380 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
381 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200383 rtc::SetBE32(data.data() + 8, ssrc);
384 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000385 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200386 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000387 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 return data;
389 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200390 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
391 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200393 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 return data;
395 }
396
397 bool CheckNoRtp1() {
398 return media_channel1_->CheckNoRtp();
399 }
400 bool CheckNoRtp2() {
401 return media_channel2_->CheckNoRtp();
402 }
403 bool CheckNoRtcp1() {
404 return media_channel1_->CheckNoRtcp();
405 }
406 bool CheckNoRtcp2() {
407 return media_channel2_->CheckNoRtcp();
408 }
jbauchcb560652016-08-04 05:20:32 -0700409 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags.
410 // Returns true if so.
411 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
412 int suite;
zhihuangf5b251b2017-01-12 19:37:48 -0800413 if (!channel->rtp_transport()->GetSrtpCryptoSuite(&suite)) {
jbauchcb560652016-08-04 05:20:32 -0700414 return false;
415 }
416
417 if (flags & GCM_CIPHER) {
418 return rtc::IsGcmCryptoSuite(suite);
419 } else {
420 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
421 !rtc::IsGcmCryptoSuite(suite));
422 }
423 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424
425 void CreateContent(int flags,
426 const cricket::AudioCodec& audio_codec,
427 const cricket::VideoCodec& video_codec,
428 typename T::Content* content) {
429 // overridden in specialized classes
430 }
431 void CopyContent(const typename T::Content& source,
432 typename T::Content* content) {
433 // overridden in specialized classes
434 }
435
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436 // Creates a cricket::SessionDescription with one MediaContent and one stream.
437 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200438 cricket::SessionDescription* CreateSessionDescriptionWithStream(
439 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 typename T::Content content;
441 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
442 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
443 AddLegacyStreamInContent(ssrc, 0, &content);
444 sdesc->AddContent("DUMMY_CONTENT_NAME",
445 cricket::NS_JINGLE_RTP, content.Copy());
446 return sdesc;
447 }
448
ossu292d6582016-03-17 02:31:13 -0700449 // Will manage the lifetime of a CallThread, making sure it's
450 // destroyed before this object goes out of scope.
451 class ScopedCallThread {
452 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200453 template <class FunctorT>
454 ScopedCallThread(const FunctorT& functor)
455 : thread_(rtc::Thread::Create()),
456 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700457 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700458 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700459 }
460
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200461 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700462
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200463 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700464
465 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200466 std::unique_ptr<rtc::Thread> thread_;
467 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700468 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
471 return false; // overridden in specialized classes
472 }
473
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200474 void OnMediaMonitor1(typename T::Channel* channel,
475 const typename T::MediaInfo& info) {
476 RTC_DCHECK_EQ(channel, channel1_.get());
477 media_info_callbacks1_++;
478 }
479 void OnMediaMonitor2(typename T::Channel* channel,
480 const typename T::MediaInfo& info) {
481 RTC_DCHECK_EQ(channel, channel2_.get());
482 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 }
484
Honghai Zhangcc411c02016-03-29 17:27:21 -0700485 cricket::CandidatePairInterface* last_selected_candidate_pair() {
486 return last_selected_candidate_pair_;
487 }
488
Peter Boström0c4e06b2015-10-07 12:23:21 +0200489 void AddLegacyStreamInContent(uint32_t ssrc,
490 int flags,
491 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 // Base implementation.
493 }
494
495 // Tests that can be used by derived classes.
496
497 // Basic sanity check.
498 void TestInit() {
499 CreateChannels(0, 0);
500 EXPECT_FALSE(channel1_->secure());
501 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200502 if (verify_playout_) {
503 EXPECT_FALSE(media_channel1_->playout());
504 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 EXPECT_TRUE(media_channel1_->codecs().empty());
506 EXPECT_TRUE(media_channel1_->recv_streams().empty());
507 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
508 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
509 }
510
511 // Test that SetLocalContent and SetRemoteContent properly configure
512 // the codecs.
513 void TestSetContents() {
514 CreateChannels(0, 0);
515 typename T::Content content;
516 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000517 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000519 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 ASSERT_EQ(1U, media_channel1_->codecs().size());
521 EXPECT_TRUE(CodecMatches(content.codecs()[0],
522 media_channel1_->codecs()[0]));
523 }
524
525 // Test that SetLocalContent and SetRemoteContent properly deals
526 // with an empty offer.
527 void TestSetContentsNullOffer() {
528 CreateChannels(0, 0);
529 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000530 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531 CreateContent(0, kPcmuCodec, kH264Codec, &content);
532 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000533 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 ASSERT_EQ(1U, media_channel1_->codecs().size());
535 EXPECT_TRUE(CodecMatches(content.codecs()[0],
536 media_channel1_->codecs()[0]));
537 }
538
539 // Test that SetLocalContent and SetRemoteContent properly set RTCP
540 // mux.
541 void TestSetContentsRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -0800542 CreateChannels(0, 0);
zhihuangf5b251b2017-01-12 19:37:48 -0800543 EXPECT_TRUE(channel1_->rtcp_transport() != NULL);
544 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000545 typename T::Content content;
546 CreateContent(0, kPcmuCodec, kH264Codec, &content);
547 // Both sides agree on mux. Should no longer be a separate RTCP channel.
548 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000549 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
550 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuangf5b251b2017-01-12 19:37:48 -0800551 EXPECT_TRUE(channel1_->rtcp_transport() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000553 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000555 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuangf5b251b2017-01-12 19:37:48 -0800556 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 }
558
559 // Test that SetLocalContent and SetRemoteContent properly set RTCP
560 // mux when a provisional answer is received.
561 void TestSetContentsRtcpMuxWithPrAnswer() {
deadbeefac22f702017-01-12 21:59:29 -0800562 CreateChannels(0, 0);
zhihuangf5b251b2017-01-12 19:37:48 -0800563 EXPECT_TRUE(channel1_->rtcp_transport() != NULL);
564 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 typename T::Content content;
566 CreateContent(0, kPcmuCodec, kH264Codec, &content);
567 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000568 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
569 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
zhihuangf5b251b2017-01-12 19:37:48 -0800570 EXPECT_TRUE(channel1_->rtcp_transport() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000571 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 // Both sides agree on mux. Should no longer be a separate RTCP channel.
zhihuangf5b251b2017-01-12 19:37:48 -0800573 EXPECT_TRUE(channel1_->rtcp_transport() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000575 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000577 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
578 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuangf5b251b2017-01-12 19:37:48 -0800579 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 }
581
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 // Test that SetRemoteContent properly deals with a content update.
583 void TestSetRemoteContentUpdate() {
584 CreateChannels(0, 0);
585 typename T::Content content;
deadbeefac22f702017-01-12 21:59:29 -0800586 CreateContent(RTCP_MUX | SECURE, kPcmuCodec, kH264Codec, &content);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000588 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
589 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 ASSERT_EQ(1U, media_channel1_->codecs().size());
591 EXPECT_TRUE(CodecMatches(content.codecs()[0],
592 media_channel1_->codecs()[0]));
593 // Now update with other codecs.
594 typename T::Content update_content;
595 update_content.set_partial(true);
596 CreateContent(0, kIsacCodec, kH264SvcCodec,
597 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000598 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 ASSERT_EQ(1U, media_channel1_->codecs().size());
600 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
601 media_channel1_->codecs()[0]));
602 // Now update without any codecs. This is ignored.
603 typename T::Content empty_content;
604 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000605 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 ASSERT_EQ(1U, media_channel1_->codecs().size());
607 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
608 media_channel1_->codecs()[0]));
609 }
610
611 // Test that Add/RemoveStream properly forward to the media channel.
612 void TestStreams() {
613 CreateChannels(0, 0);
614 EXPECT_TRUE(AddStream1(1));
615 EXPECT_TRUE(AddStream1(2));
616 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
617 EXPECT_TRUE(RemoveStream1(2));
618 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
619 EXPECT_TRUE(RemoveStream1(1));
620 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
621 }
622
623 // Test that SetLocalContent properly handles adding and removing StreamParams
624 // to the local content description.
625 // This test uses the CA_UPDATE action that don't require a full
626 // MediaContentDescription to do an update.
627 void TestUpdateStreamsInLocalContent() {
628 cricket::StreamParams stream1;
629 stream1.groupid = "group1";
630 stream1.id = "stream1";
631 stream1.ssrcs.push_back(kSsrc1);
632 stream1.cname = "stream1_cname";
633
634 cricket::StreamParams stream2;
635 stream2.groupid = "group2";
636 stream2.id = "stream2";
637 stream2.ssrcs.push_back(kSsrc2);
638 stream2.cname = "stream2_cname";
639
640 cricket::StreamParams stream3;
641 stream3.groupid = "group3";
642 stream3.id = "stream3";
643 stream3.ssrcs.push_back(kSsrc3);
644 stream3.cname = "stream3_cname";
645
646 CreateChannels(0, 0);
647 typename T::Content content1;
648 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
649 content1.AddStream(stream1);
650 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000651 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652
653 ASSERT_EQ(1u, media_channel1_->send_streams().size());
654 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
655
656 // Update the local streams by adding another sending stream.
657 // Use a partial updated session description.
658 typename T::Content content2;
659 content2.AddStream(stream2);
660 content2.AddStream(stream3);
661 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000662 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000663 ASSERT_EQ(3u, media_channel1_->send_streams().size());
664 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
665 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
666 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
667
668 // Update the local streams by removing the first sending stream.
669 // This is done by removing all SSRCS for this particular stream.
670 typename T::Content content3;
671 stream1.ssrcs.clear();
672 content3.AddStream(stream1);
673 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000674 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 ASSERT_EQ(2u, media_channel1_->send_streams().size());
676 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
677 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
678
679 // Update the local streams with a stream that does not change.
680 // THe update is ignored.
681 typename T::Content content4;
682 content4.AddStream(stream2);
683 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000684 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 ASSERT_EQ(2u, media_channel1_->send_streams().size());
686 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
687 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
688 }
689
690 // Test that SetRemoteContent properly handles adding and removing
691 // StreamParams to the remote content description.
692 // This test uses the CA_UPDATE action that don't require a full
693 // MediaContentDescription to do an update.
694 void TestUpdateStreamsInRemoteContent() {
695 cricket::StreamParams stream1;
696 stream1.id = "Stream1";
697 stream1.groupid = "1";
698 stream1.ssrcs.push_back(kSsrc1);
699 stream1.cname = "stream1_cname";
700
701 cricket::StreamParams stream2;
702 stream2.id = "Stream2";
703 stream2.groupid = "2";
704 stream2.ssrcs.push_back(kSsrc2);
705 stream2.cname = "stream2_cname";
706
707 cricket::StreamParams stream3;
708 stream3.id = "Stream3";
709 stream3.groupid = "3";
710 stream3.ssrcs.push_back(kSsrc3);
711 stream3.cname = "stream3_cname";
712
713 CreateChannels(0, 0);
714 typename T::Content content1;
715 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
716 content1.AddStream(stream1);
717 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000718 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719
720 ASSERT_EQ(1u, media_channel1_->codecs().size());
721 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
722 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
723
724 // Update the remote streams by adding another sending stream.
725 // Use a partial updated session description.
726 typename T::Content content2;
727 content2.AddStream(stream2);
728 content2.AddStream(stream3);
729 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000730 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
732 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
733 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
734 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
735
736 // Update the remote streams by removing the first stream.
737 // This is done by removing all SSRCS for this particular stream.
738 typename T::Content content3;
739 stream1.ssrcs.clear();
740 content3.AddStream(stream1);
741 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000742 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
744 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
745 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
746
747 // Update the remote streams with a stream that does not change.
748 // The update is ignored.
749 typename T::Content content4;
750 content4.AddStream(stream2);
751 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000752 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
754 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
755 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
756 }
757
758 // Test that SetLocalContent and SetRemoteContent properly
759 // handles adding and removing StreamParams when the action is a full
760 // CA_OFFER / CA_ANSWER.
761 void TestChangeStreamParamsInContent() {
762 cricket::StreamParams stream1;
763 stream1.groupid = "group1";
764 stream1.id = "stream1";
765 stream1.ssrcs.push_back(kSsrc1);
766 stream1.cname = "stream1_cname";
767
768 cricket::StreamParams stream2;
769 stream2.groupid = "group1";
770 stream2.id = "stream2";
771 stream2.ssrcs.push_back(kSsrc2);
772 stream2.cname = "stream2_cname";
773
774 // Setup a call where channel 1 send |stream1| to channel 2.
775 CreateChannels(0, 0);
776 typename T::Content content1;
777 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
778 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000779 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 EXPECT_TRUE(channel1_->Enable(true));
781 EXPECT_EQ(1u, media_channel1_->send_streams().size());
782
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000783 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200785 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786
787 // Channel 2 do not send anything.
788 typename T::Content content2;
789 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000790 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000792 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 EXPECT_TRUE(channel2_->Enable(true));
794 EXPECT_EQ(0u, media_channel2_->send_streams().size());
795
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200796 SendCustomRtp1(kSsrc1, 0);
797 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
799
800 // Let channel 2 update the content by sending |stream2| and enable SRTP.
801 typename T::Content content3;
802 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
803 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000804 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 ASSERT_EQ(1u, media_channel2_->send_streams().size());
806 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
807
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000808 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
810 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
811
812 // Channel 1 replies but stop sending stream1.
813 typename T::Content content4;
814 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000815 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 EXPECT_EQ(0u, media_channel1_->send_streams().size());
817
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000818 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
820
821 EXPECT_TRUE(channel1_->secure());
822 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200823 SendCustomRtp2(kSsrc2, 0);
824 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
826 }
827
828 // Test that we only start playout and sending at the right times.
829 void TestPlayoutAndSendingStates() {
830 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200831 if (verify_playout_) {
832 EXPECT_FALSE(media_channel1_->playout());
833 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200835 if (verify_playout_) {
836 EXPECT_FALSE(media_channel2_->playout());
837 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 EXPECT_FALSE(media_channel2_->sending());
839 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200840 if (verify_playout_) {
841 EXPECT_FALSE(media_channel1_->playout());
842 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000844 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
845 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200846 if (verify_playout_) {
847 EXPECT_TRUE(media_channel1_->playout());
848 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000850 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
851 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200852 if (verify_playout_) {
853 EXPECT_FALSE(media_channel2_->playout());
854 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000856 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
857 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200858 if (verify_playout_) {
859 EXPECT_FALSE(media_channel2_->playout());
860 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 EXPECT_FALSE(media_channel2_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200862 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200863 if (verify_playout_) {
864 EXPECT_TRUE(media_channel1_->playout());
865 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200867 if (verify_playout_) {
868 EXPECT_FALSE(media_channel2_->playout());
869 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_FALSE(media_channel2_->sending());
871 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200872 if (verify_playout_) {
873 EXPECT_TRUE(media_channel2_->playout());
874 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000876 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
877 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200878 if (verify_playout_) {
879 EXPECT_TRUE(media_channel1_->playout());
880 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 EXPECT_TRUE(media_channel1_->sending());
882 }
883
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 // Test that changing the MediaContentDirection in the local and remote
885 // session description start playout and sending at the right time.
886 void TestMediaContentDirection() {
887 CreateChannels(0, 0);
888 typename T::Content content1;
889 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
890 typename T::Content content2;
891 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
892 // Set |content2| to be InActive.
893 content2.set_direction(cricket::MD_INACTIVE);
894
895 EXPECT_TRUE(channel1_->Enable(true));
896 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200897 if (verify_playout_) {
898 EXPECT_FALSE(media_channel1_->playout());
899 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200901 if (verify_playout_) {
902 EXPECT_FALSE(media_channel2_->playout());
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 EXPECT_FALSE(media_channel2_->sending());
905
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000906 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
907 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
908 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
909 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200910 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911
Peter Boström34fbfff2015-09-24 19:20:30 +0200912 if (verify_playout_) {
913 EXPECT_TRUE(media_channel1_->playout());
914 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200916 if (verify_playout_) {
917 EXPECT_FALSE(media_channel2_->playout()); // local InActive
918 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 EXPECT_FALSE(media_channel2_->sending()); // local InActive
920
921 // Update |content2| to be RecvOnly.
922 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000923 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
924 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925
Peter Boström34fbfff2015-09-24 19:20:30 +0200926 if (verify_playout_) {
927 EXPECT_TRUE(media_channel1_->playout());
928 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200930 if (verify_playout_) {
931 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
932 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
934
935 // Update |content2| to be SendRecv.
936 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000937 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
938 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939
Peter Boström34fbfff2015-09-24 19:20:30 +0200940 if (verify_playout_) {
941 EXPECT_TRUE(media_channel1_->playout());
942 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200944 if (verify_playout_) {
945 EXPECT_TRUE(media_channel2_->playout());
946 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 EXPECT_TRUE(media_channel2_->sending());
948 }
949
Honghai Zhangcc411c02016-03-29 17:27:21 -0700950 // Tests that when the transport channel signals a candidate pair change
951 // event, the media channel will receive a call on the network route change.
952 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200953 constexpr uint16_t kLocalNetId = 1;
954 constexpr uint16_t kRemoteNetId = 2;
955 constexpr int kLastPacketId = 100;
956
Honghai Zhangcc411c02016-03-29 17:27:21 -0700957 CreateChannels(0, 0);
958
zhihuangf5b251b2017-01-12 19:37:48 -0800959 cricket::TransportChannel* transport_channel1 = channel1_->rtp_transport();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200960 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700961 typename T::MediaChannel* media_channel1 =
962 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200963 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700964
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200965 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700966 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200967 // The transport channel becomes disconnected.
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700968 transport_channel1->SignalSelectedCandidatePairChanged(
969 transport_channel1, nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200970 });
971 WaitForThreads();
972 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700973 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200974 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700975
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700976 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
977 media_channel1, kLocalNetId,
978 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200979 // The transport channel becomes connected.
980 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
981 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
982 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
983 transport_controller1_->CreateFakeCandidatePair(
984 local_address, kLocalNetId, remote_address, kRemoteNetId));
985 transport_channel1->SignalSelectedCandidatePairChanged(
Taylor Brandstetter6bb1ef22016-06-27 18:09:03 -0700986 transport_channel1, candidate_pair.get(), kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200987 });
988 WaitForThreads();
989 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700990 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200991 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700992 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200993 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700994 media_channel1->last_network_route().last_sent_packet_id);
michaelt79e05882016-11-08 02:50:09 -0800995 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
996 EXPECT_EQ(kTransportOverheadPerPacket,
997 media_channel1->transport_overhead_per_packet());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700998 }
999
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 // Test setting up a call.
1001 void TestCallSetup() {
1002 CreateChannels(0, 0);
1003 EXPECT_FALSE(channel1_->secure());
1004 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +02001005 if (verify_playout_) {
1006 EXPECT_TRUE(media_channel1_->playout());
1007 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 EXPECT_FALSE(media_channel1_->sending());
1009 EXPECT_TRUE(SendAccept());
1010 EXPECT_FALSE(channel1_->secure());
1011 EXPECT_TRUE(media_channel1_->sending());
1012 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +02001013 if (verify_playout_) {
1014 EXPECT_TRUE(media_channel2_->playout());
1015 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 EXPECT_TRUE(media_channel2_->sending());
1017 EXPECT_EQ(1U, media_channel2_->codecs().size());
1018 }
1019
1020 // Test that we don't crash if packets are sent during call teardown
1021 // when RTCP mux is enabled. This is a regression test against a specific
1022 // race condition that would only occur when a RTCP packet was sent during
1023 // teardown of a channel on which RTCP mux was enabled.
1024 void TestCallTeardownRtcpMux() {
1025 class LastWordMediaChannel : public T::MediaChannel {
1026 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001027 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001029 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1030 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1032 }
1033 };
1034 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
deadbeefac22f702017-01-12 21:59:29 -08001035 RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 EXPECT_TRUE(SendInitiate());
1037 EXPECT_TRUE(SendAccept());
1038 EXPECT_TRUE(SendTerminate());
1039 }
1040
1041 // Send voice RTP data to the other side and ensure it gets there.
1042 void SendRtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001043 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 EXPECT_TRUE(SendInitiate());
1045 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001046 EXPECT_EQ(1U, GetChannels1().size());
1047 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001048 SendRtp1();
1049 SendRtp2();
1050 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001051 EXPECT_TRUE(CheckRtp1());
1052 EXPECT_TRUE(CheckRtp2());
1053 EXPECT_TRUE(CheckNoRtp1());
1054 EXPECT_TRUE(CheckNoRtp2());
1055 }
1056
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001057 void TestDeinit() {
deadbeefac22f702017-01-12 21:59:29 -08001058 CreateChannels(0, 0);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001059 EXPECT_TRUE(SendInitiate());
1060 EXPECT_TRUE(SendAccept());
1061 SendRtp1();
1062 SendRtp2();
1063 SendRtcp1();
1064 SendRtcp2();
1065 // Do not wait, destroy channels.
1066 channel1_.reset(nullptr);
1067 channel2_.reset(nullptr);
1068 }
1069
deadbeefac22f702017-01-12 21:59:29 -08001070 // Check that RTCP can be transmitted between both sides.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 void SendRtcpToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001072 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001073 EXPECT_TRUE(SendInitiate());
1074 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001075 EXPECT_EQ(2U, GetChannels1().size());
1076 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001077 SendRtcp1();
1078 SendRtcp2();
1079 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 EXPECT_TRUE(CheckRtcp1());
1081 EXPECT_TRUE(CheckRtcp2());
1082 EXPECT_TRUE(CheckNoRtcp1());
1083 EXPECT_TRUE(CheckNoRtcp2());
1084 }
1085
1086 // Check that RTCP is transmitted if only the initiator supports mux.
1087 void SendRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001088 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 EXPECT_TRUE(SendInitiate());
1090 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001091 EXPECT_EQ(2U, GetChannels1().size());
1092 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001093 SendRtcp1();
1094 SendRtcp2();
1095 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 EXPECT_TRUE(CheckRtcp1());
1097 EXPECT_TRUE(CheckRtcp2());
1098 EXPECT_TRUE(CheckNoRtcp1());
1099 EXPECT_TRUE(CheckNoRtcp2());
1100 }
1101
1102 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1103 void SendRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001104 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001106 EXPECT_EQ(2U, GetChannels1().size());
1107 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001109 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001110 SendRtp1();
1111 SendRtp2();
1112 SendRtcp1();
1113 SendRtcp2();
1114 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 EXPECT_TRUE(CheckRtp1());
1116 EXPECT_TRUE(CheckRtp2());
1117 EXPECT_TRUE(CheckNoRtp1());
1118 EXPECT_TRUE(CheckNoRtp2());
1119 EXPECT_TRUE(CheckRtcp1());
1120 EXPECT_TRUE(CheckRtcp2());
1121 EXPECT_TRUE(CheckNoRtcp1());
1122 EXPECT_TRUE(CheckNoRtcp2());
1123 }
1124
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001125 // Check that RTP and RTCP are transmitted ok when both sides
1126 // support mux and one the offerer requires mux.
1127 void SendRequireRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001128 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001129 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001130 EXPECT_EQ(1U, GetChannels1().size());
1131 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001132 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001133 SendRtp1();
1134 SendRtp2();
1135 SendRtcp1();
1136 SendRtcp2();
1137 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001138 EXPECT_TRUE(CheckRtp1());
1139 EXPECT_TRUE(CheckRtp2());
1140 EXPECT_TRUE(CheckNoRtp1());
1141 EXPECT_TRUE(CheckNoRtp2());
1142 EXPECT_TRUE(CheckRtcp1());
1143 EXPECT_TRUE(CheckRtcp2());
1144 EXPECT_TRUE(CheckNoRtcp1());
1145 EXPECT_TRUE(CheckNoRtcp2());
1146 }
1147
1148 // Check that RTP and RTCP are transmitted ok when both sides
deadbeefac22f702017-01-12 21:59:29 -08001149 // support mux and only the answerer requires rtcp mux.
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001150 void SendRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001151 CreateChannels(RTCP_MUX, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001152 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001153 EXPECT_EQ(2U, GetChannels1().size());
1154 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001155 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001156 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001157 SendRtp1();
1158 SendRtp2();
1159 SendRtcp1();
1160 SendRtcp2();
1161 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001162 EXPECT_TRUE(CheckRtp1());
1163 EXPECT_TRUE(CheckRtp2());
1164 EXPECT_TRUE(CheckNoRtp1());
1165 EXPECT_TRUE(CheckNoRtp2());
1166 EXPECT_TRUE(CheckRtcp1());
1167 EXPECT_TRUE(CheckRtcp2());
1168 EXPECT_TRUE(CheckNoRtcp1());
1169 EXPECT_TRUE(CheckNoRtcp2());
1170 }
1171
1172 // Check that RTP and RTCP are transmitted ok when both sides
1173 // require mux.
1174 void SendRequireRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001175 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001176 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001177 EXPECT_EQ(1U, GetChannels1().size());
1178 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001179 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001180 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001181 SendRtp1();
1182 SendRtp2();
1183 SendRtcp1();
1184 SendRtcp2();
1185 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001186 EXPECT_TRUE(CheckRtp1());
1187 EXPECT_TRUE(CheckRtp2());
1188 EXPECT_TRUE(CheckNoRtp1());
1189 EXPECT_TRUE(CheckNoRtp2());
1190 EXPECT_TRUE(CheckRtcp1());
1191 EXPECT_TRUE(CheckRtcp2());
1192 EXPECT_TRUE(CheckNoRtcp1());
1193 EXPECT_TRUE(CheckNoRtcp2());
1194 }
1195
1196 // Check that SendAccept fails if the answerer doesn't support mux
1197 // and the offerer requires it.
1198 void SendRequireRtcpMuxToNoRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001199 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, 0);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001200 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001201 EXPECT_EQ(1U, GetChannels1().size());
1202 EXPECT_EQ(2U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001203 EXPECT_FALSE(SendAccept());
1204 }
1205
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206 // Check that RTCP data sent by the initiator before the accept is not muxed.
1207 void SendEarlyRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001208 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001210 EXPECT_EQ(2U, GetChannels1().size());
1211 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212
1213 // RTCP can be sent before the call is accepted, if the transport is ready.
1214 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001215 SendRtcp1();
1216 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001217 EXPECT_TRUE(CheckNoRtp2());
1218 EXPECT_TRUE(CheckRtcp2());
1219
1220 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001221 SendRtcp2();
1222 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001223 EXPECT_TRUE(CheckNoRtp1());
1224 EXPECT_TRUE(CheckRtcp1());
1225
1226 // Complete call setup and ensure everything is still OK.
1227 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001228 EXPECT_EQ(2U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001229 SendRtcp1();
1230 SendRtcp2();
1231 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 EXPECT_TRUE(CheckRtcp1());
1234 }
1235
1236
1237 // Check that RTCP data is not muxed until both sides have enabled muxing,
1238 // but that we properly demux before we get the accept message, since there
1239 // is a race between RTP data and the jingle accept.
1240 void SendEarlyRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001241 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001243 EXPECT_EQ(2U, GetChannels1().size());
1244 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245
1246 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1247 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001248 SendRtcp1();
1249 WaitForThreads();
1250 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001251
1252 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001253 SendRtcp2();
1254 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 EXPECT_TRUE(CheckNoRtp1());
1256 EXPECT_TRUE(CheckRtcp1());
1257
1258 // Complete call setup and ensure everything is still OK.
1259 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001260 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001261 SendRtcp1();
1262 SendRtcp2();
1263 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 EXPECT_TRUE(CheckRtcp1());
1266 }
1267
1268 // Test that we properly send SRTP with RTCP in both directions.
1269 // You can pass in DTLS and/or RTCP_MUX as flags.
1270 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
jbauchcb560652016-08-04 05:20:32 -07001271 ASSERT((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1272 ASSERT((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273
deadbeefac22f702017-01-12 21:59:29 -08001274 int flags1 = SECURE | flags1_in;
1275 int flags2 = SECURE | flags2_in;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276 bool dtls1 = !!(flags1_in & DTLS);
1277 bool dtls2 = !!(flags2_in & DTLS);
1278 CreateChannels(flags1, flags2);
1279 EXPECT_FALSE(channel1_->secure());
1280 EXPECT_FALSE(channel2_->secure());
1281 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001282 WaitForThreads();
1283 EXPECT_TRUE(channel1_->writable());
1284 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001285 EXPECT_TRUE(SendAccept());
1286 EXPECT_TRUE(channel1_->secure());
1287 EXPECT_TRUE(channel2_->secure());
1288 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1289 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001290 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1291 // channels.
1292 if (dtls1 && dtls2) {
1293 // A GCM cipher is only used if both channels support GCM ciphers.
1294 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1295 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1296 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1297 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001298 SendRtp1();
1299 SendRtp2();
1300 SendRtcp1();
1301 SendRtcp2();
1302 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 EXPECT_TRUE(CheckRtp1());
1304 EXPECT_TRUE(CheckRtp2());
1305 EXPECT_TRUE(CheckNoRtp1());
1306 EXPECT_TRUE(CheckNoRtp2());
1307 EXPECT_TRUE(CheckRtcp1());
1308 EXPECT_TRUE(CheckRtcp2());
1309 EXPECT_TRUE(CheckNoRtcp1());
1310 EXPECT_TRUE(CheckNoRtcp2());
1311 }
1312
1313 // Test that we properly handling SRTP negotiating down to RTP.
1314 void SendSrtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001315 CreateChannels(SECURE, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316 EXPECT_FALSE(channel1_->secure());
1317 EXPECT_FALSE(channel2_->secure());
1318 EXPECT_TRUE(SendInitiate());
1319 EXPECT_TRUE(SendAccept());
1320 EXPECT_FALSE(channel1_->secure());
1321 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001322 SendRtp1();
1323 SendRtp2();
1324 SendRtcp1();
1325 SendRtcp2();
1326 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 EXPECT_TRUE(CheckRtp1());
1328 EXPECT_TRUE(CheckRtp2());
1329 EXPECT_TRUE(CheckNoRtp1());
1330 EXPECT_TRUE(CheckNoRtp2());
1331 EXPECT_TRUE(CheckRtcp1());
1332 EXPECT_TRUE(CheckRtcp2());
1333 EXPECT_TRUE(CheckNoRtcp1());
1334 EXPECT_TRUE(CheckNoRtcp2());
1335 }
1336
1337 // Test that we can send and receive early media when a provisional answer is
1338 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1339 void SendEarlyMediaUsingRtcpMuxSrtp() {
1340 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1341
deadbeefac22f702017-01-12 21:59:29 -08001342 CreateChannels(SSRC_MUX | RTCP_MUX | SECURE,
1343 SSRC_MUX | RTCP_MUX | SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 EXPECT_TRUE(SendOffer());
1345 EXPECT_TRUE(SendProvisionalAnswer());
1346 EXPECT_TRUE(channel1_->secure());
1347 EXPECT_TRUE(channel2_->secure());
deadbeef49f34fd2016-12-06 16:22:06 -08001348 EXPECT_EQ(2U, GetChannels1().size());
1349 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001350 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1351 SendCustomRtcp1(kSsrc1);
1352 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1353 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1356
1357 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001358 SendCustomRtcp2(kSsrc2);
1359 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1360 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1363
1364 // Complete call setup and ensure everything is still OK.
1365 EXPECT_TRUE(SendFinalAnswer());
deadbeef49f34fd2016-12-06 16:22:06 -08001366 EXPECT_EQ(1U, GetChannels1().size());
1367 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 EXPECT_TRUE(channel1_->secure());
1369 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001370 SendCustomRtcp1(kSsrc1);
1371 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1372 SendCustomRtcp2(kSsrc2);
1373 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1374 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1379 }
1380
1381 // Test that we properly send RTP without SRTP from a thread.
1382 void SendRtpToRtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001383 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001384 EXPECT_TRUE(SendInitiate());
1385 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001386 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1387 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1388 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1389 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1390 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1391 send_rtcp1.thread(),
1392 send_rtcp2.thread()};
1393 WaitForThreads(involved_threads);
1394 EXPECT_TRUE(CheckRtp1());
1395 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 EXPECT_TRUE(CheckNoRtp1());
1397 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001398 EXPECT_TRUE(CheckRtcp1());
1399 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400 EXPECT_TRUE(CheckNoRtcp1());
1401 EXPECT_TRUE(CheckNoRtcp2());
1402 }
1403
1404 // Test that we properly send SRTP with RTCP from a thread.
1405 void SendSrtpToSrtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001406 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 EXPECT_TRUE(SendInitiate());
1408 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001409 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1410 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1411 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1412 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1413 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1414 send_rtcp1.thread(),
1415 send_rtcp2.thread()};
1416 WaitForThreads(involved_threads);
1417 EXPECT_TRUE(CheckRtp1());
1418 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 EXPECT_TRUE(CheckNoRtp1());
1420 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001421 EXPECT_TRUE(CheckRtcp1());
1422 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 EXPECT_TRUE(CheckNoRtcp1());
1424 EXPECT_TRUE(CheckNoRtcp2());
1425 }
1426
1427 // Test that the mediachannel retains its sending state after the transport
1428 // becomes non-writable.
1429 void SendWithWritabilityLoss() {
deadbeefac22f702017-01-12 21:59:29 -08001430 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001431 EXPECT_TRUE(SendInitiate());
1432 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001433 EXPECT_EQ(1U, GetChannels1().size());
1434 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001435 SendRtp1();
1436 SendRtp2();
1437 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 EXPECT_TRUE(CheckRtp1());
1439 EXPECT_TRUE(CheckRtp2());
1440 EXPECT_TRUE(CheckNoRtp1());
1441 EXPECT_TRUE(CheckNoRtp2());
1442
wu@webrtc.org97077a32013-10-25 21:18:33 +00001443 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001444 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001445 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001446 SendRtp1();
1447 SendRtp2();
1448 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 EXPECT_TRUE(CheckRtp1());
1450 EXPECT_TRUE(CheckNoRtp2());
1451
1452 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001453 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001454 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001456 SendRtp1();
1457 SendRtp2();
1458 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 EXPECT_TRUE(CheckRtp1());
1460 EXPECT_TRUE(CheckRtp2());
1461 EXPECT_TRUE(CheckNoRtp1());
1462 EXPECT_TRUE(CheckNoRtp2());
1463
1464 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001465 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001466 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetDestination(nullptr); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 EXPECT_TRUE(media_channel1_->sending());
1468
wu@webrtc.org97077a32013-10-25 21:18:33 +00001469 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001470 SendRtp1();
1471 SendRtp2();
1472 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 EXPECT_TRUE(CheckRtp1());
1474 EXPECT_TRUE(CheckNoRtp2());
1475
1476 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001477 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeef49f34fd2016-12-06 16:22:06 -08001478 GetFakeChannel1(1)->SetDestination(GetFakeChannel2(1));
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001479 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001481 SendRtp1();
1482 SendRtp2();
1483 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 EXPECT_TRUE(CheckRtp1());
1485 EXPECT_TRUE(CheckRtp2());
1486 EXPECT_TRUE(CheckNoRtp1());
1487 EXPECT_TRUE(CheckNoRtp2());
1488 }
1489
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001490 void SendBundleToBundle(
1491 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1492 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001494 // Only pl_type1 was added to the bundle filter for both |channel1_|
1495 // and |channel2_|.
1496 int pl_type1 = pl_types[0];
1497 int pl_type2 = pl_types[1];
deadbeefac22f702017-01-12 21:59:29 -08001498 int flags = SSRC_MUX;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001499 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001500 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001501 if (rtcp_mux) {
1502 flags |= RTCP_MUX;
1503 expected_channels = 1U;
1504 }
1505 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001507 EXPECT_EQ(2U, GetChannels1().size());
1508 EXPECT_EQ(expected_channels, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001510 EXPECT_EQ(expected_channels, GetChannels1().size());
1511 EXPECT_EQ(expected_channels, GetChannels2().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001512 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1513 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1514 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1515 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001516
1517 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001518 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1519 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1520 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001521 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001522 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1523 EXPECT_TRUE(CheckNoRtp1());
1524 EXPECT_TRUE(CheckNoRtp2());
1525
1526 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001527 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1528 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1529 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001530 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001531 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1532
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001533 SendCustomRtcp1(kSsrc1);
1534 SendCustomRtcp2(kSsrc2);
1535 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1537 EXPECT_TRUE(CheckNoRtcp1());
1538 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1539 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001541 SendCustomRtcp1(kSsrc2);
1542 SendCustomRtcp2(kSsrc1);
1543 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001544 // Bundle filter shouldn't filter out any RTCP.
1545 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1546 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 }
1548
deadbeefc6b6e092016-12-01 12:49:20 -08001549 // Test that the media monitor can be run and gives callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 void TestMediaMonitor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 CreateChannels(0, 0);
1552 EXPECT_TRUE(SendInitiate());
1553 EXPECT_TRUE(SendAccept());
1554 channel1_->StartMediaMonitor(100);
1555 channel2_->StartMediaMonitor(100);
1556 // Ensure we get callbacks and stop.
deadbeefc6b6e092016-12-01 12:49:20 -08001557 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
1558 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 channel1_->StopMediaMonitor();
1560 channel2_->StopMediaMonitor();
1561 // Ensure a restart of a stopped monitor works.
1562 channel1_->StartMediaMonitor(100);
deadbeefc6b6e092016-12-01 12:49:20 -08001563 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 channel1_->StopMediaMonitor();
1565 // Ensure stopping a stopped monitor is OK.
1566 channel1_->StopMediaMonitor();
1567 }
1568
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 void TestSetContentFailure() {
1570 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571
Peter Thatchera6d24442015-07-09 21:26:36 -07001572 auto sdesc = cricket::SessionDescription();
1573 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1574 new cricket::AudioContentDescription());
1575 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1576 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577
Peter Thatchera6d24442015-07-09 21:26:36 -07001578 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001580 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1581 &sdesc, cricket::CA_OFFER, &err));
1582 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1583 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001586 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1587 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001589 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1590 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 }
1592
1593 void TestSendTwoOffers() {
1594 CreateChannels(0, 0);
1595
Peter Thatchera6d24442015-07-09 21:26:36 -07001596 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001597 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001598 CreateSessionDescriptionWithStream(1));
1599 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1600 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1602
kwiberg31022942016-03-11 14:18:21 -08001603 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001604 CreateSessionDescriptionWithStream(2));
1605 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1606 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1608 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1609 }
1610
1611 void TestReceiveTwoOffers() {
1612 CreateChannels(0, 0);
1613
Peter Thatchera6d24442015-07-09 21:26:36 -07001614 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001615 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001616 CreateSessionDescriptionWithStream(1));
1617 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1618 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1620
kwiberg31022942016-03-11 14:18:21 -08001621 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001622 CreateSessionDescriptionWithStream(2));
1623 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1624 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1626 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1627 }
1628
1629 void TestSendPrAnswer() {
1630 CreateChannels(0, 0);
1631
Peter Thatchera6d24442015-07-09 21:26:36 -07001632 std::string err;
1633 // Receive offer
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
Peter Thatchera6d24442015-07-09 21:26:36 -07001640 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001641 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001642 CreateSessionDescriptionWithStream(2));
1643 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1644 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1646 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1647
Peter Thatchera6d24442015-07-09 21:26:36 -07001648 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001649 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001650 CreateSessionDescriptionWithStream(3));
1651 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1652 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1654 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1655 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1656 }
1657
1658 void TestReceivePrAnswer() {
1659 CreateChannels(0, 0);
1660
Peter Thatchera6d24442015-07-09 21:26:36 -07001661 std::string err;
1662 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001663 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001664 CreateSessionDescriptionWithStream(1));
1665 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1666 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1668
Peter Thatchera6d24442015-07-09 21:26:36 -07001669 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001670 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001671 CreateSessionDescriptionWithStream(2));
1672 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1673 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1675 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1676
Peter Thatchera6d24442015-07-09 21:26:36 -07001677 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001678 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001679 CreateSessionDescriptionWithStream(3));
1680 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1681 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1683 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1684 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1685 }
1686
1687 void TestFlushRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001688 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 EXPECT_TRUE(SendInitiate());
1690 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001691 EXPECT_EQ(2U, GetChannels1().size());
1692 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693
1694 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001695 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 // The sending message is only posted. channel2_ should be empty.
1697 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001698 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1699 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700
1701 // When channel1_ is deleted, the RTCP packet should be sent out to
1702 // channel2_.
1703 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001704 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 EXPECT_TRUE(CheckRtcp2());
1706 }
1707
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001708 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001709 struct SrtpErrorHandler : public sigslot::has_slots<> {
1710 SrtpErrorHandler() :
1711 mode_(cricket::SrtpFilter::UNPROTECT),
1712 error_(cricket::SrtpFilter::ERROR_NONE) {}
1713 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1714 cricket::SrtpFilter::Error error) {
1715 mode_ = mode;
1716 error_ = error;
1717 }
1718 cricket::SrtpFilter::Mode mode_;
1719 cricket::SrtpFilter::Error error_;
1720 } error_handler;
1721
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001722 // For Audio, only pl_type 0 is added to the bundle filter.
1723 // For Video, only pl_type 97 is added to the bundle filter.
1724 // So we need to pass in pl_type so that the packet can pass through
1725 // the bundle filter before it can be processed by the srtp filter.
1726 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001727 static unsigned const char kBadPacket[] = {
1728 0x84, static_cast<unsigned char>(pl_type),
1729 0x00, 0x01,
1730 0x00, 0x00,
1731 0x00, 0x00,
1732 0x00, 0x00,
1733 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001734
1735 // Using fake clock because this tests that SRTP errors are signaled at
1736 // specific times based on set_signal_silent_time.
1737 rtc::ScopedFakeClock fake_clock;
1738 // Some code uses a time of 0 as a special value, so we must start with
1739 // a non-zero time.
1740 // TODO(deadbeef): Fix this.
1741 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1742
deadbeefac22f702017-01-12 21:59:29 -08001743 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 EXPECT_FALSE(channel1_->secure());
1745 EXPECT_FALSE(channel2_->secure());
1746 EXPECT_TRUE(SendInitiate());
1747 EXPECT_TRUE(SendAccept());
1748 EXPECT_TRUE(channel1_->secure());
1749 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001750 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001751 channel2_->srtp_filter()->SignalSrtpError.connect(
1752 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753
1754 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001755 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1756 rtc::PacketOptions());
1757 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001759 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001760 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1761 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001762 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1763 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001764 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1765 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001767 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001768 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001769 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001770 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1771 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001772 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001773 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1774 rtc::PacketOptions());
1775 WaitForThreads();
1776 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001777 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778
1779 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001780 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001781 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001782
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001783 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
zhihuangf5b251b2017-01-12 19:37:48 -08001784 cricket::TransportChannel* transport_channel = channel2_->rtp_transport();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001785 transport_channel->SignalReadPacket(
1786 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1787 sizeof(kBadPacket), rtc::PacketTime(), 0);
1788 });
1789 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001790 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001791 // Terminate channels before the fake clock is destroyed.
1792 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 }
1794
1795 void TestOnReadyToSend() {
deadbeefac22f702017-01-12 21:59:29 -08001796 CreateChannels(0, 0);
zhihuangf5b251b2017-01-12 19:37:48 -08001797 TransportChannel* rtp = channel1_->rtp_transport();
1798 TransportChannel* rtcp = channel1_->rtcp_transport();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001800
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001801 network_thread_->Invoke<void>(RTC_FROM_HERE,
1802 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001803 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001805
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001806 network_thread_->Invoke<void>(RTC_FROM_HERE,
1807 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001808 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1810 // channel are ready to send.
1811 EXPECT_TRUE(media_channel1_->ready_to_send());
1812
1813 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001814 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1815 channel1_->SetTransportChannelReadyToSend(false, false);
1816 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001817 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001819
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001820 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1821 channel1_->SetTransportChannelReadyToSend(false, true);
1822 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001823 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 EXPECT_TRUE(media_channel1_->ready_to_send());
1825
1826 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001827 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1828 channel1_->SetTransportChannelReadyToSend(true, false);
1829 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001830 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001832
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001833 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1834 channel1_->SetTransportChannelReadyToSend(true, true);
1835 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001836 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 EXPECT_TRUE(media_channel1_->ready_to_send());
1838 }
1839
1840 void TestOnReadyToSendWithRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001841 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 typename T::Content content;
1843 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1844 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1845 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001846 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1847 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuangf5b251b2017-01-12 19:37:48 -08001848 EXPECT_TRUE(channel1_->rtcp_transport() == NULL);
1849 TransportChannel* rtp = channel1_->rtp_transport();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 EXPECT_FALSE(media_channel1_->ready_to_send());
1851 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1852 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001853 network_thread_->Invoke<void>(RTC_FROM_HERE,
1854 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001855 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001857
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001858 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1859 channel1_->SetTransportChannelReadyToSend(false, false);
1860 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001861 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 EXPECT_FALSE(media_channel1_->ready_to_send());
1863 }
1864
skvladdc1c62c2016-03-16 19:07:43 -07001865 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1866 typename T::Content content;
1867 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1868 content.set_bandwidth(remote_limit);
1869 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1870 }
1871
1872 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1873 webrtc::RtpParameters parameters;
1874 webrtc::RtpEncodingParameters encoding;
1875 encoding.max_bitrate_bps = limit;
1876 parameters.encodings.push_back(encoding);
1877 return parameters;
1878 }
1879
1880 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1881 int expected_bitrate) {
1882 EXPECT_EQ(1UL, parameters.encodings.size());
1883 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1884 }
1885
1886 void DefaultMaxBitrateIsUnlimited() {
1887 CreateChannels(0, 0);
1888 EXPECT_TRUE(
1889 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1890 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001891 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001892 }
1893
1894 void CanChangeMaxBitrate() {
1895 CreateChannels(0, 0);
1896 EXPECT_TRUE(
1897 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1898
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001899 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1900 kSsrc1, BitrateLimitedParameters(1000)));
1901 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1902 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001903 EXPECT_EQ(-1, media_channel1_->max_bps());
1904
1905 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001906 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1907 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1908 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001909 EXPECT_EQ(-1, media_channel1_->max_bps());
1910 }
1911
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001913 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1914 static void ProcessThreadQueue(rtc::Thread* thread) {
1915 RTC_DCHECK(thread->IsCurrent());
1916 while (!thread->empty()) {
1917 thread->ProcessMessages(0);
1918 }
1919 }
1920 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1921 // |threads| and current thread post packets to network thread.
1922 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001923 thread->Invoke<void>(RTC_FROM_HERE,
1924 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001925 }
1926 ProcessThreadQueue(rtc::Thread::Current());
1927 // Network thread move them around and post back to worker = current thread.
1928 if (!network_thread_->IsCurrent()) {
1929 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001930 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001931 }
1932 // Worker thread = current Thread process received messages.
1933 ProcessThreadQueue(rtc::Thread::Current());
1934 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001935 // TODO(pbos): Remove playout from all media channels and let renderers mute
1936 // themselves.
1937 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001938 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1939 rtc::Thread* network_thread_;
1940 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1941 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 cricket::FakeMediaEngine media_engine_;
1943 // The media channels are owned by the voice channel objects below.
1944 typename T::MediaChannel* media_channel1_;
1945 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001946 std::unique_ptr<typename T::Channel> channel1_;
1947 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948 typename T::Content local_media_content1_;
1949 typename T::Content local_media_content2_;
1950 typename T::Content remote_media_content1_;
1951 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001953 rtc::Buffer rtp_packet_;
1954 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001955 int media_info_callbacks1_;
1956 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001957 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958};
1959
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960template<>
1961void ChannelTest<VoiceTraits>::CreateContent(
1962 int flags,
1963 const cricket::AudioCodec& audio_codec,
1964 const cricket::VideoCodec& video_codec,
1965 cricket::AudioContentDescription* audio) {
1966 audio->AddCodec(audio_codec);
1967 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1968 if (flags & SECURE) {
1969 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001970 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1971 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 }
1973}
1974
1975template<>
1976void ChannelTest<VoiceTraits>::CopyContent(
1977 const cricket::AudioContentDescription& source,
1978 cricket::AudioContentDescription* audio) {
1979 *audio = source;
1980}
1981
1982template<>
1983bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1984 const cricket::AudioCodec& c2) {
1985 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1986 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1987}
1988
Peter Boström0c4e06b2015-10-07 12:23:21 +02001989template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001991 uint32_t ssrc,
1992 int flags,
1993 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 audio->AddLegacyStream(ssrc);
1995}
1996
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001997class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 public:
solenberg1dd98f32015-09-10 01:57:14 -07001999 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002000 VoiceChannelSingleThreadTest()
2001 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2002};
2003
2004class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2005 public:
2006 typedef ChannelTest<VoiceTraits> Base;
2007 VoiceChannelDoubleThreadTest()
2008 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009};
2010
2011// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002012template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002014 rtc::Thread* worker_thread,
2015 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002016 cricket::MediaEngineInterface* engine,
2017 cricket::FakeVideoMediaChannel* ch,
2018 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002019 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -08002020 rtc::Thread* signaling_thread =
2021 transport_controller ? transport_controller->signaling_thread() : nullptr;
deadbeef7af91dd2016-12-13 11:29:11 -08002022 cricket::VideoChannel* channel = new cricket::VideoChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08002023 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO,
deadbeefac22f702017-01-12 21:59:29 -08002024 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07002025 rtc::CryptoOptions crypto_options;
2026 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2027 channel->SetCryptoOptions(crypto_options);
zhihuangf5b251b2017-01-12 19:37:48 -08002028 cricket::TransportChannel* rtp_transport =
2029 transport_controller->CreateTransportChannel(
2030 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
2031 cricket::TransportChannel* rtcp_transport = nullptr;
2032 if (channel->NeedsRtcpTransport()) {
2033 rtcp_transport = transport_controller->CreateTransportChannel(
2034 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
2035 }
2036 if (!channel->Init_w(rtp_transport, rtcp_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 delete channel;
2038 channel = NULL;
2039 }
2040 return channel;
2041}
2042
2043// override to add 0 parameter
2044template<>
2045bool ChannelTest<VideoTraits>::AddStream1(int id) {
2046 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2047}
2048
2049template<>
2050void ChannelTest<VideoTraits>::CreateContent(
2051 int flags,
2052 const cricket::AudioCodec& audio_codec,
2053 const cricket::VideoCodec& video_codec,
2054 cricket::VideoContentDescription* video) {
2055 video->AddCodec(video_codec);
2056 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2057 if (flags & SECURE) {
2058 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002059 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2060 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 }
2062}
2063
2064template<>
2065void ChannelTest<VideoTraits>::CopyContent(
2066 const cricket::VideoContentDescription& source,
2067 cricket::VideoContentDescription* video) {
2068 *video = source;
2069}
2070
2071template<>
2072bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2073 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002074 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075}
2076
Peter Boström0c4e06b2015-10-07 12:23:21 +02002077template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002079 uint32_t ssrc,
2080 int flags,
2081 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 video->AddLegacyStream(ssrc);
2083}
2084
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002085class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 public:
solenberg1dd98f32015-09-10 01:57:14 -07002087 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002088 VideoChannelSingleThreadTest()
2089 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090};
2091
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002092class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2093 public:
2094 typedef ChannelTest<VideoTraits> Base;
2095 VideoChannelDoubleThreadTest()
2096 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2097};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002099// VoiceChannelSingleThreadTest
2100TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 Base::TestInit();
2102 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2103 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2104}
2105
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002106TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2107 Base::TestDeinit();
2108}
2109
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002110TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 Base::TestSetContents();
2112}
2113
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002114TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 Base::TestSetContentsNullOffer();
2116}
2117
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002118TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 Base::TestSetContentsRtcpMux();
2120}
2121
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002122TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 Base::TestSetContentsRtcpMux();
2124}
2125
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002126TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 Base::TestSetRemoteContentUpdate();
2128}
2129
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002130TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 Base::TestStreams();
2132}
2133
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002134TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 Base::TestUpdateStreamsInLocalContent();
2136}
2137
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002138TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139 Base::TestUpdateStreamsInRemoteContent();
2140}
2141
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002142TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 Base::TestChangeStreamParamsInContent();
2144}
2145
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002146TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 Base::TestPlayoutAndSendingStates();
2148}
2149
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002150TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002151 CreateChannels(0, 0);
2152 // Test that we can Mute the default channel even though the sending SSRC
2153 // is unknown.
2154 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002155 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002156 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2157 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002158 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2159
2160 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002161 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002162
2163 SendInitiate();
2164 // After the local session description has been set, we can mute a stream
2165 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002166 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002167 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2168 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002169 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170}
2171
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002172TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 Base::TestMediaContentDirection();
2174}
2175
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002176TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002177 Base::TestNetworkRouteChanges();
2178}
2179
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002180TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 Base::TestCallSetup();
2182}
2183
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002184TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 Base::TestCallTeardownRtcpMux();
2186}
2187
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002188TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 Base::SendRtpToRtp();
2190}
2191
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002192TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 Base::SendRtcpToRtcp();
2194}
2195
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002196TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197 Base::SendRtcpMuxToRtcp();
2198}
2199
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002200TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201 Base::SendRtcpMuxToRtcpMux();
2202}
2203
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002204TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002205 Base::SendRequireRtcpMuxToRtcpMux();
2206}
2207
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002208TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002209 Base::SendRtcpMuxToRequireRtcpMux();
2210}
2211
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002212TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002213 Base::SendRequireRtcpMuxToRequireRtcpMux();
2214}
2215
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002216TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002217 Base::SendRequireRtcpMuxToNoRtcpMux();
2218}
2219
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002220TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 Base::SendEarlyRtcpMuxToRtcp();
2222}
2223
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002224TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 Base::SendEarlyRtcpMuxToRtcpMux();
2226}
2227
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002228TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2230}
2231
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002232TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 Base::SendSrtpToSrtp();
2234}
2235
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002236TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2238}
2239
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002240TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2242 Base::SendSrtpToSrtp(DTLS, 0);
2243}
2244
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002245TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2247 Base::SendSrtpToSrtp(DTLS, DTLS);
2248}
2249
jbauchcb560652016-08-04 05:20:32 -07002250TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2251 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2252 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2253}
2254
2255TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2256 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2257 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2258}
2259
2260TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2261 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2262 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2263}
2264
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002265TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2267 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2268}
2269
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002270TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2272}
2273
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002274TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 Base::SendRtpToRtpOnThread();
2276}
2277
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002278TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279 Base::SendSrtpToSrtpOnThread();
2280}
2281
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002282TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 Base::SendWithWritabilityLoss();
2284}
2285
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002286TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 Base::TestMediaMonitor();
2288}
2289
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002291TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 CreateChannels(0, 0);
2293 EXPECT_TRUE(SendInitiate());
2294 EXPECT_TRUE(SendAccept());
2295 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2296
solenberg1d63dd02015-12-02 12:35:09 -08002297 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2298 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2299 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002301 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002303 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002304 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002305 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002306 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002307 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308}
2309
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002310TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 Base::TestSetContentFailure();
2312}
2313
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002314TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 Base::TestSendTwoOffers();
2316}
2317
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002318TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 Base::TestReceiveTwoOffers();
2320}
2321
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002322TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 Base::TestSendPrAnswer();
2324}
2325
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002326TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327 Base::TestReceivePrAnswer();
2328}
2329
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002330TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 Base::TestFlushRtcp();
2332}
2333
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002334TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002335 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336}
2337
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002338TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 Base::TestOnReadyToSend();
2340}
2341
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002342TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 Base::TestOnReadyToSendWithRtcpMux();
2344}
2345
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002347TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002348 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 EXPECT_TRUE(SendInitiate());
2350 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002351 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352
solenberg4bac9c52015-10-09 02:32:53 -07002353 // Default is (1.0).
2354 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2355 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002356 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002357 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358
solenberg4bac9c52015-10-09 02:32:53 -07002359 // Set scale to (1.5).
2360 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2361 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2362 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363
solenberg4bac9c52015-10-09 02:32:53 -07002364 // Set scale to (0).
2365 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2366 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2367 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368}
2369
2370// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002371TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002372 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 EXPECT_TRUE(SendInitiate());
2374 EXPECT_TRUE(SendAccept());
2375 EXPECT_TRUE(AddStream1(1));
2376 EXPECT_TRUE(AddStream1(2));
2377
solenberg4bac9c52015-10-09 02:32:53 -07002378 double volume;
2379 // Default is (1.0).
2380 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2381 EXPECT_DOUBLE_EQ(1.0, volume);
2382 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2383 EXPECT_DOUBLE_EQ(1.0, volume);
2384 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2385 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002387 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388
solenberg4bac9c52015-10-09 02:32:53 -07002389 // Set scale to (1.5) for ssrc = 1.
2390 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2391 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2392 EXPECT_DOUBLE_EQ(1.5, volume);
2393 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2394 EXPECT_DOUBLE_EQ(1.0, volume);
2395 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2396 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397
solenberg4bac9c52015-10-09 02:32:53 -07002398 // Set scale to (0) for all ssrcs.
2399 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2400 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2401 EXPECT_DOUBLE_EQ(0.0, volume);
2402 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2403 EXPECT_DOUBLE_EQ(0.0, volume);
2404 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2405 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406}
2407
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002408TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002409 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002410}
2411
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002412TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002413 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002414}
2415
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002416TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002417 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002418}
2419
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002420TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002421 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422}
2423
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002424TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002425 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002426}
2427
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002428TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002429 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002430}
2431
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002432// VoiceChannelDoubleThreadTest
2433TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002435 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2436 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437}
2438
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002439TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2440 Base::TestDeinit();
2441}
2442
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002443TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 Base::TestSetContents();
2445}
2446
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002447TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448 Base::TestSetContentsNullOffer();
2449}
2450
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002451TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 Base::TestSetContentsRtcpMux();
2453}
2454
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002455TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 Base::TestSetContentsRtcpMux();
2457}
2458
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002459TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 Base::TestSetRemoteContentUpdate();
2461}
2462
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002463TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 Base::TestStreams();
2465}
2466
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002467TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002468 Base::TestUpdateStreamsInLocalContent();
2469}
2470
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002471TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 Base::TestUpdateStreamsInRemoteContent();
2473}
2474
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002475TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476 Base::TestChangeStreamParamsInContent();
2477}
2478
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002479TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 Base::TestPlayoutAndSendingStates();
2481}
2482
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002483TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2484 CreateChannels(0, 0);
2485 // Test that we can Mute the default channel even though the sending SSRC
2486 // is unknown.
2487 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2488 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2489 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2490 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2491 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2492
2493 // Test that we can not mute an unknown SSRC.
2494 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2495
2496 SendInitiate();
2497 // After the local session description has been set, we can mute a stream
2498 // with its SSRC.
2499 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2500 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2501 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2502 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2503}
2504
2505TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2506 Base::TestMediaContentDirection();
2507}
2508
2509TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2510 Base::TestNetworkRouteChanges();
2511}
2512
2513TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2514 Base::TestCallSetup();
2515}
2516
2517TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2518 Base::TestCallTeardownRtcpMux();
2519}
2520
2521TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2522 Base::SendRtpToRtp();
2523}
2524
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002525TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2526 Base::SendRtcpToRtcp();
2527}
2528
2529TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2530 Base::SendRtcpMuxToRtcp();
2531}
2532
2533TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2534 Base::SendRtcpMuxToRtcpMux();
2535}
2536
2537TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2538 Base::SendRequireRtcpMuxToRtcpMux();
2539}
2540
2541TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2542 Base::SendRtcpMuxToRequireRtcpMux();
2543}
2544
2545TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2546 Base::SendRequireRtcpMuxToRequireRtcpMux();
2547}
2548
2549TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2550 Base::SendRequireRtcpMuxToNoRtcpMux();
2551}
2552
2553TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2554 Base::SendEarlyRtcpMuxToRtcp();
2555}
2556
2557TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2558 Base::SendEarlyRtcpMuxToRtcpMux();
2559}
2560
2561TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2562 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2563}
2564
2565TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2566 Base::SendSrtpToSrtp();
2567}
2568
2569TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2570 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2571}
2572
2573TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2574 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2575 Base::SendSrtpToSrtp(DTLS, 0);
2576}
2577
2578TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2579 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2580 Base::SendSrtpToSrtp(DTLS, DTLS);
2581}
2582
jbauchcb560652016-08-04 05:20:32 -07002583TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2584 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2585 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2586}
2587
2588TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2589 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2590 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2591}
2592
2593TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2594 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2595 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2596}
2597
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002598TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2599 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2600 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2601}
2602
2603TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2604 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2605}
2606
2607TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2608 Base::SendRtpToRtpOnThread();
2609}
2610
2611TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2612 Base::SendSrtpToSrtpOnThread();
2613}
2614
2615TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2616 Base::SendWithWritabilityLoss();
2617}
2618
2619TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2620 Base::TestMediaMonitor();
2621}
2622
2623// Test that InsertDtmf properly forwards to the media channel.
2624TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2625 CreateChannels(0, 0);
2626 EXPECT_TRUE(SendInitiate());
2627 EXPECT_TRUE(SendAccept());
2628 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2629
2630 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2631 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2632 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2633
2634 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2635 EXPECT_TRUE(
2636 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2637 EXPECT_TRUE(
2638 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2639 EXPECT_TRUE(
2640 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2641}
2642
2643TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2644 Base::TestSetContentFailure();
2645}
2646
2647TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2648 Base::TestSendTwoOffers();
2649}
2650
2651TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2652 Base::TestReceiveTwoOffers();
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2656 Base::TestSendPrAnswer();
2657}
2658
2659TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2660 Base::TestReceivePrAnswer();
2661}
2662
2663TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2664 Base::TestFlushRtcp();
2665}
2666
2667TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2668 Base::TestSrtpError(kAudioPts[0]);
2669}
2670
2671TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2672 Base::TestOnReadyToSend();
2673}
2674
2675TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2676 Base::TestOnReadyToSendWithRtcpMux();
2677}
2678
2679// Test that we can scale the output volume properly for 1:1 calls.
2680TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002681 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002682 EXPECT_TRUE(SendInitiate());
2683 EXPECT_TRUE(SendAccept());
2684 double volume;
2685
2686 // Default is (1.0).
2687 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2688 EXPECT_DOUBLE_EQ(1.0, volume);
2689 // invalid ssrc.
2690 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2691
2692 // Set scale to (1.5).
2693 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2694 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2695 EXPECT_DOUBLE_EQ(1.5, volume);
2696
2697 // Set scale to (0).
2698 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2699 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2700 EXPECT_DOUBLE_EQ(0.0, volume);
2701}
2702
2703// Test that we can scale the output volume properly for multiway calls.
2704TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002705 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002706 EXPECT_TRUE(SendInitiate());
2707 EXPECT_TRUE(SendAccept());
2708 EXPECT_TRUE(AddStream1(1));
2709 EXPECT_TRUE(AddStream1(2));
2710
2711 double volume;
2712 // Default is (1.0).
2713 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2714 EXPECT_DOUBLE_EQ(1.0, volume);
2715 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2716 EXPECT_DOUBLE_EQ(1.0, volume);
2717 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2718 EXPECT_DOUBLE_EQ(1.0, volume);
2719 // invalid ssrc.
2720 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2721
2722 // Set scale to (1.5) for ssrc = 1.
2723 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2724 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2725 EXPECT_DOUBLE_EQ(1.5, volume);
2726 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2727 EXPECT_DOUBLE_EQ(1.0, volume);
2728 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2729 EXPECT_DOUBLE_EQ(1.0, volume);
2730
2731 // Set scale to (0) for all ssrcs.
2732 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2733 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2734 EXPECT_DOUBLE_EQ(0.0, volume);
2735 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2736 EXPECT_DOUBLE_EQ(0.0, volume);
2737 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2738 EXPECT_DOUBLE_EQ(0.0, volume);
2739}
2740
2741TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2742 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2743}
2744
2745TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2746 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2747}
2748
2749TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2750 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2751}
2752
2753TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2754 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2755}
2756
2757TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2758 Base::DefaultMaxBitrateIsUnlimited();
2759}
2760
2761TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2762 Base::CanChangeMaxBitrate();
2763}
2764
2765// VideoChannelSingleThreadTest
2766TEST_F(VideoChannelSingleThreadTest, TestInit) {
2767 Base::TestInit();
2768}
2769
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002770TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2771 Base::TestDeinit();
2772}
2773
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002774TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2775 Base::TestSetContents();
2776}
2777
2778TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2779 Base::TestSetContentsNullOffer();
2780}
2781
2782TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2783 Base::TestSetContentsRtcpMux();
2784}
2785
2786TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2787 Base::TestSetContentsRtcpMux();
2788}
2789
2790TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2791 Base::TestSetRemoteContentUpdate();
2792}
2793
2794TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2795 Base::TestStreams();
2796}
2797
2798TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2799 Base::TestUpdateStreamsInLocalContent();
2800}
2801
2802TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2803 Base::TestUpdateStreamsInRemoteContent();
2804}
2805
2806TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2807 Base::TestChangeStreamParamsInContent();
2808}
2809
2810TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2811 Base::TestPlayoutAndSendingStates();
2812}
2813
2814TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002815 CreateChannels(0, 0);
2816 // Test that we can Mute the default channel even though the sending SSRC
2817 // is unknown.
2818 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002819 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002820 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002821 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002822 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2823 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002824 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002825 SendInitiate();
2826 // After the local session description has been set, we can mute a stream
2827 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002828 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002829 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002830 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002831 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002832}
2833
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002834TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 Base::TestMediaContentDirection();
2836}
2837
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002838TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002839 Base::TestNetworkRouteChanges();
2840}
2841
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002842TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002843 Base::TestCallSetup();
2844}
2845
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002846TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847 Base::TestCallTeardownRtcpMux();
2848}
2849
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002850TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 Base::SendRtpToRtp();
2852}
2853
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002854TEST_F(VideoChannelSingleThreadTest, 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
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003086TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3087 Base::SendRtcpToRtcp();
3088}
3089
3090TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3091 Base::SendRtcpMuxToRtcp();
3092}
3093
3094TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3095 Base::SendRtcpMuxToRtcpMux();
3096}
3097
3098TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3099 Base::SendRequireRtcpMuxToRtcpMux();
3100}
3101
3102TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3103 Base::SendRtcpMuxToRequireRtcpMux();
3104}
3105
3106TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3107 Base::SendRequireRtcpMuxToRequireRtcpMux();
3108}
3109
3110TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3111 Base::SendRequireRtcpMuxToNoRtcpMux();
3112}
3113
3114TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3115 Base::SendEarlyRtcpMuxToRtcp();
3116}
3117
3118TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3119 Base::SendEarlyRtcpMuxToRtcpMux();
3120}
3121
3122TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3123 Base::SendSrtpToSrtp();
3124}
3125
3126TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3127 Base::SendSrtpToSrtp();
3128}
3129
3130TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3131 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3132 Base::SendSrtpToSrtp(DTLS, 0);
3133}
3134
3135TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3136 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3137 Base::SendSrtpToSrtp(DTLS, DTLS);
3138}
3139
3140TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3141 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3142 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3143}
3144
3145TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3146 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3147}
3148
3149TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3150 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3151}
3152
3153TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3154 Base::SendRtpToRtpOnThread();
3155}
3156
3157TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3158 Base::SendSrtpToSrtpOnThread();
3159}
3160
3161TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3162 Base::SendWithWritabilityLoss();
3163}
3164
3165TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3166 Base::TestMediaMonitor();
3167}
3168
3169TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3170 Base::TestSetContentFailure();
3171}
3172
3173TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3174 Base::TestSendTwoOffers();
3175}
3176
3177TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3178 Base::TestReceiveTwoOffers();
3179}
3180
3181TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3182 Base::TestSendPrAnswer();
3183}
3184
3185TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3186 Base::TestReceivePrAnswer();
3187}
3188
3189TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3190 Base::TestFlushRtcp();
3191}
3192
3193TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3194 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3195}
3196
3197TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3198 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3199}
3200
3201TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3202 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3203}
3204
3205TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3206 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3207}
3208
3209TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3210 Base::TestSrtpError(kVideoPts[0]);
3211}
3212
3213TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3214 Base::TestOnReadyToSend();
3215}
3216
3217TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3218 Base::TestOnReadyToSendWithRtcpMux();
3219}
3220
3221TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3222 Base::DefaultMaxBitrateIsUnlimited();
3223}
3224
3225TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3226 Base::CanChangeMaxBitrate();
3227}
3228
deadbeef953c2ce2017-01-09 14:53:41 -08003229// RtpDataChannelSingleThreadTest
3230class RtpDataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003231 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003232 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003233 RtpDataChannelSingleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003234 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3235};
3236
deadbeef953c2ce2017-01-09 14:53:41 -08003237// RtpDataChannelDoubleThreadTest
3238class RtpDataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003239 public:
3240 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003241 RtpDataChannelDoubleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003242 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243};
3244
3245// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003246template <>
deadbeef953c2ce2017-01-09 14:53:41 -08003247cricket::RtpDataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003248 rtc::Thread* worker_thread,
3249 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003250 cricket::MediaEngineInterface* engine,
3251 cricket::FakeDataMediaChannel* ch,
3252 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003253 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -08003254 rtc::Thread* signaling_thread =
3255 transport_controller ? transport_controller->signaling_thread() : nullptr;
deadbeef953c2ce2017-01-09 14:53:41 -08003256 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003257 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA,
deadbeefac22f702017-01-12 21:59:29 -08003258 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07003259 rtc::CryptoOptions crypto_options;
3260 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3261 channel->SetCryptoOptions(crypto_options);
zhihuangf5b251b2017-01-12 19:37:48 -08003262 cricket::TransportChannel* rtp_transport =
3263 transport_controller->CreateTransportChannel(
3264 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
3265 cricket::TransportChannel* rtcp_transport = nullptr;
3266 if (channel->NeedsRtcpTransport()) {
3267 rtcp_transport = transport_controller->CreateTransportChannel(
3268 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3269 }
3270 if (!channel->Init_w(rtp_transport, rtcp_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271 delete channel;
3272 channel = NULL;
3273 }
3274 return channel;
3275}
3276
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003277template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003278void ChannelTest<DataTraits>::CreateContent(
3279 int flags,
3280 const cricket::AudioCodec& audio_codec,
3281 const cricket::VideoCodec& video_codec,
3282 cricket::DataContentDescription* data) {
3283 data->AddCodec(kGoogleDataCodec);
3284 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3285 if (flags & SECURE) {
3286 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003287 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3288 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289 }
3290}
3291
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003292template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003293void ChannelTest<DataTraits>::CopyContent(
3294 const cricket::DataContentDescription& source,
3295 cricket::DataContentDescription* data) {
3296 *data = source;
3297}
3298
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003299template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003300bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3301 const cricket::DataCodec& c2) {
3302 return c1.name == c2.name;
3303}
3304
Peter Boström0c4e06b2015-10-07 12:23:21 +02003305template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003306void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003307 uint32_t ssrc,
3308 int flags,
3309 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003310 data->AddLegacyStream(ssrc);
3311}
3312
deadbeef953c2ce2017-01-09 14:53:41 -08003313TEST_F(RtpDataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314 Base::TestInit();
3315 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3316}
3317
deadbeef953c2ce2017-01-09 14:53:41 -08003318TEST_F(RtpDataChannelSingleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003319 Base::TestDeinit();
3320}
3321
deadbeef953c2ce2017-01-09 14:53:41 -08003322TEST_F(RtpDataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323 Base::TestSetContents();
3324}
3325
deadbeef953c2ce2017-01-09 14:53:41 -08003326TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003327 Base::TestSetContentsNullOffer();
3328}
3329
deadbeef953c2ce2017-01-09 14:53:41 -08003330TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331 Base::TestSetContentsRtcpMux();
3332}
3333
deadbeef953c2ce2017-01-09 14:53:41 -08003334TEST_F(RtpDataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335 Base::TestSetRemoteContentUpdate();
3336}
3337
deadbeef953c2ce2017-01-09 14:53:41 -08003338TEST_F(RtpDataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003339 Base::TestStreams();
3340}
3341
deadbeef953c2ce2017-01-09 14:53:41 -08003342TEST_F(RtpDataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343 Base::TestUpdateStreamsInLocalContent();
3344}
3345
deadbeef953c2ce2017-01-09 14:53:41 -08003346TEST_F(RtpDataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347 Base::TestUpdateStreamsInRemoteContent();
3348}
3349
deadbeef953c2ce2017-01-09 14:53:41 -08003350TEST_F(RtpDataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003351 Base::TestChangeStreamParamsInContent();
3352}
3353
deadbeef953c2ce2017-01-09 14:53:41 -08003354TEST_F(RtpDataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003355 Base::TestPlayoutAndSendingStates();
3356}
3357
deadbeef953c2ce2017-01-09 14:53:41 -08003358TEST_F(RtpDataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003359 Base::TestMediaContentDirection();
3360}
3361
deadbeef953c2ce2017-01-09 14:53:41 -08003362TEST_F(RtpDataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003363 Base::TestCallSetup();
3364}
3365
deadbeef953c2ce2017-01-09 14:53:41 -08003366TEST_F(RtpDataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003367 Base::TestCallTeardownRtcpMux();
3368}
3369
deadbeef953c2ce2017-01-09 14:53:41 -08003370TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003371 Base::TestOnReadyToSend();
3372}
3373
deadbeef953c2ce2017-01-09 14:53:41 -08003374TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375 Base::TestOnReadyToSendWithRtcpMux();
3376}
3377
deadbeef953c2ce2017-01-09 14:53:41 -08003378TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003379 Base::SendRtpToRtp();
3380}
3381
deadbeef953c2ce2017-01-09 14:53:41 -08003382TEST_F(RtpDataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003383 Base::SendRtcpToRtcp();
3384}
3385
deadbeef953c2ce2017-01-09 14:53:41 -08003386TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387 Base::SendRtcpMuxToRtcp();
3388}
3389
deadbeef953c2ce2017-01-09 14:53:41 -08003390TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 Base::SendRtcpMuxToRtcpMux();
3392}
3393
deadbeef953c2ce2017-01-09 14:53:41 -08003394TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003395 Base::SendEarlyRtcpMuxToRtcp();
3396}
3397
deadbeef953c2ce2017-01-09 14:53:41 -08003398TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399 Base::SendEarlyRtcpMuxToRtcpMux();
3400}
3401
deadbeef953c2ce2017-01-09 14:53:41 -08003402TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003403 Base::SendSrtpToSrtp();
3404}
3405
deadbeef953c2ce2017-01-09 14:53:41 -08003406TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003407 Base::SendSrtpToSrtp();
3408}
3409
deadbeef953c2ce2017-01-09 14:53:41 -08003410TEST_F(RtpDataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3412}
3413
deadbeef953c2ce2017-01-09 14:53:41 -08003414TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003415 Base::SendRtpToRtpOnThread();
3416}
3417
deadbeef953c2ce2017-01-09 14:53:41 -08003418TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003419 Base::SendSrtpToSrtpOnThread();
3420}
3421
deadbeef953c2ce2017-01-09 14:53:41 -08003422TEST_F(RtpDataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423 Base::SendWithWritabilityLoss();
3424}
3425
deadbeef953c2ce2017-01-09 14:53:41 -08003426TEST_F(RtpDataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427 Base::TestMediaMonitor();
3428}
3429
deadbeef953c2ce2017-01-09 14:53:41 -08003430TEST_F(RtpDataChannelSingleThreadTest, TestSendData) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003431 CreateChannels(0, 0);
3432 EXPECT_TRUE(SendInitiate());
3433 EXPECT_TRUE(SendAccept());
3434
3435 cricket::SendDataParams params;
3436 params.ssrc = 42;
3437 unsigned char data[] = {'f', 'o', 'o'};
3438 rtc::CopyOnWriteBuffer payload(data, 3);
3439 cricket::SendDataResult result;
3440 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3441 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3442 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3443}
3444
deadbeef953c2ce2017-01-09 14:53:41 -08003445TEST_F(RtpDataChannelDoubleThreadTest, TestInit) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003446 Base::TestInit();
3447 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3448}
3449
deadbeef953c2ce2017-01-09 14:53:41 -08003450TEST_F(RtpDataChannelDoubleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003451 Base::TestDeinit();
3452}
3453
deadbeef953c2ce2017-01-09 14:53:41 -08003454TEST_F(RtpDataChannelDoubleThreadTest, TestSetContents) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003455 Base::TestSetContents();
3456}
3457
deadbeef953c2ce2017-01-09 14:53:41 -08003458TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsNullOffer) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003459 Base::TestSetContentsNullOffer();
3460}
3461
deadbeef953c2ce2017-01-09 14:53:41 -08003462TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003463 Base::TestSetContentsRtcpMux();
3464}
3465
deadbeef953c2ce2017-01-09 14:53:41 -08003466TEST_F(RtpDataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003467 Base::TestSetRemoteContentUpdate();
3468}
3469
deadbeef953c2ce2017-01-09 14:53:41 -08003470TEST_F(RtpDataChannelDoubleThreadTest, TestStreams) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003471 Base::TestStreams();
3472}
3473
deadbeef953c2ce2017-01-09 14:53:41 -08003474TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003475 Base::TestUpdateStreamsInLocalContent();
3476}
3477
deadbeef953c2ce2017-01-09 14:53:41 -08003478TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003479 Base::TestUpdateStreamsInRemoteContent();
3480}
3481
deadbeef953c2ce2017-01-09 14:53:41 -08003482TEST_F(RtpDataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003483 Base::TestChangeStreamParamsInContent();
3484}
3485
deadbeef953c2ce2017-01-09 14:53:41 -08003486TEST_F(RtpDataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003487 Base::TestPlayoutAndSendingStates();
3488}
3489
deadbeef953c2ce2017-01-09 14:53:41 -08003490TEST_F(RtpDataChannelDoubleThreadTest, TestMediaContentDirection) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003491 Base::TestMediaContentDirection();
3492}
3493
deadbeef953c2ce2017-01-09 14:53:41 -08003494TEST_F(RtpDataChannelDoubleThreadTest, TestCallSetup) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003495 Base::TestCallSetup();
3496}
3497
deadbeef953c2ce2017-01-09 14:53:41 -08003498TEST_F(RtpDataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003499 Base::TestCallTeardownRtcpMux();
3500}
3501
deadbeef953c2ce2017-01-09 14:53:41 -08003502TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSend) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003503 Base::TestOnReadyToSend();
3504}
3505
deadbeef953c2ce2017-01-09 14:53:41 -08003506TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003507 Base::TestOnReadyToSendWithRtcpMux();
3508}
3509
deadbeef953c2ce2017-01-09 14:53:41 -08003510TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003511 Base::SendRtpToRtp();
3512}
3513
deadbeef953c2ce2017-01-09 14:53:41 -08003514TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003515 Base::SendRtcpToRtcp();
3516}
3517
deadbeef953c2ce2017-01-09 14:53:41 -08003518TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003519 Base::SendRtcpMuxToRtcp();
3520}
3521
deadbeef953c2ce2017-01-09 14:53:41 -08003522TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003523 Base::SendRtcpMuxToRtcpMux();
3524}
3525
deadbeef953c2ce2017-01-09 14:53:41 -08003526TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003527 Base::SendEarlyRtcpMuxToRtcp();
3528}
3529
deadbeef953c2ce2017-01-09 14:53:41 -08003530TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003531 Base::SendEarlyRtcpMuxToRtcpMux();
3532}
3533
deadbeef953c2ce2017-01-09 14:53:41 -08003534TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003535 Base::SendSrtpToSrtp();
3536}
3537
deadbeef953c2ce2017-01-09 14:53:41 -08003538TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003539 Base::SendSrtpToSrtp();
3540}
3541
deadbeef953c2ce2017-01-09 14:53:41 -08003542TEST_F(RtpDataChannelDoubleThreadTest, SendSrtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003543 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3544}
3545
deadbeef953c2ce2017-01-09 14:53:41 -08003546TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003547 Base::SendRtpToRtpOnThread();
3548}
3549
deadbeef953c2ce2017-01-09 14:53:41 -08003550TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003551 Base::SendSrtpToSrtpOnThread();
3552}
3553
deadbeef953c2ce2017-01-09 14:53:41 -08003554TEST_F(RtpDataChannelDoubleThreadTest, SendWithWritabilityLoss) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003555 Base::SendWithWritabilityLoss();
3556}
3557
deadbeef953c2ce2017-01-09 14:53:41 -08003558TEST_F(RtpDataChannelDoubleThreadTest, TestMediaMonitor) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003559 Base::TestMediaMonitor();
3560}
3561
deadbeef953c2ce2017-01-09 14:53:41 -08003562TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563 CreateChannels(0, 0);
3564 EXPECT_TRUE(SendInitiate());
3565 EXPECT_TRUE(SendAccept());
3566
3567 cricket::SendDataParams params;
3568 params.ssrc = 42;
3569 unsigned char data[] = {
3570 'f', 'o', 'o'
3571 };
jbaucheec21bd2016-03-20 06:15:43 -07003572 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573 cricket::SendDataResult result;
3574 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3575 EXPECT_EQ(params.ssrc,
3576 media_channel1_->last_sent_data_params().ssrc);
3577 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3578}
3579
deadbeefbad5dad2017-01-17 18:32:35 -08003580#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3581
3582// Verifies some DCHECKs are in place.
3583// Uses VoiceChannel, but any BaseChannel subclass would work.
3584class BaseChannelDeathTest : public testing::Test {
3585 public:
3586 BaseChannelDeathTest()
3587 : // RTCP mux not required, SRTP required.
3588 voice_channel_(
3589 rtc::Thread::Current(),
3590 rtc::Thread::Current(),
3591 rtc::Thread::Current(),
3592 &fake_media_engine_,
3593 new cricket::FakeVoiceMediaChannel(nullptr,
3594 cricket::AudioOptions()),
3595 cricket::CN_AUDIO,
3596 false,
3597 true) {
3598 rtp_transport_ = fake_transport_controller_.CreateTransportChannel(
3599 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3600 rtcp_transport_ = fake_transport_controller_.CreateTransportChannel(
3601 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3602 EXPECT_TRUE(voice_channel_.Init_w(rtp_transport_, rtcp_transport_));
3603 }
3604
3605 protected:
3606 cricket::FakeTransportController fake_transport_controller_;
3607 cricket::FakeMediaEngine fake_media_engine_;
3608 cricket::VoiceChannel voice_channel_;
3609 // Will be cleaned up by FakeTransportController, don't need to worry about
3610 // deleting them in this test.
3611 cricket::TransportChannel* rtp_transport_;
3612 cricket::TransportChannel* rtcp_transport_;
3613};
3614
3615TEST_F(BaseChannelDeathTest, SetTransportWithNullRtpTransport) {
3616 cricket::TransportChannel* new_rtcp_transport =
3617 fake_transport_controller_.CreateTransportChannel(
3618 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3619 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, new_rtcp_transport), "");
3620}
3621
3622TEST_F(BaseChannelDeathTest, SetTransportWithMissingRtcpTransport) {
3623 cricket::TransportChannel* new_rtp_transport =
3624 fake_transport_controller_.CreateTransportChannel(
3625 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3626 EXPECT_DEATH(voice_channel_.SetTransports(new_rtp_transport, nullptr), "");
3627}
3628
3629TEST_F(BaseChannelDeathTest, SetTransportWithUnneededRtcpTransport) {
3630 // Activate RTCP muxing, simulating offer/answer negotiation.
3631 cricket::AudioContentDescription content;
3632 content.set_rtcp_mux(true);
3633 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
3634 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
3635 cricket::TransportChannel* new_rtp_transport =
3636 fake_transport_controller_.CreateTransportChannel(
3637 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3638 cricket::TransportChannel* new_rtcp_transport =
3639 fake_transport_controller_.CreateTransportChannel(
3640 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3641 // After muxing is enabled, no RTCP transport should be passed in here.
3642 EXPECT_DEATH(
3643 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3644}
3645
3646// This test will probably go away if/when we move the transport name out of
3647// the transport classes and into their parent classes.
3648TEST_F(BaseChannelDeathTest, SetTransportWithMismatchingTransportNames) {
3649 cricket::TransportChannel* new_rtp_transport =
3650 fake_transport_controller_.CreateTransportChannel(
3651 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3652 cricket::TransportChannel* new_rtcp_transport =
3653 fake_transport_controller_.CreateTransportChannel(
3654 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3655 EXPECT_DEATH(
3656 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3657}
3658
3659#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3660
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003661// TODO(pthatcher): TestSetReceiver?