blob: 08d83b5f6b992c578e385e84c56ecbd00deb0c65 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
2 * libjingle
3 * Copyright 2009 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028#include "talk/media/base/fakemediaengine.h"
29#include "talk/media/base/fakertp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000030#include "talk/media/base/fakescreencapturerfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/media/base/fakevideocapturer.h"
32#include "talk/media/base/mediachannel.h"
33#include "talk/media/base/rtpdump.h"
34#include "talk/media/base/screencastid.h"
35#include "talk/media/base/testutils.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/session/media/channel.h"
tfarina5237aaf2015-11-10 23:44:30 -080037#include "webrtc/p2p/base/faketransportcontroller.h"
38#include "webrtc/base/arraysize.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000039#include "webrtc/base/fileutils.h"
40#include "webrtc/base/gunit.h"
41#include "webrtc/base/helpers.h"
42#include "webrtc/base/logging.h"
43#include "webrtc/base/pathutils.h"
44#include "webrtc/base/signalthread.h"
45#include "webrtc/base/ssladapter.h"
46#include "webrtc/base/sslidentity.h"
47#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048
49#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000050 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051 LOG(LS_INFO) << "Feature disabled... skipping"; \
52 return; \
53 }
54
55using cricket::CA_OFFER;
56using cricket::CA_PRANSWER;
57using cricket::CA_ANSWER;
58using cricket::CA_UPDATE;
59using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::ScreencastId;
61using cricket::StreamParams;
62using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000063using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064
65static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
67static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
68static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
69static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
70static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
Peter Boström0c4e06b2015-10-07 12:23:21 +020071static const uint32_t kSsrc1 = 0x1111;
72static const uint32_t kSsrc2 = 0x2222;
73static const uint32_t kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000074static const int kAudioPts[] = {0, 8};
75static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
deadbeefcbecd352015-09-23 11:50:27 -070077template <class ChannelT,
78 class MediaChannelT,
79 class ContentT,
80 class CodecT,
81 class MediaInfoT,
82 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083class Traits {
84 public:
85 typedef ChannelT Channel;
86 typedef MediaChannelT MediaChannel;
87 typedef ContentT Content;
88 typedef CodecT Codec;
89 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020090 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091};
92
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093// Controls how long we wait for a session to send messages that we
94// expect, in milliseconds. We put it high to avoid flaky tests.
95static const int kEventTimeout = 5000;
96
97class VoiceTraits : public Traits<cricket::VoiceChannel,
98 cricket::FakeVoiceMediaChannel,
99 cricket::AudioContentDescription,
100 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200101 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700102 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
104class VideoTraits : public Traits<cricket::VideoChannel,
105 cricket::FakeVideoMediaChannel,
106 cricket::VideoContentDescription,
107 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200108 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700109 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
111class DataTraits : public Traits<cricket::DataChannel,
112 cricket::FakeDataMediaChannel,
113 cricket::DataContentDescription,
114 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200115 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700116 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000118rtc::StreamInterface* Open(const std::string& path) {
119 return rtc::Filesystem::OpenFile(
120 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121}
122
123// Base class for Voice/VideoChannel tests
124template<class T>
125class ChannelTest : public testing::Test, public sigslot::has_slots<> {
126 public:
127 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
128 DTLS = 0x10 };
129
Peter Boström34fbfff2015-09-24 19:20:30 +0200130 ChannelTest(bool verify_playout,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200131 const uint8_t* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700132 int rtp_len,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200133 const uint8_t* rtcp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700134 int rtcp_len)
Peter Boström34fbfff2015-09-24 19:20:30 +0200135 : verify_playout_(verify_playout),
136 transport_controller1_(cricket::ICEROLE_CONTROLLING),
deadbeefcbecd352015-09-23 11:50:27 -0700137 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138 media_channel1_(NULL),
139 media_channel2_(NULL),
140 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
141 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
142 media_info_callbacks1_(),
solenberg5b14b422015-10-01 04:10:31 -0700143 media_info_callbacks2_() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200146 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
147 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000148 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 void CreateChannels(
151 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000152 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 media_channel1_ = ch1;
154 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700155 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
156 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700158 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
159 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000160 (flags2 & RTCP) != 0));
161 channel1_->SignalMediaMonitor.connect(
162 this, &ChannelTest<T>::OnMediaMonitor);
163 channel2_->SignalMediaMonitor.connect(
164 this, &ChannelTest<T>::OnMediaMonitor);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000165 if ((flags1 & DTLS) && (flags2 & DTLS)) {
166 flags1 = (flags1 & ~SECURE);
167 flags2 = (flags2 & ~SECURE);
168 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 CreateContent(flags1, kPcmuCodec, kH264Codec,
170 &local_media_content1_);
171 CreateContent(flags2, kPcmuCodec, kH264Codec,
172 &local_media_content2_);
173 CopyContent(local_media_content1_, &remote_media_content1_);
174 CopyContent(local_media_content2_, &remote_media_content2_);
175
176 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200177 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700178 transport_controller1_.SetLocalCertificate(rtc::RTCCertificate::Create(
179 rtc::scoped_ptr<rtc::SSLIdentity>(
180 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))
181 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 }
183 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200184 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700185 transport_controller2_.SetLocalCertificate(rtc::RTCCertificate::Create(
186 rtc::scoped_ptr<rtc::SSLIdentity>(
187 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))
188 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 }
190
191 // Add stream information (SSRC) to the local content but not to the remote
192 // content. This means that we per default know the SSRC of what we send but
193 // not what we receive.
194 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
195 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
196
197 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
198 if (flags1 & SSRC_MUX) {
199 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
200 }
201 if (flags2 & SSRC_MUX) {
202 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
203 }
204 }
deadbeefcbecd352015-09-23 11:50:27 -0700205 typename T::Channel* CreateChannel(
206 rtc::Thread* thread,
207 cricket::MediaEngineInterface* engine,
208 typename T::MediaChannel* ch,
209 cricket::TransportController* transport_controller,
210 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700212 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 if (!channel->Init()) {
214 delete channel;
215 channel = NULL;
216 }
217 return channel;
218 }
219
220 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000221 bool result = channel1_->SetLocalContent(&local_media_content1_,
222 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 if (result) {
224 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000225 result = channel2_->SetRemoteContent(&remote_media_content1_,
226 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700228 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000230 result = channel2_->SetLocalContent(&local_media_content2_,
231 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 }
233 }
234 return result;
235 }
236
237 bool SendAccept() {
238 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000239 return channel1_->SetRemoteContent(&remote_media_content2_,
240 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 }
242
243 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000244 bool result = channel1_->SetLocalContent(&local_media_content1_,
245 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000246 if (result) {
247 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000248 result = channel2_->SetRemoteContent(&remote_media_content1_,
249 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 }
251 return result;
252 }
253
254 bool SendProvisionalAnswer() {
255 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000256 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 if (result) {
258 channel2_->Enable(true);
259 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000260 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700261 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 }
263 return result;
264 }
265
266 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000267 bool result = channel2_->SetLocalContent(&local_media_content2_,
268 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000269 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000270 result = channel1_->SetRemoteContent(&remote_media_content2_,
271 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 return result;
273 }
274
275 bool SendTerminate() {
276 channel1_.reset();
277 channel2_.reset();
278 return true;
279 }
280
281 bool AddStream1(int id) {
282 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
283 }
284 bool RemoveStream1(int id) {
285 return channel1_->RemoveRecvStream(id);
286 }
287
deadbeefcbecd352015-09-23 11:50:27 -0700288 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700290 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 }
292 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700293 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000294 }
295
296 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000297 return media_channel1_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700298 static_cast<int>(rtp_packet_.size()),
299 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
301 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000302 return media_channel2_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700303 static_cast<int>(rtp_packet_.size()),
304 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000305 }
306 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000307 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
308 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 }
310 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000311 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
312 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 }
314 // Methods to send custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200315 bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000316 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700317 return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()),
318 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200320 bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000321 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700322 return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()),
323 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200325 bool SendCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000327 return media_channel1_->SendRtcp(data.c_str(),
328 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000329 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200330 bool SendCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000332 return media_channel2_->SendRtcp(data.c_str(),
333 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000334 }
335 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000336 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
337 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 }
339 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000340 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
341 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 }
343 bool CheckRtcp1() {
344 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000345 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 }
347 bool CheckRtcp2() {
348 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000349 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 }
351 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200352 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000353 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000354 return media_channel1_->CheckRtp(data.c_str(),
355 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200357 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000358 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000359 return media_channel2_->CheckRtp(data.c_str(),
360 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200362 bool CheckCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000364 return media_channel1_->CheckRtcp(data.c_str(),
365 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200367 bool CheckCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000369 return media_channel2_->CheckRtcp(data.c_str(),
370 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200372 std::string CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 std::string data(rtp_packet_);
374 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000375 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
376 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000377 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000378 rtc::Set8(const_cast<char*>(data.c_str()), 1,
379 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000380 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 return data;
382 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200383 std::string CreateRtcpData(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 std::string data(rtcp_packet_);
385 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000386 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 return data;
388 }
389
390 bool CheckNoRtp1() {
391 return media_channel1_->CheckNoRtp();
392 }
393 bool CheckNoRtp2() {
394 return media_channel2_->CheckNoRtp();
395 }
396 bool CheckNoRtcp1() {
397 return media_channel1_->CheckNoRtcp();
398 }
399 bool CheckNoRtcp2() {
400 return media_channel2_->CheckNoRtcp();
401 }
402
403 void CreateContent(int flags,
404 const cricket::AudioCodec& audio_codec,
405 const cricket::VideoCodec& video_codec,
406 typename T::Content* content) {
407 // overridden in specialized classes
408 }
409 void CopyContent(const typename T::Content& source,
410 typename T::Content* content) {
411 // overridden in specialized classes
412 }
413
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 // Creates a cricket::SessionDescription with one MediaContent and one stream.
415 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200416 cricket::SessionDescription* CreateSessionDescriptionWithStream(
417 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 typename T::Content content;
419 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
420 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
421 AddLegacyStreamInContent(ssrc, 0, &content);
422 sdesc->AddContent("DUMMY_CONTENT_NAME",
423 cricket::NS_JINGLE_RTP, content.Copy());
424 return sdesc;
425 }
426
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000427 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 public:
429 typedef bool (ChannelTest<T>::*Method)();
430 CallThread(ChannelTest<T>* obj, Method method, bool* result)
431 : obj_(obj),
432 method_(method),
433 result_(result) {
434 *result = false;
435 }
436 virtual void DoWork() {
437 bool result = (*obj_.*method_)();
438 if (result_) {
439 *result_ = result;
440 }
441 }
442 private:
443 ChannelTest<T>* obj_;
444 Method method_;
445 bool* result_;
446 };
447 void CallOnThread(typename CallThread::Method method, bool* result) {
448 CallThread* thread = new CallThread(this, method, result);
449 thread->Start();
450 thread->Release();
451 }
452
453 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
454 bool* result) {
455 CallThread* thread = new CallThread(this, method, result);
456 thread->Start();
457 thread->Destroy(true);
458 }
459
460 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
461 return false; // overridden in specialized classes
462 }
463
464 void OnMediaMonitor(typename T::Channel* channel,
465 const typename T::MediaInfo& info) {
466 if (channel == channel1_.get()) {
467 media_info_callbacks1_++;
468 } else if (channel == channel2_.get()) {
469 media_info_callbacks2_++;
470 }
471 }
472
Peter Boström0c4e06b2015-10-07 12:23:21 +0200473 void AddLegacyStreamInContent(uint32_t ssrc,
474 int flags,
475 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000476 // Base implementation.
477 }
478
479 // Tests that can be used by derived classes.
480
481 // Basic sanity check.
482 void TestInit() {
483 CreateChannels(0, 0);
484 EXPECT_FALSE(channel1_->secure());
485 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200486 if (verify_playout_) {
487 EXPECT_FALSE(media_channel1_->playout());
488 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489 EXPECT_TRUE(media_channel1_->codecs().empty());
490 EXPECT_TRUE(media_channel1_->recv_streams().empty());
491 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
492 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
493 }
494
495 // Test that SetLocalContent and SetRemoteContent properly configure
496 // the codecs.
497 void TestSetContents() {
498 CreateChannels(0, 0);
499 typename T::Content content;
500 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000501 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000503 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000504 ASSERT_EQ(1U, media_channel1_->codecs().size());
505 EXPECT_TRUE(CodecMatches(content.codecs()[0],
506 media_channel1_->codecs()[0]));
507 }
508
509 // Test that SetLocalContent and SetRemoteContent properly deals
510 // with an empty offer.
511 void TestSetContentsNullOffer() {
512 CreateChannels(0, 0);
513 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000514 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 CreateContent(0, kPcmuCodec, kH264Codec, &content);
516 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000517 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 ASSERT_EQ(1U, media_channel1_->codecs().size());
519 EXPECT_TRUE(CodecMatches(content.codecs()[0],
520 media_channel1_->codecs()[0]));
521 }
522
523 // Test that SetLocalContent and SetRemoteContent properly set RTCP
524 // mux.
525 void TestSetContentsRtcpMux() {
526 CreateChannels(RTCP, RTCP);
527 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
528 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
529 typename T::Content content;
530 CreateContent(0, kPcmuCodec, kH264Codec, &content);
531 // Both sides agree on mux. Should no longer be a separate RTCP channel.
532 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000533 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
534 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
536 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000537 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000539 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
541 }
542
543 // Test that SetLocalContent and SetRemoteContent properly set RTCP
544 // mux when a provisional answer is received.
545 void TestSetContentsRtcpMuxWithPrAnswer() {
546 CreateChannels(RTCP, RTCP);
547 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
548 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
549 typename T::Content content;
550 CreateContent(0, kPcmuCodec, kH264Codec, &content);
551 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000552 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
553 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000555 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 // Both sides agree on mux. Should no longer be a separate RTCP channel.
557 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
558 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000559 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000561 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
562 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
564 }
565
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 // Test that SetRemoteContent properly deals with a content update.
567 void TestSetRemoteContentUpdate() {
568 CreateChannels(0, 0);
569 typename T::Content content;
570 CreateContent(RTCP | RTCP_MUX | SECURE,
571 kPcmuCodec, kH264Codec,
572 &content);
573 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000574 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
575 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 ASSERT_EQ(1U, media_channel1_->codecs().size());
577 EXPECT_TRUE(CodecMatches(content.codecs()[0],
578 media_channel1_->codecs()[0]));
579 // Now update with other codecs.
580 typename T::Content update_content;
581 update_content.set_partial(true);
582 CreateContent(0, kIsacCodec, kH264SvcCodec,
583 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000584 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 ASSERT_EQ(1U, media_channel1_->codecs().size());
586 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
587 media_channel1_->codecs()[0]));
588 // Now update without any codecs. This is ignored.
589 typename T::Content empty_content;
590 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000591 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592 ASSERT_EQ(1U, media_channel1_->codecs().size());
593 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
594 media_channel1_->codecs()[0]));
595 }
596
597 // Test that Add/RemoveStream properly forward to the media channel.
598 void TestStreams() {
599 CreateChannels(0, 0);
600 EXPECT_TRUE(AddStream1(1));
601 EXPECT_TRUE(AddStream1(2));
602 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
603 EXPECT_TRUE(RemoveStream1(2));
604 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
605 EXPECT_TRUE(RemoveStream1(1));
606 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
607 }
608
609 // Test that SetLocalContent properly handles adding and removing StreamParams
610 // to the local content description.
611 // This test uses the CA_UPDATE action that don't require a full
612 // MediaContentDescription to do an update.
613 void TestUpdateStreamsInLocalContent() {
614 cricket::StreamParams stream1;
615 stream1.groupid = "group1";
616 stream1.id = "stream1";
617 stream1.ssrcs.push_back(kSsrc1);
618 stream1.cname = "stream1_cname";
619
620 cricket::StreamParams stream2;
621 stream2.groupid = "group2";
622 stream2.id = "stream2";
623 stream2.ssrcs.push_back(kSsrc2);
624 stream2.cname = "stream2_cname";
625
626 cricket::StreamParams stream3;
627 stream3.groupid = "group3";
628 stream3.id = "stream3";
629 stream3.ssrcs.push_back(kSsrc3);
630 stream3.cname = "stream3_cname";
631
632 CreateChannels(0, 0);
633 typename T::Content content1;
634 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
635 content1.AddStream(stream1);
636 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000637 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638
639 ASSERT_EQ(1u, media_channel1_->send_streams().size());
640 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
641
642 // Update the local streams by adding another sending stream.
643 // Use a partial updated session description.
644 typename T::Content content2;
645 content2.AddStream(stream2);
646 content2.AddStream(stream3);
647 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000648 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 ASSERT_EQ(3u, media_channel1_->send_streams().size());
650 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
651 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
652 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
653
654 // Update the local streams by removing the first sending stream.
655 // This is done by removing all SSRCS for this particular stream.
656 typename T::Content content3;
657 stream1.ssrcs.clear();
658 content3.AddStream(stream1);
659 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000660 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 ASSERT_EQ(2u, media_channel1_->send_streams().size());
662 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
663 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
664
665 // Update the local streams with a stream that does not change.
666 // THe update is ignored.
667 typename T::Content content4;
668 content4.AddStream(stream2);
669 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000670 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 ASSERT_EQ(2u, media_channel1_->send_streams().size());
672 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
673 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
674 }
675
676 // Test that SetRemoteContent properly handles adding and removing
677 // StreamParams to the remote content description.
678 // This test uses the CA_UPDATE action that don't require a full
679 // MediaContentDescription to do an update.
680 void TestUpdateStreamsInRemoteContent() {
681 cricket::StreamParams stream1;
682 stream1.id = "Stream1";
683 stream1.groupid = "1";
684 stream1.ssrcs.push_back(kSsrc1);
685 stream1.cname = "stream1_cname";
686
687 cricket::StreamParams stream2;
688 stream2.id = "Stream2";
689 stream2.groupid = "2";
690 stream2.ssrcs.push_back(kSsrc2);
691 stream2.cname = "stream2_cname";
692
693 cricket::StreamParams stream3;
694 stream3.id = "Stream3";
695 stream3.groupid = "3";
696 stream3.ssrcs.push_back(kSsrc3);
697 stream3.cname = "stream3_cname";
698
699 CreateChannels(0, 0);
700 typename T::Content content1;
701 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
702 content1.AddStream(stream1);
703 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000704 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705
706 ASSERT_EQ(1u, media_channel1_->codecs().size());
707 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
708 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
709
710 // Update the remote streams by adding another sending stream.
711 // Use a partial updated session description.
712 typename T::Content content2;
713 content2.AddStream(stream2);
714 content2.AddStream(stream3);
715 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000716 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
718 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
719 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
720 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
721
722 // Update the remote streams by removing the first stream.
723 // This is done by removing all SSRCS for this particular stream.
724 typename T::Content content3;
725 stream1.ssrcs.clear();
726 content3.AddStream(stream1);
727 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
730 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
731 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
732
733 // Update the remote streams with a stream that does not change.
734 // The update is ignored.
735 typename T::Content content4;
736 content4.AddStream(stream2);
737 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000738 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
740 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
741 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
742 }
743
744 // Test that SetLocalContent and SetRemoteContent properly
745 // handles adding and removing StreamParams when the action is a full
746 // CA_OFFER / CA_ANSWER.
747 void TestChangeStreamParamsInContent() {
748 cricket::StreamParams stream1;
749 stream1.groupid = "group1";
750 stream1.id = "stream1";
751 stream1.ssrcs.push_back(kSsrc1);
752 stream1.cname = "stream1_cname";
753
754 cricket::StreamParams stream2;
755 stream2.groupid = "group1";
756 stream2.id = "stream2";
757 stream2.ssrcs.push_back(kSsrc2);
758 stream2.cname = "stream2_cname";
759
760 // Setup a call where channel 1 send |stream1| to channel 2.
761 CreateChannels(0, 0);
762 typename T::Content content1;
763 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
764 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000765 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 EXPECT_TRUE(channel1_->Enable(true));
767 EXPECT_EQ(1u, media_channel1_->send_streams().size());
768
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000769 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700771 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772
773 // Channel 2 do not send anything.
774 typename T::Content content2;
775 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000776 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000778 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 EXPECT_TRUE(channel2_->Enable(true));
780 EXPECT_EQ(0u, media_channel2_->send_streams().size());
781
782 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
783 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
784
785 // Let channel 2 update the content by sending |stream2| and enable SRTP.
786 typename T::Content content3;
787 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
788 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000789 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 ASSERT_EQ(1u, media_channel2_->send_streams().size());
791 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
792
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
795 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
796
797 // Channel 1 replies but stop sending stream1.
798 typename T::Content content4;
799 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000800 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(0u, media_channel1_->send_streams().size());
802
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000803 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
805
806 EXPECT_TRUE(channel1_->secure());
807 EXPECT_TRUE(channel2_->secure());
808 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
809 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
810 }
811
812 // Test that we only start playout and sending at the right times.
813 void TestPlayoutAndSendingStates() {
814 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200815 if (verify_playout_) {
816 EXPECT_FALSE(media_channel1_->playout());
817 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 EXPECT_FALSE(media_channel1_->sending());
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());
823 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200824 if (verify_playout_) {
825 EXPECT_FALSE(media_channel1_->playout());
826 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000828 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
829 CA_OFFER, NULL));
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());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000834 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
835 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200836 if (verify_playout_) {
837 EXPECT_FALSE(media_channel2_->playout());
838 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000840 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
841 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200842 if (verify_playout_) {
843 EXPECT_FALSE(media_channel2_->playout());
844 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700846 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200847 if (verify_playout_) {
848 EXPECT_TRUE(media_channel1_->playout());
849 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200851 if (verify_playout_) {
852 EXPECT_FALSE(media_channel2_->playout());
853 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 EXPECT_FALSE(media_channel2_->sending());
855 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200856 if (verify_playout_) {
857 EXPECT_TRUE(media_channel2_->playout());
858 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000860 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
861 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200862 if (verify_playout_) {
863 EXPECT_TRUE(media_channel1_->playout());
864 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 EXPECT_TRUE(media_channel1_->sending());
866 }
867
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 // Test that changing the MediaContentDirection in the local and remote
869 // session description start playout and sending at the right time.
870 void TestMediaContentDirection() {
871 CreateChannels(0, 0);
872 typename T::Content content1;
873 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
874 typename T::Content content2;
875 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
876 // Set |content2| to be InActive.
877 content2.set_direction(cricket::MD_INACTIVE);
878
879 EXPECT_TRUE(channel1_->Enable(true));
880 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200881 if (verify_playout_) {
882 EXPECT_FALSE(media_channel1_->playout());
883 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200885 if (verify_playout_) {
886 EXPECT_FALSE(media_channel2_->playout());
887 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 EXPECT_FALSE(media_channel2_->sending());
889
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000890 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
891 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
892 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
893 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700894 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895
Peter Boström34fbfff2015-09-24 19:20:30 +0200896 if (verify_playout_) {
897 EXPECT_TRUE(media_channel1_->playout());
898 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200900 if (verify_playout_) {
901 EXPECT_FALSE(media_channel2_->playout()); // local InActive
902 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 EXPECT_FALSE(media_channel2_->sending()); // local InActive
904
905 // Update |content2| to be RecvOnly.
906 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000907 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
908 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909
Peter Boström34fbfff2015-09-24 19:20:30 +0200910 if (verify_playout_) {
911 EXPECT_TRUE(media_channel1_->playout());
912 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200914 if (verify_playout_) {
915 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
916 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000917 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
918
919 // Update |content2| to be SendRecv.
920 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000921 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
922 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923
Peter Boström34fbfff2015-09-24 19:20:30 +0200924 if (verify_playout_) {
925 EXPECT_TRUE(media_channel1_->playout());
926 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200928 if (verify_playout_) {
929 EXPECT_TRUE(media_channel2_->playout());
930 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 EXPECT_TRUE(media_channel2_->sending());
932 }
933
934 // Test setting up a call.
935 void TestCallSetup() {
936 CreateChannels(0, 0);
937 EXPECT_FALSE(channel1_->secure());
938 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200939 if (verify_playout_) {
940 EXPECT_TRUE(media_channel1_->playout());
941 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 EXPECT_FALSE(media_channel1_->sending());
943 EXPECT_TRUE(SendAccept());
944 EXPECT_FALSE(channel1_->secure());
945 EXPECT_TRUE(media_channel1_->sending());
946 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200947 if (verify_playout_) {
948 EXPECT_TRUE(media_channel2_->playout());
949 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 EXPECT_TRUE(media_channel2_->sending());
951 EXPECT_EQ(1U, media_channel2_->codecs().size());
952 }
953
954 // Test that we don't crash if packets are sent during call teardown
955 // when RTCP mux is enabled. This is a regression test against a specific
956 // race condition that would only occur when a RTCP packet was sent during
957 // teardown of a channel on which RTCP mux was enabled.
958 void TestCallTeardownRtcpMux() {
959 class LastWordMediaChannel : public T::MediaChannel {
960 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200961 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700963 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
964 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
966 }
967 };
968 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
969 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000970 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 EXPECT_TRUE(SendInitiate());
972 EXPECT_TRUE(SendAccept());
973 EXPECT_TRUE(SendTerminate());
974 }
975
976 // Send voice RTP data to the other side and ensure it gets there.
977 void SendRtpToRtp() {
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_TRUE(SendRtp1());
986 EXPECT_TRUE(SendRtp2());
987 EXPECT_TRUE(CheckRtp1());
988 EXPECT_TRUE(CheckRtp2());
989 EXPECT_TRUE(CheckNoRtp1());
990 EXPECT_TRUE(CheckNoRtp2());
991 }
992
993 // Check that RTCP is not transmitted if both sides don't support RTCP.
994 void SendNoRtcpToNoRtcp() {
995 CreateChannels(0, 0);
996 EXPECT_TRUE(SendInitiate());
997 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700998 ASSERT_TRUE(GetTransport1());
999 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 EXPECT_EQ(1U, GetTransport1()->channels().size());
1001 EXPECT_EQ(1U, GetTransport2()->channels().size());
1002 EXPECT_FALSE(SendRtcp1());
1003 EXPECT_FALSE(SendRtcp2());
1004 EXPECT_TRUE(CheckNoRtcp1());
1005 EXPECT_TRUE(CheckNoRtcp2());
1006 }
1007
1008 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1009 void SendNoRtcpToRtcp() {
1010 CreateChannels(0, RTCP);
1011 EXPECT_TRUE(SendInitiate());
1012 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001013 ASSERT_TRUE(GetTransport1());
1014 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001015 EXPECT_EQ(1U, GetTransport1()->channels().size());
1016 EXPECT_EQ(2U, GetTransport2()->channels().size());
1017 EXPECT_FALSE(SendRtcp1());
1018 EXPECT_FALSE(SendRtcp2());
1019 EXPECT_TRUE(CheckNoRtcp1());
1020 EXPECT_TRUE(CheckNoRtcp2());
1021 }
1022
1023 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1024 void SendRtcpToNoRtcp() {
1025 CreateChannels(RTCP, 0);
1026 EXPECT_TRUE(SendInitiate());
1027 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001028 ASSERT_TRUE(GetTransport1());
1029 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001030 EXPECT_EQ(2U, GetTransport1()->channels().size());
1031 EXPECT_EQ(1U, GetTransport2()->channels().size());
1032 EXPECT_FALSE(SendRtcp1());
1033 EXPECT_FALSE(SendRtcp2());
1034 EXPECT_TRUE(CheckNoRtcp1());
1035 EXPECT_TRUE(CheckNoRtcp2());
1036 }
1037
1038 // Check that RTCP is transmitted if both sides support RTCP.
1039 void SendRtcpToRtcp() {
1040 CreateChannels(RTCP, 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 RTCP is transmitted if only the initiator supports mux.
1056 void SendRtcpMuxToRtcp() {
1057 CreateChannels(RTCP | RTCP_MUX, RTCP);
1058 EXPECT_TRUE(SendInitiate());
1059 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001060 ASSERT_TRUE(GetTransport1());
1061 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 EXPECT_EQ(2U, GetTransport1()->channels().size());
1063 EXPECT_EQ(2U, GetTransport2()->channels().size());
1064 EXPECT_TRUE(SendRtcp1());
1065 EXPECT_TRUE(SendRtcp2());
1066 EXPECT_TRUE(CheckRtcp1());
1067 EXPECT_TRUE(CheckRtcp2());
1068 EXPECT_TRUE(CheckNoRtcp1());
1069 EXPECT_TRUE(CheckNoRtcp2());
1070 }
1071
1072 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1073 void SendRtcpMuxToRtcpMux() {
1074 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1075 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001076 ASSERT_TRUE(GetTransport1());
1077 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001078 EXPECT_EQ(2U, GetTransport1()->channels().size());
1079 EXPECT_EQ(1U, GetTransport2()->channels().size());
1080 EXPECT_TRUE(SendAccept());
1081 EXPECT_EQ(1U, GetTransport1()->channels().size());
1082 EXPECT_TRUE(SendRtp1());
1083 EXPECT_TRUE(SendRtp2());
1084 EXPECT_TRUE(SendRtcp1());
1085 EXPECT_TRUE(SendRtcp2());
1086 EXPECT_TRUE(CheckRtp1());
1087 EXPECT_TRUE(CheckRtp2());
1088 EXPECT_TRUE(CheckNoRtp1());
1089 EXPECT_TRUE(CheckNoRtp2());
1090 EXPECT_TRUE(CheckRtcp1());
1091 EXPECT_TRUE(CheckRtcp2());
1092 EXPECT_TRUE(CheckNoRtcp1());
1093 EXPECT_TRUE(CheckNoRtcp2());
1094 }
1095
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001096 // Check that RTP and RTCP are transmitted ok when both sides
1097 // support mux and one the offerer requires mux.
1098 void SendRequireRtcpMuxToRtcpMux() {
1099 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1100 channel1_->ActivateRtcpMux();
1101 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001102 ASSERT_TRUE(GetTransport1());
1103 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001104 EXPECT_EQ(1U, GetTransport1()->channels().size());
1105 EXPECT_EQ(1U, GetTransport2()->channels().size());
1106 EXPECT_TRUE(SendAccept());
1107 EXPECT_TRUE(SendRtp1());
1108 EXPECT_TRUE(SendRtp2());
1109 EXPECT_TRUE(SendRtcp1());
1110 EXPECT_TRUE(SendRtcp2());
1111 EXPECT_TRUE(CheckRtp1());
1112 EXPECT_TRUE(CheckRtp2());
1113 EXPECT_TRUE(CheckNoRtp1());
1114 EXPECT_TRUE(CheckNoRtp2());
1115 EXPECT_TRUE(CheckRtcp1());
1116 EXPECT_TRUE(CheckRtcp2());
1117 EXPECT_TRUE(CheckNoRtcp1());
1118 EXPECT_TRUE(CheckNoRtcp2());
1119 }
1120
1121 // Check that RTP and RTCP are transmitted ok when both sides
1122 // support mux and one the answerer requires rtcp mux.
1123 void SendRtcpMuxToRequireRtcpMux() {
1124 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1125 channel2_->ActivateRtcpMux();
1126 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001127 ASSERT_TRUE(GetTransport1());
1128 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001129 EXPECT_EQ(2U, GetTransport1()->channels().size());
1130 EXPECT_EQ(1U, GetTransport2()->channels().size());
1131 EXPECT_TRUE(SendAccept());
1132 EXPECT_EQ(1U, GetTransport1()->channels().size());
1133 EXPECT_TRUE(SendRtp1());
1134 EXPECT_TRUE(SendRtp2());
1135 EXPECT_TRUE(SendRtcp1());
1136 EXPECT_TRUE(SendRtcp2());
1137 EXPECT_TRUE(CheckRtp1());
1138 EXPECT_TRUE(CheckRtp2());
1139 EXPECT_TRUE(CheckNoRtp1());
1140 EXPECT_TRUE(CheckNoRtp2());
1141 EXPECT_TRUE(CheckRtcp1());
1142 EXPECT_TRUE(CheckRtcp2());
1143 EXPECT_TRUE(CheckNoRtcp1());
1144 EXPECT_TRUE(CheckNoRtcp2());
1145 }
1146
1147 // Check that RTP and RTCP are transmitted ok when both sides
1148 // require mux.
1149 void SendRequireRtcpMuxToRequireRtcpMux() {
1150 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1151 channel1_->ActivateRtcpMux();
1152 channel2_->ActivateRtcpMux();
1153 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001154 ASSERT_TRUE(GetTransport1());
1155 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001156 EXPECT_EQ(1U, GetTransport1()->channels().size());
1157 EXPECT_EQ(1U, GetTransport2()->channels().size());
1158 EXPECT_TRUE(SendAccept());
1159 EXPECT_EQ(1U, GetTransport1()->channels().size());
1160 EXPECT_TRUE(SendRtp1());
1161 EXPECT_TRUE(SendRtp2());
1162 EXPECT_TRUE(SendRtcp1());
1163 EXPECT_TRUE(SendRtcp2());
1164 EXPECT_TRUE(CheckRtp1());
1165 EXPECT_TRUE(CheckRtp2());
1166 EXPECT_TRUE(CheckNoRtp1());
1167 EXPECT_TRUE(CheckNoRtp2());
1168 EXPECT_TRUE(CheckRtcp1());
1169 EXPECT_TRUE(CheckRtcp2());
1170 EXPECT_TRUE(CheckNoRtcp1());
1171 EXPECT_TRUE(CheckNoRtcp2());
1172 }
1173
1174 // Check that SendAccept fails if the answerer doesn't support mux
1175 // and the offerer requires it.
1176 void SendRequireRtcpMuxToNoRtcpMux() {
1177 CreateChannels(RTCP | RTCP_MUX, RTCP);
1178 channel1_->ActivateRtcpMux();
1179 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001180 ASSERT_TRUE(GetTransport1());
1181 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001182 EXPECT_EQ(1U, GetTransport1()->channels().size());
1183 EXPECT_EQ(2U, GetTransport2()->channels().size());
1184 EXPECT_FALSE(SendAccept());
1185 }
1186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 // Check that RTCP data sent by the initiator before the accept is not muxed.
1188 void SendEarlyRtcpMuxToRtcp() {
1189 CreateChannels(RTCP | RTCP_MUX, RTCP);
1190 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001191 ASSERT_TRUE(GetTransport1());
1192 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 EXPECT_EQ(2U, GetTransport1()->channels().size());
1194 EXPECT_EQ(2U, GetTransport2()->channels().size());
1195
1196 // RTCP can be sent before the call is accepted, if the transport is ready.
1197 // It should not be muxed though, as the remote side doesn't support mux.
1198 EXPECT_TRUE(SendRtcp1());
1199 EXPECT_TRUE(CheckNoRtp2());
1200 EXPECT_TRUE(CheckRtcp2());
1201
1202 // Send RTCP packet from callee and verify that it is received.
1203 EXPECT_TRUE(SendRtcp2());
1204 EXPECT_TRUE(CheckNoRtp1());
1205 EXPECT_TRUE(CheckRtcp1());
1206
1207 // Complete call setup and ensure everything is still OK.
1208 EXPECT_TRUE(SendAccept());
1209 EXPECT_EQ(2U, GetTransport1()->channels().size());
1210 EXPECT_TRUE(SendRtcp1());
1211 EXPECT_TRUE(CheckRtcp2());
1212 EXPECT_TRUE(SendRtcp2());
1213 EXPECT_TRUE(CheckRtcp1());
1214 }
1215
1216
1217 // Check that RTCP data is not muxed until both sides have enabled muxing,
1218 // but that we properly demux before we get the accept message, since there
1219 // is a race between RTP data and the jingle accept.
1220 void SendEarlyRtcpMuxToRtcpMux() {
1221 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1222 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001223 ASSERT_TRUE(GetTransport1());
1224 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 EXPECT_EQ(2U, GetTransport1()->channels().size());
1226 EXPECT_EQ(1U, GetTransport2()->channels().size());
1227
1228 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1229 // we haven't yet received the accept that says we should mux.
1230 EXPECT_FALSE(SendRtcp1());
1231
1232 // Send muxed RTCP packet from callee and verify that it is received.
1233 EXPECT_TRUE(SendRtcp2());
1234 EXPECT_TRUE(CheckNoRtp1());
1235 EXPECT_TRUE(CheckRtcp1());
1236
1237 // Complete call setup and ensure everything is still OK.
1238 EXPECT_TRUE(SendAccept());
1239 EXPECT_EQ(1U, GetTransport1()->channels().size());
1240 EXPECT_TRUE(SendRtcp1());
1241 EXPECT_TRUE(CheckRtcp2());
1242 EXPECT_TRUE(SendRtcp2());
1243 EXPECT_TRUE(CheckRtcp1());
1244 }
1245
1246 // Test that we properly send SRTP with RTCP in both directions.
1247 // You can pass in DTLS and/or RTCP_MUX as flags.
1248 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1249 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1250 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1251
1252 int flags1 = RTCP | SECURE | flags1_in;
1253 int flags2 = RTCP | SECURE | flags2_in;
1254 bool dtls1 = !!(flags1_in & DTLS);
1255 bool dtls2 = !!(flags2_in & DTLS);
1256 CreateChannels(flags1, flags2);
1257 EXPECT_FALSE(channel1_->secure());
1258 EXPECT_FALSE(channel2_->secure());
1259 EXPECT_TRUE(SendInitiate());
1260 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1261 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1262 EXPECT_TRUE(SendAccept());
1263 EXPECT_TRUE(channel1_->secure());
1264 EXPECT_TRUE(channel2_->secure());
1265 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1266 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1267 EXPECT_TRUE(SendRtp1());
1268 EXPECT_TRUE(SendRtp2());
1269 EXPECT_TRUE(SendRtcp1());
1270 EXPECT_TRUE(SendRtcp2());
1271 EXPECT_TRUE(CheckRtp1());
1272 EXPECT_TRUE(CheckRtp2());
1273 EXPECT_TRUE(CheckNoRtp1());
1274 EXPECT_TRUE(CheckNoRtp2());
1275 EXPECT_TRUE(CheckRtcp1());
1276 EXPECT_TRUE(CheckRtcp2());
1277 EXPECT_TRUE(CheckNoRtcp1());
1278 EXPECT_TRUE(CheckNoRtcp2());
1279 }
1280
1281 // Test that we properly handling SRTP negotiating down to RTP.
1282 void SendSrtpToRtp() {
1283 CreateChannels(RTCP | SECURE, RTCP);
1284 EXPECT_FALSE(channel1_->secure());
1285 EXPECT_FALSE(channel2_->secure());
1286 EXPECT_TRUE(SendInitiate());
1287 EXPECT_TRUE(SendAccept());
1288 EXPECT_FALSE(channel1_->secure());
1289 EXPECT_FALSE(channel2_->secure());
1290 EXPECT_TRUE(SendRtp1());
1291 EXPECT_TRUE(SendRtp2());
1292 EXPECT_TRUE(SendRtcp1());
1293 EXPECT_TRUE(SendRtcp2());
1294 EXPECT_TRUE(CheckRtp1());
1295 EXPECT_TRUE(CheckRtp2());
1296 EXPECT_TRUE(CheckNoRtp1());
1297 EXPECT_TRUE(CheckNoRtp2());
1298 EXPECT_TRUE(CheckRtcp1());
1299 EXPECT_TRUE(CheckRtcp2());
1300 EXPECT_TRUE(CheckNoRtcp1());
1301 EXPECT_TRUE(CheckNoRtcp2());
1302 }
1303
1304 // Test that we can send and receive early media when a provisional answer is
1305 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1306 void SendEarlyMediaUsingRtcpMuxSrtp() {
1307 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1308
1309 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1310 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1311 EXPECT_TRUE(SendOffer());
1312 EXPECT_TRUE(SendProvisionalAnswer());
1313 EXPECT_TRUE(channel1_->secure());
1314 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001315 ASSERT_TRUE(GetTransport1());
1316 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 EXPECT_EQ(2U, GetTransport1()->channels().size());
1318 EXPECT_EQ(2U, GetTransport2()->channels().size());
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
1324 // Send packets from callee and verify that it is received.
1325 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1326 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1327 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1328 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1329
1330 // Complete call setup and ensure everything is still OK.
1331 EXPECT_TRUE(SendFinalAnswer());
1332 EXPECT_EQ(1U, GetTransport1()->channels().size());
1333 EXPECT_EQ(1U, GetTransport2()->channels().size());
1334 EXPECT_TRUE(channel1_->secure());
1335 EXPECT_TRUE(channel2_->secure());
1336 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1337 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1338 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1339 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1340 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1341 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1342 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1343 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1344 }
1345
1346 // Test that we properly send RTP without SRTP from a thread.
1347 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001348 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1349 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 EXPECT_TRUE(SendInitiate());
1351 EXPECT_TRUE(SendAccept());
1352 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1353 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001354 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1355 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1357 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1358 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1359 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1360 EXPECT_TRUE(CheckNoRtp1());
1361 EXPECT_TRUE(CheckNoRtp2());
1362 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1363 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1364 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1365 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1366 EXPECT_TRUE(CheckNoRtcp1());
1367 EXPECT_TRUE(CheckNoRtcp2());
1368 }
1369
1370 // Test that we properly send SRTP with RTCP from a thread.
1371 void SendSrtpToSrtpOnThread() {
1372 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1373 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1374 EXPECT_TRUE(SendInitiate());
1375 EXPECT_TRUE(SendAccept());
1376 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1377 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1378 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1379 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1380 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1381 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1382 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1383 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1384 EXPECT_TRUE(CheckNoRtp1());
1385 EXPECT_TRUE(CheckNoRtp2());
1386 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1387 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1388 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1389 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1390 EXPECT_TRUE(CheckNoRtcp1());
1391 EXPECT_TRUE(CheckNoRtcp2());
1392 }
1393
1394 // Test that the mediachannel retains its sending state after the transport
1395 // becomes non-writable.
1396 void SendWithWritabilityLoss() {
1397 CreateChannels(0, 0);
1398 EXPECT_TRUE(SendInitiate());
1399 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001400 ASSERT_TRUE(GetTransport1());
1401 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 EXPECT_EQ(1U, GetTransport1()->channels().size());
1403 EXPECT_EQ(1U, GetTransport2()->channels().size());
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
wu@webrtc.org97077a32013-10-25 21:18:33 +00001411 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_FALSE(SendRtp1());
1414 EXPECT_TRUE(SendRtp2());
1415 EXPECT_TRUE(CheckRtp1());
1416 EXPECT_TRUE(CheckNoRtp2());
1417
1418 // Regain writability
1419 GetTransport1()->SetWritable(true);
1420 EXPECT_TRUE(media_channel1_->sending());
1421 EXPECT_TRUE(SendRtp1());
1422 EXPECT_TRUE(SendRtp2());
1423 EXPECT_TRUE(CheckRtp1());
1424 EXPECT_TRUE(CheckRtp2());
1425 EXPECT_TRUE(CheckNoRtp1());
1426 EXPECT_TRUE(CheckNoRtp2());
1427
1428 // Lose writability completely
1429 GetTransport1()->SetDestination(NULL);
1430 EXPECT_TRUE(media_channel1_->sending());
1431
wu@webrtc.org97077a32013-10-25 21:18:33 +00001432 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 EXPECT_FALSE(SendRtp1());
1434 EXPECT_TRUE(SendRtp2());
1435 EXPECT_TRUE(CheckRtp1());
1436 EXPECT_TRUE(CheckNoRtp2());
1437
1438 // Gain writability back
1439 GetTransport1()->SetDestination(GetTransport2());
1440 EXPECT_TRUE(media_channel1_->sending());
1441 EXPECT_TRUE(SendRtp1());
1442 EXPECT_TRUE(SendRtp2());
1443 EXPECT_TRUE(CheckRtp1());
1444 EXPECT_TRUE(CheckRtp2());
1445 EXPECT_TRUE(CheckNoRtp1());
1446 EXPECT_TRUE(CheckNoRtp2());
1447 }
1448
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001449 void SendBundleToBundle(
1450 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1451 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001453 // Only pl_type1 was added to the bundle filter for both |channel1_|
1454 // and |channel2_|.
1455 int pl_type1 = pl_types[0];
1456 int pl_type2 = pl_types[1];
1457 int flags = SSRC_MUX | RTCP;
1458 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001459 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001460 if (rtcp_mux) {
1461 flags |= RTCP_MUX;
1462 expected_channels = 1U;
1463 }
1464 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001466 ASSERT_TRUE(GetTransport1());
1467 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001469 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001471 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1472 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1473 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1474 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1475 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1476 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001477
1478 // Both channels can receive pl_type1 only.
1479 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1480 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1481 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1482 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1483 EXPECT_TRUE(CheckNoRtp1());
1484 EXPECT_TRUE(CheckNoRtp2());
1485
1486 // RTCP test
1487 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1488 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1489 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1490 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1491
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1493 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1495 EXPECT_TRUE(CheckNoRtcp1());
1496 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1497 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001499 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1500 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
pbos482b12e2015-11-16 10:19:58 -08001501 // Bundle filter shouldn't filter out any RTCP.
1502 EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
1503 EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 }
1505
1506 // Test that the media monitor can be run and gives timely callbacks.
1507 void TestMediaMonitor() {
1508 static const int kTimeout = 500;
1509 CreateChannels(0, 0);
1510 EXPECT_TRUE(SendInitiate());
1511 EXPECT_TRUE(SendAccept());
1512 channel1_->StartMediaMonitor(100);
1513 channel2_->StartMediaMonitor(100);
1514 // Ensure we get callbacks and stop.
1515 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1516 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1517 channel1_->StopMediaMonitor();
1518 channel2_->StopMediaMonitor();
1519 // Ensure a restart of a stopped monitor works.
1520 channel1_->StartMediaMonitor(100);
1521 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1522 channel1_->StopMediaMonitor();
1523 // Ensure stopping a stopped monitor is OK.
1524 channel1_->StopMediaMonitor();
1525 }
1526
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 void TestSetContentFailure() {
1528 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529
Peter Thatchera6d24442015-07-09 21:26:36 -07001530 auto sdesc = cricket::SessionDescription();
1531 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1532 new cricket::AudioContentDescription());
1533 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1534 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535
Peter Thatchera6d24442015-07-09 21:26:36 -07001536 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001538 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1539 &sdesc, cricket::CA_OFFER, &err));
1540 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1541 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001544 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1545 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001547 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1548 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 }
1550
1551 void TestSendTwoOffers() {
1552 CreateChannels(0, 0);
1553
Peter Thatchera6d24442015-07-09 21:26:36 -07001554 std::string err;
1555 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1556 CreateSessionDescriptionWithStream(1));
1557 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1558 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1560
Peter Thatchera6d24442015-07-09 21:26:36 -07001561 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1562 CreateSessionDescriptionWithStream(2));
1563 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1564 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1566 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1567 }
1568
1569 void TestReceiveTwoOffers() {
1570 CreateChannels(0, 0);
1571
Peter Thatchera6d24442015-07-09 21:26:36 -07001572 std::string err;
1573 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1574 CreateSessionDescriptionWithStream(1));
1575 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1576 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1578
Peter Thatchera6d24442015-07-09 21:26:36 -07001579 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1580 CreateSessionDescriptionWithStream(2));
1581 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1582 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1584 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1585 }
1586
1587 void TestSendPrAnswer() {
1588 CreateChannels(0, 0);
1589
Peter Thatchera6d24442015-07-09 21:26:36 -07001590 std::string err;
1591 // Receive offer
1592 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1593 CreateSessionDescriptionWithStream(1));
1594 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1595 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1597
Peter Thatchera6d24442015-07-09 21:26:36 -07001598 // Send PR answer
1599 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1600 CreateSessionDescriptionWithStream(2));
1601 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1602 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1604 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1605
Peter Thatchera6d24442015-07-09 21:26:36 -07001606 // Send answer
1607 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1608 CreateSessionDescriptionWithStream(3));
1609 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1610 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1612 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1613 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1614 }
1615
1616 void TestReceivePrAnswer() {
1617 CreateChannels(0, 0);
1618
Peter Thatchera6d24442015-07-09 21:26:36 -07001619 std::string err;
1620 // Send offer
1621 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1622 CreateSessionDescriptionWithStream(1));
1623 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1624 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1626
Peter Thatchera6d24442015-07-09 21:26:36 -07001627 // Receive PR answer
1628 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1629 CreateSessionDescriptionWithStream(2));
1630 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1631 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1633 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1634
Peter Thatchera6d24442015-07-09 21:26:36 -07001635 // Receive answer
1636 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1637 CreateSessionDescriptionWithStream(3));
1638 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1639 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1641 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1642 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1643 }
1644
1645 void TestFlushRtcp() {
1646 bool send_rtcp1;
1647
1648 CreateChannels(RTCP, RTCP);
1649 EXPECT_TRUE(SendInitiate());
1650 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001651 ASSERT_TRUE(GetTransport1());
1652 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 EXPECT_EQ(2U, GetTransport1()->channels().size());
1654 EXPECT_EQ(2U, GetTransport2()->channels().size());
1655
1656 // Send RTCP1 from a different thread.
1657 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1658 EXPECT_TRUE(send_rtcp1);
1659 // The sending message is only posted. channel2_ should be empty.
1660 EXPECT_TRUE(CheckNoRtcp2());
1661
1662 // When channel1_ is deleted, the RTCP packet should be sent out to
1663 // channel2_.
1664 channel1_.reset();
1665 EXPECT_TRUE(CheckRtcp2());
1666 }
1667
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001668 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001669 struct SrtpErrorHandler : public sigslot::has_slots<> {
1670 SrtpErrorHandler() :
1671 mode_(cricket::SrtpFilter::UNPROTECT),
1672 error_(cricket::SrtpFilter::ERROR_NONE) {}
1673 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1674 cricket::SrtpFilter::Error error) {
1675 mode_ = mode;
1676 error_ = error;
1677 }
1678 cricket::SrtpFilter::Mode mode_;
1679 cricket::SrtpFilter::Error error_;
1680 } error_handler;
1681
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001682 // For Audio, only pl_type 0 is added to the bundle filter.
1683 // For Video, only pl_type 97 is added to the bundle filter.
1684 // So we need to pass in pl_type so that the packet can pass through
1685 // the bundle filter before it can be processed by the srtp filter.
1686 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001687 unsigned const char kBadPacket[] = {0x84,
1688 static_cast<unsigned char>(pl_type),
1689 0x00,
1690 0x01,
1691 0x00,
1692 0x00,
1693 0x00,
1694 0x00,
1695 0x00,
1696 0x00,
1697 0x00,
1698 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1700 EXPECT_FALSE(channel1_->secure());
1701 EXPECT_FALSE(channel2_->secure());
1702 EXPECT_TRUE(SendInitiate());
1703 EXPECT_TRUE(SendAccept());
1704 EXPECT_TRUE(channel1_->secure());
1705 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001706 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001707 channel2_->srtp_filter()->SignalSrtpError.connect(
1708 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709
1710 // Testing failures in sending packets.
stefanc1aeaf02015-10-15 07:26:07 -07001711 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1712 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001714 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1715 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1716 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001717 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1718 // The next 250 ms failures will not trigger an error.
stefanc1aeaf02015-10-15 07:26:07 -07001719 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1720 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001722 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001723 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001724 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1725 // Wait for a little more - the error will be triggered again.
1726 rtc::Thread::Current()->ProcessMessages(200);
stefanc1aeaf02015-10-15 07:26:07 -07001727 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1728 rtc::PacketOptions()));
solenberg5b14b422015-10-01 04:10:31 -07001729 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1730 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731
1732 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001733 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001734 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001735
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 cricket::TransportChannel* transport_channel =
1737 channel2_->transport_channel();
1738 transport_channel->SignalReadPacket(
1739 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001740 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001741 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1742 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 }
1744
1745 void TestOnReadyToSend() {
1746 CreateChannels(RTCP, RTCP);
1747 TransportChannel* rtp = channel1_->transport_channel();
1748 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1749 EXPECT_FALSE(media_channel1_->ready_to_send());
1750 rtp->SignalReadyToSend(rtp);
1751 EXPECT_FALSE(media_channel1_->ready_to_send());
1752 rtcp->SignalReadyToSend(rtcp);
1753 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1754 // channel are ready to send.
1755 EXPECT_TRUE(media_channel1_->ready_to_send());
1756
1757 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001758 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001760 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 EXPECT_TRUE(media_channel1_->ready_to_send());
1762
1763 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001764 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001766 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 EXPECT_TRUE(media_channel1_->ready_to_send());
1768 }
1769
1770 void TestOnReadyToSendWithRtcpMux() {
1771 CreateChannels(RTCP, RTCP);
1772 typename T::Content content;
1773 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1774 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1775 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001776 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1777 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1779 TransportChannel* rtp = channel1_->transport_channel();
1780 EXPECT_FALSE(media_channel1_->ready_to_send());
1781 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1782 // should trigger the MediaChannel's OnReadyToSend.
1783 rtp->SignalReadyToSend(rtp);
1784 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001785 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 EXPECT_FALSE(media_channel1_->ready_to_send());
1787 }
1788
1789 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001790 // TODO(pbos): Remove playout from all media channels and let renderers mute
1791 // themselves.
1792 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001793 cricket::FakeTransportController transport_controller1_;
1794 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 cricket::FakeMediaEngine media_engine_;
1796 // The media channels are owned by the voice channel objects below.
1797 typename T::MediaChannel* media_channel1_;
1798 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001799 rtc::scoped_ptr<typename T::Channel> channel1_;
1800 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 typename T::Content local_media_content1_;
1802 typename T::Content local_media_content2_;
1803 typename T::Content remote_media_content1_;
1804 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 // The RTP and RTCP packets to send in the tests.
1806 std::string rtp_packet_;
1807 std::string rtcp_packet_;
1808 int media_info_callbacks1_;
1809 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810};
1811
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812template<>
1813void ChannelTest<VoiceTraits>::CreateContent(
1814 int flags,
1815 const cricket::AudioCodec& audio_codec,
1816 const cricket::VideoCodec& video_codec,
1817 cricket::AudioContentDescription* audio) {
1818 audio->AddCodec(audio_codec);
1819 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1820 if (flags & SECURE) {
1821 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001822 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1823 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001824 }
1825}
1826
1827template<>
1828void ChannelTest<VoiceTraits>::CopyContent(
1829 const cricket::AudioContentDescription& source,
1830 cricket::AudioContentDescription* audio) {
1831 *audio = source;
1832}
1833
1834template<>
1835bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1836 const cricket::AudioCodec& c2) {
1837 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1838 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1839}
1840
Peter Boström0c4e06b2015-10-07 12:23:21 +02001841template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001843 uint32_t ssrc,
1844 int flags,
1845 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 audio->AddLegacyStream(ssrc);
1847}
1848
1849class VoiceChannelTest
1850 : public ChannelTest<VoiceTraits> {
1851 public:
solenberg1dd98f32015-09-10 01:57:14 -07001852 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001853 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001854 : Base(true,
1855 kPcmuFrame,
1856 sizeof(kPcmuFrame),
1857 kRtcpReport,
1858 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859};
1860
1861// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001862template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001864 rtc::Thread* thread,
1865 cricket::MediaEngineInterface* engine,
1866 cricket::FakeVideoMediaChannel* ch,
1867 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 bool rtcp) {
1869 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001870 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 if (!channel->Init()) {
1872 delete channel;
1873 channel = NULL;
1874 }
1875 return channel;
1876}
1877
1878// override to add 0 parameter
1879template<>
1880bool ChannelTest<VideoTraits>::AddStream1(int id) {
1881 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1882}
1883
1884template<>
1885void ChannelTest<VideoTraits>::CreateContent(
1886 int flags,
1887 const cricket::AudioCodec& audio_codec,
1888 const cricket::VideoCodec& video_codec,
1889 cricket::VideoContentDescription* video) {
1890 video->AddCodec(video_codec);
1891 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1892 if (flags & SECURE) {
1893 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001894 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1895 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 }
1897}
1898
1899template<>
1900void ChannelTest<VideoTraits>::CopyContent(
1901 const cricket::VideoContentDescription& source,
1902 cricket::VideoContentDescription* video) {
1903 *video = source;
1904}
1905
1906template<>
1907bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1908 const cricket::VideoCodec& c2) {
1909 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1910 c1.framerate == c2.framerate;
1911}
1912
Peter Boström0c4e06b2015-10-07 12:23:21 +02001913template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001915 uint32_t ssrc,
1916 int flags,
1917 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918 video->AddLegacyStream(ssrc);
1919}
1920
1921class VideoChannelTest
1922 : public ChannelTest<VideoTraits> {
1923 public:
solenberg1dd98f32015-09-10 01:57:14 -07001924 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001925 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001926 : Base(false,
1927 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001928 sizeof(kH264Packet),
1929 kRtcpReport,
1930 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001931};
1932
1933
1934// VoiceChannelTest
1935
1936TEST_F(VoiceChannelTest, TestInit) {
1937 Base::TestInit();
1938 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1939 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1940}
1941
1942TEST_F(VoiceChannelTest, TestSetContents) {
1943 Base::TestSetContents();
1944}
1945
1946TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1947 Base::TestSetContentsNullOffer();
1948}
1949
1950TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1951 Base::TestSetContentsRtcpMux();
1952}
1953
1954TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1955 Base::TestSetContentsRtcpMux();
1956}
1957
1958TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1959 Base::TestSetRemoteContentUpdate();
1960}
1961
1962TEST_F(VoiceChannelTest, TestStreams) {
1963 Base::TestStreams();
1964}
1965
1966TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1967 Base::TestUpdateStreamsInLocalContent();
1968}
1969
1970TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1971 Base::TestUpdateStreamsInRemoteContent();
1972}
1973
1974TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1975 Base::TestChangeStreamParamsInContent();
1976}
1977
1978TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1979 Base::TestPlayoutAndSendingStates();
1980}
1981
1982TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001983 CreateChannels(0, 0);
1984 // Test that we can Mute the default channel even though the sending SSRC
1985 // is unknown.
1986 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07001987 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001988 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1989 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001990 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1991
1992 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07001993 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001994
1995 SendInitiate();
1996 // After the local session description has been set, we can mute a stream
1997 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07001998 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001999 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2000 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002001 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002}
2003
2004TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2005 Base::TestMediaContentDirection();
2006}
2007
2008TEST_F(VoiceChannelTest, TestCallSetup) {
2009 Base::TestCallSetup();
2010}
2011
2012TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2013 Base::TestCallTeardownRtcpMux();
2014}
2015
2016TEST_F(VoiceChannelTest, SendRtpToRtp) {
2017 Base::SendRtpToRtp();
2018}
2019
2020TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2021 Base::SendNoRtcpToNoRtcp();
2022}
2023
2024TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2025 Base::SendNoRtcpToRtcp();
2026}
2027
2028TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2029 Base::SendRtcpToNoRtcp();
2030}
2031
2032TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2033 Base::SendRtcpToRtcp();
2034}
2035
2036TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2037 Base::SendRtcpMuxToRtcp();
2038}
2039
2040TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2041 Base::SendRtcpMuxToRtcpMux();
2042}
2043
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002044TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2045 Base::SendRequireRtcpMuxToRtcpMux();
2046}
2047
2048TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2049 Base::SendRtcpMuxToRequireRtcpMux();
2050}
2051
2052TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2053 Base::SendRequireRtcpMuxToRequireRtcpMux();
2054}
2055
2056TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2057 Base::SendRequireRtcpMuxToNoRtcpMux();
2058}
2059
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2061 Base::SendEarlyRtcpMuxToRtcp();
2062}
2063
2064TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2065 Base::SendEarlyRtcpMuxToRtcpMux();
2066}
2067
2068TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2069 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2070}
2071
2072TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2073 Base::SendSrtpToSrtp();
2074}
2075
2076TEST_F(VoiceChannelTest, SendSrtcpMux) {
2077 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2078}
2079
2080TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2081 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2082 Base::SendSrtpToSrtp(DTLS, 0);
2083}
2084
2085TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2086 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2087 Base::SendSrtpToSrtp(DTLS, DTLS);
2088}
2089
2090TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2091 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2092 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2093}
2094
2095TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2096 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2097}
2098
2099TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2100 Base::SendRtpToRtpOnThread();
2101}
2102
2103TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2104 Base::SendSrtpToSrtpOnThread();
2105}
2106
2107TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2108 Base::SendWithWritabilityLoss();
2109}
2110
2111TEST_F(VoiceChannelTest, TestMediaMonitor) {
2112 Base::TestMediaMonitor();
2113}
2114
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115// Test that InsertDtmf properly forwards to the media channel.
2116TEST_F(VoiceChannelTest, TestInsertDtmf) {
2117 CreateChannels(0, 0);
2118 EXPECT_TRUE(SendInitiate());
2119 EXPECT_TRUE(SendAccept());
2120 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2121
solenberg1d63dd02015-12-02 12:35:09 -08002122 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
2123 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
2124 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002126 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
solenberg1d63dd02015-12-02 12:35:09 -08002128 1, 3, 100));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002129 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
solenberg1d63dd02015-12-02 12:35:09 -08002130 2, 5, 110));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002131 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
solenberg1d63dd02015-12-02 12:35:09 -08002132 3, 7, 120));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133}
2134
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135TEST_F(VoiceChannelTest, TestSetContentFailure) {
2136 Base::TestSetContentFailure();
2137}
2138
2139TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2140 Base::TestSendTwoOffers();
2141}
2142
2143TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2144 Base::TestReceiveTwoOffers();
2145}
2146
2147TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2148 Base::TestSendPrAnswer();
2149}
2150
2151TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2152 Base::TestReceivePrAnswer();
2153}
2154
2155TEST_F(VoiceChannelTest, TestFlushRtcp) {
2156 Base::TestFlushRtcp();
2157}
2158
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002160 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161}
2162
2163TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2164 Base::TestOnReadyToSend();
2165}
2166
2167TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2168 Base::TestOnReadyToSendWithRtcpMux();
2169}
2170
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171// Test that we can scale the output volume properly for 1:1 calls.
2172TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2173 CreateChannels(RTCP, RTCP);
2174 EXPECT_TRUE(SendInitiate());
2175 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002176 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177
solenberg4bac9c52015-10-09 02:32:53 -07002178 // Default is (1.0).
2179 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2180 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002182 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183
solenberg4bac9c52015-10-09 02:32:53 -07002184 // Set scale to (1.5).
2185 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2186 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2187 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188
solenberg4bac9c52015-10-09 02:32:53 -07002189 // Set scale to (0).
2190 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2191 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2192 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193}
2194
2195// Test that we can scale the output volume properly for multiway calls.
2196TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2197 CreateChannels(RTCP, RTCP);
2198 EXPECT_TRUE(SendInitiate());
2199 EXPECT_TRUE(SendAccept());
2200 EXPECT_TRUE(AddStream1(1));
2201 EXPECT_TRUE(AddStream1(2));
2202
solenberg4bac9c52015-10-09 02:32:53 -07002203 double volume;
2204 // Default is (1.0).
2205 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2206 EXPECT_DOUBLE_EQ(1.0, volume);
2207 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2208 EXPECT_DOUBLE_EQ(1.0, volume);
2209 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2210 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002212 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213
solenberg4bac9c52015-10-09 02:32:53 -07002214 // Set scale to (1.5) for ssrc = 1.
2215 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2216 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2217 EXPECT_DOUBLE_EQ(1.5, volume);
2218 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2219 EXPECT_DOUBLE_EQ(1.0, volume);
2220 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2221 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222
solenberg4bac9c52015-10-09 02:32:53 -07002223 // Set scale to (0) for all ssrcs.
2224 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2225 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2226 EXPECT_DOUBLE_EQ(0.0, volume);
2227 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2228 EXPECT_DOUBLE_EQ(0.0, volume);
2229 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2230 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231}
2232
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002233TEST_F(VoiceChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002234 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235}
2236
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002237TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002238 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002239}
2240
2241TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002242 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002243}
2244
2245TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002246 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247}
2248
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249// VideoChannelTest
2250TEST_F(VideoChannelTest, TestInit) {
2251 Base::TestInit();
2252}
2253
2254TEST_F(VideoChannelTest, TestSetContents) {
2255 Base::TestSetContents();
2256}
2257
2258TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2259 Base::TestSetContentsNullOffer();
2260}
2261
2262TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2263 Base::TestSetContentsRtcpMux();
2264}
2265
2266TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2267 Base::TestSetContentsRtcpMux();
2268}
2269
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2271 Base::TestSetRemoteContentUpdate();
2272}
2273
2274TEST_F(VideoChannelTest, TestStreams) {
2275 Base::TestStreams();
2276}
2277
2278TEST_F(VideoChannelTest, TestScreencastEvents) {
2279 const int kTimeoutMs = 500;
2280 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 cricket::ScreencastEventCatcher catcher;
2282 channel1_->SignalScreencastWindowEvent.connect(
2283 &catcher,
2284 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002285
2286 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2287 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2288 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2289 ScreencastId(WindowId(0)));
2290 ASSERT_TRUE(screen_capturer != NULL);
2291
2292 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2293 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002295
2296 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002297 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002298
2299 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002300 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002301
2302 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002303 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002304
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306}
2307
2308TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2309 Base::TestUpdateStreamsInLocalContent();
2310}
2311
2312TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2313 Base::TestUpdateStreamsInRemoteContent();
2314}
2315
2316TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2317 Base::TestChangeStreamParamsInContent();
2318}
2319
2320TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2321 Base::TestPlayoutAndSendingStates();
2322}
2323
2324TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002325 CreateChannels(0, 0);
2326 // Test that we can Mute the default channel even though the sending SSRC
2327 // is unknown.
2328 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002329 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002330 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2331 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002332 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2333 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002334 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002335 SendInitiate();
2336 // After the local session description has been set, we can mute a stream
2337 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002338 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002339 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2340 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002341 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342}
2343
2344TEST_F(VideoChannelTest, TestMediaContentDirection) {
2345 Base::TestMediaContentDirection();
2346}
2347
2348TEST_F(VideoChannelTest, TestCallSetup) {
2349 Base::TestCallSetup();
2350}
2351
2352TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2353 Base::TestCallTeardownRtcpMux();
2354}
2355
2356TEST_F(VideoChannelTest, SendRtpToRtp) {
2357 Base::SendRtpToRtp();
2358}
2359
2360TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2361 Base::SendNoRtcpToNoRtcp();
2362}
2363
2364TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2365 Base::SendNoRtcpToRtcp();
2366}
2367
2368TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2369 Base::SendRtcpToNoRtcp();
2370}
2371
2372TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2373 Base::SendRtcpToRtcp();
2374}
2375
2376TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2377 Base::SendRtcpMuxToRtcp();
2378}
2379
2380TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2381 Base::SendRtcpMuxToRtcpMux();
2382}
2383
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002384TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2385 Base::SendRequireRtcpMuxToRtcpMux();
2386}
2387
2388TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2389 Base::SendRtcpMuxToRequireRtcpMux();
2390}
2391
2392TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2393 Base::SendRequireRtcpMuxToRequireRtcpMux();
2394}
2395
2396TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2397 Base::SendRequireRtcpMuxToNoRtcpMux();
2398}
2399
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2401 Base::SendEarlyRtcpMuxToRtcp();
2402}
2403
2404TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2405 Base::SendEarlyRtcpMuxToRtcpMux();
2406}
2407
2408TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2409 Base::SendSrtpToSrtp();
2410}
2411
2412TEST_F(VideoChannelTest, SendSrtpToRtp) {
2413 Base::SendSrtpToSrtp();
2414}
2415
2416TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2417 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2418 Base::SendSrtpToSrtp(DTLS, 0);
2419}
2420
2421TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2422 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2423 Base::SendSrtpToSrtp(DTLS, DTLS);
2424}
2425
2426TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2427 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2428 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2429}
2430
2431TEST_F(VideoChannelTest, SendSrtcpMux) {
2432 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2433}
2434
2435TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2436 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2437}
2438
2439TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2440 Base::SendRtpToRtpOnThread();
2441}
2442
2443TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2444 Base::SendSrtpToSrtpOnThread();
2445}
2446
2447TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2448 Base::SendWithWritabilityLoss();
2449}
2450
2451TEST_F(VideoChannelTest, TestMediaMonitor) {
2452 Base::TestMediaMonitor();
2453}
2454
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455TEST_F(VideoChannelTest, TestSetContentFailure) {
2456 Base::TestSetContentFailure();
2457}
2458
2459TEST_F(VideoChannelTest, TestSendTwoOffers) {
2460 Base::TestSendTwoOffers();
2461}
2462
2463TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2464 Base::TestReceiveTwoOffers();
2465}
2466
2467TEST_F(VideoChannelTest, TestSendPrAnswer) {
2468 Base::TestSendPrAnswer();
2469}
2470
2471TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2472 Base::TestReceivePrAnswer();
2473}
2474
2475TEST_F(VideoChannelTest, TestFlushRtcp) {
2476 Base::TestFlushRtcp();
2477}
2478
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002479TEST_F(VideoChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002480 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481}
2482
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002483TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002484 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002485}
2486
2487TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002488 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002489}
2490
2491TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002492 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493}
2494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002496 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497}
2498
2499TEST_F(VideoChannelTest, TestOnReadyToSend) {
2500 Base::TestOnReadyToSend();
2501}
2502
2503TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2504 Base::TestOnReadyToSendWithRtcpMux();
2505}
2506
2507TEST_F(VideoChannelTest, TestApplyViewRequest) {
2508 CreateChannels(0, 0);
2509 cricket::StreamParams stream2;
2510 stream2.id = "stream2";
2511 stream2.ssrcs.push_back(2222);
2512 local_media_content1_.AddStream(stream2);
2513
2514 EXPECT_TRUE(SendInitiate());
2515 EXPECT_TRUE(SendAccept());
2516
2517 cricket::VideoFormat send_format;
2518 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2519 EXPECT_EQ(640, send_format.width);
2520 EXPECT_EQ(400, send_format.height);
2521 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2522
2523 cricket::ViewRequest request;
2524 // stream1: 320x200x15; stream2: 0x0x0
2525 request.static_video_views.push_back(cricket::StaticVideoView(
2526 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2527 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2528 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2529 EXPECT_EQ(320, send_format.width);
2530 EXPECT_EQ(200, send_format.height);
2531 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2532 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2533 EXPECT_EQ(0, send_format.width);
2534 EXPECT_EQ(0, send_format.height);
2535
2536 // stream1: 160x100x8; stream2: 0x0x0
2537 request.static_video_views.clear();
2538 request.static_video_views.push_back(cricket::StaticVideoView(
2539 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2540 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2541 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2542 EXPECT_EQ(160, send_format.width);
2543 EXPECT_EQ(100, send_format.height);
2544 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2545
2546 // stream1: 0x0x0; stream2: 640x400x30
2547 request.static_video_views.clear();
2548 request.static_video_views.push_back(cricket::StaticVideoView(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002549 cricket::StreamSelector(std::string(), stream2.id), 640, 400, 30));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2551 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2552 EXPECT_EQ(0, send_format.width);
2553 EXPECT_EQ(0, send_format.height);
2554 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2555 EXPECT_EQ(640, send_format.width);
2556 EXPECT_EQ(400, send_format.height);
2557 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2558
2559 // stream1: 0x0x0; stream2: 0x0x0
2560 request.static_video_views.clear();
2561 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2562 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2563 EXPECT_EQ(0, send_format.width);
2564 EXPECT_EQ(0, send_format.height);
2565}
2566
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567
2568// DataChannelTest
2569
2570class DataChannelTest
2571 : public ChannelTest<DataTraits> {
2572 public:
2573 typedef ChannelTest<DataTraits>
2574 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002575 DataChannelTest()
2576 : Base(true,
2577 kDataPacket,
2578 sizeof(kDataPacket),
2579 kRtcpReport,
2580 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581};
2582
2583// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002584template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002586 rtc::Thread* thread,
2587 cricket::MediaEngineInterface* engine,
2588 cricket::FakeDataMediaChannel* ch,
2589 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590 bool rtcp) {
2591 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002592 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 if (!channel->Init()) {
2594 delete channel;
2595 channel = NULL;
2596 }
2597 return channel;
2598}
2599
2600template<>
2601void ChannelTest<DataTraits>::CreateContent(
2602 int flags,
2603 const cricket::AudioCodec& audio_codec,
2604 const cricket::VideoCodec& video_codec,
2605 cricket::DataContentDescription* data) {
2606 data->AddCodec(kGoogleDataCodec);
2607 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2608 if (flags & SECURE) {
2609 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002610 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2611 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 }
2613}
2614
2615template<>
2616void ChannelTest<DataTraits>::CopyContent(
2617 const cricket::DataContentDescription& source,
2618 cricket::DataContentDescription* data) {
2619 *data = source;
2620}
2621
2622template<>
2623bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2624 const cricket::DataCodec& c2) {
2625 return c1.name == c2.name;
2626}
2627
Peter Boström0c4e06b2015-10-07 12:23:21 +02002628template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002630 uint32_t ssrc,
2631 int flags,
2632 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 data->AddLegacyStream(ssrc);
2634}
2635
2636TEST_F(DataChannelTest, TestInit) {
2637 Base::TestInit();
2638 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2639}
2640
2641TEST_F(DataChannelTest, TestSetContents) {
2642 Base::TestSetContents();
2643}
2644
2645TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2646 Base::TestSetContentsNullOffer();
2647}
2648
2649TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2650 Base::TestSetContentsRtcpMux();
2651}
2652
2653TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2654 Base::TestSetRemoteContentUpdate();
2655}
2656
2657TEST_F(DataChannelTest, TestStreams) {
2658 Base::TestStreams();
2659}
2660
2661TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2662 Base::TestUpdateStreamsInLocalContent();
2663}
2664
2665TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2666 Base::TestUpdateStreamsInRemoteContent();
2667}
2668
2669TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2670 Base::TestChangeStreamParamsInContent();
2671}
2672
2673TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2674 Base::TestPlayoutAndSendingStates();
2675}
2676
2677TEST_F(DataChannelTest, TestMediaContentDirection) {
2678 Base::TestMediaContentDirection();
2679}
2680
2681TEST_F(DataChannelTest, TestCallSetup) {
2682 Base::TestCallSetup();
2683}
2684
2685TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2686 Base::TestCallTeardownRtcpMux();
2687}
2688
2689TEST_F(DataChannelTest, TestOnReadyToSend) {
2690 Base::TestOnReadyToSend();
2691}
2692
2693TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2694 Base::TestOnReadyToSendWithRtcpMux();
2695}
2696
2697TEST_F(DataChannelTest, SendRtpToRtp) {
2698 Base::SendRtpToRtp();
2699}
2700
2701TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2702 Base::SendNoRtcpToNoRtcp();
2703}
2704
2705TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2706 Base::SendNoRtcpToRtcp();
2707}
2708
2709TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2710 Base::SendRtcpToNoRtcp();
2711}
2712
2713TEST_F(DataChannelTest, SendRtcpToRtcp) {
2714 Base::SendRtcpToRtcp();
2715}
2716
2717TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2718 Base::SendRtcpMuxToRtcp();
2719}
2720
2721TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2722 Base::SendRtcpMuxToRtcpMux();
2723}
2724
2725TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2726 Base::SendEarlyRtcpMuxToRtcp();
2727}
2728
2729TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2730 Base::SendEarlyRtcpMuxToRtcpMux();
2731}
2732
2733TEST_F(DataChannelTest, SendSrtpToSrtp) {
2734 Base::SendSrtpToSrtp();
2735}
2736
2737TEST_F(DataChannelTest, SendSrtpToRtp) {
2738 Base::SendSrtpToSrtp();
2739}
2740
2741TEST_F(DataChannelTest, SendSrtcpMux) {
2742 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2743}
2744
2745TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2746 Base::SendRtpToRtpOnThread();
2747}
2748
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2750 Base::SendSrtpToSrtpOnThread();
2751}
2752
2753TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2754 Base::SendWithWritabilityLoss();
2755}
2756
2757TEST_F(DataChannelTest, TestMediaMonitor) {
2758 Base::TestMediaMonitor();
2759}
2760
2761TEST_F(DataChannelTest, TestSendData) {
2762 CreateChannels(0, 0);
2763 EXPECT_TRUE(SendInitiate());
2764 EXPECT_TRUE(SendAccept());
2765
2766 cricket::SendDataParams params;
2767 params.ssrc = 42;
2768 unsigned char data[] = {
2769 'f', 'o', 'o'
2770 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002771 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 cricket::SendDataResult result;
2773 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2774 EXPECT_EQ(params.ssrc,
2775 media_channel1_->last_sent_data_params().ssrc);
2776 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2777}
2778
2779// TODO(pthatcher): TestSetReceiver?