blob: 7b4a31a1b348974663580509e00a90ff75d406b8 [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"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000014#include "webrtc/base/fileutils.h"
15#include "webrtc/base/gunit.h"
16#include "webrtc/base/helpers.h"
17#include "webrtc/base/logging.h"
18#include "webrtc/base/pathutils.h"
19#include "webrtc/base/signalthread.h"
20#include "webrtc/base/ssladapter.h"
21#include "webrtc/base/sslidentity.h"
22#include "webrtc/base/window.h"
kjellandera96e2d72016-02-04 23:52:28 -080023#include "webrtc/media/base/fakemediaengine.h"
24#include "webrtc/media/base/fakertp.h"
25#include "webrtc/media/base/fakescreencapturerfactory.h"
26#include "webrtc/media/base/fakevideocapturer.h"
27#include "webrtc/media/base/mediachannel.h"
28#include "webrtc/media/base/rtpdump.h"
29#include "webrtc/media/base/screencastid.h"
30#include "webrtc/media/base/testutils.h"
Tommif888bb52015-12-12 01:37:01 +010031#include "webrtc/p2p/base/faketransportcontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010032#include "webrtc/pc/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033
34#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000035 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036 LOG(LS_INFO) << "Feature disabled... skipping"; \
37 return; \
38 }
39
40using cricket::CA_OFFER;
41using cricket::CA_PRANSWER;
42using cricket::CA_ANSWER;
43using cricket::CA_UPDATE;
44using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045using cricket::ScreencastId;
46using cricket::StreamParams;
47using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000048using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
51static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
52static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
53static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
54static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
55static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
Peter Boström0c4e06b2015-10-07 12:23:21 +020056static const uint32_t kSsrc1 = 0x1111;
57static const uint32_t kSsrc2 = 0x2222;
58static const uint32_t kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000059static const int kAudioPts[] = {0, 8};
60static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
deadbeefcbecd352015-09-23 11:50:27 -070062template <class ChannelT,
63 class MediaChannelT,
64 class ContentT,
65 class CodecT,
66 class MediaInfoT,
67 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068class Traits {
69 public:
70 typedef ChannelT Channel;
71 typedef MediaChannelT MediaChannel;
72 typedef ContentT Content;
73 typedef CodecT Codec;
74 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020075 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076};
77
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078// Controls how long we wait for a session to send messages that we
79// expect, in milliseconds. We put it high to avoid flaky tests.
80static const int kEventTimeout = 5000;
81
82class VoiceTraits : public Traits<cricket::VoiceChannel,
83 cricket::FakeVoiceMediaChannel,
84 cricket::AudioContentDescription,
85 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020086 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070087 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088
89class VideoTraits : public Traits<cricket::VideoChannel,
90 cricket::FakeVideoMediaChannel,
91 cricket::VideoContentDescription,
92 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +020093 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -070094 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095
96class DataTraits : public Traits<cricket::DataChannel,
97 cricket::FakeDataMediaChannel,
98 cricket::DataContentDescription,
99 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200100 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700101 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000103rtc::StreamInterface* Open(const std::string& path) {
104 return rtc::Filesystem::OpenFile(
105 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106}
107
108// Base class for Voice/VideoChannel tests
109template<class T>
110class ChannelTest : public testing::Test, public sigslot::has_slots<> {
111 public:
112 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
113 DTLS = 0x10 };
114
Peter Boström34fbfff2015-09-24 19:20:30 +0200115 ChannelTest(bool verify_playout,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200116 const uint8_t* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700117 int rtp_len,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200118 const uint8_t* rtcp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700119 int rtcp_len)
Peter Boström34fbfff2015-09-24 19:20:30 +0200120 : verify_playout_(verify_playout),
121 transport_controller1_(cricket::ICEROLE_CONTROLLING),
deadbeefcbecd352015-09-23 11:50:27 -0700122 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 media_channel1_(NULL),
124 media_channel2_(NULL),
125 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
126 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
127 media_info_callbacks1_(),
solenberg5b14b422015-10-01 04:10:31 -0700128 media_info_callbacks2_() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000130 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200131 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
132 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000133 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 void CreateChannels(
136 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000137 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 media_channel1_ = ch1;
139 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700140 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
141 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700143 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
144 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 (flags2 & RTCP) != 0));
146 channel1_->SignalMediaMonitor.connect(
147 this, &ChannelTest<T>::OnMediaMonitor);
148 channel2_->SignalMediaMonitor.connect(
149 this, &ChannelTest<T>::OnMediaMonitor);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000150 if ((flags1 & DTLS) && (flags2 & DTLS)) {
151 flags1 = (flags1 & ~SECURE);
152 flags2 = (flags2 & ~SECURE);
153 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 CreateContent(flags1, kPcmuCodec, kH264Codec,
155 &local_media_content1_);
156 CreateContent(flags2, kPcmuCodec, kH264Codec,
157 &local_media_content2_);
158 CopyContent(local_media_content1_, &remote_media_content1_);
159 CopyContent(local_media_content2_, &remote_media_content2_);
160
161 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200162 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800163 transport_controller1_.SetLocalCertificate(
164 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
165 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 }
167 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200168 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800169 transport_controller2_.SetLocalCertificate(
170 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
171 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
173
174 // Add stream information (SSRC) to the local content but not to the remote
175 // content. This means that we per default know the SSRC of what we send but
176 // not what we receive.
177 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
178 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
179
180 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
181 if (flags1 & SSRC_MUX) {
182 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
183 }
184 if (flags2 & SSRC_MUX) {
185 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
186 }
187 }
deadbeefcbecd352015-09-23 11:50:27 -0700188 typename T::Channel* CreateChannel(
189 rtc::Thread* thread,
190 cricket::MediaEngineInterface* engine,
191 typename T::MediaChannel* ch,
192 cricket::TransportController* transport_controller,
193 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000194 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700195 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 if (!channel->Init()) {
197 delete channel;
198 channel = NULL;
199 }
200 return channel;
201 }
202
203 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000204 bool result = channel1_->SetLocalContent(&local_media_content1_,
205 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 if (result) {
207 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000208 result = channel2_->SetRemoteContent(&remote_media_content1_,
209 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700211 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000213 result = channel2_->SetLocalContent(&local_media_content2_,
214 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000215 }
216 }
217 return result;
218 }
219
220 bool SendAccept() {
221 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000222 return channel1_->SetRemoteContent(&remote_media_content2_,
223 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 }
225
226 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000227 bool result = channel1_->SetLocalContent(&local_media_content1_,
228 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 if (result) {
230 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000231 result = channel2_->SetRemoteContent(&remote_media_content1_,
232 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233 }
234 return result;
235 }
236
237 bool SendProvisionalAnswer() {
238 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000239 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 if (result) {
241 channel2_->Enable(true);
242 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000243 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700244 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 }
246 return result;
247 }
248
249 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000250 bool result = channel2_->SetLocalContent(&local_media_content2_,
251 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000253 result = channel1_->SetRemoteContent(&remote_media_content2_,
254 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 return result;
256 }
257
258 bool SendTerminate() {
259 channel1_.reset();
260 channel2_.reset();
261 return true;
262 }
263
264 bool AddStream1(int id) {
265 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
266 }
267 bool RemoveStream1(int id) {
268 return channel1_->RemoveRecvStream(id);
269 }
270
deadbeefcbecd352015-09-23 11:50:27 -0700271 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700273 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 }
275 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700276 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 }
278
279 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000280 return media_channel1_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700281 static_cast<int>(rtp_packet_.size()),
282 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 }
284 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000285 return media_channel2_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700286 static_cast<int>(rtp_packet_.size()),
287 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 }
289 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000290 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
291 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 }
293 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000294 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
295 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 }
297 // Methods to send custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200298 bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000299 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700300 return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()),
301 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200303 bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000304 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700305 return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()),
306 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200308 bool SendCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000310 return media_channel1_->SendRtcp(data.c_str(),
311 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200313 bool SendCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000315 return media_channel2_->SendRtcp(data.c_str(),
316 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 }
318 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000319 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
320 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
322 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000323 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
324 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 }
326 bool CheckRtcp1() {
327 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000328 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
330 bool CheckRtcp2() {
331 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000332 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
334 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200335 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000336 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000337 return media_channel1_->CheckRtp(data.c_str(),
338 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200340 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000341 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000342 return media_channel2_->CheckRtp(data.c_str(),
343 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200345 bool CheckCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000347 return media_channel1_->CheckRtcp(data.c_str(),
348 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200350 bool CheckCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000352 return media_channel2_->CheckRtcp(data.c_str(),
353 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200355 std::string CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 std::string data(rtp_packet_);
357 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000358 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
359 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000360 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000361 rtc::Set8(const_cast<char*>(data.c_str()), 1,
362 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000363 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 return data;
365 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200366 std::string CreateRtcpData(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 std::string data(rtcp_packet_);
368 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000369 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 return data;
371 }
372
373 bool CheckNoRtp1() {
374 return media_channel1_->CheckNoRtp();
375 }
376 bool CheckNoRtp2() {
377 return media_channel2_->CheckNoRtp();
378 }
379 bool CheckNoRtcp1() {
380 return media_channel1_->CheckNoRtcp();
381 }
382 bool CheckNoRtcp2() {
383 return media_channel2_->CheckNoRtcp();
384 }
385
386 void CreateContent(int flags,
387 const cricket::AudioCodec& audio_codec,
388 const cricket::VideoCodec& video_codec,
389 typename T::Content* content) {
390 // overridden in specialized classes
391 }
392 void CopyContent(const typename T::Content& source,
393 typename T::Content* content) {
394 // overridden in specialized classes
395 }
396
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 // Creates a cricket::SessionDescription with one MediaContent and one stream.
398 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200399 cricket::SessionDescription* CreateSessionDescriptionWithStream(
400 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000401 typename T::Content content;
402 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
403 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
404 AddLegacyStreamInContent(ssrc, 0, &content);
405 sdesc->AddContent("DUMMY_CONTENT_NAME",
406 cricket::NS_JINGLE_RTP, content.Copy());
407 return sdesc;
408 }
409
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000410 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 public:
412 typedef bool (ChannelTest<T>::*Method)();
413 CallThread(ChannelTest<T>* obj, Method method, bool* result)
414 : obj_(obj),
415 method_(method),
416 result_(result) {
417 *result = false;
418 }
419 virtual void DoWork() {
420 bool result = (*obj_.*method_)();
421 if (result_) {
422 *result_ = result;
423 }
424 }
425 private:
426 ChannelTest<T>* obj_;
427 Method method_;
428 bool* result_;
429 };
430 void CallOnThread(typename CallThread::Method method, bool* result) {
431 CallThread* thread = new CallThread(this, method, result);
432 thread->Start();
433 thread->Release();
434 }
435
436 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
437 bool* result) {
438 CallThread* thread = new CallThread(this, method, result);
439 thread->Start();
440 thread->Destroy(true);
441 }
442
443 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
444 return false; // overridden in specialized classes
445 }
446
447 void OnMediaMonitor(typename T::Channel* channel,
448 const typename T::MediaInfo& info) {
449 if (channel == channel1_.get()) {
450 media_info_callbacks1_++;
451 } else if (channel == channel2_.get()) {
452 media_info_callbacks2_++;
453 }
454 }
455
Peter Boström0c4e06b2015-10-07 12:23:21 +0200456 void AddLegacyStreamInContent(uint32_t ssrc,
457 int flags,
458 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 // Base implementation.
460 }
461
462 // Tests that can be used by derived classes.
463
464 // Basic sanity check.
465 void TestInit() {
466 CreateChannels(0, 0);
467 EXPECT_FALSE(channel1_->secure());
468 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200469 if (verify_playout_) {
470 EXPECT_FALSE(media_channel1_->playout());
471 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 EXPECT_TRUE(media_channel1_->codecs().empty());
473 EXPECT_TRUE(media_channel1_->recv_streams().empty());
474 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
475 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
476 }
477
478 // Test that SetLocalContent and SetRemoteContent properly configure
479 // the codecs.
480 void TestSetContents() {
481 CreateChannels(0, 0);
482 typename T::Content content;
483 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000484 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000485 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000486 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 ASSERT_EQ(1U, media_channel1_->codecs().size());
488 EXPECT_TRUE(CodecMatches(content.codecs()[0],
489 media_channel1_->codecs()[0]));
490 }
491
492 // Test that SetLocalContent and SetRemoteContent properly deals
493 // with an empty offer.
494 void TestSetContentsNullOffer() {
495 CreateChannels(0, 0);
496 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000497 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498 CreateContent(0, kPcmuCodec, kH264Codec, &content);
499 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000500 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 ASSERT_EQ(1U, media_channel1_->codecs().size());
502 EXPECT_TRUE(CodecMatches(content.codecs()[0],
503 media_channel1_->codecs()[0]));
504 }
505
506 // Test that SetLocalContent and SetRemoteContent properly set RTCP
507 // mux.
508 void TestSetContentsRtcpMux() {
509 CreateChannels(RTCP, RTCP);
510 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
511 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
512 typename T::Content content;
513 CreateContent(0, kPcmuCodec, kH264Codec, &content);
514 // Both sides agree on mux. Should no longer be a separate RTCP channel.
515 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000516 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
517 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
519 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000520 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000522 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
524 }
525
526 // Test that SetLocalContent and SetRemoteContent properly set RTCP
527 // mux when a provisional answer is received.
528 void TestSetContentsRtcpMuxWithPrAnswer() {
529 CreateChannels(RTCP, RTCP);
530 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
531 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
532 typename T::Content content;
533 CreateContent(0, kPcmuCodec, kH264Codec, &content);
534 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000535 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
536 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000538 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 // Both sides agree on mux. Should no longer be a separate RTCP channel.
540 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
541 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000542 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000544 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
545 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
547 }
548
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 // Test that SetRemoteContent properly deals with a content update.
550 void TestSetRemoteContentUpdate() {
551 CreateChannels(0, 0);
552 typename T::Content content;
553 CreateContent(RTCP | RTCP_MUX | SECURE,
554 kPcmuCodec, kH264Codec,
555 &content);
556 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000557 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
558 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 ASSERT_EQ(1U, media_channel1_->codecs().size());
560 EXPECT_TRUE(CodecMatches(content.codecs()[0],
561 media_channel1_->codecs()[0]));
562 // Now update with other codecs.
563 typename T::Content update_content;
564 update_content.set_partial(true);
565 CreateContent(0, kIsacCodec, kH264SvcCodec,
566 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000567 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 ASSERT_EQ(1U, media_channel1_->codecs().size());
569 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
570 media_channel1_->codecs()[0]));
571 // Now update without any codecs. This is ignored.
572 typename T::Content empty_content;
573 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000574 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 ASSERT_EQ(1U, media_channel1_->codecs().size());
576 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
577 media_channel1_->codecs()[0]));
578 }
579
580 // Test that Add/RemoveStream properly forward to the media channel.
581 void TestStreams() {
582 CreateChannels(0, 0);
583 EXPECT_TRUE(AddStream1(1));
584 EXPECT_TRUE(AddStream1(2));
585 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
586 EXPECT_TRUE(RemoveStream1(2));
587 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
588 EXPECT_TRUE(RemoveStream1(1));
589 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
590 }
591
592 // Test that SetLocalContent properly handles adding and removing StreamParams
593 // to the local content description.
594 // This test uses the CA_UPDATE action that don't require a full
595 // MediaContentDescription to do an update.
596 void TestUpdateStreamsInLocalContent() {
597 cricket::StreamParams stream1;
598 stream1.groupid = "group1";
599 stream1.id = "stream1";
600 stream1.ssrcs.push_back(kSsrc1);
601 stream1.cname = "stream1_cname";
602
603 cricket::StreamParams stream2;
604 stream2.groupid = "group2";
605 stream2.id = "stream2";
606 stream2.ssrcs.push_back(kSsrc2);
607 stream2.cname = "stream2_cname";
608
609 cricket::StreamParams stream3;
610 stream3.groupid = "group3";
611 stream3.id = "stream3";
612 stream3.ssrcs.push_back(kSsrc3);
613 stream3.cname = "stream3_cname";
614
615 CreateChannels(0, 0);
616 typename T::Content content1;
617 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
618 content1.AddStream(stream1);
619 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000620 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621
622 ASSERT_EQ(1u, media_channel1_->send_streams().size());
623 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
624
625 // Update the local streams by adding another sending stream.
626 // Use a partial updated session description.
627 typename T::Content content2;
628 content2.AddStream(stream2);
629 content2.AddStream(stream3);
630 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000631 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 ASSERT_EQ(3u, media_channel1_->send_streams().size());
633 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
634 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
635 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
636
637 // Update the local streams by removing the first sending stream.
638 // This is done by removing all SSRCS for this particular stream.
639 typename T::Content content3;
640 stream1.ssrcs.clear();
641 content3.AddStream(stream1);
642 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000643 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 ASSERT_EQ(2u, media_channel1_->send_streams().size());
645 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
646 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
647
648 // Update the local streams with a stream that does not change.
649 // THe update is ignored.
650 typename T::Content content4;
651 content4.AddStream(stream2);
652 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000653 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000654 ASSERT_EQ(2u, media_channel1_->send_streams().size());
655 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
656 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
657 }
658
659 // Test that SetRemoteContent properly handles adding and removing
660 // StreamParams to the remote content description.
661 // This test uses the CA_UPDATE action that don't require a full
662 // MediaContentDescription to do an update.
663 void TestUpdateStreamsInRemoteContent() {
664 cricket::StreamParams stream1;
665 stream1.id = "Stream1";
666 stream1.groupid = "1";
667 stream1.ssrcs.push_back(kSsrc1);
668 stream1.cname = "stream1_cname";
669
670 cricket::StreamParams stream2;
671 stream2.id = "Stream2";
672 stream2.groupid = "2";
673 stream2.ssrcs.push_back(kSsrc2);
674 stream2.cname = "stream2_cname";
675
676 cricket::StreamParams stream3;
677 stream3.id = "Stream3";
678 stream3.groupid = "3";
679 stream3.ssrcs.push_back(kSsrc3);
680 stream3.cname = "stream3_cname";
681
682 CreateChannels(0, 0);
683 typename T::Content content1;
684 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
685 content1.AddStream(stream1);
686 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000687 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688
689 ASSERT_EQ(1u, media_channel1_->codecs().size());
690 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
691 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
692
693 // Update the remote streams by adding another sending stream.
694 // Use a partial updated session description.
695 typename T::Content content2;
696 content2.AddStream(stream2);
697 content2.AddStream(stream3);
698 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
701 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
702 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
703 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
704
705 // Update the remote streams by removing the first stream.
706 // This is done by removing all SSRCS for this particular stream.
707 typename T::Content content3;
708 stream1.ssrcs.clear();
709 content3.AddStream(stream1);
710 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000711 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
713 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
714 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
715
716 // Update the remote streams with a stream that does not change.
717 // The update is ignored.
718 typename T::Content content4;
719 content4.AddStream(stream2);
720 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000721 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
723 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
724 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
725 }
726
727 // Test that SetLocalContent and SetRemoteContent properly
728 // handles adding and removing StreamParams when the action is a full
729 // CA_OFFER / CA_ANSWER.
730 void TestChangeStreamParamsInContent() {
731 cricket::StreamParams stream1;
732 stream1.groupid = "group1";
733 stream1.id = "stream1";
734 stream1.ssrcs.push_back(kSsrc1);
735 stream1.cname = "stream1_cname";
736
737 cricket::StreamParams stream2;
738 stream2.groupid = "group1";
739 stream2.id = "stream2";
740 stream2.ssrcs.push_back(kSsrc2);
741 stream2.cname = "stream2_cname";
742
743 // Setup a call where channel 1 send |stream1| to channel 2.
744 CreateChannels(0, 0);
745 typename T::Content content1;
746 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
747 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000748 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 EXPECT_TRUE(channel1_->Enable(true));
750 EXPECT_EQ(1u, media_channel1_->send_streams().size());
751
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000752 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700754 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755
756 // Channel 2 do not send anything.
757 typename T::Content content2;
758 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000759 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000761 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 EXPECT_TRUE(channel2_->Enable(true));
763 EXPECT_EQ(0u, media_channel2_->send_streams().size());
764
765 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
766 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
767
768 // Let channel 2 update the content by sending |stream2| and enable SRTP.
769 typename T::Content content3;
770 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
771 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000772 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 ASSERT_EQ(1u, media_channel2_->send_streams().size());
774 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
775
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000776 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
778 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
779
780 // Channel 1 replies but stop sending stream1.
781 typename T::Content content4;
782 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000783 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 EXPECT_EQ(0u, media_channel1_->send_streams().size());
785
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000786 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
788
789 EXPECT_TRUE(channel1_->secure());
790 EXPECT_TRUE(channel2_->secure());
791 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
792 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
793 }
794
795 // Test that we only start playout and sending at the right times.
796 void TestPlayoutAndSendingStates() {
797 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200798 if (verify_playout_) {
799 EXPECT_FALSE(media_channel1_->playout());
800 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200802 if (verify_playout_) {
803 EXPECT_FALSE(media_channel2_->playout());
804 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 EXPECT_FALSE(media_channel2_->sending());
806 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200807 if (verify_playout_) {
808 EXPECT_FALSE(media_channel1_->playout());
809 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000811 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
812 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200813 if (verify_playout_) {
814 EXPECT_TRUE(media_channel1_->playout());
815 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000817 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
818 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200819 if (verify_playout_) {
820 EXPECT_FALSE(media_channel2_->playout());
821 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000823 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
824 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200825 if (verify_playout_) {
826 EXPECT_FALSE(media_channel2_->playout());
827 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700829 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200830 if (verify_playout_) {
831 EXPECT_TRUE(media_channel1_->playout());
832 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200834 if (verify_playout_) {
835 EXPECT_FALSE(media_channel2_->playout());
836 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 EXPECT_FALSE(media_channel2_->sending());
838 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200839 if (verify_playout_) {
840 EXPECT_TRUE(media_channel2_->playout());
841 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000843 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
844 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200845 if (verify_playout_) {
846 EXPECT_TRUE(media_channel1_->playout());
847 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000848 EXPECT_TRUE(media_channel1_->sending());
849 }
850
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 // Test that changing the MediaContentDirection in the local and remote
852 // session description start playout and sending at the right time.
853 void TestMediaContentDirection() {
854 CreateChannels(0, 0);
855 typename T::Content content1;
856 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
857 typename T::Content content2;
858 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
859 // Set |content2| to be InActive.
860 content2.set_direction(cricket::MD_INACTIVE);
861
862 EXPECT_TRUE(channel1_->Enable(true));
863 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200864 if (verify_playout_) {
865 EXPECT_FALSE(media_channel1_->playout());
866 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200868 if (verify_playout_) {
869 EXPECT_FALSE(media_channel2_->playout());
870 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 EXPECT_FALSE(media_channel2_->sending());
872
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000873 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
874 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
875 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
876 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700877 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878
Peter Boström34fbfff2015-09-24 19:20:30 +0200879 if (verify_playout_) {
880 EXPECT_TRUE(media_channel1_->playout());
881 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200883 if (verify_playout_) {
884 EXPECT_FALSE(media_channel2_->playout()); // local InActive
885 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000886 EXPECT_FALSE(media_channel2_->sending()); // local InActive
887
888 // Update |content2| to be RecvOnly.
889 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000890 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
891 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892
Peter Boström34fbfff2015-09-24 19:20:30 +0200893 if (verify_playout_) {
894 EXPECT_TRUE(media_channel1_->playout());
895 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200897 if (verify_playout_) {
898 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
899 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
901
902 // Update |content2| to be SendRecv.
903 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000904 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
905 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906
Peter Boström34fbfff2015-09-24 19:20:30 +0200907 if (verify_playout_) {
908 EXPECT_TRUE(media_channel1_->playout());
909 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200911 if (verify_playout_) {
912 EXPECT_TRUE(media_channel2_->playout());
913 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 EXPECT_TRUE(media_channel2_->sending());
915 }
916
917 // Test setting up a call.
918 void TestCallSetup() {
919 CreateChannels(0, 0);
920 EXPECT_FALSE(channel1_->secure());
921 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200922 if (verify_playout_) {
923 EXPECT_TRUE(media_channel1_->playout());
924 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 EXPECT_FALSE(media_channel1_->sending());
926 EXPECT_TRUE(SendAccept());
927 EXPECT_FALSE(channel1_->secure());
928 EXPECT_TRUE(media_channel1_->sending());
929 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200930 if (verify_playout_) {
931 EXPECT_TRUE(media_channel2_->playout());
932 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 EXPECT_TRUE(media_channel2_->sending());
934 EXPECT_EQ(1U, media_channel2_->codecs().size());
935 }
936
937 // Test that we don't crash if packets are sent during call teardown
938 // when RTCP mux is enabled. This is a regression test against a specific
939 // race condition that would only occur when a RTCP packet was sent during
940 // teardown of a channel on which RTCP mux was enabled.
941 void TestCallTeardownRtcpMux() {
942 class LastWordMediaChannel : public T::MediaChannel {
943 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200944 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700946 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
947 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
949 }
950 };
951 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
952 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000953 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000954 EXPECT_TRUE(SendInitiate());
955 EXPECT_TRUE(SendAccept());
956 EXPECT_TRUE(SendTerminate());
957 }
958
959 // Send voice RTP data to the other side and ensure it gets there.
960 void SendRtpToRtp() {
961 CreateChannels(0, 0);
962 EXPECT_TRUE(SendInitiate());
963 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700964 ASSERT_TRUE(GetTransport1());
965 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 EXPECT_EQ(1U, GetTransport1()->channels().size());
967 EXPECT_EQ(1U, GetTransport2()->channels().size());
968 EXPECT_TRUE(SendRtp1());
969 EXPECT_TRUE(SendRtp2());
970 EXPECT_TRUE(CheckRtp1());
971 EXPECT_TRUE(CheckRtp2());
972 EXPECT_TRUE(CheckNoRtp1());
973 EXPECT_TRUE(CheckNoRtp2());
974 }
975
976 // Check that RTCP is not transmitted if both sides don't support RTCP.
977 void SendNoRtcpToNoRtcp() {
978 CreateChannels(0, 0);
979 EXPECT_TRUE(SendInitiate());
980 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700981 ASSERT_TRUE(GetTransport1());
982 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 EXPECT_EQ(1U, GetTransport1()->channels().size());
984 EXPECT_EQ(1U, GetTransport2()->channels().size());
985 EXPECT_FALSE(SendRtcp1());
986 EXPECT_FALSE(SendRtcp2());
987 EXPECT_TRUE(CheckNoRtcp1());
988 EXPECT_TRUE(CheckNoRtcp2());
989 }
990
991 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
992 void SendNoRtcpToRtcp() {
993 CreateChannels(0, RTCP);
994 EXPECT_TRUE(SendInitiate());
995 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700996 ASSERT_TRUE(GetTransport1());
997 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 EXPECT_EQ(1U, GetTransport1()->channels().size());
999 EXPECT_EQ(2U, GetTransport2()->channels().size());
1000 EXPECT_FALSE(SendRtcp1());
1001 EXPECT_FALSE(SendRtcp2());
1002 EXPECT_TRUE(CheckNoRtcp1());
1003 EXPECT_TRUE(CheckNoRtcp2());
1004 }
1005
1006 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1007 void SendRtcpToNoRtcp() {
1008 CreateChannels(RTCP, 0);
1009 EXPECT_TRUE(SendInitiate());
1010 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001011 ASSERT_TRUE(GetTransport1());
1012 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 EXPECT_EQ(2U, GetTransport1()->channels().size());
1014 EXPECT_EQ(1U, GetTransport2()->channels().size());
1015 EXPECT_FALSE(SendRtcp1());
1016 EXPECT_FALSE(SendRtcp2());
1017 EXPECT_TRUE(CheckNoRtcp1());
1018 EXPECT_TRUE(CheckNoRtcp2());
1019 }
1020
1021 // Check that RTCP is transmitted if both sides support RTCP.
1022 void SendRtcpToRtcp() {
1023 CreateChannels(RTCP, RTCP);
1024 EXPECT_TRUE(SendInitiate());
1025 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001026 ASSERT_TRUE(GetTransport1());
1027 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028 EXPECT_EQ(2U, GetTransport1()->channels().size());
1029 EXPECT_EQ(2U, GetTransport2()->channels().size());
1030 EXPECT_TRUE(SendRtcp1());
1031 EXPECT_TRUE(SendRtcp2());
1032 EXPECT_TRUE(CheckRtcp1());
1033 EXPECT_TRUE(CheckRtcp2());
1034 EXPECT_TRUE(CheckNoRtcp1());
1035 EXPECT_TRUE(CheckNoRtcp2());
1036 }
1037
1038 // Check that RTCP is transmitted if only the initiator supports mux.
1039 void SendRtcpMuxToRtcp() {
1040 CreateChannels(RTCP | RTCP_MUX, RTCP);
1041 EXPECT_TRUE(SendInitiate());
1042 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001043 ASSERT_TRUE(GetTransport1());
1044 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001045 EXPECT_EQ(2U, GetTransport1()->channels().size());
1046 EXPECT_EQ(2U, GetTransport2()->channels().size());
1047 EXPECT_TRUE(SendRtcp1());
1048 EXPECT_TRUE(SendRtcp2());
1049 EXPECT_TRUE(CheckRtcp1());
1050 EXPECT_TRUE(CheckRtcp2());
1051 EXPECT_TRUE(CheckNoRtcp1());
1052 EXPECT_TRUE(CheckNoRtcp2());
1053 }
1054
1055 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1056 void SendRtcpMuxToRtcpMux() {
1057 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1058 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001059 ASSERT_TRUE(GetTransport1());
1060 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 EXPECT_EQ(2U, GetTransport1()->channels().size());
1062 EXPECT_EQ(1U, GetTransport2()->channels().size());
1063 EXPECT_TRUE(SendAccept());
1064 EXPECT_EQ(1U, GetTransport1()->channels().size());
1065 EXPECT_TRUE(SendRtp1());
1066 EXPECT_TRUE(SendRtp2());
1067 EXPECT_TRUE(SendRtcp1());
1068 EXPECT_TRUE(SendRtcp2());
1069 EXPECT_TRUE(CheckRtp1());
1070 EXPECT_TRUE(CheckRtp2());
1071 EXPECT_TRUE(CheckNoRtp1());
1072 EXPECT_TRUE(CheckNoRtp2());
1073 EXPECT_TRUE(CheckRtcp1());
1074 EXPECT_TRUE(CheckRtcp2());
1075 EXPECT_TRUE(CheckNoRtcp1());
1076 EXPECT_TRUE(CheckNoRtcp2());
1077 }
1078
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001079 // Check that RTP and RTCP are transmitted ok when both sides
1080 // support mux and one the offerer requires mux.
1081 void SendRequireRtcpMuxToRtcpMux() {
1082 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1083 channel1_->ActivateRtcpMux();
1084 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001085 ASSERT_TRUE(GetTransport1());
1086 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001087 EXPECT_EQ(1U, GetTransport1()->channels().size());
1088 EXPECT_EQ(1U, GetTransport2()->channels().size());
1089 EXPECT_TRUE(SendAccept());
1090 EXPECT_TRUE(SendRtp1());
1091 EXPECT_TRUE(SendRtp2());
1092 EXPECT_TRUE(SendRtcp1());
1093 EXPECT_TRUE(SendRtcp2());
1094 EXPECT_TRUE(CheckRtp1());
1095 EXPECT_TRUE(CheckRtp2());
1096 EXPECT_TRUE(CheckNoRtp1());
1097 EXPECT_TRUE(CheckNoRtp2());
1098 EXPECT_TRUE(CheckRtcp1());
1099 EXPECT_TRUE(CheckRtcp2());
1100 EXPECT_TRUE(CheckNoRtcp1());
1101 EXPECT_TRUE(CheckNoRtcp2());
1102 }
1103
1104 // Check that RTP and RTCP are transmitted ok when both sides
1105 // support mux and one the answerer requires rtcp mux.
1106 void SendRtcpMuxToRequireRtcpMux() {
1107 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1108 channel2_->ActivateRtcpMux();
1109 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001110 ASSERT_TRUE(GetTransport1());
1111 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001112 EXPECT_EQ(2U, GetTransport1()->channels().size());
1113 EXPECT_EQ(1U, GetTransport2()->channels().size());
1114 EXPECT_TRUE(SendAccept());
1115 EXPECT_EQ(1U, GetTransport1()->channels().size());
1116 EXPECT_TRUE(SendRtp1());
1117 EXPECT_TRUE(SendRtp2());
1118 EXPECT_TRUE(SendRtcp1());
1119 EXPECT_TRUE(SendRtcp2());
1120 EXPECT_TRUE(CheckRtp1());
1121 EXPECT_TRUE(CheckRtp2());
1122 EXPECT_TRUE(CheckNoRtp1());
1123 EXPECT_TRUE(CheckNoRtp2());
1124 EXPECT_TRUE(CheckRtcp1());
1125 EXPECT_TRUE(CheckRtcp2());
1126 EXPECT_TRUE(CheckNoRtcp1());
1127 EXPECT_TRUE(CheckNoRtcp2());
1128 }
1129
1130 // Check that RTP and RTCP are transmitted ok when both sides
1131 // require mux.
1132 void SendRequireRtcpMuxToRequireRtcpMux() {
1133 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1134 channel1_->ActivateRtcpMux();
1135 channel2_->ActivateRtcpMux();
1136 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001137 ASSERT_TRUE(GetTransport1());
1138 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001139 EXPECT_EQ(1U, GetTransport1()->channels().size());
1140 EXPECT_EQ(1U, GetTransport2()->channels().size());
1141 EXPECT_TRUE(SendAccept());
1142 EXPECT_EQ(1U, GetTransport1()->channels().size());
1143 EXPECT_TRUE(SendRtp1());
1144 EXPECT_TRUE(SendRtp2());
1145 EXPECT_TRUE(SendRtcp1());
1146 EXPECT_TRUE(SendRtcp2());
1147 EXPECT_TRUE(CheckRtp1());
1148 EXPECT_TRUE(CheckRtp2());
1149 EXPECT_TRUE(CheckNoRtp1());
1150 EXPECT_TRUE(CheckNoRtp2());
1151 EXPECT_TRUE(CheckRtcp1());
1152 EXPECT_TRUE(CheckRtcp2());
1153 EXPECT_TRUE(CheckNoRtcp1());
1154 EXPECT_TRUE(CheckNoRtcp2());
1155 }
1156
1157 // Check that SendAccept fails if the answerer doesn't support mux
1158 // and the offerer requires it.
1159 void SendRequireRtcpMuxToNoRtcpMux() {
1160 CreateChannels(RTCP | RTCP_MUX, RTCP);
1161 channel1_->ActivateRtcpMux();
1162 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001163 ASSERT_TRUE(GetTransport1());
1164 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001165 EXPECT_EQ(1U, GetTransport1()->channels().size());
1166 EXPECT_EQ(2U, GetTransport2()->channels().size());
1167 EXPECT_FALSE(SendAccept());
1168 }
1169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 // Check that RTCP data sent by the initiator before the accept is not muxed.
1171 void SendEarlyRtcpMuxToRtcp() {
1172 CreateChannels(RTCP | RTCP_MUX, RTCP);
1173 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001174 ASSERT_TRUE(GetTransport1());
1175 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 EXPECT_EQ(2U, GetTransport1()->channels().size());
1177 EXPECT_EQ(2U, GetTransport2()->channels().size());
1178
1179 // RTCP can be sent before the call is accepted, if the transport is ready.
1180 // It should not be muxed though, as the remote side doesn't support mux.
1181 EXPECT_TRUE(SendRtcp1());
1182 EXPECT_TRUE(CheckNoRtp2());
1183 EXPECT_TRUE(CheckRtcp2());
1184
1185 // Send RTCP packet from callee and verify that it is received.
1186 EXPECT_TRUE(SendRtcp2());
1187 EXPECT_TRUE(CheckNoRtp1());
1188 EXPECT_TRUE(CheckRtcp1());
1189
1190 // Complete call setup and ensure everything is still OK.
1191 EXPECT_TRUE(SendAccept());
1192 EXPECT_EQ(2U, GetTransport1()->channels().size());
1193 EXPECT_TRUE(SendRtcp1());
1194 EXPECT_TRUE(CheckRtcp2());
1195 EXPECT_TRUE(SendRtcp2());
1196 EXPECT_TRUE(CheckRtcp1());
1197 }
1198
1199
1200 // Check that RTCP data is not muxed until both sides have enabled muxing,
1201 // but that we properly demux before we get the accept message, since there
1202 // is a race between RTP data and the jingle accept.
1203 void SendEarlyRtcpMuxToRtcpMux() {
1204 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1205 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001206 ASSERT_TRUE(GetTransport1());
1207 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208 EXPECT_EQ(2U, GetTransport1()->channels().size());
1209 EXPECT_EQ(1U, GetTransport2()->channels().size());
1210
1211 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1212 // we haven't yet received the accept that says we should mux.
1213 EXPECT_FALSE(SendRtcp1());
1214
1215 // Send muxed RTCP packet from callee and verify that it is received.
1216 EXPECT_TRUE(SendRtcp2());
1217 EXPECT_TRUE(CheckNoRtp1());
1218 EXPECT_TRUE(CheckRtcp1());
1219
1220 // Complete call setup and ensure everything is still OK.
1221 EXPECT_TRUE(SendAccept());
1222 EXPECT_EQ(1U, GetTransport1()->channels().size());
1223 EXPECT_TRUE(SendRtcp1());
1224 EXPECT_TRUE(CheckRtcp2());
1225 EXPECT_TRUE(SendRtcp2());
1226 EXPECT_TRUE(CheckRtcp1());
1227 }
1228
1229 // Test that we properly send SRTP with RTCP in both directions.
1230 // You can pass in DTLS and/or RTCP_MUX as flags.
1231 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1232 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1233 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1234
1235 int flags1 = RTCP | SECURE | flags1_in;
1236 int flags2 = RTCP | SECURE | flags2_in;
1237 bool dtls1 = !!(flags1_in & DTLS);
1238 bool dtls2 = !!(flags2_in & DTLS);
1239 CreateChannels(flags1, flags2);
1240 EXPECT_FALSE(channel1_->secure());
1241 EXPECT_FALSE(channel2_->secure());
1242 EXPECT_TRUE(SendInitiate());
1243 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1244 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1245 EXPECT_TRUE(SendAccept());
1246 EXPECT_TRUE(channel1_->secure());
1247 EXPECT_TRUE(channel2_->secure());
1248 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1249 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1250 EXPECT_TRUE(SendRtp1());
1251 EXPECT_TRUE(SendRtp2());
1252 EXPECT_TRUE(SendRtcp1());
1253 EXPECT_TRUE(SendRtcp2());
1254 EXPECT_TRUE(CheckRtp1());
1255 EXPECT_TRUE(CheckRtp2());
1256 EXPECT_TRUE(CheckNoRtp1());
1257 EXPECT_TRUE(CheckNoRtp2());
1258 EXPECT_TRUE(CheckRtcp1());
1259 EXPECT_TRUE(CheckRtcp2());
1260 EXPECT_TRUE(CheckNoRtcp1());
1261 EXPECT_TRUE(CheckNoRtcp2());
1262 }
1263
1264 // Test that we properly handling SRTP negotiating down to RTP.
1265 void SendSrtpToRtp() {
1266 CreateChannels(RTCP | SECURE, RTCP);
1267 EXPECT_FALSE(channel1_->secure());
1268 EXPECT_FALSE(channel2_->secure());
1269 EXPECT_TRUE(SendInitiate());
1270 EXPECT_TRUE(SendAccept());
1271 EXPECT_FALSE(channel1_->secure());
1272 EXPECT_FALSE(channel2_->secure());
1273 EXPECT_TRUE(SendRtp1());
1274 EXPECT_TRUE(SendRtp2());
1275 EXPECT_TRUE(SendRtcp1());
1276 EXPECT_TRUE(SendRtcp2());
1277 EXPECT_TRUE(CheckRtp1());
1278 EXPECT_TRUE(CheckRtp2());
1279 EXPECT_TRUE(CheckNoRtp1());
1280 EXPECT_TRUE(CheckNoRtp2());
1281 EXPECT_TRUE(CheckRtcp1());
1282 EXPECT_TRUE(CheckRtcp2());
1283 EXPECT_TRUE(CheckNoRtcp1());
1284 EXPECT_TRUE(CheckNoRtcp2());
1285 }
1286
1287 // Test that we can send and receive early media when a provisional answer is
1288 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1289 void SendEarlyMediaUsingRtcpMuxSrtp() {
1290 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1291
1292 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1293 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1294 EXPECT_TRUE(SendOffer());
1295 EXPECT_TRUE(SendProvisionalAnswer());
1296 EXPECT_TRUE(channel1_->secure());
1297 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001298 ASSERT_TRUE(GetTransport1());
1299 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 EXPECT_EQ(2U, GetTransport1()->channels().size());
1301 EXPECT_EQ(2U, GetTransport2()->channels().size());
1302 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1303 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1304 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1305 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1306
1307 // Send packets from callee and verify that it is received.
1308 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1309 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1310 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1311 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1312
1313 // Complete call setup and ensure everything is still OK.
1314 EXPECT_TRUE(SendFinalAnswer());
1315 EXPECT_EQ(1U, GetTransport1()->channels().size());
1316 EXPECT_EQ(1U, GetTransport2()->channels().size());
1317 EXPECT_TRUE(channel1_->secure());
1318 EXPECT_TRUE(channel2_->secure());
1319 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1320 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1321 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1322 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1323 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1324 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1325 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1326 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1327 }
1328
1329 // Test that we properly send RTP without SRTP from a thread.
1330 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001331 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1332 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 EXPECT_TRUE(SendInitiate());
1334 EXPECT_TRUE(SendAccept());
1335 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1336 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001337 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1338 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1340 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1341 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1342 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1343 EXPECT_TRUE(CheckNoRtp1());
1344 EXPECT_TRUE(CheckNoRtp2());
1345 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1346 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1347 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1348 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1349 EXPECT_TRUE(CheckNoRtcp1());
1350 EXPECT_TRUE(CheckNoRtcp2());
1351 }
1352
1353 // Test that we properly send SRTP with RTCP from a thread.
1354 void SendSrtpToSrtpOnThread() {
1355 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1356 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1357 EXPECT_TRUE(SendInitiate());
1358 EXPECT_TRUE(SendAccept());
1359 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1360 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1361 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1362 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1363 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1364 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1365 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1366 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1367 EXPECT_TRUE(CheckNoRtp1());
1368 EXPECT_TRUE(CheckNoRtp2());
1369 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1370 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1371 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1372 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1373 EXPECT_TRUE(CheckNoRtcp1());
1374 EXPECT_TRUE(CheckNoRtcp2());
1375 }
1376
1377 // Test that the mediachannel retains its sending state after the transport
1378 // becomes non-writable.
1379 void SendWithWritabilityLoss() {
1380 CreateChannels(0, 0);
1381 EXPECT_TRUE(SendInitiate());
1382 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001383 ASSERT_TRUE(GetTransport1());
1384 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 EXPECT_EQ(1U, GetTransport1()->channels().size());
1386 EXPECT_EQ(1U, GetTransport2()->channels().size());
1387 EXPECT_TRUE(SendRtp1());
1388 EXPECT_TRUE(SendRtp2());
1389 EXPECT_TRUE(CheckRtp1());
1390 EXPECT_TRUE(CheckRtp2());
1391 EXPECT_TRUE(CheckNoRtp1());
1392 EXPECT_TRUE(CheckNoRtp2());
1393
wu@webrtc.org97077a32013-10-25 21:18:33 +00001394 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 EXPECT_FALSE(SendRtp1());
1397 EXPECT_TRUE(SendRtp2());
1398 EXPECT_TRUE(CheckRtp1());
1399 EXPECT_TRUE(CheckNoRtp2());
1400
1401 // Regain writability
1402 GetTransport1()->SetWritable(true);
1403 EXPECT_TRUE(media_channel1_->sending());
1404 EXPECT_TRUE(SendRtp1());
1405 EXPECT_TRUE(SendRtp2());
1406 EXPECT_TRUE(CheckRtp1());
1407 EXPECT_TRUE(CheckRtp2());
1408 EXPECT_TRUE(CheckNoRtp1());
1409 EXPECT_TRUE(CheckNoRtp2());
1410
1411 // Lose writability completely
1412 GetTransport1()->SetDestination(NULL);
1413 EXPECT_TRUE(media_channel1_->sending());
1414
wu@webrtc.org97077a32013-10-25 21:18:33 +00001415 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 EXPECT_FALSE(SendRtp1());
1417 EXPECT_TRUE(SendRtp2());
1418 EXPECT_TRUE(CheckRtp1());
1419 EXPECT_TRUE(CheckNoRtp2());
1420
1421 // Gain writability back
1422 GetTransport1()->SetDestination(GetTransport2());
1423 EXPECT_TRUE(media_channel1_->sending());
1424 EXPECT_TRUE(SendRtp1());
1425 EXPECT_TRUE(SendRtp2());
1426 EXPECT_TRUE(CheckRtp1());
1427 EXPECT_TRUE(CheckRtp2());
1428 EXPECT_TRUE(CheckNoRtp1());
1429 EXPECT_TRUE(CheckNoRtp2());
1430 }
1431
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001432 void SendBundleToBundle(
1433 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1434 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001436 // Only pl_type1 was added to the bundle filter for both |channel1_|
1437 // and |channel2_|.
1438 int pl_type1 = pl_types[0];
1439 int pl_type2 = pl_types[1];
1440 int flags = SSRC_MUX | RTCP;
1441 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001442 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001443 if (rtcp_mux) {
1444 flags |= RTCP_MUX;
1445 expected_channels = 1U;
1446 }
1447 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001449 ASSERT_TRUE(GetTransport1());
1450 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001452 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001454 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1455 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1456 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1457 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1458 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1459 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001460
1461 // Both channels can receive pl_type1 only.
1462 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1463 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1464 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1465 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1466 EXPECT_TRUE(CheckNoRtp1());
1467 EXPECT_TRUE(CheckNoRtp2());
1468
1469 // RTCP test
1470 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1471 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1472 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1473 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1476 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1478 EXPECT_TRUE(CheckNoRtcp1());
1479 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1480 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001481
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001482 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1483 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
pbos482b12e2015-11-16 10:19:58 -08001484 // Bundle filter shouldn't filter out any RTCP.
1485 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1486 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001487 }
1488
1489 // Test that the media monitor can be run and gives timely callbacks.
1490 void TestMediaMonitor() {
1491 static const int kTimeout = 500;
1492 CreateChannels(0, 0);
1493 EXPECT_TRUE(SendInitiate());
1494 EXPECT_TRUE(SendAccept());
1495 channel1_->StartMediaMonitor(100);
1496 channel2_->StartMediaMonitor(100);
1497 // Ensure we get callbacks and stop.
1498 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1499 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1500 channel1_->StopMediaMonitor();
1501 channel2_->StopMediaMonitor();
1502 // Ensure a restart of a stopped monitor works.
1503 channel1_->StartMediaMonitor(100);
1504 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1505 channel1_->StopMediaMonitor();
1506 // Ensure stopping a stopped monitor is OK.
1507 channel1_->StopMediaMonitor();
1508 }
1509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 void TestSetContentFailure() {
1511 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512
Peter Thatchera6d24442015-07-09 21:26:36 -07001513 auto sdesc = cricket::SessionDescription();
1514 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1515 new cricket::AudioContentDescription());
1516 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1517 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518
Peter Thatchera6d24442015-07-09 21:26:36 -07001519 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001520 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001521 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1522 &sdesc, cricket::CA_OFFER, &err));
1523 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1524 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001525
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001527 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1528 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001530 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1531 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532 }
1533
1534 void TestSendTwoOffers() {
1535 CreateChannels(0, 0);
1536
Peter Thatchera6d24442015-07-09 21:26:36 -07001537 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001538 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001539 CreateSessionDescriptionWithStream(1));
1540 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1541 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1543
kwiberg31022942016-03-11 14:18:21 -08001544 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001545 CreateSessionDescriptionWithStream(2));
1546 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1547 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1549 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1550 }
1551
1552 void TestReceiveTwoOffers() {
1553 CreateChannels(0, 0);
1554
Peter Thatchera6d24442015-07-09 21:26:36 -07001555 std::string err;
kwiberg31022942016-03-11 14:18:21 -08001556 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001557 CreateSessionDescriptionWithStream(1));
1558 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1559 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1561
kwiberg31022942016-03-11 14:18:21 -08001562 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001563 CreateSessionDescriptionWithStream(2));
1564 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1565 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1567 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1568 }
1569
1570 void TestSendPrAnswer() {
1571 CreateChannels(0, 0);
1572
Peter Thatchera6d24442015-07-09 21:26:36 -07001573 std::string err;
1574 // Receive offer
kwiberg31022942016-03-11 14:18:21 -08001575 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001576 CreateSessionDescriptionWithStream(1));
1577 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1578 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1580
Peter Thatchera6d24442015-07-09 21:26:36 -07001581 // Send PR answer
kwiberg31022942016-03-11 14:18:21 -08001582 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001583 CreateSessionDescriptionWithStream(2));
1584 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1585 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1587 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1588
Peter Thatchera6d24442015-07-09 21:26:36 -07001589 // Send answer
kwiberg31022942016-03-11 14:18:21 -08001590 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001591 CreateSessionDescriptionWithStream(3));
1592 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1593 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1595 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1596 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1597 }
1598
1599 void TestReceivePrAnswer() {
1600 CreateChannels(0, 0);
1601
Peter Thatchera6d24442015-07-09 21:26:36 -07001602 std::string err;
1603 // Send offer
kwiberg31022942016-03-11 14:18:21 -08001604 std::unique_ptr<cricket::SessionDescription> sdesc1(
Peter Thatchera6d24442015-07-09 21:26:36 -07001605 CreateSessionDescriptionWithStream(1));
1606 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1607 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1609
Peter Thatchera6d24442015-07-09 21:26:36 -07001610 // Receive PR answer
kwiberg31022942016-03-11 14:18:21 -08001611 std::unique_ptr<cricket::SessionDescription> sdesc2(
Peter Thatchera6d24442015-07-09 21:26:36 -07001612 CreateSessionDescriptionWithStream(2));
1613 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1614 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1616 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1617
Peter Thatchera6d24442015-07-09 21:26:36 -07001618 // Receive answer
kwiberg31022942016-03-11 14:18:21 -08001619 std::unique_ptr<cricket::SessionDescription> sdesc3(
Peter Thatchera6d24442015-07-09 21:26:36 -07001620 CreateSessionDescriptionWithStream(3));
1621 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1622 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1624 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1625 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1626 }
1627
1628 void TestFlushRtcp() {
1629 bool send_rtcp1;
1630
1631 CreateChannels(RTCP, RTCP);
1632 EXPECT_TRUE(SendInitiate());
1633 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001634 ASSERT_TRUE(GetTransport1());
1635 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 EXPECT_EQ(2U, GetTransport1()->channels().size());
1637 EXPECT_EQ(2U, GetTransport2()->channels().size());
1638
1639 // Send RTCP1 from a different thread.
1640 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1641 EXPECT_TRUE(send_rtcp1);
1642 // The sending message is only posted. channel2_ should be empty.
1643 EXPECT_TRUE(CheckNoRtcp2());
1644
1645 // When channel1_ is deleted, the RTCP packet should be sent out to
1646 // channel2_.
1647 channel1_.reset();
1648 EXPECT_TRUE(CheckRtcp2());
1649 }
1650
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001651 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001652 struct SrtpErrorHandler : public sigslot::has_slots<> {
1653 SrtpErrorHandler() :
1654 mode_(cricket::SrtpFilter::UNPROTECT),
1655 error_(cricket::SrtpFilter::ERROR_NONE) {}
1656 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1657 cricket::SrtpFilter::Error error) {
1658 mode_ = mode;
1659 error_ = error;
1660 }
1661 cricket::SrtpFilter::Mode mode_;
1662 cricket::SrtpFilter::Error error_;
1663 } error_handler;
1664
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001665 // For Audio, only pl_type 0 is added to the bundle filter.
1666 // For Video, only pl_type 97 is added to the bundle filter.
1667 // So we need to pass in pl_type so that the packet can pass through
1668 // the bundle filter before it can be processed by the srtp filter.
1669 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001670 unsigned const char kBadPacket[] = {0x84,
1671 static_cast<unsigned char>(pl_type),
1672 0x00,
1673 0x01,
1674 0x00,
1675 0x00,
1676 0x00,
1677 0x00,
1678 0x00,
1679 0x00,
1680 0x00,
1681 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001682 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1683 EXPECT_FALSE(channel1_->secure());
1684 EXPECT_FALSE(channel2_->secure());
1685 EXPECT_TRUE(SendInitiate());
1686 EXPECT_TRUE(SendAccept());
1687 EXPECT_TRUE(channel1_->secure());
1688 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001689 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001690 channel2_->srtp_filter()->SignalSrtpError.connect(
1691 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692
1693 // Testing failures in sending packets.
stefanc1aeaf02015-10-15 07:26:07 -07001694 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1695 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001696 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001697 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1698 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1699 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001700 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1701 // The next 250 ms failures will not trigger an error.
stefanc1aeaf02015-10-15 07:26:07 -07001702 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1703 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001705 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001706 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001707 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1708 // Wait for a little more - the error will be triggered again.
1709 rtc::Thread::Current()->ProcessMessages(200);
stefanc1aeaf02015-10-15 07:26:07 -07001710 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1711 rtc::PacketOptions()));
solenberg5b14b422015-10-01 04:10:31 -07001712 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1713 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714
1715 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001716 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001717 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001718
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 cricket::TransportChannel* transport_channel =
1720 channel2_->transport_channel();
1721 transport_channel->SignalReadPacket(
1722 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001723 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001724 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1725 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 }
1727
1728 void TestOnReadyToSend() {
1729 CreateChannels(RTCP, RTCP);
1730 TransportChannel* rtp = channel1_->transport_channel();
1731 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1732 EXPECT_FALSE(media_channel1_->ready_to_send());
1733 rtp->SignalReadyToSend(rtp);
1734 EXPECT_FALSE(media_channel1_->ready_to_send());
1735 rtcp->SignalReadyToSend(rtcp);
1736 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1737 // channel are ready to send.
1738 EXPECT_TRUE(media_channel1_->ready_to_send());
1739
1740 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001741 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001743 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 EXPECT_TRUE(media_channel1_->ready_to_send());
1745
1746 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001747 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001749 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 EXPECT_TRUE(media_channel1_->ready_to_send());
1751 }
1752
1753 void TestOnReadyToSendWithRtcpMux() {
1754 CreateChannels(RTCP, RTCP);
1755 typename T::Content content;
1756 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1757 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1758 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001759 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1760 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1762 TransportChannel* rtp = channel1_->transport_channel();
1763 EXPECT_FALSE(media_channel1_->ready_to_send());
1764 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1765 // should trigger the MediaChannel's OnReadyToSend.
1766 rtp->SignalReadyToSend(rtp);
1767 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001768 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 EXPECT_FALSE(media_channel1_->ready_to_send());
1770 }
1771
1772 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001773 // TODO(pbos): Remove playout from all media channels and let renderers mute
1774 // themselves.
1775 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001776 cricket::FakeTransportController transport_controller1_;
1777 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 cricket::FakeMediaEngine media_engine_;
1779 // The media channels are owned by the voice channel objects below.
1780 typename T::MediaChannel* media_channel1_;
1781 typename T::MediaChannel* media_channel2_;
kwiberg31022942016-03-11 14:18:21 -08001782 std::unique_ptr<typename T::Channel> channel1_;
1783 std::unique_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 typename T::Content local_media_content1_;
1785 typename T::Content local_media_content2_;
1786 typename T::Content remote_media_content1_;
1787 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 // The RTP and RTCP packets to send in the tests.
1789 std::string rtp_packet_;
1790 std::string rtcp_packet_;
1791 int media_info_callbacks1_;
1792 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793};
1794
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795template<>
1796void ChannelTest<VoiceTraits>::CreateContent(
1797 int flags,
1798 const cricket::AudioCodec& audio_codec,
1799 const cricket::VideoCodec& video_codec,
1800 cricket::AudioContentDescription* audio) {
1801 audio->AddCodec(audio_codec);
1802 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1803 if (flags & SECURE) {
1804 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001805 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1806 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 }
1808}
1809
1810template<>
1811void ChannelTest<VoiceTraits>::CopyContent(
1812 const cricket::AudioContentDescription& source,
1813 cricket::AudioContentDescription* audio) {
1814 *audio = source;
1815}
1816
1817template<>
1818bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1819 const cricket::AudioCodec& c2) {
1820 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1821 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1822}
1823
Peter Boström0c4e06b2015-10-07 12:23:21 +02001824template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001826 uint32_t ssrc,
1827 int flags,
1828 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 audio->AddLegacyStream(ssrc);
1830}
1831
1832class VoiceChannelTest
1833 : public ChannelTest<VoiceTraits> {
1834 public:
solenberg1dd98f32015-09-10 01:57:14 -07001835 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001836 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001837 : Base(true,
1838 kPcmuFrame,
1839 sizeof(kPcmuFrame),
1840 kRtcpReport,
1841 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842};
1843
1844// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001845template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001847 rtc::Thread* thread,
1848 cricket::MediaEngineInterface* engine,
1849 cricket::FakeVideoMediaChannel* ch,
1850 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 bool rtcp) {
1852 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001853 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 if (!channel->Init()) {
1855 delete channel;
1856 channel = NULL;
1857 }
1858 return channel;
1859}
1860
1861// override to add 0 parameter
1862template<>
1863bool ChannelTest<VideoTraits>::AddStream1(int id) {
1864 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1865}
1866
1867template<>
1868void ChannelTest<VideoTraits>::CreateContent(
1869 int flags,
1870 const cricket::AudioCodec& audio_codec,
1871 const cricket::VideoCodec& video_codec,
1872 cricket::VideoContentDescription* video) {
1873 video->AddCodec(video_codec);
1874 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1875 if (flags & SECURE) {
1876 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001877 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1878 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 }
1880}
1881
1882template<>
1883void ChannelTest<VideoTraits>::CopyContent(
1884 const cricket::VideoContentDescription& source,
1885 cricket::VideoContentDescription* video) {
1886 *video = source;
1887}
1888
1889template<>
1890bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1891 const cricket::VideoCodec& c2) {
1892 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1893 c1.framerate == c2.framerate;
1894}
1895
Peter Boström0c4e06b2015-10-07 12:23:21 +02001896template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001898 uint32_t ssrc,
1899 int flags,
1900 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 video->AddLegacyStream(ssrc);
1902}
1903
1904class VideoChannelTest
1905 : public ChannelTest<VideoTraits> {
1906 public:
solenberg1dd98f32015-09-10 01:57:14 -07001907 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001908 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001909 : Base(false,
1910 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001911 sizeof(kH264Packet),
1912 kRtcpReport,
1913 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914};
1915
1916
1917// VoiceChannelTest
1918
1919TEST_F(VoiceChannelTest, TestInit) {
1920 Base::TestInit();
1921 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1922 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1923}
1924
1925TEST_F(VoiceChannelTest, TestSetContents) {
1926 Base::TestSetContents();
1927}
1928
1929TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1930 Base::TestSetContentsNullOffer();
1931}
1932
1933TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1934 Base::TestSetContentsRtcpMux();
1935}
1936
1937TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1938 Base::TestSetContentsRtcpMux();
1939}
1940
1941TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1942 Base::TestSetRemoteContentUpdate();
1943}
1944
1945TEST_F(VoiceChannelTest, TestStreams) {
1946 Base::TestStreams();
1947}
1948
1949TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1950 Base::TestUpdateStreamsInLocalContent();
1951}
1952
1953TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1954 Base::TestUpdateStreamsInRemoteContent();
1955}
1956
1957TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1958 Base::TestChangeStreamParamsInContent();
1959}
1960
1961TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1962 Base::TestPlayoutAndSendingStates();
1963}
1964
1965TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001966 CreateChannels(0, 0);
1967 // Test that we can Mute the default channel even though the sending SSRC
1968 // is unknown.
1969 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07001970 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001971 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1972 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001973 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1974
1975 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07001976 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001977
1978 SendInitiate();
1979 // After the local session description has been set, we can mute a stream
1980 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07001981 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001982 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
1983 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001984 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985}
1986
1987TEST_F(VoiceChannelTest, TestMediaContentDirection) {
1988 Base::TestMediaContentDirection();
1989}
1990
1991TEST_F(VoiceChannelTest, TestCallSetup) {
1992 Base::TestCallSetup();
1993}
1994
1995TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
1996 Base::TestCallTeardownRtcpMux();
1997}
1998
1999TEST_F(VoiceChannelTest, SendRtpToRtp) {
2000 Base::SendRtpToRtp();
2001}
2002
2003TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2004 Base::SendNoRtcpToNoRtcp();
2005}
2006
2007TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2008 Base::SendNoRtcpToRtcp();
2009}
2010
2011TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2012 Base::SendRtcpToNoRtcp();
2013}
2014
2015TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2016 Base::SendRtcpToRtcp();
2017}
2018
2019TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2020 Base::SendRtcpMuxToRtcp();
2021}
2022
2023TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2024 Base::SendRtcpMuxToRtcpMux();
2025}
2026
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002027TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2028 Base::SendRequireRtcpMuxToRtcpMux();
2029}
2030
2031TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2032 Base::SendRtcpMuxToRequireRtcpMux();
2033}
2034
2035TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2036 Base::SendRequireRtcpMuxToRequireRtcpMux();
2037}
2038
2039TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2040 Base::SendRequireRtcpMuxToNoRtcpMux();
2041}
2042
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2044 Base::SendEarlyRtcpMuxToRtcp();
2045}
2046
2047TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2048 Base::SendEarlyRtcpMuxToRtcpMux();
2049}
2050
2051TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2052 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2053}
2054
2055TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2056 Base::SendSrtpToSrtp();
2057}
2058
2059TEST_F(VoiceChannelTest, SendSrtcpMux) {
2060 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2061}
2062
2063TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2064 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2065 Base::SendSrtpToSrtp(DTLS, 0);
2066}
2067
2068TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2069 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2070 Base::SendSrtpToSrtp(DTLS, DTLS);
2071}
2072
2073TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2074 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2075 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2076}
2077
2078TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2079 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2080}
2081
2082TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2083 Base::SendRtpToRtpOnThread();
2084}
2085
2086TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2087 Base::SendSrtpToSrtpOnThread();
2088}
2089
2090TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2091 Base::SendWithWritabilityLoss();
2092}
2093
2094TEST_F(VoiceChannelTest, TestMediaMonitor) {
2095 Base::TestMediaMonitor();
2096}
2097
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098// Test that InsertDtmf properly forwards to the media channel.
2099TEST_F(VoiceChannelTest, TestInsertDtmf) {
2100 CreateChannels(0, 0);
2101 EXPECT_TRUE(SendInitiate());
2102 EXPECT_TRUE(SendAccept());
2103 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2104
solenberg1d63dd02015-12-02 12:35:09 -08002105 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2106 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2107 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002109 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002111 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002112 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002113 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002114 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002115 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116}
2117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118TEST_F(VoiceChannelTest, TestSetContentFailure) {
2119 Base::TestSetContentFailure();
2120}
2121
2122TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2123 Base::TestSendTwoOffers();
2124}
2125
2126TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2127 Base::TestReceiveTwoOffers();
2128}
2129
2130TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2131 Base::TestSendPrAnswer();
2132}
2133
2134TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2135 Base::TestReceivePrAnswer();
2136}
2137
2138TEST_F(VoiceChannelTest, TestFlushRtcp) {
2139 Base::TestFlushRtcp();
2140}
2141
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002143 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144}
2145
2146TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2147 Base::TestOnReadyToSend();
2148}
2149
2150TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2151 Base::TestOnReadyToSendWithRtcpMux();
2152}
2153
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154// Test that we can scale the output volume properly for 1:1 calls.
2155TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2156 CreateChannels(RTCP, RTCP);
2157 EXPECT_TRUE(SendInitiate());
2158 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002159 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160
solenberg4bac9c52015-10-09 02:32:53 -07002161 // Default is (1.0).
2162 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2163 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002165 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166
solenberg4bac9c52015-10-09 02:32:53 -07002167 // Set scale to (1.5).
2168 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2169 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2170 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171
solenberg4bac9c52015-10-09 02:32:53 -07002172 // Set scale to (0).
2173 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2174 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2175 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176}
2177
2178// Test that we can scale the output volume properly for multiway calls.
2179TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2180 CreateChannels(RTCP, RTCP);
2181 EXPECT_TRUE(SendInitiate());
2182 EXPECT_TRUE(SendAccept());
2183 EXPECT_TRUE(AddStream1(1));
2184 EXPECT_TRUE(AddStream1(2));
2185
solenberg4bac9c52015-10-09 02:32:53 -07002186 double volume;
2187 // Default is (1.0).
2188 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2189 EXPECT_DOUBLE_EQ(1.0, volume);
2190 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2191 EXPECT_DOUBLE_EQ(1.0, volume);
2192 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2193 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002195 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196
solenberg4bac9c52015-10-09 02:32:53 -07002197 // Set scale to (1.5) for ssrc = 1.
2198 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2199 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2200 EXPECT_DOUBLE_EQ(1.5, volume);
2201 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2202 EXPECT_DOUBLE_EQ(1.0, volume);
2203 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2204 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205
solenberg4bac9c52015-10-09 02:32:53 -07002206 // Set scale to (0) for all ssrcs.
2207 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2208 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2209 EXPECT_DOUBLE_EQ(0.0, volume);
2210 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2211 EXPECT_DOUBLE_EQ(0.0, volume);
2212 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2213 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214}
2215
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002216TEST_F(VoiceChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002217 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218}
2219
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002220TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002221 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002222}
2223
2224TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002225 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002226}
2227
2228TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002229 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230}
2231
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232// VideoChannelTest
2233TEST_F(VideoChannelTest, TestInit) {
2234 Base::TestInit();
2235}
2236
2237TEST_F(VideoChannelTest, TestSetContents) {
2238 Base::TestSetContents();
2239}
2240
2241TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2242 Base::TestSetContentsNullOffer();
2243}
2244
2245TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2246 Base::TestSetContentsRtcpMux();
2247}
2248
2249TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2250 Base::TestSetContentsRtcpMux();
2251}
2252
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2254 Base::TestSetRemoteContentUpdate();
2255}
2256
2257TEST_F(VideoChannelTest, TestStreams) {
2258 Base::TestStreams();
2259}
2260
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2262 Base::TestUpdateStreamsInLocalContent();
2263}
2264
2265TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2266 Base::TestUpdateStreamsInRemoteContent();
2267}
2268
2269TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2270 Base::TestChangeStreamParamsInContent();
2271}
2272
2273TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2274 Base::TestPlayoutAndSendingStates();
2275}
2276
2277TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002278 CreateChannels(0, 0);
2279 // Test that we can Mute the default channel even though the sending SSRC
2280 // is unknown.
2281 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002282 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002283 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2284 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002285 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2286 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002287 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002288 SendInitiate();
2289 // After the local session description has been set, we can mute a stream
2290 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002291 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002292 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2293 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002294 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295}
2296
2297TEST_F(VideoChannelTest, TestMediaContentDirection) {
2298 Base::TestMediaContentDirection();
2299}
2300
2301TEST_F(VideoChannelTest, TestCallSetup) {
2302 Base::TestCallSetup();
2303}
2304
2305TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2306 Base::TestCallTeardownRtcpMux();
2307}
2308
2309TEST_F(VideoChannelTest, SendRtpToRtp) {
2310 Base::SendRtpToRtp();
2311}
2312
2313TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2314 Base::SendNoRtcpToNoRtcp();
2315}
2316
2317TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2318 Base::SendNoRtcpToRtcp();
2319}
2320
2321TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2322 Base::SendRtcpToNoRtcp();
2323}
2324
2325TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2326 Base::SendRtcpToRtcp();
2327}
2328
2329TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2330 Base::SendRtcpMuxToRtcp();
2331}
2332
2333TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2334 Base::SendRtcpMuxToRtcpMux();
2335}
2336
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002337TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2338 Base::SendRequireRtcpMuxToRtcpMux();
2339}
2340
2341TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2342 Base::SendRtcpMuxToRequireRtcpMux();
2343}
2344
2345TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2346 Base::SendRequireRtcpMuxToRequireRtcpMux();
2347}
2348
2349TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2350 Base::SendRequireRtcpMuxToNoRtcpMux();
2351}
2352
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2354 Base::SendEarlyRtcpMuxToRtcp();
2355}
2356
2357TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2358 Base::SendEarlyRtcpMuxToRtcpMux();
2359}
2360
2361TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2362 Base::SendSrtpToSrtp();
2363}
2364
2365TEST_F(VideoChannelTest, SendSrtpToRtp) {
2366 Base::SendSrtpToSrtp();
2367}
2368
2369TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2370 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2371 Base::SendSrtpToSrtp(DTLS, 0);
2372}
2373
2374TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2375 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2376 Base::SendSrtpToSrtp(DTLS, DTLS);
2377}
2378
2379TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2380 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2381 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2382}
2383
2384TEST_F(VideoChannelTest, SendSrtcpMux) {
2385 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2386}
2387
2388TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2389 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2390}
2391
2392TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2393 Base::SendRtpToRtpOnThread();
2394}
2395
2396TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2397 Base::SendSrtpToSrtpOnThread();
2398}
2399
2400TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2401 Base::SendWithWritabilityLoss();
2402}
2403
2404TEST_F(VideoChannelTest, TestMediaMonitor) {
2405 Base::TestMediaMonitor();
2406}
2407
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408TEST_F(VideoChannelTest, TestSetContentFailure) {
2409 Base::TestSetContentFailure();
2410}
2411
2412TEST_F(VideoChannelTest, TestSendTwoOffers) {
2413 Base::TestSendTwoOffers();
2414}
2415
2416TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2417 Base::TestReceiveTwoOffers();
2418}
2419
2420TEST_F(VideoChannelTest, TestSendPrAnswer) {
2421 Base::TestSendPrAnswer();
2422}
2423
2424TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2425 Base::TestReceivePrAnswer();
2426}
2427
2428TEST_F(VideoChannelTest, TestFlushRtcp) {
2429 Base::TestFlushRtcp();
2430}
2431
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002432TEST_F(VideoChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002433 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434}
2435
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002436TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002437 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002438}
2439
2440TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002441 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002442}
2443
2444TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002445 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446}
2447
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002449 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450}
2451
2452TEST_F(VideoChannelTest, TestOnReadyToSend) {
2453 Base::TestOnReadyToSend();
2454}
2455
2456TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2457 Base::TestOnReadyToSendWithRtcpMux();
2458}
2459
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460// DataChannelTest
2461
2462class DataChannelTest
2463 : public ChannelTest<DataTraits> {
2464 public:
2465 typedef ChannelTest<DataTraits>
2466 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002467 DataChannelTest()
2468 : Base(true,
2469 kDataPacket,
2470 sizeof(kDataPacket),
2471 kRtcpReport,
2472 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473};
2474
2475// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002476template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002478 rtc::Thread* thread,
2479 cricket::MediaEngineInterface* engine,
2480 cricket::FakeDataMediaChannel* ch,
2481 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 bool rtcp) {
2483 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002484 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 if (!channel->Init()) {
2486 delete channel;
2487 channel = NULL;
2488 }
2489 return channel;
2490}
2491
2492template<>
2493void ChannelTest<DataTraits>::CreateContent(
2494 int flags,
2495 const cricket::AudioCodec& audio_codec,
2496 const cricket::VideoCodec& video_codec,
2497 cricket::DataContentDescription* data) {
2498 data->AddCodec(kGoogleDataCodec);
2499 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2500 if (flags & SECURE) {
2501 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002502 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2503 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 }
2505}
2506
2507template<>
2508void ChannelTest<DataTraits>::CopyContent(
2509 const cricket::DataContentDescription& source,
2510 cricket::DataContentDescription* data) {
2511 *data = source;
2512}
2513
2514template<>
2515bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2516 const cricket::DataCodec& c2) {
2517 return c1.name == c2.name;
2518}
2519
Peter Boström0c4e06b2015-10-07 12:23:21 +02002520template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002522 uint32_t ssrc,
2523 int flags,
2524 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 data->AddLegacyStream(ssrc);
2526}
2527
2528TEST_F(DataChannelTest, TestInit) {
2529 Base::TestInit();
2530 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2531}
2532
2533TEST_F(DataChannelTest, TestSetContents) {
2534 Base::TestSetContents();
2535}
2536
2537TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2538 Base::TestSetContentsNullOffer();
2539}
2540
2541TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2542 Base::TestSetContentsRtcpMux();
2543}
2544
2545TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2546 Base::TestSetRemoteContentUpdate();
2547}
2548
2549TEST_F(DataChannelTest, TestStreams) {
2550 Base::TestStreams();
2551}
2552
2553TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2554 Base::TestUpdateStreamsInLocalContent();
2555}
2556
2557TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2558 Base::TestUpdateStreamsInRemoteContent();
2559}
2560
2561TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2562 Base::TestChangeStreamParamsInContent();
2563}
2564
2565TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2566 Base::TestPlayoutAndSendingStates();
2567}
2568
2569TEST_F(DataChannelTest, TestMediaContentDirection) {
2570 Base::TestMediaContentDirection();
2571}
2572
2573TEST_F(DataChannelTest, TestCallSetup) {
2574 Base::TestCallSetup();
2575}
2576
2577TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2578 Base::TestCallTeardownRtcpMux();
2579}
2580
2581TEST_F(DataChannelTest, TestOnReadyToSend) {
2582 Base::TestOnReadyToSend();
2583}
2584
2585TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2586 Base::TestOnReadyToSendWithRtcpMux();
2587}
2588
2589TEST_F(DataChannelTest, SendRtpToRtp) {
2590 Base::SendRtpToRtp();
2591}
2592
2593TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2594 Base::SendNoRtcpToNoRtcp();
2595}
2596
2597TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2598 Base::SendNoRtcpToRtcp();
2599}
2600
2601TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2602 Base::SendRtcpToNoRtcp();
2603}
2604
2605TEST_F(DataChannelTest, SendRtcpToRtcp) {
2606 Base::SendRtcpToRtcp();
2607}
2608
2609TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2610 Base::SendRtcpMuxToRtcp();
2611}
2612
2613TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2614 Base::SendRtcpMuxToRtcpMux();
2615}
2616
2617TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2618 Base::SendEarlyRtcpMuxToRtcp();
2619}
2620
2621TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2622 Base::SendEarlyRtcpMuxToRtcpMux();
2623}
2624
2625TEST_F(DataChannelTest, SendSrtpToSrtp) {
2626 Base::SendSrtpToSrtp();
2627}
2628
2629TEST_F(DataChannelTest, SendSrtpToRtp) {
2630 Base::SendSrtpToSrtp();
2631}
2632
2633TEST_F(DataChannelTest, SendSrtcpMux) {
2634 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2635}
2636
2637TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2638 Base::SendRtpToRtpOnThread();
2639}
2640
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2642 Base::SendSrtpToSrtpOnThread();
2643}
2644
2645TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2646 Base::SendWithWritabilityLoss();
2647}
2648
2649TEST_F(DataChannelTest, TestMediaMonitor) {
2650 Base::TestMediaMonitor();
2651}
2652
2653TEST_F(DataChannelTest, TestSendData) {
2654 CreateChannels(0, 0);
2655 EXPECT_TRUE(SendInitiate());
2656 EXPECT_TRUE(SendAccept());
2657
2658 cricket::SendDataParams params;
2659 params.ssrc = 42;
2660 unsigned char data[] = {
2661 'f', 'o', 'o'
2662 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002663 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002664 cricket::SendDataResult result;
2665 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2666 EXPECT_EQ(params.ssrc,
2667 media_channel1_->last_sent_data_params().ssrc);
2668 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2669}
2670
2671// TODO(pthatcher): TestSetReceiver?