blob: dd5eaa19f47b0359d5ec50e023e1e68df3edefb6 [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"
nissec8ee8822017-01-18 07:20:55 -080015#include "webrtc/base/checks.h"
Taylor Brandstetter88532892016-08-01 14:17:27 -070016#include "webrtc/base/fakeclock.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000017#include "webrtc/base/gunit.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000018#include "webrtc/base/logging.h"
jbauchcb560652016-08-04 05:20:32 -070019#include "webrtc/base/sslstreamadapter.h"
kjellandera96e2d72016-02-04 23:52:28 -080020#include "webrtc/media/base/fakemediaengine.h"
21#include "webrtc/media/base/fakertp.h"
kjellandera96e2d72016-02-04 23:52:28 -080022#include "webrtc/media/base/mediachannel.h"
kjellandera96e2d72016-02-04 23:52:28 -080023#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010024#include "webrtc/p2p/base/faketransportcontroller.h"
zhihuang6ce92592017-01-19 04:49:47 -080025#include "webrtc/p2p/base/transportchannelimpl.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010026#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
28#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000029 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030 LOG(LS_INFO) << "Feature disabled... skipping"; \
31 return; \
32 }
33
34using cricket::CA_OFFER;
35using cricket::CA_PRANSWER;
36using cricket::CA_ANSWER;
37using cricket::CA_UPDATE;
38using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039using cricket::StreamParams;
zhihuang6ce92592017-01-19 04:49:47 -080040using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000041
Danil Chapovalov33b01f22016-05-11 19:55:27 +020042namespace {
43const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
44const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
45const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
perkj26752742016-10-24 01:21:16 -070046const cricket::VideoCodec kH264Codec(97, "H264");
47const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
Danil Chapovalov33b01f22016-05-11 19:55:27 +020048const cricket::DataCodec kGoogleDataCodec(101, "google-data");
49const uint32_t kSsrc1 = 0x1111;
50const uint32_t kSsrc2 = 0x2222;
51const uint32_t kSsrc3 = 0x3333;
52const int kAudioPts[] = {0, 8};
53const int kVideoPts[] = {97, 99};
54enum class NetworkIsWorker { Yes, No };
deadbeefc6b6e092016-12-01 12:49:20 -080055const int kDefaultTimeout = 10000; // 10 seconds.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020056} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057
deadbeefcbecd352015-09-23 11:50:27 -070058template <class ChannelT,
59 class MediaChannelT,
60 class ContentT,
61 class CodecT,
62 class MediaInfoT,
63 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064class Traits {
65 public:
66 typedef ChannelT Channel;
67 typedef MediaChannelT MediaChannel;
68 typedef ContentT Content;
69 typedef CodecT Codec;
70 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020071 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072};
73
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074class VoiceTraits : public Traits<cricket::VoiceChannel,
75 cricket::FakeVoiceMediaChannel,
76 cricket::AudioContentDescription,
77 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020078 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070079 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
81class VideoTraits : public Traits<cricket::VideoChannel,
82 cricket::FakeVideoMediaChannel,
83 cricket::VideoContentDescription,
84 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020085 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070086 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087
deadbeef953c2ce2017-01-09 14:53:41 -080088class DataTraits : public Traits<cricket::RtpDataChannel,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089 cricket::FakeDataMediaChannel,
90 cricket::DataContentDescription,
91 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020092 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070093 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
deadbeef953c2ce2017-01-09 14:53:41 -080095// Base class for Voice/Video/RtpDataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096template<class T>
97class ChannelTest : public testing::Test, public sigslot::has_slots<> {
98 public:
deadbeefac22f702017-01-12 21:59:29 -080099 enum Flags {
100 RTCP_MUX = 0x1,
101 RTCP_MUX_REQUIRED = 0x2,
102 SECURE = 0x4,
103 SSRC_MUX = 0x8,
104 DTLS = 0x10,
105 GCM_CIPHER = 0x20
106 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107
Peter Boström34fbfff2015-09-24 19:20:30 +0200108 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200109 rtc::ArrayView<const uint8_t> rtp_data,
110 rtc::ArrayView<const uint8_t> rtcp_data,
111 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200112 : verify_playout_(verify_playout),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113 media_channel1_(NULL),
114 media_channel2_(NULL),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200115 rtp_packet_(rtp_data.data(), rtp_data.size()),
116 rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117 media_info_callbacks1_(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200118 media_info_callbacks2_() {
119 if (network_is_worker == NetworkIsWorker::Yes) {
120 network_thread_ = rtc::Thread::Current();
121 } else {
122 network_thread_keeper_ = rtc::Thread::Create();
123 network_thread_keeper_->SetName("Network", nullptr);
124 network_thread_keeper_->Start();
125 network_thread_ = network_thread_keeper_.get();
126 }
127 transport_controller1_.reset(new cricket::FakeTransportController(
128 network_thread_, cricket::ICEROLE_CONTROLLING));
129 transport_controller2_.reset(new cricket::FakeTransportController(
130 network_thread_, cricket::ICEROLE_CONTROLLED));
131 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200134 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
135 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200136 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200138 void CreateChannels(typename T::MediaChannel* ch1,
139 typename T::MediaChannel* ch2,
140 int flags1,
141 int flags2) {
deadbeefac22f702017-01-12 21:59:29 -0800142 // Make sure RTCP_MUX_REQUIRED isn't set without RTCP_MUX.
143 ASSERT_NE(RTCP_MUX_REQUIRED, flags1 & (RTCP_MUX | RTCP_MUX_REQUIRED));
144 ASSERT_NE(RTCP_MUX_REQUIRED, flags2 & (RTCP_MUX | RTCP_MUX_REQUIRED));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200145 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 media_channel1_ = ch1;
147 media_channel2_ = ch2;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200148 channel1_.reset(
149 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
jbauchcb560652016-08-04 05:20:32 -0700150 transport_controller1_.get(), flags1));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200151 channel2_.reset(
152 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
jbauchcb560652016-08-04 05:20:32 -0700153 transport_controller2_.get(), flags2));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200154 channel1_->SignalMediaMonitor.connect(this,
155 &ChannelTest<T>::OnMediaMonitor1);
156 channel2_->SignalMediaMonitor.connect(this,
157 &ChannelTest<T>::OnMediaMonitor2);
deadbeefac22f702017-01-12 21:59:29 -0800158 channel1_->SignalRtcpMuxFullyActive.connect(
zhihuangf5b251b2017-01-12 19:37:48 -0800159 transport_controller1_.get(),
160 &cricket::FakeTransportController::DestroyRtcpTransport);
deadbeefac22f702017-01-12 21:59:29 -0800161 channel2_->SignalRtcpMuxFullyActive.connect(
zhihuangf5b251b2017-01-12 19:37:48 -0800162 transport_controller2_.get(),
163 &cricket::FakeTransportController::DestroyRtcpTransport);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000164 if ((flags1 & DTLS) && (flags2 & DTLS)) {
165 flags1 = (flags1 & ~SECURE);
166 flags2 = (flags2 & ~SECURE);
167 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 CreateContent(flags1, kPcmuCodec, kH264Codec,
169 &local_media_content1_);
170 CreateContent(flags2, kPcmuCodec, kH264Codec,
171 &local_media_content2_);
172 CopyContent(local_media_content1_, &remote_media_content1_);
173 CopyContent(local_media_content2_, &remote_media_content2_);
174
175 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200176 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200177 transport_controller1_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700178 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800179 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 }
181 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200182 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200183 transport_controller2_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700184 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800185 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
187
188 // Add stream information (SSRC) to the local content but not to the remote
189 // content. This means that we per default know the SSRC of what we send but
190 // not what we receive.
191 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
192 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
193
194 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
195 if (flags1 & SSRC_MUX) {
196 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
197 }
198 if (flags2 & SSRC_MUX) {
199 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
200 }
201 }
deadbeefcbecd352015-09-23 11:50:27 -0700202 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200203 rtc::Thread* worker_thread,
204 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700205 cricket::MediaEngineInterface* engine,
206 typename T::MediaChannel* ch,
207 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -0700208 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -0800209 rtc::Thread* signaling_thread =
210 transport_controller ? transport_controller->signaling_thread()
211 : nullptr;
deadbeef7af91dd2016-12-13 11:29:11 -0800212 typename T::Channel* channel = new typename T::Channel(
zhihuangf5b251b2017-01-12 19:37:48 -0800213 worker_thread, network_thread, signaling_thread, engine, ch,
deadbeefac22f702017-01-12 21:59:29 -0800214 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0,
215 (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -0700216 rtc::CryptoOptions crypto_options;
217 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
218 channel->SetCryptoOptions(crypto_options);
zhihuang6ce92592017-01-19 04:49:47 -0800219 cricket::TransportChannel* rtp_transport =
220 transport_controller->CreateTransportChannel(
zhihuangf5b251b2017-01-12 19:37:48 -0800221 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuang6ce92592017-01-19 04:49:47 -0800222 cricket::TransportChannel* rtcp_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -0800223 if (channel->NeedsRtcpTransport()) {
zhihuang6ce92592017-01-19 04:49:47 -0800224 rtcp_transport = transport_controller->CreateTransportChannel(
zhihuangf5b251b2017-01-12 19:37:48 -0800225 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
226 }
zhihuang6ce92592017-01-19 04:49:47 -0800227 if (!channel->Init_w(rtp_transport, rtcp_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228 delete channel;
229 channel = NULL;
230 }
231 return channel;
232 }
233
234 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000235 bool result = channel1_->SetLocalContent(&local_media_content1_,
236 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 if (result) {
238 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000239 result = channel2_->SetRemoteContent(&remote_media_content1_,
240 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200242 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000244 result = channel2_->SetLocalContent(&local_media_content2_,
245 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 }
247 }
248 return result;
249 }
250
251 bool SendAccept() {
252 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000253 return channel1_->SetRemoteContent(&remote_media_content2_,
254 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 }
256
257 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000258 bool result = channel1_->SetLocalContent(&local_media_content1_,
259 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260 if (result) {
261 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000262 result = channel2_->SetRemoteContent(&remote_media_content1_,
263 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000264 }
265 return result;
266 }
267
268 bool SendProvisionalAnswer() {
269 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000270 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 if (result) {
272 channel2_->Enable(true);
273 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000274 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200275 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 }
277 return result;
278 }
279
280 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000281 bool result = channel2_->SetLocalContent(&local_media_content2_,
282 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000284 result = channel1_->SetRemoteContent(&remote_media_content2_,
285 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 return result;
287 }
288
289 bool SendTerminate() {
290 channel1_.reset();
291 channel2_.reset();
292 return true;
293 }
294
295 bool AddStream1(int id) {
296 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
297 }
298 bool RemoveStream1(int id) {
299 return channel1_->RemoveRecvStream(id);
300 }
301
zhihuang6ce92592017-01-19 04:49:47 -0800302 std::vector<cricket::TransportChannelImpl*> GetChannels1() {
deadbeef49f34fd2016-12-06 16:22:06 -0800303 return transport_controller1_->channels_for_testing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 }
deadbeef49f34fd2016-12-06 16:22:06 -0800305
zhihuang6ce92592017-01-19 04:49:47 -0800306 std::vector<cricket::TransportChannelImpl*> GetChannels2() {
deadbeef49f34fd2016-12-06 16:22:06 -0800307 return transport_controller2_->channels_for_testing();
308 }
309
zhihuang6ce92592017-01-19 04:49:47 -0800310 cricket::FakeTransportChannel* GetFakeChannel1(int component) {
311 return transport_controller1_->GetFakeTransportChannel_n(
deadbeef49f34fd2016-12-06 16:22:06 -0800312 channel1_->content_name(), component);
313 }
314
zhihuang6ce92592017-01-19 04:49:47 -0800315 cricket::FakeTransportChannel* GetFakeChannel2(int component) {
316 return transport_controller2_->GetFakeTransportChannel_n(
deadbeef49f34fd2016-12-06 16:22:06 -0800317 channel2_->content_name(), component);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 }
319
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200320 void SendRtp1() {
321 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
322 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200324 void SendRtp2() {
325 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
326 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200328 void SendRtcp1() {
329 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200331 void SendRtcp2() {
332 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
334 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200335 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
336 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
337 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200339 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
340 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
341 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200343 void SendCustomRtcp1(uint32_t ssrc) {
344 rtc::Buffer data = CreateRtcpData(ssrc);
345 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200347 void SendCustomRtcp2(uint32_t ssrc) {
348 rtc::Buffer data = CreateRtcpData(ssrc);
349 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200351
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200353 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 }
355 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200356 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 }
358 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200359 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 }
361 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200362 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 }
364 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200365 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200366 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
367 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200369 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200370 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
371 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200373 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200374 rtc::Buffer data = CreateRtcpData(ssrc);
375 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200377 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200378 rtc::Buffer data = CreateRtcpData(ssrc);
379 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200381 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
382 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200384 rtc::SetBE32(data.data() + 8, ssrc);
385 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000386 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200387 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000388 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 return data;
390 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200391 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
392 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200394 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 return data;
396 }
397
398 bool CheckNoRtp1() {
399 return media_channel1_->CheckNoRtp();
400 }
401 bool CheckNoRtp2() {
402 return media_channel2_->CheckNoRtp();
403 }
404 bool CheckNoRtcp1() {
405 return media_channel1_->CheckNoRtcp();
406 }
407 bool CheckNoRtcp2() {
408 return media_channel2_->CheckNoRtcp();
409 }
jbauchcb560652016-08-04 05:20:32 -0700410 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags.
411 // Returns true if so.
412 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
413 int suite;
zhihuang6ce92592017-01-19 04:49:47 -0800414 if (!channel->rtp_transport()->GetSrtpCryptoSuite(&suite)) {
jbauchcb560652016-08-04 05:20:32 -0700415 return false;
416 }
417
418 if (flags & GCM_CIPHER) {
419 return rtc::IsGcmCryptoSuite(suite);
420 } else {
421 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
422 !rtc::IsGcmCryptoSuite(suite));
423 }
424 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425
426 void CreateContent(int flags,
427 const cricket::AudioCodec& audio_codec,
428 const cricket::VideoCodec& video_codec,
429 typename T::Content* content) {
430 // overridden in specialized classes
431 }
432 void CopyContent(const typename T::Content& source,
433 typename T::Content* content) {
434 // overridden in specialized classes
435 }
436
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 // Creates a cricket::SessionDescription with one MediaContent and one stream.
438 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200439 cricket::SessionDescription* CreateSessionDescriptionWithStream(
440 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 typename T::Content content;
442 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
443 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
444 AddLegacyStreamInContent(ssrc, 0, &content);
445 sdesc->AddContent("DUMMY_CONTENT_NAME",
446 cricket::NS_JINGLE_RTP, content.Copy());
447 return sdesc;
448 }
449
ossu292d6582016-03-17 02:31:13 -0700450 // Will manage the lifetime of a CallThread, making sure it's
451 // destroyed before this object goes out of scope.
452 class ScopedCallThread {
453 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200454 template <class FunctorT>
455 ScopedCallThread(const FunctorT& functor)
456 : thread_(rtc::Thread::Create()),
457 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700458 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700459 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700460 }
461
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200462 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700463
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200464 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700465
466 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200467 std::unique_ptr<rtc::Thread> thread_;
468 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700469 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
472 return false; // overridden in specialized classes
473 }
474
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200475 void OnMediaMonitor1(typename T::Channel* channel,
476 const typename T::MediaInfo& info) {
477 RTC_DCHECK_EQ(channel, channel1_.get());
478 media_info_callbacks1_++;
479 }
480 void OnMediaMonitor2(typename T::Channel* channel,
481 const typename T::MediaInfo& info) {
482 RTC_DCHECK_EQ(channel, channel2_.get());
483 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 }
485
Honghai Zhangcc411c02016-03-29 17:27:21 -0700486 cricket::CandidatePairInterface* last_selected_candidate_pair() {
487 return last_selected_candidate_pair_;
488 }
489
Peter Boström0c4e06b2015-10-07 12:23:21 +0200490 void AddLegacyStreamInContent(uint32_t ssrc,
491 int flags,
492 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000493 // Base implementation.
494 }
495
496 // Tests that can be used by derived classes.
497
498 // Basic sanity check.
499 void TestInit() {
500 CreateChannels(0, 0);
501 EXPECT_FALSE(channel1_->secure());
502 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200503 if (verify_playout_) {
504 EXPECT_FALSE(media_channel1_->playout());
505 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506 EXPECT_TRUE(media_channel1_->codecs().empty());
507 EXPECT_TRUE(media_channel1_->recv_streams().empty());
508 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
509 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
510 }
511
512 // Test that SetLocalContent and SetRemoteContent properly configure
513 // the codecs.
514 void TestSetContents() {
515 CreateChannels(0, 0);
516 typename T::Content content;
517 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000518 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000520 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 ASSERT_EQ(1U, media_channel1_->codecs().size());
522 EXPECT_TRUE(CodecMatches(content.codecs()[0],
523 media_channel1_->codecs()[0]));
524 }
525
526 // Test that SetLocalContent and SetRemoteContent properly deals
527 // with an empty offer.
528 void TestSetContentsNullOffer() {
529 CreateChannels(0, 0);
530 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000531 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532 CreateContent(0, kPcmuCodec, kH264Codec, &content);
533 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000534 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 ASSERT_EQ(1U, media_channel1_->codecs().size());
536 EXPECT_TRUE(CodecMatches(content.codecs()[0],
537 media_channel1_->codecs()[0]));
538 }
539
540 // Test that SetLocalContent and SetRemoteContent properly set RTCP
541 // mux.
542 void TestSetContentsRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -0800543 CreateChannels(0, 0);
zhihuang6ce92592017-01-19 04:49:47 -0800544 EXPECT_TRUE(channel1_->rtcp_transport() != NULL);
545 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 typename T::Content content;
547 CreateContent(0, kPcmuCodec, kH264Codec, &content);
548 // Both sides agree on mux. Should no longer be a separate RTCP channel.
549 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000550 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
551 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuang6ce92592017-01-19 04:49:47 -0800552 EXPECT_TRUE(channel1_->rtcp_transport() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000554 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000556 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuang6ce92592017-01-19 04:49:47 -0800557 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 }
559
560 // Test that SetLocalContent and SetRemoteContent properly set RTCP
561 // mux when a provisional answer is received.
562 void TestSetContentsRtcpMuxWithPrAnswer() {
deadbeefac22f702017-01-12 21:59:29 -0800563 CreateChannels(0, 0);
zhihuang6ce92592017-01-19 04:49:47 -0800564 EXPECT_TRUE(channel1_->rtcp_transport() != NULL);
565 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 typename T::Content content;
567 CreateContent(0, kPcmuCodec, kH264Codec, &content);
568 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000569 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
570 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
zhihuang6ce92592017-01-19 04:49:47 -0800571 EXPECT_TRUE(channel1_->rtcp_transport() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000572 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 // Both sides agree on mux. Should no longer be a separate RTCP channel.
zhihuang6ce92592017-01-19 04:49:47 -0800574 EXPECT_TRUE(channel1_->rtcp_transport() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000576 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000577 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000578 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
579 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuang6ce92592017-01-19 04:49:47 -0800580 EXPECT_TRUE(channel2_->rtcp_transport() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 }
582
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 // Test that SetRemoteContent properly deals with a content update.
584 void TestSetRemoteContentUpdate() {
585 CreateChannels(0, 0);
586 typename T::Content content;
deadbeefac22f702017-01-12 21:59:29 -0800587 CreateContent(RTCP_MUX | SECURE, kPcmuCodec, kH264Codec, &content);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000589 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
590 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 ASSERT_EQ(1U, media_channel1_->codecs().size());
592 EXPECT_TRUE(CodecMatches(content.codecs()[0],
593 media_channel1_->codecs()[0]));
594 // Now update with other codecs.
595 typename T::Content update_content;
596 update_content.set_partial(true);
597 CreateContent(0, kIsacCodec, kH264SvcCodec,
598 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000599 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 ASSERT_EQ(1U, media_channel1_->codecs().size());
601 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
602 media_channel1_->codecs()[0]));
603 // Now update without any codecs. This is ignored.
604 typename T::Content empty_content;
605 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000606 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 ASSERT_EQ(1U, media_channel1_->codecs().size());
608 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
609 media_channel1_->codecs()[0]));
610 }
611
612 // Test that Add/RemoveStream properly forward to the media channel.
613 void TestStreams() {
614 CreateChannels(0, 0);
615 EXPECT_TRUE(AddStream1(1));
616 EXPECT_TRUE(AddStream1(2));
617 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
618 EXPECT_TRUE(RemoveStream1(2));
619 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
620 EXPECT_TRUE(RemoveStream1(1));
621 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
622 }
623
624 // Test that SetLocalContent properly handles adding and removing StreamParams
625 // to the local content description.
626 // This test uses the CA_UPDATE action that don't require a full
627 // MediaContentDescription to do an update.
628 void TestUpdateStreamsInLocalContent() {
629 cricket::StreamParams stream1;
630 stream1.groupid = "group1";
631 stream1.id = "stream1";
632 stream1.ssrcs.push_back(kSsrc1);
633 stream1.cname = "stream1_cname";
634
635 cricket::StreamParams stream2;
636 stream2.groupid = "group2";
637 stream2.id = "stream2";
638 stream2.ssrcs.push_back(kSsrc2);
639 stream2.cname = "stream2_cname";
640
641 cricket::StreamParams stream3;
642 stream3.groupid = "group3";
643 stream3.id = "stream3";
644 stream3.ssrcs.push_back(kSsrc3);
645 stream3.cname = "stream3_cname";
646
647 CreateChannels(0, 0);
648 typename T::Content content1;
649 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
650 content1.AddStream(stream1);
651 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000652 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653
654 ASSERT_EQ(1u, media_channel1_->send_streams().size());
655 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
656
657 // Update the local streams by adding another sending stream.
658 // Use a partial updated session description.
659 typename T::Content content2;
660 content2.AddStream(stream2);
661 content2.AddStream(stream3);
662 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000663 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 ASSERT_EQ(3u, media_channel1_->send_streams().size());
665 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
666 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
667 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
668
669 // Update the local streams by removing the first sending stream.
670 // This is done by removing all SSRCS for this particular stream.
671 typename T::Content content3;
672 stream1.ssrcs.clear();
673 content3.AddStream(stream1);
674 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000675 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 ASSERT_EQ(2u, media_channel1_->send_streams().size());
677 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
678 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
679
680 // Update the local streams with a stream that does not change.
681 // THe update is ignored.
682 typename T::Content content4;
683 content4.AddStream(stream2);
684 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000685 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 ASSERT_EQ(2u, media_channel1_->send_streams().size());
687 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
688 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
689 }
690
691 // Test that SetRemoteContent properly handles adding and removing
692 // StreamParams to the remote content description.
693 // This test uses the CA_UPDATE action that don't require a full
694 // MediaContentDescription to do an update.
695 void TestUpdateStreamsInRemoteContent() {
696 cricket::StreamParams stream1;
697 stream1.id = "Stream1";
698 stream1.groupid = "1";
699 stream1.ssrcs.push_back(kSsrc1);
700 stream1.cname = "stream1_cname";
701
702 cricket::StreamParams stream2;
703 stream2.id = "Stream2";
704 stream2.groupid = "2";
705 stream2.ssrcs.push_back(kSsrc2);
706 stream2.cname = "stream2_cname";
707
708 cricket::StreamParams stream3;
709 stream3.id = "Stream3";
710 stream3.groupid = "3";
711 stream3.ssrcs.push_back(kSsrc3);
712 stream3.cname = "stream3_cname";
713
714 CreateChannels(0, 0);
715 typename T::Content content1;
716 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
717 content1.AddStream(stream1);
718 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000719 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000720
721 ASSERT_EQ(1u, media_channel1_->codecs().size());
722 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
723 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
724
725 // Update the remote streams by adding another sending stream.
726 // Use a partial updated session description.
727 typename T::Content content2;
728 content2.AddStream(stream2);
729 content2.AddStream(stream3);
730 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000731 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
733 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
734 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
735 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
736
737 // Update the remote streams by removing the first stream.
738 // This is done by removing all SSRCS for this particular stream.
739 typename T::Content content3;
740 stream1.ssrcs.clear();
741 content3.AddStream(stream1);
742 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000743 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
745 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
746 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
747
748 // Update the remote streams with a stream that does not change.
749 // The update is ignored.
750 typename T::Content content4;
751 content4.AddStream(stream2);
752 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000753 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
755 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
756 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
757 }
758
759 // Test that SetLocalContent and SetRemoteContent properly
760 // handles adding and removing StreamParams when the action is a full
761 // CA_OFFER / CA_ANSWER.
762 void TestChangeStreamParamsInContent() {
763 cricket::StreamParams stream1;
764 stream1.groupid = "group1";
765 stream1.id = "stream1";
766 stream1.ssrcs.push_back(kSsrc1);
767 stream1.cname = "stream1_cname";
768
769 cricket::StreamParams stream2;
770 stream2.groupid = "group1";
771 stream2.id = "stream2";
772 stream2.ssrcs.push_back(kSsrc2);
773 stream2.cname = "stream2_cname";
774
775 // Setup a call where channel 1 send |stream1| to channel 2.
776 CreateChannels(0, 0);
777 typename T::Content content1;
778 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
779 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000780 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 EXPECT_TRUE(channel1_->Enable(true));
782 EXPECT_EQ(1u, media_channel1_->send_streams().size());
783
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000784 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200786 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787
788 // Channel 2 do not send anything.
789 typename T::Content content2;
790 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000791 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 EXPECT_TRUE(channel2_->Enable(true));
795 EXPECT_EQ(0u, media_channel2_->send_streams().size());
796
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200797 SendCustomRtp1(kSsrc1, 0);
798 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
800
801 // Let channel 2 update the content by sending |stream2| and enable SRTP.
802 typename T::Content content3;
803 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
804 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000805 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 ASSERT_EQ(1u, media_channel2_->send_streams().size());
807 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
808
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000809 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
811 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
812
813 // Channel 1 replies but stop sending stream1.
814 typename T::Content content4;
815 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000816 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_EQ(0u, media_channel1_->send_streams().size());
818
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000819 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
821
822 EXPECT_TRUE(channel1_->secure());
823 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200824 SendCustomRtp2(kSsrc2, 0);
825 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
827 }
828
829 // Test that we only start playout and sending at the right times.
830 void TestPlayoutAndSendingStates() {
831 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200832 if (verify_playout_) {
833 EXPECT_FALSE(media_channel1_->playout());
834 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200836 if (verify_playout_) {
837 EXPECT_FALSE(media_channel2_->playout());
838 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 EXPECT_FALSE(media_channel2_->sending());
840 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200841 if (verify_playout_) {
842 EXPECT_FALSE(media_channel1_->playout());
843 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000845 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
846 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200847 if (verify_playout_) {
848 EXPECT_TRUE(media_channel1_->playout());
849 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000851 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
852 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200853 if (verify_playout_) {
854 EXPECT_FALSE(media_channel2_->playout());
855 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000857 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
858 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200859 if (verify_playout_) {
860 EXPECT_FALSE(media_channel2_->playout());
861 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 EXPECT_FALSE(media_channel2_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200863 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200864 if (verify_playout_) {
865 EXPECT_TRUE(media_channel1_->playout());
866 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200868 if (verify_playout_) {
869 EXPECT_FALSE(media_channel2_->playout());
870 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_FALSE(media_channel2_->sending());
872 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200873 if (verify_playout_) {
874 EXPECT_TRUE(media_channel2_->playout());
875 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000877 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
878 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200879 if (verify_playout_) {
880 EXPECT_TRUE(media_channel1_->playout());
881 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 EXPECT_TRUE(media_channel1_->sending());
883 }
884
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 // Test that changing the MediaContentDirection in the local and remote
886 // session description start playout and sending at the right time.
887 void TestMediaContentDirection() {
888 CreateChannels(0, 0);
889 typename T::Content content1;
890 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
891 typename T::Content content2;
892 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
893 // Set |content2| to be InActive.
894 content2.set_direction(cricket::MD_INACTIVE);
895
896 EXPECT_TRUE(channel1_->Enable(true));
897 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200898 if (verify_playout_) {
899 EXPECT_FALSE(media_channel1_->playout());
900 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200902 if (verify_playout_) {
903 EXPECT_FALSE(media_channel2_->playout());
904 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 EXPECT_FALSE(media_channel2_->sending());
906
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000907 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
908 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
909 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
910 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200911 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912
Peter Boström34fbfff2015-09-24 19:20:30 +0200913 if (verify_playout_) {
914 EXPECT_TRUE(media_channel1_->playout());
915 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200917 if (verify_playout_) {
918 EXPECT_FALSE(media_channel2_->playout()); // local InActive
919 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 EXPECT_FALSE(media_channel2_->sending()); // local InActive
921
922 // Update |content2| to be RecvOnly.
923 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000924 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
925 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926
Peter Boström34fbfff2015-09-24 19:20:30 +0200927 if (verify_playout_) {
928 EXPECT_TRUE(media_channel1_->playout());
929 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200931 if (verify_playout_) {
932 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
933 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
935
936 // Update |content2| to be SendRecv.
937 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000938 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
939 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940
Peter Boström34fbfff2015-09-24 19:20:30 +0200941 if (verify_playout_) {
942 EXPECT_TRUE(media_channel1_->playout());
943 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200945 if (verify_playout_) {
946 EXPECT_TRUE(media_channel2_->playout());
947 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_TRUE(media_channel2_->sending());
949 }
950
Honghai Zhangcc411c02016-03-29 17:27:21 -0700951 // Tests that when the transport channel signals a candidate pair change
952 // event, the media channel will receive a call on the network route change.
953 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200954 constexpr uint16_t kLocalNetId = 1;
955 constexpr uint16_t kRemoteNetId = 2;
956 constexpr int kLastPacketId = 100;
957
Honghai Zhangcc411c02016-03-29 17:27:21 -0700958 CreateChannels(0, 0);
959
zhihuang6ce92592017-01-19 04:49:47 -0800960 cricket::TransportChannel* transport_channel1 = channel1_->rtp_transport();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200961 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700962 typename T::MediaChannel* media_channel1 =
963 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200964 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700965
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200966 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700967 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200968 // The transport channel becomes disconnected.
zhihuang6ce92592017-01-19 04:49:47 -0800969 transport_channel1->SignalSelectedCandidatePairChanged(
970 transport_channel1, nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200971 });
972 WaitForThreads();
973 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700974 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200975 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700976
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700977 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
978 media_channel1, kLocalNetId,
979 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200980 // The transport channel becomes connected.
981 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
982 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
983 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
984 transport_controller1_->CreateFakeCandidatePair(
985 local_address, kLocalNetId, remote_address, kRemoteNetId));
zhihuang6ce92592017-01-19 04:49:47 -0800986 transport_channel1->SignalSelectedCandidatePairChanged(
987 transport_channel1, candidate_pair.get(), kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200988 });
989 WaitForThreads();
990 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700991 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200992 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700993 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200994 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700995 media_channel1->last_network_route().last_sent_packet_id);
michaelt79e05882016-11-08 02:50:09 -0800996 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
997 EXPECT_EQ(kTransportOverheadPerPacket,
998 media_channel1->transport_overhead_per_packet());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700999 }
1000
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 // Test setting up a call.
1002 void TestCallSetup() {
1003 CreateChannels(0, 0);
1004 EXPECT_FALSE(channel1_->secure());
1005 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +02001006 if (verify_playout_) {
1007 EXPECT_TRUE(media_channel1_->playout());
1008 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 EXPECT_FALSE(media_channel1_->sending());
1010 EXPECT_TRUE(SendAccept());
1011 EXPECT_FALSE(channel1_->secure());
1012 EXPECT_TRUE(media_channel1_->sending());
1013 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +02001014 if (verify_playout_) {
1015 EXPECT_TRUE(media_channel2_->playout());
1016 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 EXPECT_TRUE(media_channel2_->sending());
1018 EXPECT_EQ(1U, media_channel2_->codecs().size());
1019 }
1020
1021 // Test that we don't crash if packets are sent during call teardown
1022 // when RTCP mux is enabled. This is a regression test against a specific
1023 // race condition that would only occur when a RTCP packet was sent during
1024 // teardown of a channel on which RTCP mux was enabled.
1025 void TestCallTeardownRtcpMux() {
1026 class LastWordMediaChannel : public T::MediaChannel {
1027 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001028 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001030 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1031 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1033 }
1034 };
1035 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
deadbeefac22f702017-01-12 21:59:29 -08001036 RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037 EXPECT_TRUE(SendInitiate());
1038 EXPECT_TRUE(SendAccept());
1039 EXPECT_TRUE(SendTerminate());
1040 }
1041
1042 // Send voice RTP data to the other side and ensure it gets there.
1043 void SendRtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001044 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 EXPECT_TRUE(SendInitiate());
1046 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001047 EXPECT_EQ(1U, GetChannels1().size());
1048 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001049 SendRtp1();
1050 SendRtp2();
1051 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 EXPECT_TRUE(CheckRtp1());
1053 EXPECT_TRUE(CheckRtp2());
1054 EXPECT_TRUE(CheckNoRtp1());
1055 EXPECT_TRUE(CheckNoRtp2());
1056 }
1057
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001058 void TestDeinit() {
deadbeefac22f702017-01-12 21:59:29 -08001059 CreateChannels(0, 0);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001060 EXPECT_TRUE(SendInitiate());
1061 EXPECT_TRUE(SendAccept());
1062 SendRtp1();
1063 SendRtp2();
1064 SendRtcp1();
1065 SendRtcp2();
1066 // Do not wait, destroy channels.
1067 channel1_.reset(nullptr);
1068 channel2_.reset(nullptr);
1069 }
1070
deadbeefac22f702017-01-12 21:59:29 -08001071 // Check that RTCP can be transmitted between both sides.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 void SendRtcpToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001073 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 EXPECT_TRUE(SendInitiate());
1075 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001076 EXPECT_EQ(2U, GetChannels1().size());
1077 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001078 SendRtcp1();
1079 SendRtcp2();
1080 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 EXPECT_TRUE(CheckRtcp1());
1082 EXPECT_TRUE(CheckRtcp2());
1083 EXPECT_TRUE(CheckNoRtcp1());
1084 EXPECT_TRUE(CheckNoRtcp2());
1085 }
1086
1087 // Check that RTCP is transmitted if only the initiator supports mux.
1088 void SendRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001089 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 EXPECT_TRUE(SendInitiate());
1091 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001092 EXPECT_EQ(2U, GetChannels1().size());
1093 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001094 SendRtcp1();
1095 SendRtcp2();
1096 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 EXPECT_TRUE(CheckRtcp1());
1098 EXPECT_TRUE(CheckRtcp2());
1099 EXPECT_TRUE(CheckNoRtcp1());
1100 EXPECT_TRUE(CheckNoRtcp2());
1101 }
1102
1103 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1104 void SendRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001105 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001107 EXPECT_EQ(2U, GetChannels1().size());
1108 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001110 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001111 SendRtp1();
1112 SendRtp2();
1113 SendRtcp1();
1114 SendRtcp2();
1115 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116 EXPECT_TRUE(CheckRtp1());
1117 EXPECT_TRUE(CheckRtp2());
1118 EXPECT_TRUE(CheckNoRtp1());
1119 EXPECT_TRUE(CheckNoRtp2());
1120 EXPECT_TRUE(CheckRtcp1());
1121 EXPECT_TRUE(CheckRtcp2());
1122 EXPECT_TRUE(CheckNoRtcp1());
1123 EXPECT_TRUE(CheckNoRtcp2());
1124 }
1125
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001126 // Check that RTP and RTCP are transmitted ok when both sides
1127 // support mux and one the offerer requires mux.
1128 void SendRequireRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001129 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001130 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001131 EXPECT_EQ(1U, GetChannels1().size());
1132 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001133 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001134 SendRtp1();
1135 SendRtp2();
1136 SendRtcp1();
1137 SendRtcp2();
1138 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001139 EXPECT_TRUE(CheckRtp1());
1140 EXPECT_TRUE(CheckRtp2());
1141 EXPECT_TRUE(CheckNoRtp1());
1142 EXPECT_TRUE(CheckNoRtp2());
1143 EXPECT_TRUE(CheckRtcp1());
1144 EXPECT_TRUE(CheckRtcp2());
1145 EXPECT_TRUE(CheckNoRtcp1());
1146 EXPECT_TRUE(CheckNoRtcp2());
1147 }
1148
1149 // Check that RTP and RTCP are transmitted ok when both sides
deadbeefac22f702017-01-12 21:59:29 -08001150 // support mux and only the answerer requires rtcp mux.
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001151 void SendRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001152 CreateChannels(RTCP_MUX, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001153 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001154 EXPECT_EQ(2U, GetChannels1().size());
1155 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001156 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001157 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001158 SendRtp1();
1159 SendRtp2();
1160 SendRtcp1();
1161 SendRtcp2();
1162 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001163 EXPECT_TRUE(CheckRtp1());
1164 EXPECT_TRUE(CheckRtp2());
1165 EXPECT_TRUE(CheckNoRtp1());
1166 EXPECT_TRUE(CheckNoRtp2());
1167 EXPECT_TRUE(CheckRtcp1());
1168 EXPECT_TRUE(CheckRtcp2());
1169 EXPECT_TRUE(CheckNoRtcp1());
1170 EXPECT_TRUE(CheckNoRtcp2());
1171 }
1172
1173 // Check that RTP and RTCP are transmitted ok when both sides
1174 // require mux.
1175 void SendRequireRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001176 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001177 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001178 EXPECT_EQ(1U, GetChannels1().size());
1179 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001180 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001181 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001182 SendRtp1();
1183 SendRtp2();
1184 SendRtcp1();
1185 SendRtcp2();
1186 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001187 EXPECT_TRUE(CheckRtp1());
1188 EXPECT_TRUE(CheckRtp2());
1189 EXPECT_TRUE(CheckNoRtp1());
1190 EXPECT_TRUE(CheckNoRtp2());
1191 EXPECT_TRUE(CheckRtcp1());
1192 EXPECT_TRUE(CheckRtcp2());
1193 EXPECT_TRUE(CheckNoRtcp1());
1194 EXPECT_TRUE(CheckNoRtcp2());
1195 }
1196
1197 // Check that SendAccept fails if the answerer doesn't support mux
1198 // and the offerer requires it.
1199 void SendRequireRtcpMuxToNoRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001200 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, 0);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001201 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001202 EXPECT_EQ(1U, GetChannels1().size());
1203 EXPECT_EQ(2U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001204 EXPECT_FALSE(SendAccept());
1205 }
1206
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207 // Check that RTCP data sent by the initiator before the accept is not muxed.
1208 void SendEarlyRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001209 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001211 EXPECT_EQ(2U, GetChannels1().size());
1212 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213
1214 // RTCP can be sent before the call is accepted, if the transport is ready.
1215 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001216 SendRtcp1();
1217 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001218 EXPECT_TRUE(CheckNoRtp2());
1219 EXPECT_TRUE(CheckRtcp2());
1220
1221 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001222 SendRtcp2();
1223 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001224 EXPECT_TRUE(CheckNoRtp1());
1225 EXPECT_TRUE(CheckRtcp1());
1226
1227 // Complete call setup and ensure everything is still OK.
1228 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001229 EXPECT_EQ(2U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001230 SendRtcp1();
1231 SendRtcp2();
1232 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001233 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 EXPECT_TRUE(CheckRtcp1());
1235 }
1236
1237
1238 // Check that RTCP data is not muxed until both sides have enabled muxing,
1239 // but that we properly demux before we get the accept message, since there
1240 // is a race between RTP data and the jingle accept.
1241 void SendEarlyRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001242 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001243 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001244 EXPECT_EQ(2U, GetChannels1().size());
1245 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246
1247 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1248 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001249 SendRtcp1();
1250 WaitForThreads();
1251 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252
1253 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001254 SendRtcp2();
1255 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 EXPECT_TRUE(CheckNoRtp1());
1257 EXPECT_TRUE(CheckRtcp1());
1258
1259 // Complete call setup and ensure everything is still OK.
1260 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001261 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001262 SendRtcp1();
1263 SendRtcp2();
1264 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266 EXPECT_TRUE(CheckRtcp1());
1267 }
1268
1269 // Test that we properly send SRTP with RTCP in both directions.
1270 // You can pass in DTLS and/or RTCP_MUX as flags.
1271 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
nissec8ee8822017-01-18 07:20:55 -08001272 RTC_CHECK((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1273 RTC_CHECK((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274
deadbeefac22f702017-01-12 21:59:29 -08001275 int flags1 = SECURE | flags1_in;
1276 int flags2 = SECURE | flags2_in;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 bool dtls1 = !!(flags1_in & DTLS);
1278 bool dtls2 = !!(flags2_in & DTLS);
1279 CreateChannels(flags1, flags2);
1280 EXPECT_FALSE(channel1_->secure());
1281 EXPECT_FALSE(channel2_->secure());
1282 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001283 WaitForThreads();
1284 EXPECT_TRUE(channel1_->writable());
1285 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 EXPECT_TRUE(SendAccept());
1287 EXPECT_TRUE(channel1_->secure());
1288 EXPECT_TRUE(channel2_->secure());
1289 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1290 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001291 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1292 // channels.
1293 if (dtls1 && dtls2) {
1294 // A GCM cipher is only used if both channels support GCM ciphers.
1295 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1296 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1297 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1298 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001299 SendRtp1();
1300 SendRtp2();
1301 SendRtcp1();
1302 SendRtcp2();
1303 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 EXPECT_TRUE(CheckRtp1());
1305 EXPECT_TRUE(CheckRtp2());
1306 EXPECT_TRUE(CheckNoRtp1());
1307 EXPECT_TRUE(CheckNoRtp2());
1308 EXPECT_TRUE(CheckRtcp1());
1309 EXPECT_TRUE(CheckRtcp2());
1310 EXPECT_TRUE(CheckNoRtcp1());
1311 EXPECT_TRUE(CheckNoRtcp2());
1312 }
1313
1314 // Test that we properly handling SRTP negotiating down to RTP.
1315 void SendSrtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001316 CreateChannels(SECURE, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 EXPECT_FALSE(channel1_->secure());
1318 EXPECT_FALSE(channel2_->secure());
1319 EXPECT_TRUE(SendInitiate());
1320 EXPECT_TRUE(SendAccept());
1321 EXPECT_FALSE(channel1_->secure());
1322 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001323 SendRtp1();
1324 SendRtp2();
1325 SendRtcp1();
1326 SendRtcp2();
1327 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 EXPECT_TRUE(CheckRtp1());
1329 EXPECT_TRUE(CheckRtp2());
1330 EXPECT_TRUE(CheckNoRtp1());
1331 EXPECT_TRUE(CheckNoRtp2());
1332 EXPECT_TRUE(CheckRtcp1());
1333 EXPECT_TRUE(CheckRtcp2());
1334 EXPECT_TRUE(CheckNoRtcp1());
1335 EXPECT_TRUE(CheckNoRtcp2());
1336 }
1337
1338 // Test that we can send and receive early media when a provisional answer is
1339 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1340 void SendEarlyMediaUsingRtcpMuxSrtp() {
1341 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1342
deadbeefac22f702017-01-12 21:59:29 -08001343 CreateChannels(SSRC_MUX | RTCP_MUX | SECURE,
1344 SSRC_MUX | RTCP_MUX | SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 EXPECT_TRUE(SendOffer());
1346 EXPECT_TRUE(SendProvisionalAnswer());
1347 EXPECT_TRUE(channel1_->secure());
1348 EXPECT_TRUE(channel2_->secure());
deadbeef49f34fd2016-12-06 16:22:06 -08001349 EXPECT_EQ(2U, GetChannels1().size());
1350 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001351 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1352 SendCustomRtcp1(kSsrc1);
1353 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1354 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1357
1358 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001359 SendCustomRtcp2(kSsrc2);
1360 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1361 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1364
1365 // Complete call setup and ensure everything is still OK.
1366 EXPECT_TRUE(SendFinalAnswer());
deadbeef49f34fd2016-12-06 16:22:06 -08001367 EXPECT_EQ(1U, GetChannels1().size());
1368 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 EXPECT_TRUE(channel1_->secure());
1370 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001371 SendCustomRtcp1(kSsrc1);
1372 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1373 SendCustomRtcp2(kSsrc2);
1374 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1375 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1380 }
1381
1382 // Test that we properly send RTP without SRTP from a thread.
1383 void SendRtpToRtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001384 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 EXPECT_TRUE(SendInitiate());
1386 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001387 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1388 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1389 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1390 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1391 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1392 send_rtcp1.thread(),
1393 send_rtcp2.thread()};
1394 WaitForThreads(involved_threads);
1395 EXPECT_TRUE(CheckRtp1());
1396 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 EXPECT_TRUE(CheckNoRtp1());
1398 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001399 EXPECT_TRUE(CheckRtcp1());
1400 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 EXPECT_TRUE(CheckNoRtcp1());
1402 EXPECT_TRUE(CheckNoRtcp2());
1403 }
1404
1405 // Test that we properly send SRTP with RTCP from a thread.
1406 void SendSrtpToSrtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001407 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 EXPECT_TRUE(SendInitiate());
1409 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001410 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1411 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1412 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1413 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1414 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1415 send_rtcp1.thread(),
1416 send_rtcp2.thread()};
1417 WaitForThreads(involved_threads);
1418 EXPECT_TRUE(CheckRtp1());
1419 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 EXPECT_TRUE(CheckNoRtp1());
1421 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001422 EXPECT_TRUE(CheckRtcp1());
1423 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_TRUE(CheckNoRtcp1());
1425 EXPECT_TRUE(CheckNoRtcp2());
1426 }
1427
1428 // Test that the mediachannel retains its sending state after the transport
1429 // becomes non-writable.
1430 void SendWithWritabilityLoss() {
deadbeefac22f702017-01-12 21:59:29 -08001431 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 EXPECT_TRUE(SendInitiate());
1433 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001434 EXPECT_EQ(1U, GetChannels1().size());
1435 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001436 SendRtp1();
1437 SendRtp2();
1438 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 EXPECT_TRUE(CheckRtp1());
1440 EXPECT_TRUE(CheckRtp2());
1441 EXPECT_TRUE(CheckNoRtp1());
1442 EXPECT_TRUE(CheckNoRtp2());
1443
wu@webrtc.org97077a32013-10-25 21:18:33 +00001444 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001445 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001446 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001447 SendRtp1();
1448 SendRtp2();
1449 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 EXPECT_TRUE(CheckRtp1());
1451 EXPECT_TRUE(CheckNoRtp2());
1452
1453 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001454 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001455 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001457 SendRtp1();
1458 SendRtp2();
1459 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001460 EXPECT_TRUE(CheckRtp1());
1461 EXPECT_TRUE(CheckRtp2());
1462 EXPECT_TRUE(CheckNoRtp1());
1463 EXPECT_TRUE(CheckNoRtp2());
1464
1465 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001466 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001467 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetDestination(nullptr); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 EXPECT_TRUE(media_channel1_->sending());
1469
wu@webrtc.org97077a32013-10-25 21:18:33 +00001470 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001471 SendRtp1();
1472 SendRtp2();
1473 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 EXPECT_TRUE(CheckRtp1());
1475 EXPECT_TRUE(CheckNoRtp2());
1476
1477 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001478 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeef49f34fd2016-12-06 16:22:06 -08001479 GetFakeChannel1(1)->SetDestination(GetFakeChannel2(1));
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001480 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001482 SendRtp1();
1483 SendRtp2();
1484 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485 EXPECT_TRUE(CheckRtp1());
1486 EXPECT_TRUE(CheckRtp2());
1487 EXPECT_TRUE(CheckNoRtp1());
1488 EXPECT_TRUE(CheckNoRtp2());
1489 }
1490
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001491 void SendBundleToBundle(
1492 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1493 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001495 // Only pl_type1 was added to the bundle filter for both |channel1_|
1496 // and |channel2_|.
1497 int pl_type1 = pl_types[0];
1498 int pl_type2 = pl_types[1];
deadbeefac22f702017-01-12 21:59:29 -08001499 int flags = SSRC_MUX;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001500 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001501 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001502 if (rtcp_mux) {
1503 flags |= RTCP_MUX;
1504 expected_channels = 1U;
1505 }
1506 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001508 EXPECT_EQ(2U, GetChannels1().size());
1509 EXPECT_EQ(expected_channels, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001511 EXPECT_EQ(expected_channels, GetChannels1().size());
1512 EXPECT_EQ(expected_channels, GetChannels2().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001513 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1514 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1515 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1516 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001517
1518 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001519 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1520 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1521 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001522 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001523 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1524 EXPECT_TRUE(CheckNoRtp1());
1525 EXPECT_TRUE(CheckNoRtp2());
1526
1527 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001528 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1529 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1530 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001531 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001532 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1533
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001534 SendCustomRtcp1(kSsrc1);
1535 SendCustomRtcp2(kSsrc2);
1536 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1538 EXPECT_TRUE(CheckNoRtcp1());
1539 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1540 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001542 SendCustomRtcp1(kSsrc2);
1543 SendCustomRtcp2(kSsrc1);
1544 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001545 // Bundle filter shouldn't filter out any RTCP.
1546 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1547 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 }
1549
deadbeefc6b6e092016-12-01 12:49:20 -08001550 // Test that the media monitor can be run and gives callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 void TestMediaMonitor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 CreateChannels(0, 0);
1553 EXPECT_TRUE(SendInitiate());
1554 EXPECT_TRUE(SendAccept());
1555 channel1_->StartMediaMonitor(100);
1556 channel2_->StartMediaMonitor(100);
1557 // Ensure we get callbacks and stop.
deadbeefc6b6e092016-12-01 12:49:20 -08001558 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
1559 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 channel1_->StopMediaMonitor();
1561 channel2_->StopMediaMonitor();
1562 // Ensure a restart of a stopped monitor works.
1563 channel1_->StartMediaMonitor(100);
deadbeefc6b6e092016-12-01 12:49:20 -08001564 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 channel1_->StopMediaMonitor();
1566 // Ensure stopping a stopped monitor is OK.
1567 channel1_->StopMediaMonitor();
1568 }
1569
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 void TestSetContentFailure() {
1571 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572
Peter Thatchera6d24442015-07-09 21:26:36 -07001573 auto sdesc = cricket::SessionDescription();
1574 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1575 new cricket::AudioContentDescription());
1576 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1577 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578
Peter Thatchera6d24442015-07-09 21:26:36 -07001579 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001581 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1582 &sdesc, cricket::CA_OFFER, &err));
1583 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1584 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001587 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1588 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001590 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1591 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 }
1593
1594 void TestSendTwoOffers() {
1595 CreateChannels(0, 0);
1596
Peter Thatchera6d24442015-07-09 21:26:36 -07001597 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001598 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001599 CreateSessionDescriptionWithStream(1));
1600 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1601 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1603
kwiberg31022942016-03-11 14:18:21 -08001604 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001605 CreateSessionDescriptionWithStream(2));
1606 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1607 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1609 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1610 }
1611
1612 void TestReceiveTwoOffers() {
1613 CreateChannels(0, 0);
1614
Peter Thatchera6d24442015-07-09 21:26:36 -07001615 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001616 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001617 CreateSessionDescriptionWithStream(1));
1618 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1619 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1621
kwiberg31022942016-03-11 14:18:21 -08001622 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001623 CreateSessionDescriptionWithStream(2));
1624 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1625 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1627 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1628 }
1629
1630 void TestSendPrAnswer() {
1631 CreateChannels(0, 0);
1632
Peter Thatchera6d24442015-07-09 21:26:36 -07001633 std::string err;
1634 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001635 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001636 CreateSessionDescriptionWithStream(1));
1637 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1638 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1640
Peter Thatchera6d24442015-07-09 21:26:36 -07001641 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001642 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001643 CreateSessionDescriptionWithStream(2));
1644 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1645 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1647 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1648
Peter Thatchera6d24442015-07-09 21:26:36 -07001649 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001650 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001651 CreateSessionDescriptionWithStream(3));
1652 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1653 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1655 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1656 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1657 }
1658
1659 void TestReceivePrAnswer() {
1660 CreateChannels(0, 0);
1661
Peter Thatchera6d24442015-07-09 21:26:36 -07001662 std::string err;
1663 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001664 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001665 CreateSessionDescriptionWithStream(1));
1666 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1667 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1669
Peter Thatchera6d24442015-07-09 21:26:36 -07001670 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001671 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001672 CreateSessionDescriptionWithStream(2));
1673 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1674 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1676 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1677
Peter Thatchera6d24442015-07-09 21:26:36 -07001678 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001679 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001680 CreateSessionDescriptionWithStream(3));
1681 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1682 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1684 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1685 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1686 }
1687
1688 void TestFlushRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001689 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 EXPECT_TRUE(SendInitiate());
1691 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001692 EXPECT_EQ(2U, GetChannels1().size());
1693 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694
1695 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001696 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 // The sending message is only posted. channel2_ should be empty.
1698 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001699 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1700 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701
1702 // When channel1_ is deleted, the RTCP packet should be sent out to
1703 // channel2_.
1704 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001705 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 EXPECT_TRUE(CheckRtcp2());
1707 }
1708
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001709 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001710 struct SrtpErrorHandler : public sigslot::has_slots<> {
1711 SrtpErrorHandler() :
1712 mode_(cricket::SrtpFilter::UNPROTECT),
1713 error_(cricket::SrtpFilter::ERROR_NONE) {}
1714 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1715 cricket::SrtpFilter::Error error) {
1716 mode_ = mode;
1717 error_ = error;
1718 }
1719 cricket::SrtpFilter::Mode mode_;
1720 cricket::SrtpFilter::Error error_;
1721 } error_handler;
1722
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001723 // For Audio, only pl_type 0 is added to the bundle filter.
1724 // For Video, only pl_type 97 is added to the bundle filter.
1725 // So we need to pass in pl_type so that the packet can pass through
1726 // the bundle filter before it can be processed by the srtp filter.
1727 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001728 static unsigned const char kBadPacket[] = {
1729 0x84, static_cast<unsigned char>(pl_type),
1730 0x00, 0x01,
1731 0x00, 0x00,
1732 0x00, 0x00,
1733 0x00, 0x00,
1734 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001735
1736 // Using fake clock because this tests that SRTP errors are signaled at
1737 // specific times based on set_signal_silent_time.
1738 rtc::ScopedFakeClock fake_clock;
1739 // Some code uses a time of 0 as a special value, so we must start with
1740 // a non-zero time.
1741 // TODO(deadbeef): Fix this.
1742 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1743
deadbeefac22f702017-01-12 21:59:29 -08001744 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 EXPECT_FALSE(channel1_->secure());
1746 EXPECT_FALSE(channel2_->secure());
1747 EXPECT_TRUE(SendInitiate());
1748 EXPECT_TRUE(SendAccept());
1749 EXPECT_TRUE(channel1_->secure());
1750 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001751 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001752 channel2_->srtp_filter()->SignalSrtpError.connect(
1753 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754
1755 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001756 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1757 rtc::PacketOptions());
1758 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001760 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001761 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1762 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001763 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1764 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001765 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1766 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001768 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001769 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001770 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001771 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1772 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001773 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001774 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1775 rtc::PacketOptions());
1776 WaitForThreads();
1777 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001778 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779
1780 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001781 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001782 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001783
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001784 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
zhihuang6ce92592017-01-19 04:49:47 -08001785 cricket::TransportChannel* transport_channel = channel2_->rtp_transport();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001786 transport_channel->SignalReadPacket(
1787 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1788 sizeof(kBadPacket), rtc::PacketTime(), 0);
1789 });
1790 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001791 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001792 // Terminate channels before the fake clock is destroyed.
1793 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 }
1795
1796 void TestOnReadyToSend() {
deadbeefac22f702017-01-12 21:59:29 -08001797 CreateChannels(0, 0);
zhihuang6ce92592017-01-19 04:49:47 -08001798 TransportChannel* rtp = channel1_->rtp_transport();
1799 TransportChannel* rtcp = channel1_->rtcp_transport();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001801
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001802 network_thread_->Invoke<void>(RTC_FROM_HERE,
1803 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001804 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001806
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001807 network_thread_->Invoke<void>(RTC_FROM_HERE,
1808 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001809 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1811 // channel are ready to send.
1812 EXPECT_TRUE(media_channel1_->ready_to_send());
1813
1814 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001815 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1816 channel1_->SetTransportChannelReadyToSend(false, false);
1817 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001818 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001820
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001821 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1822 channel1_->SetTransportChannelReadyToSend(false, true);
1823 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001824 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 EXPECT_TRUE(media_channel1_->ready_to_send());
1826
1827 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001828 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1829 channel1_->SetTransportChannelReadyToSend(true, false);
1830 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001831 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001833
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001834 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1835 channel1_->SetTransportChannelReadyToSend(true, true);
1836 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001837 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 EXPECT_TRUE(media_channel1_->ready_to_send());
1839 }
1840
1841 void TestOnReadyToSendWithRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001842 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843 typename T::Content content;
1844 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1845 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1846 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001847 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1848 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuang6ce92592017-01-19 04:49:47 -08001849 EXPECT_TRUE(channel1_->rtcp_transport() == NULL);
1850 TransportChannel* rtp = channel1_->rtp_transport();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 EXPECT_FALSE(media_channel1_->ready_to_send());
1852 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1853 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001854 network_thread_->Invoke<void>(RTC_FROM_HERE,
1855 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001856 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001858
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001859 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1860 channel1_->SetTransportChannelReadyToSend(false, false);
1861 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001862 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 EXPECT_FALSE(media_channel1_->ready_to_send());
1864 }
1865
skvladdc1c62c2016-03-16 19:07:43 -07001866 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1867 typename T::Content content;
1868 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1869 content.set_bandwidth(remote_limit);
1870 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1871 }
1872
1873 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1874 webrtc::RtpParameters parameters;
1875 webrtc::RtpEncodingParameters encoding;
1876 encoding.max_bitrate_bps = limit;
1877 parameters.encodings.push_back(encoding);
1878 return parameters;
1879 }
1880
1881 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1882 int expected_bitrate) {
1883 EXPECT_EQ(1UL, parameters.encodings.size());
1884 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1885 }
1886
1887 void DefaultMaxBitrateIsUnlimited() {
1888 CreateChannels(0, 0);
1889 EXPECT_TRUE(
1890 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1891 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001892 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001893 }
1894
1895 void CanChangeMaxBitrate() {
1896 CreateChannels(0, 0);
1897 EXPECT_TRUE(
1898 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1899
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001900 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1901 kSsrc1, BitrateLimitedParameters(1000)));
1902 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1903 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001904 EXPECT_EQ(-1, media_channel1_->max_bps());
1905
1906 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001907 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1908 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1909 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001910 EXPECT_EQ(-1, media_channel1_->max_bps());
1911 }
1912
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001914 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1915 static void ProcessThreadQueue(rtc::Thread* thread) {
1916 RTC_DCHECK(thread->IsCurrent());
1917 while (!thread->empty()) {
1918 thread->ProcessMessages(0);
1919 }
1920 }
1921 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1922 // |threads| and current thread post packets to network thread.
1923 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001924 thread->Invoke<void>(RTC_FROM_HERE,
1925 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001926 }
1927 ProcessThreadQueue(rtc::Thread::Current());
1928 // Network thread move them around and post back to worker = current thread.
1929 if (!network_thread_->IsCurrent()) {
1930 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001931 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001932 }
1933 // Worker thread = current Thread process received messages.
1934 ProcessThreadQueue(rtc::Thread::Current());
1935 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001936 // TODO(pbos): Remove playout from all media channels and let renderers mute
1937 // themselves.
1938 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001939 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1940 rtc::Thread* network_thread_;
1941 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1942 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 cricket::FakeMediaEngine media_engine_;
1944 // The media channels are owned by the voice channel objects below.
1945 typename T::MediaChannel* media_channel1_;
1946 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001947 std::unique_ptr<typename T::Channel> channel1_;
1948 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949 typename T::Content local_media_content1_;
1950 typename T::Content local_media_content2_;
1951 typename T::Content remote_media_content1_;
1952 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001954 rtc::Buffer rtp_packet_;
1955 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 int media_info_callbacks1_;
1957 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001958 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959};
1960
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961template<>
1962void ChannelTest<VoiceTraits>::CreateContent(
1963 int flags,
1964 const cricket::AudioCodec& audio_codec,
1965 const cricket::VideoCodec& video_codec,
1966 cricket::AudioContentDescription* audio) {
1967 audio->AddCodec(audio_codec);
1968 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1969 if (flags & SECURE) {
1970 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001971 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1972 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 }
1974}
1975
1976template<>
1977void ChannelTest<VoiceTraits>::CopyContent(
1978 const cricket::AudioContentDescription& source,
1979 cricket::AudioContentDescription* audio) {
1980 *audio = source;
1981}
1982
1983template<>
1984bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1985 const cricket::AudioCodec& c2) {
1986 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1987 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1988}
1989
Peter Boström0c4e06b2015-10-07 12:23:21 +02001990template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001991void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001992 uint32_t ssrc,
1993 int flags,
1994 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 audio->AddLegacyStream(ssrc);
1996}
1997
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001998class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 public:
solenberg1dd98f32015-09-10 01:57:14 -07002000 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002001 VoiceChannelSingleThreadTest()
2002 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2003};
2004
2005class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2006 public:
2007 typedef ChannelTest<VoiceTraits> Base;
2008 VoiceChannelDoubleThreadTest()
2009 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010};
2011
2012// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002013template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002015 rtc::Thread* worker_thread,
2016 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002017 cricket::MediaEngineInterface* engine,
2018 cricket::FakeVideoMediaChannel* ch,
2019 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002020 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -08002021 rtc::Thread* signaling_thread =
2022 transport_controller ? transport_controller->signaling_thread() : nullptr;
deadbeef7af91dd2016-12-13 11:29:11 -08002023 cricket::VideoChannel* channel = new cricket::VideoChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08002024 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO,
deadbeefac22f702017-01-12 21:59:29 -08002025 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07002026 rtc::CryptoOptions crypto_options;
2027 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2028 channel->SetCryptoOptions(crypto_options);
zhihuang6ce92592017-01-19 04:49:47 -08002029 cricket::TransportChannel* rtp_transport =
2030 transport_controller->CreateTransportChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08002031 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuang6ce92592017-01-19 04:49:47 -08002032 cricket::TransportChannel* rtcp_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08002033 if (channel->NeedsRtcpTransport()) {
zhihuang6ce92592017-01-19 04:49:47 -08002034 rtcp_transport = transport_controller->CreateTransportChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08002035 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
2036 }
zhihuang6ce92592017-01-19 04:49:47 -08002037 if (!channel->Init_w(rtp_transport, rtcp_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 delete channel;
2039 channel = NULL;
2040 }
2041 return channel;
2042}
2043
2044// override to add 0 parameter
2045template<>
2046bool ChannelTest<VideoTraits>::AddStream1(int id) {
2047 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2048}
2049
2050template<>
2051void ChannelTest<VideoTraits>::CreateContent(
2052 int flags,
2053 const cricket::AudioCodec& audio_codec,
2054 const cricket::VideoCodec& video_codec,
2055 cricket::VideoContentDescription* video) {
2056 video->AddCodec(video_codec);
2057 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2058 if (flags & SECURE) {
2059 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002060 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2061 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 }
2063}
2064
2065template<>
2066void ChannelTest<VideoTraits>::CopyContent(
2067 const cricket::VideoContentDescription& source,
2068 cricket::VideoContentDescription* video) {
2069 *video = source;
2070}
2071
2072template<>
2073bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2074 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002075 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076}
2077
Peter Boström0c4e06b2015-10-07 12:23:21 +02002078template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002080 uint32_t ssrc,
2081 int flags,
2082 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 video->AddLegacyStream(ssrc);
2084}
2085
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002086class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 public:
solenberg1dd98f32015-09-10 01:57:14 -07002088 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002089 VideoChannelSingleThreadTest()
2090 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091};
2092
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002093class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2094 public:
2095 typedef ChannelTest<VideoTraits> Base;
2096 VideoChannelDoubleThreadTest()
2097 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2098};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002100// VoiceChannelSingleThreadTest
2101TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 Base::TestInit();
2103 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2104 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2105}
2106
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002107TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2108 Base::TestDeinit();
2109}
2110
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002111TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 Base::TestSetContents();
2113}
2114
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002115TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 Base::TestSetContentsNullOffer();
2117}
2118
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002119TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 Base::TestSetContentsRtcpMux();
2121}
2122
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002123TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 Base::TestSetContentsRtcpMux();
2125}
2126
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002127TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 Base::TestSetRemoteContentUpdate();
2129}
2130
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002131TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 Base::TestStreams();
2133}
2134
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002135TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 Base::TestUpdateStreamsInLocalContent();
2137}
2138
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002139TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 Base::TestUpdateStreamsInRemoteContent();
2141}
2142
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002143TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 Base::TestChangeStreamParamsInContent();
2145}
2146
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002147TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 Base::TestPlayoutAndSendingStates();
2149}
2150
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002151TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002152 CreateChannels(0, 0);
2153 // Test that we can Mute the default channel even though the sending SSRC
2154 // is unknown.
2155 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002156 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002157 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2158 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002159 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2160
2161 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002162 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002163
2164 SendInitiate();
2165 // After the local session description has been set, we can mute a stream
2166 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002167 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002168 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2169 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002170 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171}
2172
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002173TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 Base::TestMediaContentDirection();
2175}
2176
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002177TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002178 Base::TestNetworkRouteChanges();
2179}
2180
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002181TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182 Base::TestCallSetup();
2183}
2184
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002185TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 Base::TestCallTeardownRtcpMux();
2187}
2188
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002189TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 Base::SendRtpToRtp();
2191}
2192
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002193TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 Base::SendRtcpToRtcp();
2195}
2196
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002197TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198 Base::SendRtcpMuxToRtcp();
2199}
2200
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002201TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202 Base::SendRtcpMuxToRtcpMux();
2203}
2204
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002205TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002206 Base::SendRequireRtcpMuxToRtcpMux();
2207}
2208
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002209TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002210 Base::SendRtcpMuxToRequireRtcpMux();
2211}
2212
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002213TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002214 Base::SendRequireRtcpMuxToRequireRtcpMux();
2215}
2216
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002217TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002218 Base::SendRequireRtcpMuxToNoRtcpMux();
2219}
2220
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002221TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222 Base::SendEarlyRtcpMuxToRtcp();
2223}
2224
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002225TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 Base::SendEarlyRtcpMuxToRtcpMux();
2227}
2228
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002229TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2231}
2232
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002233TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 Base::SendSrtpToSrtp();
2235}
2236
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002237TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2239}
2240
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002241TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2243 Base::SendSrtpToSrtp(DTLS, 0);
2244}
2245
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002246TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2248 Base::SendSrtpToSrtp(DTLS, DTLS);
2249}
2250
jbauchcb560652016-08-04 05:20:32 -07002251TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2252 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2253 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2254}
2255
2256TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2257 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2258 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2259}
2260
2261TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2262 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2263 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2264}
2265
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002266TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2268 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2269}
2270
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002271TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2273}
2274
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002275TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 Base::SendRtpToRtpOnThread();
2277}
2278
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002279TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 Base::SendSrtpToSrtpOnThread();
2281}
2282
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002283TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 Base::SendWithWritabilityLoss();
2285}
2286
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002287TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 Base::TestMediaMonitor();
2289}
2290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002292TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293 CreateChannels(0, 0);
2294 EXPECT_TRUE(SendInitiate());
2295 EXPECT_TRUE(SendAccept());
2296 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2297
solenberg1d63dd02015-12-02 12:35:09 -08002298 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2299 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2300 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002302 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002304 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002305 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002306 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002307 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002308 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309}
2310
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002311TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 Base::TestSetContentFailure();
2313}
2314
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002315TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 Base::TestSendTwoOffers();
2317}
2318
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002319TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 Base::TestReceiveTwoOffers();
2321}
2322
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002323TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 Base::TestSendPrAnswer();
2325}
2326
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002327TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 Base::TestReceivePrAnswer();
2329}
2330
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002331TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 Base::TestFlushRtcp();
2333}
2334
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002335TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002336 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337}
2338
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002339TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 Base::TestOnReadyToSend();
2341}
2342
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002343TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 Base::TestOnReadyToSendWithRtcpMux();
2345}
2346
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002348TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002349 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 EXPECT_TRUE(SendInitiate());
2351 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002352 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353
solenberg4bac9c52015-10-09 02:32:53 -07002354 // Default is (1.0).
2355 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2356 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002358 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359
solenberg4bac9c52015-10-09 02:32:53 -07002360 // Set scale to (1.5).
2361 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2362 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2363 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364
solenberg4bac9c52015-10-09 02:32:53 -07002365 // Set scale to (0).
2366 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2367 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2368 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369}
2370
2371// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002372TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002373 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374 EXPECT_TRUE(SendInitiate());
2375 EXPECT_TRUE(SendAccept());
2376 EXPECT_TRUE(AddStream1(1));
2377 EXPECT_TRUE(AddStream1(2));
2378
solenberg4bac9c52015-10-09 02:32:53 -07002379 double volume;
2380 // Default is (1.0).
2381 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2382 EXPECT_DOUBLE_EQ(1.0, volume);
2383 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2384 EXPECT_DOUBLE_EQ(1.0, volume);
2385 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2386 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002388 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389
solenberg4bac9c52015-10-09 02:32:53 -07002390 // Set scale to (1.5) for ssrc = 1.
2391 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2392 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2393 EXPECT_DOUBLE_EQ(1.5, volume);
2394 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2395 EXPECT_DOUBLE_EQ(1.0, volume);
2396 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2397 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398
solenberg4bac9c52015-10-09 02:32:53 -07002399 // Set scale to (0) for all ssrcs.
2400 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2401 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2402 EXPECT_DOUBLE_EQ(0.0, volume);
2403 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2404 EXPECT_DOUBLE_EQ(0.0, volume);
2405 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2406 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407}
2408
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002409TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002410 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411}
2412
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002413TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002414 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002415}
2416
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002417TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002418 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002419}
2420
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002421TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002422 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423}
2424
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002425TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002426 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002427}
2428
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002429TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002430 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002431}
2432
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002433// VoiceChannelDoubleThreadTest
2434TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002436 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2437 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438}
2439
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002440TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2441 Base::TestDeinit();
2442}
2443
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002444TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 Base::TestSetContents();
2446}
2447
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002448TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 Base::TestSetContentsNullOffer();
2450}
2451
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002452TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 Base::TestSetContentsRtcpMux();
2454}
2455
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002456TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457 Base::TestSetContentsRtcpMux();
2458}
2459
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002460TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461 Base::TestSetRemoteContentUpdate();
2462}
2463
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002464TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 Base::TestStreams();
2466}
2467
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002468TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 Base::TestUpdateStreamsInLocalContent();
2470}
2471
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002472TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473 Base::TestUpdateStreamsInRemoteContent();
2474}
2475
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002476TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 Base::TestChangeStreamParamsInContent();
2478}
2479
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002480TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 Base::TestPlayoutAndSendingStates();
2482}
2483
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002484TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2485 CreateChannels(0, 0);
2486 // Test that we can Mute the default channel even though the sending SSRC
2487 // is unknown.
2488 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2489 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2490 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2491 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2492 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2493
2494 // Test that we can not mute an unknown SSRC.
2495 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2496
2497 SendInitiate();
2498 // After the local session description has been set, we can mute a stream
2499 // with its SSRC.
2500 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2501 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2502 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2503 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2504}
2505
2506TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2507 Base::TestMediaContentDirection();
2508}
2509
2510TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2511 Base::TestNetworkRouteChanges();
2512}
2513
2514TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2515 Base::TestCallSetup();
2516}
2517
2518TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2519 Base::TestCallTeardownRtcpMux();
2520}
2521
2522TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2523 Base::SendRtpToRtp();
2524}
2525
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002526TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2527 Base::SendRtcpToRtcp();
2528}
2529
2530TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2531 Base::SendRtcpMuxToRtcp();
2532}
2533
2534TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2535 Base::SendRtcpMuxToRtcpMux();
2536}
2537
2538TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2539 Base::SendRequireRtcpMuxToRtcpMux();
2540}
2541
2542TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2543 Base::SendRtcpMuxToRequireRtcpMux();
2544}
2545
2546TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2547 Base::SendRequireRtcpMuxToRequireRtcpMux();
2548}
2549
2550TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2551 Base::SendRequireRtcpMuxToNoRtcpMux();
2552}
2553
2554TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2555 Base::SendEarlyRtcpMuxToRtcp();
2556}
2557
2558TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2559 Base::SendEarlyRtcpMuxToRtcpMux();
2560}
2561
2562TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2563 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2564}
2565
2566TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2567 Base::SendSrtpToSrtp();
2568}
2569
2570TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2571 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2572}
2573
2574TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2575 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2576 Base::SendSrtpToSrtp(DTLS, 0);
2577}
2578
2579TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2580 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2581 Base::SendSrtpToSrtp(DTLS, DTLS);
2582}
2583
jbauchcb560652016-08-04 05:20:32 -07002584TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2585 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2586 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2587}
2588
2589TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2590 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2591 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2592}
2593
2594TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2595 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2596 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2597}
2598
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002599TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2600 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2601 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2602}
2603
2604TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2605 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2606}
2607
2608TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2609 Base::SendRtpToRtpOnThread();
2610}
2611
2612TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2613 Base::SendSrtpToSrtpOnThread();
2614}
2615
2616TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2617 Base::SendWithWritabilityLoss();
2618}
2619
2620TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2621 Base::TestMediaMonitor();
2622}
2623
2624// Test that InsertDtmf properly forwards to the media channel.
2625TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2626 CreateChannels(0, 0);
2627 EXPECT_TRUE(SendInitiate());
2628 EXPECT_TRUE(SendAccept());
2629 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2630
2631 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2632 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2633 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2634
2635 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2636 EXPECT_TRUE(
2637 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2638 EXPECT_TRUE(
2639 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2640 EXPECT_TRUE(
2641 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2642}
2643
2644TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2645 Base::TestSetContentFailure();
2646}
2647
2648TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2649 Base::TestSendTwoOffers();
2650}
2651
2652TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2653 Base::TestReceiveTwoOffers();
2654}
2655
2656TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2657 Base::TestSendPrAnswer();
2658}
2659
2660TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2661 Base::TestReceivePrAnswer();
2662}
2663
2664TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2665 Base::TestFlushRtcp();
2666}
2667
2668TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2669 Base::TestSrtpError(kAudioPts[0]);
2670}
2671
2672TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2673 Base::TestOnReadyToSend();
2674}
2675
2676TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2677 Base::TestOnReadyToSendWithRtcpMux();
2678}
2679
2680// Test that we can scale the output volume properly for 1:1 calls.
2681TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002682 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002683 EXPECT_TRUE(SendInitiate());
2684 EXPECT_TRUE(SendAccept());
2685 double volume;
2686
2687 // Default is (1.0).
2688 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2689 EXPECT_DOUBLE_EQ(1.0, volume);
2690 // invalid ssrc.
2691 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2692
2693 // Set scale to (1.5).
2694 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2695 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2696 EXPECT_DOUBLE_EQ(1.5, volume);
2697
2698 // Set scale to (0).
2699 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2700 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2701 EXPECT_DOUBLE_EQ(0.0, volume);
2702}
2703
2704// Test that we can scale the output volume properly for multiway calls.
2705TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002706 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002707 EXPECT_TRUE(SendInitiate());
2708 EXPECT_TRUE(SendAccept());
2709 EXPECT_TRUE(AddStream1(1));
2710 EXPECT_TRUE(AddStream1(2));
2711
2712 double volume;
2713 // Default is (1.0).
2714 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2715 EXPECT_DOUBLE_EQ(1.0, volume);
2716 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2717 EXPECT_DOUBLE_EQ(1.0, volume);
2718 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2719 EXPECT_DOUBLE_EQ(1.0, volume);
2720 // invalid ssrc.
2721 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2722
2723 // Set scale to (1.5) for ssrc = 1.
2724 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2725 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2726 EXPECT_DOUBLE_EQ(1.5, volume);
2727 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2728 EXPECT_DOUBLE_EQ(1.0, volume);
2729 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2730 EXPECT_DOUBLE_EQ(1.0, volume);
2731
2732 // Set scale to (0) for all ssrcs.
2733 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2734 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2735 EXPECT_DOUBLE_EQ(0.0, volume);
2736 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2737 EXPECT_DOUBLE_EQ(0.0, volume);
2738 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2739 EXPECT_DOUBLE_EQ(0.0, volume);
2740}
2741
2742TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2743 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2744}
2745
2746TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2747 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2748}
2749
2750TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2751 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2752}
2753
2754TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2755 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2756}
2757
2758TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2759 Base::DefaultMaxBitrateIsUnlimited();
2760}
2761
2762TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2763 Base::CanChangeMaxBitrate();
2764}
2765
2766// VideoChannelSingleThreadTest
2767TEST_F(VideoChannelSingleThreadTest, TestInit) {
2768 Base::TestInit();
2769}
2770
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002771TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2772 Base::TestDeinit();
2773}
2774
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002775TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2776 Base::TestSetContents();
2777}
2778
2779TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2780 Base::TestSetContentsNullOffer();
2781}
2782
2783TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2784 Base::TestSetContentsRtcpMux();
2785}
2786
2787TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2788 Base::TestSetContentsRtcpMux();
2789}
2790
2791TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2792 Base::TestSetRemoteContentUpdate();
2793}
2794
2795TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2796 Base::TestStreams();
2797}
2798
2799TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2800 Base::TestUpdateStreamsInLocalContent();
2801}
2802
2803TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2804 Base::TestUpdateStreamsInRemoteContent();
2805}
2806
2807TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2808 Base::TestChangeStreamParamsInContent();
2809}
2810
2811TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2812 Base::TestPlayoutAndSendingStates();
2813}
2814
2815TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002816 CreateChannels(0, 0);
2817 // Test that we can Mute the default channel even though the sending SSRC
2818 // is unknown.
2819 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002820 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002821 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002822 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002823 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2824 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002825 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002826 SendInitiate();
2827 // After the local session description has been set, we can mute a stream
2828 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002829 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002830 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002831 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002832 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833}
2834
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002835TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002836 Base::TestMediaContentDirection();
2837}
2838
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002839TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002840 Base::TestNetworkRouteChanges();
2841}
2842
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002843TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002844 Base::TestCallSetup();
2845}
2846
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002847TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002848 Base::TestCallTeardownRtcpMux();
2849}
2850
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002851TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852 Base::SendRtpToRtp();
2853}
2854
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002855TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 Base::SendRtcpToRtcp();
2857}
2858
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002859TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002860 Base::SendRtcpMuxToRtcp();
2861}
2862
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002863TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864 Base::SendRtcpMuxToRtcpMux();
2865}
2866
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002867TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002868 Base::SendRequireRtcpMuxToRtcpMux();
2869}
2870
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002871TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002872 Base::SendRtcpMuxToRequireRtcpMux();
2873}
2874
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002875TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002876 Base::SendRequireRtcpMuxToRequireRtcpMux();
2877}
2878
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002879TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002880 Base::SendRequireRtcpMuxToNoRtcpMux();
2881}
2882
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002883TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002884 Base::SendEarlyRtcpMuxToRtcp();
2885}
2886
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002887TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002888 Base::SendEarlyRtcpMuxToRtcpMux();
2889}
2890
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002891TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 Base::SendSrtpToSrtp();
2893}
2894
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002895TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 Base::SendSrtpToSrtp();
2897}
2898
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002899TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002900 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2901 Base::SendSrtpToSrtp(DTLS, 0);
2902}
2903
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002904TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002905 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2906 Base::SendSrtpToSrtp(DTLS, DTLS);
2907}
2908
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002909TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2911 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2912}
2913
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002914TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2916}
2917
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002918TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2920}
2921
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002922TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923 Base::SendRtpToRtpOnThread();
2924}
2925
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002926TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002927 Base::SendSrtpToSrtpOnThread();
2928}
2929
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002930TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931 Base::SendWithWritabilityLoss();
2932}
2933
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002934TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002935 Base::TestMediaMonitor();
2936}
2937
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002938TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939 Base::TestSetContentFailure();
2940}
2941
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002942TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002943 Base::TestSendTwoOffers();
2944}
2945
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002946TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947 Base::TestReceiveTwoOffers();
2948}
2949
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002950TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002951 Base::TestSendPrAnswer();
2952}
2953
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002954TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955 Base::TestReceivePrAnswer();
2956}
2957
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002958TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002959 Base::TestFlushRtcp();
2960}
2961
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002962TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002963 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964}
2965
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002966TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002967 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002968}
2969
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002970TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002971 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002972}
2973
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002974TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002975 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976}
2977
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002978TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002979 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002980}
2981
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002982TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983 Base::TestOnReadyToSend();
2984}
2985
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002986TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002987 Base::TestOnReadyToSendWithRtcpMux();
2988}
2989
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002990TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07002991 Base::DefaultMaxBitrateIsUnlimited();
2992}
2993
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002994TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07002995 Base::CanChangeMaxBitrate();
2996}
2997
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002998// VideoChannelDoubleThreadTest
2999TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3000 Base::TestInit();
3001}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003003TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3004 Base::TestDeinit();
3005}
3006
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003007TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3008 Base::TestSetContents();
3009}
3010
3011TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3012 Base::TestSetContentsNullOffer();
3013}
3014
3015TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3016 Base::TestSetContentsRtcpMux();
3017}
3018
3019TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3020 Base::TestSetContentsRtcpMux();
3021}
3022
3023TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3024 Base::TestSetRemoteContentUpdate();
3025}
3026
3027TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3028 Base::TestStreams();
3029}
3030
3031TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3032 Base::TestUpdateStreamsInLocalContent();
3033}
3034
3035TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3036 Base::TestUpdateStreamsInRemoteContent();
3037}
3038
3039TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3040 Base::TestChangeStreamParamsInContent();
3041}
3042
3043TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3044 Base::TestPlayoutAndSendingStates();
3045}
3046
3047TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3048 CreateChannels(0, 0);
3049 // Test that we can Mute the default channel even though the sending SSRC
3050 // is unknown.
3051 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003052 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003053 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003054 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003055 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3056 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003057 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003058 SendInitiate();
3059 // After the local session description has been set, we can mute a stream
3060 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003061 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003062 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003063 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003064 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3065}
3066
3067TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3068 Base::TestMediaContentDirection();
3069}
3070
3071TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3072 Base::TestNetworkRouteChanges();
3073}
3074
3075TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3076 Base::TestCallSetup();
3077}
3078
3079TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3080 Base::TestCallTeardownRtcpMux();
3081}
3082
3083TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3084 Base::SendRtpToRtp();
3085}
3086
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003087TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3088 Base::SendRtcpToRtcp();
3089}
3090
3091TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3092 Base::SendRtcpMuxToRtcp();
3093}
3094
3095TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3096 Base::SendRtcpMuxToRtcpMux();
3097}
3098
3099TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3100 Base::SendRequireRtcpMuxToRtcpMux();
3101}
3102
3103TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3104 Base::SendRtcpMuxToRequireRtcpMux();
3105}
3106
3107TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3108 Base::SendRequireRtcpMuxToRequireRtcpMux();
3109}
3110
3111TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3112 Base::SendRequireRtcpMuxToNoRtcpMux();
3113}
3114
3115TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3116 Base::SendEarlyRtcpMuxToRtcp();
3117}
3118
3119TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3120 Base::SendEarlyRtcpMuxToRtcpMux();
3121}
3122
3123TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3124 Base::SendSrtpToSrtp();
3125}
3126
3127TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3128 Base::SendSrtpToSrtp();
3129}
3130
3131TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3132 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3133 Base::SendSrtpToSrtp(DTLS, 0);
3134}
3135
3136TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3137 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3138 Base::SendSrtpToSrtp(DTLS, DTLS);
3139}
3140
3141TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3142 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3143 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3144}
3145
3146TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3147 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3148}
3149
3150TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3151 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3152}
3153
3154TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3155 Base::SendRtpToRtpOnThread();
3156}
3157
3158TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3159 Base::SendSrtpToSrtpOnThread();
3160}
3161
3162TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3163 Base::SendWithWritabilityLoss();
3164}
3165
3166TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3167 Base::TestMediaMonitor();
3168}
3169
3170TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3171 Base::TestSetContentFailure();
3172}
3173
3174TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3175 Base::TestSendTwoOffers();
3176}
3177
3178TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3179 Base::TestReceiveTwoOffers();
3180}
3181
3182TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3183 Base::TestSendPrAnswer();
3184}
3185
3186TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3187 Base::TestReceivePrAnswer();
3188}
3189
3190TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3191 Base::TestFlushRtcp();
3192}
3193
3194TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3195 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3196}
3197
3198TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3199 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3200}
3201
3202TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3203 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3204}
3205
3206TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3207 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3208}
3209
3210TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3211 Base::TestSrtpError(kVideoPts[0]);
3212}
3213
3214TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3215 Base::TestOnReadyToSend();
3216}
3217
3218TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3219 Base::TestOnReadyToSendWithRtcpMux();
3220}
3221
3222TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3223 Base::DefaultMaxBitrateIsUnlimited();
3224}
3225
3226TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3227 Base::CanChangeMaxBitrate();
3228}
3229
deadbeef953c2ce2017-01-09 14:53:41 -08003230// RtpDataChannelSingleThreadTest
3231class RtpDataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003233 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003234 RtpDataChannelSingleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003235 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3236};
3237
deadbeef953c2ce2017-01-09 14:53:41 -08003238// RtpDataChannelDoubleThreadTest
3239class RtpDataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003240 public:
3241 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003242 RtpDataChannelDoubleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003243 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244};
3245
3246// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003247template <>
deadbeef953c2ce2017-01-09 14:53:41 -08003248cricket::RtpDataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003249 rtc::Thread* worker_thread,
3250 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003251 cricket::MediaEngineInterface* engine,
3252 cricket::FakeDataMediaChannel* ch,
3253 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003254 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -08003255 rtc::Thread* signaling_thread =
3256 transport_controller ? transport_controller->signaling_thread() : nullptr;
deadbeef953c2ce2017-01-09 14:53:41 -08003257 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003258 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA,
deadbeefac22f702017-01-12 21:59:29 -08003259 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07003260 rtc::CryptoOptions crypto_options;
3261 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3262 channel->SetCryptoOptions(crypto_options);
zhihuang6ce92592017-01-19 04:49:47 -08003263 cricket::TransportChannel* rtp_transport =
3264 transport_controller->CreateTransportChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003265 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuang6ce92592017-01-19 04:49:47 -08003266 cricket::TransportChannel* rtcp_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08003267 if (channel->NeedsRtcpTransport()) {
zhihuang6ce92592017-01-19 04:49:47 -08003268 rtcp_transport = transport_controller->CreateTransportChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003269 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3270 }
zhihuang6ce92592017-01-19 04:49:47 -08003271 if (!channel->Init_w(rtp_transport, rtcp_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003272 delete channel;
3273 channel = NULL;
3274 }
3275 return channel;
3276}
3277
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003278template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003279void ChannelTest<DataTraits>::CreateContent(
3280 int flags,
3281 const cricket::AudioCodec& audio_codec,
3282 const cricket::VideoCodec& video_codec,
3283 cricket::DataContentDescription* data) {
3284 data->AddCodec(kGoogleDataCodec);
3285 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3286 if (flags & SECURE) {
3287 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003288 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3289 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003290 }
3291}
3292
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003293template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294void ChannelTest<DataTraits>::CopyContent(
3295 const cricket::DataContentDescription& source,
3296 cricket::DataContentDescription* data) {
3297 *data = source;
3298}
3299
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003300template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003301bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3302 const cricket::DataCodec& c2) {
3303 return c1.name == c2.name;
3304}
3305
Peter Boström0c4e06b2015-10-07 12:23:21 +02003306template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003307void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003308 uint32_t ssrc,
3309 int flags,
3310 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311 data->AddLegacyStream(ssrc);
3312}
3313
deadbeef953c2ce2017-01-09 14:53:41 -08003314TEST_F(RtpDataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315 Base::TestInit();
3316 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3317}
3318
deadbeef953c2ce2017-01-09 14:53:41 -08003319TEST_F(RtpDataChannelSingleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003320 Base::TestDeinit();
3321}
3322
deadbeef953c2ce2017-01-09 14:53:41 -08003323TEST_F(RtpDataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324 Base::TestSetContents();
3325}
3326
deadbeef953c2ce2017-01-09 14:53:41 -08003327TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 Base::TestSetContentsNullOffer();
3329}
3330
deadbeef953c2ce2017-01-09 14:53:41 -08003331TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003332 Base::TestSetContentsRtcpMux();
3333}
3334
deadbeef953c2ce2017-01-09 14:53:41 -08003335TEST_F(RtpDataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 Base::TestSetRemoteContentUpdate();
3337}
3338
deadbeef953c2ce2017-01-09 14:53:41 -08003339TEST_F(RtpDataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 Base::TestStreams();
3341}
3342
deadbeef953c2ce2017-01-09 14:53:41 -08003343TEST_F(RtpDataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003344 Base::TestUpdateStreamsInLocalContent();
3345}
3346
deadbeef953c2ce2017-01-09 14:53:41 -08003347TEST_F(RtpDataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348 Base::TestUpdateStreamsInRemoteContent();
3349}
3350
deadbeef953c2ce2017-01-09 14:53:41 -08003351TEST_F(RtpDataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003352 Base::TestChangeStreamParamsInContent();
3353}
3354
deadbeef953c2ce2017-01-09 14:53:41 -08003355TEST_F(RtpDataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356 Base::TestPlayoutAndSendingStates();
3357}
3358
deadbeef953c2ce2017-01-09 14:53:41 -08003359TEST_F(RtpDataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360 Base::TestMediaContentDirection();
3361}
3362
deadbeef953c2ce2017-01-09 14:53:41 -08003363TEST_F(RtpDataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003364 Base::TestCallSetup();
3365}
3366
deadbeef953c2ce2017-01-09 14:53:41 -08003367TEST_F(RtpDataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003368 Base::TestCallTeardownRtcpMux();
3369}
3370
deadbeef953c2ce2017-01-09 14:53:41 -08003371TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003372 Base::TestOnReadyToSend();
3373}
3374
deadbeef953c2ce2017-01-09 14:53:41 -08003375TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003376 Base::TestOnReadyToSendWithRtcpMux();
3377}
3378
deadbeef953c2ce2017-01-09 14:53:41 -08003379TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380 Base::SendRtpToRtp();
3381}
3382
deadbeef953c2ce2017-01-09 14:53:41 -08003383TEST_F(RtpDataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384 Base::SendRtcpToRtcp();
3385}
3386
deadbeef953c2ce2017-01-09 14:53:41 -08003387TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003388 Base::SendRtcpMuxToRtcp();
3389}
3390
deadbeef953c2ce2017-01-09 14:53:41 -08003391TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392 Base::SendRtcpMuxToRtcpMux();
3393}
3394
deadbeef953c2ce2017-01-09 14:53:41 -08003395TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 Base::SendEarlyRtcpMuxToRtcp();
3397}
3398
deadbeef953c2ce2017-01-09 14:53:41 -08003399TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400 Base::SendEarlyRtcpMuxToRtcpMux();
3401}
3402
deadbeef953c2ce2017-01-09 14:53:41 -08003403TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 Base::SendSrtpToSrtp();
3405}
3406
deadbeef953c2ce2017-01-09 14:53:41 -08003407TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408 Base::SendSrtpToSrtp();
3409}
3410
deadbeef953c2ce2017-01-09 14:53:41 -08003411TEST_F(RtpDataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3413}
3414
deadbeef953c2ce2017-01-09 14:53:41 -08003415TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 Base::SendRtpToRtpOnThread();
3417}
3418
deadbeef953c2ce2017-01-09 14:53:41 -08003419TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420 Base::SendSrtpToSrtpOnThread();
3421}
3422
deadbeef953c2ce2017-01-09 14:53:41 -08003423TEST_F(RtpDataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 Base::SendWithWritabilityLoss();
3425}
3426
deadbeef953c2ce2017-01-09 14:53:41 -08003427TEST_F(RtpDataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 Base::TestMediaMonitor();
3429}
3430
deadbeef953c2ce2017-01-09 14:53:41 -08003431TEST_F(RtpDataChannelSingleThreadTest, TestSendData) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003432 CreateChannels(0, 0);
3433 EXPECT_TRUE(SendInitiate());
3434 EXPECT_TRUE(SendAccept());
3435
3436 cricket::SendDataParams params;
3437 params.ssrc = 42;
3438 unsigned char data[] = {'f', 'o', 'o'};
3439 rtc::CopyOnWriteBuffer payload(data, 3);
3440 cricket::SendDataResult result;
3441 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3442 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3443 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3444}
3445
deadbeef953c2ce2017-01-09 14:53:41 -08003446TEST_F(RtpDataChannelDoubleThreadTest, TestInit) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003447 Base::TestInit();
3448 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3449}
3450
deadbeef953c2ce2017-01-09 14:53:41 -08003451TEST_F(RtpDataChannelDoubleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003452 Base::TestDeinit();
3453}
3454
deadbeef953c2ce2017-01-09 14:53:41 -08003455TEST_F(RtpDataChannelDoubleThreadTest, TestSetContents) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003456 Base::TestSetContents();
3457}
3458
deadbeef953c2ce2017-01-09 14:53:41 -08003459TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsNullOffer) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003460 Base::TestSetContentsNullOffer();
3461}
3462
deadbeef953c2ce2017-01-09 14:53:41 -08003463TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003464 Base::TestSetContentsRtcpMux();
3465}
3466
deadbeef953c2ce2017-01-09 14:53:41 -08003467TEST_F(RtpDataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003468 Base::TestSetRemoteContentUpdate();
3469}
3470
deadbeef953c2ce2017-01-09 14:53:41 -08003471TEST_F(RtpDataChannelDoubleThreadTest, TestStreams) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003472 Base::TestStreams();
3473}
3474
deadbeef953c2ce2017-01-09 14:53:41 -08003475TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003476 Base::TestUpdateStreamsInLocalContent();
3477}
3478
deadbeef953c2ce2017-01-09 14:53:41 -08003479TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003480 Base::TestUpdateStreamsInRemoteContent();
3481}
3482
deadbeef953c2ce2017-01-09 14:53:41 -08003483TEST_F(RtpDataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003484 Base::TestChangeStreamParamsInContent();
3485}
3486
deadbeef953c2ce2017-01-09 14:53:41 -08003487TEST_F(RtpDataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003488 Base::TestPlayoutAndSendingStates();
3489}
3490
deadbeef953c2ce2017-01-09 14:53:41 -08003491TEST_F(RtpDataChannelDoubleThreadTest, TestMediaContentDirection) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003492 Base::TestMediaContentDirection();
3493}
3494
deadbeef953c2ce2017-01-09 14:53:41 -08003495TEST_F(RtpDataChannelDoubleThreadTest, TestCallSetup) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003496 Base::TestCallSetup();
3497}
3498
deadbeef953c2ce2017-01-09 14:53:41 -08003499TEST_F(RtpDataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003500 Base::TestCallTeardownRtcpMux();
3501}
3502
deadbeef953c2ce2017-01-09 14:53:41 -08003503TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSend) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003504 Base::TestOnReadyToSend();
3505}
3506
deadbeef953c2ce2017-01-09 14:53:41 -08003507TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003508 Base::TestOnReadyToSendWithRtcpMux();
3509}
3510
deadbeef953c2ce2017-01-09 14:53:41 -08003511TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003512 Base::SendRtpToRtp();
3513}
3514
deadbeef953c2ce2017-01-09 14:53:41 -08003515TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003516 Base::SendRtcpToRtcp();
3517}
3518
deadbeef953c2ce2017-01-09 14:53:41 -08003519TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003520 Base::SendRtcpMuxToRtcp();
3521}
3522
deadbeef953c2ce2017-01-09 14:53:41 -08003523TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003524 Base::SendRtcpMuxToRtcpMux();
3525}
3526
deadbeef953c2ce2017-01-09 14:53:41 -08003527TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003528 Base::SendEarlyRtcpMuxToRtcp();
3529}
3530
deadbeef953c2ce2017-01-09 14:53:41 -08003531TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003532 Base::SendEarlyRtcpMuxToRtcpMux();
3533}
3534
deadbeef953c2ce2017-01-09 14:53:41 -08003535TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003536 Base::SendSrtpToSrtp();
3537}
3538
deadbeef953c2ce2017-01-09 14:53:41 -08003539TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003540 Base::SendSrtpToSrtp();
3541}
3542
deadbeef953c2ce2017-01-09 14:53:41 -08003543TEST_F(RtpDataChannelDoubleThreadTest, SendSrtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003544 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3545}
3546
deadbeef953c2ce2017-01-09 14:53:41 -08003547TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003548 Base::SendRtpToRtpOnThread();
3549}
3550
deadbeef953c2ce2017-01-09 14:53:41 -08003551TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003552 Base::SendSrtpToSrtpOnThread();
3553}
3554
deadbeef953c2ce2017-01-09 14:53:41 -08003555TEST_F(RtpDataChannelDoubleThreadTest, SendWithWritabilityLoss) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003556 Base::SendWithWritabilityLoss();
3557}
3558
deadbeef953c2ce2017-01-09 14:53:41 -08003559TEST_F(RtpDataChannelDoubleThreadTest, TestMediaMonitor) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003560 Base::TestMediaMonitor();
3561}
3562
deadbeef953c2ce2017-01-09 14:53:41 -08003563TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564 CreateChannels(0, 0);
3565 EXPECT_TRUE(SendInitiate());
3566 EXPECT_TRUE(SendAccept());
3567
3568 cricket::SendDataParams params;
3569 params.ssrc = 42;
3570 unsigned char data[] = {
3571 'f', 'o', 'o'
3572 };
jbaucheec21bd2016-03-20 06:15:43 -07003573 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574 cricket::SendDataResult result;
3575 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3576 EXPECT_EQ(params.ssrc,
3577 media_channel1_->last_sent_data_params().ssrc);
3578 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3579}
3580
deadbeefbad5dad2017-01-17 18:32:35 -08003581#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3582
3583// Verifies some DCHECKs are in place.
3584// Uses VoiceChannel, but any BaseChannel subclass would work.
3585class BaseChannelDeathTest : public testing::Test {
3586 public:
3587 BaseChannelDeathTest()
3588 : // RTCP mux not required, SRTP required.
3589 voice_channel_(
3590 rtc::Thread::Current(),
3591 rtc::Thread::Current(),
3592 rtc::Thread::Current(),
3593 &fake_media_engine_,
3594 new cricket::FakeVoiceMediaChannel(nullptr,
3595 cricket::AudioOptions()),
3596 cricket::CN_AUDIO,
3597 false,
3598 true) {
zhihuang6ce92592017-01-19 04:49:47 -08003599 rtp_transport_ = fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003600 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuang6ce92592017-01-19 04:49:47 -08003601 rtcp_transport_ = fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003602 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3603 EXPECT_TRUE(voice_channel_.Init_w(rtp_transport_, rtcp_transport_));
3604 }
3605
3606 protected:
3607 cricket::FakeTransportController fake_transport_controller_;
3608 cricket::FakeMediaEngine fake_media_engine_;
3609 cricket::VoiceChannel voice_channel_;
3610 // Will be cleaned up by FakeTransportController, don't need to worry about
3611 // deleting them in this test.
zhihuang6ce92592017-01-19 04:49:47 -08003612 cricket::TransportChannel* rtp_transport_;
3613 cricket::TransportChannel* rtcp_transport_;
deadbeefbad5dad2017-01-17 18:32:35 -08003614};
3615
3616TEST_F(BaseChannelDeathTest, SetTransportWithNullRtpTransport) {
zhihuang6ce92592017-01-19 04:49:47 -08003617 cricket::TransportChannel* new_rtcp_transport =
3618 fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003619 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3620 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, new_rtcp_transport), "");
3621}
3622
3623TEST_F(BaseChannelDeathTest, SetTransportWithMissingRtcpTransport) {
zhihuang6ce92592017-01-19 04:49:47 -08003624 cricket::TransportChannel* new_rtp_transport =
3625 fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003626 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3627 EXPECT_DEATH(voice_channel_.SetTransports(new_rtp_transport, nullptr), "");
3628}
3629
3630TEST_F(BaseChannelDeathTest, SetTransportWithUnneededRtcpTransport) {
3631 // Activate RTCP muxing, simulating offer/answer negotiation.
3632 cricket::AudioContentDescription content;
3633 content.set_rtcp_mux(true);
3634 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
3635 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
zhihuang6ce92592017-01-19 04:49:47 -08003636 cricket::TransportChannel* new_rtp_transport =
3637 fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003638 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuang6ce92592017-01-19 04:49:47 -08003639 cricket::TransportChannel* new_rtcp_transport =
3640 fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003641 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3642 // After muxing is enabled, no RTCP transport should be passed in here.
3643 EXPECT_DEATH(
3644 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3645}
3646
3647// This test will probably go away if/when we move the transport name out of
3648// the transport classes and into their parent classes.
3649TEST_F(BaseChannelDeathTest, SetTransportWithMismatchingTransportNames) {
zhihuang6ce92592017-01-19 04:49:47 -08003650 cricket::TransportChannel* new_rtp_transport =
3651 fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003652 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuang6ce92592017-01-19 04:49:47 -08003653 cricket::TransportChannel* new_rtcp_transport =
3654 fake_transport_controller_.CreateTransportChannel(
deadbeefbad5dad2017-01-17 18:32:35 -08003655 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3656 EXPECT_DEATH(
3657 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3658}
3659
3660#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3661
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003662// TODO(pthatcher): TestSetReceiver?