blob: 57e7afb17946c6077a01c10ee72171f4783e3b82 [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"
deadbeeff5346592017-01-24 21:51:21 -080024#include "webrtc/p2p/base/fakecandidatepair.h"
25#include "webrtc/p2p/base/fakedtlstransport.h"
26#include "webrtc/p2p/base/fakepackettransport.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010027#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029using cricket::CA_OFFER;
30using cricket::CA_PRANSWER;
31using cricket::CA_ANSWER;
32using cricket::CA_UPDATE;
zhihuangb2cdd932017-01-19 16:54:25 -080033using cricket::DtlsTransportInternal;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035using cricket::StreamParams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036
Danil Chapovalov33b01f22016-05-11 19:55:27 +020037namespace {
38const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
39const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
40const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
perkj26752742016-10-24 01:21:16 -070041const cricket::VideoCodec kH264Codec(97, "H264");
42const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC");
Danil Chapovalov33b01f22016-05-11 19:55:27 +020043const cricket::DataCodec kGoogleDataCodec(101, "google-data");
44const uint32_t kSsrc1 = 0x1111;
45const uint32_t kSsrc2 = 0x2222;
46const uint32_t kSsrc3 = 0x3333;
47const int kAudioPts[] = {0, 8};
48const int kVideoPts[] = {97, 99};
49enum class NetworkIsWorker { Yes, No };
deadbeefc6b6e092016-12-01 12:49:20 -080050const int kDefaultTimeout = 10000; // 10 seconds.
Danil Chapovalov33b01f22016-05-11 19:55:27 +020051} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
deadbeefcbecd352015-09-23 11:50:27 -070053template <class ChannelT,
54 class MediaChannelT,
55 class ContentT,
56 class CodecT,
57 class MediaInfoT,
58 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059class Traits {
60 public:
61 typedef ChannelT Channel;
62 typedef MediaChannelT MediaChannel;
63 typedef ContentT Content;
64 typedef CodecT Codec;
65 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020066 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067};
68
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069class VoiceTraits : public Traits<cricket::VoiceChannel,
70 cricket::FakeVoiceMediaChannel,
71 cricket::AudioContentDescription,
72 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020073 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070074 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
76class VideoTraits : public Traits<cricket::VideoChannel,
77 cricket::FakeVideoMediaChannel,
78 cricket::VideoContentDescription,
79 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020080 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070081 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082
deadbeef953c2ce2017-01-09 14:53:41 -080083class DataTraits : public Traits<cricket::RtpDataChannel,
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084 cricket::FakeDataMediaChannel,
85 cricket::DataContentDescription,
86 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020087 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070088 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
deadbeef953c2ce2017-01-09 14:53:41 -080090// Base class for Voice/Video/RtpDataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091template<class T>
92class ChannelTest : public testing::Test, public sigslot::has_slots<> {
93 public:
deadbeefac22f702017-01-12 21:59:29 -080094 enum Flags {
95 RTCP_MUX = 0x1,
96 RTCP_MUX_REQUIRED = 0x2,
97 SECURE = 0x4,
98 SSRC_MUX = 0x8,
99 DTLS = 0x10,
deadbeeff5346592017-01-24 21:51:21 -0800100 GCM_CIPHER = 0x20,
101 // Use BaseChannel with PacketTransportInterface rather than
102 // DtlsTransportInternal.
103 RAW_PACKET_TRANSPORT = 0x40,
deadbeefac22f702017-01-12 21:59:29 -0800104 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
Peter Boström34fbfff2015-09-24 19:20:30 +0200106 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200107 rtc::ArrayView<const uint8_t> rtp_data,
108 rtc::ArrayView<const uint8_t> rtcp_data,
109 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200110 : verify_playout_(verify_playout),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200111 rtp_packet_(rtp_data.data(), rtp_data.size()),
deadbeeff5346592017-01-24 21:51:21 -0800112 rtcp_packet_(rtcp_data.data(), rtcp_data.size()) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200113 if (network_is_worker == NetworkIsWorker::Yes) {
114 network_thread_ = rtc::Thread::Current();
115 } else {
116 network_thread_keeper_ = rtc::Thread::Create();
117 network_thread_keeper_->SetName("Network", nullptr);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200118 network_thread_ = network_thread_keeper_.get();
119 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200120 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200123 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
124 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200125 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000126 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200127 void CreateChannels(typename T::MediaChannel* ch1,
128 typename T::MediaChannel* ch2,
129 int flags1,
130 int flags2) {
deadbeeff5346592017-01-24 21:51:21 -0800131 // Network thread is started in CreateChannels, to allow the test to
132 // configure a fake clock before any threads are spawned and attempt to
133 // access the time.
134 if (network_thread_keeper_) {
135 network_thread_keeper_->Start();
136 }
deadbeefac22f702017-01-12 21:59:29 -0800137 // Make sure RTCP_MUX_REQUIRED isn't set without RTCP_MUX.
deadbeeff5346592017-01-24 21:51:21 -0800138 RTC_DCHECK_NE(RTCP_MUX_REQUIRED, flags1 & (RTCP_MUX | RTCP_MUX_REQUIRED));
139 RTC_DCHECK_NE(RTCP_MUX_REQUIRED, flags2 & (RTCP_MUX | RTCP_MUX_REQUIRED));
140 // Make sure if using raw packet transports, they're used for both
141 // channels.
142 RTC_DCHECK_EQ(flags1 & RAW_PACKET_TRANSPORT, flags2 & RAW_PACKET_TRANSPORT);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200143 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 media_channel1_ = ch1;
145 media_channel2_ = ch2;
deadbeeff5346592017-01-24 21:51:21 -0800146 rtc::PacketTransportInterface* rtp1 = nullptr;
147 rtc::PacketTransportInterface* rtcp1 = nullptr;
148 rtc::PacketTransportInterface* rtp2 = nullptr;
149 rtc::PacketTransportInterface* rtcp2 = nullptr;
150 // Based on flags, create fake DTLS or raw packet transports.
151 if (flags1 & RAW_PACKET_TRANSPORT) {
152 fake_rtp_packet_transport1_.reset(
153 new rtc::FakePacketTransport("channel1_rtp"));
154 rtp1 = fake_rtp_packet_transport1_.get();
155 if (!(flags1 & RTCP_MUX_REQUIRED)) {
156 fake_rtcp_packet_transport1_.reset(
157 new rtc::FakePacketTransport("channel1_rtcp"));
158 rtcp1 = fake_rtcp_packet_transport1_.get();
159 }
160 } else {
161 // Confirmed to work with KT_RSA and KT_ECDSA.
162 fake_rtp_dtls_transport1_.reset(new cricket::FakeDtlsTransport(
163 "channel1", cricket::ICE_CANDIDATE_COMPONENT_RTP));
164 rtp1 = fake_rtp_dtls_transport1_.get();
165 if (!(flags1 & RTCP_MUX_REQUIRED)) {
166 fake_rtcp_dtls_transport1_.reset(new cricket::FakeDtlsTransport(
167 "channel1", cricket::ICE_CANDIDATE_COMPONENT_RTCP));
168 rtcp1 = fake_rtcp_dtls_transport1_.get();
169 }
170 if (flags1 & DTLS) {
171 auto cert1 =
172 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
173 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT)));
174 fake_rtp_dtls_transport1_->SetLocalCertificate(cert1);
175 if (fake_rtcp_dtls_transport1_) {
176 fake_rtcp_dtls_transport1_->SetLocalCertificate(cert1);
177 }
178 }
179 }
180 // Based on flags, create fake DTLS or raw packet transports.
181 if (flags2 & RAW_PACKET_TRANSPORT) {
182 fake_rtp_packet_transport2_.reset(
183 new rtc::FakePacketTransport("channel2_rtp"));
184 rtp2 = fake_rtp_packet_transport2_.get();
185 if (!(flags2 & RTCP_MUX_REQUIRED)) {
186 fake_rtcp_packet_transport2_.reset(
187 new rtc::FakePacketTransport("channel2_rtcp"));
188 rtcp2 = fake_rtcp_packet_transport2_.get();
189 }
190 } else {
191 // Confirmed to work with KT_RSA and KT_ECDSA.
192 fake_rtp_dtls_transport2_.reset(new cricket::FakeDtlsTransport(
193 "channel2", cricket::ICE_CANDIDATE_COMPONENT_RTP));
194 rtp2 = fake_rtp_dtls_transport2_.get();
195 if (!(flags2 & RTCP_MUX_REQUIRED)) {
196 fake_rtcp_dtls_transport2_.reset(new cricket::FakeDtlsTransport(
197 "channel2", cricket::ICE_CANDIDATE_COMPONENT_RTCP));
198 rtcp2 = fake_rtcp_dtls_transport2_.get();
199 }
200 if (flags2 & DTLS) {
201 auto cert2 =
202 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
203 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT)));
204 fake_rtp_dtls_transport2_->SetLocalCertificate(cert2);
205 if (fake_rtcp_dtls_transport2_) {
206 fake_rtcp_dtls_transport2_->SetLocalCertificate(cert2);
207 }
208 }
209 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200210 channel1_.reset(
211 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
deadbeeff5346592017-01-24 21:51:21 -0800212 fake_rtp_dtls_transport1_.get(),
213 fake_rtcp_dtls_transport1_.get(), rtp1, rtcp1, flags1));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200214 channel2_.reset(
215 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
deadbeeff5346592017-01-24 21:51:21 -0800216 fake_rtp_dtls_transport2_.get(),
217 fake_rtcp_dtls_transport2_.get(), rtp2, rtcp2, flags2));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200218 channel1_->SignalMediaMonitor.connect(this,
219 &ChannelTest<T>::OnMediaMonitor1);
220 channel2_->SignalMediaMonitor.connect(this,
221 &ChannelTest<T>::OnMediaMonitor2);
deadbeefac22f702017-01-12 21:59:29 -0800222 channel1_->SignalRtcpMuxFullyActive.connect(
deadbeeff5346592017-01-24 21:51:21 -0800223 this, &ChannelTest<T>::OnRtcpMuxFullyActive1);
deadbeefac22f702017-01-12 21:59:29 -0800224 channel2_->SignalRtcpMuxFullyActive.connect(
deadbeeff5346592017-01-24 21:51:21 -0800225 this, &ChannelTest<T>::OnRtcpMuxFullyActive2);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000226 if ((flags1 & DTLS) && (flags2 & DTLS)) {
227 flags1 = (flags1 & ~SECURE);
228 flags2 = (flags2 & ~SECURE);
229 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 CreateContent(flags1, kPcmuCodec, kH264Codec,
231 &local_media_content1_);
232 CreateContent(flags2, kPcmuCodec, kH264Codec,
233 &local_media_content2_);
234 CopyContent(local_media_content1_, &remote_media_content1_);
235 CopyContent(local_media_content2_, &remote_media_content2_);
236
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 // Add stream information (SSRC) to the local content but not to the remote
238 // content. This means that we per default know the SSRC of what we send but
239 // not what we receive.
240 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
241 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
242
243 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
244 if (flags1 & SSRC_MUX) {
245 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
246 }
247 if (flags2 & SSRC_MUX) {
248 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
249 }
250 }
deadbeefcbecd352015-09-23 11:50:27 -0700251 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200252 rtc::Thread* worker_thread,
253 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700254 cricket::MediaEngineInterface* engine,
255 typename T::MediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -0800256 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
257 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
258 rtc::PacketTransportInterface* fake_rtp_packet_transport,
259 rtc::PacketTransportInterface* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -0700260 int flags) {
deadbeeff5346592017-01-24 21:51:21 -0800261 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef7af91dd2016-12-13 11:29:11 -0800262 typename T::Channel* channel = new typename T::Channel(
zhihuangf5b251b2017-01-12 19:37:48 -0800263 worker_thread, network_thread, signaling_thread, engine, ch,
deadbeefac22f702017-01-12 21:59:29 -0800264 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0,
265 (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -0700266 rtc::CryptoOptions crypto_options;
267 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
268 channel->SetCryptoOptions(crypto_options);
deadbeeff5346592017-01-24 21:51:21 -0800269 if (!channel->NeedsRtcpTransport()) {
270 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -0800271 }
deadbeeff5346592017-01-24 21:51:21 -0800272 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
273 fake_rtp_packet_transport,
274 fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 delete channel;
276 channel = NULL;
277 }
278 return channel;
279 }
280
deadbeeff5346592017-01-24 21:51:21 -0800281 void ConnectFakeTransports() {
282 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
283 bool asymmetric = false;
284 // Depending on test flags, could be using DTLS or raw packet transport.
285 if (fake_rtp_dtls_transport1_ && fake_rtp_dtls_transport2_) {
286 fake_rtp_dtls_transport1_->SetDestination(
287 fake_rtp_dtls_transport2_.get(), asymmetric);
288 }
289 if (fake_rtcp_dtls_transport1_ && fake_rtcp_dtls_transport2_) {
290 fake_rtcp_dtls_transport1_->SetDestination(
291 fake_rtcp_dtls_transport2_.get(), asymmetric);
292 }
293 if (fake_rtp_packet_transport1_ && fake_rtp_packet_transport2_) {
294 fake_rtp_packet_transport1_->SetDestination(
295 fake_rtp_packet_transport2_.get(), asymmetric);
296 }
297 if (fake_rtcp_packet_transport1_ && fake_rtcp_packet_transport2_) {
298 fake_rtcp_packet_transport1_->SetDestination(
299 fake_rtcp_packet_transport2_.get(), asymmetric);
300 }
301 });
302 }
303
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000305 bool result = channel1_->SetLocalContent(&local_media_content1_,
306 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 if (result) {
308 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000309 result = channel2_->SetRemoteContent(&remote_media_content1_,
310 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 if (result) {
deadbeeff5346592017-01-24 21:51:21 -0800312 ConnectFakeTransports();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000313 result = channel2_->SetLocalContent(&local_media_content2_,
314 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 }
316 }
317 return result;
318 }
319
320 bool SendAccept() {
321 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000322 return channel1_->SetRemoteContent(&remote_media_content2_,
323 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 }
325
326 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000327 bool result = channel1_->SetLocalContent(&local_media_content1_,
328 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 if (result) {
330 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000331 result = channel2_->SetRemoteContent(&remote_media_content1_,
332 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
334 return result;
335 }
336
337 bool SendProvisionalAnswer() {
338 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000339 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 if (result) {
341 channel2_->Enable(true);
342 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000343 CA_PRANSWER, NULL);
deadbeeff5346592017-01-24 21:51:21 -0800344 ConnectFakeTransports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
346 return result;
347 }
348
349 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000350 bool result = channel2_->SetLocalContent(&local_media_content2_,
351 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000353 result = channel1_->SetRemoteContent(&remote_media_content2_,
354 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 return result;
356 }
357
deadbeeff5346592017-01-24 21:51:21 -0800358 bool Terminate() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 channel1_.reset();
360 channel2_.reset();
deadbeeff5346592017-01-24 21:51:21 -0800361 fake_rtp_dtls_transport1_.reset();
362 fake_rtcp_dtls_transport1_.reset();
363 fake_rtp_dtls_transport2_.reset();
364 fake_rtcp_dtls_transport2_.reset();
365 fake_rtp_packet_transport1_.reset();
366 fake_rtcp_packet_transport1_.reset();
367 fake_rtp_packet_transport2_.reset();
368 fake_rtcp_packet_transport2_.reset();
369 if (network_thread_keeper_) {
370 network_thread_keeper_.reset();
371 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 return true;
373 }
374
375 bool AddStream1(int id) {
376 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
377 }
378 bool RemoveStream1(int id) {
379 return channel1_->RemoveRecvStream(id);
380 }
381
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200382 void SendRtp1() {
383 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
384 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200386 void SendRtp2() {
387 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
388 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200390 void SendRtcp1() {
391 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200393 void SendRtcp2() {
394 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000395 }
396 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200397 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
398 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
399 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200401 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
402 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
403 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200405 void SendCustomRtcp1(uint32_t ssrc) {
406 rtc::Buffer data = CreateRtcpData(ssrc);
407 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200409 void SendCustomRtcp2(uint32_t ssrc) {
410 rtc::Buffer data = CreateRtcpData(ssrc);
411 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200413
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200415 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 }
417 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200418 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 }
420 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200421 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 }
423 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200424 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 }
426 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200427 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200428 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
429 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200431 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200432 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
433 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200435 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200436 rtc::Buffer data = CreateRtcpData(ssrc);
437 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200439 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200440 rtc::Buffer data = CreateRtcpData(ssrc);
441 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000442 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200443 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
444 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200446 rtc::SetBE32(data.data() + 8, ssrc);
447 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000448 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200449 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000450 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 return data;
452 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200453 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
454 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200456 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 return data;
458 }
459
460 bool CheckNoRtp1() {
461 return media_channel1_->CheckNoRtp();
462 }
463 bool CheckNoRtp2() {
464 return media_channel2_->CheckNoRtp();
465 }
466 bool CheckNoRtcp1() {
467 return media_channel1_->CheckNoRtcp();
468 }
469 bool CheckNoRtcp2() {
470 return media_channel2_->CheckNoRtcp();
471 }
jbauchcb560652016-08-04 05:20:32 -0700472 // Checks that the channel is using GCM iff GCM_CIPHER is set in flags.
473 // Returns true if so.
474 bool CheckGcmCipher(typename T::Channel* channel, int flags) {
475 int suite;
deadbeeff5346592017-01-24 21:51:21 -0800476 cricket::FakeDtlsTransport* transport =
477 (channel == channel1_.get()) ? fake_rtp_dtls_transport1_.get()
478 : fake_rtp_dtls_transport2_.get();
479 RTC_DCHECK(transport);
480 if (!transport->GetSrtpCryptoSuite(&suite)) {
jbauchcb560652016-08-04 05:20:32 -0700481 return false;
482 }
483
484 if (flags & GCM_CIPHER) {
485 return rtc::IsGcmCryptoSuite(suite);
486 } else {
487 return (suite != rtc::SRTP_INVALID_CRYPTO_SUITE &&
488 !rtc::IsGcmCryptoSuite(suite));
489 }
490 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000491
492 void CreateContent(int flags,
493 const cricket::AudioCodec& audio_codec,
494 const cricket::VideoCodec& video_codec,
495 typename T::Content* content) {
496 // overridden in specialized classes
497 }
498 void CopyContent(const typename T::Content& source,
499 typename T::Content* content) {
500 // overridden in specialized classes
501 }
502
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503 // Creates a cricket::SessionDescription with one MediaContent and one stream.
504 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200505 cricket::SessionDescription* CreateSessionDescriptionWithStream(
506 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507 typename T::Content content;
508 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
509 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
510 AddLegacyStreamInContent(ssrc, 0, &content);
511 sdesc->AddContent("DUMMY_CONTENT_NAME",
512 cricket::NS_JINGLE_RTP, content.Copy());
513 return sdesc;
514 }
515
ossu292d6582016-03-17 02:31:13 -0700516 // Will manage the lifetime of a CallThread, making sure it's
517 // destroyed before this object goes out of scope.
518 class ScopedCallThread {
519 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200520 template <class FunctorT>
521 ScopedCallThread(const FunctorT& functor)
522 : thread_(rtc::Thread::Create()),
523 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700524 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700525 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700526 }
527
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200528 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700529
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200530 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700531
532 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200533 std::unique_ptr<rtc::Thread> thread_;
534 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700535 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
538 return false; // overridden in specialized classes
539 }
540
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200541 void OnMediaMonitor1(typename T::Channel* channel,
542 const typename T::MediaInfo& info) {
543 RTC_DCHECK_EQ(channel, channel1_.get());
544 media_info_callbacks1_++;
545 }
546 void OnMediaMonitor2(typename T::Channel* channel,
547 const typename T::MediaInfo& info) {
548 RTC_DCHECK_EQ(channel, channel2_.get());
549 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 }
deadbeeff5346592017-01-24 21:51:21 -0800551 void OnRtcpMuxFullyActive1(const std::string&) {
552 rtcp_mux_activated_callbacks1_++;
553 }
554 void OnRtcpMuxFullyActive2(const std::string&) {
555 rtcp_mux_activated_callbacks2_++;
556 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557
Honghai Zhangcc411c02016-03-29 17:27:21 -0700558 cricket::CandidatePairInterface* last_selected_candidate_pair() {
559 return last_selected_candidate_pair_;
560 }
561
Peter Boström0c4e06b2015-10-07 12:23:21 +0200562 void AddLegacyStreamInContent(uint32_t ssrc,
563 int flags,
564 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 // Base implementation.
566 }
567
568 // Tests that can be used by derived classes.
569
570 // Basic sanity check.
571 void TestInit() {
572 CreateChannels(0, 0);
573 EXPECT_FALSE(channel1_->secure());
574 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200575 if (verify_playout_) {
576 EXPECT_FALSE(media_channel1_->playout());
577 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 EXPECT_TRUE(media_channel1_->codecs().empty());
579 EXPECT_TRUE(media_channel1_->recv_streams().empty());
580 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
581 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
582 }
583
584 // Test that SetLocalContent and SetRemoteContent properly configure
585 // the codecs.
586 void TestSetContents() {
587 CreateChannels(0, 0);
588 typename T::Content content;
589 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000590 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000592 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 ASSERT_EQ(1U, media_channel1_->codecs().size());
594 EXPECT_TRUE(CodecMatches(content.codecs()[0],
595 media_channel1_->codecs()[0]));
596 }
597
598 // Test that SetLocalContent and SetRemoteContent properly deals
599 // with an empty offer.
600 void TestSetContentsNullOffer() {
601 CreateChannels(0, 0);
602 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000603 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604 CreateContent(0, kPcmuCodec, kH264Codec, &content);
605 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000606 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 ASSERT_EQ(1U, media_channel1_->codecs().size());
608 EXPECT_TRUE(CodecMatches(content.codecs()[0],
609 media_channel1_->codecs()[0]));
610 }
611
612 // Test that SetLocalContent and SetRemoteContent properly set RTCP
613 // mux.
614 void TestSetContentsRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -0800615 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 typename T::Content content;
617 CreateContent(0, kPcmuCodec, kH264Codec, &content);
618 // Both sides agree on mux. Should no longer be a separate RTCP channel.
619 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000620 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
621 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000623 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000625 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 }
627
628 // Test that SetLocalContent and SetRemoteContent properly set RTCP
629 // mux when a provisional answer is received.
630 void TestSetContentsRtcpMuxWithPrAnswer() {
deadbeefac22f702017-01-12 21:59:29 -0800631 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 typename T::Content content;
633 CreateContent(0, kPcmuCodec, kH264Codec, &content);
634 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000635 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
636 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800637 // Both sides agree on mux. Should signal RTCP mux as fully activated.
638 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000639 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800640 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000642 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000644 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
645 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800646 EXPECT_EQ(0, rtcp_mux_activated_callbacks2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647 }
648
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 // Test that SetRemoteContent properly deals with a content update.
650 void TestSetRemoteContentUpdate() {
651 CreateChannels(0, 0);
652 typename T::Content content;
deadbeefac22f702017-01-12 21:59:29 -0800653 CreateContent(RTCP_MUX | SECURE, kPcmuCodec, kH264Codec, &content);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000655 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
656 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 ASSERT_EQ(1U, media_channel1_->codecs().size());
658 EXPECT_TRUE(CodecMatches(content.codecs()[0],
659 media_channel1_->codecs()[0]));
660 // Now update with other codecs.
661 typename T::Content update_content;
662 update_content.set_partial(true);
663 CreateContent(0, kIsacCodec, kH264SvcCodec,
664 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000665 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 ASSERT_EQ(1U, media_channel1_->codecs().size());
667 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
668 media_channel1_->codecs()[0]));
669 // Now update without any codecs. This is ignored.
670 typename T::Content empty_content;
671 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000672 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 ASSERT_EQ(1U, media_channel1_->codecs().size());
674 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
675 media_channel1_->codecs()[0]));
676 }
677
678 // Test that Add/RemoveStream properly forward to the media channel.
679 void TestStreams() {
680 CreateChannels(0, 0);
681 EXPECT_TRUE(AddStream1(1));
682 EXPECT_TRUE(AddStream1(2));
683 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
684 EXPECT_TRUE(RemoveStream1(2));
685 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
686 EXPECT_TRUE(RemoveStream1(1));
687 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
688 }
689
690 // Test that SetLocalContent properly handles adding and removing StreamParams
691 // to the local content description.
692 // This test uses the CA_UPDATE action that don't require a full
693 // MediaContentDescription to do an update.
694 void TestUpdateStreamsInLocalContent() {
695 cricket::StreamParams stream1;
696 stream1.groupid = "group1";
697 stream1.id = "stream1";
698 stream1.ssrcs.push_back(kSsrc1);
699 stream1.cname = "stream1_cname";
700
701 cricket::StreamParams stream2;
702 stream2.groupid = "group2";
703 stream2.id = "stream2";
704 stream2.ssrcs.push_back(kSsrc2);
705 stream2.cname = "stream2_cname";
706
707 cricket::StreamParams stream3;
708 stream3.groupid = "group3";
709 stream3.id = "stream3";
710 stream3.ssrcs.push_back(kSsrc3);
711 stream3.cname = "stream3_cname";
712
713 CreateChannels(0, 0);
714 typename T::Content content1;
715 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
716 content1.AddStream(stream1);
717 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000718 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719
720 ASSERT_EQ(1u, media_channel1_->send_streams().size());
721 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
722
723 // Update the local streams by adding another sending stream.
724 // Use a partial updated session description.
725 typename T::Content content2;
726 content2.AddStream(stream2);
727 content2.AddStream(stream3);
728 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000729 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 ASSERT_EQ(3u, media_channel1_->send_streams().size());
731 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
732 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
733 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
734
735 // Update the local streams by removing the first sending stream.
736 // This is done by removing all SSRCS for this particular stream.
737 typename T::Content content3;
738 stream1.ssrcs.clear();
739 content3.AddStream(stream1);
740 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000741 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000742 ASSERT_EQ(2u, media_channel1_->send_streams().size());
743 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
744 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
745
746 // Update the local streams with a stream that does not change.
747 // THe update is ignored.
748 typename T::Content content4;
749 content4.AddStream(stream2);
750 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000751 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 ASSERT_EQ(2u, media_channel1_->send_streams().size());
753 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
754 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
755 }
756
757 // Test that SetRemoteContent properly handles adding and removing
758 // StreamParams to the remote content description.
759 // This test uses the CA_UPDATE action that don't require a full
760 // MediaContentDescription to do an update.
761 void TestUpdateStreamsInRemoteContent() {
762 cricket::StreamParams stream1;
763 stream1.id = "Stream1";
764 stream1.groupid = "1";
765 stream1.ssrcs.push_back(kSsrc1);
766 stream1.cname = "stream1_cname";
767
768 cricket::StreamParams stream2;
769 stream2.id = "Stream2";
770 stream2.groupid = "2";
771 stream2.ssrcs.push_back(kSsrc2);
772 stream2.cname = "stream2_cname";
773
774 cricket::StreamParams stream3;
775 stream3.id = "Stream3";
776 stream3.groupid = "3";
777 stream3.ssrcs.push_back(kSsrc3);
778 stream3.cname = "stream3_cname";
779
780 CreateChannels(0, 0);
781 typename T::Content content1;
782 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
783 content1.AddStream(stream1);
784 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000785 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786
787 ASSERT_EQ(1u, media_channel1_->codecs().size());
788 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
789 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
790
791 // Update the remote streams by adding another sending stream.
792 // Use a partial updated session description.
793 typename T::Content content2;
794 content2.AddStream(stream2);
795 content2.AddStream(stream3);
796 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000797 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
799 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
800 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
801 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
802
803 // Update the remote streams by removing the first stream.
804 // This is done by removing all SSRCS for this particular stream.
805 typename T::Content content3;
806 stream1.ssrcs.clear();
807 content3.AddStream(stream1);
808 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000809 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
811 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
812 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
813
814 // Update the remote streams with a stream that does not change.
815 // The update is ignored.
816 typename T::Content content4;
817 content4.AddStream(stream2);
818 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000819 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
821 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
822 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
823 }
824
825 // Test that SetLocalContent and SetRemoteContent properly
826 // handles adding and removing StreamParams when the action is a full
827 // CA_OFFER / CA_ANSWER.
828 void TestChangeStreamParamsInContent() {
829 cricket::StreamParams stream1;
830 stream1.groupid = "group1";
831 stream1.id = "stream1";
832 stream1.ssrcs.push_back(kSsrc1);
833 stream1.cname = "stream1_cname";
834
835 cricket::StreamParams stream2;
836 stream2.groupid = "group1";
837 stream2.id = "stream2";
838 stream2.ssrcs.push_back(kSsrc2);
839 stream2.cname = "stream2_cname";
840
841 // Setup a call where channel 1 send |stream1| to channel 2.
842 CreateChannels(0, 0);
843 typename T::Content content1;
844 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
845 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000846 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 EXPECT_TRUE(channel1_->Enable(true));
848 EXPECT_EQ(1u, media_channel1_->send_streams().size());
849
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000850 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeeff5346592017-01-24 21:51:21 -0800852 ConnectFakeTransports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853
854 // Channel 2 do not send anything.
855 typename T::Content content2;
856 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000857 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000859 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 EXPECT_TRUE(channel2_->Enable(true));
861 EXPECT_EQ(0u, media_channel2_->send_streams().size());
862
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200863 SendCustomRtp1(kSsrc1, 0);
864 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
866
867 // Let channel 2 update the content by sending |stream2| and enable SRTP.
868 typename T::Content content3;
869 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
870 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000871 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872 ASSERT_EQ(1u, media_channel2_->send_streams().size());
873 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
874
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000875 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
877 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
878
879 // Channel 1 replies but stop sending stream1.
880 typename T::Content content4;
881 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000882 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_EQ(0u, media_channel1_->send_streams().size());
884
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000885 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
887
888 EXPECT_TRUE(channel1_->secure());
889 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200890 SendCustomRtp2(kSsrc2, 0);
891 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
893 }
894
895 // Test that we only start playout and sending at the right times.
896 void TestPlayoutAndSendingStates() {
897 CreateChannels(0, 0);
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 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200907 if (verify_playout_) {
908 EXPECT_FALSE(media_channel1_->playout());
909 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000911 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
912 CA_OFFER, NULL));
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());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000917 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
918 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200919 if (verify_playout_) {
920 EXPECT_FALSE(media_channel2_->playout());
921 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000923 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
924 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200925 if (verify_playout_) {
926 EXPECT_FALSE(media_channel2_->playout());
927 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 EXPECT_FALSE(media_channel2_->sending());
deadbeeff5346592017-01-24 21:51:21 -0800929 ConnectFakeTransports();
Peter Boström34fbfff2015-09-24 19:20:30 +0200930 if (verify_playout_) {
931 EXPECT_TRUE(media_channel1_->playout());
932 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200934 if (verify_playout_) {
935 EXPECT_FALSE(media_channel2_->playout());
936 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 EXPECT_FALSE(media_channel2_->sending());
938 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200939 if (verify_playout_) {
940 EXPECT_TRUE(media_channel2_->playout());
941 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000943 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
944 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200945 if (verify_playout_) {
946 EXPECT_TRUE(media_channel1_->playout());
947 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_TRUE(media_channel1_->sending());
949 }
950
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 // Test that changing the MediaContentDirection in the local and remote
952 // session description start playout and sending at the right time.
953 void TestMediaContentDirection() {
954 CreateChannels(0, 0);
955 typename T::Content content1;
956 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
957 typename T::Content content2;
958 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
959 // Set |content2| to be InActive.
960 content2.set_direction(cricket::MD_INACTIVE);
961
962 EXPECT_TRUE(channel1_->Enable(true));
963 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200964 if (verify_playout_) {
965 EXPECT_FALSE(media_channel1_->playout());
966 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200968 if (verify_playout_) {
969 EXPECT_FALSE(media_channel2_->playout());
970 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 EXPECT_FALSE(media_channel2_->sending());
972
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000973 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
974 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
975 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
976 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800977 ConnectFakeTransports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978
Peter Boström34fbfff2015-09-24 19:20:30 +0200979 if (verify_playout_) {
980 EXPECT_TRUE(media_channel1_->playout());
981 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200983 if (verify_playout_) {
984 EXPECT_FALSE(media_channel2_->playout()); // local InActive
985 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 EXPECT_FALSE(media_channel2_->sending()); // local InActive
987
988 // Update |content2| to be RecvOnly.
989 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000990 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
991 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992
Peter Boström34fbfff2015-09-24 19:20:30 +0200993 if (verify_playout_) {
994 EXPECT_TRUE(media_channel1_->playout());
995 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200997 if (verify_playout_) {
998 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
999 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
1001
1002 // Update |content2| to be SendRecv.
1003 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001004 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
1005 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006
Peter Boström34fbfff2015-09-24 19:20:30 +02001007 if (verify_playout_) {
1008 EXPECT_TRUE(media_channel1_->playout());
1009 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001010 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +02001011 if (verify_playout_) {
1012 EXPECT_TRUE(media_channel2_->playout());
1013 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 EXPECT_TRUE(media_channel2_->sending());
1015 }
1016
Honghai Zhangcc411c02016-03-29 17:27:21 -07001017 // Tests that when the transport channel signals a candidate pair change
1018 // event, the media channel will receive a call on the network route change.
1019 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001020 constexpr uint16_t kLocalNetId = 1;
1021 constexpr uint16_t kRemoteNetId = 2;
1022 constexpr int kLastPacketId = 100;
1023
Honghai Zhangcc411c02016-03-29 17:27:21 -07001024 CreateChannels(0, 0);
1025
Honghai Zhangcc411c02016-03-29 17:27:21 -07001026 typename T::MediaChannel* media_channel1 =
1027 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001028 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -07001029
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001030 media_channel1->set_num_network_route_changes(0);
deadbeeff5346592017-01-24 21:51:21 -08001031 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001032 // The transport channel becomes disconnected.
deadbeeff5346592017-01-24 21:51:21 -08001033 fake_rtp_dtls_transport1_->ice_transport()
1034 ->SignalSelectedCandidatePairChanged(
1035 fake_rtp_dtls_transport1_->ice_transport(), nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001036 });
1037 WaitForThreads();
1038 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -07001039 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001040 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -07001041
deadbeeff5346592017-01-24 21:51:21 -08001042 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, media_channel1,
1043 kLocalNetId, kRemoteNetId,
1044 kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001045 // The transport channel becomes connected.
1046 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
1047 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
deadbeeff5346592017-01-24 21:51:21 -08001048 auto candidate_pair = cricket::FakeCandidatePair::Create(
1049 local_address, kLocalNetId, remote_address, kRemoteNetId);
1050 fake_rtp_dtls_transport1_->ice_transport()
1051 ->SignalSelectedCandidatePairChanged(
1052 fake_rtp_dtls_transport1_->ice_transport(), candidate_pair.get(),
1053 kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001054 });
1055 WaitForThreads();
1056 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -07001057 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001058 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -07001059 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001060 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -07001061 media_channel1->last_network_route().last_sent_packet_id);
michaelt79e05882016-11-08 02:50:09 -08001062 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
1063 EXPECT_EQ(kTransportOverheadPerPacket,
1064 media_channel1->transport_overhead_per_packet());
Honghai Zhangcc411c02016-03-29 17:27:21 -07001065 }
1066
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 // Test setting up a call.
1068 void TestCallSetup() {
1069 CreateChannels(0, 0);
1070 EXPECT_FALSE(channel1_->secure());
1071 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +02001072 if (verify_playout_) {
1073 EXPECT_TRUE(media_channel1_->playout());
1074 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 EXPECT_FALSE(media_channel1_->sending());
1076 EXPECT_TRUE(SendAccept());
1077 EXPECT_FALSE(channel1_->secure());
1078 EXPECT_TRUE(media_channel1_->sending());
1079 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +02001080 if (verify_playout_) {
1081 EXPECT_TRUE(media_channel2_->playout());
1082 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 EXPECT_TRUE(media_channel2_->sending());
1084 EXPECT_EQ(1U, media_channel2_->codecs().size());
1085 }
1086
1087 // Test that we don't crash if packets are sent during call teardown
1088 // when RTCP mux is enabled. This is a regression test against a specific
1089 // race condition that would only occur when a RTCP packet was sent during
1090 // teardown of a channel on which RTCP mux was enabled.
1091 void TestCallTeardownRtcpMux() {
1092 class LastWordMediaChannel : public T::MediaChannel {
1093 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001094 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001096 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1097 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1099 }
1100 };
1101 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
deadbeefac22f702017-01-12 21:59:29 -08001102 RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103 EXPECT_TRUE(SendInitiate());
1104 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001105 EXPECT_TRUE(Terminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 }
1107
1108 // Send voice RTP data to the other side and ensure it gets there.
1109 void SendRtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001110 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 EXPECT_TRUE(SendInitiate());
1112 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001113 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1114 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001115 SendRtp1();
1116 SendRtp2();
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 }
1123
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001124 void TestDeinit() {
deadbeefac22f702017-01-12 21:59:29 -08001125 CreateChannels(0, 0);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001126 EXPECT_TRUE(SendInitiate());
1127 EXPECT_TRUE(SendAccept());
1128 SendRtp1();
1129 SendRtp2();
1130 SendRtcp1();
1131 SendRtcp2();
1132 // Do not wait, destroy channels.
1133 channel1_.reset(nullptr);
1134 channel2_.reset(nullptr);
1135 }
1136
deadbeefac22f702017-01-12 21:59:29 -08001137 // Check that RTCP can be transmitted between both sides.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 void SendRtcpToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001139 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 EXPECT_TRUE(SendInitiate());
1141 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001142 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1143 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001144 SendRtcp1();
1145 SendRtcp2();
1146 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 EXPECT_TRUE(CheckRtcp1());
1148 EXPECT_TRUE(CheckRtcp2());
1149 EXPECT_TRUE(CheckNoRtcp1());
1150 EXPECT_TRUE(CheckNoRtcp2());
1151 }
1152
1153 // Check that RTCP is transmitted if only the initiator supports mux.
1154 void SendRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001155 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 EXPECT_TRUE(SendInitiate());
1157 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001158 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1159 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001160 SendRtcp1();
1161 SendRtcp2();
1162 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001163 EXPECT_TRUE(CheckRtcp1());
1164 EXPECT_TRUE(CheckRtcp2());
1165 EXPECT_TRUE(CheckNoRtcp1());
1166 EXPECT_TRUE(CheckNoRtcp2());
1167 }
1168
1169 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1170 void SendRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001171 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001173 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1174 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
1175 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001177 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1178 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001179 SendRtp1();
1180 SendRtp2();
1181 SendRtcp1();
1182 SendRtcp2();
1183 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184 EXPECT_TRUE(CheckRtp1());
1185 EXPECT_TRUE(CheckRtp2());
1186 EXPECT_TRUE(CheckNoRtp1());
1187 EXPECT_TRUE(CheckNoRtp2());
1188 EXPECT_TRUE(CheckRtcp1());
1189 EXPECT_TRUE(CheckRtcp2());
1190 EXPECT_TRUE(CheckNoRtcp1());
1191 EXPECT_TRUE(CheckNoRtcp2());
1192 }
1193
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001194 // Check that RTP and RTCP are transmitted ok when both sides
1195 // support mux and one the offerer requires mux.
1196 void SendRequireRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001197 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001198 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001199 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1200 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001201 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001202 SendRtp1();
1203 SendRtp2();
1204 SendRtcp1();
1205 SendRtcp2();
1206 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001207 EXPECT_TRUE(CheckRtp1());
1208 EXPECT_TRUE(CheckRtp2());
1209 EXPECT_TRUE(CheckNoRtp1());
1210 EXPECT_TRUE(CheckNoRtp2());
1211 EXPECT_TRUE(CheckRtcp1());
1212 EXPECT_TRUE(CheckRtcp2());
1213 EXPECT_TRUE(CheckNoRtcp1());
1214 EXPECT_TRUE(CheckNoRtcp2());
1215 }
1216
1217 // Check that RTP and RTCP are transmitted ok when both sides
deadbeefac22f702017-01-12 21:59:29 -08001218 // support mux and only the answerer requires rtcp mux.
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001219 void SendRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001220 CreateChannels(RTCP_MUX, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001221 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001222 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1223 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
1224 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001225 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001226 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1227 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001228 SendRtp1();
1229 SendRtp2();
1230 SendRtcp1();
1231 SendRtcp2();
1232 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001233 EXPECT_TRUE(CheckRtp1());
1234 EXPECT_TRUE(CheckRtp2());
1235 EXPECT_TRUE(CheckNoRtp1());
1236 EXPECT_TRUE(CheckNoRtp2());
1237 EXPECT_TRUE(CheckRtcp1());
1238 EXPECT_TRUE(CheckRtcp2());
1239 EXPECT_TRUE(CheckNoRtcp1());
1240 EXPECT_TRUE(CheckNoRtcp2());
1241 }
1242
1243 // Check that RTP and RTCP are transmitted ok when both sides
1244 // require mux.
1245 void SendRequireRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001246 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001247 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001248 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1249 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001250 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001251 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001252 SendRtp1();
1253 SendRtp2();
1254 SendRtcp1();
1255 SendRtcp2();
1256 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001257 EXPECT_TRUE(CheckRtp1());
1258 EXPECT_TRUE(CheckRtp2());
1259 EXPECT_TRUE(CheckNoRtp1());
1260 EXPECT_TRUE(CheckNoRtp2());
1261 EXPECT_TRUE(CheckRtcp1());
1262 EXPECT_TRUE(CheckRtcp2());
1263 EXPECT_TRUE(CheckNoRtcp1());
1264 EXPECT_TRUE(CheckNoRtcp2());
1265 }
1266
1267 // Check that SendAccept fails if the answerer doesn't support mux
1268 // and the offerer requires it.
1269 void SendRequireRtcpMuxToNoRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001270 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, 0);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001271 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001272 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1273 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001274 EXPECT_FALSE(SendAccept());
1275 }
1276
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 // Check that RTCP data sent by the initiator before the accept is not muxed.
1278 void SendEarlyRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001279 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001281 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1282 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283
1284 // RTCP can be sent before the call is accepted, if the transport is ready.
1285 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001286 SendRtcp1();
1287 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 EXPECT_TRUE(CheckNoRtp2());
1289 EXPECT_TRUE(CheckRtcp2());
1290
1291 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001292 SendRtcp2();
1293 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 EXPECT_TRUE(CheckNoRtp1());
1295 EXPECT_TRUE(CheckRtcp1());
1296
1297 // Complete call setup and ensure everything is still OK.
1298 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001299 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001300 SendRtcp1();
1301 SendRtcp2();
1302 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 EXPECT_TRUE(CheckRtcp1());
1305 }
1306
1307
1308 // Check that RTCP data is not muxed until both sides have enabled muxing,
1309 // but that we properly demux before we get the accept message, since there
1310 // is a race between RTP data and the jingle accept.
1311 void SendEarlyRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001312 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001314 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1315 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316
1317 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1318 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001319 SendRtcp1();
1320 WaitForThreads();
1321 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322
1323 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001324 SendRtcp2();
1325 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 EXPECT_TRUE(CheckNoRtp1());
1327 EXPECT_TRUE(CheckRtcp1());
1328
1329 // Complete call setup and ensure everything is still OK.
deadbeeff5346592017-01-24 21:51:21 -08001330 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001331 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001332 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1333 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001334 SendRtcp1();
1335 SendRtcp2();
1336 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 EXPECT_TRUE(CheckRtcp1());
1339 }
1340
1341 // Test that we properly send SRTP with RTCP in both directions.
deadbeeff5346592017-01-24 21:51:21 -08001342 // You can pass in DTLS, RTCP_MUX, GCM_CIPHER and RAW_PACKET_TRANSPORT as
1343 // flags.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
deadbeeff5346592017-01-24 21:51:21 -08001345 RTC_CHECK((flags1_in &
1346 ~(RTCP_MUX | DTLS | GCM_CIPHER | RAW_PACKET_TRANSPORT)) == 0);
1347 RTC_CHECK((flags2_in &
1348 ~(RTCP_MUX | DTLS | GCM_CIPHER | RAW_PACKET_TRANSPORT)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349
deadbeefac22f702017-01-12 21:59:29 -08001350 int flags1 = SECURE | flags1_in;
1351 int flags2 = SECURE | flags2_in;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 bool dtls1 = !!(flags1_in & DTLS);
1353 bool dtls2 = !!(flags2_in & DTLS);
1354 CreateChannels(flags1, flags2);
1355 EXPECT_FALSE(channel1_->secure());
1356 EXPECT_FALSE(channel2_->secure());
1357 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001358 WaitForThreads();
1359 EXPECT_TRUE(channel1_->writable());
1360 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 EXPECT_TRUE(SendAccept());
1362 EXPECT_TRUE(channel1_->secure());
1363 EXPECT_TRUE(channel2_->secure());
1364 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1365 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
jbauchcb560652016-08-04 05:20:32 -07001366 // We can only query the negotiated cipher suite for DTLS-SRTP transport
1367 // channels.
1368 if (dtls1 && dtls2) {
1369 // A GCM cipher is only used if both channels support GCM ciphers.
1370 int common_gcm_flags = flags1 & flags2 & GCM_CIPHER;
1371 EXPECT_TRUE(CheckGcmCipher(channel1_.get(), common_gcm_flags));
1372 EXPECT_TRUE(CheckGcmCipher(channel2_.get(), common_gcm_flags));
1373 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001374 SendRtp1();
1375 SendRtp2();
1376 SendRtcp1();
1377 SendRtcp2();
1378 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 EXPECT_TRUE(CheckRtp1());
1380 EXPECT_TRUE(CheckRtp2());
1381 EXPECT_TRUE(CheckNoRtp1());
1382 EXPECT_TRUE(CheckNoRtp2());
1383 EXPECT_TRUE(CheckRtcp1());
1384 EXPECT_TRUE(CheckRtcp2());
1385 EXPECT_TRUE(CheckNoRtcp1());
1386 EXPECT_TRUE(CheckNoRtcp2());
1387 }
1388
1389 // Test that we properly handling SRTP negotiating down to RTP.
1390 void SendSrtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001391 CreateChannels(SECURE, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392 EXPECT_FALSE(channel1_->secure());
1393 EXPECT_FALSE(channel2_->secure());
1394 EXPECT_TRUE(SendInitiate());
1395 EXPECT_TRUE(SendAccept());
1396 EXPECT_FALSE(channel1_->secure());
1397 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001398 SendRtp1();
1399 SendRtp2();
1400 SendRtcp1();
1401 SendRtcp2();
1402 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 EXPECT_TRUE(CheckRtp1());
1404 EXPECT_TRUE(CheckRtp2());
1405 EXPECT_TRUE(CheckNoRtp1());
1406 EXPECT_TRUE(CheckNoRtp2());
1407 EXPECT_TRUE(CheckRtcp1());
1408 EXPECT_TRUE(CheckRtcp2());
1409 EXPECT_TRUE(CheckNoRtcp1());
1410 EXPECT_TRUE(CheckNoRtcp2());
1411 }
1412
1413 // Test that we can send and receive early media when a provisional answer is
1414 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1415 void SendEarlyMediaUsingRtcpMuxSrtp() {
1416 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1417
deadbeefac22f702017-01-12 21:59:29 -08001418 CreateChannels(SSRC_MUX | RTCP_MUX | SECURE,
1419 SSRC_MUX | RTCP_MUX | SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 EXPECT_TRUE(SendOffer());
1421 EXPECT_TRUE(SendProvisionalAnswer());
1422 EXPECT_TRUE(channel1_->secure());
1423 EXPECT_TRUE(channel2_->secure());
deadbeeff5346592017-01-24 21:51:21 -08001424 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1425 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001426 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1427 SendCustomRtcp1(kSsrc1);
1428 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1429 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001431 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1432
1433 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001434 SendCustomRtcp2(kSsrc2);
1435 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1436 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1439
1440 // Complete call setup and ensure everything is still OK.
deadbeeff5346592017-01-24 21:51:21 -08001441 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
1442 EXPECT_EQ(0, rtcp_mux_activated_callbacks2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 EXPECT_TRUE(SendFinalAnswer());
deadbeeff5346592017-01-24 21:51:21 -08001444 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1445 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
1446 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
1447 EXPECT_EQ(1, rtcp_mux_activated_callbacks2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 EXPECT_TRUE(channel1_->secure());
1449 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001450 SendCustomRtcp1(kSsrc1);
1451 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1452 SendCustomRtcp2(kSsrc2);
1453 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1454 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001457 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1459 }
1460
1461 // Test that we properly send RTP without SRTP from a thread.
1462 void SendRtpToRtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001463 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_TRUE(SendInitiate());
1465 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001466 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1467 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1468 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1469 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1470 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1471 send_rtcp1.thread(),
1472 send_rtcp2.thread()};
1473 WaitForThreads(involved_threads);
1474 EXPECT_TRUE(CheckRtp1());
1475 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001476 EXPECT_TRUE(CheckNoRtp1());
1477 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001478 EXPECT_TRUE(CheckRtcp1());
1479 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 EXPECT_TRUE(CheckNoRtcp1());
1481 EXPECT_TRUE(CheckNoRtcp2());
1482 }
1483
1484 // Test that we properly send SRTP with RTCP from a thread.
1485 void SendSrtpToSrtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001486 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487 EXPECT_TRUE(SendInitiate());
1488 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001489 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1490 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1491 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1492 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1493 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1494 send_rtcp1.thread(),
1495 send_rtcp2.thread()};
1496 WaitForThreads(involved_threads);
1497 EXPECT_TRUE(CheckRtp1());
1498 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 EXPECT_TRUE(CheckNoRtp1());
1500 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001501 EXPECT_TRUE(CheckRtcp1());
1502 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 EXPECT_TRUE(CheckNoRtcp1());
1504 EXPECT_TRUE(CheckNoRtcp2());
1505 }
1506
1507 // Test that the mediachannel retains its sending state after the transport
1508 // becomes non-writable.
1509 void SendWithWritabilityLoss() {
deadbeefac22f702017-01-12 21:59:29 -08001510 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001511 EXPECT_TRUE(SendInitiate());
1512 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001513 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1514 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001515 SendRtp1();
1516 SendRtp2();
1517 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 EXPECT_TRUE(CheckRtp1());
1519 EXPECT_TRUE(CheckRtp2());
1520 EXPECT_TRUE(CheckNoRtp1());
1521 EXPECT_TRUE(CheckNoRtp2());
1522
wu@webrtc.org97077a32013-10-25 21:18:33 +00001523 // Lose writability, which should fail.
deadbeeff5346592017-01-24 21:51:21 -08001524 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1525 fake_rtp_dtls_transport1_->SetWritable(false);
1526 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001527 SendRtp1();
1528 SendRtp2();
1529 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 EXPECT_TRUE(CheckRtp1());
1531 EXPECT_TRUE(CheckNoRtp2());
1532
1533 // Regain writability
deadbeeff5346592017-01-24 21:51:21 -08001534 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1535 fake_rtp_dtls_transport1_->SetWritable(true);
1536 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001538 SendRtp1();
1539 SendRtp2();
1540 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541 EXPECT_TRUE(CheckRtp1());
1542 EXPECT_TRUE(CheckRtp2());
1543 EXPECT_TRUE(CheckNoRtp1());
1544 EXPECT_TRUE(CheckNoRtp2());
1545
1546 // Lose writability completely
deadbeeff5346592017-01-24 21:51:21 -08001547 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1548 bool asymmetric = true;
1549 fake_rtp_dtls_transport1_->SetDestination(nullptr, asymmetric);
1550 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 EXPECT_TRUE(media_channel1_->sending());
1552
wu@webrtc.org97077a32013-10-25 21:18:33 +00001553 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001554 SendRtp1();
1555 SendRtp2();
1556 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 EXPECT_TRUE(CheckRtp1());
1558 EXPECT_TRUE(CheckNoRtp2());
zhihuangb2cdd932017-01-19 16:54:25 -08001559 EXPECT_TRUE(CheckNoRtp1());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560
1561 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001562 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeeff5346592017-01-24 21:51:21 -08001563 bool asymmetric = true;
1564 fake_rtp_dtls_transport1_->SetDestination(fake_rtp_dtls_transport2_.get(),
1565 asymmetric);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001566 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001568 SendRtp1();
1569 SendRtp2();
1570 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 EXPECT_TRUE(CheckRtp1());
1572 EXPECT_TRUE(CheckRtp2());
1573 EXPECT_TRUE(CheckNoRtp1());
1574 EXPECT_TRUE(CheckNoRtp2());
1575 }
1576
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001577 void SendBundleToBundle(
1578 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1579 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001581 // Only pl_type1 was added to the bundle filter for both |channel1_|
1582 // and |channel2_|.
1583 int pl_type1 = pl_types[0];
1584 int pl_type2 = pl_types[1];
deadbeefac22f702017-01-12 21:59:29 -08001585 int flags = SSRC_MUX;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001586 if (secure) flags |= SECURE;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001587 if (rtcp_mux) {
1588 flags |= RTCP_MUX;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001589 }
1590 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001592 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1593 EXPECT_EQ(rtcp_mux, !channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001595 EXPECT_EQ(rtcp_mux, !channel1_->NeedsRtcpTransport());
1596 EXPECT_EQ(rtcp_mux, !channel2_->NeedsRtcpTransport());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001597 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1598 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1599 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1600 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001601
1602 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001603 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1604 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1605 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001606 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001607 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1608 EXPECT_TRUE(CheckNoRtp1());
1609 EXPECT_TRUE(CheckNoRtp2());
1610
1611 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001612 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1613 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1614 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001615 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001616 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1617
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001618 SendCustomRtcp1(kSsrc1);
1619 SendCustomRtcp2(kSsrc2);
1620 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1622 EXPECT_TRUE(CheckNoRtcp1());
1623 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1624 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001626 SendCustomRtcp1(kSsrc2);
1627 SendCustomRtcp2(kSsrc1);
1628 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001629 // Bundle filter shouldn't filter out any RTCP.
1630 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1631 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 }
1633
deadbeefc6b6e092016-12-01 12:49:20 -08001634 // Test that the media monitor can be run and gives callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 void TestMediaMonitor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 CreateChannels(0, 0);
1637 EXPECT_TRUE(SendInitiate());
1638 EXPECT_TRUE(SendAccept());
1639 channel1_->StartMediaMonitor(100);
1640 channel2_->StartMediaMonitor(100);
1641 // Ensure we get callbacks and stop.
deadbeefc6b6e092016-12-01 12:49:20 -08001642 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
1643 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 channel1_->StopMediaMonitor();
1645 channel2_->StopMediaMonitor();
1646 // Ensure a restart of a stopped monitor works.
1647 channel1_->StartMediaMonitor(100);
deadbeefc6b6e092016-12-01 12:49:20 -08001648 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 channel1_->StopMediaMonitor();
1650 // Ensure stopping a stopped monitor is OK.
1651 channel1_->StopMediaMonitor();
1652 }
1653
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 void TestSetContentFailure() {
1655 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656
Peter Thatchera6d24442015-07-09 21:26:36 -07001657 auto sdesc = cricket::SessionDescription();
1658 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1659 new cricket::AudioContentDescription());
1660 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1661 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662
Peter Thatchera6d24442015-07-09 21:26:36 -07001663 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001665 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1666 &sdesc, cricket::CA_OFFER, &err));
1667 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1668 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001669
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001671 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1672 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001674 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1675 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 }
1677
1678 void TestSendTwoOffers() {
1679 CreateChannels(0, 0);
1680
Peter Thatchera6d24442015-07-09 21:26:36 -07001681 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001682 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001683 CreateSessionDescriptionWithStream(1));
1684 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1685 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1687
kwiberg31022942016-03-11 14:18:21 -08001688 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001689 CreateSessionDescriptionWithStream(2));
1690 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1691 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1693 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1694 }
1695
1696 void TestReceiveTwoOffers() {
1697 CreateChannels(0, 0);
1698
Peter Thatchera6d24442015-07-09 21:26:36 -07001699 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001700 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001701 CreateSessionDescriptionWithStream(1));
1702 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1703 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1705
kwiberg31022942016-03-11 14:18:21 -08001706 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001707 CreateSessionDescriptionWithStream(2));
1708 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1709 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1711 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1712 }
1713
1714 void TestSendPrAnswer() {
1715 CreateChannels(0, 0);
1716
Peter Thatchera6d24442015-07-09 21:26:36 -07001717 std::string err;
1718 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001719 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001720 CreateSessionDescriptionWithStream(1));
1721 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1722 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1724
Peter Thatchera6d24442015-07-09 21:26:36 -07001725 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001726 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001727 CreateSessionDescriptionWithStream(2));
1728 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1729 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1731 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1732
Peter Thatchera6d24442015-07-09 21:26:36 -07001733 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001734 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001735 CreateSessionDescriptionWithStream(3));
1736 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1737 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1739 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1740 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1741 }
1742
1743 void TestReceivePrAnswer() {
1744 CreateChannels(0, 0);
1745
Peter Thatchera6d24442015-07-09 21:26:36 -07001746 std::string err;
1747 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001748 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001749 CreateSessionDescriptionWithStream(1));
1750 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1751 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001752 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1753
Peter Thatchera6d24442015-07-09 21:26:36 -07001754 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001755 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001756 CreateSessionDescriptionWithStream(2));
1757 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1758 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1760 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1761
Peter Thatchera6d24442015-07-09 21:26:36 -07001762 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001763 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001764 CreateSessionDescriptionWithStream(3));
1765 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1766 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1768 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1769 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1770 }
1771
1772 void TestFlushRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001773 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 EXPECT_TRUE(SendInitiate());
1775 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001776 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1777 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778
1779 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001780 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 // The sending message is only posted. channel2_ should be empty.
1782 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001783 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1784 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785
1786 // When channel1_ is deleted, the RTCP packet should be sent out to
1787 // channel2_.
1788 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001789 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 EXPECT_TRUE(CheckRtcp2());
1791 }
1792
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001793 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001794 struct SrtpErrorHandler : public sigslot::has_slots<> {
1795 SrtpErrorHandler() :
1796 mode_(cricket::SrtpFilter::UNPROTECT),
1797 error_(cricket::SrtpFilter::ERROR_NONE) {}
1798 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1799 cricket::SrtpFilter::Error error) {
1800 mode_ = mode;
1801 error_ = error;
1802 }
1803 cricket::SrtpFilter::Mode mode_;
1804 cricket::SrtpFilter::Error error_;
1805 } error_handler;
1806
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001807 // For Audio, only pl_type 0 is added to the bundle filter.
1808 // For Video, only pl_type 97 is added to the bundle filter.
1809 // So we need to pass in pl_type so that the packet can pass through
1810 // the bundle filter before it can be processed by the srtp filter.
1811 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001812 static unsigned const char kBadPacket[] = {
1813 0x84, static_cast<unsigned char>(pl_type),
1814 0x00, 0x01,
1815 0x00, 0x00,
1816 0x00, 0x00,
1817 0x00, 0x00,
1818 0x00, 0x01};
Taylor Brandstetter88532892016-08-01 14:17:27 -07001819
1820 // Using fake clock because this tests that SRTP errors are signaled at
1821 // specific times based on set_signal_silent_time.
1822 rtc::ScopedFakeClock fake_clock;
deadbeeff5346592017-01-24 21:51:21 -08001823
1824 CreateChannels(SECURE, SECURE);
Taylor Brandstetter88532892016-08-01 14:17:27 -07001825 // Some code uses a time of 0 as a special value, so we must start with
1826 // a non-zero time.
1827 // TODO(deadbeef): Fix this.
1828 fake_clock.AdvanceTime(rtc::TimeDelta::FromSeconds(1));
1829
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 EXPECT_FALSE(channel1_->secure());
1831 EXPECT_FALSE(channel2_->secure());
1832 EXPECT_TRUE(SendInitiate());
1833 EXPECT_TRUE(SendAccept());
1834 EXPECT_TRUE(channel1_->secure());
1835 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001836 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001837 channel2_->srtp_filter()->SignalSrtpError.connect(
1838 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839
1840 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001841 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1842 rtc::PacketOptions());
1843 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001845 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001846 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1847 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001848 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1849 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001850 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1851 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001853 WaitForThreads();
Taylor Brandstetter88532892016-08-01 14:17:27 -07001854 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
solenberg5b14b422015-10-01 04:10:31 -07001855 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001856 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1857 // Wait for a little more - the error will be triggered again.
Taylor Brandstetter88532892016-08-01 14:17:27 -07001858 fake_clock.AdvanceTime(rtc::TimeDelta::FromMilliseconds(200));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001859 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1860 rtc::PacketOptions());
1861 WaitForThreads();
1862 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001863 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864
1865 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001866 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001867 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001868
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001869 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeeff5346592017-01-24 21:51:21 -08001870 fake_rtp_dtls_transport2_->SignalReadPacket(
1871 fake_rtp_dtls_transport2_.get(),
1872 reinterpret_cast<const char*>(kBadPacket), sizeof(kBadPacket),
1873 rtc::PacketTime(), 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001874 });
1875 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001876 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
deadbeeff5346592017-01-24 21:51:21 -08001877 // Terminate channels/threads before the fake clock is destroyed.
1878 EXPECT_TRUE(Terminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 }
1880
1881 void TestOnReadyToSend() {
deadbeefac22f702017-01-12 21:59:29 -08001882 CreateChannels(0, 0);
deadbeeff5346592017-01-24 21:51:21 -08001883 cricket::FakeDtlsTransport* rtp = fake_rtp_dtls_transport1_.get();
1884 cricket::FakeDtlsTransport* rtcp = fake_rtcp_dtls_transport1_.get();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001886
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001887 network_thread_->Invoke<void>(RTC_FROM_HERE,
1888 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001889 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001891
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001892 network_thread_->Invoke<void>(RTC_FROM_HERE,
1893 [rtcp] { rtcp->SignalReadyToSend(rtcp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001894 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001895 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1896 // channel are ready to send.
1897 EXPECT_TRUE(media_channel1_->ready_to_send());
1898
1899 // rtp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001900 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1901 channel1_->SetTransportChannelReadyToSend(false, false);
1902 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001903 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001905
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001906 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1907 channel1_->SetTransportChannelReadyToSend(false, true);
1908 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001909 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 EXPECT_TRUE(media_channel1_->ready_to_send());
1911
1912 // rtcp channel becomes not ready to send will be propagated to mediachannel
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001913 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1914 channel1_->SetTransportChannelReadyToSend(true, false);
1915 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001916 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001918
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001919 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1920 channel1_->SetTransportChannelReadyToSend(true, true);
1921 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001922 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923 EXPECT_TRUE(media_channel1_->ready_to_send());
1924 }
1925
1926 void TestOnReadyToSendWithRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001927 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 typename T::Content content;
1929 CreateContent(0, kPcmuCodec, kH264Codec, &content);
deadbeeff5346592017-01-24 21:51:21 -08001930 // Both sides agree on mux. Should signal that RTCP mux is fully active.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001932 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
deadbeeff5346592017-01-24 21:51:21 -08001933 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001934 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -08001935 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
1936 cricket::FakeDtlsTransport* rtp = fake_rtp_dtls_transport1_.get();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 EXPECT_FALSE(media_channel1_->ready_to_send());
1938 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1939 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001940 network_thread_->Invoke<void>(RTC_FROM_HERE,
1941 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001942 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001943 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001944
Taylor Brandstetterbad33bf2016-08-25 13:31:14 -07001945 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1946 channel1_->SetTransportChannelReadyToSend(false, false);
1947 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001948 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001949 EXPECT_FALSE(media_channel1_->ready_to_send());
1950 }
1951
skvladdc1c62c2016-03-16 19:07:43 -07001952 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1953 typename T::Content content;
1954 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1955 content.set_bandwidth(remote_limit);
1956 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1957 }
1958
1959 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1960 webrtc::RtpParameters parameters;
1961 webrtc::RtpEncodingParameters encoding;
1962 encoding.max_bitrate_bps = limit;
1963 parameters.encodings.push_back(encoding);
1964 return parameters;
1965 }
1966
1967 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1968 int expected_bitrate) {
1969 EXPECT_EQ(1UL, parameters.encodings.size());
1970 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1971 }
1972
1973 void DefaultMaxBitrateIsUnlimited() {
1974 CreateChannels(0, 0);
1975 EXPECT_TRUE(
1976 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1977 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001978 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001979 }
1980
1981 void CanChangeMaxBitrate() {
1982 CreateChannels(0, 0);
1983 EXPECT_TRUE(
1984 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1985
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001986 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1987 kSsrc1, BitrateLimitedParameters(1000)));
1988 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1989 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001990 EXPECT_EQ(-1, media_channel1_->max_bps());
1991
1992 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001993 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1994 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1995 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001996 EXPECT_EQ(-1, media_channel1_->max_bps());
1997 }
1998
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001999 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002000 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
2001 static void ProcessThreadQueue(rtc::Thread* thread) {
2002 RTC_DCHECK(thread->IsCurrent());
2003 while (!thread->empty()) {
2004 thread->ProcessMessages(0);
2005 }
2006 }
2007 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
2008 // |threads| and current thread post packets to network thread.
2009 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07002010 thread->Invoke<void>(RTC_FROM_HERE,
2011 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002012 }
2013 ProcessThreadQueue(rtc::Thread::Current());
2014 // Network thread move them around and post back to worker = current thread.
2015 if (!network_thread_->IsCurrent()) {
2016 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07002017 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002018 }
2019 // Worker thread = current Thread process received messages.
2020 ProcessThreadQueue(rtc::Thread::Current());
2021 }
Peter Boström34fbfff2015-09-24 19:20:30 +02002022 // TODO(pbos): Remove playout from all media channels and let renderers mute
2023 // themselves.
2024 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002025 std::unique_ptr<rtc::Thread> network_thread_keeper_;
2026 rtc::Thread* network_thread_;
deadbeeff5346592017-01-24 21:51:21 -08002027 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport1_;
2028 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport1_;
2029 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport2_;
2030 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport2_;
2031 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport1_;
2032 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport1_;
2033 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport2_;
2034 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035 cricket::FakeMediaEngine media_engine_;
2036 // The media channels are owned by the voice channel objects below.
deadbeeff5346592017-01-24 21:51:21 -08002037 typename T::MediaChannel* media_channel1_ = nullptr;
2038 typename T::MediaChannel* media_channel2_ = nullptr;
kwiberg31022942016-03-11 14:18:21 -08002039 std::unique_ptr<typename T::Channel> channel1_;
2040 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 typename T::Content local_media_content1_;
2042 typename T::Content local_media_content2_;
2043 typename T::Content remote_media_content1_;
2044 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002046 rtc::Buffer rtp_packet_;
2047 rtc::Buffer rtcp_packet_;
deadbeeff5346592017-01-24 21:51:21 -08002048 int media_info_callbacks1_ = 0;
2049 int media_info_callbacks2_ = 0;
2050 int rtcp_mux_activated_callbacks1_ = 0;
2051 int rtcp_mux_activated_callbacks2_ = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -07002052 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053};
2054
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055template<>
2056void ChannelTest<VoiceTraits>::CreateContent(
2057 int flags,
2058 const cricket::AudioCodec& audio_codec,
2059 const cricket::VideoCodec& video_codec,
2060 cricket::AudioContentDescription* audio) {
2061 audio->AddCodec(audio_codec);
2062 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
2063 if (flags & SECURE) {
2064 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002065 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2066 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 }
2068}
2069
2070template<>
2071void ChannelTest<VoiceTraits>::CopyContent(
2072 const cricket::AudioContentDescription& source,
2073 cricket::AudioContentDescription* audio) {
2074 *audio = source;
2075}
2076
2077template<>
2078bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2079 const cricket::AudioCodec& c2) {
2080 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2081 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2082}
2083
Peter Boström0c4e06b2015-10-07 12:23:21 +02002084template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002086 uint32_t ssrc,
2087 int flags,
2088 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 audio->AddLegacyStream(ssrc);
2090}
2091
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002092class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 public:
solenberg1dd98f32015-09-10 01:57:14 -07002094 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002095 VoiceChannelSingleThreadTest()
2096 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2097};
2098
2099class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2100 public:
2101 typedef ChannelTest<VoiceTraits> Base;
2102 VoiceChannelDoubleThreadTest()
2103 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104};
2105
2106// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002107template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002109 rtc::Thread* worker_thread,
2110 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002111 cricket::MediaEngineInterface* engine,
2112 cricket::FakeVideoMediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -08002113 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
2114 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
2115 rtc::PacketTransportInterface* fake_rtp_packet_transport,
2116 rtc::PacketTransportInterface* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -07002117 int flags) {
deadbeeff5346592017-01-24 21:51:21 -08002118 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef7af91dd2016-12-13 11:29:11 -08002119 cricket::VideoChannel* channel = new cricket::VideoChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08002120 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO,
deadbeefac22f702017-01-12 21:59:29 -08002121 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07002122 rtc::CryptoOptions crypto_options;
2123 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2124 channel->SetCryptoOptions(crypto_options);
deadbeeff5346592017-01-24 21:51:21 -08002125 if (!channel->NeedsRtcpTransport()) {
2126 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08002127 }
deadbeeff5346592017-01-24 21:51:21 -08002128 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
2129 fake_rtp_packet_transport, fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 delete channel;
2131 channel = NULL;
2132 }
2133 return channel;
2134}
2135
2136// override to add 0 parameter
2137template<>
2138bool ChannelTest<VideoTraits>::AddStream1(int id) {
2139 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2140}
2141
2142template<>
2143void ChannelTest<VideoTraits>::CreateContent(
2144 int flags,
2145 const cricket::AudioCodec& audio_codec,
2146 const cricket::VideoCodec& video_codec,
2147 cricket::VideoContentDescription* video) {
2148 video->AddCodec(video_codec);
2149 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2150 if (flags & SECURE) {
2151 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002152 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2153 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 }
2155}
2156
2157template<>
2158void ChannelTest<VideoTraits>::CopyContent(
2159 const cricket::VideoContentDescription& source,
2160 cricket::VideoContentDescription* video) {
2161 *video = source;
2162}
2163
2164template<>
2165bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2166 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002167 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168}
2169
Peter Boström0c4e06b2015-10-07 12:23:21 +02002170template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002172 uint32_t ssrc,
2173 int flags,
2174 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 video->AddLegacyStream(ssrc);
2176}
2177
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002178class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 public:
solenberg1dd98f32015-09-10 01:57:14 -07002180 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002181 VideoChannelSingleThreadTest()
2182 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183};
2184
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002185class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2186 public:
2187 typedef ChannelTest<VideoTraits> Base;
2188 VideoChannelDoubleThreadTest()
2189 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2190};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002192// VoiceChannelSingleThreadTest
2193TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 Base::TestInit();
2195 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2196 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2197}
2198
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002199TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2200 Base::TestDeinit();
2201}
2202
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002203TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204 Base::TestSetContents();
2205}
2206
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002207TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 Base::TestSetContentsNullOffer();
2209}
2210
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002211TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 Base::TestSetContentsRtcpMux();
2213}
2214
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002215TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216 Base::TestSetContentsRtcpMux();
2217}
2218
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002219TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 Base::TestSetRemoteContentUpdate();
2221}
2222
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002223TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 Base::TestStreams();
2225}
2226
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002227TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 Base::TestUpdateStreamsInLocalContent();
2229}
2230
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002231TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 Base::TestUpdateStreamsInRemoteContent();
2233}
2234
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002235TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236 Base::TestChangeStreamParamsInContent();
2237}
2238
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002239TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240 Base::TestPlayoutAndSendingStates();
2241}
2242
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002243TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002244 CreateChannels(0, 0);
2245 // Test that we can Mute the default channel even though the sending SSRC
2246 // is unknown.
2247 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002248 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002249 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2250 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002251 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2252
2253 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002254 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002255
2256 SendInitiate();
2257 // After the local session description has been set, we can mute a stream
2258 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002259 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002260 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2261 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002262 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263}
2264
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002265TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 Base::TestMediaContentDirection();
2267}
2268
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002269TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002270 Base::TestNetworkRouteChanges();
2271}
2272
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002273TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 Base::TestCallSetup();
2275}
2276
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002277TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 Base::TestCallTeardownRtcpMux();
2279}
2280
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002281TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 Base::SendRtpToRtp();
2283}
2284
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002285TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 Base::SendRtcpToRtcp();
2287}
2288
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002289TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290 Base::SendRtcpMuxToRtcp();
2291}
2292
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002293TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 Base::SendRtcpMuxToRtcpMux();
2295}
2296
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002297TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002298 Base::SendRequireRtcpMuxToRtcpMux();
2299}
2300
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002301TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002302 Base::SendRtcpMuxToRequireRtcpMux();
2303}
2304
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002305TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002306 Base::SendRequireRtcpMuxToRequireRtcpMux();
2307}
2308
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002309TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002310 Base::SendRequireRtcpMuxToNoRtcpMux();
2311}
2312
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002313TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 Base::SendEarlyRtcpMuxToRtcp();
2315}
2316
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002317TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 Base::SendEarlyRtcpMuxToRtcpMux();
2319}
2320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002321TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2323}
2324
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002325TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 Base::SendSrtpToSrtp();
2327}
2328
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002329TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2331}
2332
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002333TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334 Base::SendSrtpToSrtp(DTLS, 0);
2335}
2336
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002337TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 Base::SendSrtpToSrtp(DTLS, DTLS);
2339}
2340
jbauchcb560652016-08-04 05:20:32 -07002341TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
jbauchcb560652016-08-04 05:20:32 -07002342 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2343}
2344
2345TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
jbauchcb560652016-08-04 05:20:32 -07002346 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2347}
2348
2349TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
jbauchcb560652016-08-04 05:20:32 -07002350 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2351}
2352
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002353TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2355}
2356
deadbeeff5346592017-01-24 21:51:21 -08002357// Test using the channel with a raw packet interface, as opposed to a DTLS
2358// transport interface.
2359TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
2360 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
2361}
2362
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002363TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2365}
2366
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002367TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 Base::SendRtpToRtpOnThread();
2369}
2370
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002371TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372 Base::SendSrtpToSrtpOnThread();
2373}
2374
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002375TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 Base::SendWithWritabilityLoss();
2377}
2378
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002379TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 Base::TestMediaMonitor();
2381}
2382
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002384TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 CreateChannels(0, 0);
2386 EXPECT_TRUE(SendInitiate());
2387 EXPECT_TRUE(SendAccept());
2388 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2389
solenberg1d63dd02015-12-02 12:35:09 -08002390 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2391 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2392 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002394 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002396 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002397 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002398 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002399 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002400 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401}
2402
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002403TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 Base::TestSetContentFailure();
2405}
2406
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002407TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 Base::TestSendTwoOffers();
2409}
2410
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002411TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 Base::TestReceiveTwoOffers();
2413}
2414
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002415TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 Base::TestSendPrAnswer();
2417}
2418
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002419TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 Base::TestReceivePrAnswer();
2421}
2422
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002423TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 Base::TestFlushRtcp();
2425}
2426
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002427TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002428 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429}
2430
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002431TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002432 Base::TestOnReadyToSend();
2433}
2434
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002435TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 Base::TestOnReadyToSendWithRtcpMux();
2437}
2438
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002440TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002441 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002442 EXPECT_TRUE(SendInitiate());
2443 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002444 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445
solenberg4bac9c52015-10-09 02:32:53 -07002446 // Default is (1.0).
2447 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2448 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002450 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451
solenberg4bac9c52015-10-09 02:32:53 -07002452 // Set scale to (1.5).
2453 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2454 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2455 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456
solenberg4bac9c52015-10-09 02:32:53 -07002457 // Set scale to (0).
2458 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2459 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2460 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461}
2462
2463// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002464TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002465 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466 EXPECT_TRUE(SendInitiate());
2467 EXPECT_TRUE(SendAccept());
2468 EXPECT_TRUE(AddStream1(1));
2469 EXPECT_TRUE(AddStream1(2));
2470
solenberg4bac9c52015-10-09 02:32:53 -07002471 double volume;
2472 // Default is (1.0).
2473 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2474 EXPECT_DOUBLE_EQ(1.0, volume);
2475 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2476 EXPECT_DOUBLE_EQ(1.0, volume);
2477 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2478 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002480 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481
solenberg4bac9c52015-10-09 02:32:53 -07002482 // Set scale to (1.5) for ssrc = 1.
2483 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2484 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2485 EXPECT_DOUBLE_EQ(1.5, volume);
2486 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2487 EXPECT_DOUBLE_EQ(1.0, volume);
2488 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2489 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490
solenberg4bac9c52015-10-09 02:32:53 -07002491 // Set scale to (0) for all ssrcs.
2492 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2493 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2494 EXPECT_DOUBLE_EQ(0.0, volume);
2495 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2496 EXPECT_DOUBLE_EQ(0.0, volume);
2497 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2498 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499}
2500
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002501TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002502 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503}
2504
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002505TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002506 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002507}
2508
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002509TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002510 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002511}
2512
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002513TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002514 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515}
2516
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002517TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002518 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002519}
2520
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002521TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002522 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002523}
2524
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002525// VoiceChannelDoubleThreadTest
2526TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002528 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2529 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530}
2531
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002532TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2533 Base::TestDeinit();
2534}
2535
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002536TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 Base::TestSetContents();
2538}
2539
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002540TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 Base::TestSetContentsNullOffer();
2542}
2543
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002544TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 Base::TestSetContentsRtcpMux();
2546}
2547
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002548TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 Base::TestSetContentsRtcpMux();
2550}
2551
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002552TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 Base::TestSetRemoteContentUpdate();
2554}
2555
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002556TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 Base::TestStreams();
2558}
2559
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002560TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 Base::TestUpdateStreamsInLocalContent();
2562}
2563
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002564TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 Base::TestUpdateStreamsInRemoteContent();
2566}
2567
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002568TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569 Base::TestChangeStreamParamsInContent();
2570}
2571
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002572TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 Base::TestPlayoutAndSendingStates();
2574}
2575
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002576TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2577 CreateChannels(0, 0);
2578 // Test that we can Mute the default channel even though the sending SSRC
2579 // is unknown.
2580 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2581 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2582 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2583 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2584 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2585
2586 // Test that we can not mute an unknown SSRC.
2587 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2588
2589 SendInitiate();
2590 // After the local session description has been set, we can mute a stream
2591 // with its SSRC.
2592 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2593 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2594 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2595 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2596}
2597
2598TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2599 Base::TestMediaContentDirection();
2600}
2601
2602TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2603 Base::TestNetworkRouteChanges();
2604}
2605
2606TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2607 Base::TestCallSetup();
2608}
2609
2610TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2611 Base::TestCallTeardownRtcpMux();
2612}
2613
2614TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2615 Base::SendRtpToRtp();
2616}
2617
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002618TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2619 Base::SendRtcpToRtcp();
2620}
2621
2622TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2623 Base::SendRtcpMuxToRtcp();
2624}
2625
2626TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2627 Base::SendRtcpMuxToRtcpMux();
2628}
2629
2630TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2631 Base::SendRequireRtcpMuxToRtcpMux();
2632}
2633
2634TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2635 Base::SendRtcpMuxToRequireRtcpMux();
2636}
2637
2638TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2639 Base::SendRequireRtcpMuxToRequireRtcpMux();
2640}
2641
2642TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2643 Base::SendRequireRtcpMuxToNoRtcpMux();
2644}
2645
2646TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2647 Base::SendEarlyRtcpMuxToRtcp();
2648}
2649
2650TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2651 Base::SendEarlyRtcpMuxToRtcpMux();
2652}
2653
2654TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2655 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2656}
2657
2658TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2659 Base::SendSrtpToSrtp();
2660}
2661
2662TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2663 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2664}
2665
2666TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002667 Base::SendSrtpToSrtp(DTLS, 0);
2668}
2669
2670TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002671 Base::SendSrtpToSrtp(DTLS, DTLS);
2672}
2673
jbauchcb560652016-08-04 05:20:32 -07002674TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
jbauchcb560652016-08-04 05:20:32 -07002675 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2676}
2677
2678TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
jbauchcb560652016-08-04 05:20:32 -07002679 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2680}
2681
2682TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
jbauchcb560652016-08-04 05:20:32 -07002683 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2684}
2685
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002686TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002687 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2688}
2689
deadbeeff5346592017-01-24 21:51:21 -08002690// Test using the channel with a raw packet interface, as opposed to a DTLS
2691// transport interface.
2692TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
2693 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
2694}
2695
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002696TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2697 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2698}
2699
2700TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2701 Base::SendRtpToRtpOnThread();
2702}
2703
2704TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2705 Base::SendSrtpToSrtpOnThread();
2706}
2707
2708TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2709 Base::SendWithWritabilityLoss();
2710}
2711
2712TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2713 Base::TestMediaMonitor();
2714}
2715
2716// Test that InsertDtmf properly forwards to the media channel.
2717TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2718 CreateChannels(0, 0);
2719 EXPECT_TRUE(SendInitiate());
2720 EXPECT_TRUE(SendAccept());
2721 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2722
2723 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2724 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2725 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2726
2727 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2728 EXPECT_TRUE(
2729 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2730 EXPECT_TRUE(
2731 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2732 EXPECT_TRUE(
2733 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2734}
2735
2736TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2737 Base::TestSetContentFailure();
2738}
2739
2740TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2741 Base::TestSendTwoOffers();
2742}
2743
2744TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2745 Base::TestReceiveTwoOffers();
2746}
2747
2748TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2749 Base::TestSendPrAnswer();
2750}
2751
2752TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2753 Base::TestReceivePrAnswer();
2754}
2755
2756TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2757 Base::TestFlushRtcp();
2758}
2759
2760TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2761 Base::TestSrtpError(kAudioPts[0]);
2762}
2763
2764TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2765 Base::TestOnReadyToSend();
2766}
2767
2768TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2769 Base::TestOnReadyToSendWithRtcpMux();
2770}
2771
2772// Test that we can scale the output volume properly for 1:1 calls.
2773TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002774 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002775 EXPECT_TRUE(SendInitiate());
2776 EXPECT_TRUE(SendAccept());
2777 double volume;
2778
2779 // Default is (1.0).
2780 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2781 EXPECT_DOUBLE_EQ(1.0, volume);
2782 // invalid ssrc.
2783 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2784
2785 // Set scale to (1.5).
2786 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2787 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2788 EXPECT_DOUBLE_EQ(1.5, volume);
2789
2790 // Set scale to (0).
2791 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2792 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2793 EXPECT_DOUBLE_EQ(0.0, volume);
2794}
2795
2796// Test that we can scale the output volume properly for multiway calls.
2797TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002798 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002799 EXPECT_TRUE(SendInitiate());
2800 EXPECT_TRUE(SendAccept());
2801 EXPECT_TRUE(AddStream1(1));
2802 EXPECT_TRUE(AddStream1(2));
2803
2804 double volume;
2805 // Default is (1.0).
2806 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2807 EXPECT_DOUBLE_EQ(1.0, volume);
2808 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2809 EXPECT_DOUBLE_EQ(1.0, volume);
2810 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2811 EXPECT_DOUBLE_EQ(1.0, volume);
2812 // invalid ssrc.
2813 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2814
2815 // Set scale to (1.5) for ssrc = 1.
2816 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2817 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2818 EXPECT_DOUBLE_EQ(1.5, volume);
2819 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2820 EXPECT_DOUBLE_EQ(1.0, volume);
2821 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2822 EXPECT_DOUBLE_EQ(1.0, volume);
2823
2824 // Set scale to (0) for all ssrcs.
2825 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2826 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2827 EXPECT_DOUBLE_EQ(0.0, volume);
2828 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2829 EXPECT_DOUBLE_EQ(0.0, volume);
2830 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2831 EXPECT_DOUBLE_EQ(0.0, volume);
2832}
2833
2834TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2835 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2836}
2837
2838TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2839 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2840}
2841
2842TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2843 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2844}
2845
2846TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2847 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2848}
2849
2850TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2851 Base::DefaultMaxBitrateIsUnlimited();
2852}
2853
2854TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2855 Base::CanChangeMaxBitrate();
2856}
2857
2858// VideoChannelSingleThreadTest
2859TEST_F(VideoChannelSingleThreadTest, TestInit) {
2860 Base::TestInit();
2861}
2862
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002863TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2864 Base::TestDeinit();
2865}
2866
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002867TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2868 Base::TestSetContents();
2869}
2870
2871TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2872 Base::TestSetContentsNullOffer();
2873}
2874
2875TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2876 Base::TestSetContentsRtcpMux();
2877}
2878
2879TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2880 Base::TestSetContentsRtcpMux();
2881}
2882
2883TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2884 Base::TestSetRemoteContentUpdate();
2885}
2886
2887TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2888 Base::TestStreams();
2889}
2890
2891TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2892 Base::TestUpdateStreamsInLocalContent();
2893}
2894
2895TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2896 Base::TestUpdateStreamsInRemoteContent();
2897}
2898
2899TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2900 Base::TestChangeStreamParamsInContent();
2901}
2902
2903TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2904 Base::TestPlayoutAndSendingStates();
2905}
2906
2907TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002908 CreateChannels(0, 0);
2909 // Test that we can Mute the default channel even though the sending SSRC
2910 // is unknown.
2911 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002912 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002913 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002914 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002915 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2916 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002917 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002918 SendInitiate();
2919 // After the local session description has been set, we can mute a stream
2920 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002921 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002922 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002923 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002924 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002925}
2926
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002927TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928 Base::TestMediaContentDirection();
2929}
2930
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002931TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002932 Base::TestNetworkRouteChanges();
2933}
2934
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002935TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002936 Base::TestCallSetup();
2937}
2938
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002939TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002940 Base::TestCallTeardownRtcpMux();
2941}
2942
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002943TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002944 Base::SendRtpToRtp();
2945}
2946
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002947TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002948 Base::SendRtcpToRtcp();
2949}
2950
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002951TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952 Base::SendRtcpMuxToRtcp();
2953}
2954
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002955TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 Base::SendRtcpMuxToRtcpMux();
2957}
2958
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002959TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002960 Base::SendRequireRtcpMuxToRtcpMux();
2961}
2962
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002963TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002964 Base::SendRtcpMuxToRequireRtcpMux();
2965}
2966
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002967TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002968 Base::SendRequireRtcpMuxToRequireRtcpMux();
2969}
2970
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002971TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002972 Base::SendRequireRtcpMuxToNoRtcpMux();
2973}
2974
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002975TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976 Base::SendEarlyRtcpMuxToRtcp();
2977}
2978
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002979TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002980 Base::SendEarlyRtcpMuxToRtcpMux();
2981}
2982
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002983TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984 Base::SendSrtpToSrtp();
2985}
2986
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002987TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002988 Base::SendSrtpToSrtp();
2989}
2990
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002991TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002992 Base::SendSrtpToSrtp(DTLS, 0);
2993}
2994
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002995TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 Base::SendSrtpToSrtp(DTLS, DTLS);
2997}
2998
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002999TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3001}
3002
deadbeeff5346592017-01-24 21:51:21 -08003003// Test using the channel with a raw packet interface, as opposed to a DTLS
3004// transport interface.
3005TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
3006 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
3007}
3008
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003009TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3011}
3012
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003013TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3015}
3016
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003017TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018 Base::SendRtpToRtpOnThread();
3019}
3020
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003021TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003022 Base::SendSrtpToSrtpOnThread();
3023}
3024
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003025TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026 Base::SendWithWritabilityLoss();
3027}
3028
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003029TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003030 Base::TestMediaMonitor();
3031}
3032
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003033TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 Base::TestSetContentFailure();
3035}
3036
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003037TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038 Base::TestSendTwoOffers();
3039}
3040
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003041TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003042 Base::TestReceiveTwoOffers();
3043}
3044
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003045TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046 Base::TestSendPrAnswer();
3047}
3048
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003049TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050 Base::TestReceivePrAnswer();
3051}
3052
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003053TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003054 Base::TestFlushRtcp();
3055}
3056
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003057TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08003058 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059}
3060
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003061TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003062 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003063}
3064
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003065TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08003066 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003067}
3068
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003069TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003070 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071}
3072
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003073TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003074 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075}
3076
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003077TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078 Base::TestOnReadyToSend();
3079}
3080
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003081TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003082 Base::TestOnReadyToSendWithRtcpMux();
3083}
3084
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003085TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003086 Base::DefaultMaxBitrateIsUnlimited();
3087}
3088
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003089TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003090 Base::CanChangeMaxBitrate();
3091}
3092
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003093// VideoChannelDoubleThreadTest
3094TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3095 Base::TestInit();
3096}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003098TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3099 Base::TestDeinit();
3100}
3101
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003102TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3103 Base::TestSetContents();
3104}
3105
3106TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3107 Base::TestSetContentsNullOffer();
3108}
3109
3110TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3111 Base::TestSetContentsRtcpMux();
3112}
3113
3114TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3115 Base::TestSetContentsRtcpMux();
3116}
3117
3118TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3119 Base::TestSetRemoteContentUpdate();
3120}
3121
3122TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3123 Base::TestStreams();
3124}
3125
3126TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3127 Base::TestUpdateStreamsInLocalContent();
3128}
3129
3130TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3131 Base::TestUpdateStreamsInRemoteContent();
3132}
3133
3134TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3135 Base::TestChangeStreamParamsInContent();
3136}
3137
3138TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3139 Base::TestPlayoutAndSendingStates();
3140}
3141
3142TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3143 CreateChannels(0, 0);
3144 // Test that we can Mute the default channel even though the sending SSRC
3145 // is unknown.
3146 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003147 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003148 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003149 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003150 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3151 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003152 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003153 SendInitiate();
3154 // After the local session description has been set, we can mute a stream
3155 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003156 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003157 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003158 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003159 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3160}
3161
3162TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3163 Base::TestMediaContentDirection();
3164}
3165
3166TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3167 Base::TestNetworkRouteChanges();
3168}
3169
3170TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3171 Base::TestCallSetup();
3172}
3173
3174TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3175 Base::TestCallTeardownRtcpMux();
3176}
3177
3178TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3179 Base::SendRtpToRtp();
3180}
3181
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003182TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3183 Base::SendRtcpToRtcp();
3184}
3185
3186TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3187 Base::SendRtcpMuxToRtcp();
3188}
3189
3190TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3191 Base::SendRtcpMuxToRtcpMux();
3192}
3193
3194TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3195 Base::SendRequireRtcpMuxToRtcpMux();
3196}
3197
3198TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3199 Base::SendRtcpMuxToRequireRtcpMux();
3200}
3201
3202TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3203 Base::SendRequireRtcpMuxToRequireRtcpMux();
3204}
3205
3206TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3207 Base::SendRequireRtcpMuxToNoRtcpMux();
3208}
3209
3210TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3211 Base::SendEarlyRtcpMuxToRtcp();
3212}
3213
3214TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3215 Base::SendEarlyRtcpMuxToRtcpMux();
3216}
3217
3218TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3219 Base::SendSrtpToSrtp();
3220}
3221
3222TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3223 Base::SendSrtpToSrtp();
3224}
3225
3226TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003227 Base::SendSrtpToSrtp(DTLS, 0);
3228}
3229
3230TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003231 Base::SendSrtpToSrtp(DTLS, DTLS);
3232}
3233
3234TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003235 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3236}
3237
deadbeeff5346592017-01-24 21:51:21 -08003238// Test using the channel with a raw packet interface, as opposed to a DTLS
3239// transport interface.
3240TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
3241 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
3242}
3243
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003244TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3245 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3246}
3247
3248TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3249 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3250}
3251
3252TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3253 Base::SendRtpToRtpOnThread();
3254}
3255
3256TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3257 Base::SendSrtpToSrtpOnThread();
3258}
3259
3260TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3261 Base::SendWithWritabilityLoss();
3262}
3263
3264TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3265 Base::TestMediaMonitor();
3266}
3267
3268TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3269 Base::TestSetContentFailure();
3270}
3271
3272TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3273 Base::TestSendTwoOffers();
3274}
3275
3276TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3277 Base::TestReceiveTwoOffers();
3278}
3279
3280TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3281 Base::TestSendPrAnswer();
3282}
3283
3284TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3285 Base::TestReceivePrAnswer();
3286}
3287
3288TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3289 Base::TestFlushRtcp();
3290}
3291
3292TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3293 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3294}
3295
3296TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3297 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3298}
3299
3300TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3301 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3302}
3303
3304TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3305 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3306}
3307
3308TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3309 Base::TestSrtpError(kVideoPts[0]);
3310}
3311
3312TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3313 Base::TestOnReadyToSend();
3314}
3315
3316TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3317 Base::TestOnReadyToSendWithRtcpMux();
3318}
3319
3320TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3321 Base::DefaultMaxBitrateIsUnlimited();
3322}
3323
3324TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3325 Base::CanChangeMaxBitrate();
3326}
3327
deadbeef953c2ce2017-01-09 14:53:41 -08003328// RtpDataChannelSingleThreadTest
3329class RtpDataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003331 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003332 RtpDataChannelSingleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003333 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3334};
3335
deadbeef953c2ce2017-01-09 14:53:41 -08003336// RtpDataChannelDoubleThreadTest
3337class RtpDataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003338 public:
3339 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003340 RtpDataChannelDoubleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003341 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342};
3343
3344// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003345template <>
deadbeef953c2ce2017-01-09 14:53:41 -08003346cricket::RtpDataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003347 rtc::Thread* worker_thread,
3348 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003349 cricket::MediaEngineInterface* engine,
3350 cricket::FakeDataMediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -08003351 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
3352 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
3353 rtc::PacketTransportInterface* fake_rtp_packet_transport,
3354 rtc::PacketTransportInterface* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -07003355 int flags) {
deadbeeff5346592017-01-24 21:51:21 -08003356 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef953c2ce2017-01-09 14:53:41 -08003357 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003358 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA,
deadbeefac22f702017-01-12 21:59:29 -08003359 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07003360 rtc::CryptoOptions crypto_options;
3361 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3362 channel->SetCryptoOptions(crypto_options);
deadbeeff5346592017-01-24 21:51:21 -08003363 if (!channel->NeedsRtcpTransport()) {
3364 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08003365 }
deadbeeff5346592017-01-24 21:51:21 -08003366 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
3367 fake_rtp_packet_transport, fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003368 delete channel;
3369 channel = NULL;
3370 }
3371 return channel;
3372}
3373
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003374template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375void ChannelTest<DataTraits>::CreateContent(
3376 int flags,
3377 const cricket::AudioCodec& audio_codec,
3378 const cricket::VideoCodec& video_codec,
3379 cricket::DataContentDescription* data) {
3380 data->AddCodec(kGoogleDataCodec);
3381 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3382 if (flags & SECURE) {
3383 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003384 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3385 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 }
3387}
3388
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003389template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390void ChannelTest<DataTraits>::CopyContent(
3391 const cricket::DataContentDescription& source,
3392 cricket::DataContentDescription* data) {
3393 *data = source;
3394}
3395
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003396template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3398 const cricket::DataCodec& c2) {
3399 return c1.name == c2.name;
3400}
3401
Peter Boström0c4e06b2015-10-07 12:23:21 +02003402template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003403void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003404 uint32_t ssrc,
3405 int flags,
3406 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003407 data->AddLegacyStream(ssrc);
3408}
3409
deadbeef953c2ce2017-01-09 14:53:41 -08003410TEST_F(RtpDataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411 Base::TestInit();
3412 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3413}
3414
deadbeef953c2ce2017-01-09 14:53:41 -08003415TEST_F(RtpDataChannelSingleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003416 Base::TestDeinit();
3417}
3418
deadbeef953c2ce2017-01-09 14:53:41 -08003419TEST_F(RtpDataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003420 Base::TestSetContents();
3421}
3422
deadbeef953c2ce2017-01-09 14:53:41 -08003423TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003424 Base::TestSetContentsNullOffer();
3425}
3426
deadbeef953c2ce2017-01-09 14:53:41 -08003427TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003428 Base::TestSetContentsRtcpMux();
3429}
3430
deadbeef953c2ce2017-01-09 14:53:41 -08003431TEST_F(RtpDataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003432 Base::TestSetRemoteContentUpdate();
3433}
3434
deadbeef953c2ce2017-01-09 14:53:41 -08003435TEST_F(RtpDataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003436 Base::TestStreams();
3437}
3438
deadbeef953c2ce2017-01-09 14:53:41 -08003439TEST_F(RtpDataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003440 Base::TestUpdateStreamsInLocalContent();
3441}
3442
deadbeef953c2ce2017-01-09 14:53:41 -08003443TEST_F(RtpDataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003444 Base::TestUpdateStreamsInRemoteContent();
3445}
3446
deadbeef953c2ce2017-01-09 14:53:41 -08003447TEST_F(RtpDataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448 Base::TestChangeStreamParamsInContent();
3449}
3450
deadbeef953c2ce2017-01-09 14:53:41 -08003451TEST_F(RtpDataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452 Base::TestPlayoutAndSendingStates();
3453}
3454
deadbeef953c2ce2017-01-09 14:53:41 -08003455TEST_F(RtpDataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003456 Base::TestMediaContentDirection();
3457}
3458
deadbeef953c2ce2017-01-09 14:53:41 -08003459TEST_F(RtpDataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460 Base::TestCallSetup();
3461}
3462
deadbeef953c2ce2017-01-09 14:53:41 -08003463TEST_F(RtpDataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464 Base::TestCallTeardownRtcpMux();
3465}
3466
deadbeef953c2ce2017-01-09 14:53:41 -08003467TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468 Base::TestOnReadyToSend();
3469}
3470
deadbeef953c2ce2017-01-09 14:53:41 -08003471TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003472 Base::TestOnReadyToSendWithRtcpMux();
3473}
3474
deadbeef953c2ce2017-01-09 14:53:41 -08003475TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 Base::SendRtpToRtp();
3477}
3478
deadbeef953c2ce2017-01-09 14:53:41 -08003479TEST_F(RtpDataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003480 Base::SendRtcpToRtcp();
3481}
3482
deadbeef953c2ce2017-01-09 14:53:41 -08003483TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484 Base::SendRtcpMuxToRtcp();
3485}
3486
deadbeef953c2ce2017-01-09 14:53:41 -08003487TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 Base::SendRtcpMuxToRtcpMux();
3489}
3490
deadbeef953c2ce2017-01-09 14:53:41 -08003491TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492 Base::SendEarlyRtcpMuxToRtcp();
3493}
3494
deadbeef953c2ce2017-01-09 14:53:41 -08003495TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003496 Base::SendEarlyRtcpMuxToRtcpMux();
3497}
3498
deadbeef953c2ce2017-01-09 14:53:41 -08003499TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500 Base::SendSrtpToSrtp();
3501}
3502
deadbeef953c2ce2017-01-09 14:53:41 -08003503TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504 Base::SendSrtpToSrtp();
3505}
3506
deadbeef953c2ce2017-01-09 14:53:41 -08003507TEST_F(RtpDataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3509}
3510
deadbeef953c2ce2017-01-09 14:53:41 -08003511TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512 Base::SendRtpToRtpOnThread();
3513}
3514
deadbeef953c2ce2017-01-09 14:53:41 -08003515TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516 Base::SendSrtpToSrtpOnThread();
3517}
3518
deadbeef953c2ce2017-01-09 14:53:41 -08003519TEST_F(RtpDataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520 Base::SendWithWritabilityLoss();
3521}
3522
deadbeef953c2ce2017-01-09 14:53:41 -08003523TEST_F(RtpDataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524 Base::TestMediaMonitor();
3525}
3526
deadbeef953c2ce2017-01-09 14:53:41 -08003527TEST_F(RtpDataChannelSingleThreadTest, TestSendData) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003528 CreateChannels(0, 0);
3529 EXPECT_TRUE(SendInitiate());
3530 EXPECT_TRUE(SendAccept());
3531
3532 cricket::SendDataParams params;
3533 params.ssrc = 42;
3534 unsigned char data[] = {'f', 'o', 'o'};
3535 rtc::CopyOnWriteBuffer payload(data, 3);
3536 cricket::SendDataResult result;
3537 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3538 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3539 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3540}
3541
deadbeef953c2ce2017-01-09 14:53:41 -08003542TEST_F(RtpDataChannelDoubleThreadTest, TestInit) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003543 Base::TestInit();
3544 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3545}
3546
deadbeef953c2ce2017-01-09 14:53:41 -08003547TEST_F(RtpDataChannelDoubleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003548 Base::TestDeinit();
3549}
3550
deadbeef953c2ce2017-01-09 14:53:41 -08003551TEST_F(RtpDataChannelDoubleThreadTest, TestSetContents) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003552 Base::TestSetContents();
3553}
3554
deadbeef953c2ce2017-01-09 14:53:41 -08003555TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsNullOffer) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003556 Base::TestSetContentsNullOffer();
3557}
3558
deadbeef953c2ce2017-01-09 14:53:41 -08003559TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003560 Base::TestSetContentsRtcpMux();
3561}
3562
deadbeef953c2ce2017-01-09 14:53:41 -08003563TEST_F(RtpDataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003564 Base::TestSetRemoteContentUpdate();
3565}
3566
deadbeef953c2ce2017-01-09 14:53:41 -08003567TEST_F(RtpDataChannelDoubleThreadTest, TestStreams) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003568 Base::TestStreams();
3569}
3570
deadbeef953c2ce2017-01-09 14:53:41 -08003571TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003572 Base::TestUpdateStreamsInLocalContent();
3573}
3574
deadbeef953c2ce2017-01-09 14:53:41 -08003575TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003576 Base::TestUpdateStreamsInRemoteContent();
3577}
3578
deadbeef953c2ce2017-01-09 14:53:41 -08003579TEST_F(RtpDataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003580 Base::TestChangeStreamParamsInContent();
3581}
3582
deadbeef953c2ce2017-01-09 14:53:41 -08003583TEST_F(RtpDataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003584 Base::TestPlayoutAndSendingStates();
3585}
3586
deadbeef953c2ce2017-01-09 14:53:41 -08003587TEST_F(RtpDataChannelDoubleThreadTest, TestMediaContentDirection) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003588 Base::TestMediaContentDirection();
3589}
3590
deadbeef953c2ce2017-01-09 14:53:41 -08003591TEST_F(RtpDataChannelDoubleThreadTest, TestCallSetup) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003592 Base::TestCallSetup();
3593}
3594
deadbeef953c2ce2017-01-09 14:53:41 -08003595TEST_F(RtpDataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003596 Base::TestCallTeardownRtcpMux();
3597}
3598
deadbeef953c2ce2017-01-09 14:53:41 -08003599TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSend) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003600 Base::TestOnReadyToSend();
3601}
3602
deadbeef953c2ce2017-01-09 14:53:41 -08003603TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003604 Base::TestOnReadyToSendWithRtcpMux();
3605}
3606
deadbeef953c2ce2017-01-09 14:53:41 -08003607TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003608 Base::SendRtpToRtp();
3609}
3610
deadbeef953c2ce2017-01-09 14:53:41 -08003611TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003612 Base::SendRtcpToRtcp();
3613}
3614
deadbeef953c2ce2017-01-09 14:53:41 -08003615TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003616 Base::SendRtcpMuxToRtcp();
3617}
3618
deadbeef953c2ce2017-01-09 14:53:41 -08003619TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003620 Base::SendRtcpMuxToRtcpMux();
3621}
3622
deadbeef953c2ce2017-01-09 14:53:41 -08003623TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003624 Base::SendEarlyRtcpMuxToRtcp();
3625}
3626
deadbeef953c2ce2017-01-09 14:53:41 -08003627TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003628 Base::SendEarlyRtcpMuxToRtcpMux();
3629}
3630
deadbeef953c2ce2017-01-09 14:53:41 -08003631TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003632 Base::SendSrtpToSrtp();
3633}
3634
deadbeef953c2ce2017-01-09 14:53:41 -08003635TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003636 Base::SendSrtpToSrtp();
3637}
3638
deadbeef953c2ce2017-01-09 14:53:41 -08003639TEST_F(RtpDataChannelDoubleThreadTest, SendSrtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003640 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3641}
3642
deadbeef953c2ce2017-01-09 14:53:41 -08003643TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003644 Base::SendRtpToRtpOnThread();
3645}
3646
deadbeef953c2ce2017-01-09 14:53:41 -08003647TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003648 Base::SendSrtpToSrtpOnThread();
3649}
3650
deadbeef953c2ce2017-01-09 14:53:41 -08003651TEST_F(RtpDataChannelDoubleThreadTest, SendWithWritabilityLoss) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003652 Base::SendWithWritabilityLoss();
3653}
3654
deadbeef953c2ce2017-01-09 14:53:41 -08003655TEST_F(RtpDataChannelDoubleThreadTest, TestMediaMonitor) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003656 Base::TestMediaMonitor();
3657}
3658
deadbeef953c2ce2017-01-09 14:53:41 -08003659TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003660 CreateChannels(0, 0);
3661 EXPECT_TRUE(SendInitiate());
3662 EXPECT_TRUE(SendAccept());
3663
3664 cricket::SendDataParams params;
3665 params.ssrc = 42;
3666 unsigned char data[] = {
3667 'f', 'o', 'o'
3668 };
jbaucheec21bd2016-03-20 06:15:43 -07003669 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670 cricket::SendDataResult result;
3671 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3672 EXPECT_EQ(params.ssrc,
3673 media_channel1_->last_sent_data_params().ssrc);
3674 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3675}
3676
deadbeefbad5dad2017-01-17 18:32:35 -08003677#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3678
3679// Verifies some DCHECKs are in place.
3680// Uses VoiceChannel, but any BaseChannel subclass would work.
3681class BaseChannelDeathTest : public testing::Test {
3682 public:
3683 BaseChannelDeathTest()
deadbeeff5346592017-01-24 21:51:21 -08003684 : fake_rtp_dtls_transport_("foo", cricket::ICE_CANDIDATE_COMPONENT_RTP),
3685 fake_rtcp_dtls_transport_("foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP),
3686 // RTCP mux not required, SRTP required.
deadbeefbad5dad2017-01-17 18:32:35 -08003687 voice_channel_(
3688 rtc::Thread::Current(),
3689 rtc::Thread::Current(),
3690 rtc::Thread::Current(),
3691 &fake_media_engine_,
3692 new cricket::FakeVoiceMediaChannel(nullptr,
3693 cricket::AudioOptions()),
3694 cricket::CN_AUDIO,
3695 false,
deadbeeff5346592017-01-24 21:51:21 -08003696 true) {}
deadbeefbad5dad2017-01-17 18:32:35 -08003697
3698 protected:
deadbeefbad5dad2017-01-17 18:32:35 -08003699 cricket::FakeMediaEngine fake_media_engine_;
deadbeeff5346592017-01-24 21:51:21 -08003700 cricket::FakeDtlsTransport fake_rtp_dtls_transport_;
3701 cricket::FakeDtlsTransport fake_rtcp_dtls_transport_;
deadbeefbad5dad2017-01-17 18:32:35 -08003702 cricket::VoiceChannel voice_channel_;
deadbeefbad5dad2017-01-17 18:32:35 -08003703};
3704
deadbeeff5346592017-01-24 21:51:21 -08003705TEST_F(BaseChannelDeathTest, SetTransportsWithNullRtpTransport) {
3706 ASSERT_TRUE(voice_channel_.Init_w(
3707 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3708 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3709 cricket::FakeDtlsTransport new_rtcp_transport(
3710 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3711 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, &new_rtcp_transport), "");
deadbeefbad5dad2017-01-17 18:32:35 -08003712}
3713
deadbeeff5346592017-01-24 21:51:21 -08003714TEST_F(BaseChannelDeathTest, SetTransportsWithMissingRtcpTransport) {
3715 ASSERT_TRUE(voice_channel_.Init_w(
3716 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3717 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3718 cricket::FakeDtlsTransport new_rtp_transport(
3719 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3720 EXPECT_DEATH(voice_channel_.SetTransports(&new_rtp_transport, nullptr), "");
deadbeefbad5dad2017-01-17 18:32:35 -08003721}
3722
deadbeeff5346592017-01-24 21:51:21 -08003723TEST_F(BaseChannelDeathTest, SetTransportsWithUnneededRtcpTransport) {
3724 ASSERT_TRUE(voice_channel_.Init_w(
3725 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3726 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
deadbeefbad5dad2017-01-17 18:32:35 -08003727 // Activate RTCP muxing, simulating offer/answer negotiation.
3728 cricket::AudioContentDescription content;
3729 content.set_rtcp_mux(true);
3730 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
3731 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
deadbeeff5346592017-01-24 21:51:21 -08003732 cricket::FakeDtlsTransport new_rtp_transport(
3733 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3734 cricket::FakeDtlsTransport new_rtcp_transport(
3735 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
deadbeefbad5dad2017-01-17 18:32:35 -08003736 // After muxing is enabled, no RTCP transport should be passed in here.
3737 EXPECT_DEATH(
deadbeeff5346592017-01-24 21:51:21 -08003738 voice_channel_.SetTransports(&new_rtp_transport, &new_rtcp_transport),
3739 "");
deadbeefbad5dad2017-01-17 18:32:35 -08003740}
3741
3742// This test will probably go away if/when we move the transport name out of
3743// the transport classes and into their parent classes.
deadbeeff5346592017-01-24 21:51:21 -08003744TEST_F(BaseChannelDeathTest, SetTransportsWithMismatchingTransportNames) {
3745 ASSERT_TRUE(voice_channel_.Init_w(
3746 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3747 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3748 cricket::FakeDtlsTransport new_rtp_transport(
3749 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3750 cricket::FakeDtlsTransport new_rtcp_transport(
3751 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
deadbeefbad5dad2017-01-17 18:32:35 -08003752 EXPECT_DEATH(
deadbeeff5346592017-01-24 21:51:21 -08003753 voice_channel_.SetTransports(&new_rtp_transport, &new_rtcp_transport),
3754 "");
3755}
3756
3757// Not expected to support going from DtlsTransportInternal to
3758// PacketTransportInterface.
3759TEST_F(BaseChannelDeathTest, SetTransportsDtlsToNonDtls) {
3760 ASSERT_TRUE(voice_channel_.Init_w(
3761 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3762 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3763 EXPECT_DEATH(
3764 voice_channel_.SetTransports(static_cast<rtc::PacketTransportInterface*>(
3765 &fake_rtp_dtls_transport_),
3766 static_cast<rtc::PacketTransportInterface*>(
3767 &fake_rtp_dtls_transport_)),
3768 "");
3769}
3770
3771// Not expected to support going from PacketTransportInterface to
3772// DtlsTransportInternal.
3773TEST_F(BaseChannelDeathTest, SetTransportsNonDtlsToDtls) {
3774 ASSERT_TRUE(voice_channel_.Init_w(nullptr, nullptr, &fake_rtp_dtls_transport_,
3775 &fake_rtcp_dtls_transport_));
3776 EXPECT_DEATH(voice_channel_.SetTransports(&fake_rtp_dtls_transport_,
3777 &fake_rtp_dtls_transport_),
3778 "");
deadbeefbad5dad2017-01-17 18:32:35 -08003779}
3780
3781#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3782
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003783// TODO(pthatcher): TestSetReceiver?