blob: 00ceb7d9d53a9567b03195905dd69a0241092325 [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"
zhihuangb2cdd932017-01-19 16:54:25 -080024#include "webrtc/p2p/base/dtlstransportinternal.h"
Tommif888bb52015-12-12 01:37:01 +010025#include "webrtc/p2p/base/faketransportcontroller.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;
zhihuangb2cdd932017-01-19 16:54:25 -080038using cricket::DtlsTransportInternal;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040using cricket::StreamParams;
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);
zhihuangb2cdd932017-01-19 16:54:25 -0800219 cricket::DtlsTransportInternal* rtp_dtls_transport =
220 transport_controller->CreateDtlsTransport(
zhihuangf5b251b2017-01-12 19:37:48 -0800221 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuangb2cdd932017-01-19 16:54:25 -0800222 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -0800223 if (channel->NeedsRtcpTransport()) {
zhihuangb2cdd932017-01-19 16:54:25 -0800224 rtcp_dtls_transport = transport_controller->CreateDtlsTransport(
zhihuangf5b251b2017-01-12 19:37:48 -0800225 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
226 }
zhihuangb2cdd932017-01-19 16:54:25 -0800227 if (!channel->Init_w(rtp_dtls_transport, rtcp_dtls_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
zhihuangb2cdd932017-01-19 16:54:25 -0800302 std::vector<cricket::DtlsTransportInternal*> 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
zhihuangb2cdd932017-01-19 16:54:25 -0800306 std::vector<cricket::DtlsTransportInternal*> GetChannels2() {
deadbeef49f34fd2016-12-06 16:22:06 -0800307 return transport_controller2_->channels_for_testing();
308 }
309
zhihuangb2cdd932017-01-19 16:54:25 -0800310 cricket::FakeDtlsTransport* GetFakeChannel1(int component) {
311 return transport_controller1_->GetFakeDtlsTransport_n(
deadbeef49f34fd2016-12-06 16:22:06 -0800312 channel1_->content_name(), component);
313 }
314
zhihuangb2cdd932017-01-19 16:54:25 -0800315 cricket::FakeDtlsTransport* GetFakeChannel2(int component) {
316 return transport_controller2_->GetFakeDtlsTransport_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;
zhihuangb2cdd932017-01-19 16:54:25 -0800414 if (!channel->rtp_dtls_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);
zhihuangb2cdd932017-01-19 16:54:25 -0800544 EXPECT_TRUE(channel1_->rtcp_dtls_transport() != NULL);
545 EXPECT_TRUE(channel2_->rtcp_dtls_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));
zhihuangb2cdd932017-01-19 16:54:25 -0800552 EXPECT_TRUE(channel1_->rtcp_dtls_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));
zhihuangb2cdd932017-01-19 16:54:25 -0800557 EXPECT_TRUE(channel2_->rtcp_dtls_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);
zhihuangb2cdd932017-01-19 16:54:25 -0800564 EXPECT_TRUE(channel1_->rtcp_dtls_transport() != NULL);
565 EXPECT_TRUE(channel2_->rtcp_dtls_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));
zhihuangb2cdd932017-01-19 16:54:25 -0800571 EXPECT_TRUE(channel1_->rtcp_dtls_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.
zhihuangb2cdd932017-01-19 16:54:25 -0800574 EXPECT_TRUE(channel1_->rtcp_dtls_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));
zhihuangb2cdd932017-01-19 16:54:25 -0800580 EXPECT_TRUE(channel2_->rtcp_dtls_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
zhihuangb2cdd932017-01-19 16:54:25 -0800960 cricket::DtlsTransportInternal* transport_channel1 =
961 channel1_->rtp_dtls_transport();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200962 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700963 typename T::MediaChannel* media_channel1 =
964 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200965 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700966
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200967 media_channel1->set_num_network_route_changes(0);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700968 network_thread_->Invoke<void>(RTC_FROM_HERE, [transport_channel1] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200969 // The transport channel becomes disconnected.
zhihuangb2cdd932017-01-19 16:54:25 -0800970 transport_channel1->ice_transport()->SignalSelectedCandidatePairChanged(
971 transport_channel1->ice_transport(), nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200972 });
973 WaitForThreads();
974 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700975 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200976 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700977
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700978 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, transport_channel1,
979 media_channel1, kLocalNetId,
980 kRemoteNetId, kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200981 // The transport channel becomes connected.
982 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
983 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
984 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
985 transport_controller1_->CreateFakeCandidatePair(
986 local_address, kLocalNetId, remote_address, kRemoteNetId));
zhihuangb2cdd932017-01-19 16:54:25 -0800987 transport_channel1->ice_transport()->SignalSelectedCandidatePairChanged(
988 transport_channel1->ice_transport(), candidate_pair.get(),
989 kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200990 });
991 WaitForThreads();
992 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -0700993 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200994 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700995 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200996 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700997 media_channel1->last_network_route().last_sent_packet_id);
michaelt79e05882016-11-08 02:50:09 -0800998 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
999 EXPECT_EQ(kTransportOverheadPerPacket,
1000 media_channel1->transport_overhead_per_packet());
Honghai Zhangcc411c02016-03-29 17:27:21 -07001001 }
1002
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 // Test setting up a call.
1004 void TestCallSetup() {
1005 CreateChannels(0, 0);
1006 EXPECT_FALSE(channel1_->secure());
1007 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +02001008 if (verify_playout_) {
1009 EXPECT_TRUE(media_channel1_->playout());
1010 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 EXPECT_FALSE(media_channel1_->sending());
1012 EXPECT_TRUE(SendAccept());
1013 EXPECT_FALSE(channel1_->secure());
1014 EXPECT_TRUE(media_channel1_->sending());
1015 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +02001016 if (verify_playout_) {
1017 EXPECT_TRUE(media_channel2_->playout());
1018 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 EXPECT_TRUE(media_channel2_->sending());
1020 EXPECT_EQ(1U, media_channel2_->codecs().size());
1021 }
1022
1023 // Test that we don't crash if packets are sent during call teardown
1024 // when RTCP mux is enabled. This is a regression test against a specific
1025 // race condition that would only occur when a RTCP packet was sent during
1026 // teardown of a channel on which RTCP mux was enabled.
1027 void TestCallTeardownRtcpMux() {
1028 class LastWordMediaChannel : public T::MediaChannel {
1029 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001030 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001032 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1033 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1035 }
1036 };
1037 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
deadbeefac22f702017-01-12 21:59:29 -08001038 RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 EXPECT_TRUE(SendInitiate());
1040 EXPECT_TRUE(SendAccept());
1041 EXPECT_TRUE(SendTerminate());
1042 }
1043
1044 // Send voice RTP data to the other side and ensure it gets there.
1045 void SendRtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001046 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 EXPECT_TRUE(SendInitiate());
1048 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001049 EXPECT_EQ(1U, GetChannels1().size());
1050 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001051 SendRtp1();
1052 SendRtp2();
1053 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 EXPECT_TRUE(CheckRtp1());
1055 EXPECT_TRUE(CheckRtp2());
1056 EXPECT_TRUE(CheckNoRtp1());
1057 EXPECT_TRUE(CheckNoRtp2());
1058 }
1059
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001060 void TestDeinit() {
deadbeefac22f702017-01-12 21:59:29 -08001061 CreateChannels(0, 0);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001062 EXPECT_TRUE(SendInitiate());
1063 EXPECT_TRUE(SendAccept());
1064 SendRtp1();
1065 SendRtp2();
1066 SendRtcp1();
1067 SendRtcp2();
1068 // Do not wait, destroy channels.
1069 channel1_.reset(nullptr);
1070 channel2_.reset(nullptr);
1071 }
1072
deadbeefac22f702017-01-12 21:59:29 -08001073 // Check that RTCP can be transmitted between both sides.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 void SendRtcpToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001075 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 EXPECT_TRUE(SendInitiate());
1077 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001078 EXPECT_EQ(2U, GetChannels1().size());
1079 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001080 SendRtcp1();
1081 SendRtcp2();
1082 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 EXPECT_TRUE(CheckRtcp1());
1084 EXPECT_TRUE(CheckRtcp2());
1085 EXPECT_TRUE(CheckNoRtcp1());
1086 EXPECT_TRUE(CheckNoRtcp2());
1087 }
1088
1089 // Check that RTCP is transmitted if only the initiator supports mux.
1090 void SendRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001091 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 EXPECT_TRUE(SendInitiate());
1093 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001094 EXPECT_EQ(2U, GetChannels1().size());
1095 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001096 SendRtcp1();
1097 SendRtcp2();
1098 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099 EXPECT_TRUE(CheckRtcp1());
1100 EXPECT_TRUE(CheckRtcp2());
1101 EXPECT_TRUE(CheckNoRtcp1());
1102 EXPECT_TRUE(CheckNoRtcp2());
1103 }
1104
1105 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1106 void SendRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001107 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001109 EXPECT_EQ(2U, GetChannels1().size());
1110 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001112 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001113 SendRtp1();
1114 SendRtp2();
1115 SendRtcp1();
1116 SendRtcp2();
1117 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 EXPECT_TRUE(CheckRtp1());
1119 EXPECT_TRUE(CheckRtp2());
1120 EXPECT_TRUE(CheckNoRtp1());
1121 EXPECT_TRUE(CheckNoRtp2());
1122 EXPECT_TRUE(CheckRtcp1());
1123 EXPECT_TRUE(CheckRtcp2());
1124 EXPECT_TRUE(CheckNoRtcp1());
1125 EXPECT_TRUE(CheckNoRtcp2());
1126 }
1127
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001128 // Check that RTP and RTCP are transmitted ok when both sides
1129 // support mux and one the offerer requires mux.
1130 void SendRequireRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001131 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001132 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001133 EXPECT_EQ(1U, GetChannels1().size());
1134 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001135 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001136 SendRtp1();
1137 SendRtp2();
1138 SendRtcp1();
1139 SendRtcp2();
1140 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001141 EXPECT_TRUE(CheckRtp1());
1142 EXPECT_TRUE(CheckRtp2());
1143 EXPECT_TRUE(CheckNoRtp1());
1144 EXPECT_TRUE(CheckNoRtp2());
1145 EXPECT_TRUE(CheckRtcp1());
1146 EXPECT_TRUE(CheckRtcp2());
1147 EXPECT_TRUE(CheckNoRtcp1());
1148 EXPECT_TRUE(CheckNoRtcp2());
1149 }
1150
1151 // Check that RTP and RTCP are transmitted ok when both sides
deadbeefac22f702017-01-12 21:59:29 -08001152 // support mux and only the answerer requires rtcp mux.
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001153 void SendRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001154 CreateChannels(RTCP_MUX, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001155 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001156 EXPECT_EQ(2U, GetChannels1().size());
1157 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001158 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001159 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001160 SendRtp1();
1161 SendRtp2();
1162 SendRtcp1();
1163 SendRtcp2();
1164 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001165 EXPECT_TRUE(CheckRtp1());
1166 EXPECT_TRUE(CheckRtp2());
1167 EXPECT_TRUE(CheckNoRtp1());
1168 EXPECT_TRUE(CheckNoRtp2());
1169 EXPECT_TRUE(CheckRtcp1());
1170 EXPECT_TRUE(CheckRtcp2());
1171 EXPECT_TRUE(CheckNoRtcp1());
1172 EXPECT_TRUE(CheckNoRtcp2());
1173 }
1174
1175 // Check that RTP and RTCP are transmitted ok when both sides
1176 // require mux.
1177 void SendRequireRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001178 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001179 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001180 EXPECT_EQ(1U, GetChannels1().size());
1181 EXPECT_EQ(1U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001182 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001183 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001184 SendRtp1();
1185 SendRtp2();
1186 SendRtcp1();
1187 SendRtcp2();
1188 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001189 EXPECT_TRUE(CheckRtp1());
1190 EXPECT_TRUE(CheckRtp2());
1191 EXPECT_TRUE(CheckNoRtp1());
1192 EXPECT_TRUE(CheckNoRtp2());
1193 EXPECT_TRUE(CheckRtcp1());
1194 EXPECT_TRUE(CheckRtcp2());
1195 EXPECT_TRUE(CheckNoRtcp1());
1196 EXPECT_TRUE(CheckNoRtcp2());
1197 }
1198
1199 // Check that SendAccept fails if the answerer doesn't support mux
1200 // and the offerer requires it.
1201 void SendRequireRtcpMuxToNoRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001202 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, 0);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001203 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001204 EXPECT_EQ(1U, GetChannels1().size());
1205 EXPECT_EQ(2U, GetChannels2().size());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001206 EXPECT_FALSE(SendAccept());
1207 }
1208
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001209 // Check that RTCP data sent by the initiator before the accept is not muxed.
1210 void SendEarlyRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001211 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001213 EXPECT_EQ(2U, GetChannels1().size());
1214 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001215
1216 // RTCP can be sent before the call is accepted, if the transport is ready.
1217 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001218 SendRtcp1();
1219 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001220 EXPECT_TRUE(CheckNoRtp2());
1221 EXPECT_TRUE(CheckRtcp2());
1222
1223 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001224 SendRtcp2();
1225 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226 EXPECT_TRUE(CheckNoRtp1());
1227 EXPECT_TRUE(CheckRtcp1());
1228
1229 // Complete call setup and ensure everything is still OK.
1230 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001231 EXPECT_EQ(2U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001232 SendRtcp1();
1233 SendRtcp2();
1234 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236 EXPECT_TRUE(CheckRtcp1());
1237 }
1238
1239
1240 // Check that RTCP data is not muxed until both sides have enabled muxing,
1241 // but that we properly demux before we get the accept message, since there
1242 // is a race between RTP data and the jingle accept.
1243 void SendEarlyRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001244 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001246 EXPECT_EQ(2U, GetChannels1().size());
1247 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248
1249 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1250 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001251 SendRtcp1();
1252 WaitForThreads();
1253 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254
1255 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001256 SendRtcp2();
1257 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258 EXPECT_TRUE(CheckNoRtp1());
1259 EXPECT_TRUE(CheckRtcp1());
1260
1261 // Complete call setup and ensure everything is still OK.
1262 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001263 EXPECT_EQ(1U, GetChannels1().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001264 SendRtcp1();
1265 SendRtcp2();
1266 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268 EXPECT_TRUE(CheckRtcp1());
1269 }
1270
1271 // Test that we properly send SRTP with RTCP in both directions.
1272 // You can pass in DTLS and/or RTCP_MUX as flags.
1273 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
nissec8ee8822017-01-18 07:20:55 -08001274 RTC_CHECK((flags1_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
1275 RTC_CHECK((flags2_in & ~(RTCP_MUX | DTLS | GCM_CIPHER)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001276
deadbeefac22f702017-01-12 21:59:29 -08001277 int flags1 = SECURE | flags1_in;
1278 int flags2 = SECURE | flags2_in;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 bool dtls1 = !!(flags1_in & DTLS);
1280 bool dtls2 = !!(flags2_in & DTLS);
1281 CreateChannels(flags1, flags2);
1282 EXPECT_FALSE(channel1_->secure());
1283 EXPECT_FALSE(channel2_->secure());
1284 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001285 WaitForThreads();
1286 EXPECT_TRUE(channel1_->writable());
1287 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 EXPECT_TRUE(SendAccept());
1289 EXPECT_TRUE(channel1_->secure());
1290 EXPECT_TRUE(channel2_->secure());
1291 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1292 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001293 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1294 // channels.
1295 if (dtls1 && dtls2) {
1296 // A GCM cipher is only used if both channels support GCM ciphers.
1297 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1298 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1299 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1300 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001301 SendRtp1();
1302 SendRtp2();
1303 SendRtcp1();
1304 SendRtcp2();
1305 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 EXPECT_TRUE(CheckRtp1());
1307 EXPECT_TRUE(CheckRtp2());
1308 EXPECT_TRUE(CheckNoRtp1());
1309 EXPECT_TRUE(CheckNoRtp2());
1310 EXPECT_TRUE(CheckRtcp1());
1311 EXPECT_TRUE(CheckRtcp2());
1312 EXPECT_TRUE(CheckNoRtcp1());
1313 EXPECT_TRUE(CheckNoRtcp2());
1314 }
1315
1316 // Test that we properly handling SRTP negotiating down to RTP.
1317 void SendSrtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001318 CreateChannels(SECURE, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 EXPECT_FALSE(channel1_->secure());
1320 EXPECT_FALSE(channel2_->secure());
1321 EXPECT_TRUE(SendInitiate());
1322 EXPECT_TRUE(SendAccept());
1323 EXPECT_FALSE(channel1_->secure());
1324 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001325 SendRtp1();
1326 SendRtp2();
1327 SendRtcp1();
1328 SendRtcp2();
1329 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 EXPECT_TRUE(CheckRtp1());
1331 EXPECT_TRUE(CheckRtp2());
1332 EXPECT_TRUE(CheckNoRtp1());
1333 EXPECT_TRUE(CheckNoRtp2());
1334 EXPECT_TRUE(CheckRtcp1());
1335 EXPECT_TRUE(CheckRtcp2());
1336 EXPECT_TRUE(CheckNoRtcp1());
1337 EXPECT_TRUE(CheckNoRtcp2());
1338 }
1339
1340 // Test that we can send and receive early media when a provisional answer is
1341 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1342 void SendEarlyMediaUsingRtcpMuxSrtp() {
1343 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1344
deadbeefac22f702017-01-12 21:59:29 -08001345 CreateChannels(SSRC_MUX | RTCP_MUX | SECURE,
1346 SSRC_MUX | RTCP_MUX | SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347 EXPECT_TRUE(SendOffer());
1348 EXPECT_TRUE(SendProvisionalAnswer());
1349 EXPECT_TRUE(channel1_->secure());
1350 EXPECT_TRUE(channel2_->secure());
deadbeef49f34fd2016-12-06 16:22:06 -08001351 EXPECT_EQ(2U, GetChannels1().size());
1352 EXPECT_EQ(2U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001353 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1354 SendCustomRtcp1(kSsrc1);
1355 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1356 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1359
1360 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001361 SendCustomRtcp2(kSsrc2);
1362 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1363 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001364 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1366
1367 // Complete call setup and ensure everything is still OK.
1368 EXPECT_TRUE(SendFinalAnswer());
deadbeef49f34fd2016-12-06 16:22:06 -08001369 EXPECT_EQ(1U, GetChannels1().size());
1370 EXPECT_EQ(1U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 EXPECT_TRUE(channel1_->secure());
1372 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001373 SendCustomRtcp1(kSsrc1);
1374 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1375 SendCustomRtcp2(kSsrc2);
1376 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1377 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1382 }
1383
1384 // Test that we properly send RTP without SRTP from a thread.
1385 void SendRtpToRtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001386 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387 EXPECT_TRUE(SendInitiate());
1388 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001389 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1390 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1391 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1392 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1393 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1394 send_rtcp1.thread(),
1395 send_rtcp2.thread()};
1396 WaitForThreads(involved_threads);
1397 EXPECT_TRUE(CheckRtp1());
1398 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 EXPECT_TRUE(CheckNoRtp1());
1400 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001401 EXPECT_TRUE(CheckRtcp1());
1402 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 EXPECT_TRUE(CheckNoRtcp1());
1404 EXPECT_TRUE(CheckNoRtcp2());
1405 }
1406
1407 // Test that we properly send SRTP with RTCP from a thread.
1408 void SendSrtpToSrtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001409 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 EXPECT_TRUE(SendInitiate());
1411 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001412 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1413 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1414 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1415 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1416 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1417 send_rtcp1.thread(),
1418 send_rtcp2.thread()};
1419 WaitForThreads(involved_threads);
1420 EXPECT_TRUE(CheckRtp1());
1421 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 EXPECT_TRUE(CheckNoRtp1());
1423 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001424 EXPECT_TRUE(CheckRtcp1());
1425 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 EXPECT_TRUE(CheckNoRtcp1());
1427 EXPECT_TRUE(CheckNoRtcp2());
1428 }
1429
1430 // Test that the mediachannel retains its sending state after the transport
1431 // becomes non-writable.
1432 void SendWithWritabilityLoss() {
deadbeefac22f702017-01-12 21:59:29 -08001433 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 EXPECT_TRUE(SendInitiate());
1435 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001436 EXPECT_EQ(1U, GetChannels1().size());
1437 EXPECT_EQ(1U, GetChannels2().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001438 SendRtp1();
1439 SendRtp2();
1440 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 EXPECT_TRUE(CheckRtp1());
1442 EXPECT_TRUE(CheckRtp2());
1443 EXPECT_TRUE(CheckNoRtp1());
1444 EXPECT_TRUE(CheckNoRtp2());
1445
wu@webrtc.org97077a32013-10-25 21:18:33 +00001446 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001447 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001448 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001449 SendRtp1();
1450 SendRtp2();
1451 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 EXPECT_TRUE(CheckRtp1());
1453 EXPECT_TRUE(CheckNoRtp2());
1454
1455 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001456 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001457 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001459 SendRtp1();
1460 SendRtp2();
1461 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_TRUE(CheckRtp1());
1463 EXPECT_TRUE(CheckRtp2());
1464 EXPECT_TRUE(CheckNoRtp1());
1465 EXPECT_TRUE(CheckNoRtp2());
1466
1467 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001468 network_thread_->Invoke<void>(
deadbeef49f34fd2016-12-06 16:22:06 -08001469 RTC_FROM_HERE, [this] { GetFakeChannel1(1)->SetDestination(nullptr); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 EXPECT_TRUE(media_channel1_->sending());
1471
wu@webrtc.org97077a32013-10-25 21:18:33 +00001472 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001473 SendRtp1();
1474 SendRtp2();
1475 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 EXPECT_TRUE(CheckRtp1());
1477 EXPECT_TRUE(CheckNoRtp2());
zhihuangb2cdd932017-01-19 16:54:25 -08001478 EXPECT_TRUE(CheckNoRtp1());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479
1480 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001481 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeef49f34fd2016-12-06 16:22:06 -08001482 GetFakeChannel1(1)->SetDestination(GetFakeChannel2(1));
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001483 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001485 SendRtp1();
1486 SendRtp2();
1487 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 EXPECT_TRUE(CheckRtp1());
1489 EXPECT_TRUE(CheckRtp2());
1490 EXPECT_TRUE(CheckNoRtp1());
1491 EXPECT_TRUE(CheckNoRtp2());
1492 }
1493
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001494 void SendBundleToBundle(
1495 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1496 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001498 // Only pl_type1 was added to the bundle filter for both |channel1_|
1499 // and |channel2_|.
1500 int pl_type1 = pl_types[0];
1501 int pl_type2 = pl_types[1];
deadbeefac22f702017-01-12 21:59:29 -08001502 int flags = SSRC_MUX;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001503 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001504 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001505 if (rtcp_mux) {
1506 flags |= RTCP_MUX;
1507 expected_channels = 1U;
1508 }
1509 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 EXPECT_TRUE(SendInitiate());
deadbeef49f34fd2016-12-06 16:22:06 -08001511 EXPECT_EQ(2U, GetChannels1().size());
1512 EXPECT_EQ(expected_channels, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001514 EXPECT_EQ(expected_channels, GetChannels1().size());
1515 EXPECT_EQ(expected_channels, GetChannels2().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001516 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1517 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1518 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1519 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001520
1521 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001522 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1523 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1524 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001525 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001526 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1527 EXPECT_TRUE(CheckNoRtp1());
1528 EXPECT_TRUE(CheckNoRtp2());
1529
1530 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001531 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1532 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1533 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001534 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001535 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1536
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001537 SendCustomRtcp1(kSsrc1);
1538 SendCustomRtcp2(kSsrc2);
1539 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1541 EXPECT_TRUE(CheckNoRtcp1());
1542 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1543 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001545 SendCustomRtcp1(kSsrc2);
1546 SendCustomRtcp2(kSsrc1);
1547 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001548 // Bundle filter shouldn't filter out any RTCP.
1549 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1550 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 }
1552
deadbeefc6b6e092016-12-01 12:49:20 -08001553 // Test that the media monitor can be run and gives callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 void TestMediaMonitor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 CreateChannels(0, 0);
1556 EXPECT_TRUE(SendInitiate());
1557 EXPECT_TRUE(SendAccept());
1558 channel1_->StartMediaMonitor(100);
1559 channel2_->StartMediaMonitor(100);
1560 // Ensure we get callbacks and stop.
deadbeefc6b6e092016-12-01 12:49:20 -08001561 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
1562 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 channel1_->StopMediaMonitor();
1564 channel2_->StopMediaMonitor();
1565 // Ensure a restart of a stopped monitor works.
1566 channel1_->StartMediaMonitor(100);
deadbeefc6b6e092016-12-01 12:49:20 -08001567 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 channel1_->StopMediaMonitor();
1569 // Ensure stopping a stopped monitor is OK.
1570 channel1_->StopMediaMonitor();
1571 }
1572
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 void TestSetContentFailure() {
1574 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575
Peter Thatchera6d24442015-07-09 21:26:36 -07001576 auto sdesc = cricket::SessionDescription();
1577 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1578 new cricket::AudioContentDescription());
1579 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1580 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581
Peter Thatchera6d24442015-07-09 21:26:36 -07001582 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001584 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1585 &sdesc, cricket::CA_OFFER, &err));
1586 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1587 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588
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_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001593 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1594 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 }
1596
1597 void TestSendTwoOffers() {
1598 CreateChannels(0, 0);
1599
Peter Thatchera6d24442015-07-09 21:26:36 -07001600 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001601 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001602 CreateSessionDescriptionWithStream(1));
1603 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1604 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1606
kwiberg31022942016-03-11 14:18:21 -08001607 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001608 CreateSessionDescriptionWithStream(2));
1609 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1610 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1612 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1613 }
1614
1615 void TestReceiveTwoOffers() {
1616 CreateChannels(0, 0);
1617
Peter Thatchera6d24442015-07-09 21:26:36 -07001618 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001619 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001620 CreateSessionDescriptionWithStream(1));
1621 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1622 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1624
kwiberg31022942016-03-11 14:18:21 -08001625 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001626 CreateSessionDescriptionWithStream(2));
1627 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1628 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1630 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1631 }
1632
1633 void TestSendPrAnswer() {
1634 CreateChannels(0, 0);
1635
Peter Thatchera6d24442015-07-09 21:26:36 -07001636 std::string err;
1637 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001638 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001639 CreateSessionDescriptionWithStream(1));
1640 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1641 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1643
Peter Thatchera6d24442015-07-09 21:26:36 -07001644 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001645 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001646 CreateSessionDescriptionWithStream(2));
1647 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1648 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1650 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1651
Peter Thatchera6d24442015-07-09 21:26:36 -07001652 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001653 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001654 CreateSessionDescriptionWithStream(3));
1655 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1656 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1658 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1659 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1660 }
1661
1662 void TestReceivePrAnswer() {
1663 CreateChannels(0, 0);
1664
Peter Thatchera6d24442015-07-09 21:26:36 -07001665 std::string err;
1666 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001667 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001668 CreateSessionDescriptionWithStream(1));
1669 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1670 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1672
Peter Thatchera6d24442015-07-09 21:26:36 -07001673 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001674 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001675 CreateSessionDescriptionWithStream(2));
1676 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1677 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1679 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1680
Peter Thatchera6d24442015-07-09 21:26:36 -07001681 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001682 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001683 CreateSessionDescriptionWithStream(3));
1684 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1685 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1687 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1688 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1689 }
1690
1691 void TestFlushRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001692 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 EXPECT_TRUE(SendInitiate());
1694 EXPECT_TRUE(SendAccept());
deadbeef49f34fd2016-12-06 16:22:06 -08001695 EXPECT_EQ(2U, GetChannels1().size());
1696 EXPECT_EQ(2U, GetChannels2().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697
1698 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001699 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 // The sending message is only posted. channel2_ should be empty.
1701 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001702 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1703 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704
1705 // When channel1_ is deleted, the RTCP packet should be sent out to
1706 // channel2_.
1707 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001708 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 EXPECT_TRUE(CheckRtcp2());
1710 }
1711
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001712 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001713 struct SrtpErrorHandler : public sigslot::has_slots<> {
1714 SrtpErrorHandler() :
1715 mode_(cricket::SrtpFilter::UNPROTECT),
1716 error_(cricket::SrtpFilter::ERROR_NONE) {}
1717 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1718 cricket::SrtpFilter::Error error) {
1719 mode_ = mode;
1720 error_ = error;
1721 }
1722 cricket::SrtpFilter::Mode mode_;
1723 cricket::SrtpFilter::Error error_;
1724 } error_handler;
1725
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001726 // For Audio, only pl_type 0 is added to the bundle filter.
1727 // For Video, only pl_type 97 is added to the bundle filter.
1728 // So we need to pass in pl_type so that the packet can pass through
1729 // the bundle filter before it can be processed by the srtp filter.
1730 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001731 static unsigned const char kBadPacket[] = {
1732 0x84, static_cast<unsigned char>(pl_type),
1733 0x00, 0x01,
1734 0x00, 0x00,
1735 0x00, 0x00,
1736 0x00, 0x00,
1737 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001738
1739 // Using fake clock because this tests that SRTP errors are signaled at
1740 // specific times based on set_signal_silent_time.
1741 rtc::ScopedFakeClock fake_clock;
1742 // Some code uses a time of 0 as a special value, so we must start with
1743 // a non-zero time.
1744 // TODO(deadbeef): Fix this.
1745 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1746
deadbeefac22f702017-01-12 21:59:29 -08001747 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 EXPECT_FALSE(channel1_->secure());
1749 EXPECT_FALSE(channel2_->secure());
1750 EXPECT_TRUE(SendInitiate());
1751 EXPECT_TRUE(SendAccept());
1752 EXPECT_TRUE(channel1_->secure());
1753 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001754 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001755 channel2_->srtp_filter()->SignalSrtpError.connect(
1756 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757
1758 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001759 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1760 rtc::PacketOptions());
1761 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001763 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001764 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1765 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001766 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1767 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001768 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1769 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001771 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001772 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001773 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001774 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1775 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001776 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001777 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1778 rtc::PacketOptions());
1779 WaitForThreads();
1780 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001781 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782
1783 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001784 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001785 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001786
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001787 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
zhihuangb2cdd932017-01-19 16:54:25 -08001788 cricket::DtlsTransportInternal* transport_channel =
1789 channel2_->rtp_dtls_transport();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001790 transport_channel->SignalReadPacket(
1791 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1792 sizeof(kBadPacket), rtc::PacketTime(), 0);
1793 });
1794 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001795 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001796 // Terminate channels before the fake clock is destroyed.
1797 EXPECT_TRUE(SendTerminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 }
1799
1800 void TestOnReadyToSend() {
deadbeefac22f702017-01-12 21:59:29 -08001801 CreateChannels(0, 0);
zhihuangb2cdd932017-01-19 16:54:25 -08001802 DtlsTransportInternal* rtp = channel1_->rtp_dtls_transport();
1803 DtlsTransportInternal* rtcp = channel1_->rtcp_dtls_transport();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001805
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001806 network_thread_->Invoke<void>(RTC_FROM_HERE,
1807 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001808 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001810
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001811 network_thread_->Invoke<void>(RTC_FROM_HERE,
1812 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001813 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1815 // channel are ready to send.
1816 EXPECT_TRUE(media_channel1_->ready_to_send());
1817
1818 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001819 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1820 channel1_->SetTransportChannelReadyToSend(false, false);
1821 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001822 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001824
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001825 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1826 channel1_->SetTransportChannelReadyToSend(false, true);
1827 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001828 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 EXPECT_TRUE(media_channel1_->ready_to_send());
1830
1831 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001832 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1833 channel1_->SetTransportChannelReadyToSend(true, false);
1834 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001835 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001837
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001838 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1839 channel1_->SetTransportChannelReadyToSend(true, true);
1840 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001841 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 EXPECT_TRUE(media_channel1_->ready_to_send());
1843 }
1844
1845 void TestOnReadyToSendWithRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001846 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 typename T::Content content;
1848 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1849 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1850 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001851 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1852 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
zhihuangb2cdd932017-01-19 16:54:25 -08001853 EXPECT_TRUE(channel1_->rtcp_dtls_transport() == NULL);
1854 DtlsTransportInternal* rtp = channel1_->rtp_dtls_transport();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 EXPECT_FALSE(media_channel1_->ready_to_send());
1856 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1857 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001858 network_thread_->Invoke<void>(RTC_FROM_HERE,
1859 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001860 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001862
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001863 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1864 channel1_->SetTransportChannelReadyToSend(false, false);
1865 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001866 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 EXPECT_FALSE(media_channel1_->ready_to_send());
1868 }
1869
skvladdc1c62c2016-03-16 19:07:43 -07001870 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1871 typename T::Content content;
1872 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1873 content.set_bandwidth(remote_limit);
1874 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1875 }
1876
1877 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1878 webrtc::RtpParameters parameters;
1879 webrtc::RtpEncodingParameters encoding;
1880 encoding.max_bitrate_bps = limit;
1881 parameters.encodings.push_back(encoding);
1882 return parameters;
1883 }
1884
1885 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1886 int expected_bitrate) {
1887 EXPECT_EQ(1UL, parameters.encodings.size());
1888 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1889 }
1890
1891 void DefaultMaxBitrateIsUnlimited() {
1892 CreateChannels(0, 0);
1893 EXPECT_TRUE(
1894 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1895 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001896 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001897 }
1898
1899 void CanChangeMaxBitrate() {
1900 CreateChannels(0, 0);
1901 EXPECT_TRUE(
1902 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1903
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001904 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1905 kSsrc1, BitrateLimitedParameters(1000)));
1906 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1907 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001908 EXPECT_EQ(-1, media_channel1_->max_bps());
1909
1910 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001911 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1912 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1913 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001914 EXPECT_EQ(-1, media_channel1_->max_bps());
1915 }
1916
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001918 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1919 static void ProcessThreadQueue(rtc::Thread* thread) {
1920 RTC_DCHECK(thread->IsCurrent());
1921 while (!thread->empty()) {
1922 thread->ProcessMessages(0);
1923 }
1924 }
1925 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1926 // |threads| and current thread post packets to network thread.
1927 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001928 thread->Invoke<void>(RTC_FROM_HERE,
1929 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001930 }
1931 ProcessThreadQueue(rtc::Thread::Current());
1932 // Network thread move them around and post back to worker = current thread.
1933 if (!network_thread_->IsCurrent()) {
1934 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001935 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001936 }
1937 // Worker thread = current Thread process received messages.
1938 ProcessThreadQueue(rtc::Thread::Current());
1939 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001940 // TODO(pbos): Remove playout from all media channels and let renderers mute
1941 // themselves.
1942 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001943 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1944 rtc::Thread* network_thread_;
1945 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1946 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 cricket::FakeMediaEngine media_engine_;
1948 // The media channels are owned by the voice channel objects below.
1949 typename T::MediaChannel* media_channel1_;
1950 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001951 std::unique_ptr<typename T::Channel> channel1_;
1952 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 typename T::Content local_media_content1_;
1954 typename T::Content local_media_content2_;
1955 typename T::Content remote_media_content1_;
1956 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001958 rtc::Buffer rtp_packet_;
1959 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 int media_info_callbacks1_;
1961 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001962 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963};
1964
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965template<>
1966void ChannelTest<VoiceTraits>::CreateContent(
1967 int flags,
1968 const cricket::AudioCodec& audio_codec,
1969 const cricket::VideoCodec& video_codec,
1970 cricket::AudioContentDescription* audio) {
1971 audio->AddCodec(audio_codec);
1972 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1973 if (flags & SECURE) {
1974 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001975 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1976 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 }
1978}
1979
1980template<>
1981void ChannelTest<VoiceTraits>::CopyContent(
1982 const cricket::AudioContentDescription& source,
1983 cricket::AudioContentDescription* audio) {
1984 *audio = source;
1985}
1986
1987template<>
1988bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1989 const cricket::AudioCodec& c2) {
1990 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1991 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1992}
1993
Peter Boström0c4e06b2015-10-07 12:23:21 +02001994template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001996 uint32_t ssrc,
1997 int flags,
1998 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 audio->AddLegacyStream(ssrc);
2000}
2001
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002002class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 public:
solenberg1dd98f32015-09-10 01:57:14 -07002004 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002005 VoiceChannelSingleThreadTest()
2006 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2007};
2008
2009class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2010 public:
2011 typedef ChannelTest<VoiceTraits> Base;
2012 VoiceChannelDoubleThreadTest()
2013 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014};
2015
2016// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002017template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002019 rtc::Thread* worker_thread,
2020 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002021 cricket::MediaEngineInterface* engine,
2022 cricket::FakeVideoMediaChannel* ch,
2023 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07002024 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -08002025 rtc::Thread* signaling_thread =
2026 transport_controller ? transport_controller->signaling_thread() : nullptr;
deadbeef7af91dd2016-12-13 11:29:11 -08002027 cricket::VideoChannel* channel = new cricket::VideoChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08002028 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO,
deadbeefac22f702017-01-12 21:59:29 -08002029 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07002030 rtc::CryptoOptions crypto_options;
2031 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2032 channel->SetCryptoOptions(crypto_options);
zhihuangb2cdd932017-01-19 16:54:25 -08002033 cricket::DtlsTransportInternal* rtp_dtls_transport =
2034 transport_controller->CreateDtlsTransport(
zhihuangf5b251b2017-01-12 19:37:48 -08002035 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuangb2cdd932017-01-19 16:54:25 -08002036 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08002037 if (channel->NeedsRtcpTransport()) {
zhihuangb2cdd932017-01-19 16:54:25 -08002038 rtcp_dtls_transport = transport_controller->CreateDtlsTransport(
zhihuangf5b251b2017-01-12 19:37:48 -08002039 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
2040 }
zhihuangb2cdd932017-01-19 16:54:25 -08002041 if (!channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 delete channel;
2043 channel = NULL;
2044 }
2045 return channel;
2046}
2047
2048// override to add 0 parameter
2049template<>
2050bool ChannelTest<VideoTraits>::AddStream1(int id) {
2051 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2052}
2053
2054template<>
2055void ChannelTest<VideoTraits>::CreateContent(
2056 int flags,
2057 const cricket::AudioCodec& audio_codec,
2058 const cricket::VideoCodec& video_codec,
2059 cricket::VideoContentDescription* video) {
2060 video->AddCodec(video_codec);
2061 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2062 if (flags & SECURE) {
2063 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002064 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2065 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066 }
2067}
2068
2069template<>
2070void ChannelTest<VideoTraits>::CopyContent(
2071 const cricket::VideoContentDescription& source,
2072 cricket::VideoContentDescription* video) {
2073 *video = source;
2074}
2075
2076template<>
2077bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2078 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002079 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080}
2081
Peter Boström0c4e06b2015-10-07 12:23:21 +02002082template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002084 uint32_t ssrc,
2085 int flags,
2086 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 video->AddLegacyStream(ssrc);
2088}
2089
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002090class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 public:
solenberg1dd98f32015-09-10 01:57:14 -07002092 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002093 VideoChannelSingleThreadTest()
2094 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095};
2096
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002097class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2098 public:
2099 typedef ChannelTest<VideoTraits> Base;
2100 VideoChannelDoubleThreadTest()
2101 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2102};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002104// VoiceChannelSingleThreadTest
2105TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 Base::TestInit();
2107 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2108 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2109}
2110
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002111TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2112 Base::TestDeinit();
2113}
2114
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002115TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116 Base::TestSetContents();
2117}
2118
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002119TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 Base::TestSetContentsNullOffer();
2121}
2122
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002123TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 Base::TestSetContentsRtcpMux();
2125}
2126
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002127TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 Base::TestSetContentsRtcpMux();
2129}
2130
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002131TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 Base::TestSetRemoteContentUpdate();
2133}
2134
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002135TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 Base::TestStreams();
2137}
2138
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002139TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 Base::TestUpdateStreamsInLocalContent();
2141}
2142
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002143TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 Base::TestUpdateStreamsInRemoteContent();
2145}
2146
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002147TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 Base::TestChangeStreamParamsInContent();
2149}
2150
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002151TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 Base::TestPlayoutAndSendingStates();
2153}
2154
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002155TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002156 CreateChannels(0, 0);
2157 // Test that we can Mute the default channel even though the sending SSRC
2158 // is unknown.
2159 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002160 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002161 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2162 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002163 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2164
2165 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002166 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002167
2168 SendInitiate();
2169 // After the local session description has been set, we can mute a stream
2170 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002171 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002172 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2173 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002174 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175}
2176
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002177TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 Base::TestMediaContentDirection();
2179}
2180
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002181TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002182 Base::TestNetworkRouteChanges();
2183}
2184
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002185TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186 Base::TestCallSetup();
2187}
2188
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002189TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 Base::TestCallTeardownRtcpMux();
2191}
2192
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002193TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 Base::SendRtpToRtp();
2195}
2196
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002197TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198 Base::SendRtcpToRtcp();
2199}
2200
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002201TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202 Base::SendRtcpMuxToRtcp();
2203}
2204
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002205TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 Base::SendRtcpMuxToRtcpMux();
2207}
2208
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002209TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002210 Base::SendRequireRtcpMuxToRtcpMux();
2211}
2212
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002213TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002214 Base::SendRtcpMuxToRequireRtcpMux();
2215}
2216
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002217TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002218 Base::SendRequireRtcpMuxToRequireRtcpMux();
2219}
2220
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002221TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002222 Base::SendRequireRtcpMuxToNoRtcpMux();
2223}
2224
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002225TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 Base::SendEarlyRtcpMuxToRtcp();
2227}
2228
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002229TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 Base::SendEarlyRtcpMuxToRtcpMux();
2231}
2232
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002233TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2235}
2236
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002237TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 Base::SendSrtpToSrtp();
2239}
2240
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002241TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2243}
2244
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002245TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2247 Base::SendSrtpToSrtp(DTLS, 0);
2248}
2249
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002250TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2252 Base::SendSrtpToSrtp(DTLS, DTLS);
2253}
2254
jbauchcb560652016-08-04 05:20:32 -07002255TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2256 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2257 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2258}
2259
2260TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2261 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2262 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2263}
2264
2265TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2266 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2267 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2268}
2269
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002270TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2272 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2273}
2274
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002275TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2277}
2278
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002279TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 Base::SendRtpToRtpOnThread();
2281}
2282
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002283TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 Base::SendSrtpToSrtpOnThread();
2285}
2286
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002287TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 Base::SendWithWritabilityLoss();
2289}
2290
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002291TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 Base::TestMediaMonitor();
2293}
2294
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002296TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 CreateChannels(0, 0);
2298 EXPECT_TRUE(SendInitiate());
2299 EXPECT_TRUE(SendAccept());
2300 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2301
solenberg1d63dd02015-12-02 12:35:09 -08002302 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2303 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2304 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002306 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002308 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002309 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002310 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002311 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002312 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313}
2314
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002315TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 Base::TestSetContentFailure();
2317}
2318
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002319TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320 Base::TestSendTwoOffers();
2321}
2322
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002323TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 Base::TestReceiveTwoOffers();
2325}
2326
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002327TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 Base::TestSendPrAnswer();
2329}
2330
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002331TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 Base::TestReceivePrAnswer();
2333}
2334
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002335TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 Base::TestFlushRtcp();
2337}
2338
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002339TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002340 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341}
2342
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002343TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 Base::TestOnReadyToSend();
2345}
2346
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002347TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 Base::TestOnReadyToSendWithRtcpMux();
2349}
2350
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002352TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002353 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 EXPECT_TRUE(SendInitiate());
2355 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002356 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357
solenberg4bac9c52015-10-09 02:32:53 -07002358 // Default is (1.0).
2359 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2360 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002362 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363
solenberg4bac9c52015-10-09 02:32:53 -07002364 // Set scale to (1.5).
2365 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2366 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2367 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368
solenberg4bac9c52015-10-09 02:32:53 -07002369 // Set scale to (0).
2370 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2371 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2372 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373}
2374
2375// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002376TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002377 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 EXPECT_TRUE(SendInitiate());
2379 EXPECT_TRUE(SendAccept());
2380 EXPECT_TRUE(AddStream1(1));
2381 EXPECT_TRUE(AddStream1(2));
2382
solenberg4bac9c52015-10-09 02:32:53 -07002383 double volume;
2384 // Default is (1.0).
2385 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2386 EXPECT_DOUBLE_EQ(1.0, volume);
2387 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2388 EXPECT_DOUBLE_EQ(1.0, volume);
2389 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2390 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002392 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393
solenberg4bac9c52015-10-09 02:32:53 -07002394 // Set scale to (1.5) for ssrc = 1.
2395 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2396 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2397 EXPECT_DOUBLE_EQ(1.5, volume);
2398 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2399 EXPECT_DOUBLE_EQ(1.0, volume);
2400 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2401 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402
solenberg4bac9c52015-10-09 02:32:53 -07002403 // Set scale to (0) for all ssrcs.
2404 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2405 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2406 EXPECT_DOUBLE_EQ(0.0, volume);
2407 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2408 EXPECT_DOUBLE_EQ(0.0, volume);
2409 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2410 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411}
2412
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002413TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002414 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415}
2416
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002417TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002418 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002419}
2420
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002421TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002422 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002423}
2424
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002425TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002426 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427}
2428
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002429TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002430 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002431}
2432
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002433TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002434 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002435}
2436
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002437// VoiceChannelDoubleThreadTest
2438TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002440 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2441 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442}
2443
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002444TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2445 Base::TestDeinit();
2446}
2447
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002448TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 Base::TestSetContents();
2450}
2451
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002452TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 Base::TestSetContentsNullOffer();
2454}
2455
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002456TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457 Base::TestSetContentsRtcpMux();
2458}
2459
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002460TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461 Base::TestSetContentsRtcpMux();
2462}
2463
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002464TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 Base::TestSetRemoteContentUpdate();
2466}
2467
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002468TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 Base::TestStreams();
2470}
2471
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002472TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473 Base::TestUpdateStreamsInLocalContent();
2474}
2475
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002476TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 Base::TestUpdateStreamsInRemoteContent();
2478}
2479
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002480TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 Base::TestChangeStreamParamsInContent();
2482}
2483
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002484TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 Base::TestPlayoutAndSendingStates();
2486}
2487
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002488TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2489 CreateChannels(0, 0);
2490 // Test that we can Mute the default channel even though the sending SSRC
2491 // is unknown.
2492 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2493 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2494 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2495 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2496 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2497
2498 // Test that we can not mute an unknown SSRC.
2499 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2500
2501 SendInitiate();
2502 // After the local session description has been set, we can mute a stream
2503 // with its SSRC.
2504 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2505 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2506 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2507 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2508}
2509
2510TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2511 Base::TestMediaContentDirection();
2512}
2513
2514TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2515 Base::TestNetworkRouteChanges();
2516}
2517
2518TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2519 Base::TestCallSetup();
2520}
2521
2522TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2523 Base::TestCallTeardownRtcpMux();
2524}
2525
2526TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2527 Base::SendRtpToRtp();
2528}
2529
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002530TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2531 Base::SendRtcpToRtcp();
2532}
2533
2534TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2535 Base::SendRtcpMuxToRtcp();
2536}
2537
2538TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2539 Base::SendRtcpMuxToRtcpMux();
2540}
2541
2542TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2543 Base::SendRequireRtcpMuxToRtcpMux();
2544}
2545
2546TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2547 Base::SendRtcpMuxToRequireRtcpMux();
2548}
2549
2550TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2551 Base::SendRequireRtcpMuxToRequireRtcpMux();
2552}
2553
2554TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2555 Base::SendRequireRtcpMuxToNoRtcpMux();
2556}
2557
2558TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2559 Base::SendEarlyRtcpMuxToRtcp();
2560}
2561
2562TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2563 Base::SendEarlyRtcpMuxToRtcpMux();
2564}
2565
2566TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2567 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2568}
2569
2570TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2571 Base::SendSrtpToSrtp();
2572}
2573
2574TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2575 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2576}
2577
2578TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2579 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2580 Base::SendSrtpToSrtp(DTLS, 0);
2581}
2582
2583TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2584 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2585 Base::SendSrtpToSrtp(DTLS, DTLS);
2586}
2587
jbauchcb560652016-08-04 05:20:32 -07002588TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
2589 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2590 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2591}
2592
2593TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
2594 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2595 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2596}
2597
2598TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
2599 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2600 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2601}
2602
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002603TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2604 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2605 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2606}
2607
2608TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2609 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2610}
2611
2612TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2613 Base::SendRtpToRtpOnThread();
2614}
2615
2616TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2617 Base::SendSrtpToSrtpOnThread();
2618}
2619
2620TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2621 Base::SendWithWritabilityLoss();
2622}
2623
2624TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2625 Base::TestMediaMonitor();
2626}
2627
2628// Test that InsertDtmf properly forwards to the media channel.
2629TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2630 CreateChannels(0, 0);
2631 EXPECT_TRUE(SendInitiate());
2632 EXPECT_TRUE(SendAccept());
2633 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2634
2635 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2636 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2637 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2638
2639 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2640 EXPECT_TRUE(
2641 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2642 EXPECT_TRUE(
2643 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2644 EXPECT_TRUE(
2645 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2646}
2647
2648TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2649 Base::TestSetContentFailure();
2650}
2651
2652TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2653 Base::TestSendTwoOffers();
2654}
2655
2656TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2657 Base::TestReceiveTwoOffers();
2658}
2659
2660TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2661 Base::TestSendPrAnswer();
2662}
2663
2664TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2665 Base::TestReceivePrAnswer();
2666}
2667
2668TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2669 Base::TestFlushRtcp();
2670}
2671
2672TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2673 Base::TestSrtpError(kAudioPts[0]);
2674}
2675
2676TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2677 Base::TestOnReadyToSend();
2678}
2679
2680TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2681 Base::TestOnReadyToSendWithRtcpMux();
2682}
2683
2684// Test that we can scale the output volume properly for 1:1 calls.
2685TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002686 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002687 EXPECT_TRUE(SendInitiate());
2688 EXPECT_TRUE(SendAccept());
2689 double volume;
2690
2691 // Default is (1.0).
2692 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2693 EXPECT_DOUBLE_EQ(1.0, volume);
2694 // invalid ssrc.
2695 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2696
2697 // Set scale to (1.5).
2698 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2699 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2700 EXPECT_DOUBLE_EQ(1.5, volume);
2701
2702 // Set scale to (0).
2703 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2704 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2705 EXPECT_DOUBLE_EQ(0.0, volume);
2706}
2707
2708// Test that we can scale the output volume properly for multiway calls.
2709TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002710 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002711 EXPECT_TRUE(SendInitiate());
2712 EXPECT_TRUE(SendAccept());
2713 EXPECT_TRUE(AddStream1(1));
2714 EXPECT_TRUE(AddStream1(2));
2715
2716 double volume;
2717 // Default is (1.0).
2718 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2719 EXPECT_DOUBLE_EQ(1.0, volume);
2720 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2721 EXPECT_DOUBLE_EQ(1.0, volume);
2722 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2723 EXPECT_DOUBLE_EQ(1.0, volume);
2724 // invalid ssrc.
2725 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2726
2727 // Set scale to (1.5) for ssrc = 1.
2728 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2729 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2730 EXPECT_DOUBLE_EQ(1.5, volume);
2731 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2732 EXPECT_DOUBLE_EQ(1.0, volume);
2733 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2734 EXPECT_DOUBLE_EQ(1.0, volume);
2735
2736 // Set scale to (0) for all ssrcs.
2737 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2738 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2739 EXPECT_DOUBLE_EQ(0.0, volume);
2740 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2741 EXPECT_DOUBLE_EQ(0.0, volume);
2742 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2743 EXPECT_DOUBLE_EQ(0.0, volume);
2744}
2745
2746TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2747 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2748}
2749
2750TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2751 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2752}
2753
2754TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2755 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2756}
2757
2758TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2759 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2760}
2761
2762TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2763 Base::DefaultMaxBitrateIsUnlimited();
2764}
2765
2766TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2767 Base::CanChangeMaxBitrate();
2768}
2769
2770// VideoChannelSingleThreadTest
2771TEST_F(VideoChannelSingleThreadTest, TestInit) {
2772 Base::TestInit();
2773}
2774
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002775TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2776 Base::TestDeinit();
2777}
2778
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002779TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2780 Base::TestSetContents();
2781}
2782
2783TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2784 Base::TestSetContentsNullOffer();
2785}
2786
2787TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2788 Base::TestSetContentsRtcpMux();
2789}
2790
2791TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2792 Base::TestSetContentsRtcpMux();
2793}
2794
2795TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2796 Base::TestSetRemoteContentUpdate();
2797}
2798
2799TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2800 Base::TestStreams();
2801}
2802
2803TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2804 Base::TestUpdateStreamsInLocalContent();
2805}
2806
2807TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2808 Base::TestUpdateStreamsInRemoteContent();
2809}
2810
2811TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2812 Base::TestChangeStreamParamsInContent();
2813}
2814
2815TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2816 Base::TestPlayoutAndSendingStates();
2817}
2818
2819TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002820 CreateChannels(0, 0);
2821 // Test that we can Mute the default channel even though the sending SSRC
2822 // is unknown.
2823 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002824 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002825 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002826 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002827 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2828 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002829 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002830 SendInitiate();
2831 // After the local session description has been set, we can mute a stream
2832 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002833 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002834 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002835 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002836 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837}
2838
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002839TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840 Base::TestMediaContentDirection();
2841}
2842
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002843TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002844 Base::TestNetworkRouteChanges();
2845}
2846
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002847TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002848 Base::TestCallSetup();
2849}
2850
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002851TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852 Base::TestCallTeardownRtcpMux();
2853}
2854
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002855TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 Base::SendRtpToRtp();
2857}
2858
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002859TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002860 Base::SendRtcpToRtcp();
2861}
2862
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002863TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864 Base::SendRtcpMuxToRtcp();
2865}
2866
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002867TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868 Base::SendRtcpMuxToRtcpMux();
2869}
2870
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002871TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002872 Base::SendRequireRtcpMuxToRtcpMux();
2873}
2874
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002875TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002876 Base::SendRtcpMuxToRequireRtcpMux();
2877}
2878
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002879TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002880 Base::SendRequireRtcpMuxToRequireRtcpMux();
2881}
2882
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002883TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002884 Base::SendRequireRtcpMuxToNoRtcpMux();
2885}
2886
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002887TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002888 Base::SendEarlyRtcpMuxToRtcp();
2889}
2890
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002891TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 Base::SendEarlyRtcpMuxToRtcpMux();
2893}
2894
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002895TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 Base::SendSrtpToSrtp();
2897}
2898
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002899TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002900 Base::SendSrtpToSrtp();
2901}
2902
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002903TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002904 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2905 Base::SendSrtpToSrtp(DTLS, 0);
2906}
2907
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002908TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2910 Base::SendSrtpToSrtp(DTLS, DTLS);
2911}
2912
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002913TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2915 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2916}
2917
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002918TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2920}
2921
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002922TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002923 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2924}
2925
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002926TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002927 Base::SendRtpToRtpOnThread();
2928}
2929
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002930TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931 Base::SendSrtpToSrtpOnThread();
2932}
2933
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002934TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002935 Base::SendWithWritabilityLoss();
2936}
2937
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002938TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939 Base::TestMediaMonitor();
2940}
2941
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002942TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002943 Base::TestSetContentFailure();
2944}
2945
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002946TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947 Base::TestSendTwoOffers();
2948}
2949
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002950TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002951 Base::TestReceiveTwoOffers();
2952}
2953
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002954TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955 Base::TestSendPrAnswer();
2956}
2957
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002958TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002959 Base::TestReceivePrAnswer();
2960}
2961
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002962TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002963 Base::TestFlushRtcp();
2964}
2965
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002966TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002967 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002968}
2969
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002970TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002971 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002972}
2973
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002974TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002975 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002976}
2977
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002978TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002979 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002980}
2981
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002982TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002983 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984}
2985
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002986TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002987 Base::TestOnReadyToSend();
2988}
2989
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002990TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991 Base::TestOnReadyToSendWithRtcpMux();
2992}
2993
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002994TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07002995 Base::DefaultMaxBitrateIsUnlimited();
2996}
2997
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002998TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07002999 Base::CanChangeMaxBitrate();
3000}
3001
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003002// VideoChannelDoubleThreadTest
3003TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3004 Base::TestInit();
3005}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003007TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3008 Base::TestDeinit();
3009}
3010
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003011TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3012 Base::TestSetContents();
3013}
3014
3015TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3016 Base::TestSetContentsNullOffer();
3017}
3018
3019TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3020 Base::TestSetContentsRtcpMux();
3021}
3022
3023TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3024 Base::TestSetContentsRtcpMux();
3025}
3026
3027TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3028 Base::TestSetRemoteContentUpdate();
3029}
3030
3031TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3032 Base::TestStreams();
3033}
3034
3035TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3036 Base::TestUpdateStreamsInLocalContent();
3037}
3038
3039TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3040 Base::TestUpdateStreamsInRemoteContent();
3041}
3042
3043TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3044 Base::TestChangeStreamParamsInContent();
3045}
3046
3047TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3048 Base::TestPlayoutAndSendingStates();
3049}
3050
3051TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3052 CreateChannels(0, 0);
3053 // Test that we can Mute the default channel even though the sending SSRC
3054 // is unknown.
3055 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003056 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003057 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003058 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003059 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3060 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003061 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003062 SendInitiate();
3063 // After the local session description has been set, we can mute a stream
3064 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003065 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003066 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003067 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003068 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3069}
3070
3071TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3072 Base::TestMediaContentDirection();
3073}
3074
3075TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3076 Base::TestNetworkRouteChanges();
3077}
3078
3079TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3080 Base::TestCallSetup();
3081}
3082
3083TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3084 Base::TestCallTeardownRtcpMux();
3085}
3086
3087TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3088 Base::SendRtpToRtp();
3089}
3090
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003091TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3092 Base::SendRtcpToRtcp();
3093}
3094
3095TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3096 Base::SendRtcpMuxToRtcp();
3097}
3098
3099TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3100 Base::SendRtcpMuxToRtcpMux();
3101}
3102
3103TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3104 Base::SendRequireRtcpMuxToRtcpMux();
3105}
3106
3107TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3108 Base::SendRtcpMuxToRequireRtcpMux();
3109}
3110
3111TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3112 Base::SendRequireRtcpMuxToRequireRtcpMux();
3113}
3114
3115TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3116 Base::SendRequireRtcpMuxToNoRtcpMux();
3117}
3118
3119TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3120 Base::SendEarlyRtcpMuxToRtcp();
3121}
3122
3123TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3124 Base::SendEarlyRtcpMuxToRtcpMux();
3125}
3126
3127TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3128 Base::SendSrtpToSrtp();
3129}
3130
3131TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3132 Base::SendSrtpToSrtp();
3133}
3134
3135TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3136 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3137 Base::SendSrtpToSrtp(DTLS, 0);
3138}
3139
3140TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3141 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3142 Base::SendSrtpToSrtp(DTLS, DTLS);
3143}
3144
3145TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3146 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3147 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3148}
3149
3150TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3151 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3152}
3153
3154TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3155 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3156}
3157
3158TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3159 Base::SendRtpToRtpOnThread();
3160}
3161
3162TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3163 Base::SendSrtpToSrtpOnThread();
3164}
3165
3166TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3167 Base::SendWithWritabilityLoss();
3168}
3169
3170TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3171 Base::TestMediaMonitor();
3172}
3173
3174TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3175 Base::TestSetContentFailure();
3176}
3177
3178TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3179 Base::TestSendTwoOffers();
3180}
3181
3182TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3183 Base::TestReceiveTwoOffers();
3184}
3185
3186TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3187 Base::TestSendPrAnswer();
3188}
3189
3190TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3191 Base::TestReceivePrAnswer();
3192}
3193
3194TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3195 Base::TestFlushRtcp();
3196}
3197
3198TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3199 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3200}
3201
3202TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3203 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3204}
3205
3206TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3207 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3208}
3209
3210TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3211 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3212}
3213
3214TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3215 Base::TestSrtpError(kVideoPts[0]);
3216}
3217
3218TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3219 Base::TestOnReadyToSend();
3220}
3221
3222TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3223 Base::TestOnReadyToSendWithRtcpMux();
3224}
3225
3226TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3227 Base::DefaultMaxBitrateIsUnlimited();
3228}
3229
3230TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3231 Base::CanChangeMaxBitrate();
3232}
3233
deadbeef953c2ce2017-01-09 14:53:41 -08003234// RtpDataChannelSingleThreadTest
3235class RtpDataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003237 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003238 RtpDataChannelSingleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003239 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3240};
3241
deadbeef953c2ce2017-01-09 14:53:41 -08003242// RtpDataChannelDoubleThreadTest
3243class RtpDataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003244 public:
3245 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003246 RtpDataChannelDoubleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003247 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003248};
3249
3250// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003251template <>
deadbeef953c2ce2017-01-09 14:53:41 -08003252cricket::RtpDataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003253 rtc::Thread* worker_thread,
3254 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003255 cricket::MediaEngineInterface* engine,
3256 cricket::FakeDataMediaChannel* ch,
3257 cricket::TransportController* transport_controller,
jbauchcb560652016-08-04 05:20:32 -07003258 int flags) {
zhihuangf5b251b2017-01-12 19:37:48 -08003259 rtc::Thread* signaling_thread =
3260 transport_controller ? transport_controller->signaling_thread() : nullptr;
deadbeef953c2ce2017-01-09 14:53:41 -08003261 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003262 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA,
deadbeefac22f702017-01-12 21:59:29 -08003263 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07003264 rtc::CryptoOptions crypto_options;
3265 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3266 channel->SetCryptoOptions(crypto_options);
zhihuangb2cdd932017-01-19 16:54:25 -08003267 cricket::DtlsTransportInternal* rtp_dtls_transport =
3268 transport_controller->CreateDtlsTransport(
zhihuangf5b251b2017-01-12 19:37:48 -08003269 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuangb2cdd932017-01-19 16:54:25 -08003270 cricket::DtlsTransportInternal* rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08003271 if (channel->NeedsRtcpTransport()) {
zhihuangb2cdd932017-01-19 16:54:25 -08003272 rtcp_dtls_transport = transport_controller->CreateDtlsTransport(
zhihuangf5b251b2017-01-12 19:37:48 -08003273 channel->content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3274 }
zhihuangb2cdd932017-01-19 16:54:25 -08003275 if (!channel->Init_w(rtp_dtls_transport, rtcp_dtls_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 delete channel;
3277 channel = NULL;
3278 }
3279 return channel;
3280}
3281
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003282template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283void ChannelTest<DataTraits>::CreateContent(
3284 int flags,
3285 const cricket::AudioCodec& audio_codec,
3286 const cricket::VideoCodec& video_codec,
3287 cricket::DataContentDescription* data) {
3288 data->AddCodec(kGoogleDataCodec);
3289 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3290 if (flags & SECURE) {
3291 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003292 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3293 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294 }
3295}
3296
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003297template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003298void ChannelTest<DataTraits>::CopyContent(
3299 const cricket::DataContentDescription& source,
3300 cricket::DataContentDescription* data) {
3301 *data = source;
3302}
3303
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003304template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003305bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3306 const cricket::DataCodec& c2) {
3307 return c1.name == c2.name;
3308}
3309
Peter Boström0c4e06b2015-10-07 12:23:21 +02003310template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003312 uint32_t ssrc,
3313 int flags,
3314 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315 data->AddLegacyStream(ssrc);
3316}
3317
deadbeef953c2ce2017-01-09 14:53:41 -08003318TEST_F(RtpDataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003319 Base::TestInit();
3320 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3321}
3322
deadbeef953c2ce2017-01-09 14:53:41 -08003323TEST_F(RtpDataChannelSingleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003324 Base::TestDeinit();
3325}
3326
deadbeef953c2ce2017-01-09 14:53:41 -08003327TEST_F(RtpDataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 Base::TestSetContents();
3329}
3330
deadbeef953c2ce2017-01-09 14:53:41 -08003331TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003332 Base::TestSetContentsNullOffer();
3333}
3334
deadbeef953c2ce2017-01-09 14:53:41 -08003335TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 Base::TestSetContentsRtcpMux();
3337}
3338
deadbeef953c2ce2017-01-09 14:53:41 -08003339TEST_F(RtpDataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003340 Base::TestSetRemoteContentUpdate();
3341}
3342
deadbeef953c2ce2017-01-09 14:53:41 -08003343TEST_F(RtpDataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003344 Base::TestStreams();
3345}
3346
deadbeef953c2ce2017-01-09 14:53:41 -08003347TEST_F(RtpDataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348 Base::TestUpdateStreamsInLocalContent();
3349}
3350
deadbeef953c2ce2017-01-09 14:53:41 -08003351TEST_F(RtpDataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003352 Base::TestUpdateStreamsInRemoteContent();
3353}
3354
deadbeef953c2ce2017-01-09 14:53:41 -08003355TEST_F(RtpDataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356 Base::TestChangeStreamParamsInContent();
3357}
3358
deadbeef953c2ce2017-01-09 14:53:41 -08003359TEST_F(RtpDataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003360 Base::TestPlayoutAndSendingStates();
3361}
3362
deadbeef953c2ce2017-01-09 14:53:41 -08003363TEST_F(RtpDataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003364 Base::TestMediaContentDirection();
3365}
3366
deadbeef953c2ce2017-01-09 14:53:41 -08003367TEST_F(RtpDataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003368 Base::TestCallSetup();
3369}
3370
deadbeef953c2ce2017-01-09 14:53:41 -08003371TEST_F(RtpDataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003372 Base::TestCallTeardownRtcpMux();
3373}
3374
deadbeef953c2ce2017-01-09 14:53:41 -08003375TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003376 Base::TestOnReadyToSend();
3377}
3378
deadbeef953c2ce2017-01-09 14:53:41 -08003379TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380 Base::TestOnReadyToSendWithRtcpMux();
3381}
3382
deadbeef953c2ce2017-01-09 14:53:41 -08003383TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003384 Base::SendRtpToRtp();
3385}
3386
deadbeef953c2ce2017-01-09 14:53:41 -08003387TEST_F(RtpDataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003388 Base::SendRtcpToRtcp();
3389}
3390
deadbeef953c2ce2017-01-09 14:53:41 -08003391TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392 Base::SendRtcpMuxToRtcp();
3393}
3394
deadbeef953c2ce2017-01-09 14:53:41 -08003395TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 Base::SendRtcpMuxToRtcpMux();
3397}
3398
deadbeef953c2ce2017-01-09 14:53:41 -08003399TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400 Base::SendEarlyRtcpMuxToRtcp();
3401}
3402
deadbeef953c2ce2017-01-09 14:53:41 -08003403TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404 Base::SendEarlyRtcpMuxToRtcpMux();
3405}
3406
deadbeef953c2ce2017-01-09 14:53:41 -08003407TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408 Base::SendSrtpToSrtp();
3409}
3410
deadbeef953c2ce2017-01-09 14:53:41 -08003411TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412 Base::SendSrtpToSrtp();
3413}
3414
deadbeef953c2ce2017-01-09 14:53:41 -08003415TEST_F(RtpDataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3417}
3418
deadbeef953c2ce2017-01-09 14:53:41 -08003419TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420 Base::SendRtpToRtpOnThread();
3421}
3422
deadbeef953c2ce2017-01-09 14:53:41 -08003423TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 Base::SendSrtpToSrtpOnThread();
3425}
3426
deadbeef953c2ce2017-01-09 14:53:41 -08003427TEST_F(RtpDataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 Base::SendWithWritabilityLoss();
3429}
3430
deadbeef953c2ce2017-01-09 14:53:41 -08003431TEST_F(RtpDataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 Base::TestMediaMonitor();
3433}
3434
deadbeef953c2ce2017-01-09 14:53:41 -08003435TEST_F(RtpDataChannelSingleThreadTest, TestSendData) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003436 CreateChannels(0, 0);
3437 EXPECT_TRUE(SendInitiate());
3438 EXPECT_TRUE(SendAccept());
3439
3440 cricket::SendDataParams params;
3441 params.ssrc = 42;
3442 unsigned char data[] = {'f', 'o', 'o'};
3443 rtc::CopyOnWriteBuffer payload(data, 3);
3444 cricket::SendDataResult result;
3445 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3446 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3447 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3448}
3449
deadbeef953c2ce2017-01-09 14:53:41 -08003450TEST_F(RtpDataChannelDoubleThreadTest, TestInit) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003451 Base::TestInit();
3452 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3453}
3454
deadbeef953c2ce2017-01-09 14:53:41 -08003455TEST_F(RtpDataChannelDoubleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003456 Base::TestDeinit();
3457}
3458
deadbeef953c2ce2017-01-09 14:53:41 -08003459TEST_F(RtpDataChannelDoubleThreadTest, TestSetContents) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003460 Base::TestSetContents();
3461}
3462
deadbeef953c2ce2017-01-09 14:53:41 -08003463TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsNullOffer) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003464 Base::TestSetContentsNullOffer();
3465}
3466
deadbeef953c2ce2017-01-09 14:53:41 -08003467TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003468 Base::TestSetContentsRtcpMux();
3469}
3470
deadbeef953c2ce2017-01-09 14:53:41 -08003471TEST_F(RtpDataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003472 Base::TestSetRemoteContentUpdate();
3473}
3474
deadbeef953c2ce2017-01-09 14:53:41 -08003475TEST_F(RtpDataChannelDoubleThreadTest, TestStreams) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003476 Base::TestStreams();
3477}
3478
deadbeef953c2ce2017-01-09 14:53:41 -08003479TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003480 Base::TestUpdateStreamsInLocalContent();
3481}
3482
deadbeef953c2ce2017-01-09 14:53:41 -08003483TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003484 Base::TestUpdateStreamsInRemoteContent();
3485}
3486
deadbeef953c2ce2017-01-09 14:53:41 -08003487TEST_F(RtpDataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003488 Base::TestChangeStreamParamsInContent();
3489}
3490
deadbeef953c2ce2017-01-09 14:53:41 -08003491TEST_F(RtpDataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003492 Base::TestPlayoutAndSendingStates();
3493}
3494
deadbeef953c2ce2017-01-09 14:53:41 -08003495TEST_F(RtpDataChannelDoubleThreadTest, TestMediaContentDirection) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003496 Base::TestMediaContentDirection();
3497}
3498
deadbeef953c2ce2017-01-09 14:53:41 -08003499TEST_F(RtpDataChannelDoubleThreadTest, TestCallSetup) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003500 Base::TestCallSetup();
3501}
3502
deadbeef953c2ce2017-01-09 14:53:41 -08003503TEST_F(RtpDataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003504 Base::TestCallTeardownRtcpMux();
3505}
3506
deadbeef953c2ce2017-01-09 14:53:41 -08003507TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSend) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003508 Base::TestOnReadyToSend();
3509}
3510
deadbeef953c2ce2017-01-09 14:53:41 -08003511TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003512 Base::TestOnReadyToSendWithRtcpMux();
3513}
3514
deadbeef953c2ce2017-01-09 14:53:41 -08003515TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003516 Base::SendRtpToRtp();
3517}
3518
deadbeef953c2ce2017-01-09 14:53:41 -08003519TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003520 Base::SendRtcpToRtcp();
3521}
3522
deadbeef953c2ce2017-01-09 14:53:41 -08003523TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003524 Base::SendRtcpMuxToRtcp();
3525}
3526
deadbeef953c2ce2017-01-09 14:53:41 -08003527TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003528 Base::SendRtcpMuxToRtcpMux();
3529}
3530
deadbeef953c2ce2017-01-09 14:53:41 -08003531TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003532 Base::SendEarlyRtcpMuxToRtcp();
3533}
3534
deadbeef953c2ce2017-01-09 14:53:41 -08003535TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003536 Base::SendEarlyRtcpMuxToRtcpMux();
3537}
3538
deadbeef953c2ce2017-01-09 14:53:41 -08003539TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003540 Base::SendSrtpToSrtp();
3541}
3542
deadbeef953c2ce2017-01-09 14:53:41 -08003543TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003544 Base::SendSrtpToSrtp();
3545}
3546
deadbeef953c2ce2017-01-09 14:53:41 -08003547TEST_F(RtpDataChannelDoubleThreadTest, SendSrtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003548 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3549}
3550
deadbeef953c2ce2017-01-09 14:53:41 -08003551TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003552 Base::SendRtpToRtpOnThread();
3553}
3554
deadbeef953c2ce2017-01-09 14:53:41 -08003555TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003556 Base::SendSrtpToSrtpOnThread();
3557}
3558
deadbeef953c2ce2017-01-09 14:53:41 -08003559TEST_F(RtpDataChannelDoubleThreadTest, SendWithWritabilityLoss) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003560 Base::SendWithWritabilityLoss();
3561}
3562
deadbeef953c2ce2017-01-09 14:53:41 -08003563TEST_F(RtpDataChannelDoubleThreadTest, TestMediaMonitor) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003564 Base::TestMediaMonitor();
3565}
3566
deadbeef953c2ce2017-01-09 14:53:41 -08003567TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568 CreateChannels(0, 0);
3569 EXPECT_TRUE(SendInitiate());
3570 EXPECT_TRUE(SendAccept());
3571
3572 cricket::SendDataParams params;
3573 params.ssrc = 42;
3574 unsigned char data[] = {
3575 'f', 'o', 'o'
3576 };
jbaucheec21bd2016-03-20 06:15:43 -07003577 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578 cricket::SendDataResult result;
3579 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3580 EXPECT_EQ(params.ssrc,
3581 media_channel1_->last_sent_data_params().ssrc);
3582 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3583}
3584
deadbeefbad5dad2017-01-17 18:32:35 -08003585#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3586
3587// Verifies some DCHECKs are in place.
3588// Uses VoiceChannel, but any BaseChannel subclass would work.
3589class BaseChannelDeathTest : public testing::Test {
3590 public:
3591 BaseChannelDeathTest()
3592 : // RTCP mux not required, SRTP required.
3593 voice_channel_(
3594 rtc::Thread::Current(),
3595 rtc::Thread::Current(),
3596 rtc::Thread::Current(),
3597 &fake_media_engine_,
3598 new cricket::FakeVoiceMediaChannel(nullptr,
3599 cricket::AudioOptions()),
3600 cricket::CN_AUDIO,
3601 false,
3602 true) {
zhihuangb2cdd932017-01-19 16:54:25 -08003603 rtp_transport_ = fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003604 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuangb2cdd932017-01-19 16:54:25 -08003605 rtcp_transport_ = fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003606 "foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3607 EXPECT_TRUE(voice_channel_.Init_w(rtp_transport_, rtcp_transport_));
3608 }
3609
3610 protected:
3611 cricket::FakeTransportController fake_transport_controller_;
3612 cricket::FakeMediaEngine fake_media_engine_;
3613 cricket::VoiceChannel voice_channel_;
3614 // Will be cleaned up by FakeTransportController, don't need to worry about
3615 // deleting them in this test.
zhihuangb2cdd932017-01-19 16:54:25 -08003616 cricket::DtlsTransportInternal* rtp_transport_;
3617 cricket::DtlsTransportInternal* rtcp_transport_;
deadbeefbad5dad2017-01-17 18:32:35 -08003618};
3619
3620TEST_F(BaseChannelDeathTest, SetTransportWithNullRtpTransport) {
zhihuangb2cdd932017-01-19 16:54:25 -08003621 cricket::DtlsTransportInternal* new_rtcp_transport =
3622 fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003623 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3624 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, new_rtcp_transport), "");
3625}
3626
3627TEST_F(BaseChannelDeathTest, SetTransportWithMissingRtcpTransport) {
zhihuangb2cdd932017-01-19 16:54:25 -08003628 cricket::DtlsTransportInternal* new_rtp_transport =
3629 fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003630 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3631 EXPECT_DEATH(voice_channel_.SetTransports(new_rtp_transport, nullptr), "");
3632}
3633
3634TEST_F(BaseChannelDeathTest, SetTransportWithUnneededRtcpTransport) {
3635 // Activate RTCP muxing, simulating offer/answer negotiation.
3636 cricket::AudioContentDescription content;
3637 content.set_rtcp_mux(true);
3638 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
3639 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
zhihuangb2cdd932017-01-19 16:54:25 -08003640 cricket::DtlsTransportInternal* new_rtp_transport =
3641 fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003642 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuangb2cdd932017-01-19 16:54:25 -08003643 cricket::DtlsTransportInternal* new_rtcp_transport =
3644 fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003645 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3646 // After muxing is enabled, no RTCP transport should be passed in here.
3647 EXPECT_DEATH(
3648 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3649}
3650
3651// This test will probably go away if/when we move the transport name out of
3652// the transport classes and into their parent classes.
3653TEST_F(BaseChannelDeathTest, SetTransportWithMismatchingTransportNames) {
zhihuangb2cdd932017-01-19 16:54:25 -08003654 cricket::DtlsTransportInternal* new_rtp_transport =
3655 fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003656 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
zhihuangb2cdd932017-01-19 16:54:25 -08003657 cricket::DtlsTransportInternal* new_rtcp_transport =
3658 fake_transport_controller_.CreateDtlsTransport(
deadbeefbad5dad2017-01-17 18:32:35 -08003659 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3660 EXPECT_DEATH(
3661 voice_channel_.SetTransports(new_rtp_transport, new_rtcp_transport), "");
3662}
3663
3664#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3665
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666// TODO(pthatcher): TestSetReceiver?