blob: 6039065e8321b38757834d9ef940d41ae144c113 [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
tfarina5237aaf2015-11-10 23:44:30 -080013#include "webrtc/base/arraysize.h"
ossu292d6582016-03-17 02:31:13 -070014#include "webrtc/base/criticalsection.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000015#include "webrtc/base/fileutils.h"
16#include "webrtc/base/gunit.h"
17#include "webrtc/base/helpers.h"
18#include "webrtc/base/logging.h"
19#include "webrtc/base/pathutils.h"
20#include "webrtc/base/signalthread.h"
21#include "webrtc/base/ssladapter.h"
22#include "webrtc/base/sslidentity.h"
23#include "webrtc/base/window.h"
kjellandera96e2d72016-02-04 23:52:28 -080024#include "webrtc/media/base/fakemediaengine.h"
25#include "webrtc/media/base/fakertp.h"
26#include "webrtc/media/base/fakescreencapturerfactory.h"
27#include "webrtc/media/base/fakevideocapturer.h"
28#include "webrtc/media/base/mediachannel.h"
29#include "webrtc/media/base/rtpdump.h"
30#include "webrtc/media/base/screencastid.h"
31#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010032#include "webrtc/p2p/base/faketransportcontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010033#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034
35#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000036 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037 LOG(LS_INFO) << "Feature disabled... skipping"; \
38 return; \
39 }
40
41using cricket::CA_OFFER;
42using cricket::CA_PRANSWER;
43using cricket::CA_ANSWER;
44using cricket::CA_UPDATE;
45using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::ScreencastId;
47using cricket::StreamParams;
48using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050
deadbeef67cf2c12016-04-13 10:07:16 -070051static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
52static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
53static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
54static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30);
55static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15);
56static const cricket::DataCodec kGoogleDataCodec(101, "google-data");
Peter Boström0c4e06b2015-10-07 12:23:21 +020057static const uint32_t kSsrc1 = 0x1111;
58static const uint32_t kSsrc2 = 0x2222;
59static const uint32_t kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000060static const int kAudioPts[] = {0, 8};
61static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
deadbeefcbecd352015-09-23 11:50:27 -070063template <class ChannelT,
64 class MediaChannelT,
65 class ContentT,
66 class CodecT,
67 class MediaInfoT,
68 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069class Traits {
70 public:
71 typedef ChannelT Channel;
72 typedef MediaChannelT MediaChannel;
73 typedef ContentT Content;
74 typedef CodecT Codec;
75 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020076 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077};
78
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079// Controls how long we wait for a session to send messages that we
80// expect, in milliseconds. We put it high to avoid flaky tests.
81static const int kEventTimeout = 5000;
82
83class VoiceTraits : public Traits<cricket::VoiceChannel,
84 cricket::FakeVoiceMediaChannel,
85 cricket::AudioContentDescription,
86 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020087 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070088 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
90class VideoTraits : public Traits<cricket::VideoChannel,
91 cricket::FakeVideoMediaChannel,
92 cricket::VideoContentDescription,
93 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020094 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070095 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97class DataTraits : public Traits<cricket::DataChannel,
98 cricket::FakeDataMediaChannel,
99 cricket::DataContentDescription,
100 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200101 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700102 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000104rtc::StreamInterface* Open(const std::string& path) {
105 return rtc::Filesystem::OpenFile(
106 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107}
108
109// Base class for Voice/VideoChannel tests
110template<class T>
111class ChannelTest : public testing::Test, public sigslot::has_slots<> {
112 public:
113 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
114 DTLS = 0x10 };
115
Peter Boström34fbfff2015-09-24 19:20:30 +0200116 ChannelTest(bool verify_playout,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200117 const uint8_t* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700118 int rtp_len,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200119 const uint8_t* rtcp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700120 int rtcp_len)
Peter Boström34fbfff2015-09-24 19:20:30 +0200121 : verify_playout_(verify_playout),
122 transport_controller1_(cricket::ICEROLE_CONTROLLING),
deadbeefcbecd352015-09-23 11:50:27 -0700123 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 media_channel1_(NULL),
125 media_channel2_(NULL),
126 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
127 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
128 media_info_callbacks1_(),
solenberg5b14b422015-10-01 04:10:31 -0700129 media_info_callbacks2_() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200132 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
133 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000134 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136 void CreateChannels(
137 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000138 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 media_channel1_ = ch1;
140 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700141 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
142 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700144 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
145 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 (flags2 & RTCP) != 0));
147 channel1_->SignalMediaMonitor.connect(
148 this, &ChannelTest<T>::OnMediaMonitor);
149 channel2_->SignalMediaMonitor.connect(
150 this, &ChannelTest<T>::OnMediaMonitor);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000151 if ((flags1 & DTLS) && (flags2 & DTLS)) {
152 flags1 = (flags1 & ~SECURE);
153 flags2 = (flags2 & ~SECURE);
154 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 CreateContent(flags1, kPcmuCodec, kH264Codec,
156 &local_media_content1_);
157 CreateContent(flags2, kPcmuCodec, kH264Codec,
158 &local_media_content2_);
159 CopyContent(local_media_content1_, &remote_media_content1_);
160 CopyContent(local_media_content2_, &remote_media_content2_);
161
162 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200163 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800164 transport_controller1_.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("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 }
168 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200169 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800170 transport_controller2_.SetLocalCertificate(
jbauch555604a2016-04-26 03:13:22 -0700171 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800172 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 }
174
175 // Add stream information (SSRC) to the local content but not to the remote
176 // content. This means that we per default know the SSRC of what we send but
177 // not what we receive.
178 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
179 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
180
181 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
182 if (flags1 & SSRC_MUX) {
183 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
184 }
185 if (flags2 & SSRC_MUX) {
186 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
187 }
188 }
deadbeefcbecd352015-09-23 11:50:27 -0700189 typename T::Channel* CreateChannel(
190 rtc::Thread* thread,
191 cricket::MediaEngineInterface* engine,
192 typename T::MediaChannel* ch,
193 cricket::TransportController* transport_controller,
194 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700196 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000197 if (!channel->Init()) {
198 delete channel;
199 channel = NULL;
200 }
201 return channel;
202 }
203
204 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000205 bool result = channel1_->SetLocalContent(&local_media_content1_,
206 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 if (result) {
208 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000209 result = channel2_->SetRemoteContent(&remote_media_content1_,
210 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700212 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000214 result = channel2_->SetLocalContent(&local_media_content2_,
215 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000216 }
217 }
218 return result;
219 }
220
221 bool SendAccept() {
222 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000223 return channel1_->SetRemoteContent(&remote_media_content2_,
224 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 }
226
227 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000228 bool result = channel1_->SetLocalContent(&local_media_content1_,
229 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 if (result) {
231 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000232 result = channel2_->SetRemoteContent(&remote_media_content1_,
233 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 }
235 return result;
236 }
237
238 bool SendProvisionalAnswer() {
239 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000240 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 if (result) {
242 channel2_->Enable(true);
243 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000244 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700245 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 }
247 return result;
248 }
249
250 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000251 bool result = channel2_->SetLocalContent(&local_media_content2_,
252 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000254 result = channel1_->SetRemoteContent(&remote_media_content2_,
255 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 return result;
257 }
258
259 bool SendTerminate() {
260 channel1_.reset();
261 channel2_.reset();
262 return true;
263 }
264
265 bool AddStream1(int id) {
266 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
267 }
268 bool RemoveStream1(int id) {
269 return channel1_->RemoveRecvStream(id);
270 }
271
deadbeefcbecd352015-09-23 11:50:27 -0700272 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700274 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 }
276 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700277 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 }
279
280 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000281 return media_channel1_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700282 static_cast<int>(rtp_packet_.size()),
283 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284 }
285 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000286 return media_channel2_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700287 static_cast<int>(rtp_packet_.size()),
288 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 }
290 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000291 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
292 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 }
294 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000295 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
296 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 }
298 // Methods to send custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200299 bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000300 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700301 return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()),
302 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200304 bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000305 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700306 return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()),
307 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200309 bool SendCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000311 return media_channel1_->SendRtcp(data.c_str(),
312 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200314 bool SendCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000316 return media_channel2_->SendRtcp(data.c_str(),
317 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 }
319 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000320 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
321 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 }
323 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000324 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
325 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 }
327 bool CheckRtcp1() {
328 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000329 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
331 bool CheckRtcp2() {
332 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000333 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 }
335 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200336 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000337 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000338 return media_channel1_->CheckRtp(data.c_str(),
339 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200341 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000342 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000343 return media_channel2_->CheckRtp(data.c_str(),
344 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200346 bool CheckCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000348 return media_channel1_->CheckRtcp(data.c_str(),
349 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200351 bool CheckCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000353 return media_channel2_->CheckRtcp(data.c_str(),
354 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200356 std::string CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 std::string data(rtp_packet_);
358 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000359 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
360 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000361 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000362 rtc::Set8(const_cast<char*>(data.c_str()), 1,
363 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000364 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 return data;
366 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200367 std::string CreateRtcpData(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 std::string data(rtcp_packet_);
369 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000370 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 return data;
372 }
373
374 bool CheckNoRtp1() {
375 return media_channel1_->CheckNoRtp();
376 }
377 bool CheckNoRtp2() {
378 return media_channel2_->CheckNoRtp();
379 }
380 bool CheckNoRtcp1() {
381 return media_channel1_->CheckNoRtcp();
382 }
383 bool CheckNoRtcp2() {
384 return media_channel2_->CheckNoRtcp();
385 }
386
387 void CreateContent(int flags,
388 const cricket::AudioCodec& audio_codec,
389 const cricket::VideoCodec& video_codec,
390 typename T::Content* content) {
391 // overridden in specialized classes
392 }
393 void CopyContent(const typename T::Content& source,
394 typename T::Content* content) {
395 // overridden in specialized classes
396 }
397
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 // Creates a cricket::SessionDescription with one MediaContent and one stream.
399 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200400 cricket::SessionDescription* CreateSessionDescriptionWithStream(
401 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 typename T::Content content;
403 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
404 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
405 AddLegacyStreamInContent(ssrc, 0, &content);
406 sdesc->AddContent("DUMMY_CONTENT_NAME",
407 cricket::NS_JINGLE_RTP, content.Copy());
408 return sdesc;
409 }
410
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000411 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 public:
413 typedef bool (ChannelTest<T>::*Method)();
ossu292d6582016-03-17 02:31:13 -0700414 CallThread(ChannelTest<T>* obj, Method method, bool* result = nullptr)
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 : obj_(obj),
416 method_(method),
ossu292d6582016-03-17 02:31:13 -0700417 result_(false),
418 result_ptr_(result) {
419 if (result_ptr_)
420 *result_ptr_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 }
ossu292d6582016-03-17 02:31:13 -0700422
423 ~CallThread() {
424 if (result_ptr_) {
425 rtc::CritScope cs(&result_lock_);
426 *result_ptr_ = result_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 }
428 }
ossu292d6582016-03-17 02:31:13 -0700429
430 virtual void DoWork() {
431 SetResult((*obj_.*method_)());
432 }
433
434 bool result() {
435 rtc::CritScope cs(&result_lock_);
436 return result_;
437 }
438
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 private:
ossu292d6582016-03-17 02:31:13 -0700440 void SetResult(const bool& result) {
441 rtc::CritScope cs(&result_lock_);
442 result_ = result;
443 }
444
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 ChannelTest<T>* obj_;
446 Method method_;
ossu292d6582016-03-17 02:31:13 -0700447 rtc::CriticalSection result_lock_;
448 bool result_ GUARDED_BY(result_lock_);
449 bool* result_ptr_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 };
ossu292d6582016-03-17 02:31:13 -0700451
452 // Will manage the lifetime of a CallThread, making sure it's
453 // destroyed before this object goes out of scope.
454 class ScopedCallThread {
455 public:
456 using Method = typename CallThread::Method;
457
458 ScopedCallThread(ChannelTest<T>* obj, Method method)
459 : thread_(new CallThread(obj, method)) {
460 thread_->Start();
461 }
462
463 ~ScopedCallThread() {
464 thread_->Destroy(true);
465 }
466
467 bool result() const { return thread_->result(); }
468
469 private:
470 CallThread* thread_;
471 };
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472
473 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
474 bool* result) {
475 CallThread* thread = new CallThread(this, method, result);
476 thread->Start();
477 thread->Destroy(true);
478 }
479
480 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
481 return false; // overridden in specialized classes
482 }
483
484 void OnMediaMonitor(typename T::Channel* channel,
485 const typename T::MediaInfo& info) {
486 if (channel == channel1_.get()) {
487 media_info_callbacks1_++;
488 } else if (channel == channel2_.get()) {
489 media_info_callbacks2_++;
490 }
491 }
492
Honghai Zhangcc411c02016-03-29 17:27:21 -0700493 cricket::CandidatePairInterface* last_selected_candidate_pair() {
494 return last_selected_candidate_pair_;
495 }
496
Peter Boström0c4e06b2015-10-07 12:23:21 +0200497 void AddLegacyStreamInContent(uint32_t ssrc,
498 int flags,
499 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000500 // Base implementation.
501 }
502
503 // Tests that can be used by derived classes.
504
505 // Basic sanity check.
506 void TestInit() {
507 CreateChannels(0, 0);
508 EXPECT_FALSE(channel1_->secure());
509 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200510 if (verify_playout_) {
511 EXPECT_FALSE(media_channel1_->playout());
512 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 EXPECT_TRUE(media_channel1_->codecs().empty());
514 EXPECT_TRUE(media_channel1_->recv_streams().empty());
515 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
516 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
517 }
518
519 // Test that SetLocalContent and SetRemoteContent properly configure
520 // the codecs.
521 void TestSetContents() {
522 CreateChannels(0, 0);
523 typename T::Content content;
524 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000525 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000527 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000528 ASSERT_EQ(1U, media_channel1_->codecs().size());
529 EXPECT_TRUE(CodecMatches(content.codecs()[0],
530 media_channel1_->codecs()[0]));
531 }
532
533 // Test that SetLocalContent and SetRemoteContent properly deals
534 // with an empty offer.
535 void TestSetContentsNullOffer() {
536 CreateChannels(0, 0);
537 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000538 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 CreateContent(0, kPcmuCodec, kH264Codec, &content);
540 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000541 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000542 ASSERT_EQ(1U, media_channel1_->codecs().size());
543 EXPECT_TRUE(CodecMatches(content.codecs()[0],
544 media_channel1_->codecs()[0]));
545 }
546
547 // Test that SetLocalContent and SetRemoteContent properly set RTCP
548 // mux.
549 void TestSetContentsRtcpMux() {
550 CreateChannels(RTCP, RTCP);
551 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
552 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
553 typename T::Content content;
554 CreateContent(0, kPcmuCodec, kH264Codec, &content);
555 // Both sides agree on mux. Should no longer be a separate RTCP channel.
556 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000557 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
558 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
560 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000561 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000563 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
565 }
566
567 // Test that SetLocalContent and SetRemoteContent properly set RTCP
568 // mux when a provisional answer is received.
569 void TestSetContentsRtcpMuxWithPrAnswer() {
570 CreateChannels(RTCP, RTCP);
571 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
572 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
573 typename T::Content content;
574 CreateContent(0, kPcmuCodec, kH264Codec, &content);
575 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000576 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
577 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000579 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 // Both sides agree on mux. Should no longer be a separate RTCP channel.
581 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
582 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000583 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000585 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
586 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
588 }
589
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 // Test that SetRemoteContent properly deals with a content update.
591 void TestSetRemoteContentUpdate() {
592 CreateChannels(0, 0);
593 typename T::Content content;
594 CreateContent(RTCP | RTCP_MUX | SECURE,
595 kPcmuCodec, kH264Codec,
596 &content);
597 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000598 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
599 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000600 ASSERT_EQ(1U, media_channel1_->codecs().size());
601 EXPECT_TRUE(CodecMatches(content.codecs()[0],
602 media_channel1_->codecs()[0]));
603 // Now update with other codecs.
604 typename T::Content update_content;
605 update_content.set_partial(true);
606 CreateContent(0, kIsacCodec, kH264SvcCodec,
607 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000608 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 ASSERT_EQ(1U, media_channel1_->codecs().size());
610 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
611 media_channel1_->codecs()[0]));
612 // Now update without any codecs. This is ignored.
613 typename T::Content empty_content;
614 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000615 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 ASSERT_EQ(1U, media_channel1_->codecs().size());
617 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
618 media_channel1_->codecs()[0]));
619 }
620
621 // Test that Add/RemoveStream properly forward to the media channel.
622 void TestStreams() {
623 CreateChannels(0, 0);
624 EXPECT_TRUE(AddStream1(1));
625 EXPECT_TRUE(AddStream1(2));
626 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
627 EXPECT_TRUE(RemoveStream1(2));
628 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
629 EXPECT_TRUE(RemoveStream1(1));
630 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
631 }
632
633 // Test that SetLocalContent properly handles adding and removing StreamParams
634 // to the local content description.
635 // This test uses the CA_UPDATE action that don't require a full
636 // MediaContentDescription to do an update.
637 void TestUpdateStreamsInLocalContent() {
638 cricket::StreamParams stream1;
639 stream1.groupid = "group1";
640 stream1.id = "stream1";
641 stream1.ssrcs.push_back(kSsrc1);
642 stream1.cname = "stream1_cname";
643
644 cricket::StreamParams stream2;
645 stream2.groupid = "group2";
646 stream2.id = "stream2";
647 stream2.ssrcs.push_back(kSsrc2);
648 stream2.cname = "stream2_cname";
649
650 cricket::StreamParams stream3;
651 stream3.groupid = "group3";
652 stream3.id = "stream3";
653 stream3.ssrcs.push_back(kSsrc3);
654 stream3.cname = "stream3_cname";
655
656 CreateChannels(0, 0);
657 typename T::Content content1;
658 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
659 content1.AddStream(stream1);
660 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000661 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662
663 ASSERT_EQ(1u, media_channel1_->send_streams().size());
664 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
665
666 // Update the local streams by adding another sending stream.
667 // Use a partial updated session description.
668 typename T::Content content2;
669 content2.AddStream(stream2);
670 content2.AddStream(stream3);
671 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000672 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 ASSERT_EQ(3u, media_channel1_->send_streams().size());
674 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
675 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
676 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
677
678 // Update the local streams by removing the first sending stream.
679 // This is done by removing all SSRCS for this particular stream.
680 typename T::Content content3;
681 stream1.ssrcs.clear();
682 content3.AddStream(stream1);
683 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000684 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 ASSERT_EQ(2u, media_channel1_->send_streams().size());
686 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
687 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
688
689 // Update the local streams with a stream that does not change.
690 // THe update is ignored.
691 typename T::Content content4;
692 content4.AddStream(stream2);
693 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000694 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 ASSERT_EQ(2u, media_channel1_->send_streams().size());
696 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
697 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
698 }
699
700 // Test that SetRemoteContent properly handles adding and removing
701 // StreamParams to the remote content description.
702 // This test uses the CA_UPDATE action that don't require a full
703 // MediaContentDescription to do an update.
704 void TestUpdateStreamsInRemoteContent() {
705 cricket::StreamParams stream1;
706 stream1.id = "Stream1";
707 stream1.groupid = "1";
708 stream1.ssrcs.push_back(kSsrc1);
709 stream1.cname = "stream1_cname";
710
711 cricket::StreamParams stream2;
712 stream2.id = "Stream2";
713 stream2.groupid = "2";
714 stream2.ssrcs.push_back(kSsrc2);
715 stream2.cname = "stream2_cname";
716
717 cricket::StreamParams stream3;
718 stream3.id = "Stream3";
719 stream3.groupid = "3";
720 stream3.ssrcs.push_back(kSsrc3);
721 stream3.cname = "stream3_cname";
722
723 CreateChannels(0, 0);
724 typename T::Content content1;
725 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
726 content1.AddStream(stream1);
727 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729
730 ASSERT_EQ(1u, media_channel1_->codecs().size());
731 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
732 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
733
734 // Update the remote streams by adding another sending stream.
735 // Use a partial updated session description.
736 typename T::Content content2;
737 content2.AddStream(stream2);
738 content2.AddStream(stream3);
739 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000740 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
742 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
743 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
744 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
745
746 // Update the remote streams by removing the first stream.
747 // This is done by removing all SSRCS for this particular stream.
748 typename T::Content content3;
749 stream1.ssrcs.clear();
750 content3.AddStream(stream1);
751 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000752 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
754 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
755 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
756
757 // Update the remote streams with a stream that does not change.
758 // The update is ignored.
759 typename T::Content content4;
760 content4.AddStream(stream2);
761 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000762 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
764 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
765 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
766 }
767
768 // Test that SetLocalContent and SetRemoteContent properly
769 // handles adding and removing StreamParams when the action is a full
770 // CA_OFFER / CA_ANSWER.
771 void TestChangeStreamParamsInContent() {
772 cricket::StreamParams stream1;
773 stream1.groupid = "group1";
774 stream1.id = "stream1";
775 stream1.ssrcs.push_back(kSsrc1);
776 stream1.cname = "stream1_cname";
777
778 cricket::StreamParams stream2;
779 stream2.groupid = "group1";
780 stream2.id = "stream2";
781 stream2.ssrcs.push_back(kSsrc2);
782 stream2.cname = "stream2_cname";
783
784 // Setup a call where channel 1 send |stream1| to channel 2.
785 CreateChannels(0, 0);
786 typename T::Content content1;
787 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
788 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000789 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 EXPECT_TRUE(channel1_->Enable(true));
791 EXPECT_EQ(1u, media_channel1_->send_streams().size());
792
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700795 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796
797 // Channel 2 do not send anything.
798 typename T::Content content2;
799 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000800 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000802 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_TRUE(channel2_->Enable(true));
804 EXPECT_EQ(0u, media_channel2_->send_streams().size());
805
806 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
807 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
808
809 // Let channel 2 update the content by sending |stream2| and enable SRTP.
810 typename T::Content content3;
811 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
812 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000813 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 ASSERT_EQ(1u, media_channel2_->send_streams().size());
815 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
816
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000817 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
819 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
820
821 // Channel 1 replies but stop sending stream1.
822 typename T::Content content4;
823 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000824 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 EXPECT_EQ(0u, media_channel1_->send_streams().size());
826
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000827 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
829
830 EXPECT_TRUE(channel1_->secure());
831 EXPECT_TRUE(channel2_->secure());
832 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
833 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
834 }
835
836 // Test that we only start playout and sending at the right times.
837 void TestPlayoutAndSendingStates() {
838 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200839 if (verify_playout_) {
840 EXPECT_FALSE(media_channel1_->playout());
841 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200843 if (verify_playout_) {
844 EXPECT_FALSE(media_channel2_->playout());
845 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 EXPECT_FALSE(media_channel2_->sending());
847 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200848 if (verify_playout_) {
849 EXPECT_FALSE(media_channel1_->playout());
850 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000852 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
853 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200854 if (verify_playout_) {
855 EXPECT_TRUE(media_channel1_->playout());
856 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
859 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200860 if (verify_playout_) {
861 EXPECT_FALSE(media_channel2_->playout());
862 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000864 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
865 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200866 if (verify_playout_) {
867 EXPECT_FALSE(media_channel2_->playout());
868 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700870 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200871 if (verify_playout_) {
872 EXPECT_TRUE(media_channel1_->playout());
873 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200875 if (verify_playout_) {
876 EXPECT_FALSE(media_channel2_->playout());
877 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 EXPECT_FALSE(media_channel2_->sending());
879 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200880 if (verify_playout_) {
881 EXPECT_TRUE(media_channel2_->playout());
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000884 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
885 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200886 if (verify_playout_) {
887 EXPECT_TRUE(media_channel1_->playout());
888 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 EXPECT_TRUE(media_channel1_->sending());
890 }
891
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 // Test that changing the MediaContentDirection in the local and remote
893 // session description start playout and sending at the right time.
894 void TestMediaContentDirection() {
895 CreateChannels(0, 0);
896 typename T::Content content1;
897 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
898 typename T::Content content2;
899 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
900 // Set |content2| to be InActive.
901 content2.set_direction(cricket::MD_INACTIVE);
902
903 EXPECT_TRUE(channel1_->Enable(true));
904 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200905 if (verify_playout_) {
906 EXPECT_FALSE(media_channel1_->playout());
907 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200909 if (verify_playout_) {
910 EXPECT_FALSE(media_channel2_->playout());
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_FALSE(media_channel2_->sending());
913
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000914 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
915 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
916 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
917 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700918 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919
Peter Boström34fbfff2015-09-24 19:20:30 +0200920 if (verify_playout_) {
921 EXPECT_TRUE(media_channel1_->playout());
922 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200924 if (verify_playout_) {
925 EXPECT_FALSE(media_channel2_->playout()); // local InActive
926 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 EXPECT_FALSE(media_channel2_->sending()); // local InActive
928
929 // Update |content2| to be RecvOnly.
930 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000931 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
932 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933
Peter Boström34fbfff2015-09-24 19:20:30 +0200934 if (verify_playout_) {
935 EXPECT_TRUE(media_channel1_->playout());
936 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200938 if (verify_playout_) {
939 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
940 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
942
943 // Update |content2| to be SendRecv.
944 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000945 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
946 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947
Peter Boström34fbfff2015-09-24 19:20:30 +0200948 if (verify_playout_) {
949 EXPECT_TRUE(media_channel1_->playout());
950 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200952 if (verify_playout_) {
953 EXPECT_TRUE(media_channel2_->playout());
954 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 EXPECT_TRUE(media_channel2_->sending());
956 }
957
Honghai Zhangcc411c02016-03-29 17:27:21 -0700958 // Tests that when the transport channel signals a candidate pair change
959 // event, the media channel will receive a call on the network route change.
960 void TestNetworkRouteChanges() {
961 CreateChannels(0, 0);
962
963 cricket::TransportChannel* transport_channel1 =
964 channel1_->transport_channel();
965 ASSERT_TRUE(transport_channel1 != nullptr);
966 typename T::MediaChannel* media_channel1 =
967 static_cast<typename T::MediaChannel*>(channel1_->media_channel());
968 ASSERT_TRUE(media_channel1 != nullptr);
969
970 media_channel1_->set_num_network_route_changes(0);
971 // The transport channel becomes disconnected.
972 transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1,
Honghai Zhang52dce732016-03-31 12:37:31 -0700973 nullptr, -1);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700974 EXPECT_EQ(1, media_channel1_->num_network_route_changes());
975 EXPECT_FALSE(media_channel1->last_network_route().connected);
976
977 media_channel1_->set_num_network_route_changes(0);
978 // The transport channel becomes connected.
979 rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
980 rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
981 uint16_t local_net_id = 1;
982 uint16_t remote_net_id = 2;
Honghai Zhang52dce732016-03-31 12:37:31 -0700983 int last_packet_id = 100;
jbauch555604a2016-04-26 03:13:22 -0700984 std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
Honghai Zhangcc411c02016-03-29 17:27:21 -0700985 transport_controller1_.CreateFakeCandidatePair(
986 local_address, local_net_id, remote_address, remote_net_id));
987 transport_channel1->SignalSelectedCandidatePairChanged(
Honghai Zhang52dce732016-03-31 12:37:31 -0700988 transport_channel1, candidate_pair.get(), last_packet_id);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700989 EXPECT_EQ(1, media_channel1_->num_network_route_changes());
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700990 rtc::NetworkRoute expected_network_route(local_net_id, remote_net_id,
991 last_packet_id);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700992 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
Honghai Zhang52dce732016-03-31 12:37:31 -0700993 EXPECT_EQ(last_packet_id,
994 media_channel1->last_network_route().last_sent_packet_id);
Honghai Zhangcc411c02016-03-29 17:27:21 -0700995 }
996
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 // Test setting up a call.
998 void TestCallSetup() {
999 CreateChannels(0, 0);
1000 EXPECT_FALSE(channel1_->secure());
1001 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +02001002 if (verify_playout_) {
1003 EXPECT_TRUE(media_channel1_->playout());
1004 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 EXPECT_FALSE(media_channel1_->sending());
1006 EXPECT_TRUE(SendAccept());
1007 EXPECT_FALSE(channel1_->secure());
1008 EXPECT_TRUE(media_channel1_->sending());
1009 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +02001010 if (verify_playout_) {
1011 EXPECT_TRUE(media_channel2_->playout());
1012 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 EXPECT_TRUE(media_channel2_->sending());
1014 EXPECT_EQ(1U, media_channel2_->codecs().size());
1015 }
1016
1017 // Test that we don't crash if packets are sent during call teardown
1018 // when RTCP mux is enabled. This is a regression test against a specific
1019 // race condition that would only occur when a RTCP packet was sent during
1020 // teardown of a channel on which RTCP mux was enabled.
1021 void TestCallTeardownRtcpMux() {
1022 class LastWordMediaChannel : public T::MediaChannel {
1023 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001024 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001025 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001026 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1027 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1029 }
1030 };
1031 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1032 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001033 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 EXPECT_TRUE(SendInitiate());
1035 EXPECT_TRUE(SendAccept());
1036 EXPECT_TRUE(SendTerminate());
1037 }
1038
1039 // Send voice RTP data to the other side and ensure it gets there.
1040 void SendRtpToRtp() {
1041 CreateChannels(0, 0);
1042 EXPECT_TRUE(SendInitiate());
1043 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001044 ASSERT_TRUE(GetTransport1());
1045 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 EXPECT_EQ(1U, GetTransport1()->channels().size());
1047 EXPECT_EQ(1U, GetTransport2()->channels().size());
1048 EXPECT_TRUE(SendRtp1());
1049 EXPECT_TRUE(SendRtp2());
1050 EXPECT_TRUE(CheckRtp1());
1051 EXPECT_TRUE(CheckRtp2());
1052 EXPECT_TRUE(CheckNoRtp1());
1053 EXPECT_TRUE(CheckNoRtp2());
1054 }
1055
1056 // Check that RTCP is not transmitted if both sides don't support RTCP.
1057 void SendNoRtcpToNoRtcp() {
1058 CreateChannels(0, 0);
1059 EXPECT_TRUE(SendInitiate());
1060 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001061 ASSERT_TRUE(GetTransport1());
1062 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 EXPECT_EQ(1U, GetTransport1()->channels().size());
1064 EXPECT_EQ(1U, GetTransport2()->channels().size());
1065 EXPECT_FALSE(SendRtcp1());
1066 EXPECT_FALSE(SendRtcp2());
1067 EXPECT_TRUE(CheckNoRtcp1());
1068 EXPECT_TRUE(CheckNoRtcp2());
1069 }
1070
1071 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1072 void SendNoRtcpToRtcp() {
1073 CreateChannels(0, RTCP);
1074 EXPECT_TRUE(SendInitiate());
1075 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001076 ASSERT_TRUE(GetTransport1());
1077 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 EXPECT_EQ(1U, GetTransport1()->channels().size());
1079 EXPECT_EQ(2U, GetTransport2()->channels().size());
1080 EXPECT_FALSE(SendRtcp1());
1081 EXPECT_FALSE(SendRtcp2());
1082 EXPECT_TRUE(CheckNoRtcp1());
1083 EXPECT_TRUE(CheckNoRtcp2());
1084 }
1085
1086 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1087 void SendRtcpToNoRtcp() {
1088 CreateChannels(RTCP, 0);
1089 EXPECT_TRUE(SendInitiate());
1090 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001091 ASSERT_TRUE(GetTransport1());
1092 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 EXPECT_EQ(2U, GetTransport1()->channels().size());
1094 EXPECT_EQ(1U, GetTransport2()->channels().size());
1095 EXPECT_FALSE(SendRtcp1());
1096 EXPECT_FALSE(SendRtcp2());
1097 EXPECT_TRUE(CheckNoRtcp1());
1098 EXPECT_TRUE(CheckNoRtcp2());
1099 }
1100
1101 // Check that RTCP is transmitted if both sides support RTCP.
1102 void SendRtcpToRtcp() {
1103 CreateChannels(RTCP, RTCP);
1104 EXPECT_TRUE(SendInitiate());
1105 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001106 ASSERT_TRUE(GetTransport1());
1107 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 EXPECT_EQ(2U, GetTransport1()->channels().size());
1109 EXPECT_EQ(2U, GetTransport2()->channels().size());
1110 EXPECT_TRUE(SendRtcp1());
1111 EXPECT_TRUE(SendRtcp2());
1112 EXPECT_TRUE(CheckRtcp1());
1113 EXPECT_TRUE(CheckRtcp2());
1114 EXPECT_TRUE(CheckNoRtcp1());
1115 EXPECT_TRUE(CheckNoRtcp2());
1116 }
1117
1118 // Check that RTCP is transmitted if only the initiator supports mux.
1119 void SendRtcpMuxToRtcp() {
1120 CreateChannels(RTCP | RTCP_MUX, RTCP);
1121 EXPECT_TRUE(SendInitiate());
1122 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001123 ASSERT_TRUE(GetTransport1());
1124 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001125 EXPECT_EQ(2U, GetTransport1()->channels().size());
1126 EXPECT_EQ(2U, GetTransport2()->channels().size());
1127 EXPECT_TRUE(SendRtcp1());
1128 EXPECT_TRUE(SendRtcp2());
1129 EXPECT_TRUE(CheckRtcp1());
1130 EXPECT_TRUE(CheckRtcp2());
1131 EXPECT_TRUE(CheckNoRtcp1());
1132 EXPECT_TRUE(CheckNoRtcp2());
1133 }
1134
1135 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1136 void SendRtcpMuxToRtcpMux() {
1137 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1138 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001139 ASSERT_TRUE(GetTransport1());
1140 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 EXPECT_EQ(2U, GetTransport1()->channels().size());
1142 EXPECT_EQ(1U, GetTransport2()->channels().size());
1143 EXPECT_TRUE(SendAccept());
1144 EXPECT_EQ(1U, GetTransport1()->channels().size());
1145 EXPECT_TRUE(SendRtp1());
1146 EXPECT_TRUE(SendRtp2());
1147 EXPECT_TRUE(SendRtcp1());
1148 EXPECT_TRUE(SendRtcp2());
1149 EXPECT_TRUE(CheckRtp1());
1150 EXPECT_TRUE(CheckRtp2());
1151 EXPECT_TRUE(CheckNoRtp1());
1152 EXPECT_TRUE(CheckNoRtp2());
1153 EXPECT_TRUE(CheckRtcp1());
1154 EXPECT_TRUE(CheckRtcp2());
1155 EXPECT_TRUE(CheckNoRtcp1());
1156 EXPECT_TRUE(CheckNoRtcp2());
1157 }
1158
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001159 // Check that RTP and RTCP are transmitted ok when both sides
1160 // support mux and one the offerer requires mux.
1161 void SendRequireRtcpMuxToRtcpMux() {
1162 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1163 channel1_->ActivateRtcpMux();
1164 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001165 ASSERT_TRUE(GetTransport1());
1166 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001167 EXPECT_EQ(1U, GetTransport1()->channels().size());
1168 EXPECT_EQ(1U, GetTransport2()->channels().size());
1169 EXPECT_TRUE(SendAccept());
1170 EXPECT_TRUE(SendRtp1());
1171 EXPECT_TRUE(SendRtp2());
1172 EXPECT_TRUE(SendRtcp1());
1173 EXPECT_TRUE(SendRtcp2());
1174 EXPECT_TRUE(CheckRtp1());
1175 EXPECT_TRUE(CheckRtp2());
1176 EXPECT_TRUE(CheckNoRtp1());
1177 EXPECT_TRUE(CheckNoRtp2());
1178 EXPECT_TRUE(CheckRtcp1());
1179 EXPECT_TRUE(CheckRtcp2());
1180 EXPECT_TRUE(CheckNoRtcp1());
1181 EXPECT_TRUE(CheckNoRtcp2());
1182 }
1183
1184 // Check that RTP and RTCP are transmitted ok when both sides
1185 // support mux and one the answerer requires rtcp mux.
1186 void SendRtcpMuxToRequireRtcpMux() {
1187 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1188 channel2_->ActivateRtcpMux();
1189 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001190 ASSERT_TRUE(GetTransport1());
1191 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001192 EXPECT_EQ(2U, GetTransport1()->channels().size());
1193 EXPECT_EQ(1U, GetTransport2()->channels().size());
1194 EXPECT_TRUE(SendAccept());
1195 EXPECT_EQ(1U, GetTransport1()->channels().size());
1196 EXPECT_TRUE(SendRtp1());
1197 EXPECT_TRUE(SendRtp2());
1198 EXPECT_TRUE(SendRtcp1());
1199 EXPECT_TRUE(SendRtcp2());
1200 EXPECT_TRUE(CheckRtp1());
1201 EXPECT_TRUE(CheckRtp2());
1202 EXPECT_TRUE(CheckNoRtp1());
1203 EXPECT_TRUE(CheckNoRtp2());
1204 EXPECT_TRUE(CheckRtcp1());
1205 EXPECT_TRUE(CheckRtcp2());
1206 EXPECT_TRUE(CheckNoRtcp1());
1207 EXPECT_TRUE(CheckNoRtcp2());
1208 }
1209
1210 // Check that RTP and RTCP are transmitted ok when both sides
1211 // require mux.
1212 void SendRequireRtcpMuxToRequireRtcpMux() {
1213 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1214 channel1_->ActivateRtcpMux();
1215 channel2_->ActivateRtcpMux();
1216 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001217 ASSERT_TRUE(GetTransport1());
1218 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001219 EXPECT_EQ(1U, GetTransport1()->channels().size());
1220 EXPECT_EQ(1U, GetTransport2()->channels().size());
1221 EXPECT_TRUE(SendAccept());
1222 EXPECT_EQ(1U, GetTransport1()->channels().size());
1223 EXPECT_TRUE(SendRtp1());
1224 EXPECT_TRUE(SendRtp2());
1225 EXPECT_TRUE(SendRtcp1());
1226 EXPECT_TRUE(SendRtcp2());
1227 EXPECT_TRUE(CheckRtp1());
1228 EXPECT_TRUE(CheckRtp2());
1229 EXPECT_TRUE(CheckNoRtp1());
1230 EXPECT_TRUE(CheckNoRtp2());
1231 EXPECT_TRUE(CheckRtcp1());
1232 EXPECT_TRUE(CheckRtcp2());
1233 EXPECT_TRUE(CheckNoRtcp1());
1234 EXPECT_TRUE(CheckNoRtcp2());
1235 }
1236
1237 // Check that SendAccept fails if the answerer doesn't support mux
1238 // and the offerer requires it.
1239 void SendRequireRtcpMuxToNoRtcpMux() {
1240 CreateChannels(RTCP | RTCP_MUX, RTCP);
1241 channel1_->ActivateRtcpMux();
1242 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001243 ASSERT_TRUE(GetTransport1());
1244 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001245 EXPECT_EQ(1U, GetTransport1()->channels().size());
1246 EXPECT_EQ(2U, GetTransport2()->channels().size());
1247 EXPECT_FALSE(SendAccept());
1248 }
1249
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 // Check that RTCP data sent by the initiator before the accept is not muxed.
1251 void SendEarlyRtcpMuxToRtcp() {
1252 CreateChannels(RTCP | RTCP_MUX, RTCP);
1253 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001254 ASSERT_TRUE(GetTransport1());
1255 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001256 EXPECT_EQ(2U, GetTransport1()->channels().size());
1257 EXPECT_EQ(2U, GetTransport2()->channels().size());
1258
1259 // RTCP can be sent before the call is accepted, if the transport is ready.
1260 // It should not be muxed though, as the remote side doesn't support mux.
1261 EXPECT_TRUE(SendRtcp1());
1262 EXPECT_TRUE(CheckNoRtp2());
1263 EXPECT_TRUE(CheckRtcp2());
1264
1265 // Send RTCP packet from callee and verify that it is received.
1266 EXPECT_TRUE(SendRtcp2());
1267 EXPECT_TRUE(CheckNoRtp1());
1268 EXPECT_TRUE(CheckRtcp1());
1269
1270 // Complete call setup and ensure everything is still OK.
1271 EXPECT_TRUE(SendAccept());
1272 EXPECT_EQ(2U, GetTransport1()->channels().size());
1273 EXPECT_TRUE(SendRtcp1());
1274 EXPECT_TRUE(CheckRtcp2());
1275 EXPECT_TRUE(SendRtcp2());
1276 EXPECT_TRUE(CheckRtcp1());
1277 }
1278
1279
1280 // Check that RTCP data is not muxed until both sides have enabled muxing,
1281 // but that we properly demux before we get the accept message, since there
1282 // is a race between RTP data and the jingle accept.
1283 void SendEarlyRtcpMuxToRtcpMux() {
1284 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1285 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001286 ASSERT_TRUE(GetTransport1());
1287 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 EXPECT_EQ(2U, GetTransport1()->channels().size());
1289 EXPECT_EQ(1U, GetTransport2()->channels().size());
1290
1291 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1292 // we haven't yet received the accept that says we should mux.
1293 EXPECT_FALSE(SendRtcp1());
1294
1295 // Send muxed RTCP packet from callee and verify that it is received.
1296 EXPECT_TRUE(SendRtcp2());
1297 EXPECT_TRUE(CheckNoRtp1());
1298 EXPECT_TRUE(CheckRtcp1());
1299
1300 // Complete call setup and ensure everything is still OK.
1301 EXPECT_TRUE(SendAccept());
1302 EXPECT_EQ(1U, GetTransport1()->channels().size());
1303 EXPECT_TRUE(SendRtcp1());
1304 EXPECT_TRUE(CheckRtcp2());
1305 EXPECT_TRUE(SendRtcp2());
1306 EXPECT_TRUE(CheckRtcp1());
1307 }
1308
1309 // Test that we properly send SRTP with RTCP in both directions.
1310 // You can pass in DTLS and/or RTCP_MUX as flags.
1311 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1312 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1313 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1314
1315 int flags1 = RTCP | SECURE | flags1_in;
1316 int flags2 = RTCP | SECURE | flags2_in;
1317 bool dtls1 = !!(flags1_in & DTLS);
1318 bool dtls2 = !!(flags2_in & DTLS);
1319 CreateChannels(flags1, flags2);
1320 EXPECT_FALSE(channel1_->secure());
1321 EXPECT_FALSE(channel2_->secure());
1322 EXPECT_TRUE(SendInitiate());
1323 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1324 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1325 EXPECT_TRUE(SendAccept());
1326 EXPECT_TRUE(channel1_->secure());
1327 EXPECT_TRUE(channel2_->secure());
1328 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1329 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1330 EXPECT_TRUE(SendRtp1());
1331 EXPECT_TRUE(SendRtp2());
1332 EXPECT_TRUE(SendRtcp1());
1333 EXPECT_TRUE(SendRtcp2());
1334 EXPECT_TRUE(CheckRtp1());
1335 EXPECT_TRUE(CheckRtp2());
1336 EXPECT_TRUE(CheckNoRtp1());
1337 EXPECT_TRUE(CheckNoRtp2());
1338 EXPECT_TRUE(CheckRtcp1());
1339 EXPECT_TRUE(CheckRtcp2());
1340 EXPECT_TRUE(CheckNoRtcp1());
1341 EXPECT_TRUE(CheckNoRtcp2());
1342 }
1343
1344 // Test that we properly handling SRTP negotiating down to RTP.
1345 void SendSrtpToRtp() {
1346 CreateChannels(RTCP | SECURE, RTCP);
1347 EXPECT_FALSE(channel1_->secure());
1348 EXPECT_FALSE(channel2_->secure());
1349 EXPECT_TRUE(SendInitiate());
1350 EXPECT_TRUE(SendAccept());
1351 EXPECT_FALSE(channel1_->secure());
1352 EXPECT_FALSE(channel2_->secure());
1353 EXPECT_TRUE(SendRtp1());
1354 EXPECT_TRUE(SendRtp2());
1355 EXPECT_TRUE(SendRtcp1());
1356 EXPECT_TRUE(SendRtcp2());
1357 EXPECT_TRUE(CheckRtp1());
1358 EXPECT_TRUE(CheckRtp2());
1359 EXPECT_TRUE(CheckNoRtp1());
1360 EXPECT_TRUE(CheckNoRtp2());
1361 EXPECT_TRUE(CheckRtcp1());
1362 EXPECT_TRUE(CheckRtcp2());
1363 EXPECT_TRUE(CheckNoRtcp1());
1364 EXPECT_TRUE(CheckNoRtcp2());
1365 }
1366
1367 // Test that we can send and receive early media when a provisional answer is
1368 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1369 void SendEarlyMediaUsingRtcpMuxSrtp() {
1370 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1371
1372 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1373 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1374 EXPECT_TRUE(SendOffer());
1375 EXPECT_TRUE(SendProvisionalAnswer());
1376 EXPECT_TRUE(channel1_->secure());
1377 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001378 ASSERT_TRUE(GetTransport1());
1379 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001380 EXPECT_EQ(2U, GetTransport1()->channels().size());
1381 EXPECT_EQ(2U, GetTransport2()->channels().size());
1382 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1383 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1384 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1385 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1386
1387 // Send packets from callee and verify that it is received.
1388 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1389 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1390 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1391 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1392
1393 // Complete call setup and ensure everything is still OK.
1394 EXPECT_TRUE(SendFinalAnswer());
1395 EXPECT_EQ(1U, GetTransport1()->channels().size());
1396 EXPECT_EQ(1U, GetTransport2()->channels().size());
1397 EXPECT_TRUE(channel1_->secure());
1398 EXPECT_TRUE(channel2_->secure());
1399 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1400 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1401 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1402 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1403 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1404 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1405 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1406 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1407 }
1408
1409 // Test that we properly send RTP without SRTP from a thread.
1410 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001411 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 EXPECT_TRUE(SendInitiate());
1413 EXPECT_TRUE(SendAccept());
ossu292d6582016-03-17 02:31:13 -07001414 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
1415 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
1416 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
1417 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1419 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001420 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
1421 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001422 EXPECT_TRUE(CheckNoRtp1());
1423 EXPECT_TRUE(CheckNoRtp2());
1424 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1425 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001426 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
1427 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 EXPECT_TRUE(CheckNoRtcp1());
1429 EXPECT_TRUE(CheckNoRtcp2());
1430 }
1431
1432 // Test that we properly send SRTP with RTCP from a thread.
1433 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1435 EXPECT_TRUE(SendInitiate());
1436 EXPECT_TRUE(SendAccept());
ossu292d6582016-03-17 02:31:13 -07001437 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
1438 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
1439 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
1440 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1442 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001443 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
1444 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001445 EXPECT_TRUE(CheckNoRtp1());
1446 EXPECT_TRUE(CheckNoRtp2());
1447 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1448 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001449 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
1450 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 EXPECT_TRUE(CheckNoRtcp1());
1452 EXPECT_TRUE(CheckNoRtcp2());
1453 }
1454
1455 // Test that the mediachannel retains its sending state after the transport
1456 // becomes non-writable.
1457 void SendWithWritabilityLoss() {
1458 CreateChannels(0, 0);
1459 EXPECT_TRUE(SendInitiate());
1460 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001461 ASSERT_TRUE(GetTransport1());
1462 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 EXPECT_EQ(1U, GetTransport1()->channels().size());
1464 EXPECT_EQ(1U, GetTransport2()->channels().size());
1465 EXPECT_TRUE(SendRtp1());
1466 EXPECT_TRUE(SendRtp2());
1467 EXPECT_TRUE(CheckRtp1());
1468 EXPECT_TRUE(CheckRtp2());
1469 EXPECT_TRUE(CheckNoRtp1());
1470 EXPECT_TRUE(CheckNoRtp2());
1471
wu@webrtc.org97077a32013-10-25 21:18:33 +00001472 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 EXPECT_FALSE(SendRtp1());
1475 EXPECT_TRUE(SendRtp2());
1476 EXPECT_TRUE(CheckRtp1());
1477 EXPECT_TRUE(CheckNoRtp2());
1478
1479 // Regain writability
1480 GetTransport1()->SetWritable(true);
1481 EXPECT_TRUE(media_channel1_->sending());
1482 EXPECT_TRUE(SendRtp1());
1483 EXPECT_TRUE(SendRtp2());
1484 EXPECT_TRUE(CheckRtp1());
1485 EXPECT_TRUE(CheckRtp2());
1486 EXPECT_TRUE(CheckNoRtp1());
1487 EXPECT_TRUE(CheckNoRtp2());
1488
1489 // Lose writability completely
1490 GetTransport1()->SetDestination(NULL);
1491 EXPECT_TRUE(media_channel1_->sending());
1492
wu@webrtc.org97077a32013-10-25 21:18:33 +00001493 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_FALSE(SendRtp1());
1495 EXPECT_TRUE(SendRtp2());
1496 EXPECT_TRUE(CheckRtp1());
1497 EXPECT_TRUE(CheckNoRtp2());
1498
1499 // Gain writability back
1500 GetTransport1()->SetDestination(GetTransport2());
1501 EXPECT_TRUE(media_channel1_->sending());
1502 EXPECT_TRUE(SendRtp1());
1503 EXPECT_TRUE(SendRtp2());
1504 EXPECT_TRUE(CheckRtp1());
1505 EXPECT_TRUE(CheckRtp2());
1506 EXPECT_TRUE(CheckNoRtp1());
1507 EXPECT_TRUE(CheckNoRtp2());
1508 }
1509
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001510 void SendBundleToBundle(
1511 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1512 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001514 // Only pl_type1 was added to the bundle filter for both |channel1_|
1515 // and |channel2_|.
1516 int pl_type1 = pl_types[0];
1517 int pl_type2 = pl_types[1];
1518 int flags = SSRC_MUX | RTCP;
1519 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001520 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001521 if (rtcp_mux) {
1522 flags |= RTCP_MUX;
1523 expected_channels = 1U;
1524 }
1525 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001527 ASSERT_TRUE(GetTransport1());
1528 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001530 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001532 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1533 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1534 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1535 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1536 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1537 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001538
1539 // Both channels can receive pl_type1 only.
1540 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1541 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1542 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1543 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1544 EXPECT_TRUE(CheckNoRtp1());
1545 EXPECT_TRUE(CheckNoRtp2());
1546
1547 // RTCP test
1548 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1549 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1550 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1551 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1552
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1554 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1556 EXPECT_TRUE(CheckNoRtcp1());
1557 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1558 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001560 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1561 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
pbos482b12e2015-11-16 10:19:58 -08001562 // Bundle filter shouldn't filter out any RTCP.
1563 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1564 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 }
1566
1567 // Test that the media monitor can be run and gives timely callbacks.
1568 void TestMediaMonitor() {
1569 static const int kTimeout = 500;
1570 CreateChannels(0, 0);
1571 EXPECT_TRUE(SendInitiate());
1572 EXPECT_TRUE(SendAccept());
1573 channel1_->StartMediaMonitor(100);
1574 channel2_->StartMediaMonitor(100);
1575 // Ensure we get callbacks and stop.
1576 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1577 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1578 channel1_->StopMediaMonitor();
1579 channel2_->StopMediaMonitor();
1580 // Ensure a restart of a stopped monitor works.
1581 channel1_->StartMediaMonitor(100);
1582 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1583 channel1_->StopMediaMonitor();
1584 // Ensure stopping a stopped monitor is OK.
1585 channel1_->StopMediaMonitor();
1586 }
1587
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 void TestSetContentFailure() {
1589 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590
Peter Thatchera6d24442015-07-09 21:26:36 -07001591 auto sdesc = cricket::SessionDescription();
1592 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1593 new cricket::AudioContentDescription());
1594 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1595 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596
Peter Thatchera6d24442015-07-09 21:26:36 -07001597 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001599 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1600 &sdesc, cricket::CA_OFFER, &err));
1601 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1602 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001605 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1606 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001608 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1609 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 }
1611
1612 void TestSendTwoOffers() {
1613 CreateChannels(0, 0);
1614
Peter Thatchera6d24442015-07-09 21:26:36 -07001615 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001616 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001617 CreateSessionDescriptionWithStream(1));
1618 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1619 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1621
kwiberg31022942016-03-11 14:18:21 -08001622 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001623 CreateSessionDescriptionWithStream(2));
1624 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1625 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1627 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1628 }
1629
1630 void TestReceiveTwoOffers() {
1631 CreateChannels(0, 0);
1632
Peter Thatchera6d24442015-07-09 21:26:36 -07001633 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001634 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001635 CreateSessionDescriptionWithStream(1));
1636 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1637 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1639
kwiberg31022942016-03-11 14:18:21 -08001640 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001641 CreateSessionDescriptionWithStream(2));
1642 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1643 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1645 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1646 }
1647
1648 void TestSendPrAnswer() {
1649 CreateChannels(0, 0);
1650
Peter Thatchera6d24442015-07-09 21:26:36 -07001651 std::string err;
1652 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001653 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001654 CreateSessionDescriptionWithStream(1));
1655 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1656 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1658
Peter Thatchera6d24442015-07-09 21:26:36 -07001659 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001660 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001661 CreateSessionDescriptionWithStream(2));
1662 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1663 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1665 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1666
Peter Thatchera6d24442015-07-09 21:26:36 -07001667 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001668 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001669 CreateSessionDescriptionWithStream(3));
1670 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1671 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1673 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1674 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1675 }
1676
1677 void TestReceivePrAnswer() {
1678 CreateChannels(0, 0);
1679
Peter Thatchera6d24442015-07-09 21:26:36 -07001680 std::string err;
1681 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001682 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001683 CreateSessionDescriptionWithStream(1));
1684 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1685 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1687
Peter Thatchera6d24442015-07-09 21:26:36 -07001688 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001689 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001690 CreateSessionDescriptionWithStream(2));
1691 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1692 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1694 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1695
Peter Thatchera6d24442015-07-09 21:26:36 -07001696 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001697 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001698 CreateSessionDescriptionWithStream(3));
1699 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1700 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1702 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1703 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1704 }
1705
1706 void TestFlushRtcp() {
1707 bool send_rtcp1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 CreateChannels(RTCP, RTCP);
1709 EXPECT_TRUE(SendInitiate());
1710 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001711 ASSERT_TRUE(GetTransport1());
1712 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 EXPECT_EQ(2U, GetTransport1()->channels().size());
1714 EXPECT_EQ(2U, GetTransport2()->channels().size());
1715
1716 // Send RTCP1 from a different thread.
1717 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1718 EXPECT_TRUE(send_rtcp1);
1719 // The sending message is only posted. channel2_ should be empty.
1720 EXPECT_TRUE(CheckNoRtcp2());
1721
1722 // When channel1_ is deleted, the RTCP packet should be sent out to
1723 // channel2_.
1724 channel1_.reset();
1725 EXPECT_TRUE(CheckRtcp2());
1726 }
1727
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001728 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001729 struct SrtpErrorHandler : public sigslot::has_slots<> {
1730 SrtpErrorHandler() :
1731 mode_(cricket::SrtpFilter::UNPROTECT),
1732 error_(cricket::SrtpFilter::ERROR_NONE) {}
1733 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1734 cricket::SrtpFilter::Error error) {
1735 mode_ = mode;
1736 error_ = error;
1737 }
1738 cricket::SrtpFilter::Mode mode_;
1739 cricket::SrtpFilter::Error error_;
1740 } error_handler;
1741
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001742 // For Audio, only pl_type 0 is added to the bundle filter.
1743 // For Video, only pl_type 97 is added to the bundle filter.
1744 // So we need to pass in pl_type so that the packet can pass through
1745 // the bundle filter before it can be processed by the srtp filter.
1746 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001747 unsigned const char kBadPacket[] = {0x84,
1748 static_cast<unsigned char>(pl_type),
1749 0x00,
1750 0x01,
1751 0x00,
1752 0x00,
1753 0x00,
1754 0x00,
1755 0x00,
1756 0x00,
1757 0x00,
1758 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1760 EXPECT_FALSE(channel1_->secure());
1761 EXPECT_FALSE(channel2_->secure());
1762 EXPECT_TRUE(SendInitiate());
1763 EXPECT_TRUE(SendAccept());
1764 EXPECT_TRUE(channel1_->secure());
1765 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001766 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001767 channel2_->srtp_filter()->SignalSrtpError.connect(
1768 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769
1770 // Testing failures in sending packets.
stefanc1aeaf02015-10-15 07:26:07 -07001771 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1772 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001774 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1775 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1776 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001777 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1778 // The next 250 ms failures will not trigger an error.
stefanc1aeaf02015-10-15 07:26:07 -07001779 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1780 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001782 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001783 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001784 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1785 // Wait for a little more - the error will be triggered again.
1786 rtc::Thread::Current()->ProcessMessages(200);
stefanc1aeaf02015-10-15 07:26:07 -07001787 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1788 rtc::PacketOptions()));
solenberg5b14b422015-10-01 04:10:31 -07001789 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1790 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791
1792 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001793 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001794 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001795
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 cricket::TransportChannel* transport_channel =
1797 channel2_->transport_channel();
1798 transport_channel->SignalReadPacket(
1799 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001800 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001801 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1802 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 }
1804
1805 void TestOnReadyToSend() {
1806 CreateChannels(RTCP, RTCP);
1807 TransportChannel* rtp = channel1_->transport_channel();
1808 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1809 EXPECT_FALSE(media_channel1_->ready_to_send());
1810 rtp->SignalReadyToSend(rtp);
1811 EXPECT_FALSE(media_channel1_->ready_to_send());
1812 rtcp->SignalReadyToSend(rtcp);
1813 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1814 // channel are ready to send.
1815 EXPECT_TRUE(media_channel1_->ready_to_send());
1816
1817 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001818 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001820 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 EXPECT_TRUE(media_channel1_->ready_to_send());
1822
1823 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001824 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001826 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827 EXPECT_TRUE(media_channel1_->ready_to_send());
1828 }
1829
1830 void TestOnReadyToSendWithRtcpMux() {
1831 CreateChannels(RTCP, RTCP);
1832 typename T::Content content;
1833 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1834 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1835 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001836 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1837 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1839 TransportChannel* rtp = channel1_->transport_channel();
1840 EXPECT_FALSE(media_channel1_->ready_to_send());
1841 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1842 // should trigger the MediaChannel's OnReadyToSend.
1843 rtp->SignalReadyToSend(rtp);
1844 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001845 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 EXPECT_FALSE(media_channel1_->ready_to_send());
1847 }
1848
skvladdc1c62c2016-03-16 19:07:43 -07001849 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1850 typename T::Content content;
1851 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1852 content.set_bandwidth(remote_limit);
1853 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1854 }
1855
1856 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1857 webrtc::RtpParameters parameters;
1858 webrtc::RtpEncodingParameters encoding;
1859 encoding.max_bitrate_bps = limit;
1860 parameters.encodings.push_back(encoding);
1861 return parameters;
1862 }
1863
1864 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1865 int expected_bitrate) {
1866 EXPECT_EQ(1UL, parameters.encodings.size());
1867 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1868 }
1869
1870 void DefaultMaxBitrateIsUnlimited() {
1871 CreateChannels(0, 0);
1872 EXPECT_TRUE(
1873 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1874 EXPECT_EQ(media_channel1_->max_bps(), -1);
1875 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1);
1876 }
1877
1878 void CanChangeMaxBitrate() {
1879 CreateChannels(0, 0);
1880 EXPECT_TRUE(
1881 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1882
1883 EXPECT_TRUE(
1884 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(1000)));
1885 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), 1000);
1886 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), 1000);
1887 EXPECT_EQ(-1, media_channel1_->max_bps());
1888
1889 EXPECT_TRUE(
1890 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(-1)));
1891 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), -1);
1892 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1);
1893 EXPECT_EQ(-1, media_channel1_->max_bps());
1894 }
1895
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001897 // TODO(pbos): Remove playout from all media channels and let renderers mute
1898 // themselves.
1899 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001900 cricket::FakeTransportController transport_controller1_;
1901 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 cricket::FakeMediaEngine media_engine_;
1903 // The media channels are owned by the voice channel objects below.
1904 typename T::MediaChannel* media_channel1_;
1905 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001906 std::unique_ptr<typename T::Channel> channel1_;
1907 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 typename T::Content local_media_content1_;
1909 typename T::Content local_media_content2_;
1910 typename T::Content remote_media_content1_;
1911 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 // The RTP and RTCP packets to send in the tests.
1913 std::string rtp_packet_;
1914 std::string rtcp_packet_;
1915 int media_info_callbacks1_;
1916 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001917 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918};
1919
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920template<>
1921void ChannelTest<VoiceTraits>::CreateContent(
1922 int flags,
1923 const cricket::AudioCodec& audio_codec,
1924 const cricket::VideoCodec& video_codec,
1925 cricket::AudioContentDescription* audio) {
1926 audio->AddCodec(audio_codec);
1927 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1928 if (flags & SECURE) {
1929 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001930 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1931 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 }
1933}
1934
1935template<>
1936void ChannelTest<VoiceTraits>::CopyContent(
1937 const cricket::AudioContentDescription& source,
1938 cricket::AudioContentDescription* audio) {
1939 *audio = source;
1940}
1941
1942template<>
1943bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1944 const cricket::AudioCodec& c2) {
1945 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1946 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1947}
1948
Peter Boström0c4e06b2015-10-07 12:23:21 +02001949template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001951 uint32_t ssrc,
1952 int flags,
1953 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001954 audio->AddLegacyStream(ssrc);
1955}
1956
1957class VoiceChannelTest
1958 : public ChannelTest<VoiceTraits> {
1959 public:
solenberg1dd98f32015-09-10 01:57:14 -07001960 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001961 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001962 : Base(true,
1963 kPcmuFrame,
1964 sizeof(kPcmuFrame),
1965 kRtcpReport,
1966 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967};
1968
1969// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001970template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001972 rtc::Thread* thread,
1973 cricket::MediaEngineInterface* engine,
1974 cricket::FakeVideoMediaChannel* ch,
1975 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 bool rtcp) {
1977 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001978 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 if (!channel->Init()) {
1980 delete channel;
1981 channel = NULL;
1982 }
1983 return channel;
1984}
1985
1986// override to add 0 parameter
1987template<>
1988bool ChannelTest<VideoTraits>::AddStream1(int id) {
1989 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1990}
1991
1992template<>
1993void ChannelTest<VideoTraits>::CreateContent(
1994 int flags,
1995 const cricket::AudioCodec& audio_codec,
1996 const cricket::VideoCodec& video_codec,
1997 cricket::VideoContentDescription* video) {
1998 video->AddCodec(video_codec);
1999 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2000 if (flags & SECURE) {
2001 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002002 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
2003 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 }
2005}
2006
2007template<>
2008void ChannelTest<VideoTraits>::CopyContent(
2009 const cricket::VideoContentDescription& source,
2010 cricket::VideoContentDescription* video) {
2011 *video = source;
2012}
2013
2014template<>
2015bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2016 const cricket::VideoCodec& c2) {
2017 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2018 c1.framerate == c2.framerate;
2019}
2020
Peter Boström0c4e06b2015-10-07 12:23:21 +02002021template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002023 uint32_t ssrc,
2024 int flags,
2025 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 video->AddLegacyStream(ssrc);
2027}
2028
2029class VideoChannelTest
2030 : public ChannelTest<VideoTraits> {
2031 public:
solenberg1dd98f32015-09-10 01:57:14 -07002032 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07002033 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02002034 : Base(false,
2035 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07002036 sizeof(kH264Packet),
2037 kRtcpReport,
2038 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039};
2040
2041
2042// VoiceChannelTest
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043TEST_F(VoiceChannelTest, TestInit) {
2044 Base::TestInit();
2045 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2046 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2047}
2048
2049TEST_F(VoiceChannelTest, TestSetContents) {
2050 Base::TestSetContents();
2051}
2052
2053TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2054 Base::TestSetContentsNullOffer();
2055}
2056
2057TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2058 Base::TestSetContentsRtcpMux();
2059}
2060
2061TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2062 Base::TestSetContentsRtcpMux();
2063}
2064
2065TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2066 Base::TestSetRemoteContentUpdate();
2067}
2068
2069TEST_F(VoiceChannelTest, TestStreams) {
2070 Base::TestStreams();
2071}
2072
2073TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2074 Base::TestUpdateStreamsInLocalContent();
2075}
2076
2077TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2078 Base::TestUpdateStreamsInRemoteContent();
2079}
2080
2081TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2082 Base::TestChangeStreamParamsInContent();
2083}
2084
2085TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2086 Base::TestPlayoutAndSendingStates();
2087}
2088
2089TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002090 CreateChannels(0, 0);
2091 // Test that we can Mute the default channel even though the sending SSRC
2092 // is unknown.
2093 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002094 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002095 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2096 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002097 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2098
2099 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002100 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002101
2102 SendInitiate();
2103 // After the local session description has been set, we can mute a stream
2104 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002105 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002106 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2107 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002108 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109}
2110
2111TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2112 Base::TestMediaContentDirection();
2113}
2114
Honghai Zhangcc411c02016-03-29 17:27:21 -07002115TEST_F(VoiceChannelTest, TestNetworkRouteChanges) {
2116 Base::TestNetworkRouteChanges();
2117}
2118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119TEST_F(VoiceChannelTest, TestCallSetup) {
2120 Base::TestCallSetup();
2121}
2122
2123TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2124 Base::TestCallTeardownRtcpMux();
2125}
2126
2127TEST_F(VoiceChannelTest, SendRtpToRtp) {
2128 Base::SendRtpToRtp();
2129}
2130
2131TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2132 Base::SendNoRtcpToNoRtcp();
2133}
2134
2135TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2136 Base::SendNoRtcpToRtcp();
2137}
2138
2139TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2140 Base::SendRtcpToNoRtcp();
2141}
2142
2143TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2144 Base::SendRtcpToRtcp();
2145}
2146
2147TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2148 Base::SendRtcpMuxToRtcp();
2149}
2150
2151TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2152 Base::SendRtcpMuxToRtcpMux();
2153}
2154
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002155TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2156 Base::SendRequireRtcpMuxToRtcpMux();
2157}
2158
2159TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2160 Base::SendRtcpMuxToRequireRtcpMux();
2161}
2162
2163TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2164 Base::SendRequireRtcpMuxToRequireRtcpMux();
2165}
2166
2167TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2168 Base::SendRequireRtcpMuxToNoRtcpMux();
2169}
2170
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2172 Base::SendEarlyRtcpMuxToRtcp();
2173}
2174
2175TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2176 Base::SendEarlyRtcpMuxToRtcpMux();
2177}
2178
2179TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2180 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2181}
2182
2183TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2184 Base::SendSrtpToSrtp();
2185}
2186
2187TEST_F(VoiceChannelTest, SendSrtcpMux) {
2188 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2189}
2190
2191TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2192 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2193 Base::SendSrtpToSrtp(DTLS, 0);
2194}
2195
2196TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2197 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2198 Base::SendSrtpToSrtp(DTLS, DTLS);
2199}
2200
2201TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2202 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2203 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2204}
2205
2206TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2207 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2208}
2209
2210TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2211 Base::SendRtpToRtpOnThread();
2212}
2213
2214TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2215 Base::SendSrtpToSrtpOnThread();
2216}
2217
2218TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2219 Base::SendWithWritabilityLoss();
2220}
2221
2222TEST_F(VoiceChannelTest, TestMediaMonitor) {
2223 Base::TestMediaMonitor();
2224}
2225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226// Test that InsertDtmf properly forwards to the media channel.
2227TEST_F(VoiceChannelTest, TestInsertDtmf) {
2228 CreateChannels(0, 0);
2229 EXPECT_TRUE(SendInitiate());
2230 EXPECT_TRUE(SendAccept());
2231 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2232
solenberg1d63dd02015-12-02 12:35:09 -08002233 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2234 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2235 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002237 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002239 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002240 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002241 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002242 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002243 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244}
2245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246TEST_F(VoiceChannelTest, TestSetContentFailure) {
2247 Base::TestSetContentFailure();
2248}
2249
2250TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2251 Base::TestSendTwoOffers();
2252}
2253
2254TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2255 Base::TestReceiveTwoOffers();
2256}
2257
2258TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2259 Base::TestSendPrAnswer();
2260}
2261
2262TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2263 Base::TestReceivePrAnswer();
2264}
2265
2266TEST_F(VoiceChannelTest, TestFlushRtcp) {
2267 Base::TestFlushRtcp();
2268}
2269
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002271 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272}
2273
2274TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2275 Base::TestOnReadyToSend();
2276}
2277
2278TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2279 Base::TestOnReadyToSendWithRtcpMux();
2280}
2281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282// Test that we can scale the output volume properly for 1:1 calls.
2283TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2284 CreateChannels(RTCP, RTCP);
2285 EXPECT_TRUE(SendInitiate());
2286 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002287 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288
solenberg4bac9c52015-10-09 02:32:53 -07002289 // Default is (1.0).
2290 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2291 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002293 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294
solenberg4bac9c52015-10-09 02:32:53 -07002295 // Set scale to (1.5).
2296 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2297 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2298 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299
solenberg4bac9c52015-10-09 02:32:53 -07002300 // Set scale to (0).
2301 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2302 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2303 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304}
2305
2306// Test that we can scale the output volume properly for multiway calls.
2307TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2308 CreateChannels(RTCP, RTCP);
2309 EXPECT_TRUE(SendInitiate());
2310 EXPECT_TRUE(SendAccept());
2311 EXPECT_TRUE(AddStream1(1));
2312 EXPECT_TRUE(AddStream1(2));
2313
solenberg4bac9c52015-10-09 02:32:53 -07002314 double volume;
2315 // Default is (1.0).
2316 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2317 EXPECT_DOUBLE_EQ(1.0, volume);
2318 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2319 EXPECT_DOUBLE_EQ(1.0, volume);
2320 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2321 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002323 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324
solenberg4bac9c52015-10-09 02:32:53 -07002325 // Set scale to (1.5) for ssrc = 1.
2326 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2327 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2328 EXPECT_DOUBLE_EQ(1.5, volume);
2329 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2330 EXPECT_DOUBLE_EQ(1.0, volume);
2331 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2332 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333
solenberg4bac9c52015-10-09 02:32:53 -07002334 // Set scale to (0) for all ssrcs.
2335 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2336 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2337 EXPECT_DOUBLE_EQ(0.0, volume);
2338 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2339 EXPECT_DOUBLE_EQ(0.0, volume);
2340 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2341 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342}
2343
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002344TEST_F(VoiceChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002345 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346}
2347
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002348TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002349 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002350}
2351
2352TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002353 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002354}
2355
2356TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002357 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358}
2359
skvlade0d46372016-04-07 22:59:22 -07002360TEST_F(VoiceChannelTest, DefaultMaxBitrateIsUnlimited) {
2361 Base::DefaultMaxBitrateIsUnlimited();
skvladdc1c62c2016-03-16 19:07:43 -07002362}
2363
skvlade0d46372016-04-07 22:59:22 -07002364TEST_F(VoiceChannelTest, CanChangeMaxBitrate) {
2365 Base::CanChangeMaxBitrate();
skvladdc1c62c2016-03-16 19:07:43 -07002366}
2367
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368// VideoChannelTest
2369TEST_F(VideoChannelTest, TestInit) {
2370 Base::TestInit();
2371}
2372
2373TEST_F(VideoChannelTest, TestSetContents) {
2374 Base::TestSetContents();
2375}
2376
2377TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2378 Base::TestSetContentsNullOffer();
2379}
2380
2381TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2382 Base::TestSetContentsRtcpMux();
2383}
2384
2385TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2386 Base::TestSetContentsRtcpMux();
2387}
2388
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002389TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2390 Base::TestSetRemoteContentUpdate();
2391}
2392
2393TEST_F(VideoChannelTest, TestStreams) {
2394 Base::TestStreams();
2395}
2396
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2398 Base::TestUpdateStreamsInLocalContent();
2399}
2400
2401TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2402 Base::TestUpdateStreamsInRemoteContent();
2403}
2404
2405TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2406 Base::TestChangeStreamParamsInContent();
2407}
2408
2409TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2410 Base::TestPlayoutAndSendingStates();
2411}
2412
2413TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002414 CreateChannels(0, 0);
2415 // Test that we can Mute the default channel even though the sending SSRC
2416 // is unknown.
2417 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002418 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002419 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2420 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002421 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2422 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002423 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002424 SendInitiate();
2425 // After the local session description has been set, we can mute a stream
2426 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002427 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002428 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2429 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002430 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431}
2432
2433TEST_F(VideoChannelTest, TestMediaContentDirection) {
2434 Base::TestMediaContentDirection();
2435}
2436
Honghai Zhangcc411c02016-03-29 17:27:21 -07002437TEST_F(VideoChannelTest, TestNetworkRouteChanges) {
2438 Base::TestNetworkRouteChanges();
2439}
2440
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441TEST_F(VideoChannelTest, TestCallSetup) {
2442 Base::TestCallSetup();
2443}
2444
2445TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2446 Base::TestCallTeardownRtcpMux();
2447}
2448
2449TEST_F(VideoChannelTest, SendRtpToRtp) {
2450 Base::SendRtpToRtp();
2451}
2452
2453TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2454 Base::SendNoRtcpToNoRtcp();
2455}
2456
2457TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2458 Base::SendNoRtcpToRtcp();
2459}
2460
2461TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2462 Base::SendRtcpToNoRtcp();
2463}
2464
2465TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2466 Base::SendRtcpToRtcp();
2467}
2468
2469TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2470 Base::SendRtcpMuxToRtcp();
2471}
2472
2473TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2474 Base::SendRtcpMuxToRtcpMux();
2475}
2476
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002477TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2478 Base::SendRequireRtcpMuxToRtcpMux();
2479}
2480
2481TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2482 Base::SendRtcpMuxToRequireRtcpMux();
2483}
2484
2485TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2486 Base::SendRequireRtcpMuxToRequireRtcpMux();
2487}
2488
2489TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2490 Base::SendRequireRtcpMuxToNoRtcpMux();
2491}
2492
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2494 Base::SendEarlyRtcpMuxToRtcp();
2495}
2496
2497TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2498 Base::SendEarlyRtcpMuxToRtcpMux();
2499}
2500
2501TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2502 Base::SendSrtpToSrtp();
2503}
2504
2505TEST_F(VideoChannelTest, SendSrtpToRtp) {
2506 Base::SendSrtpToSrtp();
2507}
2508
2509TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2510 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2511 Base::SendSrtpToSrtp(DTLS, 0);
2512}
2513
2514TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2515 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2516 Base::SendSrtpToSrtp(DTLS, DTLS);
2517}
2518
2519TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2520 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2521 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2522}
2523
2524TEST_F(VideoChannelTest, SendSrtcpMux) {
2525 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2526}
2527
2528TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2529 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2530}
2531
2532TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2533 Base::SendRtpToRtpOnThread();
2534}
2535
2536TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2537 Base::SendSrtpToSrtpOnThread();
2538}
2539
2540TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2541 Base::SendWithWritabilityLoss();
2542}
2543
2544TEST_F(VideoChannelTest, TestMediaMonitor) {
2545 Base::TestMediaMonitor();
2546}
2547
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548TEST_F(VideoChannelTest, TestSetContentFailure) {
2549 Base::TestSetContentFailure();
2550}
2551
2552TEST_F(VideoChannelTest, TestSendTwoOffers) {
2553 Base::TestSendTwoOffers();
2554}
2555
2556TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2557 Base::TestReceiveTwoOffers();
2558}
2559
2560TEST_F(VideoChannelTest, TestSendPrAnswer) {
2561 Base::TestSendPrAnswer();
2562}
2563
2564TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2565 Base::TestReceivePrAnswer();
2566}
2567
2568TEST_F(VideoChannelTest, TestFlushRtcp) {
2569 Base::TestFlushRtcp();
2570}
2571
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002572TEST_F(VideoChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002573 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574}
2575
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002576TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002577 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002578}
2579
2580TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002581 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002582}
2583
2584TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002585 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586}
2587
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002589 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590}
2591
2592TEST_F(VideoChannelTest, TestOnReadyToSend) {
2593 Base::TestOnReadyToSend();
2594}
2595
2596TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2597 Base::TestOnReadyToSendWithRtcpMux();
2598}
2599
skvladdc1c62c2016-03-16 19:07:43 -07002600TEST_F(VideoChannelTest, DefaultMaxBitrateIsUnlimited) {
2601 Base::DefaultMaxBitrateIsUnlimited();
2602}
2603
2604TEST_F(VideoChannelTest, CanChangeMaxBitrate) {
2605 Base::CanChangeMaxBitrate();
2606}
2607
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608// DataChannelTest
2609
2610class DataChannelTest
2611 : public ChannelTest<DataTraits> {
2612 public:
2613 typedef ChannelTest<DataTraits>
2614 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002615 DataChannelTest()
2616 : Base(true,
2617 kDataPacket,
2618 sizeof(kDataPacket),
2619 kRtcpReport,
2620 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621};
2622
2623// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002624template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002626 rtc::Thread* thread,
2627 cricket::MediaEngineInterface* engine,
2628 cricket::FakeDataMediaChannel* ch,
2629 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630 bool rtcp) {
2631 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002632 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 if (!channel->Init()) {
2634 delete channel;
2635 channel = NULL;
2636 }
2637 return channel;
2638}
2639
2640template<>
2641void ChannelTest<DataTraits>::CreateContent(
2642 int flags,
2643 const cricket::AudioCodec& audio_codec,
2644 const cricket::VideoCodec& video_codec,
2645 cricket::DataContentDescription* data) {
2646 data->AddCodec(kGoogleDataCodec);
2647 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2648 if (flags & SECURE) {
2649 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002650 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2651 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 }
2653}
2654
2655template<>
2656void ChannelTest<DataTraits>::CopyContent(
2657 const cricket::DataContentDescription& source,
2658 cricket::DataContentDescription* data) {
2659 *data = source;
2660}
2661
2662template<>
2663bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2664 const cricket::DataCodec& c2) {
2665 return c1.name == c2.name;
2666}
2667
Peter Boström0c4e06b2015-10-07 12:23:21 +02002668template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002670 uint32_t ssrc,
2671 int flags,
2672 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673 data->AddLegacyStream(ssrc);
2674}
2675
2676TEST_F(DataChannelTest, TestInit) {
2677 Base::TestInit();
2678 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2679}
2680
2681TEST_F(DataChannelTest, TestSetContents) {
2682 Base::TestSetContents();
2683}
2684
2685TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2686 Base::TestSetContentsNullOffer();
2687}
2688
2689TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2690 Base::TestSetContentsRtcpMux();
2691}
2692
2693TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2694 Base::TestSetRemoteContentUpdate();
2695}
2696
2697TEST_F(DataChannelTest, TestStreams) {
2698 Base::TestStreams();
2699}
2700
2701TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2702 Base::TestUpdateStreamsInLocalContent();
2703}
2704
2705TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2706 Base::TestUpdateStreamsInRemoteContent();
2707}
2708
2709TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2710 Base::TestChangeStreamParamsInContent();
2711}
2712
2713TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2714 Base::TestPlayoutAndSendingStates();
2715}
2716
2717TEST_F(DataChannelTest, TestMediaContentDirection) {
2718 Base::TestMediaContentDirection();
2719}
2720
2721TEST_F(DataChannelTest, TestCallSetup) {
2722 Base::TestCallSetup();
2723}
2724
2725TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2726 Base::TestCallTeardownRtcpMux();
2727}
2728
2729TEST_F(DataChannelTest, TestOnReadyToSend) {
2730 Base::TestOnReadyToSend();
2731}
2732
2733TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2734 Base::TestOnReadyToSendWithRtcpMux();
2735}
2736
2737TEST_F(DataChannelTest, SendRtpToRtp) {
2738 Base::SendRtpToRtp();
2739}
2740
2741TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2742 Base::SendNoRtcpToNoRtcp();
2743}
2744
2745TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2746 Base::SendNoRtcpToRtcp();
2747}
2748
2749TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2750 Base::SendRtcpToNoRtcp();
2751}
2752
2753TEST_F(DataChannelTest, SendRtcpToRtcp) {
2754 Base::SendRtcpToRtcp();
2755}
2756
2757TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2758 Base::SendRtcpMuxToRtcp();
2759}
2760
2761TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2762 Base::SendRtcpMuxToRtcpMux();
2763}
2764
2765TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2766 Base::SendEarlyRtcpMuxToRtcp();
2767}
2768
2769TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2770 Base::SendEarlyRtcpMuxToRtcpMux();
2771}
2772
2773TEST_F(DataChannelTest, SendSrtpToSrtp) {
2774 Base::SendSrtpToSrtp();
2775}
2776
2777TEST_F(DataChannelTest, SendSrtpToRtp) {
2778 Base::SendSrtpToSrtp();
2779}
2780
2781TEST_F(DataChannelTest, SendSrtcpMux) {
2782 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2783}
2784
2785TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2786 Base::SendRtpToRtpOnThread();
2787}
2788
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002789TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2790 Base::SendSrtpToSrtpOnThread();
2791}
2792
2793TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2794 Base::SendWithWritabilityLoss();
2795}
2796
2797TEST_F(DataChannelTest, TestMediaMonitor) {
2798 Base::TestMediaMonitor();
2799}
2800
2801TEST_F(DataChannelTest, TestSendData) {
2802 CreateChannels(0, 0);
2803 EXPECT_TRUE(SendInitiate());
2804 EXPECT_TRUE(SendAccept());
2805
2806 cricket::SendDataParams params;
2807 params.ssrc = 42;
2808 unsigned char data[] = {
2809 'f', 'o', 'o'
2810 };
jbaucheec21bd2016-03-20 06:15:43 -07002811 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812 cricket::SendDataResult result;
2813 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2814 EXPECT_EQ(params.ssrc,
2815 media_channel1_->last_sent_data_params().ssrc);
2816 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2817}
2818
2819// TODO(pthatcher): TestSetReceiver?