blob: 5c5eefa5cb742d030af1315e000558271c764543 [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"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000015#include "webrtc/base/gunit.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000016#include "webrtc/base/logging.h"
kjellandera96e2d72016-02-04 23:52:28 -080017#include "webrtc/media/base/fakemediaengine.h"
18#include "webrtc/media/base/fakertp.h"
kjellandera96e2d72016-02-04 23:52:28 -080019#include "webrtc/media/base/mediachannel.h"
kjellandera96e2d72016-02-04 23:52:28 -080020#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010021#include "webrtc/p2p/base/faketransportcontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010022#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023
24#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000025 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026 LOG(LS_INFO) << "Feature disabled... skipping"; \
27 return; \
28 }
29
30using cricket::CA_OFFER;
31using cricket::CA_PRANSWER;
32using cricket::CA_ANSWER;
33using cricket::CA_UPDATE;
34using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035using cricket::ScreencastId;
36using cricket::StreamParams;
37using cricket::TransportChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038
Danil Chapovalov33b01f22016-05-11 19:55:27 +020039namespace {
40const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
41const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
42const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
43const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30);
44const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15);
45const cricket::DataCodec kGoogleDataCodec(101, "google-data");
46const uint32_t kSsrc1 = 0x1111;
47const uint32_t kSsrc2 = 0x2222;
48const uint32_t kSsrc3 = 0x3333;
49const int kAudioPts[] = {0, 8};
50const int kVideoPts[] = {97, 99};
51enum class NetworkIsWorker { Yes, No };
52} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053
deadbeefcbecd352015-09-23 11:50:27 -070054template <class ChannelT,
55 class MediaChannelT,
56 class ContentT,
57 class CodecT,
58 class MediaInfoT,
59 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060class Traits {
61 public:
62 typedef ChannelT Channel;
63 typedef MediaChannelT MediaChannel;
64 typedef ContentT Content;
65 typedef CodecT Codec;
66 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020067 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068};
69
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070class VoiceTraits : public Traits<cricket::VoiceChannel,
71 cricket::FakeVoiceMediaChannel,
72 cricket::AudioContentDescription,
73 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020074 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070075 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
77class VideoTraits : public Traits<cricket::VideoChannel,
78 cricket::FakeVideoMediaChannel,
79 cricket::VideoContentDescription,
80 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020081 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070082 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
84class DataTraits : public Traits<cricket::DataChannel,
85 cricket::FakeDataMediaChannel,
86 cricket::DataContentDescription,
87 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020088 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070089 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
Danil Chapovalov33b01f22016-05-11 19:55:27 +020091// Base class for Voice/Video/DataChannel tests
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092template<class T>
93class ChannelTest : public testing::Test, public sigslot::has_slots<> {
94 public:
95 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
96 DTLS = 0x10 };
97
Peter Boström34fbfff2015-09-24 19:20:30 +020098 ChannelTest(bool verify_playout,
Danil Chapovalov33b01f22016-05-11 19:55:27 +020099 rtc::ArrayView<const uint8_t> rtp_data,
100 rtc::ArrayView<const uint8_t> rtcp_data,
101 NetworkIsWorker network_is_worker)
Peter Boström34fbfff2015-09-24 19:20:30 +0200102 : verify_playout_(verify_playout),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 media_channel1_(NULL),
104 media_channel2_(NULL),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200105 rtp_packet_(rtp_data.data(), rtp_data.size()),
106 rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 media_info_callbacks1_(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200108 media_info_callbacks2_() {
109 if (network_is_worker == NetworkIsWorker::Yes) {
110 network_thread_ = rtc::Thread::Current();
111 } else {
112 network_thread_keeper_ = rtc::Thread::Create();
113 network_thread_keeper_->SetName("Network", nullptr);
114 network_thread_keeper_->Start();
115 network_thread_ = network_thread_keeper_.get();
116 }
117 transport_controller1_.reset(new cricket::FakeTransportController(
118 network_thread_, cricket::ICEROLE_CONTROLLING));
119 transport_controller2_.reset(new cricket::FakeTransportController(
120 network_thread_, cricket::ICEROLE_CONTROLLED));
121 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000122
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200124 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
125 new typename T::MediaChannel(NULL, typename T::Options()),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200126 flags1, flags2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000127 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200128 void CreateChannels(typename T::MediaChannel* ch1,
129 typename T::MediaChannel* ch2,
130 int flags1,
131 int flags2) {
132 rtc::Thread* worker_thread = rtc::Thread::Current();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133 media_channel1_ = ch1;
134 media_channel2_ = ch2;
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200135 channel1_.reset(
136 CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
137 transport_controller1_.get(), (flags1 & RTCP) != 0));
138 channel2_.reset(
139 CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
140 transport_controller2_.get(), (flags2 & RTCP) != 0));
141 channel1_->SignalMediaMonitor.connect(this,
142 &ChannelTest<T>::OnMediaMonitor1);
143 channel2_->SignalMediaMonitor.connect(this,
144 &ChannelTest<T>::OnMediaMonitor2);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000145 if ((flags1 & DTLS) && (flags2 & DTLS)) {
146 flags1 = (flags1 & ~SECURE);
147 flags2 = (flags2 & ~SECURE);
148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 CreateContent(flags1, kPcmuCodec, kH264Codec,
150 &local_media_content1_);
151 CreateContent(flags2, kPcmuCodec, kH264Codec,
152 &local_media_content2_);
153 CopyContent(local_media_content1_, &remote_media_content1_);
154 CopyContent(local_media_content2_, &remote_media_content2_);
155
156 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200157 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200158 transport_controller1_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700159 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800160 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161 }
162 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200163 // Confirmed to work with KT_RSA and KT_ECDSA.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200164 transport_controller2_->SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700165 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800166 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 }
168
169 // Add stream information (SSRC) to the local content but not to the remote
170 // content. This means that we per default know the SSRC of what we send but
171 // not what we receive.
172 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
173 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
174
175 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
176 if (flags1 & SSRC_MUX) {
177 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
178 }
179 if (flags2 & SSRC_MUX) {
180 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
181 }
182 }
deadbeefcbecd352015-09-23 11:50:27 -0700183 typename T::Channel* CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200184 rtc::Thread* worker_thread,
185 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -0700186 cricket::MediaEngineInterface* engine,
187 typename T::MediaChannel* ch,
188 cricket::TransportController* transport_controller,
189 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200190 typename T::Channel* channel =
191 new typename T::Channel(worker_thread, network_thread, engine, ch,
192 transport_controller, cricket::CN_AUDIO, rtcp);
193 if (!channel->Init_w()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 delete channel;
195 channel = NULL;
196 }
197 return channel;
198 }
199
200 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000201 bool result = channel1_->SetLocalContent(&local_media_content1_,
202 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 if (result) {
204 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000205 result = channel2_->SetRemoteContent(&remote_media_content1_,
206 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 if (result) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200208 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000210 result = channel2_->SetLocalContent(&local_media_content2_,
211 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 }
213 }
214 return result;
215 }
216
217 bool SendAccept() {
218 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000219 return channel1_->SetRemoteContent(&remote_media_content2_,
220 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 }
222
223 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000224 bool result = channel1_->SetLocalContent(&local_media_content1_,
225 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 if (result) {
227 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000228 result = channel2_->SetRemoteContent(&remote_media_content1_,
229 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 }
231 return result;
232 }
233
234 bool SendProvisionalAnswer() {
235 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000236 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000237 if (result) {
238 channel2_->Enable(true);
239 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000240 CA_PRANSWER, NULL);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200241 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 }
243 return result;
244 }
245
246 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 bool result = channel2_->SetLocalContent(&local_media_content2_,
248 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000250 result = channel1_->SetRemoteContent(&remote_media_content2_,
251 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 return result;
253 }
254
255 bool SendTerminate() {
256 channel1_.reset();
257 channel2_.reset();
258 return true;
259 }
260
261 bool AddStream1(int id) {
262 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
263 }
264 bool RemoveStream1(int id) {
265 return channel1_->RemoveRecvStream(id);
266 }
267
268 cricket::FakeTransport* GetTransport1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200269 std::string name = channel1_->content_name();
270 return network_thread_->Invoke<cricket::FakeTransport*>(
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200271 [this, name] { return transport_controller1_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 }
273 cricket::FakeTransport* GetTransport2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200274 std::string name = channel2_->content_name();
275 return network_thread_->Invoke<cricket::FakeTransport*>(
Danil Chapovalov7f216b72016-05-12 09:20:31 +0200276 [this, name] { return transport_controller2_->GetTransport_n(name); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 }
278
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200279 void SendRtp1() {
280 media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
281 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200283 void SendRtp2() {
284 media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
285 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200287 void SendRtcp1() {
288 media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200290 void SendRtcp2() {
291 media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 }
293 // Methods to send custom data.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200294 void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
295 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
296 media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200298 void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
299 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
300 media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200302 void SendCustomRtcp1(uint32_t ssrc) {
303 rtc::Buffer data = CreateRtcpData(ssrc);
304 media_channel1_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200306 void SendCustomRtcp2(uint32_t ssrc) {
307 rtc::Buffer data = CreateRtcpData(ssrc);
308 media_channel2_->SendRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200310
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 bool CheckRtp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200312 return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 }
314 bool CheckRtp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200315 return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
317 bool CheckRtcp1() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200318 return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 }
320 bool CheckRtcp2() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200321 return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
323 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200324 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200325 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
326 return media_channel1_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200328 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200329 rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
330 return media_channel2_->CheckRtp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200332 bool CheckCustomRtcp1(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200333 rtc::Buffer data = CreateRtcpData(ssrc);
334 return media_channel1_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200336 bool CheckCustomRtcp2(uint32_t ssrc) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200337 rtc::Buffer data = CreateRtcpData(ssrc);
338 return media_channel2_->CheckRtcp(data.data(), data.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200340 rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
341 rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 // Set SSRC in the rtp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200343 rtc::SetBE32(data.data() + 8, ssrc);
344 rtc::SetBE16(data.data() + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000345 if (pl_type >= 0) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200346 rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000347 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 return data;
349 }
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200350 rtc::Buffer CreateRtcpData(uint32_t ssrc) {
351 rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 // Set SSRC in the rtcp packet copy.
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200353 rtc::SetBE32(data.data() + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 return data;
355 }
356
357 bool CheckNoRtp1() {
358 return media_channel1_->CheckNoRtp();
359 }
360 bool CheckNoRtp2() {
361 return media_channel2_->CheckNoRtp();
362 }
363 bool CheckNoRtcp1() {
364 return media_channel1_->CheckNoRtcp();
365 }
366 bool CheckNoRtcp2() {
367 return media_channel2_->CheckNoRtcp();
368 }
369
370 void CreateContent(int flags,
371 const cricket::AudioCodec& audio_codec,
372 const cricket::VideoCodec& video_codec,
373 typename T::Content* content) {
374 // overridden in specialized classes
375 }
376 void CopyContent(const typename T::Content& source,
377 typename T::Content* content) {
378 // overridden in specialized classes
379 }
380
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 // Creates a cricket::SessionDescription with one MediaContent and one stream.
382 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200383 cricket::SessionDescription* CreateSessionDescriptionWithStream(
384 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 typename T::Content content;
386 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
387 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
388 AddLegacyStreamInContent(ssrc, 0, &content);
389 sdesc->AddContent("DUMMY_CONTENT_NAME",
390 cricket::NS_JINGLE_RTP, content.Copy());
391 return sdesc;
392 }
393
ossu292d6582016-03-17 02:31:13 -0700394 // Will manage the lifetime of a CallThread, making sure it's
395 // destroyed before this object goes out of scope.
396 class ScopedCallThread {
397 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200398 template <class FunctorT>
399 ScopedCallThread(const FunctorT& functor)
400 : thread_(rtc::Thread::Create()),
401 task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
ossu292d6582016-03-17 02:31:13 -0700402 thread_->Start();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200403 thread_->Post(task_.get());
ossu292d6582016-03-17 02:31:13 -0700404 }
405
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200406 ~ScopedCallThread() { thread_->Stop(); }
ossu292d6582016-03-17 02:31:13 -0700407
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200408 rtc::Thread* thread() { return thread_.get(); }
ossu292d6582016-03-17 02:31:13 -0700409
410 private:
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200411 std::unique_ptr<rtc::Thread> thread_;
412 std::unique_ptr<rtc::MessageHandler> task_;
ossu292d6582016-03-17 02:31:13 -0700413 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
416 return false; // overridden in specialized classes
417 }
418
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200419 void OnMediaMonitor1(typename T::Channel* channel,
420 const typename T::MediaInfo& info) {
421 RTC_DCHECK_EQ(channel, channel1_.get());
422 media_info_callbacks1_++;
423 }
424 void OnMediaMonitor2(typename T::Channel* channel,
425 const typename T::MediaInfo& info) {
426 RTC_DCHECK_EQ(channel, channel2_.get());
427 media_info_callbacks2_++;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 }
429
Honghai Zhangcc411c02016-03-29 17:27:21 -0700430 cricket::CandidatePairInterface* last_selected_candidate_pair() {
431 return last_selected_candidate_pair_;
432 }
433
Peter Boström0c4e06b2015-10-07 12:23:21 +0200434 void AddLegacyStreamInContent(uint32_t ssrc,
435 int flags,
436 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 // Base implementation.
438 }
439
440 // Tests that can be used by derived classes.
441
442 // Basic sanity check.
443 void TestInit() {
444 CreateChannels(0, 0);
445 EXPECT_FALSE(channel1_->secure());
446 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200447 if (verify_playout_) {
448 EXPECT_FALSE(media_channel1_->playout());
449 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 EXPECT_TRUE(media_channel1_->codecs().empty());
451 EXPECT_TRUE(media_channel1_->recv_streams().empty());
452 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
453 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
454 }
455
456 // Test that SetLocalContent and SetRemoteContent properly configure
457 // the codecs.
458 void TestSetContents() {
459 CreateChannels(0, 0);
460 typename T::Content content;
461 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000462 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000464 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000465 ASSERT_EQ(1U, media_channel1_->codecs().size());
466 EXPECT_TRUE(CodecMatches(content.codecs()[0],
467 media_channel1_->codecs()[0]));
468 }
469
470 // Test that SetLocalContent and SetRemoteContent properly deals
471 // with an empty offer.
472 void TestSetContentsNullOffer() {
473 CreateChannels(0, 0);
474 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000475 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 CreateContent(0, kPcmuCodec, kH264Codec, &content);
477 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000478 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000479 ASSERT_EQ(1U, media_channel1_->codecs().size());
480 EXPECT_TRUE(CodecMatches(content.codecs()[0],
481 media_channel1_->codecs()[0]));
482 }
483
484 // Test that SetLocalContent and SetRemoteContent properly set RTCP
485 // mux.
486 void TestSetContentsRtcpMux() {
487 CreateChannels(RTCP, RTCP);
488 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
489 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
490 typename T::Content content;
491 CreateContent(0, kPcmuCodec, kH264Codec, &content);
492 // Both sides agree on mux. Should no longer be a separate RTCP channel.
493 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000494 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
495 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
497 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000498 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000500 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
502 }
503
504 // Test that SetLocalContent and SetRemoteContent properly set RTCP
505 // mux when a provisional answer is received.
506 void TestSetContentsRtcpMuxWithPrAnswer() {
507 CreateChannels(RTCP, RTCP);
508 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
509 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
510 typename T::Content content;
511 CreateContent(0, kPcmuCodec, kH264Codec, &content);
512 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000513 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
514 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000516 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517 // Both sides agree on mux. Should no longer be a separate RTCP channel.
518 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
519 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000520 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000522 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
523 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
525 }
526
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000527 // Test that SetRemoteContent properly deals with a content update.
528 void TestSetRemoteContentUpdate() {
529 CreateChannels(0, 0);
530 typename T::Content content;
531 CreateContent(RTCP | RTCP_MUX | SECURE,
532 kPcmuCodec, kH264Codec,
533 &content);
534 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000535 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
536 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 ASSERT_EQ(1U, media_channel1_->codecs().size());
538 EXPECT_TRUE(CodecMatches(content.codecs()[0],
539 media_channel1_->codecs()[0]));
540 // Now update with other codecs.
541 typename T::Content update_content;
542 update_content.set_partial(true);
543 CreateContent(0, kIsacCodec, kH264SvcCodec,
544 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000545 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 ASSERT_EQ(1U, media_channel1_->codecs().size());
547 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
548 media_channel1_->codecs()[0]));
549 // Now update without any codecs. This is ignored.
550 typename T::Content empty_content;
551 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000552 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 ASSERT_EQ(1U, media_channel1_->codecs().size());
554 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
555 media_channel1_->codecs()[0]));
556 }
557
558 // Test that Add/RemoveStream properly forward to the media channel.
559 void TestStreams() {
560 CreateChannels(0, 0);
561 EXPECT_TRUE(AddStream1(1));
562 EXPECT_TRUE(AddStream1(2));
563 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
564 EXPECT_TRUE(RemoveStream1(2));
565 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
566 EXPECT_TRUE(RemoveStream1(1));
567 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
568 }
569
570 // Test that SetLocalContent properly handles adding and removing StreamParams
571 // to the local content description.
572 // This test uses the CA_UPDATE action that don't require a full
573 // MediaContentDescription to do an update.
574 void TestUpdateStreamsInLocalContent() {
575 cricket::StreamParams stream1;
576 stream1.groupid = "group1";
577 stream1.id = "stream1";
578 stream1.ssrcs.push_back(kSsrc1);
579 stream1.cname = "stream1_cname";
580
581 cricket::StreamParams stream2;
582 stream2.groupid = "group2";
583 stream2.id = "stream2";
584 stream2.ssrcs.push_back(kSsrc2);
585 stream2.cname = "stream2_cname";
586
587 cricket::StreamParams stream3;
588 stream3.groupid = "group3";
589 stream3.id = "stream3";
590 stream3.ssrcs.push_back(kSsrc3);
591 stream3.cname = "stream3_cname";
592
593 CreateChannels(0, 0);
594 typename T::Content content1;
595 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
596 content1.AddStream(stream1);
597 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000598 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599
600 ASSERT_EQ(1u, media_channel1_->send_streams().size());
601 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
602
603 // Update the local streams by adding another sending stream.
604 // Use a partial updated session description.
605 typename T::Content content2;
606 content2.AddStream(stream2);
607 content2.AddStream(stream3);
608 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000609 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 ASSERT_EQ(3u, media_channel1_->send_streams().size());
611 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
612 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
613 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
614
615 // Update the local streams by removing the first sending stream.
616 // This is done by removing all SSRCS for this particular stream.
617 typename T::Content content3;
618 stream1.ssrcs.clear();
619 content3.AddStream(stream1);
620 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000621 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 ASSERT_EQ(2u, media_channel1_->send_streams().size());
623 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
624 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
625
626 // Update the local streams with a stream that does not change.
627 // THe update is ignored.
628 typename T::Content content4;
629 content4.AddStream(stream2);
630 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000631 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 ASSERT_EQ(2u, media_channel1_->send_streams().size());
633 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
634 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
635 }
636
637 // Test that SetRemoteContent properly handles adding and removing
638 // StreamParams to the remote content description.
639 // This test uses the CA_UPDATE action that don't require a full
640 // MediaContentDescription to do an update.
641 void TestUpdateStreamsInRemoteContent() {
642 cricket::StreamParams stream1;
643 stream1.id = "Stream1";
644 stream1.groupid = "1";
645 stream1.ssrcs.push_back(kSsrc1);
646 stream1.cname = "stream1_cname";
647
648 cricket::StreamParams stream2;
649 stream2.id = "Stream2";
650 stream2.groupid = "2";
651 stream2.ssrcs.push_back(kSsrc2);
652 stream2.cname = "stream2_cname";
653
654 cricket::StreamParams stream3;
655 stream3.id = "Stream3";
656 stream3.groupid = "3";
657 stream3.ssrcs.push_back(kSsrc3);
658 stream3.cname = "stream3_cname";
659
660 CreateChannels(0, 0);
661 typename T::Content content1;
662 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
663 content1.AddStream(stream1);
664 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000665 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666
667 ASSERT_EQ(1u, media_channel1_->codecs().size());
668 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
669 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
670
671 // Update the remote streams by adding another sending stream.
672 // Use a partial updated session description.
673 typename T::Content content2;
674 content2.AddStream(stream2);
675 content2.AddStream(stream3);
676 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000677 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
679 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
680 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
681 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
682
683 // Update the remote streams by removing the first stream.
684 // This is done by removing all SSRCS for this particular stream.
685 typename T::Content content3;
686 stream1.ssrcs.clear();
687 content3.AddStream(stream1);
688 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000689 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000690 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
691 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
692 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
693
694 // Update the remote streams with a stream that does not change.
695 // The update is ignored.
696 typename T::Content content4;
697 content4.AddStream(stream2);
698 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
701 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
702 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
703 }
704
705 // Test that SetLocalContent and SetRemoteContent properly
706 // handles adding and removing StreamParams when the action is a full
707 // CA_OFFER / CA_ANSWER.
708 void TestChangeStreamParamsInContent() {
709 cricket::StreamParams stream1;
710 stream1.groupid = "group1";
711 stream1.id = "stream1";
712 stream1.ssrcs.push_back(kSsrc1);
713 stream1.cname = "stream1_cname";
714
715 cricket::StreamParams stream2;
716 stream2.groupid = "group1";
717 stream2.id = "stream2";
718 stream2.ssrcs.push_back(kSsrc2);
719 stream2.cname = "stream2_cname";
720
721 // Setup a call where channel 1 send |stream1| to channel 2.
722 CreateChannels(0, 0);
723 typename T::Content content1;
724 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
725 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000726 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 EXPECT_TRUE(channel1_->Enable(true));
728 EXPECT_EQ(1u, media_channel1_->send_streams().size());
729
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000730 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200732 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733
734 // Channel 2 do not send anything.
735 typename T::Content content2;
736 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000737 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000739 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 EXPECT_TRUE(channel2_->Enable(true));
741 EXPECT_EQ(0u, media_channel2_->send_streams().size());
742
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200743 SendCustomRtp1(kSsrc1, 0);
744 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
746
747 // Let channel 2 update the content by sending |stream2| and enable SRTP.
748 typename T::Content content3;
749 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
750 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000751 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 ASSERT_EQ(1u, media_channel2_->send_streams().size());
753 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
754
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000755 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
757 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
758
759 // Channel 1 replies but stop sending stream1.
760 typename T::Content content4;
761 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000762 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 EXPECT_EQ(0u, media_channel1_->send_streams().size());
764
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000765 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
767
768 EXPECT_TRUE(channel1_->secure());
769 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200770 SendCustomRtp2(kSsrc2, 0);
771 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
773 }
774
775 // Test that we only start playout and sending at the right times.
776 void TestPlayoutAndSendingStates() {
777 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200778 if (verify_playout_) {
779 EXPECT_FALSE(media_channel1_->playout());
780 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000781 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200782 if (verify_playout_) {
783 EXPECT_FALSE(media_channel2_->playout());
784 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 EXPECT_FALSE(media_channel2_->sending());
786 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200787 if (verify_playout_) {
788 EXPECT_FALSE(media_channel1_->playout());
789 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000791 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
792 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200793 if (verify_playout_) {
794 EXPECT_TRUE(media_channel1_->playout());
795 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000797 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
798 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200799 if (verify_playout_) {
800 EXPECT_FALSE(media_channel2_->playout());
801 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000803 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
804 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200805 if (verify_playout_) {
806 EXPECT_FALSE(media_channel2_->playout());
807 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 EXPECT_FALSE(media_channel2_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200809 transport_controller1_->Connect(transport_controller2_.get());
Peter Boström34fbfff2015-09-24 19:20:30 +0200810 if (verify_playout_) {
811 EXPECT_TRUE(media_channel1_->playout());
812 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200814 if (verify_playout_) {
815 EXPECT_FALSE(media_channel2_->playout());
816 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_FALSE(media_channel2_->sending());
818 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200819 if (verify_playout_) {
820 EXPECT_TRUE(media_channel2_->playout());
821 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000823 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
824 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200825 if (verify_playout_) {
826 EXPECT_TRUE(media_channel1_->playout());
827 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_TRUE(media_channel1_->sending());
829 }
830
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 // Test that changing the MediaContentDirection in the local and remote
832 // session description start playout and sending at the right time.
833 void TestMediaContentDirection() {
834 CreateChannels(0, 0);
835 typename T::Content content1;
836 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
837 typename T::Content content2;
838 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
839 // Set |content2| to be InActive.
840 content2.set_direction(cricket::MD_INACTIVE);
841
842 EXPECT_TRUE(channel1_->Enable(true));
843 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200844 if (verify_playout_) {
845 EXPECT_FALSE(media_channel1_->playout());
846 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200848 if (verify_playout_) {
849 EXPECT_FALSE(media_channel2_->playout());
850 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 EXPECT_FALSE(media_channel2_->sending());
852
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000853 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
854 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
855 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
856 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200857 transport_controller1_->Connect(transport_controller2_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858
Peter Boström34fbfff2015-09-24 19:20:30 +0200859 if (verify_playout_) {
860 EXPECT_TRUE(media_channel1_->playout());
861 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200863 if (verify_playout_) {
864 EXPECT_FALSE(media_channel2_->playout()); // local InActive
865 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 EXPECT_FALSE(media_channel2_->sending()); // local InActive
867
868 // Update |content2| to be RecvOnly.
869 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000870 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
871 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000872
Peter Boström34fbfff2015-09-24 19:20:30 +0200873 if (verify_playout_) {
874 EXPECT_TRUE(media_channel1_->playout());
875 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200877 if (verify_playout_) {
878 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
879 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
881
882 // Update |content2| to be SendRecv.
883 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000884 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
885 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886
Peter Boström34fbfff2015-09-24 19:20:30 +0200887 if (verify_playout_) {
888 EXPECT_TRUE(media_channel1_->playout());
889 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200891 if (verify_playout_) {
892 EXPECT_TRUE(media_channel2_->playout());
893 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 EXPECT_TRUE(media_channel2_->sending());
895 }
896
Honghai Zhangcc411c02016-03-29 17:27:21 -0700897 // Tests that when the transport channel signals a candidate pair change
898 // event, the media channel will receive a call on the network route change.
899 void TestNetworkRouteChanges() {
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200900 constexpr uint16_t kLocalNetId = 1;
901 constexpr uint16_t kRemoteNetId = 2;
902 constexpr int kLastPacketId = 100;
903
Honghai Zhangcc411c02016-03-29 17:27:21 -0700904 CreateChannels(0, 0);
905
906 cricket::TransportChannel* transport_channel1 =
907 channel1_->transport_channel();
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200908 ASSERT_TRUE(transport_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700909 typename T::MediaChannel* media_channel1 =
910 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200911 ASSERT_TRUE(media_channel1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700912
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200913 media_channel1->set_num_network_route_changes(0);
914 network_thread_->Invoke<void>([transport_channel1] {
915 // The transport channel becomes disconnected.
916 transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1,
917 nullptr, -1);
918 });
919 WaitForThreads();
920 EXPECT_EQ(1, media_channel1->num_network_route_changes());
Honghai Zhangcc411c02016-03-29 17:27:21 -0700921 EXPECT_FALSE(media_channel1->last_network_route().connected);
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200922 media_channel1->set_num_network_route_changes(0);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700923
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200924 network_thread_->Invoke<void>([this, transport_channel1, media_channel1,
925 kLocalNetId, kRemoteNetId, kLastPacketId] {
926 // The transport channel becomes connected.
927 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
928 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
929 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
930 transport_controller1_->CreateFakeCandidatePair(
931 local_address, kLocalNetId, remote_address, kRemoteNetId));
932 transport_channel1->SignalSelectedCandidatePairChanged(
933 transport_channel1, candidate_pair.get(), kLastPacketId);
934 });
935 WaitForThreads();
936 EXPECT_EQ(1, media_channel1->num_network_route_changes());
937 rtc::NetworkRoute expected_network_route(kLocalNetId, kRemoteNetId,
938 kLastPacketId);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700939 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200940 EXPECT_EQ(kLastPacketId,
Honghai Zhang52dce732016-03-31 12:37:31 -0700941 media_channel1->last_network_route().last_sent_packet_id);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700942 }
943
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 // Test setting up a call.
945 void TestCallSetup() {
946 CreateChannels(0, 0);
947 EXPECT_FALSE(channel1_->secure());
948 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200949 if (verify_playout_) {
950 EXPECT_TRUE(media_channel1_->playout());
951 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 EXPECT_FALSE(media_channel1_->sending());
953 EXPECT_TRUE(SendAccept());
954 EXPECT_FALSE(channel1_->secure());
955 EXPECT_TRUE(media_channel1_->sending());
956 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200957 if (verify_playout_) {
958 EXPECT_TRUE(media_channel2_->playout());
959 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 EXPECT_TRUE(media_channel2_->sending());
961 EXPECT_EQ(1U, media_channel2_->codecs().size());
962 }
963
964 // Test that we don't crash if packets are sent during call teardown
965 // when RTCP mux is enabled. This is a regression test against a specific
966 // race condition that would only occur when a RTCP packet was sent during
967 // teardown of a channel on which RTCP mux was enabled.
968 void TestCallTeardownRtcpMux() {
969 class LastWordMediaChannel : public T::MediaChannel {
970 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200971 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700973 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
974 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
976 }
977 };
978 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200979 RTCP | RTCP_MUX, RTCP | RTCP_MUX);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 EXPECT_TRUE(SendInitiate());
981 EXPECT_TRUE(SendAccept());
982 EXPECT_TRUE(SendTerminate());
983 }
984
985 // Send voice RTP data to the other side and ensure it gets there.
986 void SendRtpToRtp() {
987 CreateChannels(0, 0);
988 EXPECT_TRUE(SendInitiate());
989 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700990 ASSERT_TRUE(GetTransport1());
991 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 EXPECT_EQ(1U, GetTransport1()->channels().size());
993 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +0200994 SendRtp1();
995 SendRtp2();
996 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 EXPECT_TRUE(CheckRtp1());
998 EXPECT_TRUE(CheckRtp2());
999 EXPECT_TRUE(CheckNoRtp1());
1000 EXPECT_TRUE(CheckNoRtp2());
1001 }
1002
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02001003 void TestDeinit() {
1004 CreateChannels(RTCP, RTCP);
1005 EXPECT_TRUE(SendInitiate());
1006 EXPECT_TRUE(SendAccept());
1007 SendRtp1();
1008 SendRtp2();
1009 SendRtcp1();
1010 SendRtcp2();
1011 // Do not wait, destroy channels.
1012 channel1_.reset(nullptr);
1013 channel2_.reset(nullptr);
1014 }
1015
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 // Check that RTCP is not transmitted if both sides don't support RTCP.
1017 void SendNoRtcpToNoRtcp() {
1018 CreateChannels(0, 0);
1019 EXPECT_TRUE(SendInitiate());
1020 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001021 ASSERT_TRUE(GetTransport1());
1022 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001023 EXPECT_EQ(1U, GetTransport1()->channels().size());
1024 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001025 SendRtcp1();
1026 SendRtcp2();
1027 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 EXPECT_TRUE(CheckNoRtcp1());
1029 EXPECT_TRUE(CheckNoRtcp2());
1030 }
1031
1032 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1033 void SendNoRtcpToRtcp() {
1034 CreateChannels(0, RTCP);
1035 EXPECT_TRUE(SendInitiate());
1036 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001037 ASSERT_TRUE(GetTransport1());
1038 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 EXPECT_EQ(1U, GetTransport1()->channels().size());
1040 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001041 SendRtcp1();
1042 SendRtcp2();
1043 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 EXPECT_TRUE(CheckNoRtcp1());
1045 EXPECT_TRUE(CheckNoRtcp2());
1046 }
1047
1048 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1049 void SendRtcpToNoRtcp() {
1050 CreateChannels(RTCP, 0);
1051 EXPECT_TRUE(SendInitiate());
1052 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001053 ASSERT_TRUE(GetTransport1());
1054 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 EXPECT_EQ(2U, GetTransport1()->channels().size());
1056 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001057 SendRtcp1();
1058 SendRtcp2();
1059 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 EXPECT_TRUE(CheckNoRtcp1());
1061 EXPECT_TRUE(CheckNoRtcp2());
1062 }
1063
1064 // Check that RTCP is transmitted if both sides support RTCP.
1065 void SendRtcpToRtcp() {
1066 CreateChannels(RTCP, RTCP);
1067 EXPECT_TRUE(SendInitiate());
1068 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001069 ASSERT_TRUE(GetTransport1());
1070 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 EXPECT_EQ(2U, GetTransport1()->channels().size());
1072 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001073 SendRtcp1();
1074 SendRtcp2();
1075 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 EXPECT_TRUE(CheckRtcp1());
1077 EXPECT_TRUE(CheckRtcp2());
1078 EXPECT_TRUE(CheckNoRtcp1());
1079 EXPECT_TRUE(CheckNoRtcp2());
1080 }
1081
1082 // Check that RTCP is transmitted if only the initiator supports mux.
1083 void SendRtcpMuxToRtcp() {
1084 CreateChannels(RTCP | RTCP_MUX, RTCP);
1085 EXPECT_TRUE(SendInitiate());
1086 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001087 ASSERT_TRUE(GetTransport1());
1088 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 EXPECT_EQ(2U, GetTransport1()->channels().size());
1090 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001091 SendRtcp1();
1092 SendRtcp2();
1093 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 EXPECT_TRUE(CheckRtcp1());
1095 EXPECT_TRUE(CheckRtcp2());
1096 EXPECT_TRUE(CheckNoRtcp1());
1097 EXPECT_TRUE(CheckNoRtcp2());
1098 }
1099
1100 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1101 void SendRtcpMuxToRtcpMux() {
1102 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1103 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001104 ASSERT_TRUE(GetTransport1());
1105 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 EXPECT_EQ(2U, GetTransport1()->channels().size());
1107 EXPECT_EQ(1U, GetTransport2()->channels().size());
1108 EXPECT_TRUE(SendAccept());
1109 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001110 SendRtp1();
1111 SendRtp2();
1112 SendRtcp1();
1113 SendRtcp2();
1114 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 EXPECT_TRUE(CheckRtp1());
1116 EXPECT_TRUE(CheckRtp2());
1117 EXPECT_TRUE(CheckNoRtp1());
1118 EXPECT_TRUE(CheckNoRtp2());
1119 EXPECT_TRUE(CheckRtcp1());
1120 EXPECT_TRUE(CheckRtcp2());
1121 EXPECT_TRUE(CheckNoRtcp1());
1122 EXPECT_TRUE(CheckNoRtcp2());
1123 }
1124
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001125 // Check that RTP and RTCP are transmitted ok when both sides
1126 // support mux and one the offerer requires mux.
1127 void SendRequireRtcpMuxToRtcpMux() {
1128 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1129 channel1_->ActivateRtcpMux();
1130 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001131 ASSERT_TRUE(GetTransport1());
1132 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001133 EXPECT_EQ(1U, GetTransport1()->channels().size());
1134 EXPECT_EQ(1U, GetTransport2()->channels().size());
1135 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001136 SendRtp1();
1137 SendRtp2();
1138 SendRtcp1();
1139 SendRtcp2();
1140 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001141 EXPECT_TRUE(CheckRtp1());
1142 EXPECT_TRUE(CheckRtp2());
1143 EXPECT_TRUE(CheckNoRtp1());
1144 EXPECT_TRUE(CheckNoRtp2());
1145 EXPECT_TRUE(CheckRtcp1());
1146 EXPECT_TRUE(CheckRtcp2());
1147 EXPECT_TRUE(CheckNoRtcp1());
1148 EXPECT_TRUE(CheckNoRtcp2());
1149 }
1150
1151 // Check that RTP and RTCP are transmitted ok when both sides
1152 // support mux and one the answerer requires rtcp mux.
1153 void SendRtcpMuxToRequireRtcpMux() {
1154 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1155 channel2_->ActivateRtcpMux();
1156 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001157 ASSERT_TRUE(GetTransport1());
1158 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001159 EXPECT_EQ(2U, GetTransport1()->channels().size());
1160 EXPECT_EQ(1U, GetTransport2()->channels().size());
1161 EXPECT_TRUE(SendAccept());
1162 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001163 SendRtp1();
1164 SendRtp2();
1165 SendRtcp1();
1166 SendRtcp2();
1167 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001168 EXPECT_TRUE(CheckRtp1());
1169 EXPECT_TRUE(CheckRtp2());
1170 EXPECT_TRUE(CheckNoRtp1());
1171 EXPECT_TRUE(CheckNoRtp2());
1172 EXPECT_TRUE(CheckRtcp1());
1173 EXPECT_TRUE(CheckRtcp2());
1174 EXPECT_TRUE(CheckNoRtcp1());
1175 EXPECT_TRUE(CheckNoRtcp2());
1176 }
1177
1178 // Check that RTP and RTCP are transmitted ok when both sides
1179 // require mux.
1180 void SendRequireRtcpMuxToRequireRtcpMux() {
1181 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1182 channel1_->ActivateRtcpMux();
1183 channel2_->ActivateRtcpMux();
1184 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001185 ASSERT_TRUE(GetTransport1());
1186 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001187 EXPECT_EQ(1U, GetTransport1()->channels().size());
1188 EXPECT_EQ(1U, GetTransport2()->channels().size());
1189 EXPECT_TRUE(SendAccept());
1190 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001191 SendRtp1();
1192 SendRtp2();
1193 SendRtcp1();
1194 SendRtcp2();
1195 WaitForThreads();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001196 EXPECT_TRUE(CheckRtp1());
1197 EXPECT_TRUE(CheckRtp2());
1198 EXPECT_TRUE(CheckNoRtp1());
1199 EXPECT_TRUE(CheckNoRtp2());
1200 EXPECT_TRUE(CheckRtcp1());
1201 EXPECT_TRUE(CheckRtcp2());
1202 EXPECT_TRUE(CheckNoRtcp1());
1203 EXPECT_TRUE(CheckNoRtcp2());
1204 }
1205
1206 // Check that SendAccept fails if the answerer doesn't support mux
1207 // and the offerer requires it.
1208 void SendRequireRtcpMuxToNoRtcpMux() {
1209 CreateChannels(RTCP | RTCP_MUX, RTCP);
1210 channel1_->ActivateRtcpMux();
1211 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001212 ASSERT_TRUE(GetTransport1());
1213 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001214 EXPECT_EQ(1U, GetTransport1()->channels().size());
1215 EXPECT_EQ(2U, GetTransport2()->channels().size());
1216 EXPECT_FALSE(SendAccept());
1217 }
1218
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 // Check that RTCP data sent by the initiator before the accept is not muxed.
1220 void SendEarlyRtcpMuxToRtcp() {
1221 CreateChannels(RTCP | RTCP_MUX, RTCP);
1222 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001223 ASSERT_TRUE(GetTransport1());
1224 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 EXPECT_EQ(2U, GetTransport1()->channels().size());
1226 EXPECT_EQ(2U, GetTransport2()->channels().size());
1227
1228 // RTCP can be sent before the call is accepted, if the transport is ready.
1229 // It should not be muxed though, as the remote side doesn't support mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001230 SendRtcp1();
1231 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 EXPECT_TRUE(CheckNoRtp2());
1233 EXPECT_TRUE(CheckRtcp2());
1234
1235 // Send RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001236 SendRtcp2();
1237 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 EXPECT_TRUE(CheckNoRtp1());
1239 EXPECT_TRUE(CheckRtcp1());
1240
1241 // Complete call setup and ensure everything is still OK.
1242 EXPECT_TRUE(SendAccept());
1243 EXPECT_EQ(2U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001244 SendRtcp1();
1245 SendRtcp2();
1246 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001247 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248 EXPECT_TRUE(CheckRtcp1());
1249 }
1250
1251
1252 // Check that RTCP data is not muxed until both sides have enabled muxing,
1253 // but that we properly demux before we get the accept message, since there
1254 // is a race between RTP data and the jingle accept.
1255 void SendEarlyRtcpMuxToRtcpMux() {
1256 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1257 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001258 ASSERT_TRUE(GetTransport1());
1259 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260 EXPECT_EQ(2U, GetTransport1()->channels().size());
1261 EXPECT_EQ(1U, GetTransport2()->channels().size());
1262
1263 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1264 // we haven't yet received the accept that says we should mux.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001265 SendRtcp1();
1266 WaitForThreads();
1267 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268
1269 // Send muxed RTCP packet from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001270 SendRtcp2();
1271 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 EXPECT_TRUE(CheckNoRtp1());
1273 EXPECT_TRUE(CheckRtcp1());
1274
1275 // Complete call setup and ensure everything is still OK.
1276 EXPECT_TRUE(SendAccept());
1277 EXPECT_EQ(1U, GetTransport1()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001278 SendRtcp1();
1279 SendRtcp2();
1280 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001281 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 EXPECT_TRUE(CheckRtcp1());
1283 }
1284
1285 // Test that we properly send SRTP with RTCP in both directions.
1286 // You can pass in DTLS and/or RTCP_MUX as flags.
1287 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1288 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1289 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1290
1291 int flags1 = RTCP | SECURE | flags1_in;
1292 int flags2 = RTCP | SECURE | flags2_in;
1293 bool dtls1 = !!(flags1_in & DTLS);
1294 bool dtls2 = !!(flags2_in & DTLS);
1295 CreateChannels(flags1, flags2);
1296 EXPECT_FALSE(channel1_->secure());
1297 EXPECT_FALSE(channel2_->secure());
1298 EXPECT_TRUE(SendInitiate());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001299 WaitForThreads();
1300 EXPECT_TRUE(channel1_->writable());
1301 EXPECT_TRUE(channel2_->writable());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 EXPECT_TRUE(SendAccept());
1303 EXPECT_TRUE(channel1_->secure());
1304 EXPECT_TRUE(channel2_->secure());
1305 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1306 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001307 SendRtp1();
1308 SendRtp2();
1309 SendRtcp1();
1310 SendRtcp2();
1311 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 EXPECT_TRUE(CheckRtp1());
1313 EXPECT_TRUE(CheckRtp2());
1314 EXPECT_TRUE(CheckNoRtp1());
1315 EXPECT_TRUE(CheckNoRtp2());
1316 EXPECT_TRUE(CheckRtcp1());
1317 EXPECT_TRUE(CheckRtcp2());
1318 EXPECT_TRUE(CheckNoRtcp1());
1319 EXPECT_TRUE(CheckNoRtcp2());
1320 }
1321
1322 // Test that we properly handling SRTP negotiating down to RTP.
1323 void SendSrtpToRtp() {
1324 CreateChannels(RTCP | SECURE, RTCP);
1325 EXPECT_FALSE(channel1_->secure());
1326 EXPECT_FALSE(channel2_->secure());
1327 EXPECT_TRUE(SendInitiate());
1328 EXPECT_TRUE(SendAccept());
1329 EXPECT_FALSE(channel1_->secure());
1330 EXPECT_FALSE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001331 SendRtp1();
1332 SendRtp2();
1333 SendRtcp1();
1334 SendRtcp2();
1335 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001336 EXPECT_TRUE(CheckRtp1());
1337 EXPECT_TRUE(CheckRtp2());
1338 EXPECT_TRUE(CheckNoRtp1());
1339 EXPECT_TRUE(CheckNoRtp2());
1340 EXPECT_TRUE(CheckRtcp1());
1341 EXPECT_TRUE(CheckRtcp2());
1342 EXPECT_TRUE(CheckNoRtcp1());
1343 EXPECT_TRUE(CheckNoRtcp2());
1344 }
1345
1346 // Test that we can send and receive early media when a provisional answer is
1347 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1348 void SendEarlyMediaUsingRtcpMuxSrtp() {
1349 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1350
1351 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1352 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1353 EXPECT_TRUE(SendOffer());
1354 EXPECT_TRUE(SendProvisionalAnswer());
1355 EXPECT_TRUE(channel1_->secure());
1356 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001357 ASSERT_TRUE(GetTransport1());
1358 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 EXPECT_EQ(2U, GetTransport1()->channels().size());
1360 EXPECT_EQ(2U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001361 WaitForThreads(); // Wait for 'sending' flag go through network thread.
1362 SendCustomRtcp1(kSsrc1);
1363 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1364 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1367
1368 // Send packets from callee and verify that it is received.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001369 SendCustomRtcp2(kSsrc2);
1370 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1371 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1374
1375 // Complete call setup and ensure everything is still OK.
1376 EXPECT_TRUE(SendFinalAnswer());
1377 EXPECT_EQ(1U, GetTransport1()->channels().size());
1378 EXPECT_EQ(1U, GetTransport2()->channels().size());
1379 EXPECT_TRUE(channel1_->secure());
1380 EXPECT_TRUE(channel2_->secure());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001381 SendCustomRtcp1(kSsrc1);
1382 SendCustomRtp1(kSsrc1, ++sequence_number1_1);
1383 SendCustomRtcp2(kSsrc2);
1384 SendCustomRtp2(kSsrc2, ++sequence_number2_2);
1385 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001387 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1390 }
1391
1392 // Test that we properly send RTP without SRTP from a thread.
1393 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001394 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 EXPECT_TRUE(SendInitiate());
1396 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001397 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1398 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1399 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1400 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1401 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1402 send_rtcp1.thread(),
1403 send_rtcp2.thread()};
1404 WaitForThreads(involved_threads);
1405 EXPECT_TRUE(CheckRtp1());
1406 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 EXPECT_TRUE(CheckNoRtp1());
1408 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001409 EXPECT_TRUE(CheckRtcp1());
1410 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411 EXPECT_TRUE(CheckNoRtcp1());
1412 EXPECT_TRUE(CheckNoRtcp2());
1413 }
1414
1415 // Test that we properly send SRTP with RTCP from a thread.
1416 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1418 EXPECT_TRUE(SendInitiate());
1419 EXPECT_TRUE(SendAccept());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001420 ScopedCallThread send_rtp1([this] { SendRtp1(); });
1421 ScopedCallThread send_rtp2([this] { SendRtp2(); });
1422 ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
1423 ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
1424 rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
1425 send_rtcp1.thread(),
1426 send_rtcp2.thread()};
1427 WaitForThreads(involved_threads);
1428 EXPECT_TRUE(CheckRtp1());
1429 EXPECT_TRUE(CheckRtp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 EXPECT_TRUE(CheckNoRtp1());
1431 EXPECT_TRUE(CheckNoRtp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001432 EXPECT_TRUE(CheckRtcp1());
1433 EXPECT_TRUE(CheckRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 EXPECT_TRUE(CheckNoRtcp1());
1435 EXPECT_TRUE(CheckNoRtcp2());
1436 }
1437
1438 // Test that the mediachannel retains its sending state after the transport
1439 // becomes non-writable.
1440 void SendWithWritabilityLoss() {
1441 CreateChannels(0, 0);
1442 EXPECT_TRUE(SendInitiate());
1443 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001444 ASSERT_TRUE(GetTransport1());
1445 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 EXPECT_EQ(1U, GetTransport1()->channels().size());
1447 EXPECT_EQ(1U, GetTransport2()->channels().size());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001448 SendRtp1();
1449 SendRtp2();
1450 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 EXPECT_TRUE(CheckRtp1());
1452 EXPECT_TRUE(CheckRtp2());
1453 EXPECT_TRUE(CheckNoRtp1());
1454 EXPECT_TRUE(CheckNoRtp2());
1455
wu@webrtc.org97077a32013-10-25 21:18:33 +00001456 // Lose writability, which should fail.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001457 network_thread_->Invoke<void>(
1458 [this] { GetTransport1()->SetWritable(false); });
1459 SendRtp1();
1460 SendRtp2();
1461 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_TRUE(CheckRtp1());
1463 EXPECT_TRUE(CheckNoRtp2());
1464
1465 // Regain writability
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001466 network_thread_->Invoke<void>(
1467 [this] { GetTransport1()->SetWritable(true); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 EXPECT_TRUE(media_channel1_->sending());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001469 SendRtp1();
1470 SendRtp2();
1471 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 EXPECT_TRUE(CheckRtp1());
1473 EXPECT_TRUE(CheckRtp2());
1474 EXPECT_TRUE(CheckNoRtp1());
1475 EXPECT_TRUE(CheckNoRtp2());
1476
1477 // Lose writability completely
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001478 network_thread_->Invoke<void>(
1479 [this] { GetTransport1()->SetDestination(NULL); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001480 EXPECT_TRUE(media_channel1_->sending());
1481
wu@webrtc.org97077a32013-10-25 21:18:33 +00001482 // Should fail also.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001483 SendRtp1();
1484 SendRtp2();
1485 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486 EXPECT_TRUE(CheckRtp1());
1487 EXPECT_TRUE(CheckNoRtp2());
1488
1489 // Gain writability back
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001490 network_thread_->Invoke<void>(
1491 [this] { GetTransport1()->SetDestination(GetTransport2()); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 EXPECT_TRUE(media_channel1_->sending());
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(CheckRtp2());
1498 EXPECT_TRUE(CheckNoRtp1());
1499 EXPECT_TRUE(CheckNoRtp2());
1500 }
1501
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001502 void SendBundleToBundle(
1503 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1504 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001505 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001506 // Only pl_type1 was added to the bundle filter for both |channel1_|
1507 // and |channel2_|.
1508 int pl_type1 = pl_types[0];
1509 int pl_type2 = pl_types[1];
1510 int flags = SSRC_MUX | RTCP;
1511 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001512 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001513 if (rtcp_mux) {
1514 flags |= RTCP_MUX;
1515 expected_channels = 1U;
1516 }
1517 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001519 ASSERT_TRUE(GetTransport1());
1520 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001521 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001522 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001524 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1525 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1526 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1527 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1528 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1529 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001530
1531 // Both channels can receive pl_type1 only.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001532 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
1533 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
1534 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001535 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001536 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1537 EXPECT_TRUE(CheckNoRtp1());
1538 EXPECT_TRUE(CheckNoRtp2());
1539
1540 // RTCP test
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001541 SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
1542 SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
1543 WaitForThreads();
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001544 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001545 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1546
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001547 SendCustomRtcp1(kSsrc1);
1548 SendCustomRtcp2(kSsrc2);
1549 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1551 EXPECT_TRUE(CheckNoRtcp1());
1552 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1553 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001555 SendCustomRtcp1(kSsrc2);
1556 SendCustomRtcp2(kSsrc1);
1557 WaitForThreads();
pbos482b12e2015-11-16 10:19:58 -08001558 // Bundle filter shouldn't filter out any RTCP.
1559 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1560 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 }
1562
1563 // Test that the media monitor can be run and gives timely callbacks.
1564 void TestMediaMonitor() {
1565 static const int kTimeout = 500;
1566 CreateChannels(0, 0);
1567 EXPECT_TRUE(SendInitiate());
1568 EXPECT_TRUE(SendAccept());
1569 channel1_->StartMediaMonitor(100);
1570 channel2_->StartMediaMonitor(100);
1571 // Ensure we get callbacks and stop.
1572 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1573 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1574 channel1_->StopMediaMonitor();
1575 channel2_->StopMediaMonitor();
1576 // Ensure a restart of a stopped monitor works.
1577 channel1_->StartMediaMonitor(100);
1578 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1579 channel1_->StopMediaMonitor();
1580 // Ensure stopping a stopped monitor is OK.
1581 channel1_->StopMediaMonitor();
1582 }
1583
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 void TestSetContentFailure() {
1585 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586
Peter Thatchera6d24442015-07-09 21:26:36 -07001587 auto sdesc = cricket::SessionDescription();
1588 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1589 new cricket::AudioContentDescription());
1590 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1591 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592
Peter Thatchera6d24442015-07-09 21:26:36 -07001593 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001595 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1596 &sdesc, cricket::CA_OFFER, &err));
1597 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1598 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001601 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1602 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001604 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1605 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 }
1607
1608 void TestSendTwoOffers() {
1609 CreateChannels(0, 0);
1610
Peter Thatchera6d24442015-07-09 21:26:36 -07001611 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001612 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001613 CreateSessionDescriptionWithStream(1));
1614 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1615 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1617
kwiberg31022942016-03-11 14:18:21 -08001618 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001619 CreateSessionDescriptionWithStream(2));
1620 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1621 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1623 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1624 }
1625
1626 void TestReceiveTwoOffers() {
1627 CreateChannels(0, 0);
1628
Peter Thatchera6d24442015-07-09 21:26:36 -07001629 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001630 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001631 CreateSessionDescriptionWithStream(1));
1632 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1633 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1635
kwiberg31022942016-03-11 14:18:21 -08001636 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001637 CreateSessionDescriptionWithStream(2));
1638 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1639 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1641 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1642 }
1643
1644 void TestSendPrAnswer() {
1645 CreateChannels(0, 0);
1646
Peter Thatchera6d24442015-07-09 21:26:36 -07001647 std::string err;
1648 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001649 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001650 CreateSessionDescriptionWithStream(1));
1651 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1652 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1654
Peter Thatchera6d24442015-07-09 21:26:36 -07001655 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001656 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001657 CreateSessionDescriptionWithStream(2));
1658 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1659 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1661 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1662
Peter Thatchera6d24442015-07-09 21:26:36 -07001663 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001664 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001665 CreateSessionDescriptionWithStream(3));
1666 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1667 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1669 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1670 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1671 }
1672
1673 void TestReceivePrAnswer() {
1674 CreateChannels(0, 0);
1675
Peter Thatchera6d24442015-07-09 21:26:36 -07001676 std::string err;
1677 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001678 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001679 CreateSessionDescriptionWithStream(1));
1680 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1681 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1683
Peter Thatchera6d24442015-07-09 21:26:36 -07001684 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001685 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001686 CreateSessionDescriptionWithStream(2));
1687 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1688 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1690 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1691
Peter Thatchera6d24442015-07-09 21:26:36 -07001692 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001693 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001694 CreateSessionDescriptionWithStream(3));
1695 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1696 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1698 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1699 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1700 }
1701
1702 void TestFlushRtcp() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 CreateChannels(RTCP, RTCP);
1704 EXPECT_TRUE(SendInitiate());
1705 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001706 ASSERT_TRUE(GetTransport1());
1707 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 EXPECT_EQ(2U, GetTransport1()->channels().size());
1709 EXPECT_EQ(2U, GetTransport2()->channels().size());
1710
1711 // Send RTCP1 from a different thread.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001712 ScopedCallThread send_rtcp([this] { SendRtcp1(); });
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 // The sending message is only posted. channel2_ should be empty.
1714 EXPECT_TRUE(CheckNoRtcp2());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001715 rtc::Thread* wait_for[] = {send_rtcp.thread()};
1716 WaitForThreads(wait_for); // Ensure rtcp was posted
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717
1718 // When channel1_ is deleted, the RTCP packet should be sent out to
1719 // channel2_.
1720 channel1_.reset();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001721 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 EXPECT_TRUE(CheckRtcp2());
1723 }
1724
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001725 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001726 struct SrtpErrorHandler : public sigslot::has_slots<> {
1727 SrtpErrorHandler() :
1728 mode_(cricket::SrtpFilter::UNPROTECT),
1729 error_(cricket::SrtpFilter::ERROR_NONE) {}
1730 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1731 cricket::SrtpFilter::Error error) {
1732 mode_ = mode;
1733 error_ = error;
1734 }
1735 cricket::SrtpFilter::Mode mode_;
1736 cricket::SrtpFilter::Error error_;
1737 } error_handler;
1738
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001739 // For Audio, only pl_type 0 is added to the bundle filter.
1740 // For Video, only pl_type 97 is added to the bundle filter.
1741 // So we need to pass in pl_type so that the packet can pass through
1742 // the bundle filter before it can be processed by the srtp filter.
1743 // The packet is not a valid srtp packet because it is too short.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001744 static unsigned const char kBadPacket[] = {
1745 0x84, static_cast<unsigned char>(pl_type),
1746 0x00, 0x01,
1747 0x00, 0x00,
1748 0x00, 0x00,
1749 0x00, 0x00,
1750 0x00, 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1752 EXPECT_FALSE(channel1_->secure());
1753 EXPECT_FALSE(channel2_->secure());
1754 EXPECT_TRUE(SendInitiate());
1755 EXPECT_TRUE(SendAccept());
1756 EXPECT_TRUE(channel1_->secure());
1757 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001758 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001759 channel2_->srtp_filter()->SignalSrtpError.connect(
1760 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761
1762 // Testing failures in sending packets.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001763 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1764 rtc::PacketOptions());
1765 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 // The first failure will trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001767 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001768 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1769 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001770 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1771 // The next 250 ms failures will not trigger an error.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001772 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1773 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 // Wait for a while to ensure no message comes in.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001775 WaitForThreads();
solenberg5629a1d2015-10-01 08:45:57 -07001776 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001777 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001778 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1779 // Wait for a little more - the error will be triggered again.
1780 rtc::Thread::Current()->ProcessMessages(200);
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001781 media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1782 rtc::PacketOptions());
1783 WaitForThreads();
1784 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001785 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786
1787 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001788 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001789 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001790
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001791 network_thread_->Invoke<void>([this] {
1792 cricket::TransportChannel* transport_channel =
1793 channel2_->transport_channel();
1794 transport_channel->SignalReadPacket(
1795 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1796 sizeof(kBadPacket), rtc::PacketTime(), 0);
1797 });
1798 EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
solenberg5b14b422015-10-01 04:10:31 -07001799 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 }
1801
1802 void TestOnReadyToSend() {
1803 CreateChannels(RTCP, RTCP);
1804 TransportChannel* rtp = channel1_->transport_channel();
1805 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1806 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001807
1808 network_thread_->Invoke<void>([rtp] { rtp->SignalReadyToSend(rtp); });
1809 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001811
1812 network_thread_->Invoke<void>([rtcp] { rtcp->SignalReadyToSend(rtcp); });
1813 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1815 // channel are ready to send.
1816 EXPECT_TRUE(media_channel1_->ready_to_send());
1817
1818 // rtp channel becomes not ready to send will be propagated to mediachannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001819 network_thread_->Invoke<void>(
1820 [this] { channel1_->SetReadyToSend(false, false); });
1821 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001823
1824 network_thread_->Invoke<void>(
1825 [this] { channel1_->SetReadyToSend(false, true); });
1826 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827 EXPECT_TRUE(media_channel1_->ready_to_send());
1828
1829 // rtcp channel becomes not ready to send will be propagated to mediachannel
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001830 network_thread_->Invoke<void>(
1831 [this] { channel1_->SetReadyToSend(true, false); });
1832 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 EXPECT_FALSE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001834
1835 network_thread_->Invoke<void>(
1836 [this] { channel1_->SetReadyToSend(true, true); });
1837 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 EXPECT_TRUE(media_channel1_->ready_to_send());
1839 }
1840
1841 void TestOnReadyToSendWithRtcpMux() {
1842 CreateChannels(RTCP, RTCP);
1843 typename T::Content content;
1844 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1845 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1846 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001847 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1848 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1850 TransportChannel* rtp = channel1_->transport_channel();
1851 EXPECT_FALSE(media_channel1_->ready_to_send());
1852 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1853 // should trigger the MediaChannel's OnReadyToSend.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001854 network_thread_->Invoke<void>([rtp] { rtp->SignalReadyToSend(rtp); });
1855 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 EXPECT_TRUE(media_channel1_->ready_to_send());
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001857
1858 network_thread_->Invoke<void>(
1859 [this] { channel1_->SetReadyToSend(false, false); });
1860 WaitForThreads();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 EXPECT_FALSE(media_channel1_->ready_to_send());
1862 }
1863
skvladdc1c62c2016-03-16 19:07:43 -07001864 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1865 typename T::Content content;
1866 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1867 content.set_bandwidth(remote_limit);
1868 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1869 }
1870
1871 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1872 webrtc::RtpParameters parameters;
1873 webrtc::RtpEncodingParameters encoding;
1874 encoding.max_bitrate_bps = limit;
1875 parameters.encodings.push_back(encoding);
1876 return parameters;
1877 }
1878
1879 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1880 int expected_bitrate) {
1881 EXPECT_EQ(1UL, parameters.encodings.size());
1882 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1883 }
1884
1885 void DefaultMaxBitrateIsUnlimited() {
1886 CreateChannels(0, 0);
1887 EXPECT_TRUE(
1888 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1889 EXPECT_EQ(media_channel1_->max_bps(), -1);
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001890 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001891 }
1892
1893 void CanChangeMaxBitrate() {
1894 CreateChannels(0, 0);
1895 EXPECT_TRUE(
1896 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1897
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001898 EXPECT_TRUE(channel1_->SetRtpSendParameters(
1899 kSsrc1, BitrateLimitedParameters(1000)));
1900 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), 1000);
1901 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), 1000);
skvladdc1c62c2016-03-16 19:07:43 -07001902 EXPECT_EQ(-1, media_channel1_->max_bps());
1903
1904 EXPECT_TRUE(
Taylor Brandstetterdb0cd9e2016-05-16 11:40:30 -07001905 channel1_->SetRtpSendParameters(kSsrc1, BitrateLimitedParameters(-1)));
1906 VerifyMaxBitrate(channel1_->GetRtpSendParameters(kSsrc1), -1);
1907 VerifyMaxBitrate(media_channel1_->GetRtpSendParameters(kSsrc1), -1);
skvladdc1c62c2016-03-16 19:07:43 -07001908 EXPECT_EQ(-1, media_channel1_->max_bps());
1909 }
1910
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 protected:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001912 void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
1913 static void ProcessThreadQueue(rtc::Thread* thread) {
1914 RTC_DCHECK(thread->IsCurrent());
1915 while (!thread->empty()) {
1916 thread->ProcessMessages(0);
1917 }
1918 }
1919 void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
1920 // |threads| and current thread post packets to network thread.
1921 for (rtc::Thread* thread : threads) {
1922 thread->Invoke<void>([thread] { ProcessThreadQueue(thread); });
1923 }
1924 ProcessThreadQueue(rtc::Thread::Current());
1925 // Network thread move them around and post back to worker = current thread.
1926 if (!network_thread_->IsCurrent()) {
1927 network_thread_->Invoke<void>(
1928 [this] { ProcessThreadQueue(network_thread_); });
1929 }
1930 // Worker thread = current Thread process received messages.
1931 ProcessThreadQueue(rtc::Thread::Current());
1932 }
Peter Boström34fbfff2015-09-24 19:20:30 +02001933 // TODO(pbos): Remove playout from all media channels and let renderers mute
1934 // themselves.
1935 const bool verify_playout_;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001936 std::unique_ptr<rtc::Thread> network_thread_keeper_;
1937 rtc::Thread* network_thread_;
1938 std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
1939 std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 cricket::FakeMediaEngine media_engine_;
1941 // The media channels are owned by the voice channel objects below.
1942 typename T::MediaChannel* media_channel1_;
1943 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001944 std::unique_ptr<typename T::Channel> channel1_;
1945 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 typename T::Content local_media_content1_;
1947 typename T::Content local_media_content2_;
1948 typename T::Content remote_media_content1_;
1949 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 // The RTP and RTCP packets to send in the tests.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001951 rtc::Buffer rtp_packet_;
1952 rtc::Buffer rtcp_packet_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001953 int media_info_callbacks1_;
1954 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001955 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956};
1957
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958template<>
1959void ChannelTest<VoiceTraits>::CreateContent(
1960 int flags,
1961 const cricket::AudioCodec& audio_codec,
1962 const cricket::VideoCodec& video_codec,
1963 cricket::AudioContentDescription* audio) {
1964 audio->AddCodec(audio_codec);
1965 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1966 if (flags & SECURE) {
1967 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001968 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1969 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 }
1971}
1972
1973template<>
1974void ChannelTest<VoiceTraits>::CopyContent(
1975 const cricket::AudioContentDescription& source,
1976 cricket::AudioContentDescription* audio) {
1977 *audio = source;
1978}
1979
1980template<>
1981bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1982 const cricket::AudioCodec& c2) {
1983 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1984 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1985}
1986
Peter Boström0c4e06b2015-10-07 12:23:21 +02001987template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001989 uint32_t ssrc,
1990 int flags,
1991 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 audio->AddLegacyStream(ssrc);
1993}
1994
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001995class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 public:
solenberg1dd98f32015-09-10 01:57:14 -07001997 typedef ChannelTest<VoiceTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001998 VoiceChannelSingleThreadTest()
1999 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
2000};
2001
2002class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
2003 public:
2004 typedef ChannelTest<VoiceTraits> Base;
2005 VoiceChannelDoubleThreadTest()
2006 : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007};
2008
2009// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07002010template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002011cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002012 rtc::Thread* worker_thread,
2013 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07002014 cricket::MediaEngineInterface* engine,
2015 cricket::FakeVideoMediaChannel* ch,
2016 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002018 cricket::VideoChannel* channel =
2019 new cricket::VideoChannel(worker_thread, network_thread, ch,
2020 transport_controller, cricket::CN_VIDEO, rtcp);
2021 if (!channel->Init_w()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 delete channel;
2023 channel = NULL;
2024 }
2025 return channel;
2026}
2027
2028// override to add 0 parameter
2029template<>
2030bool ChannelTest<VideoTraits>::AddStream1(int id) {
2031 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2032}
2033
2034template<>
2035void ChannelTest<VideoTraits>::CreateContent(
2036 int flags,
2037 const cricket::AudioCodec& audio_codec,
2038 const cricket::VideoCodec& video_codec,
2039 cricket::VideoContentDescription* video) {
2040 video->AddCodec(video_codec);
2041 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2042 if (flags & SECURE) {
2043 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002044 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2045 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 }
2047}
2048
2049template<>
2050void ChannelTest<VideoTraits>::CopyContent(
2051 const cricket::VideoContentDescription& source,
2052 cricket::VideoContentDescription* video) {
2053 *video = source;
2054}
2055
2056template<>
2057bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2058 const cricket::VideoCodec& c2) {
2059 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2060 c1.framerate == c2.framerate;
2061}
2062
Peter Boström0c4e06b2015-10-07 12:23:21 +02002063template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002065 uint32_t ssrc,
2066 int flags,
2067 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 video->AddLegacyStream(ssrc);
2069}
2070
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002071class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 public:
solenberg1dd98f32015-09-10 01:57:14 -07002073 typedef ChannelTest<VideoTraits> Base;
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002074 VideoChannelSingleThreadTest()
2075 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076};
2077
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002078class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
2079 public:
2080 typedef ChannelTest<VideoTraits> Base;
2081 VideoChannelDoubleThreadTest()
2082 : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
2083};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002085// VoiceChannelSingleThreadTest
2086TEST_F(VoiceChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 Base::TestInit();
2088 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2089 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2090}
2091
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002092TEST_F(VoiceChannelSingleThreadTest, TestDeinit) {
2093 Base::TestDeinit();
2094}
2095
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002096TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 Base::TestSetContents();
2098}
2099
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002100TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 Base::TestSetContentsNullOffer();
2102}
2103
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002104TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 Base::TestSetContentsRtcpMux();
2106}
2107
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002108TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 Base::TestSetContentsRtcpMux();
2110}
2111
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002112TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 Base::TestSetRemoteContentUpdate();
2114}
2115
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002116TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 Base::TestStreams();
2118}
2119
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002120TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 Base::TestUpdateStreamsInLocalContent();
2122}
2123
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002124TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 Base::TestUpdateStreamsInRemoteContent();
2126}
2127
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002128TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 Base::TestChangeStreamParamsInContent();
2130}
2131
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002132TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 Base::TestPlayoutAndSendingStates();
2134}
2135
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002136TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002137 CreateChannels(0, 0);
2138 // Test that we can Mute the default channel even though the sending SSRC
2139 // is unknown.
2140 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002141 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002142 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2143 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002144 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2145
2146 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002147 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002148
2149 SendInitiate();
2150 // After the local session description has been set, we can mute a stream
2151 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002152 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002153 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2154 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002155 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156}
2157
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002158TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 Base::TestMediaContentDirection();
2160}
2161
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002162TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002163 Base::TestNetworkRouteChanges();
2164}
2165
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002166TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 Base::TestCallSetup();
2168}
2169
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002170TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 Base::TestCallTeardownRtcpMux();
2172}
2173
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002174TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 Base::SendRtpToRtp();
2176}
2177
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002178TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 Base::SendNoRtcpToNoRtcp();
2180}
2181
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002182TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 Base::SendNoRtcpToRtcp();
2184}
2185
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002186TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 Base::SendRtcpToNoRtcp();
2188}
2189
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002190TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 Base::SendRtcpToRtcp();
2192}
2193
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002194TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195 Base::SendRtcpMuxToRtcp();
2196}
2197
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002198TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 Base::SendRtcpMuxToRtcpMux();
2200}
2201
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002202TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002203 Base::SendRequireRtcpMuxToRtcpMux();
2204}
2205
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002206TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002207 Base::SendRtcpMuxToRequireRtcpMux();
2208}
2209
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002210TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002211 Base::SendRequireRtcpMuxToRequireRtcpMux();
2212}
2213
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002214TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002215 Base::SendRequireRtcpMuxToNoRtcpMux();
2216}
2217
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002218TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 Base::SendEarlyRtcpMuxToRtcp();
2220}
2221
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002222TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 Base::SendEarlyRtcpMuxToRtcpMux();
2224}
2225
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002226TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2228}
2229
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002230TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 Base::SendSrtpToSrtp();
2232}
2233
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002234TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2236}
2237
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002238TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2240 Base::SendSrtpToSrtp(DTLS, 0);
2241}
2242
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002243TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2245 Base::SendSrtpToSrtp(DTLS, DTLS);
2246}
2247
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002248TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2250 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2251}
2252
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002253TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2255}
2256
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002257TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 Base::SendRtpToRtpOnThread();
2259}
2260
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002261TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 Base::SendSrtpToSrtpOnThread();
2263}
2264
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002265TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 Base::SendWithWritabilityLoss();
2267}
2268
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002269TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270 Base::TestMediaMonitor();
2271}
2272
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273// Test that InsertDtmf properly forwards to the media channel.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002274TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 CreateChannels(0, 0);
2276 EXPECT_TRUE(SendInitiate());
2277 EXPECT_TRUE(SendAccept());
2278 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2279
solenberg1d63dd02015-12-02 12:35:09 -08002280 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2281 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2282 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002284 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002285 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002286 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002287 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002288 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002289 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002290 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291}
2292
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002293TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 Base::TestSetContentFailure();
2295}
2296
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002297TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 Base::TestSendTwoOffers();
2299}
2300
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002301TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 Base::TestReceiveTwoOffers();
2303}
2304
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002305TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 Base::TestSendPrAnswer();
2307}
2308
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002309TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 Base::TestReceivePrAnswer();
2311}
2312
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002313TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 Base::TestFlushRtcp();
2315}
2316
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002317TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002318 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319}
2320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002321TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 Base::TestOnReadyToSend();
2323}
2324
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002325TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 Base::TestOnReadyToSendWithRtcpMux();
2327}
2328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329// Test that we can scale the output volume properly for 1:1 calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002330TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 CreateChannels(RTCP, RTCP);
2332 EXPECT_TRUE(SendInitiate());
2333 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002334 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335
solenberg4bac9c52015-10-09 02:32:53 -07002336 // Default is (1.0).
2337 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2338 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002339 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002340 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341
solenberg4bac9c52015-10-09 02:32:53 -07002342 // Set scale to (1.5).
2343 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2344 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2345 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346
solenberg4bac9c52015-10-09 02:32:53 -07002347 // Set scale to (0).
2348 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2349 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2350 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351}
2352
2353// Test that we can scale the output volume properly for multiway calls.
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002354TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 CreateChannels(RTCP, RTCP);
2356 EXPECT_TRUE(SendInitiate());
2357 EXPECT_TRUE(SendAccept());
2358 EXPECT_TRUE(AddStream1(1));
2359 EXPECT_TRUE(AddStream1(2));
2360
solenberg4bac9c52015-10-09 02:32:53 -07002361 double volume;
2362 // Default is (1.0).
2363 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2364 EXPECT_DOUBLE_EQ(1.0, volume);
2365 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2366 EXPECT_DOUBLE_EQ(1.0, volume);
2367 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2368 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002370 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371
solenberg4bac9c52015-10-09 02:32:53 -07002372 // Set scale to (1.5) for ssrc = 1.
2373 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2374 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2375 EXPECT_DOUBLE_EQ(1.5, volume);
2376 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2377 EXPECT_DOUBLE_EQ(1.0, volume);
2378 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2379 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380
solenberg4bac9c52015-10-09 02:32:53 -07002381 // Set scale to (0) for all ssrcs.
2382 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2383 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2384 EXPECT_DOUBLE_EQ(0.0, volume);
2385 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2386 EXPECT_DOUBLE_EQ(0.0, volume);
2387 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2388 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389}
2390
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002391TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002392 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393}
2394
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002395TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002396 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002397}
2398
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002399TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002400 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002401}
2402
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002403TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002404 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405}
2406
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002407TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvlade0d46372016-04-07 22:59:22 -07002408 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002409}
2410
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002411TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
skvlade0d46372016-04-07 22:59:22 -07002412 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002413}
2414
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002415// VoiceChannelDoubleThreadTest
2416TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 Base::TestInit();
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002418 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2419 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420}
2421
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002422TEST_F(VoiceChannelDoubleThreadTest, TestDeinit) {
2423 Base::TestDeinit();
2424}
2425
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002426TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 Base::TestSetContents();
2428}
2429
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002430TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 Base::TestSetContentsNullOffer();
2432}
2433
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002434TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 Base::TestSetContentsRtcpMux();
2436}
2437
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002438TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 Base::TestSetContentsRtcpMux();
2440}
2441
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002442TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 Base::TestSetRemoteContentUpdate();
2444}
2445
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002446TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 Base::TestStreams();
2448}
2449
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002450TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 Base::TestUpdateStreamsInLocalContent();
2452}
2453
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002454TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455 Base::TestUpdateStreamsInRemoteContent();
2456}
2457
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002458TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 Base::TestChangeStreamParamsInContent();
2460}
2461
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002462TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 Base::TestPlayoutAndSendingStates();
2464}
2465
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002466TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
2467 CreateChannels(0, 0);
2468 // Test that we can Mute the default channel even though the sending SSRC
2469 // is unknown.
2470 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2471 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
2472 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2473 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
2474 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2475
2476 // Test that we can not mute an unknown SSRC.
2477 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2478
2479 SendInitiate();
2480 // After the local session description has been set, we can mute a stream
2481 // with its SSRC.
2482 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
2483 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2484 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
2485 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
2486}
2487
2488TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
2489 Base::TestMediaContentDirection();
2490}
2491
2492TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
2493 Base::TestNetworkRouteChanges();
2494}
2495
2496TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
2497 Base::TestCallSetup();
2498}
2499
2500TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
2501 Base::TestCallTeardownRtcpMux();
2502}
2503
2504TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
2505 Base::SendRtpToRtp();
2506}
2507
2508TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
2509 Base::SendNoRtcpToNoRtcp();
2510}
2511
2512TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
2513 Base::SendNoRtcpToRtcp();
2514}
2515
2516TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
2517 Base::SendRtcpToNoRtcp();
2518}
2519
2520TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
2521 Base::SendRtcpToRtcp();
2522}
2523
2524TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
2525 Base::SendRtcpMuxToRtcp();
2526}
2527
2528TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
2529 Base::SendRtcpMuxToRtcpMux();
2530}
2531
2532TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
2533 Base::SendRequireRtcpMuxToRtcpMux();
2534}
2535
2536TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
2537 Base::SendRtcpMuxToRequireRtcpMux();
2538}
2539
2540TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
2541 Base::SendRequireRtcpMuxToRequireRtcpMux();
2542}
2543
2544TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
2545 Base::SendRequireRtcpMuxToNoRtcpMux();
2546}
2547
2548TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
2549 Base::SendEarlyRtcpMuxToRtcp();
2550}
2551
2552TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
2553 Base::SendEarlyRtcpMuxToRtcpMux();
2554}
2555
2556TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
2557 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2558}
2559
2560TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
2561 Base::SendSrtpToSrtp();
2562}
2563
2564TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
2565 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2566}
2567
2568TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
2569 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2570 Base::SendSrtpToSrtp(DTLS, 0);
2571}
2572
2573TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
2574 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2575 Base::SendSrtpToSrtp(DTLS, DTLS);
2576}
2577
2578TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2579 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2580 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2581}
2582
2583TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2584 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2585}
2586
2587TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
2588 Base::SendRtpToRtpOnThread();
2589}
2590
2591TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
2592 Base::SendSrtpToSrtpOnThread();
2593}
2594
2595TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
2596 Base::SendWithWritabilityLoss();
2597}
2598
2599TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
2600 Base::TestMediaMonitor();
2601}
2602
2603// Test that InsertDtmf properly forwards to the media channel.
2604TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
2605 CreateChannels(0, 0);
2606 EXPECT_TRUE(SendInitiate());
2607 EXPECT_TRUE(SendAccept());
2608 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2609
2610 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2611 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2612 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
2613
2614 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2615 EXPECT_TRUE(
2616 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
2617 EXPECT_TRUE(
2618 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
2619 EXPECT_TRUE(
2620 CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
2621}
2622
2623TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
2624 Base::TestSetContentFailure();
2625}
2626
2627TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
2628 Base::TestSendTwoOffers();
2629}
2630
2631TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
2632 Base::TestReceiveTwoOffers();
2633}
2634
2635TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
2636 Base::TestSendPrAnswer();
2637}
2638
2639TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
2640 Base::TestReceivePrAnswer();
2641}
2642
2643TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
2644 Base::TestFlushRtcp();
2645}
2646
2647TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
2648 Base::TestSrtpError(kAudioPts[0]);
2649}
2650
2651TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
2652 Base::TestOnReadyToSend();
2653}
2654
2655TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
2656 Base::TestOnReadyToSendWithRtcpMux();
2657}
2658
2659// Test that we can scale the output volume properly for 1:1 calls.
2660TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
2661 CreateChannels(RTCP, RTCP);
2662 EXPECT_TRUE(SendInitiate());
2663 EXPECT_TRUE(SendAccept());
2664 double volume;
2665
2666 // Default is (1.0).
2667 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2668 EXPECT_DOUBLE_EQ(1.0, volume);
2669 // invalid ssrc.
2670 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2671
2672 // Set scale to (1.5).
2673 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2674 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2675 EXPECT_DOUBLE_EQ(1.5, volume);
2676
2677 // Set scale to (0).
2678 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2679 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2680 EXPECT_DOUBLE_EQ(0.0, volume);
2681}
2682
2683// Test that we can scale the output volume properly for multiway calls.
2684TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
2685 CreateChannels(RTCP, RTCP);
2686 EXPECT_TRUE(SendInitiate());
2687 EXPECT_TRUE(SendAccept());
2688 EXPECT_TRUE(AddStream1(1));
2689 EXPECT_TRUE(AddStream1(2));
2690
2691 double volume;
2692 // Default is (1.0).
2693 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2694 EXPECT_DOUBLE_EQ(1.0, volume);
2695 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2696 EXPECT_DOUBLE_EQ(1.0, volume);
2697 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2698 EXPECT_DOUBLE_EQ(1.0, volume);
2699 // invalid ssrc.
2700 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
2701
2702 // Set scale to (1.5) for ssrc = 1.
2703 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2704 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2705 EXPECT_DOUBLE_EQ(1.5, volume);
2706 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2707 EXPECT_DOUBLE_EQ(1.0, volume);
2708 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2709 EXPECT_DOUBLE_EQ(1.0, volume);
2710
2711 // Set scale to (0) for all ssrcs.
2712 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2713 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2714 EXPECT_DOUBLE_EQ(0.0, volume);
2715 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2716 EXPECT_DOUBLE_EQ(0.0, volume);
2717 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2718 EXPECT_DOUBLE_EQ(0.0, volume);
2719}
2720
2721TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
2722 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
2723}
2724
2725TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
2726 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
2727}
2728
2729TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
2730 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
2731}
2732
2733TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
2734 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
2735}
2736
2737TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
2738 Base::DefaultMaxBitrateIsUnlimited();
2739}
2740
2741TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
2742 Base::CanChangeMaxBitrate();
2743}
2744
2745// VideoChannelSingleThreadTest
2746TEST_F(VideoChannelSingleThreadTest, TestInit) {
2747 Base::TestInit();
2748}
2749
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002750TEST_F(VideoChannelSingleThreadTest, TestDeinit) {
2751 Base::TestDeinit();
2752}
2753
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002754TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
2755 Base::TestSetContents();
2756}
2757
2758TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
2759 Base::TestSetContentsNullOffer();
2760}
2761
2762TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
2763 Base::TestSetContentsRtcpMux();
2764}
2765
2766TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
2767 Base::TestSetContentsRtcpMux();
2768}
2769
2770TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
2771 Base::TestSetRemoteContentUpdate();
2772}
2773
2774TEST_F(VideoChannelSingleThreadTest, TestStreams) {
2775 Base::TestStreams();
2776}
2777
2778TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
2779 Base::TestUpdateStreamsInLocalContent();
2780}
2781
2782TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
2783 Base::TestUpdateStreamsInRemoteContent();
2784}
2785
2786TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
2787 Base::TestChangeStreamParamsInContent();
2788}
2789
2790TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
2791 Base::TestPlayoutAndSendingStates();
2792}
2793
2794TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002795 CreateChannels(0, 0);
2796 // Test that we can Mute the default channel even though the sending SSRC
2797 // is unknown.
2798 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002799 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002800 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2801 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002802 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2803 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002804 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002805 SendInitiate();
2806 // After the local session description has been set, we can mute a stream
2807 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002808 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002809 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2810 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002811 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812}
2813
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002814TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 Base::TestMediaContentDirection();
2816}
2817
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002818TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Honghai Zhangcc411c02016-03-29 17:27:21 -07002819 Base::TestNetworkRouteChanges();
2820}
2821
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002822TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823 Base::TestCallSetup();
2824}
2825
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002826TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827 Base::TestCallTeardownRtcpMux();
2828}
2829
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002830TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831 Base::SendRtpToRtp();
2832}
2833
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002834TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835 Base::SendNoRtcpToNoRtcp();
2836}
2837
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002838TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839 Base::SendNoRtcpToRtcp();
2840}
2841
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002842TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002843 Base::SendRtcpToNoRtcp();
2844}
2845
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002846TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847 Base::SendRtcpToRtcp();
2848}
2849
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002850TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 Base::SendRtcpMuxToRtcp();
2852}
2853
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002854TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002855 Base::SendRtcpMuxToRtcpMux();
2856}
2857
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002858TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002859 Base::SendRequireRtcpMuxToRtcpMux();
2860}
2861
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002862TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002863 Base::SendRtcpMuxToRequireRtcpMux();
2864}
2865
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002866TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002867 Base::SendRequireRtcpMuxToRequireRtcpMux();
2868}
2869
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002870TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002871 Base::SendRequireRtcpMuxToNoRtcpMux();
2872}
2873
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002874TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875 Base::SendEarlyRtcpMuxToRtcp();
2876}
2877
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002878TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002879 Base::SendEarlyRtcpMuxToRtcpMux();
2880}
2881
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002882TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883 Base::SendSrtpToSrtp();
2884}
2885
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002886TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 Base::SendSrtpToSrtp();
2888}
2889
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002890TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002891 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2892 Base::SendSrtpToSrtp(DTLS, 0);
2893}
2894
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002895TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2897 Base::SendSrtpToSrtp(DTLS, DTLS);
2898}
2899
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002900TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2902 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2903}
2904
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002905TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002906 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2907}
2908
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002909TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2911}
2912
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002913TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 Base::SendRtpToRtpOnThread();
2915}
2916
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002917TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918 Base::SendSrtpToSrtpOnThread();
2919}
2920
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002921TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002922 Base::SendWithWritabilityLoss();
2923}
2924
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002925TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926 Base::TestMediaMonitor();
2927}
2928
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002929TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 Base::TestSetContentFailure();
2931}
2932
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002933TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934 Base::TestSendTwoOffers();
2935}
2936
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002937TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 Base::TestReceiveTwoOffers();
2939}
2940
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002941TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002942 Base::TestSendPrAnswer();
2943}
2944
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002945TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002946 Base::TestReceivePrAnswer();
2947}
2948
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002949TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950 Base::TestFlushRtcp();
2951}
2952
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002953TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002954 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955}
2956
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002957TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002958 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002959}
2960
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002961TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002962 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002963}
2964
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002965TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002966 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967}
2968
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002969TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002970 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971}
2972
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002973TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974 Base::TestOnReadyToSend();
2975}
2976
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002977TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978 Base::TestOnReadyToSendWithRtcpMux();
2979}
2980
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002981TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
skvladdc1c62c2016-03-16 19:07:43 -07002982 Base::DefaultMaxBitrateIsUnlimited();
2983}
2984
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002985TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
skvladdc1c62c2016-03-16 19:07:43 -07002986 Base::CanChangeMaxBitrate();
2987}
2988
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002989// VideoChannelDoubleThreadTest
2990TEST_F(VideoChannelDoubleThreadTest, TestInit) {
2991 Base::TestInit();
2992}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02002994TEST_F(VideoChannelDoubleThreadTest, TestDeinit) {
2995 Base::TestDeinit();
2996}
2997
Danil Chapovalov33b01f22016-05-11 19:55:27 +02002998TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
2999 Base::TestSetContents();
3000}
3001
3002TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
3003 Base::TestSetContentsNullOffer();
3004}
3005
3006TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3007 Base::TestSetContentsRtcpMux();
3008}
3009
3010TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
3011 Base::TestSetContentsRtcpMux();
3012}
3013
3014TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3015 Base::TestSetRemoteContentUpdate();
3016}
3017
3018TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
3019 Base::TestStreams();
3020}
3021
3022TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3023 Base::TestUpdateStreamsInLocalContent();
3024}
3025
3026TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3027 Base::TestUpdateStreamsInRemoteContent();
3028}
3029
3030TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3031 Base::TestChangeStreamParamsInContent();
3032}
3033
3034TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3035 Base::TestPlayoutAndSendingStates();
3036}
3037
3038TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
3039 CreateChannels(0, 0);
3040 // Test that we can Mute the default channel even though the sending SSRC
3041 // is unknown.
3042 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3043 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
3044 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
3045 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
3046 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3047 // Test that we can not mute an unknown SSRC.
3048 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
3049 SendInitiate();
3050 // After the local session description has been set, we can mute a stream
3051 // with its SSRC.
3052 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
3053 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
3054 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
3055 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
3056}
3057
3058TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
3059 Base::TestMediaContentDirection();
3060}
3061
3062TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
3063 Base::TestNetworkRouteChanges();
3064}
3065
3066TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
3067 Base::TestCallSetup();
3068}
3069
3070TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3071 Base::TestCallTeardownRtcpMux();
3072}
3073
3074TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
3075 Base::SendRtpToRtp();
3076}
3077
3078TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3079 Base::SendNoRtcpToNoRtcp();
3080}
3081
3082TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3083 Base::SendNoRtcpToRtcp();
3084}
3085
3086TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3087 Base::SendRtcpToNoRtcp();
3088}
3089
3090TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
3091 Base::SendRtcpToRtcp();
3092}
3093
3094TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3095 Base::SendRtcpMuxToRtcp();
3096}
3097
3098TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3099 Base::SendRtcpMuxToRtcpMux();
3100}
3101
3102TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
3103 Base::SendRequireRtcpMuxToRtcpMux();
3104}
3105
3106TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
3107 Base::SendRtcpMuxToRequireRtcpMux();
3108}
3109
3110TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
3111 Base::SendRequireRtcpMuxToRequireRtcpMux();
3112}
3113
3114TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
3115 Base::SendRequireRtcpMuxToNoRtcpMux();
3116}
3117
3118TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3119 Base::SendEarlyRtcpMuxToRtcp();
3120}
3121
3122TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3123 Base::SendEarlyRtcpMuxToRtcpMux();
3124}
3125
3126TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
3127 Base::SendSrtpToSrtp();
3128}
3129
3130TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
3131 Base::SendSrtpToSrtp();
3132}
3133
3134TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
3135 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3136 Base::SendSrtpToSrtp(DTLS, 0);
3137}
3138
3139TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
3140 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3141 Base::SendSrtpToSrtp(DTLS, DTLS);
3142}
3143
3144TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
3145 MAYBE_SKIP_TEST(HaveDtlsSrtp);
3146 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
3147}
3148
3149TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
3150 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3151}
3152
3153TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
3154 Base::SendEarlyMediaUsingRtcpMuxSrtp();
3155}
3156
3157TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3158 Base::SendRtpToRtpOnThread();
3159}
3160
3161TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3162 Base::SendSrtpToSrtpOnThread();
3163}
3164
3165TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
3166 Base::SendWithWritabilityLoss();
3167}
3168
3169TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
3170 Base::TestMediaMonitor();
3171}
3172
3173TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
3174 Base::TestSetContentFailure();
3175}
3176
3177TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
3178 Base::TestSendTwoOffers();
3179}
3180
3181TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
3182 Base::TestReceiveTwoOffers();
3183}
3184
3185TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
3186 Base::TestSendPrAnswer();
3187}
3188
3189TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
3190 Base::TestReceivePrAnswer();
3191}
3192
3193TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
3194 Base::TestFlushRtcp();
3195}
3196
3197TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
3198 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
3199}
3200
3201TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
3202 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
3203}
3204
3205TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
3206 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
3207}
3208
3209TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
3210 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
3211}
3212
3213TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
3214 Base::TestSrtpError(kVideoPts[0]);
3215}
3216
3217TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
3218 Base::TestOnReadyToSend();
3219}
3220
3221TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3222 Base::TestOnReadyToSendWithRtcpMux();
3223}
3224
3225TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
3226 Base::DefaultMaxBitrateIsUnlimited();
3227}
3228
3229TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
3230 Base::CanChangeMaxBitrate();
3231}
3232
3233// DataChannelSingleThreadTest
3234class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235 public:
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003236 typedef ChannelTest<DataTraits> Base;
3237 DataChannelSingleThreadTest()
3238 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
3239};
3240
3241// DataChannelDoubleThreadTest
3242class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
3243 public:
3244 typedef ChannelTest<DataTraits> Base;
3245 DataChannelDoubleThreadTest()
3246 : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003247};
3248
3249// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07003250template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003251cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003252 rtc::Thread* worker_thread,
3253 rtc::Thread* network_thread,
deadbeefcbecd352015-09-23 11:50:27 -07003254 cricket::MediaEngineInterface* engine,
3255 cricket::FakeDataMediaChannel* ch,
3256 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003257 bool rtcp) {
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003258 cricket::DataChannel* channel =
3259 new cricket::DataChannel(worker_thread, network_thread, ch,
3260 transport_controller, cricket::CN_DATA, rtcp);
3261 if (!channel->Init_w()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003262 delete channel;
3263 channel = NULL;
3264 }
3265 return channel;
3266}
3267
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003268template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003269void ChannelTest<DataTraits>::CreateContent(
3270 int flags,
3271 const cricket::AudioCodec& audio_codec,
3272 const cricket::VideoCodec& video_codec,
3273 cricket::DataContentDescription* data) {
3274 data->AddCodec(kGoogleDataCodec);
3275 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
3276 if (flags & SECURE) {
3277 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07003278 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
3279 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003280 }
3281}
3282
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003283template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284void ChannelTest<DataTraits>::CopyContent(
3285 const cricket::DataContentDescription& source,
3286 cricket::DataContentDescription* data) {
3287 *data = source;
3288}
3289
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003290template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
3292 const cricket::DataCodec& c2) {
3293 return c1.name == c2.name;
3294}
3295
Peter Boström0c4e06b2015-10-07 12:23:21 +02003296template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003297void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02003298 uint32_t ssrc,
3299 int flags,
3300 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003301 data->AddLegacyStream(ssrc);
3302}
3303
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003304TEST_F(DataChannelSingleThreadTest, TestInit) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003305 Base::TestInit();
3306 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3307}
3308
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003309TEST_F(DataChannelSingleThreadTest, TestDeinit) {
3310 Base::TestDeinit();
3311}
3312
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003313TEST_F(DataChannelSingleThreadTest, TestSetContents) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314 Base::TestSetContents();
3315}
3316
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003317TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318 Base::TestSetContentsNullOffer();
3319}
3320
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003321TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003322 Base::TestSetContentsRtcpMux();
3323}
3324
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003325TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003326 Base::TestSetRemoteContentUpdate();
3327}
3328
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003329TEST_F(DataChannelSingleThreadTest, TestStreams) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 Base::TestStreams();
3331}
3332
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003333TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 Base::TestUpdateStreamsInLocalContent();
3335}
3336
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003337TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338 Base::TestUpdateStreamsInRemoteContent();
3339}
3340
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003341TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342 Base::TestChangeStreamParamsInContent();
3343}
3344
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003345TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 Base::TestPlayoutAndSendingStates();
3347}
3348
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003349TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 Base::TestMediaContentDirection();
3351}
3352
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003353TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003354 Base::TestCallSetup();
3355}
3356
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003357TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358 Base::TestCallTeardownRtcpMux();
3359}
3360
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003361TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 Base::TestOnReadyToSend();
3363}
3364
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003365TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003366 Base::TestOnReadyToSendWithRtcpMux();
3367}
3368
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003369TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370 Base::SendRtpToRtp();
3371}
3372
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003373TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003374 Base::SendNoRtcpToNoRtcp();
3375}
3376
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003377TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378 Base::SendNoRtcpToRtcp();
3379}
3380
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003381TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003382 Base::SendRtcpToNoRtcp();
3383}
3384
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003385TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003386 Base::SendRtcpToRtcp();
3387}
3388
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003389TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003390 Base::SendRtcpMuxToRtcp();
3391}
3392
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003393TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003394 Base::SendRtcpMuxToRtcpMux();
3395}
3396
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003397TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398 Base::SendEarlyRtcpMuxToRtcp();
3399}
3400
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003401TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003402 Base::SendEarlyRtcpMuxToRtcpMux();
3403}
3404
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003405TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406 Base::SendSrtpToSrtp();
3407}
3408
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003409TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003410 Base::SendSrtpToSrtp();
3411}
3412
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003413TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003414 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3415}
3416
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003417TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 Base::SendRtpToRtpOnThread();
3419}
3420
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003421TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003422 Base::SendSrtpToSrtpOnThread();
3423}
3424
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003425TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003426 Base::SendWithWritabilityLoss();
3427}
3428
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003429TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003430 Base::TestMediaMonitor();
3431}
3432
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003433TEST_F(DataChannelSingleThreadTest, TestSendData) {
3434 CreateChannels(0, 0);
3435 EXPECT_TRUE(SendInitiate());
3436 EXPECT_TRUE(SendAccept());
3437
3438 cricket::SendDataParams params;
3439 params.ssrc = 42;
3440 unsigned char data[] = {'f', 'o', 'o'};
3441 rtc::CopyOnWriteBuffer payload(data, 3);
3442 cricket::SendDataResult result;
3443 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3444 EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
3445 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3446}
3447
3448TEST_F(DataChannelDoubleThreadTest, TestInit) {
3449 Base::TestInit();
3450 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
3451}
3452
Danil Chapovalovdae07ba2016-05-14 01:43:50 +02003453TEST_F(DataChannelDoubleThreadTest, TestDeinit) {
3454 Base::TestDeinit();
3455}
3456
Danil Chapovalov33b01f22016-05-11 19:55:27 +02003457TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
3458 Base::TestSetContents();
3459}
3460
3461TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
3462 Base::TestSetContentsNullOffer();
3463}
3464
3465TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
3466 Base::TestSetContentsRtcpMux();
3467}
3468
3469TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
3470 Base::TestSetRemoteContentUpdate();
3471}
3472
3473TEST_F(DataChannelDoubleThreadTest, TestStreams) {
3474 Base::TestStreams();
3475}
3476
3477TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
3478 Base::TestUpdateStreamsInLocalContent();
3479}
3480
3481TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
3482 Base::TestUpdateStreamsInRemoteContent();
3483}
3484
3485TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
3486 Base::TestChangeStreamParamsInContent();
3487}
3488
3489TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
3490 Base::TestPlayoutAndSendingStates();
3491}
3492
3493TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
3494 Base::TestMediaContentDirection();
3495}
3496
3497TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
3498 Base::TestCallSetup();
3499}
3500
3501TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
3502 Base::TestCallTeardownRtcpMux();
3503}
3504
3505TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
3506 Base::TestOnReadyToSend();
3507}
3508
3509TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
3510 Base::TestOnReadyToSendWithRtcpMux();
3511}
3512
3513TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
3514 Base::SendRtpToRtp();
3515}
3516
3517TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
3518 Base::SendNoRtcpToNoRtcp();
3519}
3520
3521TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
3522 Base::SendNoRtcpToRtcp();
3523}
3524
3525TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
3526 Base::SendRtcpToNoRtcp();
3527}
3528
3529TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
3530 Base::SendRtcpToRtcp();
3531}
3532
3533TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
3534 Base::SendRtcpMuxToRtcp();
3535}
3536
3537TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
3538 Base::SendRtcpMuxToRtcpMux();
3539}
3540
3541TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
3542 Base::SendEarlyRtcpMuxToRtcp();
3543}
3544
3545TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
3546 Base::SendEarlyRtcpMuxToRtcpMux();
3547}
3548
3549TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
3550 Base::SendSrtpToSrtp();
3551}
3552
3553TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
3554 Base::SendSrtpToSrtp();
3555}
3556
3557TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
3558 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
3559}
3560
3561TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
3562 Base::SendRtpToRtpOnThread();
3563}
3564
3565TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
3566 Base::SendSrtpToSrtpOnThread();
3567}
3568
3569TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
3570 Base::SendWithWritabilityLoss();
3571}
3572
3573TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
3574 Base::TestMediaMonitor();
3575}
3576
3577TEST_F(DataChannelDoubleThreadTest, TestSendData) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578 CreateChannels(0, 0);
3579 EXPECT_TRUE(SendInitiate());
3580 EXPECT_TRUE(SendAccept());
3581
3582 cricket::SendDataParams params;
3583 params.ssrc = 42;
3584 unsigned char data[] = {
3585 'f', 'o', 'o'
3586 };
jbaucheec21bd2016-03-20 06:15:43 -07003587 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588 cricket::SendDataResult result;
3589 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3590 EXPECT_EQ(params.ssrc,
3591 media_channel1_->last_sent_data_params().ssrc);
3592 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3593}
3594
3595// TODO(pthatcher): TestSetReceiver?