blob: 4605ad9a08ddb3d700b5eeb4d0e256ab1e2668c5 [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,
deadbeef5bd5ca32017-02-10 11:31:50 -0800101 // Use BaseChannel with PacketTransportInternal rather than
deadbeeff5346592017-01-24 21:51:21 -0800102 // 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;
deadbeef5bd5ca32017-02-10 11:31:50 -0800146 rtc::PacketTransportInternal* rtp1 = nullptr;
147 rtc::PacketTransportInternal* rtcp1 = nullptr;
148 rtc::PacketTransportInternal* rtp2 = nullptr;
149 rtc::PacketTransportInternal* rtcp2 = nullptr;
deadbeeff5346592017-01-24 21:51:21 -0800150 // 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,
deadbeef5bd5ca32017-02-10 11:31:50 -0800258 rtc::PacketTransportInternal* fake_rtp_packet_transport,
259 rtc::PacketTransportInternal* 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
deadbeefe702b302017-02-04 12:09:01 -08001959 webrtc::RtpParameters BitrateLimitedParameters(rtc::Optional<int> limit) {
skvladdc1c62c2016-03-16 19:07:43 -07001960 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,
deadbeefe702b302017-02-04 12:09:01 -08001968 rtc::Optional<int> expected_bitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07001969 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);
deadbeefe702b302017-02-04 12:09:01 -08001978 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1),
1979 rtc::Optional<int>());
skvladdc1c62c2016-03-16 19:07:43 -07001980 }
1981
1982 void CanChangeMaxBitrate() {
1983 CreateChannels(0, 0);
1984 EXPECT_TRUE(
1985 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1986
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001987 EXPECT_TRUE(channel1_->SetRtpSendParameters(
deadbeefe702b302017-02-04 12:09:01 -08001988 kSsrc1, BitrateLimitedParameters(rtc::Optional<int>(1000))));
1989 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1),
1990 rtc::Optional<int>(1000));
1991 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1),
1992 rtc::Optional<int>(1000));
skvladdc1c62c2016-03-16 19:07:43 -07001993 EXPECT_EQ(-1, media_channel1_->max_bps());
1994
deadbeefe702b302017-02-04 12:09:01 -08001995 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1996 kSsrc1, BitrateLimitedParameters(rtc::Optional<int>())));
1997 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1),
1998 rtc::Optional<int>());
1999 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1),
2000 rtc::Optional<int>());
skvladdc1c62c2016-03-16 19:07:43 -07002001 EXPECT_EQ(-1, media_channel1_->max_bps());
2002 }
2003
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002005 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
2006 static void ProcessThreadQueue(rtc::Thread* thread) {
2007 RTC_DCHECK(thread->IsCurrent());
2008 while (!thread->empty()) {
2009 thread->ProcessMessages(0);
2010 }
2011 }
2012 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
2013 // |threads| and current thread post packets to network thread.
2014 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07002015 thread->Invoke<void>(RTC_FROM_HERE,
2016 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002017 }
2018 ProcessThreadQueue(rtc::Thread::Current());
2019 // Network thread move them around and post back to worker = current thread.
2020 if (!network_thread_->IsCurrent()) {
2021 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07002022 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002023 }
2024 // Worker thread = current Thread process received messages.
2025 ProcessThreadQueue(rtc::Thread::Current());
2026 }
Peter Boström34fbfff2015-09-24 19:20:30 +02002027 // TODO(pbos): Remove playout from all media channels and let renderers mute
2028 // themselves.
2029 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002030 std::unique_ptr<rtc::Thread> network_thread_keeper_;
2031 rtc::Thread* network_thread_;
deadbeeff5346592017-01-24 21:51:21 -08002032 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport1_;
2033 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport1_;
2034 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport2_;
2035 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport2_;
2036 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport1_;
2037 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport1_;
2038 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport2_;
2039 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 cricket::FakeMediaEngine media_engine_;
2041 // The media channels are owned by the voice channel objects below.
deadbeeff5346592017-01-24 21:51:21 -08002042 typename T::MediaChannel* media_channel1_ = nullptr;
2043 typename T::MediaChannel* media_channel2_ = nullptr;
kwiberg31022942016-03-11 14:18:21 -08002044 std::unique_ptr<typename T::Channel> channel1_;
2045 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 typename T::Content local_media_content1_;
2047 typename T::Content local_media_content2_;
2048 typename T::Content remote_media_content1_;
2049 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002051 rtc::Buffer rtp_packet_;
2052 rtc::Buffer rtcp_packet_;
deadbeeff5346592017-01-24 21:51:21 -08002053 int media_info_callbacks1_ = 0;
2054 int media_info_callbacks2_ = 0;
2055 int rtcp_mux_activated_callbacks1_ = 0;
2056 int rtcp_mux_activated_callbacks2_ = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -07002057 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058};
2059
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060template<>
2061void ChannelTest<VoiceTraits>::CreateContent(
2062 int flags,
2063 const cricket::AudioCodec& audio_codec,
2064 const cricket::VideoCodec& video_codec,
2065 cricket::AudioContentDescription* audio) {
2066 audio->AddCodec(audio_codec);
2067 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
2068 if (flags & SECURE) {
2069 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002070 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2071 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 }
2073}
2074
2075template<>
2076void ChannelTest<VoiceTraits>::CopyContent(
2077 const cricket::AudioContentDescription& source,
2078 cricket::AudioContentDescription* audio) {
2079 *audio = source;
2080}
2081
2082template<>
2083bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
2084 const cricket::AudioCodec& c2) {
2085 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
2086 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
2087}
2088
Peter Boström0c4e06b2015-10-07 12:23:21 +02002089template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002091 uint32_t ssrc,
2092 int flags,
2093 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 audio->AddLegacyStream(ssrc);
2095}
2096
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002097class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 public:
solenberg1dd98f32015-09-10 01:57:14 -07002099 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002100 VoiceChannelSingleThreadTest()
2101 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2102};
2103
2104class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2105 public:
2106 typedef ChannelTest<VoiceTraits> Base;
2107 VoiceChannelDoubleThreadTest()
2108 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109};
2110
2111// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002112template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002114 rtc::Thread* worker_thread,
2115 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002116 cricket::MediaEngineInterface* engine,
2117 cricket::FakeVideoMediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -08002118 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
2119 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
deadbeef5bd5ca32017-02-10 11:31:50 -08002120 rtc::PacketTransportInternal* fake_rtp_packet_transport,
2121 rtc::PacketTransportInternal* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -07002122 int flags) {
deadbeeff5346592017-01-24 21:51:21 -08002123 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef7af91dd2016-12-13 11:29:11 -08002124 cricket::VideoChannel* channel = new cricket::VideoChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08002125 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO,
deadbeefac22f702017-01-12 21:59:29 -08002126 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07002127 rtc::CryptoOptions crypto_options;
2128 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
2129 channel->SetCryptoOptions(crypto_options);
deadbeeff5346592017-01-24 21:51:21 -08002130 if (!channel->NeedsRtcpTransport()) {
2131 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08002132 }
deadbeeff5346592017-01-24 21:51:21 -08002133 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
2134 fake_rtp_packet_transport, fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 delete channel;
2136 channel = NULL;
2137 }
2138 return channel;
2139}
2140
2141// override to add 0 parameter
2142template<>
2143bool ChannelTest<VideoTraits>::AddStream1(int id) {
2144 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2145}
2146
2147template<>
2148void ChannelTest<VideoTraits>::CreateContent(
2149 int flags,
2150 const cricket::AudioCodec& audio_codec,
2151 const cricket::VideoCodec& video_codec,
2152 cricket::VideoContentDescription* video) {
2153 video->AddCodec(video_codec);
2154 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2155 if (flags & SECURE) {
2156 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002157 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2158 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 }
2160}
2161
2162template<>
2163void ChannelTest<VideoTraits>::CopyContent(
2164 const cricket::VideoContentDescription& source,
2165 cricket::VideoContentDescription* video) {
2166 *video = source;
2167}
2168
2169template<>
2170bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2171 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002172 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173}
2174
Peter Boström0c4e06b2015-10-07 12:23:21 +02002175template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002177 uint32_t ssrc,
2178 int flags,
2179 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180 video->AddLegacyStream(ssrc);
2181}
2182
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002183class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 public:
solenberg1dd98f32015-09-10 01:57:14 -07002185 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002186 VideoChannelSingleThreadTest()
2187 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188};
2189
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002190class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2191 public:
2192 typedef ChannelTest<VideoTraits> Base;
2193 VideoChannelDoubleThreadTest()
2194 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2195};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002197// VoiceChannelSingleThreadTest
2198TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 Base::TestInit();
2200 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2201 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2202}
2203
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002204TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2205 Base::TestDeinit();
2206}
2207
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002208TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 Base::TestSetContents();
2210}
2211
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002212TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 Base::TestSetContentsNullOffer();
2214}
2215
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002216TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 Base::TestSetContentsRtcpMux();
2218}
2219
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002220TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 Base::TestSetContentsRtcpMux();
2222}
2223
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002224TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 Base::TestSetRemoteContentUpdate();
2226}
2227
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002228TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 Base::TestStreams();
2230}
2231
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002232TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 Base::TestUpdateStreamsInLocalContent();
2234}
2235
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002236TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 Base::TestUpdateStreamsInRemoteContent();
2238}
2239
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002240TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 Base::TestChangeStreamParamsInContent();
2242}
2243
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002244TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 Base::TestPlayoutAndSendingStates();
2246}
2247
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002248TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002249 CreateChannels(0, 0);
2250 // Test that we can Mute the default channel even though the sending SSRC
2251 // is unknown.
2252 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002253 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002254 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2255 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002256 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2257
2258 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002259 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002260
2261 SendInitiate();
2262 // After the local session description has been set, we can mute a stream
2263 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002264 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002265 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2266 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002267 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268}
2269
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002270TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 Base::TestMediaContentDirection();
2272}
2273
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002274TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002275 Base::TestNetworkRouteChanges();
2276}
2277
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002278TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279 Base::TestCallSetup();
2280}
2281
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002282TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 Base::TestCallTeardownRtcpMux();
2284}
2285
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002286TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 Base::SendRtpToRtp();
2288}
2289
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002290TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 Base::SendRtcpToRtcp();
2292}
2293
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002294TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 Base::SendRtcpMuxToRtcp();
2296}
2297
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002298TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 Base::SendRtcpMuxToRtcpMux();
2300}
2301
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002302TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002303 Base::SendRequireRtcpMuxToRtcpMux();
2304}
2305
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002306TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002307 Base::SendRtcpMuxToRequireRtcpMux();
2308}
2309
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002310TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002311 Base::SendRequireRtcpMuxToRequireRtcpMux();
2312}
2313
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002314TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002315 Base::SendRequireRtcpMuxToNoRtcpMux();
2316}
2317
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002318TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 Base::SendEarlyRtcpMuxToRtcp();
2320}
2321
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002322TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002323 Base::SendEarlyRtcpMuxToRtcpMux();
2324}
2325
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002326TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2328}
2329
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002330TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 Base::SendSrtpToSrtp();
2332}
2333
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002334TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2336}
2337
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002338TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 Base::SendSrtpToSrtp(DTLS, 0);
2340}
2341
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002342TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 Base::SendSrtpToSrtp(DTLS, DTLS);
2344}
2345
jbauchcb560652016-08-04 05:20:32 -07002346TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
jbauchcb560652016-08-04 05:20:32 -07002347 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2348}
2349
2350TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
jbauchcb560652016-08-04 05:20:32 -07002351 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2352}
2353
2354TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
jbauchcb560652016-08-04 05:20:32 -07002355 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2356}
2357
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002358TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2360}
2361
deadbeeff5346592017-01-24 21:51:21 -08002362// Test using the channel with a raw packet interface, as opposed to a DTLS
2363// transport interface.
2364TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
2365 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
2366}
2367
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002368TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2370}
2371
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002372TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373 Base::SendRtpToRtpOnThread();
2374}
2375
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002376TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 Base::SendSrtpToSrtpOnThread();
2378}
2379
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002380TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 Base::SendWithWritabilityLoss();
2382}
2383
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002384TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002385 Base::TestMediaMonitor();
2386}
2387
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002389TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 CreateChannels(0, 0);
2391 EXPECT_TRUE(SendInitiate());
2392 EXPECT_TRUE(SendAccept());
2393 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2394
solenberg1d63dd02015-12-02 12:35:09 -08002395 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2396 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2397 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002399 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002401 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002402 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002403 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002404 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002405 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406}
2407
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002408TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 Base::TestSetContentFailure();
2410}
2411
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002412TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 Base::TestSendTwoOffers();
2414}
2415
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002416TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 Base::TestReceiveTwoOffers();
2418}
2419
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002420TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 Base::TestSendPrAnswer();
2422}
2423
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002424TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 Base::TestReceivePrAnswer();
2426}
2427
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002428TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429 Base::TestFlushRtcp();
2430}
2431
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002432TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002433 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434}
2435
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002436TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002437 Base::TestOnReadyToSend();
2438}
2439
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002440TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 Base::TestOnReadyToSendWithRtcpMux();
2442}
2443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002445TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002446 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 EXPECT_TRUE(SendInitiate());
2448 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002449 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450
solenberg4bac9c52015-10-09 02:32:53 -07002451 // Default is (1.0).
2452 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2453 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002455 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456
solenberg4bac9c52015-10-09 02:32:53 -07002457 // Set scale to (1.5).
2458 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2459 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2460 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461
solenberg4bac9c52015-10-09 02:32:53 -07002462 // Set scale to (0).
2463 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2464 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2465 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466}
2467
2468// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002469TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002470 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 EXPECT_TRUE(SendInitiate());
2472 EXPECT_TRUE(SendAccept());
2473 EXPECT_TRUE(AddStream1(1));
2474 EXPECT_TRUE(AddStream1(2));
2475
solenberg4bac9c52015-10-09 02:32:53 -07002476 double volume;
2477 // Default is (1.0).
2478 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2479 EXPECT_DOUBLE_EQ(1.0, volume);
2480 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2481 EXPECT_DOUBLE_EQ(1.0, volume);
2482 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2483 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002485 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486
solenberg4bac9c52015-10-09 02:32:53 -07002487 // Set scale to (1.5) for ssrc = 1.
2488 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2489 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2490 EXPECT_DOUBLE_EQ(1.5, volume);
2491 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2492 EXPECT_DOUBLE_EQ(1.0, volume);
2493 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2494 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495
solenberg4bac9c52015-10-09 02:32:53 -07002496 // Set scale to (0) for all ssrcs.
2497 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2498 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2499 EXPECT_DOUBLE_EQ(0.0, volume);
2500 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2501 EXPECT_DOUBLE_EQ(0.0, volume);
2502 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2503 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504}
2505
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002506TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002507 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508}
2509
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002510TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002511 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002512}
2513
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002514TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002515 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002516}
2517
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002518TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002519 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520}
2521
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002522TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002523 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002524}
2525
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002526TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002527 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002528}
2529
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002530// VoiceChannelDoubleThreadTest
2531TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002533 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2534 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535}
2536
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002537TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2538 Base::TestDeinit();
2539}
2540
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002541TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 Base::TestSetContents();
2543}
2544
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002545TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 Base::TestSetContentsNullOffer();
2547}
2548
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002549TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 Base::TestSetContentsRtcpMux();
2551}
2552
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002553TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 Base::TestSetContentsRtcpMux();
2555}
2556
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002557TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 Base::TestSetRemoteContentUpdate();
2559}
2560
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002561TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562 Base::TestStreams();
2563}
2564
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002565TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 Base::TestUpdateStreamsInLocalContent();
2567}
2568
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002569TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570 Base::TestUpdateStreamsInRemoteContent();
2571}
2572
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002573TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 Base::TestChangeStreamParamsInContent();
2575}
2576
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002577TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578 Base::TestPlayoutAndSendingStates();
2579}
2580
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002581TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2582 CreateChannels(0, 0);
2583 // Test that we can Mute the default channel even though the sending SSRC
2584 // is unknown.
2585 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2586 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2587 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2588 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2589 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2590
2591 // Test that we can not mute an unknown SSRC.
2592 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2593
2594 SendInitiate();
2595 // After the local session description has been set, we can mute a stream
2596 // with its SSRC.
2597 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2598 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2599 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2600 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2601}
2602
2603TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2604 Base::TestMediaContentDirection();
2605}
2606
2607TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2608 Base::TestNetworkRouteChanges();
2609}
2610
2611TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2612 Base::TestCallSetup();
2613}
2614
2615TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2616 Base::TestCallTeardownRtcpMux();
2617}
2618
2619TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2620 Base::SendRtpToRtp();
2621}
2622
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002623TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2624 Base::SendRtcpToRtcp();
2625}
2626
2627TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2628 Base::SendRtcpMuxToRtcp();
2629}
2630
2631TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2632 Base::SendRtcpMuxToRtcpMux();
2633}
2634
2635TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2636 Base::SendRequireRtcpMuxToRtcpMux();
2637}
2638
2639TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2640 Base::SendRtcpMuxToRequireRtcpMux();
2641}
2642
2643TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2644 Base::SendRequireRtcpMuxToRequireRtcpMux();
2645}
2646
2647TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2648 Base::SendRequireRtcpMuxToNoRtcpMux();
2649}
2650
2651TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2652 Base::SendEarlyRtcpMuxToRtcp();
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2656 Base::SendEarlyRtcpMuxToRtcpMux();
2657}
2658
2659TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2660 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2661}
2662
2663TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2664 Base::SendSrtpToSrtp();
2665}
2666
2667TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2668 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2669}
2670
2671TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002672 Base::SendSrtpToSrtp(DTLS, 0);
2673}
2674
2675TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002676 Base::SendSrtpToSrtp(DTLS, DTLS);
2677}
2678
jbauchcb560652016-08-04 05:20:32 -07002679TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmBoth) {
jbauchcb560652016-08-04 05:20:32 -07002680 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS | GCM_CIPHER);
2681}
2682
2683TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmOne) {
jbauchcb560652016-08-04 05:20:32 -07002684 Base::SendSrtpToSrtp(DTLS | GCM_CIPHER, DTLS);
2685}
2686
2687TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpGcmTwo) {
jbauchcb560652016-08-04 05:20:32 -07002688 Base::SendSrtpToSrtp(DTLS, DTLS | GCM_CIPHER);
2689}
2690
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002691TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002692 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2693}
2694
deadbeeff5346592017-01-24 21:51:21 -08002695// Test using the channel with a raw packet interface, as opposed to a DTLS
2696// transport interface.
2697TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
2698 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
2699}
2700
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002701TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2702 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2703}
2704
2705TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2706 Base::SendRtpToRtpOnThread();
2707}
2708
2709TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2710 Base::SendSrtpToSrtpOnThread();
2711}
2712
2713TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2714 Base::SendWithWritabilityLoss();
2715}
2716
2717TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2718 Base::TestMediaMonitor();
2719}
2720
2721// Test that InsertDtmf properly forwards to the media channel.
2722TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2723 CreateChannels(0, 0);
2724 EXPECT_TRUE(SendInitiate());
2725 EXPECT_TRUE(SendAccept());
2726 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2727
2728 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2729 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2730 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2731
2732 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2733 EXPECT_TRUE(
2734 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2735 EXPECT_TRUE(
2736 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2737 EXPECT_TRUE(
2738 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2739}
2740
2741TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2742 Base::TestSetContentFailure();
2743}
2744
2745TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2746 Base::TestSendTwoOffers();
2747}
2748
2749TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2750 Base::TestReceiveTwoOffers();
2751}
2752
2753TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2754 Base::TestSendPrAnswer();
2755}
2756
2757TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2758 Base::TestReceivePrAnswer();
2759}
2760
2761TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2762 Base::TestFlushRtcp();
2763}
2764
2765TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2766 Base::TestSrtpError(kAudioPts[0]);
2767}
2768
2769TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2770 Base::TestOnReadyToSend();
2771}
2772
2773TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2774 Base::TestOnReadyToSendWithRtcpMux();
2775}
2776
2777// Test that we can scale the output volume properly for 1:1 calls.
2778TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002779 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002780 EXPECT_TRUE(SendInitiate());
2781 EXPECT_TRUE(SendAccept());
2782 double volume;
2783
2784 // Default is (1.0).
2785 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2786 EXPECT_DOUBLE_EQ(1.0, volume);
2787 // invalid ssrc.
2788 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2789
2790 // Set scale to (1.5).
2791 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2792 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2793 EXPECT_DOUBLE_EQ(1.5, volume);
2794
2795 // Set scale to (0).
2796 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2797 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2798 EXPECT_DOUBLE_EQ(0.0, volume);
2799}
2800
2801// Test that we can scale the output volume properly for multiway calls.
2802TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002803 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002804 EXPECT_TRUE(SendInitiate());
2805 EXPECT_TRUE(SendAccept());
2806 EXPECT_TRUE(AddStream1(1));
2807 EXPECT_TRUE(AddStream1(2));
2808
2809 double volume;
2810 // Default is (1.0).
2811 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2812 EXPECT_DOUBLE_EQ(1.0, volume);
2813 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2814 EXPECT_DOUBLE_EQ(1.0, volume);
2815 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2816 EXPECT_DOUBLE_EQ(1.0, volume);
2817 // invalid ssrc.
2818 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2819
2820 // Set scale to (1.5) for ssrc = 1.
2821 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2822 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2823 EXPECT_DOUBLE_EQ(1.5, volume);
2824 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2825 EXPECT_DOUBLE_EQ(1.0, volume);
2826 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2827 EXPECT_DOUBLE_EQ(1.0, volume);
2828
2829 // Set scale to (0) for all ssrcs.
2830 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2831 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2832 EXPECT_DOUBLE_EQ(0.0, volume);
2833 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2834 EXPECT_DOUBLE_EQ(0.0, volume);
2835 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2836 EXPECT_DOUBLE_EQ(0.0, volume);
2837}
2838
2839TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2840 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2841}
2842
2843TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2844 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2845}
2846
2847TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2848 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2849}
2850
2851TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2852 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2853}
2854
2855TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2856 Base::DefaultMaxBitrateIsUnlimited();
2857}
2858
2859TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2860 Base::CanChangeMaxBitrate();
2861}
2862
2863// VideoChannelSingleThreadTest
2864TEST_F(VideoChannelSingleThreadTest, TestInit) {
2865 Base::TestInit();
2866}
2867
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002868TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2869 Base::TestDeinit();
2870}
2871
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002872TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2873 Base::TestSetContents();
2874}
2875
2876TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2877 Base::TestSetContentsNullOffer();
2878}
2879
2880TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2881 Base::TestSetContentsRtcpMux();
2882}
2883
2884TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2885 Base::TestSetContentsRtcpMux();
2886}
2887
2888TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2889 Base::TestSetRemoteContentUpdate();
2890}
2891
2892TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2893 Base::TestStreams();
2894}
2895
2896TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2897 Base::TestUpdateStreamsInLocalContent();
2898}
2899
2900TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2901 Base::TestUpdateStreamsInRemoteContent();
2902}
2903
2904TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2905 Base::TestChangeStreamParamsInContent();
2906}
2907
2908TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2909 Base::TestPlayoutAndSendingStates();
2910}
2911
2912TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002913 CreateChannels(0, 0);
2914 // Test that we can Mute the default channel even though the sending SSRC
2915 // is unknown.
2916 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002917 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002918 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002919 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002920 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2921 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002922 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002923 SendInitiate();
2924 // After the local session description has been set, we can mute a stream
2925 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002926 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002927 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002928 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002929 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930}
2931
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002932TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002933 Base::TestMediaContentDirection();
2934}
2935
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002936TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002937 Base::TestNetworkRouteChanges();
2938}
2939
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002940TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941 Base::TestCallSetup();
2942}
2943
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002944TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002945 Base::TestCallTeardownRtcpMux();
2946}
2947
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002948TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002949 Base::SendRtpToRtp();
2950}
2951
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002952TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953 Base::SendRtcpToRtcp();
2954}
2955
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002956TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002957 Base::SendRtcpMuxToRtcp();
2958}
2959
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002960TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002961 Base::SendRtcpMuxToRtcpMux();
2962}
2963
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002964TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002965 Base::SendRequireRtcpMuxToRtcpMux();
2966}
2967
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002968TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002969 Base::SendRtcpMuxToRequireRtcpMux();
2970}
2971
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002972TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002973 Base::SendRequireRtcpMuxToRequireRtcpMux();
2974}
2975
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002976TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002977 Base::SendRequireRtcpMuxToNoRtcpMux();
2978}
2979
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002980TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002981 Base::SendEarlyRtcpMuxToRtcp();
2982}
2983
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002984TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002985 Base::SendEarlyRtcpMuxToRtcpMux();
2986}
2987
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002988TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002989 Base::SendSrtpToSrtp();
2990}
2991
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002992TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993 Base::SendSrtpToSrtp();
2994}
2995
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002996TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002997 Base::SendSrtpToSrtp(DTLS, 0);
2998}
2999
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003000TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001 Base::SendSrtpToSrtp(DTLS, DTLS);
3002}
3003
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003004TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003005 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3006}
3007
deadbeeff5346592017-01-24 21:51:21 -08003008// Test using the channel with a raw packet interface, as opposed to a DTLS
3009// transport interface.
3010TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
3011 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
3012}
3013
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003014TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3016}
3017
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003018TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003019 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3020}
3021
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003022TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023 Base::SendRtpToRtpOnThread();
3024}
3025
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003026TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003027 Base::SendSrtpToSrtpOnThread();
3028}
3029
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003030TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031 Base::SendWithWritabilityLoss();
3032}
3033
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003034TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035 Base::TestMediaMonitor();
3036}
3037
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003038TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003039 Base::TestSetContentFailure();
3040}
3041
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003042TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003043 Base::TestSendTwoOffers();
3044}
3045
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003046TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047 Base::TestReceiveTwoOffers();
3048}
3049
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003050TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051 Base::TestSendPrAnswer();
3052}
3053
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003054TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003055 Base::TestReceivePrAnswer();
3056}
3057
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003058TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059 Base::TestFlushRtcp();
3060}
3061
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003062TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08003063 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003064}
3065
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003066TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003067 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003068}
3069
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003070TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08003071 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003072}
3073
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003074TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08003075 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003076}
3077
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003078TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003079 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003080}
3081
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003082TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083 Base::TestOnReadyToSend();
3084}
3085
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003086TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003087 Base::TestOnReadyToSendWithRtcpMux();
3088}
3089
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003090TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07003091 Base::DefaultMaxBitrateIsUnlimited();
3092}
3093
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003094TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07003095 Base::CanChangeMaxBitrate();
3096}
3097
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003098// VideoChannelDoubleThreadTest
3099TEST_F(VideoChannelDoubleThreadTest, TestInit) {
3100 Base::TestInit();
3101}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003102
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003103TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
3104 Base::TestDeinit();
3105}
3106
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003107TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
3108 Base::TestSetContents();
3109}
3110
3111TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3112 Base::TestSetContentsNullOffer();
3113}
3114
3115TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3116 Base::TestSetContentsRtcpMux();
3117}
3118
3119TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3120 Base::TestSetContentsRtcpMux();
3121}
3122
3123TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3124 Base::TestSetRemoteContentUpdate();
3125}
3126
3127TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3128 Base::TestStreams();
3129}
3130
3131TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3132 Base::TestUpdateStreamsInLocalContent();
3133}
3134
3135TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3136 Base::TestUpdateStreamsInRemoteContent();
3137}
3138
3139TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3140 Base::TestChangeStreamParamsInContent();
3141}
3142
3143TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3144 Base::TestPlayoutAndSendingStates();
3145}
3146
3147TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3148 CreateChannels(0, 0);
3149 // Test that we can Mute the default channel even though the sending SSRC
3150 // is unknown.
3151 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003152 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003153 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07003154 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003155 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3156 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003157 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003158 SendInitiate();
3159 // After the local session description has been set, we can mute a stream
3160 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07003161 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003162 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07003163 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003164 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3165}
3166
3167TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3168 Base::TestMediaContentDirection();
3169}
3170
3171TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3172 Base::TestNetworkRouteChanges();
3173}
3174
3175TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3176 Base::TestCallSetup();
3177}
3178
3179TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3180 Base::TestCallTeardownRtcpMux();
3181}
3182
3183TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3184 Base::SendRtpToRtp();
3185}
3186
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003187TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3188 Base::SendRtcpToRtcp();
3189}
3190
3191TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3192 Base::SendRtcpMuxToRtcp();
3193}
3194
3195TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3196 Base::SendRtcpMuxToRtcpMux();
3197}
3198
3199TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3200 Base::SendRequireRtcpMuxToRtcpMux();
3201}
3202
3203TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3204 Base::SendRtcpMuxToRequireRtcpMux();
3205}
3206
3207TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3208 Base::SendRequireRtcpMuxToRequireRtcpMux();
3209}
3210
3211TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3212 Base::SendRequireRtcpMuxToNoRtcpMux();
3213}
3214
3215TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3216 Base::SendEarlyRtcpMuxToRtcp();
3217}
3218
3219TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3220 Base::SendEarlyRtcpMuxToRtcpMux();
3221}
3222
3223TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3224 Base::SendSrtpToSrtp();
3225}
3226
3227TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3228 Base::SendSrtpToSrtp();
3229}
3230
3231TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003232 Base::SendSrtpToSrtp(DTLS, 0);
3233}
3234
3235TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003236 Base::SendSrtpToSrtp(DTLS, DTLS);
3237}
3238
3239TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003240 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3241}
3242
deadbeeff5346592017-01-24 21:51:21 -08003243// Test using the channel with a raw packet interface, as opposed to a DTLS
3244// transport interface.
3245TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
3246 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
3247}
3248
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003249TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3250 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3251}
3252
3253TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3254 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3255}
3256
3257TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3258 Base::SendRtpToRtpOnThread();
3259}
3260
3261TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3262 Base::SendSrtpToSrtpOnThread();
3263}
3264
3265TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3266 Base::SendWithWritabilityLoss();
3267}
3268
3269TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3270 Base::TestMediaMonitor();
3271}
3272
3273TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3274 Base::TestSetContentFailure();
3275}
3276
3277TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3278 Base::TestSendTwoOffers();
3279}
3280
3281TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3282 Base::TestReceiveTwoOffers();
3283}
3284
3285TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3286 Base::TestSendPrAnswer();
3287}
3288
3289TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3290 Base::TestReceivePrAnswer();
3291}
3292
3293TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3294 Base::TestFlushRtcp();
3295}
3296
3297TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3298 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3299}
3300
3301TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3302 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3303}
3304
3305TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3306 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3307}
3308
3309TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3310 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3311}
3312
3313TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3314 Base::TestSrtpError(kVideoPts[0]);
3315}
3316
3317TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3318 Base::TestOnReadyToSend();
3319}
3320
3321TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3322 Base::TestOnReadyToSendWithRtcpMux();
3323}
3324
3325TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3326 Base::DefaultMaxBitrateIsUnlimited();
3327}
3328
3329TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3330 Base::CanChangeMaxBitrate();
3331}
3332
deadbeef953c2ce2017-01-09 14:53:41 -08003333// RtpDataChannelSingleThreadTest
3334class RtpDataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003335 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003336 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003337 RtpDataChannelSingleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003338 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3339};
3340
deadbeef953c2ce2017-01-09 14:53:41 -08003341// RtpDataChannelDoubleThreadTest
3342class RtpDataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003343 public:
3344 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003345 RtpDataChannelDoubleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003346 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347};
3348
3349// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003350template <>
deadbeef953c2ce2017-01-09 14:53:41 -08003351cricket::RtpDataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003352 rtc::Thread* worker_thread,
3353 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003354 cricket::MediaEngineInterface* engine,
3355 cricket::FakeDataMediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -08003356 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
3357 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
deadbeef5bd5ca32017-02-10 11:31:50 -08003358 rtc::PacketTransportInternal* fake_rtp_packet_transport,
3359 rtc::PacketTransportInternal* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -07003360 int flags) {
deadbeeff5346592017-01-24 21:51:21 -08003361 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef953c2ce2017-01-09 14:53:41 -08003362 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003363 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA,
deadbeefac22f702017-01-12 21:59:29 -08003364 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
jbauchcb560652016-08-04 05:20:32 -07003365 rtc::CryptoOptions crypto_options;
3366 crypto_options.enable_gcm_crypto_suites = (flags & GCM_CIPHER) != 0;
3367 channel->SetCryptoOptions(crypto_options);
deadbeeff5346592017-01-24 21:51:21 -08003368 if (!channel->NeedsRtcpTransport()) {
3369 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08003370 }
deadbeeff5346592017-01-24 21:51:21 -08003371 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
3372 fake_rtp_packet_transport, fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003373 delete channel;
3374 channel = NULL;
3375 }
3376 return channel;
3377}
3378
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003379template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380void ChannelTest<DataTraits>::CreateContent(
3381 int flags,
3382 const cricket::AudioCodec& audio_codec,
3383 const cricket::VideoCodec& video_codec,
3384 cricket::DataContentDescription* data) {
3385 data->AddCodec(kGoogleDataCodec);
3386 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3387 if (flags & SECURE) {
3388 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003389 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3390 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391 }
3392}
3393
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003394template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003395void ChannelTest<DataTraits>::CopyContent(
3396 const cricket::DataContentDescription& source,
3397 cricket::DataContentDescription* data) {
3398 *data = source;
3399}
3400
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003401template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3403 const cricket::DataCodec& c2) {
3404 return c1.name == c2.name;
3405}
3406
Peter Boström0c4e06b2015-10-07 12:23:21 +02003407template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003408void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003409 uint32_t ssrc,
3410 int flags,
3411 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412 data->AddLegacyStream(ssrc);
3413}
3414
deadbeef953c2ce2017-01-09 14:53:41 -08003415TEST_F(RtpDataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 Base::TestInit();
3417 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3418}
3419
deadbeef953c2ce2017-01-09 14:53:41 -08003420TEST_F(RtpDataChannelSingleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003421 Base::TestDeinit();
3422}
3423
deadbeef953c2ce2017-01-09 14:53:41 -08003424TEST_F(RtpDataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425 Base::TestSetContents();
3426}
3427
deadbeef953c2ce2017-01-09 14:53:41 -08003428TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429 Base::TestSetContentsNullOffer();
3430}
3431
deadbeef953c2ce2017-01-09 14:53:41 -08003432TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003433 Base::TestSetContentsRtcpMux();
3434}
3435
deadbeef953c2ce2017-01-09 14:53:41 -08003436TEST_F(RtpDataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003437 Base::TestSetRemoteContentUpdate();
3438}
3439
deadbeef953c2ce2017-01-09 14:53:41 -08003440TEST_F(RtpDataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441 Base::TestStreams();
3442}
3443
deadbeef953c2ce2017-01-09 14:53:41 -08003444TEST_F(RtpDataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445 Base::TestUpdateStreamsInLocalContent();
3446}
3447
deadbeef953c2ce2017-01-09 14:53:41 -08003448TEST_F(RtpDataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003449 Base::TestUpdateStreamsInRemoteContent();
3450}
3451
deadbeef953c2ce2017-01-09 14:53:41 -08003452TEST_F(RtpDataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453 Base::TestChangeStreamParamsInContent();
3454}
3455
deadbeef953c2ce2017-01-09 14:53:41 -08003456TEST_F(RtpDataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457 Base::TestPlayoutAndSendingStates();
3458}
3459
deadbeef953c2ce2017-01-09 14:53:41 -08003460TEST_F(RtpDataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461 Base::TestMediaContentDirection();
3462}
3463
deadbeef953c2ce2017-01-09 14:53:41 -08003464TEST_F(RtpDataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 Base::TestCallSetup();
3466}
3467
deadbeef953c2ce2017-01-09 14:53:41 -08003468TEST_F(RtpDataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003469 Base::TestCallTeardownRtcpMux();
3470}
3471
deadbeef953c2ce2017-01-09 14:53:41 -08003472TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473 Base::TestOnReadyToSend();
3474}
3475
deadbeef953c2ce2017-01-09 14:53:41 -08003476TEST_F(RtpDataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003477 Base::TestOnReadyToSendWithRtcpMux();
3478}
3479
deadbeef953c2ce2017-01-09 14:53:41 -08003480TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481 Base::SendRtpToRtp();
3482}
3483
deadbeef953c2ce2017-01-09 14:53:41 -08003484TEST_F(RtpDataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485 Base::SendRtcpToRtcp();
3486}
3487
deadbeef953c2ce2017-01-09 14:53:41 -08003488TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489 Base::SendRtcpMuxToRtcp();
3490}
3491
deadbeef953c2ce2017-01-09 14:53:41 -08003492TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 Base::SendRtcpMuxToRtcpMux();
3494}
3495
deadbeef953c2ce2017-01-09 14:53:41 -08003496TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 Base::SendEarlyRtcpMuxToRtcp();
3498}
3499
deadbeef953c2ce2017-01-09 14:53:41 -08003500TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 Base::SendEarlyRtcpMuxToRtcpMux();
3502}
3503
deadbeef953c2ce2017-01-09 14:53:41 -08003504TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505 Base::SendSrtpToSrtp();
3506}
3507
deadbeef953c2ce2017-01-09 14:53:41 -08003508TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509 Base::SendSrtpToSrtp();
3510}
3511
deadbeef953c2ce2017-01-09 14:53:41 -08003512TEST_F(RtpDataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3514}
3515
deadbeef953c2ce2017-01-09 14:53:41 -08003516TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517 Base::SendRtpToRtpOnThread();
3518}
3519
deadbeef953c2ce2017-01-09 14:53:41 -08003520TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521 Base::SendSrtpToSrtpOnThread();
3522}
3523
deadbeef953c2ce2017-01-09 14:53:41 -08003524TEST_F(RtpDataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525 Base::SendWithWritabilityLoss();
3526}
3527
deadbeef953c2ce2017-01-09 14:53:41 -08003528TEST_F(RtpDataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529 Base::TestMediaMonitor();
3530}
3531
deadbeef953c2ce2017-01-09 14:53:41 -08003532TEST_F(RtpDataChannelSingleThreadTest, TestSendData) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003533 CreateChannels(0, 0);
3534 EXPECT_TRUE(SendInitiate());
3535 EXPECT_TRUE(SendAccept());
3536
3537 cricket::SendDataParams params;
3538 params.ssrc = 42;
3539 unsigned char data[] = {'f', 'o', 'o'};
3540 rtc::CopyOnWriteBuffer payload(data, 3);
3541 cricket::SendDataResult result;
3542 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3543 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3544 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3545}
3546
deadbeef953c2ce2017-01-09 14:53:41 -08003547TEST_F(RtpDataChannelDoubleThreadTest, TestInit) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003548 Base::TestInit();
3549 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3550}
3551
deadbeef953c2ce2017-01-09 14:53:41 -08003552TEST_F(RtpDataChannelDoubleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003553 Base::TestDeinit();
3554}
3555
deadbeef953c2ce2017-01-09 14:53:41 -08003556TEST_F(RtpDataChannelDoubleThreadTest, TestSetContents) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003557 Base::TestSetContents();
3558}
3559
deadbeef953c2ce2017-01-09 14:53:41 -08003560TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsNullOffer) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003561 Base::TestSetContentsNullOffer();
3562}
3563
deadbeef953c2ce2017-01-09 14:53:41 -08003564TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003565 Base::TestSetContentsRtcpMux();
3566}
3567
deadbeef953c2ce2017-01-09 14:53:41 -08003568TEST_F(RtpDataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003569 Base::TestSetRemoteContentUpdate();
3570}
3571
deadbeef953c2ce2017-01-09 14:53:41 -08003572TEST_F(RtpDataChannelDoubleThreadTest, TestStreams) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003573 Base::TestStreams();
3574}
3575
deadbeef953c2ce2017-01-09 14:53:41 -08003576TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003577 Base::TestUpdateStreamsInLocalContent();
3578}
3579
deadbeef953c2ce2017-01-09 14:53:41 -08003580TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003581 Base::TestUpdateStreamsInRemoteContent();
3582}
3583
deadbeef953c2ce2017-01-09 14:53:41 -08003584TEST_F(RtpDataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003585 Base::TestChangeStreamParamsInContent();
3586}
3587
deadbeef953c2ce2017-01-09 14:53:41 -08003588TEST_F(RtpDataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003589 Base::TestPlayoutAndSendingStates();
3590}
3591
deadbeef953c2ce2017-01-09 14:53:41 -08003592TEST_F(RtpDataChannelDoubleThreadTest, TestMediaContentDirection) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003593 Base::TestMediaContentDirection();
3594}
3595
deadbeef953c2ce2017-01-09 14:53:41 -08003596TEST_F(RtpDataChannelDoubleThreadTest, TestCallSetup) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003597 Base::TestCallSetup();
3598}
3599
deadbeef953c2ce2017-01-09 14:53:41 -08003600TEST_F(RtpDataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003601 Base::TestCallTeardownRtcpMux();
3602}
3603
deadbeef953c2ce2017-01-09 14:53:41 -08003604TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSend) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003605 Base::TestOnReadyToSend();
3606}
3607
deadbeef953c2ce2017-01-09 14:53:41 -08003608TEST_F(RtpDataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003609 Base::TestOnReadyToSendWithRtcpMux();
3610}
3611
deadbeef953c2ce2017-01-09 14:53:41 -08003612TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003613 Base::SendRtpToRtp();
3614}
3615
deadbeef953c2ce2017-01-09 14:53:41 -08003616TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003617 Base::SendRtcpToRtcp();
3618}
3619
deadbeef953c2ce2017-01-09 14:53:41 -08003620TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003621 Base::SendRtcpMuxToRtcp();
3622}
3623
deadbeef953c2ce2017-01-09 14:53:41 -08003624TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003625 Base::SendRtcpMuxToRtcpMux();
3626}
3627
deadbeef953c2ce2017-01-09 14:53:41 -08003628TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003629 Base::SendEarlyRtcpMuxToRtcp();
3630}
3631
deadbeef953c2ce2017-01-09 14:53:41 -08003632TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003633 Base::SendEarlyRtcpMuxToRtcpMux();
3634}
3635
deadbeef953c2ce2017-01-09 14:53:41 -08003636TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003637 Base::SendSrtpToSrtp();
3638}
3639
deadbeef953c2ce2017-01-09 14:53:41 -08003640TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003641 Base::SendSrtpToSrtp();
3642}
3643
deadbeef953c2ce2017-01-09 14:53:41 -08003644TEST_F(RtpDataChannelDoubleThreadTest, SendSrtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003645 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3646}
3647
deadbeef953c2ce2017-01-09 14:53:41 -08003648TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003649 Base::SendRtpToRtpOnThread();
3650}
3651
deadbeef953c2ce2017-01-09 14:53:41 -08003652TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003653 Base::SendSrtpToSrtpOnThread();
3654}
3655
deadbeef953c2ce2017-01-09 14:53:41 -08003656TEST_F(RtpDataChannelDoubleThreadTest, SendWithWritabilityLoss) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003657 Base::SendWithWritabilityLoss();
3658}
3659
deadbeef953c2ce2017-01-09 14:53:41 -08003660TEST_F(RtpDataChannelDoubleThreadTest, TestMediaMonitor) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003661 Base::TestMediaMonitor();
3662}
3663
deadbeef953c2ce2017-01-09 14:53:41 -08003664TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003665 CreateChannels(0, 0);
3666 EXPECT_TRUE(SendInitiate());
3667 EXPECT_TRUE(SendAccept());
3668
3669 cricket::SendDataParams params;
3670 params.ssrc = 42;
3671 unsigned char data[] = {
3672 'f', 'o', 'o'
3673 };
jbaucheec21bd2016-03-20 06:15:43 -07003674 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003675 cricket::SendDataResult result;
3676 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3677 EXPECT_EQ(params.ssrc,
3678 media_channel1_->last_sent_data_params().ssrc);
3679 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3680}
3681
deadbeefbad5dad2017-01-17 18:32:35 -08003682#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3683
3684// Verifies some DCHECKs are in place.
3685// Uses VoiceChannel, but any BaseChannel subclass would work.
3686class BaseChannelDeathTest : public testing::Test {
3687 public:
3688 BaseChannelDeathTest()
deadbeeff5346592017-01-24 21:51:21 -08003689 : fake_rtp_dtls_transport_("foo", cricket::ICE_CANDIDATE_COMPONENT_RTP),
3690 fake_rtcp_dtls_transport_("foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP),
3691 // RTCP mux not required, SRTP required.
deadbeefbad5dad2017-01-17 18:32:35 -08003692 voice_channel_(
3693 rtc::Thread::Current(),
3694 rtc::Thread::Current(),
3695 rtc::Thread::Current(),
3696 &fake_media_engine_,
3697 new cricket::FakeVoiceMediaChannel(nullptr,
3698 cricket::AudioOptions()),
3699 cricket::CN_AUDIO,
3700 false,
deadbeeff5346592017-01-24 21:51:21 -08003701 true) {}
deadbeefbad5dad2017-01-17 18:32:35 -08003702
3703 protected:
deadbeefbad5dad2017-01-17 18:32:35 -08003704 cricket::FakeMediaEngine fake_media_engine_;
deadbeeff5346592017-01-24 21:51:21 -08003705 cricket::FakeDtlsTransport fake_rtp_dtls_transport_;
3706 cricket::FakeDtlsTransport fake_rtcp_dtls_transport_;
deadbeefbad5dad2017-01-17 18:32:35 -08003707 cricket::VoiceChannel voice_channel_;
deadbeefbad5dad2017-01-17 18:32:35 -08003708};
3709
deadbeeff5346592017-01-24 21:51:21 -08003710TEST_F(BaseChannelDeathTest, SetTransportsWithNullRtpTransport) {
3711 ASSERT_TRUE(voice_channel_.Init_w(
3712 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3713 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3714 cricket::FakeDtlsTransport new_rtcp_transport(
3715 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3716 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, &new_rtcp_transport), "");
deadbeefbad5dad2017-01-17 18:32:35 -08003717}
3718
deadbeeff5346592017-01-24 21:51:21 -08003719TEST_F(BaseChannelDeathTest, SetTransportsWithMissingRtcpTransport) {
3720 ASSERT_TRUE(voice_channel_.Init_w(
3721 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3722 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3723 cricket::FakeDtlsTransport new_rtp_transport(
3724 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3725 EXPECT_DEATH(voice_channel_.SetTransports(&new_rtp_transport, nullptr), "");
deadbeefbad5dad2017-01-17 18:32:35 -08003726}
3727
deadbeeff5346592017-01-24 21:51:21 -08003728TEST_F(BaseChannelDeathTest, SetTransportsWithUnneededRtcpTransport) {
3729 ASSERT_TRUE(voice_channel_.Init_w(
3730 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3731 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
deadbeefbad5dad2017-01-17 18:32:35 -08003732 // Activate RTCP muxing, simulating offer/answer negotiation.
3733 cricket::AudioContentDescription content;
3734 content.set_rtcp_mux(true);
3735 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
3736 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
deadbeeff5346592017-01-24 21:51:21 -08003737 cricket::FakeDtlsTransport new_rtp_transport(
3738 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3739 cricket::FakeDtlsTransport new_rtcp_transport(
3740 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
deadbeefbad5dad2017-01-17 18:32:35 -08003741 // After muxing is enabled, no RTCP transport should be passed in here.
3742 EXPECT_DEATH(
deadbeeff5346592017-01-24 21:51:21 -08003743 voice_channel_.SetTransports(&new_rtp_transport, &new_rtcp_transport),
3744 "");
deadbeefbad5dad2017-01-17 18:32:35 -08003745}
3746
3747// This test will probably go away if/when we move the transport name out of
3748// the transport classes and into their parent classes.
deadbeeff5346592017-01-24 21:51:21 -08003749TEST_F(BaseChannelDeathTest, SetTransportsWithMismatchingTransportNames) {
3750 ASSERT_TRUE(voice_channel_.Init_w(
3751 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3752 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3753 cricket::FakeDtlsTransport new_rtp_transport(
3754 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3755 cricket::FakeDtlsTransport new_rtcp_transport(
3756 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
deadbeefbad5dad2017-01-17 18:32:35 -08003757 EXPECT_DEATH(
deadbeeff5346592017-01-24 21:51:21 -08003758 voice_channel_.SetTransports(&new_rtp_transport, &new_rtcp_transport),
3759 "");
3760}
3761
3762// Not expected to support going from DtlsTransportInternal to
deadbeef5bd5ca32017-02-10 11:31:50 -08003763// PacketTransportInternal.
deadbeeff5346592017-01-24 21:51:21 -08003764TEST_F(BaseChannelDeathTest, SetTransportsDtlsToNonDtls) {
3765 ASSERT_TRUE(voice_channel_.Init_w(
3766 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3767 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3768 EXPECT_DEATH(
deadbeef5bd5ca32017-02-10 11:31:50 -08003769 voice_channel_.SetTransports(
3770 static_cast<rtc::PacketTransportInternal*>(&fake_rtp_dtls_transport_),
3771 static_cast<rtc::PacketTransportInternal*>(
3772 &fake_rtp_dtls_transport_)),
deadbeeff5346592017-01-24 21:51:21 -08003773 "");
3774}
3775
deadbeef5bd5ca32017-02-10 11:31:50 -08003776// Not expected to support going from PacketTransportInternal to
deadbeeff5346592017-01-24 21:51:21 -08003777// DtlsTransportInternal.
3778TEST_F(BaseChannelDeathTest, SetTransportsNonDtlsToDtls) {
3779 ASSERT_TRUE(voice_channel_.Init_w(nullptr, nullptr, &fake_rtp_dtls_transport_,
3780 &fake_rtcp_dtls_transport_));
3781 EXPECT_DEATH(voice_channel_.SetTransports(&fake_rtp_dtls_transport_,
3782 &fake_rtp_dtls_transport_),
3783 "");
deadbeefbad5dad2017-01-17 18:32:35 -08003784}
3785
3786#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3787
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003788// TODO(pthatcher): TestSetReceiver?