blob: cb7d318982c1c8a6ee1460176d9eb4b5a89316fd [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,
deadbeef5bd5ca32017-02-10 11:31:50 -0800100 // Use BaseChannel with PacketTransportInternal rather than
deadbeeff5346592017-01-24 21:51:21 -0800101 // DtlsTransportInternal.
deadbeef7914b8c2017-04-21 03:23:33 -0700102 RAW_PACKET_TRANSPORT = 0x20,
deadbeefac22f702017-01-12 21:59:29 -0800103 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
Peter Boström34fbfff2015-09-24 19:20:30 +0200105 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200106 rtc::ArrayView<const uint8_t> rtp_data,
107 rtc::ArrayView<const uint8_t> rtcp_data,
108 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200109 : verify_playout_(verify_playout),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200110 rtp_packet_(rtp_data.data(), rtp_data.size()),
deadbeeff5346592017-01-24 21:51:21 -0800111 rtcp_packet_(rtcp_data.data(), rtcp_data.size()) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200112 if (network_is_worker == NetworkIsWorker::Yes) {
113 network_thread_ = rtc::Thread::Current();
114 } else {
115 network_thread_keeper_ = rtc::Thread::Create();
116 network_thread_keeper_->SetName("Network", nullptr);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200117 network_thread_ = network_thread_keeper_.get();
118 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200119 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200122 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
123 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200124 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000125 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200126 void CreateChannels(typename T::MediaChannel* ch1,
127 typename T::MediaChannel* ch2,
128 int flags1,
129 int flags2) {
deadbeeff5346592017-01-24 21:51:21 -0800130 // Network thread is started in CreateChannels, to allow the test to
131 // configure a fake clock before any threads are spawned and attempt to
132 // access the time.
133 if (network_thread_keeper_) {
134 network_thread_keeper_->Start();
135 }
deadbeefac22f702017-01-12 21:59:29 -0800136 // Make sure RTCP_MUX_REQUIRED isn't set without RTCP_MUX.
deadbeeff5346592017-01-24 21:51:21 -0800137 RTC_DCHECK_NE(RTCP_MUX_REQUIRED, flags1 & (RTCP_MUX | RTCP_MUX_REQUIRED));
138 RTC_DCHECK_NE(RTCP_MUX_REQUIRED, flags2 & (RTCP_MUX | RTCP_MUX_REQUIRED));
139 // Make sure if using raw packet transports, they're used for both
140 // channels.
141 RTC_DCHECK_EQ(flags1 & RAW_PACKET_TRANSPORT, flags2 & RAW_PACKET_TRANSPORT);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200142 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 media_channel1_ = ch1;
144 media_channel2_ = ch2;
deadbeef5bd5ca32017-02-10 11:31:50 -0800145 rtc::PacketTransportInternal* rtp1 = nullptr;
146 rtc::PacketTransportInternal* rtcp1 = nullptr;
147 rtc::PacketTransportInternal* rtp2 = nullptr;
148 rtc::PacketTransportInternal* rtcp2 = nullptr;
deadbeeff5346592017-01-24 21:51:21 -0800149 // Based on flags, create fake DTLS or raw packet transports.
150 if (flags1 & RAW_PACKET_TRANSPORT) {
151 fake_rtp_packet_transport1_.reset(
152 new rtc::FakePacketTransport("channel1_rtp"));
153 rtp1 = fake_rtp_packet_transport1_.get();
154 if (!(flags1 & RTCP_MUX_REQUIRED)) {
155 fake_rtcp_packet_transport1_.reset(
156 new rtc::FakePacketTransport("channel1_rtcp"));
157 rtcp1 = fake_rtcp_packet_transport1_.get();
158 }
159 } else {
160 // Confirmed to work with KT_RSA and KT_ECDSA.
161 fake_rtp_dtls_transport1_.reset(new cricket::FakeDtlsTransport(
162 "channel1", cricket::ICE_CANDIDATE_COMPONENT_RTP));
163 rtp1 = fake_rtp_dtls_transport1_.get();
164 if (!(flags1 & RTCP_MUX_REQUIRED)) {
165 fake_rtcp_dtls_transport1_.reset(new cricket::FakeDtlsTransport(
166 "channel1", cricket::ICE_CANDIDATE_COMPONENT_RTCP));
167 rtcp1 = fake_rtcp_dtls_transport1_.get();
168 }
169 if (flags1 & DTLS) {
170 auto cert1 =
171 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
172 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT)));
173 fake_rtp_dtls_transport1_->SetLocalCertificate(cert1);
174 if (fake_rtcp_dtls_transport1_) {
175 fake_rtcp_dtls_transport1_->SetLocalCertificate(cert1);
176 }
177 }
178 }
179 // Based on flags, create fake DTLS or raw packet transports.
180 if (flags2 & RAW_PACKET_TRANSPORT) {
181 fake_rtp_packet_transport2_.reset(
182 new rtc::FakePacketTransport("channel2_rtp"));
183 rtp2 = fake_rtp_packet_transport2_.get();
184 if (!(flags2 & RTCP_MUX_REQUIRED)) {
185 fake_rtcp_packet_transport2_.reset(
186 new rtc::FakePacketTransport("channel2_rtcp"));
187 rtcp2 = fake_rtcp_packet_transport2_.get();
188 }
189 } else {
190 // Confirmed to work with KT_RSA and KT_ECDSA.
191 fake_rtp_dtls_transport2_.reset(new cricket::FakeDtlsTransport(
192 "channel2", cricket::ICE_CANDIDATE_COMPONENT_RTP));
193 rtp2 = fake_rtp_dtls_transport2_.get();
194 if (!(flags2 & RTCP_MUX_REQUIRED)) {
195 fake_rtcp_dtls_transport2_.reset(new cricket::FakeDtlsTransport(
196 "channel2", cricket::ICE_CANDIDATE_COMPONENT_RTCP));
197 rtcp2 = fake_rtcp_dtls_transport2_.get();
198 }
199 if (flags2 & DTLS) {
200 auto cert2 =
201 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
202 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT)));
203 fake_rtp_dtls_transport2_->SetLocalCertificate(cert2);
204 if (fake_rtcp_dtls_transport2_) {
205 fake_rtcp_dtls_transport2_->SetLocalCertificate(cert2);
206 }
207 }
208 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200209 channel1_.reset(
210 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
deadbeeff5346592017-01-24 21:51:21 -0800211 fake_rtp_dtls_transport1_.get(),
212 fake_rtcp_dtls_transport1_.get(), rtp1, rtcp1, flags1));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200213 channel2_.reset(
214 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
deadbeeff5346592017-01-24 21:51:21 -0800215 fake_rtp_dtls_transport2_.get(),
216 fake_rtcp_dtls_transport2_.get(), rtp2, rtcp2, flags2));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200217 channel1_->SignalMediaMonitor.connect(this,
218 &ChannelTest<T>::OnMediaMonitor1);
219 channel2_->SignalMediaMonitor.connect(this,
220 &ChannelTest<T>::OnMediaMonitor2);
deadbeefac22f702017-01-12 21:59:29 -0800221 channel1_->SignalRtcpMuxFullyActive.connect(
deadbeeff5346592017-01-24 21:51:21 -0800222 this, &ChannelTest<T>::OnRtcpMuxFullyActive1);
deadbeefac22f702017-01-12 21:59:29 -0800223 channel2_->SignalRtcpMuxFullyActive.connect(
deadbeeff5346592017-01-24 21:51:21 -0800224 this, &ChannelTest<T>::OnRtcpMuxFullyActive2);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000225 if ((flags1 & DTLS) && (flags2 & DTLS)) {
226 flags1 = (flags1 & ~SECURE);
227 flags2 = (flags2 & ~SECURE);
228 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 CreateContent(flags1, kPcmuCodec, kH264Codec,
230 &local_media_content1_);
231 CreateContent(flags2, kPcmuCodec, kH264Codec,
232 &local_media_content2_);
233 CopyContent(local_media_content1_, &remote_media_content1_);
234 CopyContent(local_media_content2_, &remote_media_content2_);
235
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 // Add stream information (SSRC) to the local content but not to the remote
237 // content. This means that we per default know the SSRC of what we send but
238 // not what we receive.
239 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
240 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
241
242 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
243 if (flags1 & SSRC_MUX) {
244 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
245 }
246 if (flags2 & SSRC_MUX) {
247 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
248 }
249 }
deadbeefcbecd352015-09-23 11:50:27 -0700250 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200251 rtc::Thread* worker_thread,
252 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700253 cricket::MediaEngineInterface* engine,
254 typename T::MediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -0800255 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
256 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
deadbeef5bd5ca32017-02-10 11:31:50 -0800257 rtc::PacketTransportInternal* fake_rtp_packet_transport,
258 rtc::PacketTransportInternal* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -0700259 int flags) {
deadbeeff5346592017-01-24 21:51:21 -0800260 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef7af91dd2016-12-13 11:29:11 -0800261 typename T::Channel* channel = new typename T::Channel(
zhihuangf5b251b2017-01-12 19:37:48 -0800262 worker_thread, network_thread, signaling_thread, engine, ch,
deadbeefac22f702017-01-12 21:59:29 -0800263 cricket::CN_AUDIO, (flags & RTCP_MUX_REQUIRED) != 0,
264 (flags & SECURE) != 0);
deadbeeff5346592017-01-24 21:51:21 -0800265 if (!channel->NeedsRtcpTransport()) {
266 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -0800267 }
deadbeeff5346592017-01-24 21:51:21 -0800268 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
269 fake_rtp_packet_transport,
270 fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 delete channel;
272 channel = NULL;
273 }
274 return channel;
275 }
276
deadbeeff5346592017-01-24 21:51:21 -0800277 void ConnectFakeTransports() {
278 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
279 bool asymmetric = false;
280 // Depending on test flags, could be using DTLS or raw packet transport.
281 if (fake_rtp_dtls_transport1_ && fake_rtp_dtls_transport2_) {
282 fake_rtp_dtls_transport1_->SetDestination(
283 fake_rtp_dtls_transport2_.get(), asymmetric);
284 }
285 if (fake_rtcp_dtls_transport1_ && fake_rtcp_dtls_transport2_) {
286 fake_rtcp_dtls_transport1_->SetDestination(
287 fake_rtcp_dtls_transport2_.get(), asymmetric);
288 }
289 if (fake_rtp_packet_transport1_ && fake_rtp_packet_transport2_) {
290 fake_rtp_packet_transport1_->SetDestination(
291 fake_rtp_packet_transport2_.get(), asymmetric);
292 }
293 if (fake_rtcp_packet_transport1_ && fake_rtcp_packet_transport2_) {
294 fake_rtcp_packet_transport1_->SetDestination(
295 fake_rtcp_packet_transport2_.get(), asymmetric);
296 }
297 });
298 }
299
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000301 bool result = channel1_->SetLocalContent(&local_media_content1_,
302 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 if (result) {
304 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000305 result = channel2_->SetRemoteContent(&remote_media_content1_,
306 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 if (result) {
deadbeeff5346592017-01-24 21:51:21 -0800308 ConnectFakeTransports();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000309 result = channel2_->SetLocalContent(&local_media_content2_,
310 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 }
312 }
313 return result;
314 }
315
316 bool SendAccept() {
317 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000318 return channel1_->SetRemoteContent(&remote_media_content2_,
319 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 }
321
322 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000323 bool result = channel1_->SetLocalContent(&local_media_content1_,
324 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 if (result) {
326 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000327 result = channel2_->SetRemoteContent(&remote_media_content1_,
328 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
330 return result;
331 }
332
333 bool SendProvisionalAnswer() {
334 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000335 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 if (result) {
337 channel2_->Enable(true);
338 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000339 CA_PRANSWER, NULL);
deadbeeff5346592017-01-24 21:51:21 -0800340 ConnectFakeTransports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
342 return result;
343 }
344
345 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000346 bool result = channel2_->SetLocalContent(&local_media_content2_,
347 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000349 result = channel1_->SetRemoteContent(&remote_media_content2_,
350 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 return result;
352 }
353
deadbeeff5346592017-01-24 21:51:21 -0800354 bool Terminate() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 channel1_.reset();
356 channel2_.reset();
deadbeeff5346592017-01-24 21:51:21 -0800357 fake_rtp_dtls_transport1_.reset();
358 fake_rtcp_dtls_transport1_.reset();
359 fake_rtp_dtls_transport2_.reset();
360 fake_rtcp_dtls_transport2_.reset();
361 fake_rtp_packet_transport1_.reset();
362 fake_rtcp_packet_transport1_.reset();
363 fake_rtp_packet_transport2_.reset();
364 fake_rtcp_packet_transport2_.reset();
365 if (network_thread_keeper_) {
366 network_thread_keeper_.reset();
367 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 return true;
369 }
370
371 bool AddStream1(int id) {
372 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
373 }
374 bool RemoveStream1(int id) {
375 return channel1_->RemoveRecvStream(id);
376 }
377
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200378 void SendRtp1() {
379 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
380 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200382 void SendRtp2() {
383 media_channel2_->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 SendRtcp1() {
387 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200389 void SendRtcp2() {
390 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 }
392 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200393 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
394 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
395 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200397 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
398 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
399 media_channel2_->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 SendCustomRtcp1(uint32_t ssrc) {
402 rtc::Buffer data = CreateRtcpData(ssrc);
403 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200405 void SendCustomRtcp2(uint32_t ssrc) {
406 rtc::Buffer data = CreateRtcpData(ssrc);
407 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200409
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200411 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 }
413 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200414 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 }
416 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200417 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 }
419 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200420 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 }
422 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200423 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200424 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
425 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200427 bool CheckCustomRtp2(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_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200431 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200432 rtc::Buffer data = CreateRtcpData(ssrc);
433 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200435 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200436 rtc::Buffer data = CreateRtcpData(ssrc);
437 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000438 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200439 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
440 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200442 rtc::SetBE32(data.data() + 8, ssrc);
443 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000444 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200445 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000446 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 return data;
448 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200449 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
450 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000451 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200452 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 return data;
454 }
455
456 bool CheckNoRtp1() {
457 return media_channel1_->CheckNoRtp();
458 }
459 bool CheckNoRtp2() {
460 return media_channel2_->CheckNoRtp();
461 }
462 bool CheckNoRtcp1() {
463 return media_channel1_->CheckNoRtcp();
464 }
465 bool CheckNoRtcp2() {
466 return media_channel2_->CheckNoRtcp();
467 }
468
469 void CreateContent(int flags,
470 const cricket::AudioCodec& audio_codec,
471 const cricket::VideoCodec& video_codec,
472 typename T::Content* content) {
473 // overridden in specialized classes
474 }
475 void CopyContent(const typename T::Content& source,
476 typename T::Content* content) {
477 // overridden in specialized classes
478 }
479
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000480 // Creates a cricket::SessionDescription with one MediaContent and one stream.
481 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200482 cricket::SessionDescription* CreateSessionDescriptionWithStream(
483 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 typename T::Content content;
485 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
486 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
487 AddLegacyStreamInContent(ssrc, 0, &content);
488 sdesc->AddContent("DUMMY_CONTENT_NAME",
489 cricket::NS_JINGLE_RTP, content.Copy());
490 return sdesc;
491 }
492
ossu292d6582016-03-17 02:31:13 -0700493 // Will manage the lifetime of a CallThread, making sure it's
494 // destroyed before this object goes out of scope.
495 class ScopedCallThread {
496 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200497 template <class FunctorT>
498 ScopedCallThread(const FunctorT& functor)
499 : thread_(rtc::Thread::Create()),
500 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700501 thread_->Start();
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -0700502 thread_->Post(RTC_FROM_HERE, task_.get());
ossu292d6582016-03-17 02:31:13 -0700503 }
504
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200505 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700506
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200507 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700508
509 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200510 std::unique_ptr<rtc::Thread> thread_;
511 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700512 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
515 return false; // overridden in specialized classes
516 }
517
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200518 void OnMediaMonitor1(typename T::Channel* channel,
519 const typename T::MediaInfo& info) {
520 RTC_DCHECK_EQ(channel, channel1_.get());
521 media_info_callbacks1_++;
522 }
523 void OnMediaMonitor2(typename T::Channel* channel,
524 const typename T::MediaInfo& info) {
525 RTC_DCHECK_EQ(channel, channel2_.get());
526 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 }
deadbeeff5346592017-01-24 21:51:21 -0800528 void OnRtcpMuxFullyActive1(const std::string&) {
529 rtcp_mux_activated_callbacks1_++;
530 }
531 void OnRtcpMuxFullyActive2(const std::string&) {
532 rtcp_mux_activated_callbacks2_++;
533 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534
Honghai Zhangcc411c02016-03-29 17:27:21 -0700535 cricket::CandidatePairInterface* last_selected_candidate_pair() {
536 return last_selected_candidate_pair_;
537 }
538
Peter Boström0c4e06b2015-10-07 12:23:21 +0200539 void AddLegacyStreamInContent(uint32_t ssrc,
540 int flags,
541 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542 // Base implementation.
543 }
544
545 // Tests that can be used by derived classes.
546
547 // Basic sanity check.
548 void TestInit() {
549 CreateChannels(0, 0);
550 EXPECT_FALSE(channel1_->secure());
551 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200552 if (verify_playout_) {
553 EXPECT_FALSE(media_channel1_->playout());
554 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 EXPECT_TRUE(media_channel1_->codecs().empty());
556 EXPECT_TRUE(media_channel1_->recv_streams().empty());
557 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
558 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
559 }
560
561 // Test that SetLocalContent and SetRemoteContent properly configure
562 // the codecs.
563 void TestSetContents() {
564 CreateChannels(0, 0);
565 typename T::Content content;
566 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000567 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000569 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 ASSERT_EQ(1U, media_channel1_->codecs().size());
571 EXPECT_TRUE(CodecMatches(content.codecs()[0],
572 media_channel1_->codecs()[0]));
573 }
574
575 // Test that SetLocalContent and SetRemoteContent properly deals
576 // with an empty offer.
577 void TestSetContentsNullOffer() {
578 CreateChannels(0, 0);
579 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000580 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 CreateContent(0, kPcmuCodec, kH264Codec, &content);
582 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000583 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 ASSERT_EQ(1U, media_channel1_->codecs().size());
585 EXPECT_TRUE(CodecMatches(content.codecs()[0],
586 media_channel1_->codecs()[0]));
587 }
588
589 // Test that SetLocalContent and SetRemoteContent properly set RTCP
590 // mux.
591 void TestSetContentsRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -0800592 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 typename T::Content content;
594 CreateContent(0, kPcmuCodec, kH264Codec, &content);
595 // Both sides agree on mux. Should no longer be a separate RTCP channel.
596 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000597 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
598 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000600 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000601 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000602 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 }
604
605 // Test that SetLocalContent and SetRemoteContent properly set RTCP
606 // mux when a provisional answer is received.
607 void TestSetContentsRtcpMuxWithPrAnswer() {
deadbeefac22f702017-01-12 21:59:29 -0800608 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 typename T::Content content;
610 CreateContent(0, kPcmuCodec, kH264Codec, &content);
611 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000612 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
613 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800614 // Both sides agree on mux. Should signal RTCP mux as fully activated.
615 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000616 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800617 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000619 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000621 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
622 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800623 EXPECT_EQ(0, rtcp_mux_activated_callbacks2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 }
625
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 // Test that SetRemoteContent properly deals with a content update.
627 void TestSetRemoteContentUpdate() {
628 CreateChannels(0, 0);
629 typename T::Content content;
deadbeefac22f702017-01-12 21:59:29 -0800630 CreateContent(RTCP_MUX | SECURE, kPcmuCodec, kH264Codec, &content);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000632 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
633 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634 ASSERT_EQ(1U, media_channel1_->codecs().size());
635 EXPECT_TRUE(CodecMatches(content.codecs()[0],
636 media_channel1_->codecs()[0]));
637 // Now update with other codecs.
638 typename T::Content update_content;
639 update_content.set_partial(true);
640 CreateContent(0, kIsacCodec, kH264SvcCodec,
641 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000642 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 ASSERT_EQ(1U, media_channel1_->codecs().size());
644 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
645 media_channel1_->codecs()[0]));
646 // Now update without any codecs. This is ignored.
647 typename T::Content empty_content;
648 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000649 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 ASSERT_EQ(1U, media_channel1_->codecs().size());
651 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
652 media_channel1_->codecs()[0]));
653 }
654
655 // Test that Add/RemoveStream properly forward to the media channel.
656 void TestStreams() {
657 CreateChannels(0, 0);
658 EXPECT_TRUE(AddStream1(1));
659 EXPECT_TRUE(AddStream1(2));
660 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
661 EXPECT_TRUE(RemoveStream1(2));
662 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
663 EXPECT_TRUE(RemoveStream1(1));
664 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
665 }
666
667 // Test that SetLocalContent properly handles adding and removing StreamParams
668 // to the local content description.
669 // This test uses the CA_UPDATE action that don't require a full
670 // MediaContentDescription to do an update.
671 void TestUpdateStreamsInLocalContent() {
672 cricket::StreamParams stream1;
673 stream1.groupid = "group1";
674 stream1.id = "stream1";
675 stream1.ssrcs.push_back(kSsrc1);
676 stream1.cname = "stream1_cname";
677
678 cricket::StreamParams stream2;
679 stream2.groupid = "group2";
680 stream2.id = "stream2";
681 stream2.ssrcs.push_back(kSsrc2);
682 stream2.cname = "stream2_cname";
683
684 cricket::StreamParams stream3;
685 stream3.groupid = "group3";
686 stream3.id = "stream3";
687 stream3.ssrcs.push_back(kSsrc3);
688 stream3.cname = "stream3_cname";
689
690 CreateChannels(0, 0);
691 typename T::Content content1;
692 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
693 content1.AddStream(stream1);
694 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000695 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696
697 ASSERT_EQ(1u, media_channel1_->send_streams().size());
698 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
699
700 // Update the local streams by adding another sending stream.
701 // Use a partial updated session description.
702 typename T::Content content2;
703 content2.AddStream(stream2);
704 content2.AddStream(stream3);
705 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000706 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 ASSERT_EQ(3u, media_channel1_->send_streams().size());
708 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
709 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
710 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
711
712 // Update the local streams by removing the first sending stream.
713 // This is done by removing all SSRCS for this particular stream.
714 typename T::Content content3;
715 stream1.ssrcs.clear();
716 content3.AddStream(stream1);
717 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000718 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719 ASSERT_EQ(2u, media_channel1_->send_streams().size());
720 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
721 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
722
723 // Update the local streams with a stream that does not change.
724 // THe update is ignored.
725 typename T::Content content4;
726 content4.AddStream(stream2);
727 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 ASSERT_EQ(2u, media_channel1_->send_streams().size());
730 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
731 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
732 }
733
734 // Test that SetRemoteContent properly handles adding and removing
735 // StreamParams to the remote content description.
736 // This test uses the CA_UPDATE action that don't require a full
737 // MediaContentDescription to do an update.
738 void TestUpdateStreamsInRemoteContent() {
739 cricket::StreamParams stream1;
740 stream1.id = "Stream1";
741 stream1.groupid = "1";
742 stream1.ssrcs.push_back(kSsrc1);
743 stream1.cname = "stream1_cname";
744
745 cricket::StreamParams stream2;
746 stream2.id = "Stream2";
747 stream2.groupid = "2";
748 stream2.ssrcs.push_back(kSsrc2);
749 stream2.cname = "stream2_cname";
750
751 cricket::StreamParams stream3;
752 stream3.id = "Stream3";
753 stream3.groupid = "3";
754 stream3.ssrcs.push_back(kSsrc3);
755 stream3.cname = "stream3_cname";
756
757 CreateChannels(0, 0);
758 typename T::Content content1;
759 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
760 content1.AddStream(stream1);
761 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000762 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
764 ASSERT_EQ(1u, media_channel1_->codecs().size());
765 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
766 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
767
768 // Update the remote streams by adding another sending stream.
769 // Use a partial updated session description.
770 typename T::Content content2;
771 content2.AddStream(stream2);
772 content2.AddStream(stream3);
773 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000774 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
776 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
777 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
778 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
779
780 // Update the remote streams by removing the first stream.
781 // This is done by removing all SSRCS for this particular stream.
782 typename T::Content content3;
783 stream1.ssrcs.clear();
784 content3.AddStream(stream1);
785 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000786 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
788 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
789 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
790
791 // Update the remote streams with a stream that does not change.
792 // The update is ignored.
793 typename T::Content content4;
794 content4.AddStream(stream2);
795 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000796 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
798 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
799 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
800 }
801
802 // Test that SetLocalContent and SetRemoteContent properly
803 // handles adding and removing StreamParams when the action is a full
804 // CA_OFFER / CA_ANSWER.
805 void TestChangeStreamParamsInContent() {
806 cricket::StreamParams stream1;
807 stream1.groupid = "group1";
808 stream1.id = "stream1";
809 stream1.ssrcs.push_back(kSsrc1);
810 stream1.cname = "stream1_cname";
811
812 cricket::StreamParams stream2;
813 stream2.groupid = "group1";
814 stream2.id = "stream2";
815 stream2.ssrcs.push_back(kSsrc2);
816 stream2.cname = "stream2_cname";
817
818 // Setup a call where channel 1 send |stream1| to channel 2.
819 CreateChannels(0, 0);
820 typename T::Content content1;
821 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
822 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000823 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 EXPECT_TRUE(channel1_->Enable(true));
825 EXPECT_EQ(1u, media_channel1_->send_streams().size());
826
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000827 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeeff5346592017-01-24 21:51:21 -0800829 ConnectFakeTransports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830
831 // Channel 2 do not send anything.
832 typename T::Content content2;
833 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000834 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000836 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 EXPECT_TRUE(channel2_->Enable(true));
838 EXPECT_EQ(0u, media_channel2_->send_streams().size());
839
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200840 SendCustomRtp1(kSsrc1, 0);
841 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
843
844 // Let channel 2 update the content by sending |stream2| and enable SRTP.
845 typename T::Content content3;
846 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
847 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000848 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 ASSERT_EQ(1u, media_channel2_->send_streams().size());
850 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
851
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000852 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
854 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
855
856 // Channel 1 replies but stop sending stream1.
857 typename T::Content content4;
858 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000859 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 EXPECT_EQ(0u, media_channel1_->send_streams().size());
861
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000862 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
864
865 EXPECT_TRUE(channel1_->secure());
866 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200867 SendCustomRtp2(kSsrc2, 0);
868 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
870 }
871
872 // Test that we only start playout and sending at the right times.
873 void TestPlayoutAndSendingStates() {
874 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200875 if (verify_playout_) {
876 EXPECT_FALSE(media_channel1_->playout());
877 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200879 if (verify_playout_) {
880 EXPECT_FALSE(media_channel2_->playout());
881 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 EXPECT_FALSE(media_channel2_->sending());
883 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200884 if (verify_playout_) {
885 EXPECT_FALSE(media_channel1_->playout());
886 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000888 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
889 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200890 if (verify_playout_) {
891 EXPECT_TRUE(media_channel1_->playout());
892 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000894 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
895 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200896 if (verify_playout_) {
897 EXPECT_FALSE(media_channel2_->playout());
898 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000900 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
901 CA_ANSWER, NULL));
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());
deadbeeff5346592017-01-24 21:51:21 -0800906 ConnectFakeTransports();
Peter Boström34fbfff2015-09-24 19:20:30 +0200907 if (verify_playout_) {
908 EXPECT_TRUE(media_channel1_->playout());
909 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200911 if (verify_playout_) {
912 EXPECT_FALSE(media_channel2_->playout());
913 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 EXPECT_FALSE(media_channel2_->sending());
915 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200916 if (verify_playout_) {
917 EXPECT_TRUE(media_channel2_->playout());
918 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000920 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
921 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200922 if (verify_playout_) {
923 EXPECT_TRUE(media_channel1_->playout());
924 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 EXPECT_TRUE(media_channel1_->sending());
926 }
927
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 // Test that changing the MediaContentDirection in the local and remote
929 // session description start playout and sending at the right time.
930 void TestMediaContentDirection() {
931 CreateChannels(0, 0);
932 typename T::Content content1;
933 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
934 typename T::Content content2;
935 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
936 // Set |content2| to be InActive.
937 content2.set_direction(cricket::MD_INACTIVE);
938
939 EXPECT_TRUE(channel1_->Enable(true));
940 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200941 if (verify_playout_) {
942 EXPECT_FALSE(media_channel1_->playout());
943 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200945 if (verify_playout_) {
946 EXPECT_FALSE(media_channel2_->playout());
947 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_FALSE(media_channel2_->sending());
949
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000950 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
951 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
952 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
953 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -0800954 ConnectFakeTransports();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955
Peter Boström34fbfff2015-09-24 19:20:30 +0200956 if (verify_playout_) {
957 EXPECT_TRUE(media_channel1_->playout());
958 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200960 if (verify_playout_) {
961 EXPECT_FALSE(media_channel2_->playout()); // local InActive
962 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 EXPECT_FALSE(media_channel2_->sending()); // local InActive
964
965 // Update |content2| to be RecvOnly.
966 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000967 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
968 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969
Peter Boström34fbfff2015-09-24 19:20:30 +0200970 if (verify_playout_) {
971 EXPECT_TRUE(media_channel1_->playout());
972 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200974 if (verify_playout_) {
975 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
976 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
978
979 // Update |content2| to be SendRecv.
980 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000981 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
982 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983
Peter Boström34fbfff2015-09-24 19:20:30 +0200984 if (verify_playout_) {
985 EXPECT_TRUE(media_channel1_->playout());
986 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000987 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200988 if (verify_playout_) {
989 EXPECT_TRUE(media_channel2_->playout());
990 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 EXPECT_TRUE(media_channel2_->sending());
992 }
993
Honghai Zhangcc411c02016-03-29 17:27:21 -0700994 // Tests that when the transport channel signals a candidate pair change
995 // event, the media channel will receive a call on the network route change.
996 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200997 constexpr uint16_t kLocalNetId = 1;
998 constexpr uint16_t kRemoteNetId = 2;
999 constexpr int kLastPacketId = 100;
1000
Honghai Zhangcc411c02016-03-29 17:27:21 -07001001 CreateChannels(0, 0);
1002
Honghai Zhangcc411c02016-03-29 17:27:21 -07001003 typename T::MediaChannel* media_channel1 =
1004 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001005 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -07001006
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001007 media_channel1->set_num_network_route_changes(0);
deadbeeff5346592017-01-24 21:51:21 -08001008 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001009 // The transport channel becomes disconnected.
deadbeeff5346592017-01-24 21:51:21 -08001010 fake_rtp_dtls_transport1_->ice_transport()
1011 ->SignalSelectedCandidatePairChanged(
1012 fake_rtp_dtls_transport1_->ice_transport(), nullptr, -1, false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001013 });
1014 WaitForThreads();
1015 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -07001016 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001017 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -07001018
deadbeeff5346592017-01-24 21:51:21 -08001019 network_thread_->Invoke<void>(RTC_FROM_HERE, [this, media_channel1,
1020 kLocalNetId, kRemoteNetId,
1021 kLastPacketId] {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001022 // The transport channel becomes connected.
1023 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
1024 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
deadbeeff5346592017-01-24 21:51:21 -08001025 auto candidate_pair = cricket::FakeCandidatePair::Create(
1026 local_address, kLocalNetId, remote_address, kRemoteNetId);
1027 fake_rtp_dtls_transport1_->ice_transport()
1028 ->SignalSelectedCandidatePairChanged(
1029 fake_rtp_dtls_transport1_->ice_transport(), candidate_pair.get(),
1030 kLastPacketId, true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001031 });
1032 WaitForThreads();
1033 EXPECT_EQ(1, media_channel1->num_network_route_changes());
honghaiz059e1832016-06-24 11:03:55 -07001034 rtc::NetworkRoute expected_network_route(true, kLocalNetId, kRemoteNetId,
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001035 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -07001036 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001037 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -07001038 media_channel1->last_network_route().last_sent_packet_id);
michaelt79e05882016-11-08 02:50:09 -08001039 constexpr int kTransportOverheadPerPacket = 28; // Ipv4(20) + UDP(8).
1040 EXPECT_EQ(kTransportOverheadPerPacket,
1041 media_channel1->transport_overhead_per_packet());
Honghai Zhangcc411c02016-03-29 17:27:21 -07001042 }
1043
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 // Test setting up a call.
1045 void TestCallSetup() {
1046 CreateChannels(0, 0);
1047 EXPECT_FALSE(channel1_->secure());
1048 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +02001049 if (verify_playout_) {
1050 EXPECT_TRUE(media_channel1_->playout());
1051 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 EXPECT_FALSE(media_channel1_->sending());
1053 EXPECT_TRUE(SendAccept());
1054 EXPECT_FALSE(channel1_->secure());
1055 EXPECT_TRUE(media_channel1_->sending());
1056 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +02001057 if (verify_playout_) {
1058 EXPECT_TRUE(media_channel2_->playout());
1059 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 EXPECT_TRUE(media_channel2_->sending());
1061 EXPECT_EQ(1U, media_channel2_->codecs().size());
1062 }
1063
1064 // Test that we don't crash if packets are sent during call teardown
1065 // when RTCP mux is enabled. This is a regression test against a specific
1066 // race condition that would only occur when a RTCP packet was sent during
1067 // teardown of a channel on which RTCP mux was enabled.
1068 void TestCallTeardownRtcpMux() {
1069 class LastWordMediaChannel : public T::MediaChannel {
1070 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001071 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001073 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1074 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1076 }
1077 };
1078 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
deadbeefac22f702017-01-12 21:59:29 -08001079 RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 EXPECT_TRUE(SendInitiate());
1081 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001082 EXPECT_TRUE(Terminate());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 }
1084
1085 // Send voice RTP data to the other side and ensure it gets there.
1086 void SendRtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001087 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 EXPECT_TRUE(SendInitiate());
1089 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001090 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1091 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001092 SendRtp1();
1093 SendRtp2();
1094 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001095 EXPECT_TRUE(CheckRtp1());
1096 EXPECT_TRUE(CheckRtp2());
1097 EXPECT_TRUE(CheckNoRtp1());
1098 EXPECT_TRUE(CheckNoRtp2());
1099 }
1100
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001101 void TestDeinit() {
deadbeefac22f702017-01-12 21:59:29 -08001102 CreateChannels(0, 0);
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001103 EXPECT_TRUE(SendInitiate());
1104 EXPECT_TRUE(SendAccept());
1105 SendRtp1();
1106 SendRtp2();
1107 SendRtcp1();
1108 SendRtcp2();
1109 // Do not wait, destroy channels.
1110 channel1_.reset(nullptr);
1111 channel2_.reset(nullptr);
1112 }
1113
deadbeefac22f702017-01-12 21:59:29 -08001114 // Check that RTCP can be transmitted between both sides.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 void SendRtcpToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001116 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 EXPECT_TRUE(SendInitiate());
1118 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001119 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1120 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001121 SendRtcp1();
1122 SendRtcp2();
1123 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 EXPECT_TRUE(CheckRtcp1());
1125 EXPECT_TRUE(CheckRtcp2());
1126 EXPECT_TRUE(CheckNoRtcp1());
1127 EXPECT_TRUE(CheckNoRtcp2());
1128 }
1129
1130 // Check that RTCP is transmitted if only the initiator supports mux.
1131 void SendRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001132 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133 EXPECT_TRUE(SendInitiate());
1134 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001135 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1136 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001137 SendRtcp1();
1138 SendRtcp2();
1139 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 EXPECT_TRUE(CheckRtcp1());
1141 EXPECT_TRUE(CheckRtcp2());
1142 EXPECT_TRUE(CheckNoRtcp1());
1143 EXPECT_TRUE(CheckNoRtcp2());
1144 }
1145
1146 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1147 void SendRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001148 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001150 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1151 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
1152 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001154 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1155 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001156 SendRtp1();
1157 SendRtp2();
1158 SendRtcp1();
1159 SendRtcp2();
1160 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 EXPECT_TRUE(CheckRtp1());
1162 EXPECT_TRUE(CheckRtp2());
1163 EXPECT_TRUE(CheckNoRtp1());
1164 EXPECT_TRUE(CheckNoRtp2());
1165 EXPECT_TRUE(CheckRtcp1());
1166 EXPECT_TRUE(CheckRtcp2());
1167 EXPECT_TRUE(CheckNoRtcp1());
1168 EXPECT_TRUE(CheckNoRtcp2());
1169 }
1170
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001171 // Check that RTP and RTCP are transmitted ok when both sides
1172 // support mux and one the offerer requires mux.
1173 void SendRequireRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001174 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001175 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001176 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1177 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001178 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001179 SendRtp1();
1180 SendRtp2();
1181 SendRtcp1();
1182 SendRtcp2();
1183 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001184 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
1194 // Check that RTP and RTCP are transmitted ok when both sides
deadbeefac22f702017-01-12 21:59:29 -08001195 // support mux and only the answerer requires rtcp mux.
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001196 void SendRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001197 CreateChannels(RTCP_MUX, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001198 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001199 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1200 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
1201 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001202 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001203 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1204 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001205 SendRtp1();
1206 SendRtp2();
1207 SendRtcp1();
1208 SendRtcp2();
1209 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001210 EXPECT_TRUE(CheckRtp1());
1211 EXPECT_TRUE(CheckRtp2());
1212 EXPECT_TRUE(CheckNoRtp1());
1213 EXPECT_TRUE(CheckNoRtp2());
1214 EXPECT_TRUE(CheckRtcp1());
1215 EXPECT_TRUE(CheckRtcp2());
1216 EXPECT_TRUE(CheckNoRtcp1());
1217 EXPECT_TRUE(CheckNoRtcp2());
1218 }
1219
1220 // Check that RTP and RTCP are transmitted ok when both sides
1221 // require mux.
1222 void SendRequireRtcpMuxToRequireRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001223 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001224 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001225 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1226 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001227 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001228 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001229 SendRtp1();
1230 SendRtp2();
1231 SendRtcp1();
1232 SendRtcp2();
1233 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001234 EXPECT_TRUE(CheckRtp1());
1235 EXPECT_TRUE(CheckRtp2());
1236 EXPECT_TRUE(CheckNoRtp1());
1237 EXPECT_TRUE(CheckNoRtp2());
1238 EXPECT_TRUE(CheckRtcp1());
1239 EXPECT_TRUE(CheckRtcp2());
1240 EXPECT_TRUE(CheckNoRtcp1());
1241 EXPECT_TRUE(CheckNoRtcp2());
1242 }
1243
1244 // Check that SendAccept fails if the answerer doesn't support mux
1245 // and the offerer requires it.
1246 void SendRequireRtcpMuxToNoRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001247 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, 0);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001248 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001249 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1250 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001251 EXPECT_FALSE(SendAccept());
1252 }
1253
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 // Check that RTCP data sent by the initiator before the accept is not muxed.
1255 void SendEarlyRtcpMuxToRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001256 CreateChannels(RTCP_MUX, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001258 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1259 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260
1261 // RTCP can be sent before the call is accepted, if the transport is ready.
1262 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001263 SendRtcp1();
1264 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265 EXPECT_TRUE(CheckNoRtp2());
1266 EXPECT_TRUE(CheckRtcp2());
1267
1268 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001269 SendRtcp2();
1270 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 EXPECT_TRUE(CheckNoRtp1());
1272 EXPECT_TRUE(CheckRtcp1());
1273
1274 // Complete call setup and ensure everything is still OK.
1275 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001276 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001277 SendRtcp1();
1278 SendRtcp2();
1279 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001280 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 EXPECT_TRUE(CheckRtcp1());
1282 }
1283
1284
1285 // Check that RTCP data is not muxed until both sides have enabled muxing,
1286 // but that we properly demux before we get the accept message, since there
1287 // is a race between RTP data and the jingle accept.
1288 void SendEarlyRtcpMuxToRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001289 CreateChannels(RTCP_MUX, RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001291 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1292 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293
1294 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1295 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001296 SendRtcp1();
1297 WaitForThreads();
1298 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299
1300 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001301 SendRtcp2();
1302 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 EXPECT_TRUE(CheckNoRtp1());
1304 EXPECT_TRUE(CheckRtcp1());
1305
1306 // Complete call setup and ensure everything is still OK.
deadbeeff5346592017-01-24 21:51:21 -08001307 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001309 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1310 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001311 SendRtcp1();
1312 SendRtcp2();
1313 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 EXPECT_TRUE(CheckRtcp1());
1316 }
1317
1318 // Test that we properly send SRTP with RTCP in both directions.
deadbeef7914b8c2017-04-21 03:23:33 -07001319 // You can pass in DTLS, RTCP_MUX, and RAW_PACKET_TRANSPORT as flags.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
deadbeef7914b8c2017-04-21 03:23:33 -07001321 RTC_CHECK((flags1_in & ~(RTCP_MUX | DTLS | RAW_PACKET_TRANSPORT)) == 0);
1322 RTC_CHECK((flags2_in & ~(RTCP_MUX | DTLS | RAW_PACKET_TRANSPORT)) == 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323
deadbeefac22f702017-01-12 21:59:29 -08001324 int flags1 = SECURE | flags1_in;
1325 int flags2 = SECURE | flags2_in;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 bool dtls1 = !!(flags1_in & DTLS);
1327 bool dtls2 = !!(flags2_in & DTLS);
1328 CreateChannels(flags1, flags2);
1329 EXPECT_FALSE(channel1_->secure());
1330 EXPECT_FALSE(channel2_->secure());
1331 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001332 WaitForThreads();
1333 EXPECT_TRUE(channel1_->writable());
1334 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 EXPECT_TRUE(SendAccept());
1336 EXPECT_TRUE(channel1_->secure());
1337 EXPECT_TRUE(channel2_->secure());
1338 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1339 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001340 SendRtp1();
1341 SendRtp2();
1342 SendRtcp1();
1343 SendRtcp2();
1344 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 EXPECT_TRUE(CheckRtp1());
1346 EXPECT_TRUE(CheckRtp2());
1347 EXPECT_TRUE(CheckNoRtp1());
1348 EXPECT_TRUE(CheckNoRtp2());
1349 EXPECT_TRUE(CheckRtcp1());
1350 EXPECT_TRUE(CheckRtcp2());
1351 EXPECT_TRUE(CheckNoRtcp1());
1352 EXPECT_TRUE(CheckNoRtcp2());
1353 }
1354
1355 // Test that we properly handling SRTP negotiating down to RTP.
1356 void SendSrtpToRtp() {
deadbeefac22f702017-01-12 21:59:29 -08001357 CreateChannels(SECURE, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 EXPECT_FALSE(channel1_->secure());
1359 EXPECT_FALSE(channel2_->secure());
1360 EXPECT_TRUE(SendInitiate());
1361 EXPECT_TRUE(SendAccept());
1362 EXPECT_FALSE(channel1_->secure());
1363 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001364 SendRtp1();
1365 SendRtp2();
1366 SendRtcp1();
1367 SendRtcp2();
1368 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 EXPECT_TRUE(CheckRtp1());
1370 EXPECT_TRUE(CheckRtp2());
1371 EXPECT_TRUE(CheckNoRtp1());
1372 EXPECT_TRUE(CheckNoRtp2());
1373 EXPECT_TRUE(CheckRtcp1());
1374 EXPECT_TRUE(CheckRtcp2());
1375 EXPECT_TRUE(CheckNoRtcp1());
1376 EXPECT_TRUE(CheckNoRtcp2());
1377 }
1378
1379 // Test that we can send and receive early media when a provisional answer is
1380 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1381 void SendEarlyMediaUsingRtcpMuxSrtp() {
1382 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1383
deadbeefac22f702017-01-12 21:59:29 -08001384 CreateChannels(SSRC_MUX | RTCP_MUX | SECURE,
1385 SSRC_MUX | RTCP_MUX | SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 EXPECT_TRUE(SendOffer());
1387 EXPECT_TRUE(SendProvisionalAnswer());
1388 EXPECT_TRUE(channel1_->secure());
1389 EXPECT_TRUE(channel2_->secure());
deadbeeff5346592017-01-24 21:51:21 -08001390 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1391 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001392 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1393 SendCustomRtcp1(kSsrc1);
1394 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1395 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1398
1399 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001400 SendCustomRtcp2(kSsrc2);
1401 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1402 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1405
1406 // Complete call setup and ensure everything is still OK.
deadbeeff5346592017-01-24 21:51:21 -08001407 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
1408 EXPECT_EQ(0, rtcp_mux_activated_callbacks2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 EXPECT_TRUE(SendFinalAnswer());
deadbeeff5346592017-01-24 21:51:21 -08001410 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1411 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
1412 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
1413 EXPECT_EQ(1, rtcp_mux_activated_callbacks2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 EXPECT_TRUE(channel1_->secure());
1415 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001416 SendCustomRtcp1(kSsrc1);
1417 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1418 SendCustomRtcp2(kSsrc2);
1419 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1420 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1425 }
1426
1427 // Test that we properly send RTP without SRTP from a thread.
1428 void SendRtpToRtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001429 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 EXPECT_TRUE(SendInitiate());
1431 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001432 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1433 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1434 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1435 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1436 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1437 send_rtcp1.thread(),
1438 send_rtcp2.thread()};
1439 WaitForThreads(involved_threads);
1440 EXPECT_TRUE(CheckRtp1());
1441 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 EXPECT_TRUE(CheckNoRtp1());
1443 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001444 EXPECT_TRUE(CheckRtcp1());
1445 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 EXPECT_TRUE(CheckNoRtcp1());
1447 EXPECT_TRUE(CheckNoRtcp2());
1448 }
1449
1450 // Test that we properly send SRTP with RTCP from a thread.
1451 void SendSrtpToSrtpOnThread() {
deadbeefac22f702017-01-12 21:59:29 -08001452 CreateChannels(SECURE, SECURE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 EXPECT_TRUE(SendInitiate());
1454 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001455 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1456 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1457 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1458 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1459 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1460 send_rtcp1.thread(),
1461 send_rtcp2.thread()};
1462 WaitForThreads(involved_threads);
1463 EXPECT_TRUE(CheckRtp1());
1464 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 EXPECT_TRUE(CheckNoRtp1());
1466 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001467 EXPECT_TRUE(CheckRtcp1());
1468 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 EXPECT_TRUE(CheckNoRtcp1());
1470 EXPECT_TRUE(CheckNoRtcp2());
1471 }
1472
1473 // Test that the mediachannel retains its sending state after the transport
1474 // becomes non-writable.
1475 void SendWithWritabilityLoss() {
deadbeefac22f702017-01-12 21:59:29 -08001476 CreateChannels(RTCP_MUX | RTCP_MUX_REQUIRED, RTCP_MUX | RTCP_MUX_REQUIRED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 EXPECT_TRUE(SendInitiate());
1478 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001479 EXPECT_FALSE(channel1_->NeedsRtcpTransport());
1480 EXPECT_FALSE(channel2_->NeedsRtcpTransport());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001481 SendRtp1();
1482 SendRtp2();
1483 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001484 EXPECT_TRUE(CheckRtp1());
1485 EXPECT_TRUE(CheckRtp2());
1486 EXPECT_TRUE(CheckNoRtp1());
1487 EXPECT_TRUE(CheckNoRtp2());
1488
wu@webrtc.org97077a32013-10-25 21:18:33 +00001489 // Lose writability, which should fail.
deadbeeff5346592017-01-24 21:51:21 -08001490 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1491 fake_rtp_dtls_transport1_->SetWritable(false);
1492 });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001493 SendRtp1();
1494 SendRtp2();
1495 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 EXPECT_TRUE(CheckRtp1());
1497 EXPECT_TRUE(CheckNoRtp2());
1498
1499 // Regain writability
deadbeeff5346592017-01-24 21:51:21 -08001500 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1501 fake_rtp_dtls_transport1_->SetWritable(true);
1502 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001504 SendRtp1();
1505 SendRtp2();
1506 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_TRUE(CheckRtp1());
1508 EXPECT_TRUE(CheckRtp2());
1509 EXPECT_TRUE(CheckNoRtp1());
1510 EXPECT_TRUE(CheckNoRtp2());
1511
1512 // Lose writability completely
deadbeeff5346592017-01-24 21:51:21 -08001513 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
1514 bool asymmetric = true;
1515 fake_rtp_dtls_transport1_->SetDestination(nullptr, asymmetric);
1516 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 EXPECT_TRUE(media_channel1_->sending());
1518
wu@webrtc.org97077a32013-10-25 21:18:33 +00001519 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001520 SendRtp1();
1521 SendRtp2();
1522 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 EXPECT_TRUE(CheckRtp1());
1524 EXPECT_TRUE(CheckNoRtp2());
zhihuangb2cdd932017-01-19 16:54:25 -08001525 EXPECT_TRUE(CheckNoRtp1());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526
1527 // Gain writability back
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001528 network_thread_->Invoke<void>(RTC_FROM_HERE, [this] {
deadbeeff5346592017-01-24 21:51:21 -08001529 bool asymmetric = true;
1530 fake_rtp_dtls_transport1_->SetDestination(fake_rtp_dtls_transport2_.get(),
1531 asymmetric);
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001532 });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001534 SendRtp1();
1535 SendRtp2();
1536 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 EXPECT_TRUE(CheckRtp1());
1538 EXPECT_TRUE(CheckRtp2());
1539 EXPECT_TRUE(CheckNoRtp1());
1540 EXPECT_TRUE(CheckNoRtp2());
1541 }
1542
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001543 void SendBundleToBundle(
1544 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1545 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001547 // Only pl_type1 was added to the bundle filter for both |channel1_|
1548 // and |channel2_|.
1549 int pl_type1 = pl_types[0];
1550 int pl_type2 = pl_types[1];
deadbeefac22f702017-01-12 21:59:29 -08001551 int flags = SSRC_MUX;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001552 if (secure) flags |= SECURE;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001553 if (rtcp_mux) {
1554 flags |= RTCP_MUX;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001555 }
1556 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 EXPECT_TRUE(SendInitiate());
deadbeeff5346592017-01-24 21:51:21 -08001558 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1559 EXPECT_EQ(rtcp_mux, !channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001561 EXPECT_EQ(rtcp_mux, !channel1_->NeedsRtcpTransport());
1562 EXPECT_EQ(rtcp_mux, !channel2_->NeedsRtcpTransport());
zstein3dcf0e92017-06-01 13:22:42 -07001563 EXPECT_TRUE(channel1_->HandlesPayloadType(pl_type1));
1564 EXPECT_TRUE(channel2_->HandlesPayloadType(pl_type1));
1565 EXPECT_FALSE(channel1_->HandlesPayloadType(pl_type2));
1566 EXPECT_FALSE(channel2_->HandlesPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001567
1568 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001569 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1570 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1571 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001572 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001573 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1574 EXPECT_TRUE(CheckNoRtp1());
1575 EXPECT_TRUE(CheckNoRtp2());
1576
1577 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001578 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1579 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1580 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001581 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001582 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1583
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001584 SendCustomRtcp1(kSsrc1);
1585 SendCustomRtcp2(kSsrc2);
1586 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1588 EXPECT_TRUE(CheckNoRtcp1());
1589 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1590 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001592 SendCustomRtcp1(kSsrc2);
1593 SendCustomRtcp2(kSsrc1);
1594 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001595 // Bundle filter shouldn't filter out any RTCP.
1596 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1597 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 }
1599
deadbeefc6b6e092016-12-01 12:49:20 -08001600 // Test that the media monitor can be run and gives callbacks.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 void TestMediaMonitor() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 CreateChannels(0, 0);
1603 EXPECT_TRUE(SendInitiate());
1604 EXPECT_TRUE(SendAccept());
1605 channel1_->StartMediaMonitor(100);
1606 channel2_->StartMediaMonitor(100);
1607 // Ensure we get callbacks and stop.
deadbeefc6b6e092016-12-01 12:49:20 -08001608 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
1609 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 channel1_->StopMediaMonitor();
1611 channel2_->StopMediaMonitor();
1612 // Ensure a restart of a stopped monitor works.
1613 channel1_->StartMediaMonitor(100);
deadbeefc6b6e092016-12-01 12:49:20 -08001614 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kDefaultTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 channel1_->StopMediaMonitor();
1616 // Ensure stopping a stopped monitor is OK.
1617 channel1_->StopMediaMonitor();
1618 }
1619
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 void TestSetContentFailure() {
1621 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622
Peter Thatchera6d24442015-07-09 21:26:36 -07001623 auto sdesc = cricket::SessionDescription();
1624 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1625 new cricket::AudioContentDescription());
1626 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1627 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628
Peter Thatchera6d24442015-07-09 21:26:36 -07001629 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001631 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1632 &sdesc, cricket::CA_OFFER, &err));
1633 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1634 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001637 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1638 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001640 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1641 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642 }
1643
1644 void TestSendTwoOffers() {
1645 CreateChannels(0, 0);
1646
Peter Thatchera6d24442015-07-09 21:26:36 -07001647 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001648 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001649 CreateSessionDescriptionWithStream(1));
1650 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1651 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1653
kwiberg31022942016-03-11 14:18:21 -08001654 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001655 CreateSessionDescriptionWithStream(2));
1656 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1657 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1659 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1660 }
1661
1662 void TestReceiveTwoOffers() {
1663 CreateChannels(0, 0);
1664
Peter Thatchera6d24442015-07-09 21:26:36 -07001665 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001666 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001667 CreateSessionDescriptionWithStream(1));
1668 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1669 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1671
kwiberg31022942016-03-11 14:18:21 -08001672 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001673 CreateSessionDescriptionWithStream(2));
1674 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1675 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1677 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1678 }
1679
1680 void TestSendPrAnswer() {
1681 CreateChannels(0, 0);
1682
Peter Thatchera6d24442015-07-09 21:26:36 -07001683 std::string err;
1684 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001685 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001686 CreateSessionDescriptionWithStream(1));
1687 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1688 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1690
Peter Thatchera6d24442015-07-09 21:26:36 -07001691 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001692 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001693 CreateSessionDescriptionWithStream(2));
1694 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1695 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1697 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1698
Peter Thatchera6d24442015-07-09 21:26:36 -07001699 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001700 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001701 CreateSessionDescriptionWithStream(3));
1702 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1703 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1705 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1706 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1707 }
1708
1709 void TestReceivePrAnswer() {
1710 CreateChannels(0, 0);
1711
Peter Thatchera6d24442015-07-09 21:26:36 -07001712 std::string err;
1713 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001714 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001715 CreateSessionDescriptionWithStream(1));
1716 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1717 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1719
Peter Thatchera6d24442015-07-09 21:26:36 -07001720 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001721 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001722 CreateSessionDescriptionWithStream(2));
1723 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1724 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1726 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1727
Peter Thatchera6d24442015-07-09 21:26:36 -07001728 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001729 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001730 CreateSessionDescriptionWithStream(3));
1731 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1732 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1734 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1735 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1736 }
1737
1738 void TestFlushRtcp() {
deadbeefac22f702017-01-12 21:59:29 -08001739 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 EXPECT_TRUE(SendInitiate());
1741 EXPECT_TRUE(SendAccept());
deadbeeff5346592017-01-24 21:51:21 -08001742 EXPECT_TRUE(channel1_->NeedsRtcpTransport());
1743 EXPECT_TRUE(channel2_->NeedsRtcpTransport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744
1745 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001746 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 // The sending message is only posted. channel2_ should be empty.
1748 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001749 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1750 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
1752 // When channel1_ is deleted, the RTCP packet should be sent out to
1753 // channel2_.
1754 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001755 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 EXPECT_TRUE(CheckRtcp2());
1757 }
1758
zstein56162b92017-04-24 16:54:35 -07001759 void TestOnTransportReadyToSend() {
deadbeefac22f702017-01-12 21:59:29 -08001760 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001762
zstein56162b92017-04-24 16:54:35 -07001763 channel1_->OnTransportReadyToSend(true);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001764 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 EXPECT_TRUE(media_channel1_->ready_to_send());
1766
zstein56162b92017-04-24 16:54:35 -07001767 channel1_->OnTransportReadyToSend(false);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001768 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 EXPECT_FALSE(media_channel1_->ready_to_send());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 }
1771
zstein56162b92017-04-24 16:54:35 -07001772 void TestOnTransportReadyToSendWithRtcpMux() {
deadbeefac22f702017-01-12 21:59:29 -08001773 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 typename T::Content content;
1775 CreateContent(0, kPcmuCodec, kH264Codec, &content);
deadbeeff5346592017-01-24 21:51:21 -08001776 // Both sides agree on mux. Should signal that RTCP mux is fully active.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001778 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
deadbeeff5346592017-01-24 21:51:21 -08001779 EXPECT_EQ(0, rtcp_mux_activated_callbacks1_);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001780 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
deadbeeff5346592017-01-24 21:51:21 -08001781 EXPECT_EQ(1, rtcp_mux_activated_callbacks1_);
1782 cricket::FakeDtlsTransport* rtp = fake_rtp_dtls_transport1_.get();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 EXPECT_FALSE(media_channel1_->ready_to_send());
1784 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1785 // should trigger the MediaChannel's OnReadyToSend.
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001786 network_thread_->Invoke<void>(RTC_FROM_HERE,
1787 [rtp] { rtp->SignalReadyToSend(rtp); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001788 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001790
zstein56162b92017-04-24 16:54:35 -07001791 // TODO(zstein): Find a way to test this without making
1792 // OnTransportReadyToSend public.
1793 network_thread_->Invoke<void>(
1794 RTC_FROM_HERE, [this] { channel1_->OnTransportReadyToSend(false); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001795 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 EXPECT_FALSE(media_channel1_->ready_to_send());
1797 }
1798
skvladdc1c62c2016-03-16 19:07:43 -07001799 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1800 typename T::Content content;
1801 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1802 content.set_bandwidth(remote_limit);
1803 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1804 }
1805
deadbeefe702b302017-02-04 12:09:01 -08001806 webrtc::RtpParameters BitrateLimitedParameters(rtc::Optional<int> limit) {
skvladdc1c62c2016-03-16 19:07:43 -07001807 webrtc::RtpParameters parameters;
1808 webrtc::RtpEncodingParameters encoding;
1809 encoding.max_bitrate_bps = limit;
1810 parameters.encodings.push_back(encoding);
1811 return parameters;
1812 }
1813
1814 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
deadbeefe702b302017-02-04 12:09:01 -08001815 rtc::Optional<int> expected_bitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07001816 EXPECT_EQ(1UL, parameters.encodings.size());
1817 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1818 }
1819
1820 void DefaultMaxBitrateIsUnlimited() {
1821 CreateChannels(0, 0);
1822 EXPECT_TRUE(
1823 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1824 EXPECT_EQ(media_channel1_->max_bps(), -1);
deadbeefe702b302017-02-04 12:09:01 -08001825 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1),
1826 rtc::Optional<int>());
skvladdc1c62c2016-03-16 19:07:43 -07001827 }
1828
1829 void CanChangeMaxBitrate() {
1830 CreateChannels(0, 0);
1831 EXPECT_TRUE(
1832 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1833
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001834 EXPECT_TRUE(channel1_->SetRtpSendParameters(
deadbeefe702b302017-02-04 12:09:01 -08001835 kSsrc1, BitrateLimitedParameters(rtc::Optional<int>(1000))));
1836 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1),
1837 rtc::Optional<int>(1000));
1838 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1),
1839 rtc::Optional<int>(1000));
skvladdc1c62c2016-03-16 19:07:43 -07001840 EXPECT_EQ(-1, media_channel1_->max_bps());
1841
deadbeefe702b302017-02-04 12:09:01 -08001842 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1843 kSsrc1, BitrateLimitedParameters(rtc::Optional<int>())));
1844 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1),
1845 rtc::Optional<int>());
1846 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1),
1847 rtc::Optional<int>());
skvladdc1c62c2016-03-16 19:07:43 -07001848 EXPECT_EQ(-1, media_channel1_->max_bps());
1849 }
1850
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001852 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1853 static void ProcessThreadQueue(rtc::Thread* thread) {
1854 RTC_DCHECK(thread->IsCurrent());
1855 while (!thread->empty()) {
1856 thread->ProcessMessages(0);
1857 }
1858 }
1859 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1860 // |threads| and current thread post packets to network thread.
1861 for (rtc::Thread* thread : threads) {
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001862 thread->Invoke<void>(RTC_FROM_HERE,
1863 [thread] { ProcessThreadQueue(thread); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001864 }
1865 ProcessThreadQueue(rtc::Thread::Current());
1866 // Network thread move them around and post back to worker = current thread.
1867 if (!network_thread_->IsCurrent()) {
1868 network_thread_->Invoke<void>(
Taylor Brandstetter5d97a9a2016-06-10 14:17:27 -07001869 RTC_FROM_HERE, [this] { ProcessThreadQueue(network_thread_); });
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001870 }
1871 // Worker thread = current Thread process received messages.
1872 ProcessThreadQueue(rtc::Thread::Current());
1873 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001874 // TODO(pbos): Remove playout from all media channels and let renderers mute
1875 // themselves.
1876 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001877 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1878 rtc::Thread* network_thread_;
deadbeeff5346592017-01-24 21:51:21 -08001879 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport1_;
1880 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport1_;
1881 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtp_dtls_transport2_;
1882 std::unique_ptr<cricket::FakeDtlsTransport> fake_rtcp_dtls_transport2_;
1883 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport1_;
1884 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport1_;
1885 std::unique_ptr<rtc::FakePacketTransport> fake_rtp_packet_transport2_;
1886 std::unique_ptr<rtc::FakePacketTransport> fake_rtcp_packet_transport2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 cricket::FakeMediaEngine media_engine_;
1888 // The media channels are owned by the voice channel objects below.
deadbeeff5346592017-01-24 21:51:21 -08001889 typename T::MediaChannel* media_channel1_ = nullptr;
1890 typename T::MediaChannel* media_channel2_ = nullptr;
kwiberg31022942016-03-11 14:18:21 -08001891 std::unique_ptr<typename T::Channel> channel1_;
1892 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 typename T::Content local_media_content1_;
1894 typename T::Content local_media_content2_;
1895 typename T::Content remote_media_content1_;
1896 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001898 rtc::Buffer rtp_packet_;
1899 rtc::Buffer rtcp_packet_;
deadbeeff5346592017-01-24 21:51:21 -08001900 int media_info_callbacks1_ = 0;
1901 int media_info_callbacks2_ = 0;
1902 int rtcp_mux_activated_callbacks1_ = 0;
1903 int rtcp_mux_activated_callbacks2_ = 0;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001904 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905};
1906
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907template<>
1908void ChannelTest<VoiceTraits>::CreateContent(
1909 int flags,
1910 const cricket::AudioCodec& audio_codec,
1911 const cricket::VideoCodec& video_codec,
1912 cricket::AudioContentDescription* audio) {
1913 audio->AddCodec(audio_codec);
1914 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1915 if (flags & SECURE) {
1916 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001917 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1918 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919 }
1920}
1921
1922template<>
1923void ChannelTest<VoiceTraits>::CopyContent(
1924 const cricket::AudioContentDescription& source,
1925 cricket::AudioContentDescription* audio) {
1926 *audio = source;
1927}
1928
1929template<>
1930bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1931 const cricket::AudioCodec& c2) {
1932 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1933 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1934}
1935
Peter Boström0c4e06b2015-10-07 12:23:21 +02001936template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001938 uint32_t ssrc,
1939 int flags,
1940 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941 audio->AddLegacyStream(ssrc);
1942}
1943
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001944class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945 public:
solenberg1dd98f32015-09-10 01:57:14 -07001946 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001947 VoiceChannelSingleThreadTest()
1948 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
1949};
1950
1951class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
1952 public:
1953 typedef ChannelTest<VoiceTraits> Base;
1954 VoiceChannelDoubleThreadTest()
1955 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956};
1957
1958// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001959template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001961 rtc::Thread* worker_thread,
1962 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07001963 cricket::MediaEngineInterface* engine,
1964 cricket::FakeVideoMediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -08001965 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
1966 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
deadbeef5bd5ca32017-02-10 11:31:50 -08001967 rtc::PacketTransportInternal* fake_rtp_packet_transport,
1968 rtc::PacketTransportInternal* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -07001969 int flags) {
deadbeeff5346592017-01-24 21:51:21 -08001970 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef7af91dd2016-12-13 11:29:11 -08001971 cricket::VideoChannel* channel = new cricket::VideoChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08001972 worker_thread, network_thread, signaling_thread, ch, cricket::CN_VIDEO,
deadbeefac22f702017-01-12 21:59:29 -08001973 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
deadbeeff5346592017-01-24 21:51:21 -08001974 if (!channel->NeedsRtcpTransport()) {
1975 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08001976 }
deadbeeff5346592017-01-24 21:51:21 -08001977 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
1978 fake_rtp_packet_transport, fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 delete channel;
1980 channel = NULL;
1981 }
1982 return channel;
1983}
1984
1985// override to add 0 parameter
1986template<>
1987bool ChannelTest<VideoTraits>::AddStream1(int id) {
1988 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1989}
1990
1991template<>
1992void ChannelTest<VideoTraits>::CreateContent(
1993 int flags,
1994 const cricket::AudioCodec& audio_codec,
1995 const cricket::VideoCodec& video_codec,
1996 cricket::VideoContentDescription* video) {
1997 video->AddCodec(video_codec);
1998 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1999 if (flags & SECURE) {
2000 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002001 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2002 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002003 }
2004}
2005
2006template<>
2007void ChannelTest<VideoTraits>::CopyContent(
2008 const cricket::VideoContentDescription& source,
2009 cricket::VideoContentDescription* video) {
2010 *video = source;
2011}
2012
2013template<>
2014bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2015 const cricket::VideoCodec& c2) {
perkj26752742016-10-24 01:21:16 -07002016 return c1.name == c2.name;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017}
2018
Peter Boström0c4e06b2015-10-07 12:23:21 +02002019template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002021 uint32_t ssrc,
2022 int flags,
2023 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 video->AddLegacyStream(ssrc);
2025}
2026
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002027class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 public:
solenberg1dd98f32015-09-10 01:57:14 -07002029 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002030 VideoChannelSingleThreadTest()
2031 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032};
2033
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002034class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2035 public:
2036 typedef ChannelTest<VideoTraits> Base;
2037 VideoChannelDoubleThreadTest()
2038 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2039};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002041// VoiceChannelSingleThreadTest
kjellander7c856582017-02-26 19:53:40 -08002042// Flaky on iOS Simualtor: bugs.webrtc.org/7247
2043#if defined(WEBRTC_IOS)
2044#define MAYBE_TestInit DISABLED_TestInit
2045#else
2046#define MAYBE_TestInit TestInit
2047#endif
2048TEST_F(VoiceChannelSingleThreadTest, MAYBE_TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 Base::TestInit();
2050 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2051 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2052}
2053
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002054TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2055 Base::TestDeinit();
2056}
2057
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002058TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059 Base::TestSetContents();
2060}
2061
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002062TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 Base::TestSetContentsNullOffer();
2064}
2065
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002066TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 Base::TestSetContentsRtcpMux();
2068}
2069
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002070TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071 Base::TestSetContentsRtcpMux();
2072}
2073
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002074TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 Base::TestSetRemoteContentUpdate();
2076}
2077
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002078TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 Base::TestStreams();
2080}
2081
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002082TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083 Base::TestUpdateStreamsInLocalContent();
2084}
2085
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002086TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 Base::TestUpdateStreamsInRemoteContent();
2088}
2089
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002090TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 Base::TestChangeStreamParamsInContent();
2092}
2093
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002094TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095 Base::TestPlayoutAndSendingStates();
2096}
2097
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002098TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002099 CreateChannels(0, 0);
2100 // Test that we can Mute the default channel even though the sending SSRC
2101 // is unknown.
2102 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002103 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002104 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2105 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002106 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2107
2108 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002109 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002110
2111 SendInitiate();
2112 // After the local session description has been set, we can mute a stream
2113 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002114 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002115 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2116 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002117 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118}
2119
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002120TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 Base::TestMediaContentDirection();
2122}
2123
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002124TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002125 Base::TestNetworkRouteChanges();
2126}
2127
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002128TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 Base::TestCallSetup();
2130}
2131
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002132TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 Base::TestCallTeardownRtcpMux();
2134}
2135
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002136TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 Base::SendRtpToRtp();
2138}
2139
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002140TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141 Base::SendRtcpToRtcp();
2142}
2143
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002144TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 Base::SendRtcpMuxToRtcp();
2146}
2147
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002148TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 Base::SendRtcpMuxToRtcpMux();
2150}
2151
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002152TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002153 Base::SendRequireRtcpMuxToRtcpMux();
2154}
2155
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002156TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002157 Base::SendRtcpMuxToRequireRtcpMux();
2158}
2159
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002160TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002161 Base::SendRequireRtcpMuxToRequireRtcpMux();
2162}
2163
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002164TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002165 Base::SendRequireRtcpMuxToNoRtcpMux();
2166}
2167
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002168TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 Base::SendEarlyRtcpMuxToRtcp();
2170}
2171
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002172TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 Base::SendEarlyRtcpMuxToRtcpMux();
2174}
2175
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002176TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2178}
2179
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002180TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 Base::SendSrtpToSrtp();
2182}
2183
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002184TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2186}
2187
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002188TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 Base::SendSrtpToSrtp(DTLS, 0);
2190}
2191
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002192TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 Base::SendSrtpToSrtp(DTLS, DTLS);
2194}
2195
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002196TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2198}
2199
deadbeeff5346592017-01-24 21:51:21 -08002200// Test using the channel with a raw packet interface, as opposed to a DTLS
2201// transport interface.
2202TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
2203 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
2204}
2205
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002206TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2208}
2209
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002210TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 Base::SendRtpToRtpOnThread();
2212}
2213
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002214TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 Base::SendSrtpToSrtpOnThread();
2216}
2217
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002218TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 Base::SendWithWritabilityLoss();
2220}
2221
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002222TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 Base::TestMediaMonitor();
2224}
2225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002227TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 CreateChannels(0, 0);
2229 EXPECT_TRUE(SendInitiate());
2230 EXPECT_TRUE(SendAccept());
2231 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2232
solenberg1d63dd02015-12-02 12:35:09 -08002233 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2234 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2235 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002237 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002239 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002240 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002241 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002242 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002243 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244}
2245
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002246TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 Base::TestSetContentFailure();
2248}
2249
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002250TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 Base::TestSendTwoOffers();
2252}
2253
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002254TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 Base::TestReceiveTwoOffers();
2256}
2257
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002258TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002259 Base::TestSendPrAnswer();
2260}
2261
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002262TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 Base::TestReceivePrAnswer();
2264}
2265
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002266TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 Base::TestFlushRtcp();
2268}
2269
zstein56162b92017-04-24 16:54:35 -07002270TEST_F(VoiceChannelSingleThreadTest, TestOnTransportReadyToSend) {
2271 Base::TestOnTransportReadyToSend();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272}
2273
zstein56162b92017-04-24 16:54:35 -07002274TEST_F(VoiceChannelSingleThreadTest, TestOnTransportReadyToSendWithRtcpMux) {
2275 Base::TestOnTransportReadyToSendWithRtcpMux();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276}
2277
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002279TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002280 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 EXPECT_TRUE(SendInitiate());
2282 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002283 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284
solenberg4bac9c52015-10-09 02:32:53 -07002285 // Default is (1.0).
2286 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2287 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002289 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290
solenberg4bac9c52015-10-09 02:32:53 -07002291 // Set scale to (1.5).
2292 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2293 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2294 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295
solenberg4bac9c52015-10-09 02:32:53 -07002296 // Set scale to (0).
2297 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2298 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2299 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300}
2301
2302// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002303TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002304 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 EXPECT_TRUE(SendInitiate());
2306 EXPECT_TRUE(SendAccept());
2307 EXPECT_TRUE(AddStream1(1));
2308 EXPECT_TRUE(AddStream1(2));
2309
solenberg4bac9c52015-10-09 02:32:53 -07002310 double volume;
2311 // Default is (1.0).
2312 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2313 EXPECT_DOUBLE_EQ(1.0, volume);
2314 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2315 EXPECT_DOUBLE_EQ(1.0, volume);
2316 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2317 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002319 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320
solenberg4bac9c52015-10-09 02:32:53 -07002321 // Set scale to (1.5) for ssrc = 1.
2322 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2323 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2324 EXPECT_DOUBLE_EQ(1.5, volume);
2325 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2326 EXPECT_DOUBLE_EQ(1.0, volume);
2327 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2328 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329
solenberg4bac9c52015-10-09 02:32:53 -07002330 // Set scale to (0) for all ssrcs.
2331 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2332 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2333 EXPECT_DOUBLE_EQ(0.0, volume);
2334 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2335 EXPECT_DOUBLE_EQ(0.0, volume);
2336 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2337 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338}
2339
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002340TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002341 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342}
2343
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002344TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002345 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002346}
2347
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002348TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002349 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002350}
2351
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002352TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002353 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354}
2355
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002356TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002357 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002358}
2359
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002360TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002361 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002362}
2363
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002364// VoiceChannelDoubleThreadTest
2365TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002367 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2368 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369}
2370
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002371TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2372 Base::TestDeinit();
2373}
2374
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002375TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 Base::TestSetContents();
2377}
2378
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002379TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 Base::TestSetContentsNullOffer();
2381}
2382
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002383TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384 Base::TestSetContentsRtcpMux();
2385}
2386
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002387TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388 Base::TestSetContentsRtcpMux();
2389}
2390
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002391TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392 Base::TestSetRemoteContentUpdate();
2393}
2394
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002395TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 Base::TestStreams();
2397}
2398
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002399TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400 Base::TestUpdateStreamsInLocalContent();
2401}
2402
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002403TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 Base::TestUpdateStreamsInRemoteContent();
2405}
2406
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002407TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408 Base::TestChangeStreamParamsInContent();
2409}
2410
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002411TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 Base::TestPlayoutAndSendingStates();
2413}
2414
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002415TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2416 CreateChannels(0, 0);
2417 // Test that we can Mute the default channel even though the sending SSRC
2418 // is unknown.
2419 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2420 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2421 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2422 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2423 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2424
2425 // Test that we can not mute an unknown SSRC.
2426 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2427
2428 SendInitiate();
2429 // After the local session description has been set, we can mute a stream
2430 // with its SSRC.
2431 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2432 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2433 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2434 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2435}
2436
2437TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2438 Base::TestMediaContentDirection();
2439}
2440
2441TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2442 Base::TestNetworkRouteChanges();
2443}
2444
2445TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2446 Base::TestCallSetup();
2447}
2448
2449TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2450 Base::TestCallTeardownRtcpMux();
2451}
2452
2453TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2454 Base::SendRtpToRtp();
2455}
2456
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002457TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2458 Base::SendRtcpToRtcp();
2459}
2460
2461TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2462 Base::SendRtcpMuxToRtcp();
2463}
2464
2465TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2466 Base::SendRtcpMuxToRtcpMux();
2467}
2468
2469TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2470 Base::SendRequireRtcpMuxToRtcpMux();
2471}
2472
2473TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2474 Base::SendRtcpMuxToRequireRtcpMux();
2475}
2476
2477TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2478 Base::SendRequireRtcpMuxToRequireRtcpMux();
2479}
2480
2481TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2482 Base::SendRequireRtcpMuxToNoRtcpMux();
2483}
2484
2485TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2486 Base::SendEarlyRtcpMuxToRtcp();
2487}
2488
2489TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2490 Base::SendEarlyRtcpMuxToRtcpMux();
2491}
2492
2493TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2494 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2495}
2496
2497TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2498 Base::SendSrtpToSrtp();
2499}
2500
2501TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2502 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2503}
2504
2505TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002506 Base::SendSrtpToSrtp(DTLS, 0);
2507}
2508
2509TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002510 Base::SendSrtpToSrtp(DTLS, DTLS);
2511}
2512
2513TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002514 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2515}
2516
deadbeeff5346592017-01-24 21:51:21 -08002517// Test using the channel with a raw packet interface, as opposed to a DTLS
2518// transport interface.
2519TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
2520 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
2521}
2522
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002523TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2524 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2525}
2526
2527TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2528 Base::SendRtpToRtpOnThread();
2529}
2530
2531TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2532 Base::SendSrtpToSrtpOnThread();
2533}
2534
2535TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2536 Base::SendWithWritabilityLoss();
2537}
2538
2539TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2540 Base::TestMediaMonitor();
2541}
2542
2543// Test that InsertDtmf properly forwards to the media channel.
2544TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2545 CreateChannels(0, 0);
2546 EXPECT_TRUE(SendInitiate());
2547 EXPECT_TRUE(SendAccept());
2548 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2549
2550 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2551 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2552 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2553
2554 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2555 EXPECT_TRUE(
2556 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2557 EXPECT_TRUE(
2558 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2559 EXPECT_TRUE(
2560 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2561}
2562
2563TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2564 Base::TestSetContentFailure();
2565}
2566
2567TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2568 Base::TestSendTwoOffers();
2569}
2570
2571TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2572 Base::TestReceiveTwoOffers();
2573}
2574
2575TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2576 Base::TestSendPrAnswer();
2577}
2578
2579TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2580 Base::TestReceivePrAnswer();
2581}
2582
2583TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2584 Base::TestFlushRtcp();
2585}
2586
zstein56162b92017-04-24 16:54:35 -07002587TEST_F(VoiceChannelDoubleThreadTest, TestOnTransportReadyToSend) {
2588 Base::TestOnTransportReadyToSend();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002589}
2590
zstein56162b92017-04-24 16:54:35 -07002591TEST_F(VoiceChannelDoubleThreadTest, TestOnTransportReadyToSendWithRtcpMux) {
2592 Base::TestOnTransportReadyToSendWithRtcpMux();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002593}
2594
2595// Test that we can scale the output volume properly for 1:1 calls.
2596TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
deadbeefac22f702017-01-12 21:59:29 -08002597 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002598 EXPECT_TRUE(SendInitiate());
2599 EXPECT_TRUE(SendAccept());
2600 double volume;
2601
2602 // Default is (1.0).
2603 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2604 EXPECT_DOUBLE_EQ(1.0, volume);
2605 // invalid ssrc.
2606 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2607
2608 // Set scale to (1.5).
2609 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2610 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2611 EXPECT_DOUBLE_EQ(1.5, volume);
2612
2613 // Set scale to (0).
2614 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2615 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2616 EXPECT_DOUBLE_EQ(0.0, volume);
2617}
2618
2619// Test that we can scale the output volume properly for multiway calls.
2620TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
deadbeefac22f702017-01-12 21:59:29 -08002621 CreateChannels(0, 0);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002622 EXPECT_TRUE(SendInitiate());
2623 EXPECT_TRUE(SendAccept());
2624 EXPECT_TRUE(AddStream1(1));
2625 EXPECT_TRUE(AddStream1(2));
2626
2627 double volume;
2628 // Default is (1.0).
2629 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2630 EXPECT_DOUBLE_EQ(1.0, volume);
2631 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2632 EXPECT_DOUBLE_EQ(1.0, volume);
2633 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2634 EXPECT_DOUBLE_EQ(1.0, volume);
2635 // invalid ssrc.
2636 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2637
2638 // Set scale to (1.5) for ssrc = 1.
2639 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2640 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2641 EXPECT_DOUBLE_EQ(1.5, volume);
2642 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2643 EXPECT_DOUBLE_EQ(1.0, volume);
2644 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2645 EXPECT_DOUBLE_EQ(1.0, volume);
2646
2647 // Set scale to (0) for all ssrcs.
2648 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2649 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2650 EXPECT_DOUBLE_EQ(0.0, volume);
2651 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2652 EXPECT_DOUBLE_EQ(0.0, volume);
2653 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2654 EXPECT_DOUBLE_EQ(0.0, volume);
2655}
2656
2657TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2658 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2659}
2660
2661TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2662 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2663}
2664
2665TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2666 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2667}
2668
2669TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2670 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2671}
2672
2673TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2674 Base::DefaultMaxBitrateIsUnlimited();
2675}
2676
2677TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2678 Base::CanChangeMaxBitrate();
2679}
2680
2681// VideoChannelSingleThreadTest
2682TEST_F(VideoChannelSingleThreadTest, TestInit) {
2683 Base::TestInit();
2684}
2685
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002686TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2687 Base::TestDeinit();
2688}
2689
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002690TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2691 Base::TestSetContents();
2692}
2693
2694TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2695 Base::TestSetContentsNullOffer();
2696}
2697
2698TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2699 Base::TestSetContentsRtcpMux();
2700}
2701
2702TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2703 Base::TestSetContentsRtcpMux();
2704}
2705
2706TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2707 Base::TestSetRemoteContentUpdate();
2708}
2709
2710TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2711 Base::TestStreams();
2712}
2713
2714TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2715 Base::TestUpdateStreamsInLocalContent();
2716}
2717
2718TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2719 Base::TestUpdateStreamsInRemoteContent();
2720}
2721
2722TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2723 Base::TestChangeStreamParamsInContent();
2724}
2725
2726TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2727 Base::TestPlayoutAndSendingStates();
2728}
2729
2730TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002731 CreateChannels(0, 0);
2732 // Test that we can Mute the default channel even though the sending SSRC
2733 // is unknown.
2734 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002735 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002736 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002737 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002738 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2739 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002740 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002741 SendInitiate();
2742 // After the local session description has been set, we can mute a stream
2743 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002744 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002745 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002746 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002747 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748}
2749
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002750TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 Base::TestMediaContentDirection();
2752}
2753
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002754TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002755 Base::TestNetworkRouteChanges();
2756}
2757
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002758TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759 Base::TestCallSetup();
2760}
2761
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002762TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763 Base::TestCallTeardownRtcpMux();
2764}
2765
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002766TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767 Base::SendRtpToRtp();
2768}
2769
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002770TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771 Base::SendRtcpToRtcp();
2772}
2773
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002774TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775 Base::SendRtcpMuxToRtcp();
2776}
2777
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002778TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779 Base::SendRtcpMuxToRtcpMux();
2780}
2781
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002782TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002783 Base::SendRequireRtcpMuxToRtcpMux();
2784}
2785
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002786TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002787 Base::SendRtcpMuxToRequireRtcpMux();
2788}
2789
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002790TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002791 Base::SendRequireRtcpMuxToRequireRtcpMux();
2792}
2793
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002794TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002795 Base::SendRequireRtcpMuxToNoRtcpMux();
2796}
2797
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002798TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002799 Base::SendEarlyRtcpMuxToRtcp();
2800}
2801
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002802TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803 Base::SendEarlyRtcpMuxToRtcpMux();
2804}
2805
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002806TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807 Base::SendSrtpToSrtp();
2808}
2809
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002810TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811 Base::SendSrtpToSrtp();
2812}
2813
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002814TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 Base::SendSrtpToSrtp(DTLS, 0);
2816}
2817
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002818TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 Base::SendSrtpToSrtp(DTLS, DTLS);
2820}
2821
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002822TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2824}
2825
deadbeeff5346592017-01-24 21:51:21 -08002826// Test using the channel with a raw packet interface, as opposed to a DTLS
2827// transport interface.
2828TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
2829 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
2830}
2831
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002832TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2834}
2835
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002836TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2838}
2839
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002840TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002841 Base::SendRtpToRtpOnThread();
2842}
2843
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002844TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845 Base::SendSrtpToSrtpOnThread();
2846}
2847
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002848TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002849 Base::SendWithWritabilityLoss();
2850}
2851
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002852TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002853 Base::TestMediaMonitor();
2854}
2855
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002856TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002857 Base::TestSetContentFailure();
2858}
2859
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002860TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002861 Base::TestSendTwoOffers();
2862}
2863
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002864TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002865 Base::TestReceiveTwoOffers();
2866}
2867
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002868TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 Base::TestSendPrAnswer();
2870}
2871
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002872TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873 Base::TestReceivePrAnswer();
2874}
2875
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002876TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877 Base::TestFlushRtcp();
2878}
2879
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002880TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002881 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882}
2883
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002884TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002885 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002886}
2887
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002888TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002889 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002890}
2891
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002892TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002893 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894}
2895
zstein56162b92017-04-24 16:54:35 -07002896TEST_F(VideoChannelSingleThreadTest, TestOnTransportReadyToSend) {
2897 Base::TestOnTransportReadyToSend();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898}
2899
zstein56162b92017-04-24 16:54:35 -07002900TEST_F(VideoChannelSingleThreadTest, TestOnTransportReadyToSendWithRtcpMux) {
2901 Base::TestOnTransportReadyToSendWithRtcpMux();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902}
2903
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002904TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07002905 Base::DefaultMaxBitrateIsUnlimited();
2906}
2907
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002908TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07002909 Base::CanChangeMaxBitrate();
2910}
2911
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002912// VideoChannelDoubleThreadTest
2913TEST_F(VideoChannelDoubleThreadTest, TestInit) {
2914 Base::TestInit();
2915}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002917TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
2918 Base::TestDeinit();
2919}
2920
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002921TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
2922 Base::TestSetContents();
2923}
2924
2925TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
2926 Base::TestSetContentsNullOffer();
2927}
2928
2929TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
2930 Base::TestSetContentsRtcpMux();
2931}
2932
2933TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2934 Base::TestSetContentsRtcpMux();
2935}
2936
2937TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
2938 Base::TestSetRemoteContentUpdate();
2939}
2940
2941TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
2942 Base::TestStreams();
2943}
2944
2945TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
2946 Base::TestUpdateStreamsInLocalContent();
2947}
2948
2949TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
2950 Base::TestUpdateStreamsInRemoteContent();
2951}
2952
2953TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
2954 Base::TestChangeStreamParamsInContent();
2955}
2956
2957TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
2958 Base::TestPlayoutAndSendingStates();
2959}
2960
2961TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
2962 CreateChannels(0, 0);
2963 // Test that we can Mute the default channel even though the sending SSRC
2964 // is unknown.
2965 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002966 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002967 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
deadbeef5a4a75a2016-06-02 16:23:38 -07002968 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002969 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2970 // Test that we can not mute an unknown SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002971 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002972 SendInitiate();
2973 // After the local session description has been set, we can mute a stream
2974 // with its SSRC.
deadbeef5a4a75a2016-06-02 16:23:38 -07002975 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002976 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
deadbeef5a4a75a2016-06-02 16:23:38 -07002977 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr, nullptr));
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002978 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2979}
2980
2981TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
2982 Base::TestMediaContentDirection();
2983}
2984
2985TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
2986 Base::TestNetworkRouteChanges();
2987}
2988
2989TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
2990 Base::TestCallSetup();
2991}
2992
2993TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2994 Base::TestCallTeardownRtcpMux();
2995}
2996
2997TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
2998 Base::SendRtpToRtp();
2999}
3000
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003001TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3002 Base::SendRtcpToRtcp();
3003}
3004
3005TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3006 Base::SendRtcpMuxToRtcp();
3007}
3008
3009TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3010 Base::SendRtcpMuxToRtcpMux();
3011}
3012
3013TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3014 Base::SendRequireRtcpMuxToRtcpMux();
3015}
3016
3017TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3018 Base::SendRtcpMuxToRequireRtcpMux();
3019}
3020
3021TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3022 Base::SendRequireRtcpMuxToRequireRtcpMux();
3023}
3024
3025TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3026 Base::SendRequireRtcpMuxToNoRtcpMux();
3027}
3028
3029TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3030 Base::SendEarlyRtcpMuxToRtcp();
3031}
3032
3033TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3034 Base::SendEarlyRtcpMuxToRtcpMux();
3035}
3036
3037TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3038 Base::SendSrtpToSrtp();
3039}
3040
3041TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3042 Base::SendSrtpToSrtp();
3043}
3044
3045TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003046 Base::SendSrtpToSrtp(DTLS, 0);
3047}
3048
3049TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003050 Base::SendSrtpToSrtp(DTLS, DTLS);
3051}
3052
3053TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003054 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3055}
3056
deadbeeff5346592017-01-24 21:51:21 -08003057// Test using the channel with a raw packet interface, as opposed to a DTLS
3058// transport interface.
3059TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpWithRawPacketTransport) {
3060 Base::SendSrtpToSrtp(RAW_PACKET_TRANSPORT, RAW_PACKET_TRANSPORT);
3061}
3062
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003063TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3064 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3065}
3066
3067TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3068 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3069}
3070
3071TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3072 Base::SendRtpToRtpOnThread();
3073}
3074
3075TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3076 Base::SendSrtpToSrtpOnThread();
3077}
3078
3079TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3080 Base::SendWithWritabilityLoss();
3081}
3082
3083TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3084 Base::TestMediaMonitor();
3085}
3086
3087TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3088 Base::TestSetContentFailure();
3089}
3090
3091TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3092 Base::TestSendTwoOffers();
3093}
3094
3095TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3096 Base::TestReceiveTwoOffers();
3097}
3098
3099TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3100 Base::TestSendPrAnswer();
3101}
3102
3103TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3104 Base::TestReceivePrAnswer();
3105}
3106
3107TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3108 Base::TestFlushRtcp();
3109}
3110
3111TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3112 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3113}
3114
3115TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3116 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3117}
3118
3119TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3120 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3121}
3122
3123TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3124 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3125}
3126
zstein56162b92017-04-24 16:54:35 -07003127TEST_F(VideoChannelDoubleThreadTest, TestOnTransportReadyToSend) {
3128 Base::TestOnTransportReadyToSend();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003129}
3130
zstein56162b92017-04-24 16:54:35 -07003131TEST_F(VideoChannelDoubleThreadTest, TestOnTransportReadyToSendWithRtcpMux) {
3132 Base::TestOnTransportReadyToSendWithRtcpMux();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003133}
3134
3135TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3136 Base::DefaultMaxBitrateIsUnlimited();
3137}
3138
3139TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3140 Base::CanChangeMaxBitrate();
3141}
3142
deadbeef953c2ce2017-01-09 14:53:41 -08003143// RtpDataChannelSingleThreadTest
3144class RtpDataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003146 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003147 RtpDataChannelSingleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003148 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3149};
3150
deadbeef953c2ce2017-01-09 14:53:41 -08003151// RtpDataChannelDoubleThreadTest
3152class RtpDataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003153 public:
3154 typedef ChannelTest<DataTraits> Base;
deadbeef953c2ce2017-01-09 14:53:41 -08003155 RtpDataChannelDoubleThreadTest()
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003156 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157};
3158
3159// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003160template <>
deadbeef953c2ce2017-01-09 14:53:41 -08003161cricket::RtpDataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003162 rtc::Thread* worker_thread,
3163 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003164 cricket::MediaEngineInterface* engine,
3165 cricket::FakeDataMediaChannel* ch,
deadbeeff5346592017-01-24 21:51:21 -08003166 cricket::DtlsTransportInternal* fake_rtp_dtls_transport,
3167 cricket::DtlsTransportInternal* fake_rtcp_dtls_transport,
deadbeef5bd5ca32017-02-10 11:31:50 -08003168 rtc::PacketTransportInternal* fake_rtp_packet_transport,
3169 rtc::PacketTransportInternal* fake_rtcp_packet_transport,
jbauchcb560652016-08-04 05:20:32 -07003170 int flags) {
deadbeeff5346592017-01-24 21:51:21 -08003171 rtc::Thread* signaling_thread = rtc::Thread::Current();
deadbeef953c2ce2017-01-09 14:53:41 -08003172 cricket::RtpDataChannel* channel = new cricket::RtpDataChannel(
zhihuangf5b251b2017-01-12 19:37:48 -08003173 worker_thread, network_thread, signaling_thread, ch, cricket::CN_DATA,
deadbeefac22f702017-01-12 21:59:29 -08003174 (flags & RTCP_MUX_REQUIRED) != 0, (flags & SECURE) != 0);
deadbeeff5346592017-01-24 21:51:21 -08003175 if (!channel->NeedsRtcpTransport()) {
3176 fake_rtcp_dtls_transport = nullptr;
zhihuangf5b251b2017-01-12 19:37:48 -08003177 }
deadbeeff5346592017-01-24 21:51:21 -08003178 if (!channel->Init_w(fake_rtp_dtls_transport, fake_rtcp_dtls_transport,
3179 fake_rtp_packet_transport, fake_rtcp_packet_transport)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003180 delete channel;
3181 channel = NULL;
3182 }
3183 return channel;
3184}
3185
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003186template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003187void ChannelTest<DataTraits>::CreateContent(
3188 int flags,
3189 const cricket::AudioCodec& audio_codec,
3190 const cricket::VideoCodec& video_codec,
3191 cricket::DataContentDescription* data) {
3192 data->AddCodec(kGoogleDataCodec);
3193 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3194 if (flags & SECURE) {
3195 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003196 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3197 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198 }
3199}
3200
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003201template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202void ChannelTest<DataTraits>::CopyContent(
3203 const cricket::DataContentDescription& source,
3204 cricket::DataContentDescription* data) {
3205 *data = source;
3206}
3207
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003208template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3210 const cricket::DataCodec& c2) {
3211 return c1.name == c2.name;
3212}
3213
Peter Boström0c4e06b2015-10-07 12:23:21 +02003214template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003215void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003216 uint32_t ssrc,
3217 int flags,
3218 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003219 data->AddLegacyStream(ssrc);
3220}
3221
deadbeef953c2ce2017-01-09 14:53:41 -08003222TEST_F(RtpDataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003223 Base::TestInit();
3224 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3225}
3226
deadbeef953c2ce2017-01-09 14:53:41 -08003227TEST_F(RtpDataChannelSingleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003228 Base::TestDeinit();
3229}
3230
deadbeef953c2ce2017-01-09 14:53:41 -08003231TEST_F(RtpDataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232 Base::TestSetContents();
3233}
3234
deadbeef953c2ce2017-01-09 14:53:41 -08003235TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236 Base::TestSetContentsNullOffer();
3237}
3238
deadbeef953c2ce2017-01-09 14:53:41 -08003239TEST_F(RtpDataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003240 Base::TestSetContentsRtcpMux();
3241}
3242
deadbeef953c2ce2017-01-09 14:53:41 -08003243TEST_F(RtpDataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003244 Base::TestSetRemoteContentUpdate();
3245}
3246
deadbeef953c2ce2017-01-09 14:53:41 -08003247TEST_F(RtpDataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003248 Base::TestStreams();
3249}
3250
deadbeef953c2ce2017-01-09 14:53:41 -08003251TEST_F(RtpDataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003252 Base::TestUpdateStreamsInLocalContent();
3253}
3254
deadbeef953c2ce2017-01-09 14:53:41 -08003255TEST_F(RtpDataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256 Base::TestUpdateStreamsInRemoteContent();
3257}
3258
deadbeef953c2ce2017-01-09 14:53:41 -08003259TEST_F(RtpDataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003260 Base::TestChangeStreamParamsInContent();
3261}
3262
deadbeef953c2ce2017-01-09 14:53:41 -08003263TEST_F(RtpDataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003264 Base::TestPlayoutAndSendingStates();
3265}
3266
deadbeef953c2ce2017-01-09 14:53:41 -08003267TEST_F(RtpDataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268 Base::TestMediaContentDirection();
3269}
3270
deadbeef953c2ce2017-01-09 14:53:41 -08003271TEST_F(RtpDataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003272 Base::TestCallSetup();
3273}
3274
deadbeef953c2ce2017-01-09 14:53:41 -08003275TEST_F(RtpDataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276 Base::TestCallTeardownRtcpMux();
3277}
3278
zstein56162b92017-04-24 16:54:35 -07003279TEST_F(RtpDataChannelSingleThreadTest, TestOnTransportReadyToSend) {
3280 Base::TestOnTransportReadyToSend();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003281}
3282
zstein56162b92017-04-24 16:54:35 -07003283TEST_F(RtpDataChannelSingleThreadTest, TestOnTransportReadyToSendWithRtcpMux) {
3284 Base::TestOnTransportReadyToSendWithRtcpMux();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003285}
3286
deadbeef953c2ce2017-01-09 14:53:41 -08003287TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288 Base::SendRtpToRtp();
3289}
3290
deadbeef953c2ce2017-01-09 14:53:41 -08003291TEST_F(RtpDataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003292 Base::SendRtcpToRtcp();
3293}
3294
deadbeef953c2ce2017-01-09 14:53:41 -08003295TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296 Base::SendRtcpMuxToRtcp();
3297}
3298
deadbeef953c2ce2017-01-09 14:53:41 -08003299TEST_F(RtpDataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003300 Base::SendRtcpMuxToRtcpMux();
3301}
3302
deadbeef953c2ce2017-01-09 14:53:41 -08003303TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003304 Base::SendEarlyRtcpMuxToRtcp();
3305}
3306
deadbeef953c2ce2017-01-09 14:53:41 -08003307TEST_F(RtpDataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003308 Base::SendEarlyRtcpMuxToRtcpMux();
3309}
3310
deadbeef953c2ce2017-01-09 14:53:41 -08003311TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312 Base::SendSrtpToSrtp();
3313}
3314
deadbeef953c2ce2017-01-09 14:53:41 -08003315TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003316 Base::SendSrtpToSrtp();
3317}
3318
deadbeef953c2ce2017-01-09 14:53:41 -08003319TEST_F(RtpDataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3321}
3322
deadbeef953c2ce2017-01-09 14:53:41 -08003323TEST_F(RtpDataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324 Base::SendRtpToRtpOnThread();
3325}
3326
deadbeef953c2ce2017-01-09 14:53:41 -08003327TEST_F(RtpDataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 Base::SendSrtpToSrtpOnThread();
3329}
3330
deadbeef953c2ce2017-01-09 14:53:41 -08003331TEST_F(RtpDataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003332 Base::SendWithWritabilityLoss();
3333}
3334
deadbeef953c2ce2017-01-09 14:53:41 -08003335TEST_F(RtpDataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336 Base::TestMediaMonitor();
3337}
3338
deadbeef953c2ce2017-01-09 14:53:41 -08003339TEST_F(RtpDataChannelSingleThreadTest, TestSendData) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003340 CreateChannels(0, 0);
3341 EXPECT_TRUE(SendInitiate());
3342 EXPECT_TRUE(SendAccept());
3343
3344 cricket::SendDataParams params;
3345 params.ssrc = 42;
3346 unsigned char data[] = {'f', 'o', 'o'};
3347 rtc::CopyOnWriteBuffer payload(data, 3);
3348 cricket::SendDataResult result;
3349 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3350 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3351 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3352}
3353
deadbeef953c2ce2017-01-09 14:53:41 -08003354TEST_F(RtpDataChannelDoubleThreadTest, TestInit) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003355 Base::TestInit();
3356 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3357}
3358
deadbeef953c2ce2017-01-09 14:53:41 -08003359TEST_F(RtpDataChannelDoubleThreadTest, TestDeinit) {
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003360 Base::TestDeinit();
3361}
3362
deadbeef953c2ce2017-01-09 14:53:41 -08003363TEST_F(RtpDataChannelDoubleThreadTest, TestSetContents) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003364 Base::TestSetContents();
3365}
3366
deadbeef953c2ce2017-01-09 14:53:41 -08003367TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsNullOffer) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003368 Base::TestSetContentsNullOffer();
3369}
3370
deadbeef953c2ce2017-01-09 14:53:41 -08003371TEST_F(RtpDataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003372 Base::TestSetContentsRtcpMux();
3373}
3374
deadbeef953c2ce2017-01-09 14:53:41 -08003375TEST_F(RtpDataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003376 Base::TestSetRemoteContentUpdate();
3377}
3378
deadbeef953c2ce2017-01-09 14:53:41 -08003379TEST_F(RtpDataChannelDoubleThreadTest, TestStreams) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003380 Base::TestStreams();
3381}
3382
deadbeef953c2ce2017-01-09 14:53:41 -08003383TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003384 Base::TestUpdateStreamsInLocalContent();
3385}
3386
deadbeef953c2ce2017-01-09 14:53:41 -08003387TEST_F(RtpDataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003388 Base::TestUpdateStreamsInRemoteContent();
3389}
3390
deadbeef953c2ce2017-01-09 14:53:41 -08003391TEST_F(RtpDataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003392 Base::TestChangeStreamParamsInContent();
3393}
3394
deadbeef953c2ce2017-01-09 14:53:41 -08003395TEST_F(RtpDataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003396 Base::TestPlayoutAndSendingStates();
3397}
3398
deadbeef953c2ce2017-01-09 14:53:41 -08003399TEST_F(RtpDataChannelDoubleThreadTest, TestMediaContentDirection) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003400 Base::TestMediaContentDirection();
3401}
3402
deadbeef953c2ce2017-01-09 14:53:41 -08003403TEST_F(RtpDataChannelDoubleThreadTest, TestCallSetup) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003404 Base::TestCallSetup();
3405}
3406
deadbeef953c2ce2017-01-09 14:53:41 -08003407TEST_F(RtpDataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003408 Base::TestCallTeardownRtcpMux();
3409}
3410
zstein56162b92017-04-24 16:54:35 -07003411TEST_F(RtpDataChannelDoubleThreadTest, TestOnTransportReadyToSend) {
3412 Base::TestOnTransportReadyToSend();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003413}
3414
zstein56162b92017-04-24 16:54:35 -07003415TEST_F(RtpDataChannelDoubleThreadTest, TestOnTransportReadyToSendWithRtcpMux) {
3416 Base::TestOnTransportReadyToSendWithRtcpMux();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003417}
3418
deadbeef953c2ce2017-01-09 14:53:41 -08003419TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003420 Base::SendRtpToRtp();
3421}
3422
deadbeef953c2ce2017-01-09 14:53:41 -08003423TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003424 Base::SendRtcpToRtcp();
3425}
3426
deadbeef953c2ce2017-01-09 14:53:41 -08003427TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003428 Base::SendRtcpMuxToRtcp();
3429}
3430
deadbeef953c2ce2017-01-09 14:53:41 -08003431TEST_F(RtpDataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003432 Base::SendRtcpMuxToRtcpMux();
3433}
3434
deadbeef953c2ce2017-01-09 14:53:41 -08003435TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003436 Base::SendEarlyRtcpMuxToRtcp();
3437}
3438
deadbeef953c2ce2017-01-09 14:53:41 -08003439TEST_F(RtpDataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003440 Base::SendEarlyRtcpMuxToRtcpMux();
3441}
3442
deadbeef953c2ce2017-01-09 14:53:41 -08003443TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003444 Base::SendSrtpToSrtp();
3445}
3446
deadbeef953c2ce2017-01-09 14:53:41 -08003447TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToRtp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003448 Base::SendSrtpToSrtp();
3449}
3450
deadbeef953c2ce2017-01-09 14:53:41 -08003451TEST_F(RtpDataChannelDoubleThreadTest, SendSrtcpMux) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003452 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3453}
3454
deadbeef953c2ce2017-01-09 14:53:41 -08003455TEST_F(RtpDataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003456 Base::SendRtpToRtpOnThread();
3457}
3458
deadbeef953c2ce2017-01-09 14:53:41 -08003459TEST_F(RtpDataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003460 Base::SendSrtpToSrtpOnThread();
3461}
3462
deadbeef953c2ce2017-01-09 14:53:41 -08003463TEST_F(RtpDataChannelDoubleThreadTest, SendWithWritabilityLoss) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003464 Base::SendWithWritabilityLoss();
3465}
3466
deadbeef953c2ce2017-01-09 14:53:41 -08003467TEST_F(RtpDataChannelDoubleThreadTest, TestMediaMonitor) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003468 Base::TestMediaMonitor();
3469}
3470
deadbeef953c2ce2017-01-09 14:53:41 -08003471TEST_F(RtpDataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003472 CreateChannels(0, 0);
3473 EXPECT_TRUE(SendInitiate());
3474 EXPECT_TRUE(SendAccept());
3475
3476 cricket::SendDataParams params;
3477 params.ssrc = 42;
3478 unsigned char data[] = {
3479 'f', 'o', 'o'
3480 };
jbaucheec21bd2016-03-20 06:15:43 -07003481 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003482 cricket::SendDataResult result;
3483 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3484 EXPECT_EQ(params.ssrc,
3485 media_channel1_->last_sent_data_params().ssrc);
3486 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3487}
3488
deadbeefbad5dad2017-01-17 18:32:35 -08003489#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3490
3491// Verifies some DCHECKs are in place.
3492// Uses VoiceChannel, but any BaseChannel subclass would work.
3493class BaseChannelDeathTest : public testing::Test {
3494 public:
3495 BaseChannelDeathTest()
deadbeeff5346592017-01-24 21:51:21 -08003496 : fake_rtp_dtls_transport_("foo", cricket::ICE_CANDIDATE_COMPONENT_RTP),
3497 fake_rtcp_dtls_transport_("foo", cricket::ICE_CANDIDATE_COMPONENT_RTCP),
3498 // RTCP mux not required, SRTP required.
deadbeefbad5dad2017-01-17 18:32:35 -08003499 voice_channel_(
3500 rtc::Thread::Current(),
3501 rtc::Thread::Current(),
3502 rtc::Thread::Current(),
3503 &fake_media_engine_,
3504 new cricket::FakeVoiceMediaChannel(nullptr,
3505 cricket::AudioOptions()),
3506 cricket::CN_AUDIO,
3507 false,
deadbeeff5346592017-01-24 21:51:21 -08003508 true) {}
deadbeefbad5dad2017-01-17 18:32:35 -08003509
3510 protected:
deadbeefbad5dad2017-01-17 18:32:35 -08003511 cricket::FakeMediaEngine fake_media_engine_;
deadbeeff5346592017-01-24 21:51:21 -08003512 cricket::FakeDtlsTransport fake_rtp_dtls_transport_;
3513 cricket::FakeDtlsTransport fake_rtcp_dtls_transport_;
deadbeefbad5dad2017-01-17 18:32:35 -08003514 cricket::VoiceChannel voice_channel_;
deadbeefbad5dad2017-01-17 18:32:35 -08003515};
3516
deadbeeff5346592017-01-24 21:51:21 -08003517TEST_F(BaseChannelDeathTest, SetTransportsWithNullRtpTransport) {
3518 ASSERT_TRUE(voice_channel_.Init_w(
3519 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3520 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3521 cricket::FakeDtlsTransport new_rtcp_transport(
3522 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
3523 EXPECT_DEATH(voice_channel_.SetTransports(nullptr, &new_rtcp_transport), "");
deadbeefbad5dad2017-01-17 18:32:35 -08003524}
3525
deadbeeff5346592017-01-24 21:51:21 -08003526TEST_F(BaseChannelDeathTest, SetTransportsWithMissingRtcpTransport) {
3527 ASSERT_TRUE(voice_channel_.Init_w(
3528 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3529 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3530 cricket::FakeDtlsTransport new_rtp_transport(
3531 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3532 EXPECT_DEATH(voice_channel_.SetTransports(&new_rtp_transport, nullptr), "");
deadbeefbad5dad2017-01-17 18:32:35 -08003533}
3534
deadbeeff5346592017-01-24 21:51:21 -08003535TEST_F(BaseChannelDeathTest, SetTransportsWithUnneededRtcpTransport) {
3536 ASSERT_TRUE(voice_channel_.Init_w(
3537 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3538 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
deadbeefbad5dad2017-01-17 18:32:35 -08003539 // Activate RTCP muxing, simulating offer/answer negotiation.
3540 cricket::AudioContentDescription content;
3541 content.set_rtcp_mux(true);
3542 ASSERT_TRUE(voice_channel_.SetLocalContent(&content, CA_OFFER, nullptr));
3543 ASSERT_TRUE(voice_channel_.SetRemoteContent(&content, CA_ANSWER, nullptr));
deadbeeff5346592017-01-24 21:51:21 -08003544 cricket::FakeDtlsTransport new_rtp_transport(
3545 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3546 cricket::FakeDtlsTransport new_rtcp_transport(
3547 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
deadbeefbad5dad2017-01-17 18:32:35 -08003548 // After muxing is enabled, no RTCP transport should be passed in here.
3549 EXPECT_DEATH(
deadbeeff5346592017-01-24 21:51:21 -08003550 voice_channel_.SetTransports(&new_rtp_transport, &new_rtcp_transport),
3551 "");
deadbeefbad5dad2017-01-17 18:32:35 -08003552}
3553
3554// This test will probably go away if/when we move the transport name out of
3555// the transport classes and into their parent classes.
deadbeeff5346592017-01-24 21:51:21 -08003556TEST_F(BaseChannelDeathTest, SetTransportsWithMismatchingTransportNames) {
3557 ASSERT_TRUE(voice_channel_.Init_w(
3558 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3559 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3560 cricket::FakeDtlsTransport new_rtp_transport(
3561 "bar", cricket::ICE_CANDIDATE_COMPONENT_RTP);
3562 cricket::FakeDtlsTransport new_rtcp_transport(
3563 "baz", cricket::ICE_CANDIDATE_COMPONENT_RTCP);
deadbeefbad5dad2017-01-17 18:32:35 -08003564 EXPECT_DEATH(
deadbeeff5346592017-01-24 21:51:21 -08003565 voice_channel_.SetTransports(&new_rtp_transport, &new_rtcp_transport),
3566 "");
3567}
3568
3569// Not expected to support going from DtlsTransportInternal to
deadbeef5bd5ca32017-02-10 11:31:50 -08003570// PacketTransportInternal.
deadbeeff5346592017-01-24 21:51:21 -08003571TEST_F(BaseChannelDeathTest, SetTransportsDtlsToNonDtls) {
3572 ASSERT_TRUE(voice_channel_.Init_w(
3573 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_,
3574 &fake_rtp_dtls_transport_, &fake_rtcp_dtls_transport_));
3575 EXPECT_DEATH(
deadbeef5bd5ca32017-02-10 11:31:50 -08003576 voice_channel_.SetTransports(
3577 static_cast<rtc::PacketTransportInternal*>(&fake_rtp_dtls_transport_),
3578 static_cast<rtc::PacketTransportInternal*>(
3579 &fake_rtp_dtls_transport_)),
deadbeeff5346592017-01-24 21:51:21 -08003580 "");
3581}
3582
deadbeef5bd5ca32017-02-10 11:31:50 -08003583// Not expected to support going from PacketTransportInternal to
deadbeeff5346592017-01-24 21:51:21 -08003584// DtlsTransportInternal.
3585TEST_F(BaseChannelDeathTest, SetTransportsNonDtlsToDtls) {
3586 ASSERT_TRUE(voice_channel_.Init_w(nullptr, nullptr, &fake_rtp_dtls_transport_,
3587 &fake_rtcp_dtls_transport_));
3588 EXPECT_DEATH(voice_channel_.SetTransports(&fake_rtp_dtls_transport_,
3589 &fake_rtp_dtls_transport_),
3590 "");
deadbeefbad5dad2017-01-17 18:32:35 -08003591}
3592
3593#endif // RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
3594
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003595// TODO(pthatcher): TestSetReceiver?