blob: 9d20def32f2c60bf9b5b307c605497ed9961ad9e [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
51static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
52static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
53static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
54static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
55static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
56static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
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(
165 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
166 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(
171 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
172 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,
973 nullptr);
974 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;
983 rtc::scoped_ptr<cricket::CandidatePairInterface> candidate_pair(
984 transport_controller1_.CreateFakeCandidatePair(
985 local_address, local_net_id, remote_address, remote_net_id));
986 transport_channel1->SignalSelectedCandidatePairChanged(
987 transport_channel1, candidate_pair.get());
988 EXPECT_EQ(1, media_channel1_->num_network_route_changes());
989 cricket::NetworkRoute expected_network_route(local_net_id, remote_net_id);
990 EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
991 }
992
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 // Test setting up a call.
994 void TestCallSetup() {
995 CreateChannels(0, 0);
996 EXPECT_FALSE(channel1_->secure());
997 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200998 if (verify_playout_) {
999 EXPECT_TRUE(media_channel1_->playout());
1000 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001001 EXPECT_FALSE(media_channel1_->sending());
1002 EXPECT_TRUE(SendAccept());
1003 EXPECT_FALSE(channel1_->secure());
1004 EXPECT_TRUE(media_channel1_->sending());
1005 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +02001006 if (verify_playout_) {
1007 EXPECT_TRUE(media_channel2_->playout());
1008 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 EXPECT_TRUE(media_channel2_->sending());
1010 EXPECT_EQ(1U, media_channel2_->codecs().size());
1011 }
1012
1013 // Test that we don't crash if packets are sent during call teardown
1014 // when RTCP mux is enabled. This is a regression test against a specific
1015 // race condition that would only occur when a RTCP packet was sent during
1016 // teardown of a channel on which RTCP mux was enabled.
1017 void TestCallTeardownRtcpMux() {
1018 class LastWordMediaChannel : public T::MediaChannel {
1019 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +02001020 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -07001022 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
1023 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1025 }
1026 };
1027 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1028 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001029 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030 EXPECT_TRUE(SendInitiate());
1031 EXPECT_TRUE(SendAccept());
1032 EXPECT_TRUE(SendTerminate());
1033 }
1034
1035 // Send voice RTP data to the other side and ensure it gets there.
1036 void SendRtpToRtp() {
1037 CreateChannels(0, 0);
1038 EXPECT_TRUE(SendInitiate());
1039 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001040 ASSERT_TRUE(GetTransport1());
1041 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042 EXPECT_EQ(1U, GetTransport1()->channels().size());
1043 EXPECT_EQ(1U, GetTransport2()->channels().size());
1044 EXPECT_TRUE(SendRtp1());
1045 EXPECT_TRUE(SendRtp2());
1046 EXPECT_TRUE(CheckRtp1());
1047 EXPECT_TRUE(CheckRtp2());
1048 EXPECT_TRUE(CheckNoRtp1());
1049 EXPECT_TRUE(CheckNoRtp2());
1050 }
1051
1052 // Check that RTCP is not transmitted if both sides don't support RTCP.
1053 void SendNoRtcpToNoRtcp() {
1054 CreateChannels(0, 0);
1055 EXPECT_TRUE(SendInitiate());
1056 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001057 ASSERT_TRUE(GetTransport1());
1058 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 EXPECT_EQ(1U, GetTransport1()->channels().size());
1060 EXPECT_EQ(1U, GetTransport2()->channels().size());
1061 EXPECT_FALSE(SendRtcp1());
1062 EXPECT_FALSE(SendRtcp2());
1063 EXPECT_TRUE(CheckNoRtcp1());
1064 EXPECT_TRUE(CheckNoRtcp2());
1065 }
1066
1067 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1068 void SendNoRtcpToRtcp() {
1069 CreateChannels(0, RTCP);
1070 EXPECT_TRUE(SendInitiate());
1071 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001072 ASSERT_TRUE(GetTransport1());
1073 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 EXPECT_EQ(1U, GetTransport1()->channels().size());
1075 EXPECT_EQ(2U, GetTransport2()->channels().size());
1076 EXPECT_FALSE(SendRtcp1());
1077 EXPECT_FALSE(SendRtcp2());
1078 EXPECT_TRUE(CheckNoRtcp1());
1079 EXPECT_TRUE(CheckNoRtcp2());
1080 }
1081
1082 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1083 void SendRtcpToNoRtcp() {
1084 CreateChannels(RTCP, 0);
1085 EXPECT_TRUE(SendInitiate());
1086 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001087 ASSERT_TRUE(GetTransport1());
1088 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 EXPECT_EQ(2U, GetTransport1()->channels().size());
1090 EXPECT_EQ(1U, GetTransport2()->channels().size());
1091 EXPECT_FALSE(SendRtcp1());
1092 EXPECT_FALSE(SendRtcp2());
1093 EXPECT_TRUE(CheckNoRtcp1());
1094 EXPECT_TRUE(CheckNoRtcp2());
1095 }
1096
1097 // Check that RTCP is transmitted if both sides support RTCP.
1098 void SendRtcpToRtcp() {
1099 CreateChannels(RTCP, RTCP);
1100 EXPECT_TRUE(SendInitiate());
1101 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001102 ASSERT_TRUE(GetTransport1());
1103 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 EXPECT_EQ(2U, GetTransport1()->channels().size());
1105 EXPECT_EQ(2U, GetTransport2()->channels().size());
1106 EXPECT_TRUE(SendRtcp1());
1107 EXPECT_TRUE(SendRtcp2());
1108 EXPECT_TRUE(CheckRtcp1());
1109 EXPECT_TRUE(CheckRtcp2());
1110 EXPECT_TRUE(CheckNoRtcp1());
1111 EXPECT_TRUE(CheckNoRtcp2());
1112 }
1113
1114 // Check that RTCP is transmitted if only the initiator supports mux.
1115 void SendRtcpMuxToRtcp() {
1116 CreateChannels(RTCP | RTCP_MUX, RTCP);
1117 EXPECT_TRUE(SendInitiate());
1118 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001119 ASSERT_TRUE(GetTransport1());
1120 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 EXPECT_EQ(2U, GetTransport1()->channels().size());
1122 EXPECT_EQ(2U, GetTransport2()->channels().size());
1123 EXPECT_TRUE(SendRtcp1());
1124 EXPECT_TRUE(SendRtcp2());
1125 EXPECT_TRUE(CheckRtcp1());
1126 EXPECT_TRUE(CheckRtcp2());
1127 EXPECT_TRUE(CheckNoRtcp1());
1128 EXPECT_TRUE(CheckNoRtcp2());
1129 }
1130
1131 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1132 void SendRtcpMuxToRtcpMux() {
1133 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1134 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001135 ASSERT_TRUE(GetTransport1());
1136 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 EXPECT_EQ(2U, GetTransport1()->channels().size());
1138 EXPECT_EQ(1U, GetTransport2()->channels().size());
1139 EXPECT_TRUE(SendAccept());
1140 EXPECT_EQ(1U, GetTransport1()->channels().size());
1141 EXPECT_TRUE(SendRtp1());
1142 EXPECT_TRUE(SendRtp2());
1143 EXPECT_TRUE(SendRtcp1());
1144 EXPECT_TRUE(SendRtcp2());
1145 EXPECT_TRUE(CheckRtp1());
1146 EXPECT_TRUE(CheckRtp2());
1147 EXPECT_TRUE(CheckNoRtp1());
1148 EXPECT_TRUE(CheckNoRtp2());
1149 EXPECT_TRUE(CheckRtcp1());
1150 EXPECT_TRUE(CheckRtcp2());
1151 EXPECT_TRUE(CheckNoRtcp1());
1152 EXPECT_TRUE(CheckNoRtcp2());
1153 }
1154
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001155 // Check that RTP and RTCP are transmitted ok when both sides
1156 // support mux and one the offerer requires mux.
1157 void SendRequireRtcpMuxToRtcpMux() {
1158 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1159 channel1_->ActivateRtcpMux();
1160 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001161 ASSERT_TRUE(GetTransport1());
1162 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001163 EXPECT_EQ(1U, GetTransport1()->channels().size());
1164 EXPECT_EQ(1U, GetTransport2()->channels().size());
1165 EXPECT_TRUE(SendAccept());
1166 EXPECT_TRUE(SendRtp1());
1167 EXPECT_TRUE(SendRtp2());
1168 EXPECT_TRUE(SendRtcp1());
1169 EXPECT_TRUE(SendRtcp2());
1170 EXPECT_TRUE(CheckRtp1());
1171 EXPECT_TRUE(CheckRtp2());
1172 EXPECT_TRUE(CheckNoRtp1());
1173 EXPECT_TRUE(CheckNoRtp2());
1174 EXPECT_TRUE(CheckRtcp1());
1175 EXPECT_TRUE(CheckRtcp2());
1176 EXPECT_TRUE(CheckNoRtcp1());
1177 EXPECT_TRUE(CheckNoRtcp2());
1178 }
1179
1180 // Check that RTP and RTCP are transmitted ok when both sides
1181 // support mux and one the answerer requires rtcp mux.
1182 void SendRtcpMuxToRequireRtcpMux() {
1183 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1184 channel2_->ActivateRtcpMux();
1185 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001186 ASSERT_TRUE(GetTransport1());
1187 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001188 EXPECT_EQ(2U, GetTransport1()->channels().size());
1189 EXPECT_EQ(1U, GetTransport2()->channels().size());
1190 EXPECT_TRUE(SendAccept());
1191 EXPECT_EQ(1U, GetTransport1()->channels().size());
1192 EXPECT_TRUE(SendRtp1());
1193 EXPECT_TRUE(SendRtp2());
1194 EXPECT_TRUE(SendRtcp1());
1195 EXPECT_TRUE(SendRtcp2());
1196 EXPECT_TRUE(CheckRtp1());
1197 EXPECT_TRUE(CheckRtp2());
1198 EXPECT_TRUE(CheckNoRtp1());
1199 EXPECT_TRUE(CheckNoRtp2());
1200 EXPECT_TRUE(CheckRtcp1());
1201 EXPECT_TRUE(CheckRtcp2());
1202 EXPECT_TRUE(CheckNoRtcp1());
1203 EXPECT_TRUE(CheckNoRtcp2());
1204 }
1205
1206 // Check that RTP and RTCP are transmitted ok when both sides
1207 // require mux.
1208 void SendRequireRtcpMuxToRequireRtcpMux() {
1209 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1210 channel1_->ActivateRtcpMux();
1211 channel2_->ActivateRtcpMux();
1212 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001213 ASSERT_TRUE(GetTransport1());
1214 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001215 EXPECT_EQ(1U, GetTransport1()->channels().size());
1216 EXPECT_EQ(1U, GetTransport2()->channels().size());
1217 EXPECT_TRUE(SendAccept());
1218 EXPECT_EQ(1U, GetTransport1()->channels().size());
1219 EXPECT_TRUE(SendRtp1());
1220 EXPECT_TRUE(SendRtp2());
1221 EXPECT_TRUE(SendRtcp1());
1222 EXPECT_TRUE(SendRtcp2());
1223 EXPECT_TRUE(CheckRtp1());
1224 EXPECT_TRUE(CheckRtp2());
1225 EXPECT_TRUE(CheckNoRtp1());
1226 EXPECT_TRUE(CheckNoRtp2());
1227 EXPECT_TRUE(CheckRtcp1());
1228 EXPECT_TRUE(CheckRtcp2());
1229 EXPECT_TRUE(CheckNoRtcp1());
1230 EXPECT_TRUE(CheckNoRtcp2());
1231 }
1232
1233 // Check that SendAccept fails if the answerer doesn't support mux
1234 // and the offerer requires it.
1235 void SendRequireRtcpMuxToNoRtcpMux() {
1236 CreateChannels(RTCP | RTCP_MUX, RTCP);
1237 channel1_->ActivateRtcpMux();
1238 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001239 ASSERT_TRUE(GetTransport1());
1240 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001241 EXPECT_EQ(1U, GetTransport1()->channels().size());
1242 EXPECT_EQ(2U, GetTransport2()->channels().size());
1243 EXPECT_FALSE(SendAccept());
1244 }
1245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 // Check that RTCP data sent by the initiator before the accept is not muxed.
1247 void SendEarlyRtcpMuxToRtcp() {
1248 CreateChannels(RTCP | RTCP_MUX, RTCP);
1249 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001250 ASSERT_TRUE(GetTransport1());
1251 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 EXPECT_EQ(2U, GetTransport1()->channels().size());
1253 EXPECT_EQ(2U, GetTransport2()->channels().size());
1254
1255 // RTCP can be sent before the call is accepted, if the transport is ready.
1256 // It should not be muxed though, as the remote side doesn't support mux.
1257 EXPECT_TRUE(SendRtcp1());
1258 EXPECT_TRUE(CheckNoRtp2());
1259 EXPECT_TRUE(CheckRtcp2());
1260
1261 // Send RTCP packet from callee and verify that it is received.
1262 EXPECT_TRUE(SendRtcp2());
1263 EXPECT_TRUE(CheckNoRtp1());
1264 EXPECT_TRUE(CheckRtcp1());
1265
1266 // Complete call setup and ensure everything is still OK.
1267 EXPECT_TRUE(SendAccept());
1268 EXPECT_EQ(2U, GetTransport1()->channels().size());
1269 EXPECT_TRUE(SendRtcp1());
1270 EXPECT_TRUE(CheckRtcp2());
1271 EXPECT_TRUE(SendRtcp2());
1272 EXPECT_TRUE(CheckRtcp1());
1273 }
1274
1275
1276 // Check that RTCP data is not muxed until both sides have enabled muxing,
1277 // but that we properly demux before we get the accept message, since there
1278 // is a race between RTP data and the jingle accept.
1279 void SendEarlyRtcpMuxToRtcpMux() {
1280 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1281 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001282 ASSERT_TRUE(GetTransport1());
1283 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 EXPECT_EQ(2U, GetTransport1()->channels().size());
1285 EXPECT_EQ(1U, GetTransport2()->channels().size());
1286
1287 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1288 // we haven't yet received the accept that says we should mux.
1289 EXPECT_FALSE(SendRtcp1());
1290
1291 // Send muxed RTCP packet from callee and verify that it is received.
1292 EXPECT_TRUE(SendRtcp2());
1293 EXPECT_TRUE(CheckNoRtp1());
1294 EXPECT_TRUE(CheckRtcp1());
1295
1296 // Complete call setup and ensure everything is still OK.
1297 EXPECT_TRUE(SendAccept());
1298 EXPECT_EQ(1U, GetTransport1()->channels().size());
1299 EXPECT_TRUE(SendRtcp1());
1300 EXPECT_TRUE(CheckRtcp2());
1301 EXPECT_TRUE(SendRtcp2());
1302 EXPECT_TRUE(CheckRtcp1());
1303 }
1304
1305 // Test that we properly send SRTP with RTCP in both directions.
1306 // You can pass in DTLS and/or RTCP_MUX as flags.
1307 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1308 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1309 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1310
1311 int flags1 = RTCP | SECURE | flags1_in;
1312 int flags2 = RTCP | SECURE | flags2_in;
1313 bool dtls1 = !!(flags1_in & DTLS);
1314 bool dtls2 = !!(flags2_in & DTLS);
1315 CreateChannels(flags1, flags2);
1316 EXPECT_FALSE(channel1_->secure());
1317 EXPECT_FALSE(channel2_->secure());
1318 EXPECT_TRUE(SendInitiate());
1319 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1320 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1321 EXPECT_TRUE(SendAccept());
1322 EXPECT_TRUE(channel1_->secure());
1323 EXPECT_TRUE(channel2_->secure());
1324 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1325 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1326 EXPECT_TRUE(SendRtp1());
1327 EXPECT_TRUE(SendRtp2());
1328 EXPECT_TRUE(SendRtcp1());
1329 EXPECT_TRUE(SendRtcp2());
1330 EXPECT_TRUE(CheckRtp1());
1331 EXPECT_TRUE(CheckRtp2());
1332 EXPECT_TRUE(CheckNoRtp1());
1333 EXPECT_TRUE(CheckNoRtp2());
1334 EXPECT_TRUE(CheckRtcp1());
1335 EXPECT_TRUE(CheckRtcp2());
1336 EXPECT_TRUE(CheckNoRtcp1());
1337 EXPECT_TRUE(CheckNoRtcp2());
1338 }
1339
1340 // Test that we properly handling SRTP negotiating down to RTP.
1341 void SendSrtpToRtp() {
1342 CreateChannels(RTCP | SECURE, RTCP);
1343 EXPECT_FALSE(channel1_->secure());
1344 EXPECT_FALSE(channel2_->secure());
1345 EXPECT_TRUE(SendInitiate());
1346 EXPECT_TRUE(SendAccept());
1347 EXPECT_FALSE(channel1_->secure());
1348 EXPECT_FALSE(channel2_->secure());
1349 EXPECT_TRUE(SendRtp1());
1350 EXPECT_TRUE(SendRtp2());
1351 EXPECT_TRUE(SendRtcp1());
1352 EXPECT_TRUE(SendRtcp2());
1353 EXPECT_TRUE(CheckRtp1());
1354 EXPECT_TRUE(CheckRtp2());
1355 EXPECT_TRUE(CheckNoRtp1());
1356 EXPECT_TRUE(CheckNoRtp2());
1357 EXPECT_TRUE(CheckRtcp1());
1358 EXPECT_TRUE(CheckRtcp2());
1359 EXPECT_TRUE(CheckNoRtcp1());
1360 EXPECT_TRUE(CheckNoRtcp2());
1361 }
1362
1363 // Test that we can send and receive early media when a provisional answer is
1364 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1365 void SendEarlyMediaUsingRtcpMuxSrtp() {
1366 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1367
1368 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1369 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1370 EXPECT_TRUE(SendOffer());
1371 EXPECT_TRUE(SendProvisionalAnswer());
1372 EXPECT_TRUE(channel1_->secure());
1373 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001374 ASSERT_TRUE(GetTransport1());
1375 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001376 EXPECT_EQ(2U, GetTransport1()->channels().size());
1377 EXPECT_EQ(2U, GetTransport2()->channels().size());
1378 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1379 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1380 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1381 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1382
1383 // Send packets from callee and verify that it is received.
1384 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1385 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1386 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1387 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1388
1389 // Complete call setup and ensure everything is still OK.
1390 EXPECT_TRUE(SendFinalAnswer());
1391 EXPECT_EQ(1U, GetTransport1()->channels().size());
1392 EXPECT_EQ(1U, GetTransport2()->channels().size());
1393 EXPECT_TRUE(channel1_->secure());
1394 EXPECT_TRUE(channel2_->secure());
1395 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1396 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1397 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1398 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1399 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1400 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1401 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1402 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1403 }
1404
1405 // Test that we properly send RTP without SRTP from a thread.
1406 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001407 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 EXPECT_TRUE(SendInitiate());
1409 EXPECT_TRUE(SendAccept());
ossu292d6582016-03-17 02:31:13 -07001410 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
1411 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
1412 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
1413 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1415 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001416 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
1417 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 EXPECT_TRUE(CheckNoRtp1());
1419 EXPECT_TRUE(CheckNoRtp2());
1420 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1421 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001422 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
1423 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 EXPECT_TRUE(CheckNoRtcp1());
1425 EXPECT_TRUE(CheckNoRtcp2());
1426 }
1427
1428 // Test that we properly send SRTP with RTCP from a thread.
1429 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1431 EXPECT_TRUE(SendInitiate());
1432 EXPECT_TRUE(SendAccept());
ossu292d6582016-03-17 02:31:13 -07001433 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
1434 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
1435 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
1436 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1438 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001439 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
1440 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 EXPECT_TRUE(CheckNoRtp1());
1442 EXPECT_TRUE(CheckNoRtp2());
1443 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1444 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001445 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
1446 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 EXPECT_TRUE(CheckNoRtcp1());
1448 EXPECT_TRUE(CheckNoRtcp2());
1449 }
1450
1451 // Test that the mediachannel retains its sending state after the transport
1452 // becomes non-writable.
1453 void SendWithWritabilityLoss() {
1454 CreateChannels(0, 0);
1455 EXPECT_TRUE(SendInitiate());
1456 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001457 ASSERT_TRUE(GetTransport1());
1458 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 EXPECT_EQ(1U, GetTransport1()->channels().size());
1460 EXPECT_EQ(1U, GetTransport2()->channels().size());
1461 EXPECT_TRUE(SendRtp1());
1462 EXPECT_TRUE(SendRtp2());
1463 EXPECT_TRUE(CheckRtp1());
1464 EXPECT_TRUE(CheckRtp2());
1465 EXPECT_TRUE(CheckNoRtp1());
1466 EXPECT_TRUE(CheckNoRtp2());
1467
wu@webrtc.org97077a32013-10-25 21:18:33 +00001468 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 EXPECT_FALSE(SendRtp1());
1471 EXPECT_TRUE(SendRtp2());
1472 EXPECT_TRUE(CheckRtp1());
1473 EXPECT_TRUE(CheckNoRtp2());
1474
1475 // Regain writability
1476 GetTransport1()->SetWritable(true);
1477 EXPECT_TRUE(media_channel1_->sending());
1478 EXPECT_TRUE(SendRtp1());
1479 EXPECT_TRUE(SendRtp2());
1480 EXPECT_TRUE(CheckRtp1());
1481 EXPECT_TRUE(CheckRtp2());
1482 EXPECT_TRUE(CheckNoRtp1());
1483 EXPECT_TRUE(CheckNoRtp2());
1484
1485 // Lose writability completely
1486 GetTransport1()->SetDestination(NULL);
1487 EXPECT_TRUE(media_channel1_->sending());
1488
wu@webrtc.org97077a32013-10-25 21:18:33 +00001489 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001490 EXPECT_FALSE(SendRtp1());
1491 EXPECT_TRUE(SendRtp2());
1492 EXPECT_TRUE(CheckRtp1());
1493 EXPECT_TRUE(CheckNoRtp2());
1494
1495 // Gain writability back
1496 GetTransport1()->SetDestination(GetTransport2());
1497 EXPECT_TRUE(media_channel1_->sending());
1498 EXPECT_TRUE(SendRtp1());
1499 EXPECT_TRUE(SendRtp2());
1500 EXPECT_TRUE(CheckRtp1());
1501 EXPECT_TRUE(CheckRtp2());
1502 EXPECT_TRUE(CheckNoRtp1());
1503 EXPECT_TRUE(CheckNoRtp2());
1504 }
1505
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001506 void SendBundleToBundle(
1507 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1508 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001510 // Only pl_type1 was added to the bundle filter for both |channel1_|
1511 // and |channel2_|.
1512 int pl_type1 = pl_types[0];
1513 int pl_type2 = pl_types[1];
1514 int flags = SSRC_MUX | RTCP;
1515 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001516 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001517 if (rtcp_mux) {
1518 flags |= RTCP_MUX;
1519 expected_channels = 1U;
1520 }
1521 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001523 ASSERT_TRUE(GetTransport1());
1524 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001526 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001528 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1529 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1530 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1531 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1532 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1533 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001534
1535 // Both channels can receive pl_type1 only.
1536 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1537 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1538 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1539 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1540 EXPECT_TRUE(CheckNoRtp1());
1541 EXPECT_TRUE(CheckNoRtp2());
1542
1543 // RTCP test
1544 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1545 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1546 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1547 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1548
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1550 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1552 EXPECT_TRUE(CheckNoRtcp1());
1553 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1554 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001556 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1557 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
pbos482b12e2015-11-16 10:19:58 -08001558 // Bundle filter shouldn't filter out any RTCP.
1559 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1560 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 }
1562
1563 // Test that the media monitor can be run and gives timely callbacks.
1564 void TestMediaMonitor() {
1565 static const int kTimeout = 500;
1566 CreateChannels(0, 0);
1567 EXPECT_TRUE(SendInitiate());
1568 EXPECT_TRUE(SendAccept());
1569 channel1_->StartMediaMonitor(100);
1570 channel2_->StartMediaMonitor(100);
1571 // Ensure we get callbacks and stop.
1572 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1573 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1574 channel1_->StopMediaMonitor();
1575 channel2_->StopMediaMonitor();
1576 // Ensure a restart of a stopped monitor works.
1577 channel1_->StartMediaMonitor(100);
1578 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1579 channel1_->StopMediaMonitor();
1580 // Ensure stopping a stopped monitor is OK.
1581 channel1_->StopMediaMonitor();
1582 }
1583
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 void TestSetContentFailure() {
1585 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586
Peter Thatchera6d24442015-07-09 21:26:36 -07001587 auto sdesc = cricket::SessionDescription();
1588 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1589 new cricket::AudioContentDescription());
1590 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1591 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592
Peter Thatchera6d24442015-07-09 21:26:36 -07001593 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001595 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1596 &sdesc, cricket::CA_OFFER, &err));
1597 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1598 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001601 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1602 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001604 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1605 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 }
1607
1608 void TestSendTwoOffers() {
1609 CreateChannels(0, 0);
1610
Peter Thatchera6d24442015-07-09 21:26:36 -07001611 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001612 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001613 CreateSessionDescriptionWithStream(1));
1614 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1615 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1617
kwiberg31022942016-03-11 14:18:21 -08001618 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001619 CreateSessionDescriptionWithStream(2));
1620 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1621 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1623 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1624 }
1625
1626 void TestReceiveTwoOffers() {
1627 CreateChannels(0, 0);
1628
Peter Thatchera6d24442015-07-09 21:26:36 -07001629 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001630 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001631 CreateSessionDescriptionWithStream(1));
1632 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1633 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1635
kwiberg31022942016-03-11 14:18:21 -08001636 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001637 CreateSessionDescriptionWithStream(2));
1638 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1639 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1641 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1642 }
1643
1644 void TestSendPrAnswer() {
1645 CreateChannels(0, 0);
1646
Peter Thatchera6d24442015-07-09 21:26:36 -07001647 std::string err;
1648 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001649 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001650 CreateSessionDescriptionWithStream(1));
1651 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1652 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1654
Peter Thatchera6d24442015-07-09 21:26:36 -07001655 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001656 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001657 CreateSessionDescriptionWithStream(2));
1658 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1659 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1661 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1662
Peter Thatchera6d24442015-07-09 21:26:36 -07001663 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001664 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001665 CreateSessionDescriptionWithStream(3));
1666 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1667 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1669 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1670 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1671 }
1672
1673 void TestReceivePrAnswer() {
1674 CreateChannels(0, 0);
1675
Peter Thatchera6d24442015-07-09 21:26:36 -07001676 std::string err;
1677 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001678 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001679 CreateSessionDescriptionWithStream(1));
1680 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1681 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1683
Peter Thatchera6d24442015-07-09 21:26:36 -07001684 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001685 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001686 CreateSessionDescriptionWithStream(2));
1687 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1688 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1690 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1691
Peter Thatchera6d24442015-07-09 21:26:36 -07001692 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001693 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001694 CreateSessionDescriptionWithStream(3));
1695 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1696 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1698 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1699 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1700 }
1701
1702 void TestFlushRtcp() {
1703 bool send_rtcp1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 CreateChannels(RTCP, RTCP);
1705 EXPECT_TRUE(SendInitiate());
1706 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001707 ASSERT_TRUE(GetTransport1());
1708 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 EXPECT_EQ(2U, GetTransport1()->channels().size());
1710 EXPECT_EQ(2U, GetTransport2()->channels().size());
1711
1712 // Send RTCP1 from a different thread.
1713 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1714 EXPECT_TRUE(send_rtcp1);
1715 // The sending message is only posted. channel2_ should be empty.
1716 EXPECT_TRUE(CheckNoRtcp2());
1717
1718 // When channel1_ is deleted, the RTCP packet should be sent out to
1719 // channel2_.
1720 channel1_.reset();
1721 EXPECT_TRUE(CheckRtcp2());
1722 }
1723
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001724 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001725 struct SrtpErrorHandler : public sigslot::has_slots<> {
1726 SrtpErrorHandler() :
1727 mode_(cricket::SrtpFilter::UNPROTECT),
1728 error_(cricket::SrtpFilter::ERROR_NONE) {}
1729 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1730 cricket::SrtpFilter::Error error) {
1731 mode_ = mode;
1732 error_ = error;
1733 }
1734 cricket::SrtpFilter::Mode mode_;
1735 cricket::SrtpFilter::Error error_;
1736 } error_handler;
1737
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001738 // For Audio, only pl_type 0 is added to the bundle filter.
1739 // For Video, only pl_type 97 is added to the bundle filter.
1740 // So we need to pass in pl_type so that the packet can pass through
1741 // the bundle filter before it can be processed by the srtp filter.
1742 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001743 unsigned const char kBadPacket[] = {0x84,
1744 static_cast<unsigned char>(pl_type),
1745 0x00,
1746 0x01,
1747 0x00,
1748 0x00,
1749 0x00,
1750 0x00,
1751 0x00,
1752 0x00,
1753 0x00,
1754 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1756 EXPECT_FALSE(channel1_->secure());
1757 EXPECT_FALSE(channel2_->secure());
1758 EXPECT_TRUE(SendInitiate());
1759 EXPECT_TRUE(SendAccept());
1760 EXPECT_TRUE(channel1_->secure());
1761 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001762 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001763 channel2_->srtp_filter()->SignalSrtpError.connect(
1764 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765
1766 // Testing failures in sending packets.
stefanc1aeaf02015-10-15 07:26:07 -07001767 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1768 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001770 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1771 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1772 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001773 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1774 // The next 250 ms failures will not trigger an error.
stefanc1aeaf02015-10-15 07:26:07 -07001775 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1776 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001778 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001779 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001780 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1781 // Wait for a little more - the error will be triggered again.
1782 rtc::Thread::Current()->ProcessMessages(200);
stefanc1aeaf02015-10-15 07:26:07 -07001783 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1784 rtc::PacketOptions()));
solenberg5b14b422015-10-01 04:10:31 -07001785 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1786 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787
1788 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001789 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001790 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001791
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 cricket::TransportChannel* transport_channel =
1793 channel2_->transport_channel();
1794 transport_channel->SignalReadPacket(
1795 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001796 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001797 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1798 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 }
1800
1801 void TestOnReadyToSend() {
1802 CreateChannels(RTCP, RTCP);
1803 TransportChannel* rtp = channel1_->transport_channel();
1804 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1805 EXPECT_FALSE(media_channel1_->ready_to_send());
1806 rtp->SignalReadyToSend(rtp);
1807 EXPECT_FALSE(media_channel1_->ready_to_send());
1808 rtcp->SignalReadyToSend(rtcp);
1809 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1810 // channel are ready to send.
1811 EXPECT_TRUE(media_channel1_->ready_to_send());
1812
1813 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001814 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001816 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817 EXPECT_TRUE(media_channel1_->ready_to_send());
1818
1819 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001820 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001822 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 EXPECT_TRUE(media_channel1_->ready_to_send());
1824 }
1825
1826 void TestOnReadyToSendWithRtcpMux() {
1827 CreateChannels(RTCP, RTCP);
1828 typename T::Content content;
1829 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1830 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1831 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001832 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1833 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1835 TransportChannel* rtp = channel1_->transport_channel();
1836 EXPECT_FALSE(media_channel1_->ready_to_send());
1837 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1838 // should trigger the MediaChannel's OnReadyToSend.
1839 rtp->SignalReadyToSend(rtp);
1840 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001841 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 EXPECT_FALSE(media_channel1_->ready_to_send());
1843 }
1844
skvladdc1c62c2016-03-16 19:07:43 -07001845 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1846 typename T::Content content;
1847 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1848 content.set_bandwidth(remote_limit);
1849 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1850 }
1851
1852 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1853 webrtc::RtpParameters parameters;
1854 webrtc::RtpEncodingParameters encoding;
1855 encoding.max_bitrate_bps = limit;
1856 parameters.encodings.push_back(encoding);
1857 return parameters;
1858 }
1859
1860 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1861 int expected_bitrate) {
1862 EXPECT_EQ(1UL, parameters.encodings.size());
1863 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1864 }
1865
1866 void DefaultMaxBitrateIsUnlimited() {
1867 CreateChannels(0, 0);
1868 EXPECT_TRUE(
1869 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1870 EXPECT_EQ(media_channel1_->max_bps(), -1);
1871 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1);
1872 }
1873
1874 void CanChangeMaxBitrate() {
1875 CreateChannels(0, 0);
1876 EXPECT_TRUE(
1877 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1878
1879 EXPECT_TRUE(
1880 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(1000)));
1881 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), 1000);
1882 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), 1000);
1883 EXPECT_EQ(-1, media_channel1_->max_bps());
1884
1885 EXPECT_TRUE(
1886 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(-1)));
1887 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), -1);
1888 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1);
1889 EXPECT_EQ(-1, media_channel1_->max_bps());
1890 }
1891
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001893 // TODO(pbos): Remove playout from all media channels and let renderers mute
1894 // themselves.
1895 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001896 cricket::FakeTransportController transport_controller1_;
1897 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898 cricket::FakeMediaEngine media_engine_;
1899 // The media channels are owned by the voice channel objects below.
1900 typename T::MediaChannel* media_channel1_;
1901 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001902 std::unique_ptr<typename T::Channel> channel1_;
1903 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 typename T::Content local_media_content1_;
1905 typename T::Content local_media_content2_;
1906 typename T::Content remote_media_content1_;
1907 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 // The RTP and RTCP packets to send in the tests.
1909 std::string rtp_packet_;
1910 std::string rtcp_packet_;
1911 int media_info_callbacks1_;
1912 int media_info_callbacks2_;
Honghai Zhangcc411c02016-03-29 17:27:21 -07001913 cricket::CandidatePairInterface* last_selected_candidate_pair_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914};
1915
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916template<>
1917void ChannelTest<VoiceTraits>::CreateContent(
1918 int flags,
1919 const cricket::AudioCodec& audio_codec,
1920 const cricket::VideoCodec& video_codec,
1921 cricket::AudioContentDescription* audio) {
1922 audio->AddCodec(audio_codec);
1923 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1924 if (flags & SECURE) {
1925 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001926 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1927 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 }
1929}
1930
1931template<>
1932void ChannelTest<VoiceTraits>::CopyContent(
1933 const cricket::AudioContentDescription& source,
1934 cricket::AudioContentDescription* audio) {
1935 *audio = source;
1936}
1937
1938template<>
1939bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1940 const cricket::AudioCodec& c2) {
1941 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1942 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1943}
1944
Peter Boström0c4e06b2015-10-07 12:23:21 +02001945template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001947 uint32_t ssrc,
1948 int flags,
1949 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 audio->AddLegacyStream(ssrc);
1951}
1952
1953class VoiceChannelTest
1954 : public ChannelTest<VoiceTraits> {
1955 public:
solenberg1dd98f32015-09-10 01:57:14 -07001956 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001957 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001958 : Base(true,
1959 kPcmuFrame,
1960 sizeof(kPcmuFrame),
1961 kRtcpReport,
1962 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001963};
1964
1965// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001966template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001968 rtc::Thread* thread,
1969 cricket::MediaEngineInterface* engine,
1970 cricket::FakeVideoMediaChannel* ch,
1971 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 bool rtcp) {
1973 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001974 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 if (!channel->Init()) {
1976 delete channel;
1977 channel = NULL;
1978 }
1979 return channel;
1980}
1981
1982// override to add 0 parameter
1983template<>
1984bool ChannelTest<VideoTraits>::AddStream1(int id) {
1985 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1986}
1987
1988template<>
1989void ChannelTest<VideoTraits>::CreateContent(
1990 int flags,
1991 const cricket::AudioCodec& audio_codec,
1992 const cricket::VideoCodec& video_codec,
1993 cricket::VideoContentDescription* video) {
1994 video->AddCodec(video_codec);
1995 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1996 if (flags & SECURE) {
1997 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001998 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1999 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 }
2001}
2002
2003template<>
2004void ChannelTest<VideoTraits>::CopyContent(
2005 const cricket::VideoContentDescription& source,
2006 cricket::VideoContentDescription* video) {
2007 *video = source;
2008}
2009
2010template<>
2011bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2012 const cricket::VideoCodec& c2) {
2013 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2014 c1.framerate == c2.framerate;
2015}
2016
Peter Boström0c4e06b2015-10-07 12:23:21 +02002017template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002018void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002019 uint32_t ssrc,
2020 int flags,
2021 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 video->AddLegacyStream(ssrc);
2023}
2024
2025class VideoChannelTest
2026 : public ChannelTest<VideoTraits> {
2027 public:
solenberg1dd98f32015-09-10 01:57:14 -07002028 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07002029 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02002030 : Base(false,
2031 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07002032 sizeof(kH264Packet),
2033 kRtcpReport,
2034 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035};
2036
2037
2038// VoiceChannelTest
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039TEST_F(VoiceChannelTest, TestInit) {
2040 Base::TestInit();
2041 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2042 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2043}
2044
2045TEST_F(VoiceChannelTest, TestSetContents) {
2046 Base::TestSetContents();
2047}
2048
2049TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2050 Base::TestSetContentsNullOffer();
2051}
2052
2053TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2054 Base::TestSetContentsRtcpMux();
2055}
2056
2057TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2058 Base::TestSetContentsRtcpMux();
2059}
2060
2061TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2062 Base::TestSetRemoteContentUpdate();
2063}
2064
2065TEST_F(VoiceChannelTest, TestStreams) {
2066 Base::TestStreams();
2067}
2068
2069TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2070 Base::TestUpdateStreamsInLocalContent();
2071}
2072
2073TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2074 Base::TestUpdateStreamsInRemoteContent();
2075}
2076
2077TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2078 Base::TestChangeStreamParamsInContent();
2079}
2080
2081TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2082 Base::TestPlayoutAndSendingStates();
2083}
2084
2085TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002086 CreateChannels(0, 0);
2087 // Test that we can Mute the default channel even though the sending SSRC
2088 // is unknown.
2089 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002090 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002091 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2092 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002093 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2094
2095 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002096 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002097
2098 SendInitiate();
2099 // After the local session description has been set, we can mute a stream
2100 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002101 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002102 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2103 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002104 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105}
2106
2107TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2108 Base::TestMediaContentDirection();
2109}
2110
Honghai Zhangcc411c02016-03-29 17:27:21 -07002111TEST_F(VoiceChannelTest, TestNetworkRouteChanges) {
2112 Base::TestNetworkRouteChanges();
2113}
2114
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115TEST_F(VoiceChannelTest, TestCallSetup) {
2116 Base::TestCallSetup();
2117}
2118
2119TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2120 Base::TestCallTeardownRtcpMux();
2121}
2122
2123TEST_F(VoiceChannelTest, SendRtpToRtp) {
2124 Base::SendRtpToRtp();
2125}
2126
2127TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2128 Base::SendNoRtcpToNoRtcp();
2129}
2130
2131TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2132 Base::SendNoRtcpToRtcp();
2133}
2134
2135TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2136 Base::SendRtcpToNoRtcp();
2137}
2138
2139TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2140 Base::SendRtcpToRtcp();
2141}
2142
2143TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2144 Base::SendRtcpMuxToRtcp();
2145}
2146
2147TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2148 Base::SendRtcpMuxToRtcpMux();
2149}
2150
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002151TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2152 Base::SendRequireRtcpMuxToRtcpMux();
2153}
2154
2155TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2156 Base::SendRtcpMuxToRequireRtcpMux();
2157}
2158
2159TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2160 Base::SendRequireRtcpMuxToRequireRtcpMux();
2161}
2162
2163TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2164 Base::SendRequireRtcpMuxToNoRtcpMux();
2165}
2166
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2168 Base::SendEarlyRtcpMuxToRtcp();
2169}
2170
2171TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2172 Base::SendEarlyRtcpMuxToRtcpMux();
2173}
2174
2175TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2176 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2177}
2178
2179TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2180 Base::SendSrtpToSrtp();
2181}
2182
2183TEST_F(VoiceChannelTest, SendSrtcpMux) {
2184 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2185}
2186
2187TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2188 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2189 Base::SendSrtpToSrtp(DTLS, 0);
2190}
2191
2192TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2193 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2194 Base::SendSrtpToSrtp(DTLS, DTLS);
2195}
2196
2197TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2198 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2199 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2200}
2201
2202TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2203 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2204}
2205
2206TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2207 Base::SendRtpToRtpOnThread();
2208}
2209
2210TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2211 Base::SendSrtpToSrtpOnThread();
2212}
2213
2214TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2215 Base::SendWithWritabilityLoss();
2216}
2217
2218TEST_F(VoiceChannelTest, TestMediaMonitor) {
2219 Base::TestMediaMonitor();
2220}
2221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222// Test that InsertDtmf properly forwards to the media channel.
2223TEST_F(VoiceChannelTest, TestInsertDtmf) {
2224 CreateChannels(0, 0);
2225 EXPECT_TRUE(SendInitiate());
2226 EXPECT_TRUE(SendAccept());
2227 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2228
solenberg1d63dd02015-12-02 12:35:09 -08002229 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2230 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2231 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002233 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002235 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002236 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002237 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002238 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002239 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240}
2241
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242TEST_F(VoiceChannelTest, TestSetContentFailure) {
2243 Base::TestSetContentFailure();
2244}
2245
2246TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2247 Base::TestSendTwoOffers();
2248}
2249
2250TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2251 Base::TestReceiveTwoOffers();
2252}
2253
2254TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2255 Base::TestSendPrAnswer();
2256}
2257
2258TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2259 Base::TestReceivePrAnswer();
2260}
2261
2262TEST_F(VoiceChannelTest, TestFlushRtcp) {
2263 Base::TestFlushRtcp();
2264}
2265
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002267 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268}
2269
2270TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2271 Base::TestOnReadyToSend();
2272}
2273
2274TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2275 Base::TestOnReadyToSendWithRtcpMux();
2276}
2277
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278// Test that we can scale the output volume properly for 1:1 calls.
2279TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2280 CreateChannels(RTCP, RTCP);
2281 EXPECT_TRUE(SendInitiate());
2282 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002283 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284
solenberg4bac9c52015-10-09 02:32:53 -07002285 // Default is (1.0).
2286 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2287 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002289 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290
solenberg4bac9c52015-10-09 02:32:53 -07002291 // Set scale to (1.5).
2292 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2293 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2294 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295
solenberg4bac9c52015-10-09 02:32:53 -07002296 // Set scale to (0).
2297 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2298 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2299 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300}
2301
2302// Test that we can scale the output volume properly for multiway calls.
2303TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2304 CreateChannels(RTCP, RTCP);
2305 EXPECT_TRUE(SendInitiate());
2306 EXPECT_TRUE(SendAccept());
2307 EXPECT_TRUE(AddStream1(1));
2308 EXPECT_TRUE(AddStream1(2));
2309
solenberg4bac9c52015-10-09 02:32:53 -07002310 double volume;
2311 // Default is (1.0).
2312 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2313 EXPECT_DOUBLE_EQ(1.0, volume);
2314 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2315 EXPECT_DOUBLE_EQ(1.0, volume);
2316 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2317 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002319 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002320
solenberg4bac9c52015-10-09 02:32:53 -07002321 // Set scale to (1.5) for ssrc = 1.
2322 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2323 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2324 EXPECT_DOUBLE_EQ(1.5, volume);
2325 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2326 EXPECT_DOUBLE_EQ(1.0, volume);
2327 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2328 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329
solenberg4bac9c52015-10-09 02:32:53 -07002330 // Set scale to (0) for all ssrcs.
2331 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2332 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2333 EXPECT_DOUBLE_EQ(0.0, volume);
2334 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2335 EXPECT_DOUBLE_EQ(0.0, volume);
2336 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2337 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338}
2339
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002340TEST_F(VoiceChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002341 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342}
2343
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002344TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002345 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002346}
2347
2348TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002349 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002350}
2351
2352TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002353 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354}
2355
skvladdc1c62c2016-03-16 19:07:43 -07002356TEST_F(VoiceChannelTest, GetRtpParametersIsNotImplemented) {
2357 // These tests verify that the Get/SetRtpParameters methods for VoiceChannel
2358 // always fail as they are not implemented.
2359 // TODO(skvlad): Replace with full tests when support for bitrate limiting
2360 // for audio RtpSenders is added.
2361 CreateChannels(0, 0);
2362 EXPECT_TRUE(
2363 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
2364 webrtc::RtpParameters voice_parameters = channel1_->GetRtpParameters(kSsrc1);
2365 EXPECT_EQ(0UL, voice_parameters.encodings.size());
2366}
2367
2368TEST_F(VoiceChannelTest, SetRtpParametersIsNotImplemented) {
2369 CreateChannels(0, 0);
2370 EXPECT_TRUE(
2371 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
2372 EXPECT_FALSE(
2373 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(1000)));
2374}
2375
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376// VideoChannelTest
2377TEST_F(VideoChannelTest, TestInit) {
2378 Base::TestInit();
2379}
2380
2381TEST_F(VideoChannelTest, TestSetContents) {
2382 Base::TestSetContents();
2383}
2384
2385TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2386 Base::TestSetContentsNullOffer();
2387}
2388
2389TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2390 Base::TestSetContentsRtcpMux();
2391}
2392
2393TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2394 Base::TestSetContentsRtcpMux();
2395}
2396
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2398 Base::TestSetRemoteContentUpdate();
2399}
2400
2401TEST_F(VideoChannelTest, TestStreams) {
2402 Base::TestStreams();
2403}
2404
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2406 Base::TestUpdateStreamsInLocalContent();
2407}
2408
2409TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2410 Base::TestUpdateStreamsInRemoteContent();
2411}
2412
2413TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2414 Base::TestChangeStreamParamsInContent();
2415}
2416
2417TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2418 Base::TestPlayoutAndSendingStates();
2419}
2420
2421TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002422 CreateChannels(0, 0);
2423 // Test that we can Mute the default channel even though the sending SSRC
2424 // is unknown.
2425 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002426 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002427 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2428 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002429 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2430 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002431 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002432 SendInitiate();
2433 // After the local session description has been set, we can mute a stream
2434 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002435 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002436 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2437 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002438 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439}
2440
2441TEST_F(VideoChannelTest, TestMediaContentDirection) {
2442 Base::TestMediaContentDirection();
2443}
2444
Honghai Zhangcc411c02016-03-29 17:27:21 -07002445TEST_F(VideoChannelTest, TestNetworkRouteChanges) {
2446 Base::TestNetworkRouteChanges();
2447}
2448
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449TEST_F(VideoChannelTest, TestCallSetup) {
2450 Base::TestCallSetup();
2451}
2452
2453TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2454 Base::TestCallTeardownRtcpMux();
2455}
2456
2457TEST_F(VideoChannelTest, SendRtpToRtp) {
2458 Base::SendRtpToRtp();
2459}
2460
2461TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2462 Base::SendNoRtcpToNoRtcp();
2463}
2464
2465TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2466 Base::SendNoRtcpToRtcp();
2467}
2468
2469TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2470 Base::SendRtcpToNoRtcp();
2471}
2472
2473TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2474 Base::SendRtcpToRtcp();
2475}
2476
2477TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2478 Base::SendRtcpMuxToRtcp();
2479}
2480
2481TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2482 Base::SendRtcpMuxToRtcpMux();
2483}
2484
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002485TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2486 Base::SendRequireRtcpMuxToRtcpMux();
2487}
2488
2489TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2490 Base::SendRtcpMuxToRequireRtcpMux();
2491}
2492
2493TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2494 Base::SendRequireRtcpMuxToRequireRtcpMux();
2495}
2496
2497TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2498 Base::SendRequireRtcpMuxToNoRtcpMux();
2499}
2500
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2502 Base::SendEarlyRtcpMuxToRtcp();
2503}
2504
2505TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2506 Base::SendEarlyRtcpMuxToRtcpMux();
2507}
2508
2509TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2510 Base::SendSrtpToSrtp();
2511}
2512
2513TEST_F(VideoChannelTest, SendSrtpToRtp) {
2514 Base::SendSrtpToSrtp();
2515}
2516
2517TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2518 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2519 Base::SendSrtpToSrtp(DTLS, 0);
2520}
2521
2522TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2523 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2524 Base::SendSrtpToSrtp(DTLS, DTLS);
2525}
2526
2527TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2528 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2529 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2530}
2531
2532TEST_F(VideoChannelTest, SendSrtcpMux) {
2533 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2534}
2535
2536TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2537 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2538}
2539
2540TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2541 Base::SendRtpToRtpOnThread();
2542}
2543
2544TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2545 Base::SendSrtpToSrtpOnThread();
2546}
2547
2548TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2549 Base::SendWithWritabilityLoss();
2550}
2551
2552TEST_F(VideoChannelTest, TestMediaMonitor) {
2553 Base::TestMediaMonitor();
2554}
2555
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556TEST_F(VideoChannelTest, TestSetContentFailure) {
2557 Base::TestSetContentFailure();
2558}
2559
2560TEST_F(VideoChannelTest, TestSendTwoOffers) {
2561 Base::TestSendTwoOffers();
2562}
2563
2564TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2565 Base::TestReceiveTwoOffers();
2566}
2567
2568TEST_F(VideoChannelTest, TestSendPrAnswer) {
2569 Base::TestSendPrAnswer();
2570}
2571
2572TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2573 Base::TestReceivePrAnswer();
2574}
2575
2576TEST_F(VideoChannelTest, TestFlushRtcp) {
2577 Base::TestFlushRtcp();
2578}
2579
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002580TEST_F(VideoChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002581 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582}
2583
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002584TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002585 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002586}
2587
2588TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002589 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002590}
2591
2592TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002593 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594}
2595
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002597 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598}
2599
2600TEST_F(VideoChannelTest, TestOnReadyToSend) {
2601 Base::TestOnReadyToSend();
2602}
2603
2604TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2605 Base::TestOnReadyToSendWithRtcpMux();
2606}
2607
skvladdc1c62c2016-03-16 19:07:43 -07002608TEST_F(VideoChannelTest, DefaultMaxBitrateIsUnlimited) {
2609 Base::DefaultMaxBitrateIsUnlimited();
2610}
2611
2612TEST_F(VideoChannelTest, CanChangeMaxBitrate) {
2613 Base::CanChangeMaxBitrate();
2614}
2615
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616// DataChannelTest
2617
2618class DataChannelTest
2619 : public ChannelTest<DataTraits> {
2620 public:
2621 typedef ChannelTest<DataTraits>
2622 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002623 DataChannelTest()
2624 : Base(true,
2625 kDataPacket,
2626 sizeof(kDataPacket),
2627 kRtcpReport,
2628 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629};
2630
2631// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002632template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002634 rtc::Thread* thread,
2635 cricket::MediaEngineInterface* engine,
2636 cricket::FakeDataMediaChannel* ch,
2637 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 bool rtcp) {
2639 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002640 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641 if (!channel->Init()) {
2642 delete channel;
2643 channel = NULL;
2644 }
2645 return channel;
2646}
2647
2648template<>
2649void ChannelTest<DataTraits>::CreateContent(
2650 int flags,
2651 const cricket::AudioCodec& audio_codec,
2652 const cricket::VideoCodec& video_codec,
2653 cricket::DataContentDescription* data) {
2654 data->AddCodec(kGoogleDataCodec);
2655 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2656 if (flags & SECURE) {
2657 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002658 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2659 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 }
2661}
2662
2663template<>
2664void ChannelTest<DataTraits>::CopyContent(
2665 const cricket::DataContentDescription& source,
2666 cricket::DataContentDescription* data) {
2667 *data = source;
2668}
2669
2670template<>
2671bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2672 const cricket::DataCodec& c2) {
2673 return c1.name == c2.name;
2674}
2675
Peter Boström0c4e06b2015-10-07 12:23:21 +02002676template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002678 uint32_t ssrc,
2679 int flags,
2680 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681 data->AddLegacyStream(ssrc);
2682}
2683
2684TEST_F(DataChannelTest, TestInit) {
2685 Base::TestInit();
2686 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2687}
2688
2689TEST_F(DataChannelTest, TestSetContents) {
2690 Base::TestSetContents();
2691}
2692
2693TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2694 Base::TestSetContentsNullOffer();
2695}
2696
2697TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2698 Base::TestSetContentsRtcpMux();
2699}
2700
2701TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2702 Base::TestSetRemoteContentUpdate();
2703}
2704
2705TEST_F(DataChannelTest, TestStreams) {
2706 Base::TestStreams();
2707}
2708
2709TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2710 Base::TestUpdateStreamsInLocalContent();
2711}
2712
2713TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2714 Base::TestUpdateStreamsInRemoteContent();
2715}
2716
2717TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2718 Base::TestChangeStreamParamsInContent();
2719}
2720
2721TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2722 Base::TestPlayoutAndSendingStates();
2723}
2724
2725TEST_F(DataChannelTest, TestMediaContentDirection) {
2726 Base::TestMediaContentDirection();
2727}
2728
2729TEST_F(DataChannelTest, TestCallSetup) {
2730 Base::TestCallSetup();
2731}
2732
2733TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2734 Base::TestCallTeardownRtcpMux();
2735}
2736
2737TEST_F(DataChannelTest, TestOnReadyToSend) {
2738 Base::TestOnReadyToSend();
2739}
2740
2741TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2742 Base::TestOnReadyToSendWithRtcpMux();
2743}
2744
2745TEST_F(DataChannelTest, SendRtpToRtp) {
2746 Base::SendRtpToRtp();
2747}
2748
2749TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2750 Base::SendNoRtcpToNoRtcp();
2751}
2752
2753TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2754 Base::SendNoRtcpToRtcp();
2755}
2756
2757TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2758 Base::SendRtcpToNoRtcp();
2759}
2760
2761TEST_F(DataChannelTest, SendRtcpToRtcp) {
2762 Base::SendRtcpToRtcp();
2763}
2764
2765TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2766 Base::SendRtcpMuxToRtcp();
2767}
2768
2769TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2770 Base::SendRtcpMuxToRtcpMux();
2771}
2772
2773TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2774 Base::SendEarlyRtcpMuxToRtcp();
2775}
2776
2777TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2778 Base::SendEarlyRtcpMuxToRtcpMux();
2779}
2780
2781TEST_F(DataChannelTest, SendSrtpToSrtp) {
2782 Base::SendSrtpToSrtp();
2783}
2784
2785TEST_F(DataChannelTest, SendSrtpToRtp) {
2786 Base::SendSrtpToSrtp();
2787}
2788
2789TEST_F(DataChannelTest, SendSrtcpMux) {
2790 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2791}
2792
2793TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2794 Base::SendRtpToRtpOnThread();
2795}
2796
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002797TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2798 Base::SendSrtpToSrtpOnThread();
2799}
2800
2801TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2802 Base::SendWithWritabilityLoss();
2803}
2804
2805TEST_F(DataChannelTest, TestMediaMonitor) {
2806 Base::TestMediaMonitor();
2807}
2808
2809TEST_F(DataChannelTest, TestSendData) {
2810 CreateChannels(0, 0);
2811 EXPECT_TRUE(SendInitiate());
2812 EXPECT_TRUE(SendAccept());
2813
2814 cricket::SendDataParams params;
2815 params.ssrc = 42;
2816 unsigned char data[] = {
2817 'f', 'o', 'o'
2818 };
jbaucheec21bd2016-03-20 06:15:43 -07002819 rtc::CopyOnWriteBuffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820 cricket::SendDataResult result;
2821 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2822 EXPECT_EQ(params.ssrc,
2823 media_channel1_->last_sent_data_params().ssrc);
2824 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2825}
2826
2827// TODO(pthatcher): TestSetReceiver?