blob: 686f85d9eae792761e23fff64b6e142b2cd10c0e [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
Peter Boström0c4e06b2015-10-07 12:23:21 +0200493 void AddLegacyStreamInContent(uint32_t ssrc,
494 int flags,
495 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 // Base implementation.
497 }
498
499 // Tests that can be used by derived classes.
500
501 // Basic sanity check.
502 void TestInit() {
503 CreateChannels(0, 0);
504 EXPECT_FALSE(channel1_->secure());
505 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200506 if (verify_playout_) {
507 EXPECT_FALSE(media_channel1_->playout());
508 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 EXPECT_TRUE(media_channel1_->codecs().empty());
510 EXPECT_TRUE(media_channel1_->recv_streams().empty());
511 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
512 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
513 }
514
515 // Test that SetLocalContent and SetRemoteContent properly configure
516 // the codecs.
517 void TestSetContents() {
518 CreateChannels(0, 0);
519 typename T::Content content;
520 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000521 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000523 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 ASSERT_EQ(1U, media_channel1_->codecs().size());
525 EXPECT_TRUE(CodecMatches(content.codecs()[0],
526 media_channel1_->codecs()[0]));
527 }
528
529 // Test that SetLocalContent and SetRemoteContent properly deals
530 // with an empty offer.
531 void TestSetContentsNullOffer() {
532 CreateChannels(0, 0);
533 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000534 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 CreateContent(0, kPcmuCodec, kH264Codec, &content);
536 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000537 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 ASSERT_EQ(1U, media_channel1_->codecs().size());
539 EXPECT_TRUE(CodecMatches(content.codecs()[0],
540 media_channel1_->codecs()[0]));
541 }
542
543 // Test that SetLocalContent and SetRemoteContent properly set RTCP
544 // mux.
545 void TestSetContentsRtcpMux() {
546 CreateChannels(RTCP, RTCP);
547 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
548 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
549 typename T::Content content;
550 CreateContent(0, kPcmuCodec, kH264Codec, &content);
551 // Both sides agree on mux. Should no longer be a separate RTCP channel.
552 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000553 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
554 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
556 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000557 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000559 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
561 }
562
563 // Test that SetLocalContent and SetRemoteContent properly set RTCP
564 // mux when a provisional answer is received.
565 void TestSetContentsRtcpMuxWithPrAnswer() {
566 CreateChannels(RTCP, RTCP);
567 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
568 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
569 typename T::Content content;
570 CreateContent(0, kPcmuCodec, kH264Codec, &content);
571 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000572 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
573 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000575 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 // Both sides agree on mux. Should no longer be a separate RTCP channel.
577 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
578 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000579 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000581 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
582 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
584 }
585
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 // Test that SetRemoteContent properly deals with a content update.
587 void TestSetRemoteContentUpdate() {
588 CreateChannels(0, 0);
589 typename T::Content content;
590 CreateContent(RTCP | RTCP_MUX | SECURE,
591 kPcmuCodec, kH264Codec,
592 &content);
593 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000594 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
595 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 ASSERT_EQ(1U, media_channel1_->codecs().size());
597 EXPECT_TRUE(CodecMatches(content.codecs()[0],
598 media_channel1_->codecs()[0]));
599 // Now update with other codecs.
600 typename T::Content update_content;
601 update_content.set_partial(true);
602 CreateContent(0, kIsacCodec, kH264SvcCodec,
603 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000604 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605 ASSERT_EQ(1U, media_channel1_->codecs().size());
606 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
607 media_channel1_->codecs()[0]));
608 // Now update without any codecs. This is ignored.
609 typename T::Content empty_content;
610 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000611 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 ASSERT_EQ(1U, media_channel1_->codecs().size());
613 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
614 media_channel1_->codecs()[0]));
615 }
616
617 // Test that Add/RemoveStream properly forward to the media channel.
618 void TestStreams() {
619 CreateChannels(0, 0);
620 EXPECT_TRUE(AddStream1(1));
621 EXPECT_TRUE(AddStream1(2));
622 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
623 EXPECT_TRUE(RemoveStream1(2));
624 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
625 EXPECT_TRUE(RemoveStream1(1));
626 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
627 }
628
629 // Test that SetLocalContent properly handles adding and removing StreamParams
630 // to the local content description.
631 // This test uses the CA_UPDATE action that don't require a full
632 // MediaContentDescription to do an update.
633 void TestUpdateStreamsInLocalContent() {
634 cricket::StreamParams stream1;
635 stream1.groupid = "group1";
636 stream1.id = "stream1";
637 stream1.ssrcs.push_back(kSsrc1);
638 stream1.cname = "stream1_cname";
639
640 cricket::StreamParams stream2;
641 stream2.groupid = "group2";
642 stream2.id = "stream2";
643 stream2.ssrcs.push_back(kSsrc2);
644 stream2.cname = "stream2_cname";
645
646 cricket::StreamParams stream3;
647 stream3.groupid = "group3";
648 stream3.id = "stream3";
649 stream3.ssrcs.push_back(kSsrc3);
650 stream3.cname = "stream3_cname";
651
652 CreateChannels(0, 0);
653 typename T::Content content1;
654 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
655 content1.AddStream(stream1);
656 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000657 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658
659 ASSERT_EQ(1u, media_channel1_->send_streams().size());
660 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
661
662 // Update the local streams by adding another sending stream.
663 // Use a partial updated session description.
664 typename T::Content content2;
665 content2.AddStream(stream2);
666 content2.AddStream(stream3);
667 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 ASSERT_EQ(3u, media_channel1_->send_streams().size());
670 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
671 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
672 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
673
674 // Update the local streams by removing the first sending stream.
675 // This is done by removing all SSRCS for this particular stream.
676 typename T::Content content3;
677 stream1.ssrcs.clear();
678 content3.AddStream(stream1);
679 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000680 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000681 ASSERT_EQ(2u, media_channel1_->send_streams().size());
682 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
683 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
684
685 // Update the local streams with a stream that does not change.
686 // THe update is ignored.
687 typename T::Content content4;
688 content4.AddStream(stream2);
689 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000690 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000691 ASSERT_EQ(2u, media_channel1_->send_streams().size());
692 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
693 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
694 }
695
696 // Test that SetRemoteContent properly handles adding and removing
697 // StreamParams to the remote content description.
698 // This test uses the CA_UPDATE action that don't require a full
699 // MediaContentDescription to do an update.
700 void TestUpdateStreamsInRemoteContent() {
701 cricket::StreamParams stream1;
702 stream1.id = "Stream1";
703 stream1.groupid = "1";
704 stream1.ssrcs.push_back(kSsrc1);
705 stream1.cname = "stream1_cname";
706
707 cricket::StreamParams stream2;
708 stream2.id = "Stream2";
709 stream2.groupid = "2";
710 stream2.ssrcs.push_back(kSsrc2);
711 stream2.cname = "stream2_cname";
712
713 cricket::StreamParams stream3;
714 stream3.id = "Stream3";
715 stream3.groupid = "3";
716 stream3.ssrcs.push_back(kSsrc3);
717 stream3.cname = "stream3_cname";
718
719 CreateChannels(0, 0);
720 typename T::Content content1;
721 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
722 content1.AddStream(stream1);
723 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000724 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725
726 ASSERT_EQ(1u, media_channel1_->codecs().size());
727 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
728 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
729
730 // Update the remote streams by adding another sending stream.
731 // Use a partial updated session description.
732 typename T::Content content2;
733 content2.AddStream(stream2);
734 content2.AddStream(stream3);
735 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000736 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
738 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
739 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
740 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
741
742 // Update the remote streams by removing the first stream.
743 // This is done by removing all SSRCS for this particular stream.
744 typename T::Content content3;
745 stream1.ssrcs.clear();
746 content3.AddStream(stream1);
747 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000748 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
750 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
751 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
752
753 // Update the remote streams with a stream that does not change.
754 // The update is ignored.
755 typename T::Content content4;
756 content4.AddStream(stream2);
757 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000758 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
760 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
761 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
762 }
763
764 // Test that SetLocalContent and SetRemoteContent properly
765 // handles adding and removing StreamParams when the action is a full
766 // CA_OFFER / CA_ANSWER.
767 void TestChangeStreamParamsInContent() {
768 cricket::StreamParams stream1;
769 stream1.groupid = "group1";
770 stream1.id = "stream1";
771 stream1.ssrcs.push_back(kSsrc1);
772 stream1.cname = "stream1_cname";
773
774 cricket::StreamParams stream2;
775 stream2.groupid = "group1";
776 stream2.id = "stream2";
777 stream2.ssrcs.push_back(kSsrc2);
778 stream2.cname = "stream2_cname";
779
780 // Setup a call where channel 1 send |stream1| to channel 2.
781 CreateChannels(0, 0);
782 typename T::Content content1;
783 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
784 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000785 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 EXPECT_TRUE(channel1_->Enable(true));
787 EXPECT_EQ(1u, media_channel1_->send_streams().size());
788
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000789 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700791 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792
793 // Channel 2 do not send anything.
794 typename T::Content content2;
795 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000796 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000798 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_TRUE(channel2_->Enable(true));
800 EXPECT_EQ(0u, media_channel2_->send_streams().size());
801
802 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
803 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
804
805 // Let channel 2 update the content by sending |stream2| and enable SRTP.
806 typename T::Content content3;
807 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
808 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000809 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 ASSERT_EQ(1u, media_channel2_->send_streams().size());
811 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
812
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000813 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
815 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
816
817 // Channel 1 replies but stop sending stream1.
818 typename T::Content content4;
819 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000820 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 EXPECT_EQ(0u, media_channel1_->send_streams().size());
822
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000823 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
825
826 EXPECT_TRUE(channel1_->secure());
827 EXPECT_TRUE(channel2_->secure());
828 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
829 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
830 }
831
832 // Test that we only start playout and sending at the right times.
833 void TestPlayoutAndSendingStates() {
834 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200835 if (verify_playout_) {
836 EXPECT_FALSE(media_channel1_->playout());
837 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200839 if (verify_playout_) {
840 EXPECT_FALSE(media_channel2_->playout());
841 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_FALSE(media_channel2_->sending());
843 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200844 if (verify_playout_) {
845 EXPECT_FALSE(media_channel1_->playout());
846 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000848 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
849 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200850 if (verify_playout_) {
851 EXPECT_TRUE(media_channel1_->playout());
852 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000854 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
855 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200856 if (verify_playout_) {
857 EXPECT_FALSE(media_channel2_->playout());
858 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000860 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
861 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200862 if (verify_playout_) {
863 EXPECT_FALSE(media_channel2_->playout());
864 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700866 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200867 if (verify_playout_) {
868 EXPECT_TRUE(media_channel1_->playout());
869 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200871 if (verify_playout_) {
872 EXPECT_FALSE(media_channel2_->playout());
873 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 EXPECT_FALSE(media_channel2_->sending());
875 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200876 if (verify_playout_) {
877 EXPECT_TRUE(media_channel2_->playout());
878 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000880 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
881 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200882 if (verify_playout_) {
883 EXPECT_TRUE(media_channel1_->playout());
884 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 EXPECT_TRUE(media_channel1_->sending());
886 }
887
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 // Test that changing the MediaContentDirection in the local and remote
889 // session description start playout and sending at the right time.
890 void TestMediaContentDirection() {
891 CreateChannels(0, 0);
892 typename T::Content content1;
893 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
894 typename T::Content content2;
895 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
896 // Set |content2| to be InActive.
897 content2.set_direction(cricket::MD_INACTIVE);
898
899 EXPECT_TRUE(channel1_->Enable(true));
900 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200901 if (verify_playout_) {
902 EXPECT_FALSE(media_channel1_->playout());
903 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200905 if (verify_playout_) {
906 EXPECT_FALSE(media_channel2_->playout());
907 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 EXPECT_FALSE(media_channel2_->sending());
909
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000910 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
911 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
912 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
913 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700914 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915
Peter Boström34fbfff2015-09-24 19:20:30 +0200916 if (verify_playout_) {
917 EXPECT_TRUE(media_channel1_->playout());
918 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200920 if (verify_playout_) {
921 EXPECT_FALSE(media_channel2_->playout()); // local InActive
922 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 EXPECT_FALSE(media_channel2_->sending()); // local InActive
924
925 // Update |content2| to be RecvOnly.
926 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000927 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
928 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929
Peter Boström34fbfff2015-09-24 19:20:30 +0200930 if (verify_playout_) {
931 EXPECT_TRUE(media_channel1_->playout());
932 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200934 if (verify_playout_) {
935 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
936 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
938
939 // Update |content2| to be SendRecv.
940 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000941 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
942 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943
Peter Boström34fbfff2015-09-24 19:20:30 +0200944 if (verify_playout_) {
945 EXPECT_TRUE(media_channel1_->playout());
946 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200948 if (verify_playout_) {
949 EXPECT_TRUE(media_channel2_->playout());
950 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 EXPECT_TRUE(media_channel2_->sending());
952 }
953
954 // Test setting up a call.
955 void TestCallSetup() {
956 CreateChannels(0, 0);
957 EXPECT_FALSE(channel1_->secure());
958 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200959 if (verify_playout_) {
960 EXPECT_TRUE(media_channel1_->playout());
961 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 EXPECT_FALSE(media_channel1_->sending());
963 EXPECT_TRUE(SendAccept());
964 EXPECT_FALSE(channel1_->secure());
965 EXPECT_TRUE(media_channel1_->sending());
966 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200967 if (verify_playout_) {
968 EXPECT_TRUE(media_channel2_->playout());
969 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 EXPECT_TRUE(media_channel2_->sending());
971 EXPECT_EQ(1U, media_channel2_->codecs().size());
972 }
973
974 // Test that we don't crash if packets are sent during call teardown
975 // when RTCP mux is enabled. This is a regression test against a specific
976 // race condition that would only occur when a RTCP packet was sent during
977 // teardown of a channel on which RTCP mux was enabled.
978 void TestCallTeardownRtcpMux() {
979 class LastWordMediaChannel : public T::MediaChannel {
980 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200981 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700983 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
984 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
986 }
987 };
988 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
989 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000990 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 EXPECT_TRUE(SendInitiate());
992 EXPECT_TRUE(SendAccept());
993 EXPECT_TRUE(SendTerminate());
994 }
995
996 // Send voice RTP data to the other side and ensure it gets there.
997 void SendRtpToRtp() {
998 CreateChannels(0, 0);
999 EXPECT_TRUE(SendInitiate());
1000 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001001 ASSERT_TRUE(GetTransport1());
1002 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001003 EXPECT_EQ(1U, GetTransport1()->channels().size());
1004 EXPECT_EQ(1U, GetTransport2()->channels().size());
1005 EXPECT_TRUE(SendRtp1());
1006 EXPECT_TRUE(SendRtp2());
1007 EXPECT_TRUE(CheckRtp1());
1008 EXPECT_TRUE(CheckRtp2());
1009 EXPECT_TRUE(CheckNoRtp1());
1010 EXPECT_TRUE(CheckNoRtp2());
1011 }
1012
1013 // Check that RTCP is not transmitted if both sides don't support RTCP.
1014 void SendNoRtcpToNoRtcp() {
1015 CreateChannels(0, 0);
1016 EXPECT_TRUE(SendInitiate());
1017 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001018 ASSERT_TRUE(GetTransport1());
1019 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 EXPECT_EQ(1U, GetTransport1()->channels().size());
1021 EXPECT_EQ(1U, GetTransport2()->channels().size());
1022 EXPECT_FALSE(SendRtcp1());
1023 EXPECT_FALSE(SendRtcp2());
1024 EXPECT_TRUE(CheckNoRtcp1());
1025 EXPECT_TRUE(CheckNoRtcp2());
1026 }
1027
1028 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1029 void SendNoRtcpToRtcp() {
1030 CreateChannels(0, RTCP);
1031 EXPECT_TRUE(SendInitiate());
1032 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001033 ASSERT_TRUE(GetTransport1());
1034 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 EXPECT_EQ(1U, GetTransport1()->channels().size());
1036 EXPECT_EQ(2U, GetTransport2()->channels().size());
1037 EXPECT_FALSE(SendRtcp1());
1038 EXPECT_FALSE(SendRtcp2());
1039 EXPECT_TRUE(CheckNoRtcp1());
1040 EXPECT_TRUE(CheckNoRtcp2());
1041 }
1042
1043 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1044 void SendRtcpToNoRtcp() {
1045 CreateChannels(RTCP, 0);
1046 EXPECT_TRUE(SendInitiate());
1047 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001048 ASSERT_TRUE(GetTransport1());
1049 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 EXPECT_EQ(2U, GetTransport1()->channels().size());
1051 EXPECT_EQ(1U, GetTransport2()->channels().size());
1052 EXPECT_FALSE(SendRtcp1());
1053 EXPECT_FALSE(SendRtcp2());
1054 EXPECT_TRUE(CheckNoRtcp1());
1055 EXPECT_TRUE(CheckNoRtcp2());
1056 }
1057
1058 // Check that RTCP is transmitted if both sides support RTCP.
1059 void SendRtcpToRtcp() {
1060 CreateChannels(RTCP, RTCP);
1061 EXPECT_TRUE(SendInitiate());
1062 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001063 ASSERT_TRUE(GetTransport1());
1064 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001065 EXPECT_EQ(2U, GetTransport1()->channels().size());
1066 EXPECT_EQ(2U, GetTransport2()->channels().size());
1067 EXPECT_TRUE(SendRtcp1());
1068 EXPECT_TRUE(SendRtcp2());
1069 EXPECT_TRUE(CheckRtcp1());
1070 EXPECT_TRUE(CheckRtcp2());
1071 EXPECT_TRUE(CheckNoRtcp1());
1072 EXPECT_TRUE(CheckNoRtcp2());
1073 }
1074
1075 // Check that RTCP is transmitted if only the initiator supports mux.
1076 void SendRtcpMuxToRtcp() {
1077 CreateChannels(RTCP | RTCP_MUX, RTCP);
1078 EXPECT_TRUE(SendInitiate());
1079 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001080 ASSERT_TRUE(GetTransport1());
1081 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001082 EXPECT_EQ(2U, GetTransport1()->channels().size());
1083 EXPECT_EQ(2U, GetTransport2()->channels().size());
1084 EXPECT_TRUE(SendRtcp1());
1085 EXPECT_TRUE(SendRtcp2());
1086 EXPECT_TRUE(CheckRtcp1());
1087 EXPECT_TRUE(CheckRtcp2());
1088 EXPECT_TRUE(CheckNoRtcp1());
1089 EXPECT_TRUE(CheckNoRtcp2());
1090 }
1091
1092 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1093 void SendRtcpMuxToRtcpMux() {
1094 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1095 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001096 ASSERT_TRUE(GetTransport1());
1097 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 EXPECT_EQ(2U, GetTransport1()->channels().size());
1099 EXPECT_EQ(1U, GetTransport2()->channels().size());
1100 EXPECT_TRUE(SendAccept());
1101 EXPECT_EQ(1U, GetTransport1()->channels().size());
1102 EXPECT_TRUE(SendRtp1());
1103 EXPECT_TRUE(SendRtp2());
1104 EXPECT_TRUE(SendRtcp1());
1105 EXPECT_TRUE(SendRtcp2());
1106 EXPECT_TRUE(CheckRtp1());
1107 EXPECT_TRUE(CheckRtp2());
1108 EXPECT_TRUE(CheckNoRtp1());
1109 EXPECT_TRUE(CheckNoRtp2());
1110 EXPECT_TRUE(CheckRtcp1());
1111 EXPECT_TRUE(CheckRtcp2());
1112 EXPECT_TRUE(CheckNoRtcp1());
1113 EXPECT_TRUE(CheckNoRtcp2());
1114 }
1115
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001116 // Check that RTP and RTCP are transmitted ok when both sides
1117 // support mux and one the offerer requires mux.
1118 void SendRequireRtcpMuxToRtcpMux() {
1119 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1120 channel1_->ActivateRtcpMux();
1121 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001122 ASSERT_TRUE(GetTransport1());
1123 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001124 EXPECT_EQ(1U, GetTransport1()->channels().size());
1125 EXPECT_EQ(1U, GetTransport2()->channels().size());
1126 EXPECT_TRUE(SendAccept());
1127 EXPECT_TRUE(SendRtp1());
1128 EXPECT_TRUE(SendRtp2());
1129 EXPECT_TRUE(SendRtcp1());
1130 EXPECT_TRUE(SendRtcp2());
1131 EXPECT_TRUE(CheckRtp1());
1132 EXPECT_TRUE(CheckRtp2());
1133 EXPECT_TRUE(CheckNoRtp1());
1134 EXPECT_TRUE(CheckNoRtp2());
1135 EXPECT_TRUE(CheckRtcp1());
1136 EXPECT_TRUE(CheckRtcp2());
1137 EXPECT_TRUE(CheckNoRtcp1());
1138 EXPECT_TRUE(CheckNoRtcp2());
1139 }
1140
1141 // Check that RTP and RTCP are transmitted ok when both sides
1142 // support mux and one the answerer requires rtcp mux.
1143 void SendRtcpMuxToRequireRtcpMux() {
1144 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1145 channel2_->ActivateRtcpMux();
1146 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001147 ASSERT_TRUE(GetTransport1());
1148 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001149 EXPECT_EQ(2U, GetTransport1()->channels().size());
1150 EXPECT_EQ(1U, GetTransport2()->channels().size());
1151 EXPECT_TRUE(SendAccept());
1152 EXPECT_EQ(1U, GetTransport1()->channels().size());
1153 EXPECT_TRUE(SendRtp1());
1154 EXPECT_TRUE(SendRtp2());
1155 EXPECT_TRUE(SendRtcp1());
1156 EXPECT_TRUE(SendRtcp2());
1157 EXPECT_TRUE(CheckRtp1());
1158 EXPECT_TRUE(CheckRtp2());
1159 EXPECT_TRUE(CheckNoRtp1());
1160 EXPECT_TRUE(CheckNoRtp2());
1161 EXPECT_TRUE(CheckRtcp1());
1162 EXPECT_TRUE(CheckRtcp2());
1163 EXPECT_TRUE(CheckNoRtcp1());
1164 EXPECT_TRUE(CheckNoRtcp2());
1165 }
1166
1167 // Check that RTP and RTCP are transmitted ok when both sides
1168 // require mux.
1169 void SendRequireRtcpMuxToRequireRtcpMux() {
1170 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1171 channel1_->ActivateRtcpMux();
1172 channel2_->ActivateRtcpMux();
1173 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001174 ASSERT_TRUE(GetTransport1());
1175 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001176 EXPECT_EQ(1U, GetTransport1()->channels().size());
1177 EXPECT_EQ(1U, GetTransport2()->channels().size());
1178 EXPECT_TRUE(SendAccept());
1179 EXPECT_EQ(1U, GetTransport1()->channels().size());
1180 EXPECT_TRUE(SendRtp1());
1181 EXPECT_TRUE(SendRtp2());
1182 EXPECT_TRUE(SendRtcp1());
1183 EXPECT_TRUE(SendRtcp2());
1184 EXPECT_TRUE(CheckRtp1());
1185 EXPECT_TRUE(CheckRtp2());
1186 EXPECT_TRUE(CheckNoRtp1());
1187 EXPECT_TRUE(CheckNoRtp2());
1188 EXPECT_TRUE(CheckRtcp1());
1189 EXPECT_TRUE(CheckRtcp2());
1190 EXPECT_TRUE(CheckNoRtcp1());
1191 EXPECT_TRUE(CheckNoRtcp2());
1192 }
1193
1194 // Check that SendAccept fails if the answerer doesn't support mux
1195 // and the offerer requires it.
1196 void SendRequireRtcpMuxToNoRtcpMux() {
1197 CreateChannels(RTCP | RTCP_MUX, RTCP);
1198 channel1_->ActivateRtcpMux();
1199 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001200 ASSERT_TRUE(GetTransport1());
1201 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001202 EXPECT_EQ(1U, GetTransport1()->channels().size());
1203 EXPECT_EQ(2U, GetTransport2()->channels().size());
1204 EXPECT_FALSE(SendAccept());
1205 }
1206
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207 // Check that RTCP data sent by the initiator before the accept is not muxed.
1208 void SendEarlyRtcpMuxToRtcp() {
1209 CreateChannels(RTCP | RTCP_MUX, RTCP);
1210 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001211 ASSERT_TRUE(GetTransport1());
1212 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 EXPECT_EQ(2U, GetTransport1()->channels().size());
1214 EXPECT_EQ(2U, GetTransport2()->channels().size());
1215
1216 // RTCP can be sent before the call is accepted, if the transport is ready.
1217 // It should not be muxed though, as the remote side doesn't support mux.
1218 EXPECT_TRUE(SendRtcp1());
1219 EXPECT_TRUE(CheckNoRtp2());
1220 EXPECT_TRUE(CheckRtcp2());
1221
1222 // Send RTCP packet from callee and verify that it is received.
1223 EXPECT_TRUE(SendRtcp2());
1224 EXPECT_TRUE(CheckNoRtp1());
1225 EXPECT_TRUE(CheckRtcp1());
1226
1227 // Complete call setup and ensure everything is still OK.
1228 EXPECT_TRUE(SendAccept());
1229 EXPECT_EQ(2U, GetTransport1()->channels().size());
1230 EXPECT_TRUE(SendRtcp1());
1231 EXPECT_TRUE(CheckRtcp2());
1232 EXPECT_TRUE(SendRtcp2());
1233 EXPECT_TRUE(CheckRtcp1());
1234 }
1235
1236
1237 // Check that RTCP data is not muxed until both sides have enabled muxing,
1238 // but that we properly demux before we get the accept message, since there
1239 // is a race between RTP data and the jingle accept.
1240 void SendEarlyRtcpMuxToRtcpMux() {
1241 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1242 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001243 ASSERT_TRUE(GetTransport1());
1244 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001245 EXPECT_EQ(2U, GetTransport1()->channels().size());
1246 EXPECT_EQ(1U, GetTransport2()->channels().size());
1247
1248 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1249 // we haven't yet received the accept that says we should mux.
1250 EXPECT_FALSE(SendRtcp1());
1251
1252 // Send muxed RTCP packet from callee and verify that it is received.
1253 EXPECT_TRUE(SendRtcp2());
1254 EXPECT_TRUE(CheckNoRtp1());
1255 EXPECT_TRUE(CheckRtcp1());
1256
1257 // Complete call setup and ensure everything is still OK.
1258 EXPECT_TRUE(SendAccept());
1259 EXPECT_EQ(1U, GetTransport1()->channels().size());
1260 EXPECT_TRUE(SendRtcp1());
1261 EXPECT_TRUE(CheckRtcp2());
1262 EXPECT_TRUE(SendRtcp2());
1263 EXPECT_TRUE(CheckRtcp1());
1264 }
1265
1266 // Test that we properly send SRTP with RTCP in both directions.
1267 // You can pass in DTLS and/or RTCP_MUX as flags.
1268 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1269 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1270 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1271
1272 int flags1 = RTCP | SECURE | flags1_in;
1273 int flags2 = RTCP | SECURE | flags2_in;
1274 bool dtls1 = !!(flags1_in & DTLS);
1275 bool dtls2 = !!(flags2_in & DTLS);
1276 CreateChannels(flags1, flags2);
1277 EXPECT_FALSE(channel1_->secure());
1278 EXPECT_FALSE(channel2_->secure());
1279 EXPECT_TRUE(SendInitiate());
1280 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1281 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1282 EXPECT_TRUE(SendAccept());
1283 EXPECT_TRUE(channel1_->secure());
1284 EXPECT_TRUE(channel2_->secure());
1285 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1286 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1287 EXPECT_TRUE(SendRtp1());
1288 EXPECT_TRUE(SendRtp2());
1289 EXPECT_TRUE(SendRtcp1());
1290 EXPECT_TRUE(SendRtcp2());
1291 EXPECT_TRUE(CheckRtp1());
1292 EXPECT_TRUE(CheckRtp2());
1293 EXPECT_TRUE(CheckNoRtp1());
1294 EXPECT_TRUE(CheckNoRtp2());
1295 EXPECT_TRUE(CheckRtcp1());
1296 EXPECT_TRUE(CheckRtcp2());
1297 EXPECT_TRUE(CheckNoRtcp1());
1298 EXPECT_TRUE(CheckNoRtcp2());
1299 }
1300
1301 // Test that we properly handling SRTP negotiating down to RTP.
1302 void SendSrtpToRtp() {
1303 CreateChannels(RTCP | SECURE, RTCP);
1304 EXPECT_FALSE(channel1_->secure());
1305 EXPECT_FALSE(channel2_->secure());
1306 EXPECT_TRUE(SendInitiate());
1307 EXPECT_TRUE(SendAccept());
1308 EXPECT_FALSE(channel1_->secure());
1309 EXPECT_FALSE(channel2_->secure());
1310 EXPECT_TRUE(SendRtp1());
1311 EXPECT_TRUE(SendRtp2());
1312 EXPECT_TRUE(SendRtcp1());
1313 EXPECT_TRUE(SendRtcp2());
1314 EXPECT_TRUE(CheckRtp1());
1315 EXPECT_TRUE(CheckRtp2());
1316 EXPECT_TRUE(CheckNoRtp1());
1317 EXPECT_TRUE(CheckNoRtp2());
1318 EXPECT_TRUE(CheckRtcp1());
1319 EXPECT_TRUE(CheckRtcp2());
1320 EXPECT_TRUE(CheckNoRtcp1());
1321 EXPECT_TRUE(CheckNoRtcp2());
1322 }
1323
1324 // Test that we can send and receive early media when a provisional answer is
1325 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1326 void SendEarlyMediaUsingRtcpMuxSrtp() {
1327 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1328
1329 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1330 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1331 EXPECT_TRUE(SendOffer());
1332 EXPECT_TRUE(SendProvisionalAnswer());
1333 EXPECT_TRUE(channel1_->secure());
1334 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001335 ASSERT_TRUE(GetTransport1());
1336 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337 EXPECT_EQ(2U, GetTransport1()->channels().size());
1338 EXPECT_EQ(2U, GetTransport2()->channels().size());
1339 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1340 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1341 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1342 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1343
1344 // Send packets from callee and verify that it is received.
1345 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1346 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1347 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1348 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1349
1350 // Complete call setup and ensure everything is still OK.
1351 EXPECT_TRUE(SendFinalAnswer());
1352 EXPECT_EQ(1U, GetTransport1()->channels().size());
1353 EXPECT_EQ(1U, GetTransport2()->channels().size());
1354 EXPECT_TRUE(channel1_->secure());
1355 EXPECT_TRUE(channel2_->secure());
1356 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1357 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1358 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1359 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1360 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1361 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1362 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1363 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1364 }
1365
1366 // Test that we properly send RTP without SRTP from a thread.
1367 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001368 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001369 EXPECT_TRUE(SendInitiate());
1370 EXPECT_TRUE(SendAccept());
ossu292d6582016-03-17 02:31:13 -07001371 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
1372 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
1373 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
1374 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1376 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001377 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
1378 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 EXPECT_TRUE(CheckNoRtp1());
1380 EXPECT_TRUE(CheckNoRtp2());
1381 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1382 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001383 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
1384 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 EXPECT_TRUE(CheckNoRtcp1());
1386 EXPECT_TRUE(CheckNoRtcp2());
1387 }
1388
1389 // Test that we properly send SRTP with RTCP from a thread.
1390 void SendSrtpToSrtpOnThread() {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1392 EXPECT_TRUE(SendInitiate());
1393 EXPECT_TRUE(SendAccept());
ossu292d6582016-03-17 02:31:13 -07001394 ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
1395 ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
1396 ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
1397 ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1399 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001400 EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
1401 EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 EXPECT_TRUE(CheckNoRtp1());
1403 EXPECT_TRUE(CheckNoRtp2());
1404 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1405 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
ossu292d6582016-03-17 02:31:13 -07001406 EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
1407 EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 EXPECT_TRUE(CheckNoRtcp1());
1409 EXPECT_TRUE(CheckNoRtcp2());
1410 }
1411
1412 // Test that the mediachannel retains its sending state after the transport
1413 // becomes non-writable.
1414 void SendWithWritabilityLoss() {
1415 CreateChannels(0, 0);
1416 EXPECT_TRUE(SendInitiate());
1417 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001418 ASSERT_TRUE(GetTransport1());
1419 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 EXPECT_EQ(1U, GetTransport1()->channels().size());
1421 EXPECT_EQ(1U, GetTransport2()->channels().size());
1422 EXPECT_TRUE(SendRtp1());
1423 EXPECT_TRUE(SendRtp2());
1424 EXPECT_TRUE(CheckRtp1());
1425 EXPECT_TRUE(CheckRtp2());
1426 EXPECT_TRUE(CheckNoRtp1());
1427 EXPECT_TRUE(CheckNoRtp2());
1428
wu@webrtc.org97077a32013-10-25 21:18:33 +00001429 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001431 EXPECT_FALSE(SendRtp1());
1432 EXPECT_TRUE(SendRtp2());
1433 EXPECT_TRUE(CheckRtp1());
1434 EXPECT_TRUE(CheckNoRtp2());
1435
1436 // Regain writability
1437 GetTransport1()->SetWritable(true);
1438 EXPECT_TRUE(media_channel1_->sending());
1439 EXPECT_TRUE(SendRtp1());
1440 EXPECT_TRUE(SendRtp2());
1441 EXPECT_TRUE(CheckRtp1());
1442 EXPECT_TRUE(CheckRtp2());
1443 EXPECT_TRUE(CheckNoRtp1());
1444 EXPECT_TRUE(CheckNoRtp2());
1445
1446 // Lose writability completely
1447 GetTransport1()->SetDestination(NULL);
1448 EXPECT_TRUE(media_channel1_->sending());
1449
wu@webrtc.org97077a32013-10-25 21:18:33 +00001450 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 EXPECT_FALSE(SendRtp1());
1452 EXPECT_TRUE(SendRtp2());
1453 EXPECT_TRUE(CheckRtp1());
1454 EXPECT_TRUE(CheckNoRtp2());
1455
1456 // Gain writability back
1457 GetTransport1()->SetDestination(GetTransport2());
1458 EXPECT_TRUE(media_channel1_->sending());
1459 EXPECT_TRUE(SendRtp1());
1460 EXPECT_TRUE(SendRtp2());
1461 EXPECT_TRUE(CheckRtp1());
1462 EXPECT_TRUE(CheckRtp2());
1463 EXPECT_TRUE(CheckNoRtp1());
1464 EXPECT_TRUE(CheckNoRtp2());
1465 }
1466
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001467 void SendBundleToBundle(
1468 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1469 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001471 // Only pl_type1 was added to the bundle filter for both |channel1_|
1472 // and |channel2_|.
1473 int pl_type1 = pl_types[0];
1474 int pl_type2 = pl_types[1];
1475 int flags = SSRC_MUX | RTCP;
1476 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001477 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001478 if (rtcp_mux) {
1479 flags |= RTCP_MUX;
1480 expected_channels = 1U;
1481 }
1482 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001484 ASSERT_TRUE(GetTransport1());
1485 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001487 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001489 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1490 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1491 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1492 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1493 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1494 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001495
1496 // Both channels can receive pl_type1 only.
1497 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1498 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1499 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1500 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1501 EXPECT_TRUE(CheckNoRtp1());
1502 EXPECT_TRUE(CheckNoRtp2());
1503
1504 // RTCP test
1505 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1506 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1507 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1508 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1511 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1513 EXPECT_TRUE(CheckNoRtcp1());
1514 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1515 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001517 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1518 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
pbos482b12e2015-11-16 10:19:58 -08001519 // Bundle filter shouldn't filter out any RTCP.
1520 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1521 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 }
1523
1524 // Test that the media monitor can be run and gives timely callbacks.
1525 void TestMediaMonitor() {
1526 static const int kTimeout = 500;
1527 CreateChannels(0, 0);
1528 EXPECT_TRUE(SendInitiate());
1529 EXPECT_TRUE(SendAccept());
1530 channel1_->StartMediaMonitor(100);
1531 channel2_->StartMediaMonitor(100);
1532 // Ensure we get callbacks and stop.
1533 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1534 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1535 channel1_->StopMediaMonitor();
1536 channel2_->StopMediaMonitor();
1537 // Ensure a restart of a stopped monitor works.
1538 channel1_->StartMediaMonitor(100);
1539 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1540 channel1_->StopMediaMonitor();
1541 // Ensure stopping a stopped monitor is OK.
1542 channel1_->StopMediaMonitor();
1543 }
1544
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 void TestSetContentFailure() {
1546 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547
Peter Thatchera6d24442015-07-09 21:26:36 -07001548 auto sdesc = cricket::SessionDescription();
1549 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1550 new cricket::AudioContentDescription());
1551 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1552 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553
Peter Thatchera6d24442015-07-09 21:26:36 -07001554 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001556 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1557 &sdesc, cricket::CA_OFFER, &err));
1558 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1559 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001562 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1563 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001565 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1566 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567 }
1568
1569 void TestSendTwoOffers() {
1570 CreateChannels(0, 0);
1571
Peter Thatchera6d24442015-07-09 21:26:36 -07001572 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001573 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001574 CreateSessionDescriptionWithStream(1));
1575 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1576 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1578
kwiberg31022942016-03-11 14:18:21 -08001579 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001580 CreateSessionDescriptionWithStream(2));
1581 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1582 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1584 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1585 }
1586
1587 void TestReceiveTwoOffers() {
1588 CreateChannels(0, 0);
1589
Peter Thatchera6d24442015-07-09 21:26:36 -07001590 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001591 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001592 CreateSessionDescriptionWithStream(1));
1593 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1594 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1596
kwiberg31022942016-03-11 14:18:21 -08001597 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001598 CreateSessionDescriptionWithStream(2));
1599 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1600 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1602 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1603 }
1604
1605 void TestSendPrAnswer() {
1606 CreateChannels(0, 0);
1607
Peter Thatchera6d24442015-07-09 21:26:36 -07001608 std::string err;
1609 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001610 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001611 CreateSessionDescriptionWithStream(1));
1612 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1613 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1615
Peter Thatchera6d24442015-07-09 21:26:36 -07001616 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001617 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001618 CreateSessionDescriptionWithStream(2));
1619 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1620 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1622 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1623
Peter Thatchera6d24442015-07-09 21:26:36 -07001624 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001625 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001626 CreateSessionDescriptionWithStream(3));
1627 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1628 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1630 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1631 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1632 }
1633
1634 void TestReceivePrAnswer() {
1635 CreateChannels(0, 0);
1636
Peter Thatchera6d24442015-07-09 21:26:36 -07001637 std::string err;
1638 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001639 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001640 CreateSessionDescriptionWithStream(1));
1641 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1642 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1644
Peter Thatchera6d24442015-07-09 21:26:36 -07001645 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001646 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001647 CreateSessionDescriptionWithStream(2));
1648 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1649 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1651 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1652
Peter Thatchera6d24442015-07-09 21:26:36 -07001653 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001654 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001655 CreateSessionDescriptionWithStream(3));
1656 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1657 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1659 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1660 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1661 }
1662
1663 void TestFlushRtcp() {
1664 bool send_rtcp1;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 CreateChannels(RTCP, RTCP);
1666 EXPECT_TRUE(SendInitiate());
1667 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001668 ASSERT_TRUE(GetTransport1());
1669 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 EXPECT_EQ(2U, GetTransport1()->channels().size());
1671 EXPECT_EQ(2U, GetTransport2()->channels().size());
1672
1673 // Send RTCP1 from a different thread.
1674 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1675 EXPECT_TRUE(send_rtcp1);
1676 // The sending message is only posted. channel2_ should be empty.
1677 EXPECT_TRUE(CheckNoRtcp2());
1678
1679 // When channel1_ is deleted, the RTCP packet should be sent out to
1680 // channel2_.
1681 channel1_.reset();
1682 EXPECT_TRUE(CheckRtcp2());
1683 }
1684
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001685 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001686 struct SrtpErrorHandler : public sigslot::has_slots<> {
1687 SrtpErrorHandler() :
1688 mode_(cricket::SrtpFilter::UNPROTECT),
1689 error_(cricket::SrtpFilter::ERROR_NONE) {}
1690 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1691 cricket::SrtpFilter::Error error) {
1692 mode_ = mode;
1693 error_ = error;
1694 }
1695 cricket::SrtpFilter::Mode mode_;
1696 cricket::SrtpFilter::Error error_;
1697 } error_handler;
1698
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001699 // For Audio, only pl_type 0 is added to the bundle filter.
1700 // For Video, only pl_type 97 is added to the bundle filter.
1701 // So we need to pass in pl_type so that the packet can pass through
1702 // the bundle filter before it can be processed by the srtp filter.
1703 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001704 unsigned const char kBadPacket[] = {0x84,
1705 static_cast<unsigned char>(pl_type),
1706 0x00,
1707 0x01,
1708 0x00,
1709 0x00,
1710 0x00,
1711 0x00,
1712 0x00,
1713 0x00,
1714 0x00,
1715 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1717 EXPECT_FALSE(channel1_->secure());
1718 EXPECT_FALSE(channel2_->secure());
1719 EXPECT_TRUE(SendInitiate());
1720 EXPECT_TRUE(SendAccept());
1721 EXPECT_TRUE(channel1_->secure());
1722 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001723 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001724 channel2_->srtp_filter()->SignalSrtpError.connect(
1725 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726
1727 // Testing failures in sending packets.
stefanc1aeaf02015-10-15 07:26:07 -07001728 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1729 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001731 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1732 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1733 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001734 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1735 // The next 250 ms failures will not trigger an error.
stefanc1aeaf02015-10-15 07:26:07 -07001736 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1737 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001739 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001740 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001741 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1742 // Wait for a little more - the error will be triggered again.
1743 rtc::Thread::Current()->ProcessMessages(200);
stefanc1aeaf02015-10-15 07:26:07 -07001744 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1745 rtc::PacketOptions()));
solenberg5b14b422015-10-01 04:10:31 -07001746 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1747 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748
1749 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001750 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001751 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001752
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 cricket::TransportChannel* transport_channel =
1754 channel2_->transport_channel();
1755 transport_channel->SignalReadPacket(
1756 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001757 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001758 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1759 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 }
1761
1762 void TestOnReadyToSend() {
1763 CreateChannels(RTCP, RTCP);
1764 TransportChannel* rtp = channel1_->transport_channel();
1765 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1766 EXPECT_FALSE(media_channel1_->ready_to_send());
1767 rtp->SignalReadyToSend(rtp);
1768 EXPECT_FALSE(media_channel1_->ready_to_send());
1769 rtcp->SignalReadyToSend(rtcp);
1770 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1771 // channel are ready to send.
1772 EXPECT_TRUE(media_channel1_->ready_to_send());
1773
1774 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001775 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001777 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 EXPECT_TRUE(media_channel1_->ready_to_send());
1779
1780 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001781 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001783 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 EXPECT_TRUE(media_channel1_->ready_to_send());
1785 }
1786
1787 void TestOnReadyToSendWithRtcpMux() {
1788 CreateChannels(RTCP, RTCP);
1789 typename T::Content content;
1790 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1791 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1792 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001793 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1794 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1796 TransportChannel* rtp = channel1_->transport_channel();
1797 EXPECT_FALSE(media_channel1_->ready_to_send());
1798 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1799 // should trigger the MediaChannel's OnReadyToSend.
1800 rtp->SignalReadyToSend(rtp);
1801 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001802 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 EXPECT_FALSE(media_channel1_->ready_to_send());
1804 }
1805
skvladdc1c62c2016-03-16 19:07:43 -07001806 bool SetRemoteContentWithBitrateLimit(int remote_limit) {
1807 typename T::Content content;
1808 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1809 content.set_bandwidth(remote_limit);
1810 return channel1_->SetRemoteContent(&content, CA_OFFER, NULL);
1811 }
1812
1813 webrtc::RtpParameters BitrateLimitedParameters(int limit) {
1814 webrtc::RtpParameters parameters;
1815 webrtc::RtpEncodingParameters encoding;
1816 encoding.max_bitrate_bps = limit;
1817 parameters.encodings.push_back(encoding);
1818 return parameters;
1819 }
1820
1821 void VerifyMaxBitrate(const webrtc::RtpParameters& parameters,
1822 int expected_bitrate) {
1823 EXPECT_EQ(1UL, parameters.encodings.size());
1824 EXPECT_EQ(expected_bitrate, parameters.encodings[0].max_bitrate_bps);
1825 }
1826
1827 void DefaultMaxBitrateIsUnlimited() {
1828 CreateChannels(0, 0);
1829 EXPECT_TRUE(
1830 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1831 EXPECT_EQ(media_channel1_->max_bps(), -1);
1832 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1);
1833 }
1834
1835 void CanChangeMaxBitrate() {
1836 CreateChannels(0, 0);
1837 EXPECT_TRUE(
1838 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
1839
1840 EXPECT_TRUE(
1841 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(1000)));
1842 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), 1000);
1843 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), 1000);
1844 EXPECT_EQ(-1, media_channel1_->max_bps());
1845
1846 EXPECT_TRUE(
1847 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(-1)));
1848 VerifyMaxBitrate(channel1_->GetRtpParameters(kSsrc1), -1);
1849 VerifyMaxBitrate(media_channel1_->GetRtpParameters(kSsrc1), -1);
1850 EXPECT_EQ(-1, media_channel1_->max_bps());
1851 }
1852
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001854 // TODO(pbos): Remove playout from all media channels and let renderers mute
1855 // themselves.
1856 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001857 cricket::FakeTransportController transport_controller1_;
1858 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 cricket::FakeMediaEngine media_engine_;
1860 // The media channels are owned by the voice channel objects below.
1861 typename T::MediaChannel* media_channel1_;
1862 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001863 std::unique_ptr<typename T::Channel> channel1_;
1864 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 typename T::Content local_media_content1_;
1866 typename T::Content local_media_content2_;
1867 typename T::Content remote_media_content1_;
1868 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 // The RTP and RTCP packets to send in the tests.
1870 std::string rtp_packet_;
1871 std::string rtcp_packet_;
1872 int media_info_callbacks1_;
1873 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874};
1875
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876template<>
1877void ChannelTest<VoiceTraits>::CreateContent(
1878 int flags,
1879 const cricket::AudioCodec& audio_codec,
1880 const cricket::VideoCodec& video_codec,
1881 cricket::AudioContentDescription* audio) {
1882 audio->AddCodec(audio_codec);
1883 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1884 if (flags & SECURE) {
1885 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001886 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1887 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 }
1889}
1890
1891template<>
1892void ChannelTest<VoiceTraits>::CopyContent(
1893 const cricket::AudioContentDescription& source,
1894 cricket::AudioContentDescription* audio) {
1895 *audio = source;
1896}
1897
1898template<>
1899bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1900 const cricket::AudioCodec& c2) {
1901 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1902 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1903}
1904
Peter Boström0c4e06b2015-10-07 12:23:21 +02001905template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001907 uint32_t ssrc,
1908 int flags,
1909 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 audio->AddLegacyStream(ssrc);
1911}
1912
1913class VoiceChannelTest
1914 : public ChannelTest<VoiceTraits> {
1915 public:
solenberg1dd98f32015-09-10 01:57:14 -07001916 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001917 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001918 : Base(true,
1919 kPcmuFrame,
1920 sizeof(kPcmuFrame),
1921 kRtcpReport,
1922 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923};
1924
1925// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001926template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001928 rtc::Thread* thread,
1929 cricket::MediaEngineInterface* engine,
1930 cricket::FakeVideoMediaChannel* ch,
1931 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 bool rtcp) {
1933 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001934 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935 if (!channel->Init()) {
1936 delete channel;
1937 channel = NULL;
1938 }
1939 return channel;
1940}
1941
1942// override to add 0 parameter
1943template<>
1944bool ChannelTest<VideoTraits>::AddStream1(int id) {
1945 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1946}
1947
1948template<>
1949void ChannelTest<VideoTraits>::CreateContent(
1950 int flags,
1951 const cricket::AudioCodec& audio_codec,
1952 const cricket::VideoCodec& video_codec,
1953 cricket::VideoContentDescription* video) {
1954 video->AddCodec(video_codec);
1955 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1956 if (flags & SECURE) {
1957 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001958 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1959 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 }
1961}
1962
1963template<>
1964void ChannelTest<VideoTraits>::CopyContent(
1965 const cricket::VideoContentDescription& source,
1966 cricket::VideoContentDescription* video) {
1967 *video = source;
1968}
1969
1970template<>
1971bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1972 const cricket::VideoCodec& c2) {
1973 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1974 c1.framerate == c2.framerate;
1975}
1976
Peter Boström0c4e06b2015-10-07 12:23:21 +02001977template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001979 uint32_t ssrc,
1980 int flags,
1981 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 video->AddLegacyStream(ssrc);
1983}
1984
1985class VideoChannelTest
1986 : public ChannelTest<VideoTraits> {
1987 public:
solenberg1dd98f32015-09-10 01:57:14 -07001988 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001989 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001990 : Base(false,
1991 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001992 sizeof(kH264Packet),
1993 kRtcpReport,
1994 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995};
1996
1997
1998// VoiceChannelTest
1999
2000TEST_F(VoiceChannelTest, TestInit) {
2001 Base::TestInit();
2002 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2003 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2004}
2005
2006TEST_F(VoiceChannelTest, TestSetContents) {
2007 Base::TestSetContents();
2008}
2009
2010TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2011 Base::TestSetContentsNullOffer();
2012}
2013
2014TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2015 Base::TestSetContentsRtcpMux();
2016}
2017
2018TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2019 Base::TestSetContentsRtcpMux();
2020}
2021
2022TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2023 Base::TestSetRemoteContentUpdate();
2024}
2025
2026TEST_F(VoiceChannelTest, TestStreams) {
2027 Base::TestStreams();
2028}
2029
2030TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2031 Base::TestUpdateStreamsInLocalContent();
2032}
2033
2034TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2035 Base::TestUpdateStreamsInRemoteContent();
2036}
2037
2038TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2039 Base::TestChangeStreamParamsInContent();
2040}
2041
2042TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2043 Base::TestPlayoutAndSendingStates();
2044}
2045
2046TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002047 CreateChannels(0, 0);
2048 // Test that we can Mute the default channel even though the sending SSRC
2049 // is unknown.
2050 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002051 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002052 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2053 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002054 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2055
2056 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002057 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002058
2059 SendInitiate();
2060 // After the local session description has been set, we can mute a stream
2061 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002062 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002063 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2064 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002065 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002066}
2067
2068TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2069 Base::TestMediaContentDirection();
2070}
2071
2072TEST_F(VoiceChannelTest, TestCallSetup) {
2073 Base::TestCallSetup();
2074}
2075
2076TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2077 Base::TestCallTeardownRtcpMux();
2078}
2079
2080TEST_F(VoiceChannelTest, SendRtpToRtp) {
2081 Base::SendRtpToRtp();
2082}
2083
2084TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2085 Base::SendNoRtcpToNoRtcp();
2086}
2087
2088TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2089 Base::SendNoRtcpToRtcp();
2090}
2091
2092TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2093 Base::SendRtcpToNoRtcp();
2094}
2095
2096TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2097 Base::SendRtcpToRtcp();
2098}
2099
2100TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2101 Base::SendRtcpMuxToRtcp();
2102}
2103
2104TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2105 Base::SendRtcpMuxToRtcpMux();
2106}
2107
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002108TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2109 Base::SendRequireRtcpMuxToRtcpMux();
2110}
2111
2112TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2113 Base::SendRtcpMuxToRequireRtcpMux();
2114}
2115
2116TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2117 Base::SendRequireRtcpMuxToRequireRtcpMux();
2118}
2119
2120TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2121 Base::SendRequireRtcpMuxToNoRtcpMux();
2122}
2123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2125 Base::SendEarlyRtcpMuxToRtcp();
2126}
2127
2128TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2129 Base::SendEarlyRtcpMuxToRtcpMux();
2130}
2131
2132TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2133 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2134}
2135
2136TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2137 Base::SendSrtpToSrtp();
2138}
2139
2140TEST_F(VoiceChannelTest, SendSrtcpMux) {
2141 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2142}
2143
2144TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2145 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2146 Base::SendSrtpToSrtp(DTLS, 0);
2147}
2148
2149TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2150 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2151 Base::SendSrtpToSrtp(DTLS, DTLS);
2152}
2153
2154TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2155 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2156 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2157}
2158
2159TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2160 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2161}
2162
2163TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2164 Base::SendRtpToRtpOnThread();
2165}
2166
2167TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2168 Base::SendSrtpToSrtpOnThread();
2169}
2170
2171TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2172 Base::SendWithWritabilityLoss();
2173}
2174
2175TEST_F(VoiceChannelTest, TestMediaMonitor) {
2176 Base::TestMediaMonitor();
2177}
2178
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179// Test that InsertDtmf properly forwards to the media channel.
2180TEST_F(VoiceChannelTest, TestInsertDtmf) {
2181 CreateChannels(0, 0);
2182 EXPECT_TRUE(SendInitiate());
2183 EXPECT_TRUE(SendAccept());
2184 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2185
solenberg1d63dd02015-12-02 12:35:09 -08002186 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2187 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2188 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002190 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002192 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002193 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002194 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002195 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002196 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002197}
2198
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199TEST_F(VoiceChannelTest, TestSetContentFailure) {
2200 Base::TestSetContentFailure();
2201}
2202
2203TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2204 Base::TestSendTwoOffers();
2205}
2206
2207TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2208 Base::TestReceiveTwoOffers();
2209}
2210
2211TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2212 Base::TestSendPrAnswer();
2213}
2214
2215TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2216 Base::TestReceivePrAnswer();
2217}
2218
2219TEST_F(VoiceChannelTest, TestFlushRtcp) {
2220 Base::TestFlushRtcp();
2221}
2222
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002224 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225}
2226
2227TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2228 Base::TestOnReadyToSend();
2229}
2230
2231TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2232 Base::TestOnReadyToSendWithRtcpMux();
2233}
2234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235// Test that we can scale the output volume properly for 1:1 calls.
2236TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2237 CreateChannels(RTCP, RTCP);
2238 EXPECT_TRUE(SendInitiate());
2239 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002240 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241
solenberg4bac9c52015-10-09 02:32:53 -07002242 // Default is (1.0).
2243 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2244 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002246 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247
solenberg4bac9c52015-10-09 02:32:53 -07002248 // Set scale to (1.5).
2249 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2250 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2251 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252
solenberg4bac9c52015-10-09 02:32:53 -07002253 // Set scale to (0).
2254 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2255 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2256 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257}
2258
2259// Test that we can scale the output volume properly for multiway calls.
2260TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2261 CreateChannels(RTCP, RTCP);
2262 EXPECT_TRUE(SendInitiate());
2263 EXPECT_TRUE(SendAccept());
2264 EXPECT_TRUE(AddStream1(1));
2265 EXPECT_TRUE(AddStream1(2));
2266
solenberg4bac9c52015-10-09 02:32:53 -07002267 double volume;
2268 // Default is (1.0).
2269 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2270 EXPECT_DOUBLE_EQ(1.0, volume);
2271 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2272 EXPECT_DOUBLE_EQ(1.0, volume);
2273 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2274 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002276 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277
solenberg4bac9c52015-10-09 02:32:53 -07002278 // Set scale to (1.5) for ssrc = 1.
2279 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2280 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2281 EXPECT_DOUBLE_EQ(1.5, volume);
2282 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2283 EXPECT_DOUBLE_EQ(1.0, volume);
2284 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2285 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286
solenberg4bac9c52015-10-09 02:32:53 -07002287 // Set scale to (0) for all ssrcs.
2288 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2289 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2290 EXPECT_DOUBLE_EQ(0.0, volume);
2291 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2292 EXPECT_DOUBLE_EQ(0.0, volume);
2293 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2294 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295}
2296
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002297TEST_F(VoiceChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002298 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299}
2300
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002301TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002302 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002303}
2304
2305TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002306 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002307}
2308
2309TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002310 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311}
2312
skvladdc1c62c2016-03-16 19:07:43 -07002313TEST_F(VoiceChannelTest, GetRtpParametersIsNotImplemented) {
2314 // These tests verify that the Get/SetRtpParameters methods for VoiceChannel
2315 // always fail as they are not implemented.
2316 // TODO(skvlad): Replace with full tests when support for bitrate limiting
2317 // for audio RtpSenders is added.
2318 CreateChannels(0, 0);
2319 EXPECT_TRUE(
2320 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
2321 webrtc::RtpParameters voice_parameters = channel1_->GetRtpParameters(kSsrc1);
2322 EXPECT_EQ(0UL, voice_parameters.encodings.size());
2323}
2324
2325TEST_F(VoiceChannelTest, SetRtpParametersIsNotImplemented) {
2326 CreateChannels(0, 0);
2327 EXPECT_TRUE(
2328 channel1_->SetLocalContent(&local_media_content1_, CA_OFFER, NULL));
2329 EXPECT_FALSE(
2330 channel1_->SetRtpParameters(kSsrc1, BitrateLimitedParameters(1000)));
2331}
2332
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333// VideoChannelTest
2334TEST_F(VideoChannelTest, TestInit) {
2335 Base::TestInit();
2336}
2337
2338TEST_F(VideoChannelTest, TestSetContents) {
2339 Base::TestSetContents();
2340}
2341
2342TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2343 Base::TestSetContentsNullOffer();
2344}
2345
2346TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2347 Base::TestSetContentsRtcpMux();
2348}
2349
2350TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2351 Base::TestSetContentsRtcpMux();
2352}
2353
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2355 Base::TestSetRemoteContentUpdate();
2356}
2357
2358TEST_F(VideoChannelTest, TestStreams) {
2359 Base::TestStreams();
2360}
2361
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2363 Base::TestUpdateStreamsInLocalContent();
2364}
2365
2366TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2367 Base::TestUpdateStreamsInRemoteContent();
2368}
2369
2370TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2371 Base::TestChangeStreamParamsInContent();
2372}
2373
2374TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2375 Base::TestPlayoutAndSendingStates();
2376}
2377
2378TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002379 CreateChannels(0, 0);
2380 // Test that we can Mute the default channel even though the sending SSRC
2381 // is unknown.
2382 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002383 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002384 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2385 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002386 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2387 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002388 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002389 SendInitiate();
2390 // After the local session description has been set, we can mute a stream
2391 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002392 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002393 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2394 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002395 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396}
2397
2398TEST_F(VideoChannelTest, TestMediaContentDirection) {
2399 Base::TestMediaContentDirection();
2400}
2401
2402TEST_F(VideoChannelTest, TestCallSetup) {
2403 Base::TestCallSetup();
2404}
2405
2406TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2407 Base::TestCallTeardownRtcpMux();
2408}
2409
2410TEST_F(VideoChannelTest, SendRtpToRtp) {
2411 Base::SendRtpToRtp();
2412}
2413
2414TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2415 Base::SendNoRtcpToNoRtcp();
2416}
2417
2418TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2419 Base::SendNoRtcpToRtcp();
2420}
2421
2422TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2423 Base::SendRtcpToNoRtcp();
2424}
2425
2426TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2427 Base::SendRtcpToRtcp();
2428}
2429
2430TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2431 Base::SendRtcpMuxToRtcp();
2432}
2433
2434TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2435 Base::SendRtcpMuxToRtcpMux();
2436}
2437
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002438TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2439 Base::SendRequireRtcpMuxToRtcpMux();
2440}
2441
2442TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2443 Base::SendRtcpMuxToRequireRtcpMux();
2444}
2445
2446TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2447 Base::SendRequireRtcpMuxToRequireRtcpMux();
2448}
2449
2450TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2451 Base::SendRequireRtcpMuxToNoRtcpMux();
2452}
2453
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002454TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2455 Base::SendEarlyRtcpMuxToRtcp();
2456}
2457
2458TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2459 Base::SendEarlyRtcpMuxToRtcpMux();
2460}
2461
2462TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2463 Base::SendSrtpToSrtp();
2464}
2465
2466TEST_F(VideoChannelTest, SendSrtpToRtp) {
2467 Base::SendSrtpToSrtp();
2468}
2469
2470TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2471 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2472 Base::SendSrtpToSrtp(DTLS, 0);
2473}
2474
2475TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2476 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2477 Base::SendSrtpToSrtp(DTLS, DTLS);
2478}
2479
2480TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2481 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2482 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2483}
2484
2485TEST_F(VideoChannelTest, SendSrtcpMux) {
2486 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2487}
2488
2489TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2490 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2491}
2492
2493TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2494 Base::SendRtpToRtpOnThread();
2495}
2496
2497TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2498 Base::SendSrtpToSrtpOnThread();
2499}
2500
2501TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2502 Base::SendWithWritabilityLoss();
2503}
2504
2505TEST_F(VideoChannelTest, TestMediaMonitor) {
2506 Base::TestMediaMonitor();
2507}
2508
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509TEST_F(VideoChannelTest, TestSetContentFailure) {
2510 Base::TestSetContentFailure();
2511}
2512
2513TEST_F(VideoChannelTest, TestSendTwoOffers) {
2514 Base::TestSendTwoOffers();
2515}
2516
2517TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2518 Base::TestReceiveTwoOffers();
2519}
2520
2521TEST_F(VideoChannelTest, TestSendPrAnswer) {
2522 Base::TestSendPrAnswer();
2523}
2524
2525TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2526 Base::TestReceivePrAnswer();
2527}
2528
2529TEST_F(VideoChannelTest, TestFlushRtcp) {
2530 Base::TestFlushRtcp();
2531}
2532
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002533TEST_F(VideoChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002534 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535}
2536
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002537TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002538 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002539}
2540
2541TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002542 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002543}
2544
2545TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002546 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547}
2548
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002550 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551}
2552
2553TEST_F(VideoChannelTest, TestOnReadyToSend) {
2554 Base::TestOnReadyToSend();
2555}
2556
2557TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2558 Base::TestOnReadyToSendWithRtcpMux();
2559}
2560
skvladdc1c62c2016-03-16 19:07:43 -07002561TEST_F(VideoChannelTest, DefaultMaxBitrateIsUnlimited) {
2562 Base::DefaultMaxBitrateIsUnlimited();
2563}
2564
2565TEST_F(VideoChannelTest, CanChangeMaxBitrate) {
2566 Base::CanChangeMaxBitrate();
2567}
2568
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569// DataChannelTest
2570
2571class DataChannelTest
2572 : public ChannelTest<DataTraits> {
2573 public:
2574 typedef ChannelTest<DataTraits>
2575 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002576 DataChannelTest()
2577 : Base(true,
2578 kDataPacket,
2579 sizeof(kDataPacket),
2580 kRtcpReport,
2581 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582};
2583
2584// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002585template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002587 rtc::Thread* thread,
2588 cricket::MediaEngineInterface* engine,
2589 cricket::FakeDataMediaChannel* ch,
2590 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 bool rtcp) {
2592 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002593 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594 if (!channel->Init()) {
2595 delete channel;
2596 channel = NULL;
2597 }
2598 return channel;
2599}
2600
2601template<>
2602void ChannelTest<DataTraits>::CreateContent(
2603 int flags,
2604 const cricket::AudioCodec& audio_codec,
2605 const cricket::VideoCodec& video_codec,
2606 cricket::DataContentDescription* data) {
2607 data->AddCodec(kGoogleDataCodec);
2608 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2609 if (flags & SECURE) {
2610 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002611 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2612 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 }
2614}
2615
2616template<>
2617void ChannelTest<DataTraits>::CopyContent(
2618 const cricket::DataContentDescription& source,
2619 cricket::DataContentDescription* data) {
2620 *data = source;
2621}
2622
2623template<>
2624bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2625 const cricket::DataCodec& c2) {
2626 return c1.name == c2.name;
2627}
2628
Peter Boström0c4e06b2015-10-07 12:23:21 +02002629template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002630void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002631 uint32_t ssrc,
2632 int flags,
2633 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 data->AddLegacyStream(ssrc);
2635}
2636
2637TEST_F(DataChannelTest, TestInit) {
2638 Base::TestInit();
2639 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2640}
2641
2642TEST_F(DataChannelTest, TestSetContents) {
2643 Base::TestSetContents();
2644}
2645
2646TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2647 Base::TestSetContentsNullOffer();
2648}
2649
2650TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2651 Base::TestSetContentsRtcpMux();
2652}
2653
2654TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2655 Base::TestSetRemoteContentUpdate();
2656}
2657
2658TEST_F(DataChannelTest, TestStreams) {
2659 Base::TestStreams();
2660}
2661
2662TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2663 Base::TestUpdateStreamsInLocalContent();
2664}
2665
2666TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2667 Base::TestUpdateStreamsInRemoteContent();
2668}
2669
2670TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2671 Base::TestChangeStreamParamsInContent();
2672}
2673
2674TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2675 Base::TestPlayoutAndSendingStates();
2676}
2677
2678TEST_F(DataChannelTest, TestMediaContentDirection) {
2679 Base::TestMediaContentDirection();
2680}
2681
2682TEST_F(DataChannelTest, TestCallSetup) {
2683 Base::TestCallSetup();
2684}
2685
2686TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2687 Base::TestCallTeardownRtcpMux();
2688}
2689
2690TEST_F(DataChannelTest, TestOnReadyToSend) {
2691 Base::TestOnReadyToSend();
2692}
2693
2694TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2695 Base::TestOnReadyToSendWithRtcpMux();
2696}
2697
2698TEST_F(DataChannelTest, SendRtpToRtp) {
2699 Base::SendRtpToRtp();
2700}
2701
2702TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2703 Base::SendNoRtcpToNoRtcp();
2704}
2705
2706TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2707 Base::SendNoRtcpToRtcp();
2708}
2709
2710TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2711 Base::SendRtcpToNoRtcp();
2712}
2713
2714TEST_F(DataChannelTest, SendRtcpToRtcp) {
2715 Base::SendRtcpToRtcp();
2716}
2717
2718TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2719 Base::SendRtcpMuxToRtcp();
2720}
2721
2722TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2723 Base::SendRtcpMuxToRtcpMux();
2724}
2725
2726TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2727 Base::SendEarlyRtcpMuxToRtcp();
2728}
2729
2730TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2731 Base::SendEarlyRtcpMuxToRtcpMux();
2732}
2733
2734TEST_F(DataChannelTest, SendSrtpToSrtp) {
2735 Base::SendSrtpToSrtp();
2736}
2737
2738TEST_F(DataChannelTest, SendSrtpToRtp) {
2739 Base::SendSrtpToSrtp();
2740}
2741
2742TEST_F(DataChannelTest, SendSrtcpMux) {
2743 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2744}
2745
2746TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2747 Base::SendRtpToRtpOnThread();
2748}
2749
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2751 Base::SendSrtpToSrtpOnThread();
2752}
2753
2754TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2755 Base::SendWithWritabilityLoss();
2756}
2757
2758TEST_F(DataChannelTest, TestMediaMonitor) {
2759 Base::TestMediaMonitor();
2760}
2761
2762TEST_F(DataChannelTest, TestSendData) {
2763 CreateChannels(0, 0);
2764 EXPECT_TRUE(SendInitiate());
2765 EXPECT_TRUE(SendAccept());
2766
2767 cricket::SendDataParams params;
2768 params.ssrc = 42;
2769 unsigned char data[] = {
2770 'f', 'o', 'o'
2771 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002772 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002773 cricket::SendDataResult result;
2774 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2775 EXPECT_EQ(params.ssrc,
2776 media_channel1_->last_sent_data_params().ssrc);
2777 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2778}
2779
2780// TODO(pthatcher): TestSetReceiver?