blob: 28ab3d294aaa7d44654750a064dcb7e2e2f65816 [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));
1477 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1478 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1479 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1480 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1481 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1482 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1483
1484 // Both channels can receive pl_type1 only.
1485 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1486 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1487 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1488 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1489 EXPECT_TRUE(CheckNoRtp1());
1490 EXPECT_TRUE(CheckNoRtp2());
1491
1492 // RTCP test
1493 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1494 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1495 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1496 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1497
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1499 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1501 EXPECT_TRUE(CheckNoRtcp1());
1502 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1503 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001505 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1506 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1509 }
1510
1511 // Test that the media monitor can be run and gives timely callbacks.
1512 void TestMediaMonitor() {
1513 static const int kTimeout = 500;
1514 CreateChannels(0, 0);
1515 EXPECT_TRUE(SendInitiate());
1516 EXPECT_TRUE(SendAccept());
1517 channel1_->StartMediaMonitor(100);
1518 channel2_->StartMediaMonitor(100);
1519 // Ensure we get callbacks and stop.
1520 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1521 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1522 channel1_->StopMediaMonitor();
1523 channel2_->StopMediaMonitor();
1524 // Ensure a restart of a stopped monitor works.
1525 channel1_->StartMediaMonitor(100);
1526 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1527 channel1_->StopMediaMonitor();
1528 // Ensure stopping a stopped monitor is OK.
1529 channel1_->StopMediaMonitor();
1530 }
1531
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532 void TestSetContentFailure() {
1533 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534
Peter Thatchera6d24442015-07-09 21:26:36 -07001535 auto sdesc = cricket::SessionDescription();
1536 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1537 new cricket::AudioContentDescription());
1538 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1539 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540
Peter Thatchera6d24442015-07-09 21:26:36 -07001541 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001543 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1544 &sdesc, cricket::CA_OFFER, &err));
1545 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1546 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001549 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1550 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001552 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1553 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 }
1555
1556 void TestSendTwoOffers() {
1557 CreateChannels(0, 0);
1558
Peter Thatchera6d24442015-07-09 21:26:36 -07001559 std::string err;
1560 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1561 CreateSessionDescriptionWithStream(1));
1562 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1563 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1565
Peter Thatchera6d24442015-07-09 21:26:36 -07001566 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1567 CreateSessionDescriptionWithStream(2));
1568 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1569 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1571 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1572 }
1573
1574 void TestReceiveTwoOffers() {
1575 CreateChannels(0, 0);
1576
Peter Thatchera6d24442015-07-09 21:26:36 -07001577 std::string err;
1578 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1579 CreateSessionDescriptionWithStream(1));
1580 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1581 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1583
Peter Thatchera6d24442015-07-09 21:26:36 -07001584 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1585 CreateSessionDescriptionWithStream(2));
1586 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1587 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1589 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1590 }
1591
1592 void TestSendPrAnswer() {
1593 CreateChannels(0, 0);
1594
Peter Thatchera6d24442015-07-09 21:26:36 -07001595 std::string err;
1596 // Receive offer
1597 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1598 CreateSessionDescriptionWithStream(1));
1599 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1600 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1602
Peter Thatchera6d24442015-07-09 21:26:36 -07001603 // Send PR answer
1604 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1605 CreateSessionDescriptionWithStream(2));
1606 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1607 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1609 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1610
Peter Thatchera6d24442015-07-09 21:26:36 -07001611 // Send answer
1612 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1613 CreateSessionDescriptionWithStream(3));
1614 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1615 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1617 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1618 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1619 }
1620
1621 void TestReceivePrAnswer() {
1622 CreateChannels(0, 0);
1623
Peter Thatchera6d24442015-07-09 21:26:36 -07001624 std::string err;
1625 // Send offer
1626 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1627 CreateSessionDescriptionWithStream(1));
1628 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1629 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1631
Peter Thatchera6d24442015-07-09 21:26:36 -07001632 // Receive PR answer
1633 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1634 CreateSessionDescriptionWithStream(2));
1635 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1636 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1638 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1639
Peter Thatchera6d24442015-07-09 21:26:36 -07001640 // Receive answer
1641 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1642 CreateSessionDescriptionWithStream(3));
1643 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1644 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1646 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1647 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1648 }
1649
1650 void TestFlushRtcp() {
1651 bool send_rtcp1;
1652
1653 CreateChannels(RTCP, RTCP);
1654 EXPECT_TRUE(SendInitiate());
1655 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001656 ASSERT_TRUE(GetTransport1());
1657 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 EXPECT_EQ(2U, GetTransport1()->channels().size());
1659 EXPECT_EQ(2U, GetTransport2()->channels().size());
1660
1661 // Send RTCP1 from a different thread.
1662 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1663 EXPECT_TRUE(send_rtcp1);
1664 // The sending message is only posted. channel2_ should be empty.
1665 EXPECT_TRUE(CheckNoRtcp2());
1666
1667 // When channel1_ is deleted, the RTCP packet should be sent out to
1668 // channel2_.
1669 channel1_.reset();
1670 EXPECT_TRUE(CheckRtcp2());
1671 }
1672
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001673 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001674 struct SrtpErrorHandler : public sigslot::has_slots<> {
1675 SrtpErrorHandler() :
1676 mode_(cricket::SrtpFilter::UNPROTECT),
1677 error_(cricket::SrtpFilter::ERROR_NONE) {}
1678 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1679 cricket::SrtpFilter::Error error) {
1680 mode_ = mode;
1681 error_ = error;
1682 }
1683 cricket::SrtpFilter::Mode mode_;
1684 cricket::SrtpFilter::Error error_;
1685 } error_handler;
1686
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001687 // For Audio, only pl_type 0 is added to the bundle filter.
1688 // For Video, only pl_type 97 is added to the bundle filter.
1689 // So we need to pass in pl_type so that the packet can pass through
1690 // the bundle filter before it can be processed by the srtp filter.
1691 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001692 unsigned const char kBadPacket[] = {0x84,
1693 static_cast<unsigned char>(pl_type),
1694 0x00,
1695 0x01,
1696 0x00,
1697 0x00,
1698 0x00,
1699 0x00,
1700 0x00,
1701 0x00,
1702 0x00,
1703 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1705 EXPECT_FALSE(channel1_->secure());
1706 EXPECT_FALSE(channel2_->secure());
1707 EXPECT_TRUE(SendInitiate());
1708 EXPECT_TRUE(SendAccept());
1709 EXPECT_TRUE(channel1_->secure());
1710 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001711 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001712 channel2_->srtp_filter()->SignalSrtpError.connect(
1713 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714
1715 // Testing failures in sending packets.
stefanc1aeaf02015-10-15 07:26:07 -07001716 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1717 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001719 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1720 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1721 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001722 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1723 // The next 250 ms failures will not trigger an error.
stefanc1aeaf02015-10-15 07:26:07 -07001724 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1725 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001727 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001728 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001729 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1730 // Wait for a little more - the error will be triggered again.
1731 rtc::Thread::Current()->ProcessMessages(200);
stefanc1aeaf02015-10-15 07:26:07 -07001732 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1733 rtc::PacketOptions()));
solenberg5b14b422015-10-01 04:10:31 -07001734 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1735 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736
1737 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001738 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001739 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001740
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 cricket::TransportChannel* transport_channel =
1742 channel2_->transport_channel();
1743 transport_channel->SignalReadPacket(
1744 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001745 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001746 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1747 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 }
1749
1750 void TestOnReadyToSend() {
1751 CreateChannels(RTCP, RTCP);
1752 TransportChannel* rtp = channel1_->transport_channel();
1753 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1754 EXPECT_FALSE(media_channel1_->ready_to_send());
1755 rtp->SignalReadyToSend(rtp);
1756 EXPECT_FALSE(media_channel1_->ready_to_send());
1757 rtcp->SignalReadyToSend(rtcp);
1758 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1759 // channel are ready to send.
1760 EXPECT_TRUE(media_channel1_->ready_to_send());
1761
1762 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001763 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001765 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 EXPECT_TRUE(media_channel1_->ready_to_send());
1767
1768 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001769 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001771 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 EXPECT_TRUE(media_channel1_->ready_to_send());
1773 }
1774
1775 void TestOnReadyToSendWithRtcpMux() {
1776 CreateChannels(RTCP, RTCP);
1777 typename T::Content content;
1778 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1779 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1780 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001781 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1782 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1784 TransportChannel* rtp = channel1_->transport_channel();
1785 EXPECT_FALSE(media_channel1_->ready_to_send());
1786 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1787 // should trigger the MediaChannel's OnReadyToSend.
1788 rtp->SignalReadyToSend(rtp);
1789 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001790 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 EXPECT_FALSE(media_channel1_->ready_to_send());
1792 }
1793
1794 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001795 // TODO(pbos): Remove playout from all media channels and let renderers mute
1796 // themselves.
1797 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001798 cricket::FakeTransportController transport_controller1_;
1799 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 cricket::FakeMediaEngine media_engine_;
1801 // The media channels are owned by the voice channel objects below.
1802 typename T::MediaChannel* media_channel1_;
1803 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001804 rtc::scoped_ptr<typename T::Channel> channel1_;
1805 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 typename T::Content local_media_content1_;
1807 typename T::Content local_media_content2_;
1808 typename T::Content remote_media_content1_;
1809 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 // The RTP and RTCP packets to send in the tests.
1811 std::string rtp_packet_;
1812 std::string rtcp_packet_;
1813 int media_info_callbacks1_;
1814 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001815};
1816
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817template<>
1818void ChannelTest<VoiceTraits>::CreateContent(
1819 int flags,
1820 const cricket::AudioCodec& audio_codec,
1821 const cricket::VideoCodec& video_codec,
1822 cricket::AudioContentDescription* audio) {
1823 audio->AddCodec(audio_codec);
1824 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1825 if (flags & SECURE) {
1826 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001827 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1828 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 }
1830}
1831
1832template<>
1833void ChannelTest<VoiceTraits>::CopyContent(
1834 const cricket::AudioContentDescription& source,
1835 cricket::AudioContentDescription* audio) {
1836 *audio = source;
1837}
1838
1839template<>
1840bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1841 const cricket::AudioCodec& c2) {
1842 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1843 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1844}
1845
Peter Boström0c4e06b2015-10-07 12:23:21 +02001846template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001848 uint32_t ssrc,
1849 int flags,
1850 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 audio->AddLegacyStream(ssrc);
1852}
1853
1854class VoiceChannelTest
1855 : public ChannelTest<VoiceTraits> {
1856 public:
solenberg1dd98f32015-09-10 01:57:14 -07001857 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001858 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001859 : Base(true,
1860 kPcmuFrame,
1861 sizeof(kPcmuFrame),
1862 kRtcpReport,
1863 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864};
1865
1866// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001867template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001869 rtc::Thread* thread,
1870 cricket::MediaEngineInterface* engine,
1871 cricket::FakeVideoMediaChannel* ch,
1872 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001873 bool rtcp) {
1874 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001875 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 if (!channel->Init()) {
1877 delete channel;
1878 channel = NULL;
1879 }
1880 return channel;
1881}
1882
1883// override to add 0 parameter
1884template<>
1885bool ChannelTest<VideoTraits>::AddStream1(int id) {
1886 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1887}
1888
1889template<>
1890void ChannelTest<VideoTraits>::CreateContent(
1891 int flags,
1892 const cricket::AudioCodec& audio_codec,
1893 const cricket::VideoCodec& video_codec,
1894 cricket::VideoContentDescription* video) {
1895 video->AddCodec(video_codec);
1896 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1897 if (flags & SECURE) {
1898 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001899 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1900 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 }
1902}
1903
1904template<>
1905void ChannelTest<VideoTraits>::CopyContent(
1906 const cricket::VideoContentDescription& source,
1907 cricket::VideoContentDescription* video) {
1908 *video = source;
1909}
1910
1911template<>
1912bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1913 const cricket::VideoCodec& c2) {
1914 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1915 c1.framerate == c2.framerate;
1916}
1917
Peter Boström0c4e06b2015-10-07 12:23:21 +02001918template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001920 uint32_t ssrc,
1921 int flags,
1922 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923 video->AddLegacyStream(ssrc);
1924}
1925
1926class VideoChannelTest
1927 : public ChannelTest<VideoTraits> {
1928 public:
solenberg1dd98f32015-09-10 01:57:14 -07001929 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001930 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001931 : Base(false,
1932 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001933 sizeof(kH264Packet),
1934 kRtcpReport,
1935 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936};
1937
1938
1939// VoiceChannelTest
1940
1941TEST_F(VoiceChannelTest, TestInit) {
1942 Base::TestInit();
1943 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1944 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1945}
1946
1947TEST_F(VoiceChannelTest, TestSetContents) {
1948 Base::TestSetContents();
1949}
1950
1951TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1952 Base::TestSetContentsNullOffer();
1953}
1954
1955TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1956 Base::TestSetContentsRtcpMux();
1957}
1958
1959TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1960 Base::TestSetContentsRtcpMux();
1961}
1962
1963TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1964 Base::TestSetRemoteContentUpdate();
1965}
1966
1967TEST_F(VoiceChannelTest, TestStreams) {
1968 Base::TestStreams();
1969}
1970
1971TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1972 Base::TestUpdateStreamsInLocalContent();
1973}
1974
1975TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1976 Base::TestUpdateStreamsInRemoteContent();
1977}
1978
1979TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1980 Base::TestChangeStreamParamsInContent();
1981}
1982
1983TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1984 Base::TestPlayoutAndSendingStates();
1985}
1986
1987TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001988 CreateChannels(0, 0);
1989 // Test that we can Mute the default channel even though the sending SSRC
1990 // is unknown.
1991 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07001992 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001993 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1994 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001995 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1996
1997 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07001998 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001999
2000 SendInitiate();
2001 // After the local session description has been set, we can mute a stream
2002 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002003 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002004 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2005 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002006 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007}
2008
2009TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2010 Base::TestMediaContentDirection();
2011}
2012
2013TEST_F(VoiceChannelTest, TestCallSetup) {
2014 Base::TestCallSetup();
2015}
2016
2017TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2018 Base::TestCallTeardownRtcpMux();
2019}
2020
2021TEST_F(VoiceChannelTest, SendRtpToRtp) {
2022 Base::SendRtpToRtp();
2023}
2024
2025TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2026 Base::SendNoRtcpToNoRtcp();
2027}
2028
2029TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2030 Base::SendNoRtcpToRtcp();
2031}
2032
2033TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2034 Base::SendRtcpToNoRtcp();
2035}
2036
2037TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2038 Base::SendRtcpToRtcp();
2039}
2040
2041TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2042 Base::SendRtcpMuxToRtcp();
2043}
2044
2045TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2046 Base::SendRtcpMuxToRtcpMux();
2047}
2048
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002049TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2050 Base::SendRequireRtcpMuxToRtcpMux();
2051}
2052
2053TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2054 Base::SendRtcpMuxToRequireRtcpMux();
2055}
2056
2057TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2058 Base::SendRequireRtcpMuxToRequireRtcpMux();
2059}
2060
2061TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2062 Base::SendRequireRtcpMuxToNoRtcpMux();
2063}
2064
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2066 Base::SendEarlyRtcpMuxToRtcp();
2067}
2068
2069TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2070 Base::SendEarlyRtcpMuxToRtcpMux();
2071}
2072
2073TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2074 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2075}
2076
2077TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2078 Base::SendSrtpToSrtp();
2079}
2080
2081TEST_F(VoiceChannelTest, SendSrtcpMux) {
2082 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2083}
2084
2085TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2086 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2087 Base::SendSrtpToSrtp(DTLS, 0);
2088}
2089
2090TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2091 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2092 Base::SendSrtpToSrtp(DTLS, DTLS);
2093}
2094
2095TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2096 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2097 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2098}
2099
2100TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2101 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2102}
2103
2104TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2105 Base::SendRtpToRtpOnThread();
2106}
2107
2108TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2109 Base::SendSrtpToSrtpOnThread();
2110}
2111
2112TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2113 Base::SendWithWritabilityLoss();
2114}
2115
2116TEST_F(VoiceChannelTest, TestMediaMonitor) {
2117 Base::TestMediaMonitor();
2118}
2119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120// Test that PressDTMF properly forwards to the media channel.
2121TEST_F(VoiceChannelTest, TestDtmf) {
2122 CreateChannels(0, 0);
2123 EXPECT_TRUE(SendInitiate());
2124 EXPECT_TRUE(SendAccept());
2125 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2126
2127 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2128 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2129
2130 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2131 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2132 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2133 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2134 0, 8, 160, cricket::DF_SEND));
2135}
2136
2137// Test that InsertDtmf properly forwards to the media channel.
2138TEST_F(VoiceChannelTest, TestInsertDtmf) {
2139 CreateChannels(0, 0);
2140 EXPECT_TRUE(SendInitiate());
2141 EXPECT_TRUE(SendAccept());
2142 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2143
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2145 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2146 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2147 cricket::DF_PLAY | cricket::DF_SEND));
2148
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002149 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002152 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002154 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2156}
2157
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158TEST_F(VoiceChannelTest, TestSetContentFailure) {
2159 Base::TestSetContentFailure();
2160}
2161
2162TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2163 Base::TestSendTwoOffers();
2164}
2165
2166TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2167 Base::TestReceiveTwoOffers();
2168}
2169
2170TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2171 Base::TestSendPrAnswer();
2172}
2173
2174TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2175 Base::TestReceivePrAnswer();
2176}
2177
2178TEST_F(VoiceChannelTest, TestFlushRtcp) {
2179 Base::TestFlushRtcp();
2180}
2181
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002183 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184}
2185
2186TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2187 Base::TestOnReadyToSend();
2188}
2189
2190TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2191 Base::TestOnReadyToSendWithRtcpMux();
2192}
2193
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194// Test that we can scale the output volume properly for 1:1 calls.
2195TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2196 CreateChannels(RTCP, RTCP);
2197 EXPECT_TRUE(SendInitiate());
2198 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002199 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002200
solenberg4bac9c52015-10-09 02:32:53 -07002201 // Default is (1.0).
2202 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2203 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002205 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206
solenberg4bac9c52015-10-09 02:32:53 -07002207 // Set scale to (1.5).
2208 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2209 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2210 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211
solenberg4bac9c52015-10-09 02:32:53 -07002212 // Set scale to (0).
2213 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2214 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2215 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216}
2217
2218// Test that we can scale the output volume properly for multiway calls.
2219TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2220 CreateChannels(RTCP, RTCP);
2221 EXPECT_TRUE(SendInitiate());
2222 EXPECT_TRUE(SendAccept());
2223 EXPECT_TRUE(AddStream1(1));
2224 EXPECT_TRUE(AddStream1(2));
2225
solenberg4bac9c52015-10-09 02:32:53 -07002226 double volume;
2227 // Default is (1.0).
2228 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2229 EXPECT_DOUBLE_EQ(1.0, volume);
2230 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2231 EXPECT_DOUBLE_EQ(1.0, volume);
2232 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2233 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002235 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236
solenberg4bac9c52015-10-09 02:32:53 -07002237 // Set scale to (1.5) for ssrc = 1.
2238 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2239 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2240 EXPECT_DOUBLE_EQ(1.5, volume);
2241 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2242 EXPECT_DOUBLE_EQ(1.0, volume);
2243 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2244 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245
solenberg4bac9c52015-10-09 02:32:53 -07002246 // Set scale to (0) for all ssrcs.
2247 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2248 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2249 EXPECT_DOUBLE_EQ(0.0, volume);
2250 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2251 EXPECT_DOUBLE_EQ(0.0, volume);
2252 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2253 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254}
2255
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002256TEST_F(VoiceChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002257 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258}
2259
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002260TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002261 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002262}
2263
2264TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002265 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002266}
2267
2268TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002269 Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002270}
2271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272// VideoChannelTest
2273TEST_F(VideoChannelTest, TestInit) {
2274 Base::TestInit();
2275}
2276
2277TEST_F(VideoChannelTest, TestSetContents) {
2278 Base::TestSetContents();
2279}
2280
2281TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2282 Base::TestSetContentsNullOffer();
2283}
2284
2285TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2286 Base::TestSetContentsRtcpMux();
2287}
2288
2289TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2290 Base::TestSetContentsRtcpMux();
2291}
2292
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2294 Base::TestSetRemoteContentUpdate();
2295}
2296
2297TEST_F(VideoChannelTest, TestStreams) {
2298 Base::TestStreams();
2299}
2300
2301TEST_F(VideoChannelTest, TestScreencastEvents) {
2302 const int kTimeoutMs = 500;
2303 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 cricket::ScreencastEventCatcher catcher;
2305 channel1_->SignalScreencastWindowEvent.connect(
2306 &catcher,
2307 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002308
2309 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2310 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2311 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2312 ScreencastId(WindowId(0)));
2313 ASSERT_TRUE(screen_capturer != NULL);
2314
2315 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2316 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002318
2319 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002320 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002321
2322 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002323 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002324
2325 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002326 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002327
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329}
2330
2331TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2332 Base::TestUpdateStreamsInLocalContent();
2333}
2334
2335TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2336 Base::TestUpdateStreamsInRemoteContent();
2337}
2338
2339TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2340 Base::TestChangeStreamParamsInContent();
2341}
2342
2343TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2344 Base::TestPlayoutAndSendingStates();
2345}
2346
2347TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002348 CreateChannels(0, 0);
2349 // Test that we can Mute the default channel even though the sending SSRC
2350 // is unknown.
2351 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002352 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002353 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2354 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002355 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2356 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002357 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002358 SendInitiate();
2359 // After the local session description has been set, we can mute a stream
2360 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002361 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002362 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2363 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002364 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365}
2366
2367TEST_F(VideoChannelTest, TestMediaContentDirection) {
2368 Base::TestMediaContentDirection();
2369}
2370
2371TEST_F(VideoChannelTest, TestCallSetup) {
2372 Base::TestCallSetup();
2373}
2374
2375TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2376 Base::TestCallTeardownRtcpMux();
2377}
2378
2379TEST_F(VideoChannelTest, SendRtpToRtp) {
2380 Base::SendRtpToRtp();
2381}
2382
2383TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2384 Base::SendNoRtcpToNoRtcp();
2385}
2386
2387TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2388 Base::SendNoRtcpToRtcp();
2389}
2390
2391TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2392 Base::SendRtcpToNoRtcp();
2393}
2394
2395TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2396 Base::SendRtcpToRtcp();
2397}
2398
2399TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2400 Base::SendRtcpMuxToRtcp();
2401}
2402
2403TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2404 Base::SendRtcpMuxToRtcpMux();
2405}
2406
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002407TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2408 Base::SendRequireRtcpMuxToRtcpMux();
2409}
2410
2411TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2412 Base::SendRtcpMuxToRequireRtcpMux();
2413}
2414
2415TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2416 Base::SendRequireRtcpMuxToRequireRtcpMux();
2417}
2418
2419TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2420 Base::SendRequireRtcpMuxToNoRtcpMux();
2421}
2422
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2424 Base::SendEarlyRtcpMuxToRtcp();
2425}
2426
2427TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2428 Base::SendEarlyRtcpMuxToRtcpMux();
2429}
2430
2431TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2432 Base::SendSrtpToSrtp();
2433}
2434
2435TEST_F(VideoChannelTest, SendSrtpToRtp) {
2436 Base::SendSrtpToSrtp();
2437}
2438
2439TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2440 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2441 Base::SendSrtpToSrtp(DTLS, 0);
2442}
2443
2444TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2445 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2446 Base::SendSrtpToSrtp(DTLS, DTLS);
2447}
2448
2449TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2450 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2451 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2452}
2453
2454TEST_F(VideoChannelTest, SendSrtcpMux) {
2455 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2456}
2457
2458TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2459 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2460}
2461
2462TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2463 Base::SendRtpToRtpOnThread();
2464}
2465
2466TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2467 Base::SendSrtpToSrtpOnThread();
2468}
2469
2470TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2471 Base::SendWithWritabilityLoss();
2472}
2473
2474TEST_F(VideoChannelTest, TestMediaMonitor) {
2475 Base::TestMediaMonitor();
2476}
2477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478TEST_F(VideoChannelTest, TestSetContentFailure) {
2479 Base::TestSetContentFailure();
2480}
2481
2482TEST_F(VideoChannelTest, TestSendTwoOffers) {
2483 Base::TestSendTwoOffers();
2484}
2485
2486TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2487 Base::TestReceiveTwoOffers();
2488}
2489
2490TEST_F(VideoChannelTest, TestSendPrAnswer) {
2491 Base::TestSendPrAnswer();
2492}
2493
2494TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2495 Base::TestReceivePrAnswer();
2496}
2497
2498TEST_F(VideoChannelTest, TestFlushRtcp) {
2499 Base::TestFlushRtcp();
2500}
2501
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002502TEST_F(VideoChannelTest, SendBundleToBundle) {
tfarina5237aaf2015-11-10 23:44:30 -08002503 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504}
2505
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002506TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002507 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002508}
2509
2510TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
tfarina5237aaf2015-11-10 23:44:30 -08002511 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002512}
2513
2514TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
tfarina5237aaf2015-11-10 23:44:30 -08002515 Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516}
2517
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002519 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520}
2521
2522TEST_F(VideoChannelTest, TestOnReadyToSend) {
2523 Base::TestOnReadyToSend();
2524}
2525
2526TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2527 Base::TestOnReadyToSendWithRtcpMux();
2528}
2529
2530TEST_F(VideoChannelTest, TestApplyViewRequest) {
2531 CreateChannels(0, 0);
2532 cricket::StreamParams stream2;
2533 stream2.id = "stream2";
2534 stream2.ssrcs.push_back(2222);
2535 local_media_content1_.AddStream(stream2);
2536
2537 EXPECT_TRUE(SendInitiate());
2538 EXPECT_TRUE(SendAccept());
2539
2540 cricket::VideoFormat send_format;
2541 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2542 EXPECT_EQ(640, send_format.width);
2543 EXPECT_EQ(400, send_format.height);
2544 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2545
2546 cricket::ViewRequest request;
2547 // stream1: 320x200x15; stream2: 0x0x0
2548 request.static_video_views.push_back(cricket::StaticVideoView(
2549 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2550 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2551 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2552 EXPECT_EQ(320, send_format.width);
2553 EXPECT_EQ(200, send_format.height);
2554 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2555 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2556 EXPECT_EQ(0, send_format.width);
2557 EXPECT_EQ(0, send_format.height);
2558
2559 // stream1: 160x100x8; stream2: 0x0x0
2560 request.static_video_views.clear();
2561 request.static_video_views.push_back(cricket::StaticVideoView(
2562 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2563 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2564 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2565 EXPECT_EQ(160, send_format.width);
2566 EXPECT_EQ(100, send_format.height);
2567 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2568
2569 // stream1: 0x0x0; stream2: 640x400x30
2570 request.static_video_views.clear();
2571 request.static_video_views.push_back(cricket::StaticVideoView(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002572 cricket::StreamSelector(std::string(), stream2.id), 640, 400, 30));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2574 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2575 EXPECT_EQ(0, send_format.width);
2576 EXPECT_EQ(0, send_format.height);
2577 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2578 EXPECT_EQ(640, send_format.width);
2579 EXPECT_EQ(400, send_format.height);
2580 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2581
2582 // stream1: 0x0x0; stream2: 0x0x0
2583 request.static_video_views.clear();
2584 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2585 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2586 EXPECT_EQ(0, send_format.width);
2587 EXPECT_EQ(0, send_format.height);
2588}
2589
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002590
2591// DataChannelTest
2592
2593class DataChannelTest
2594 : public ChannelTest<DataTraits> {
2595 public:
2596 typedef ChannelTest<DataTraits>
2597 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002598 DataChannelTest()
2599 : Base(true,
2600 kDataPacket,
2601 sizeof(kDataPacket),
2602 kRtcpReport,
2603 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604};
2605
2606// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002607template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002609 rtc::Thread* thread,
2610 cricket::MediaEngineInterface* engine,
2611 cricket::FakeDataMediaChannel* ch,
2612 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 bool rtcp) {
2614 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002615 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 if (!channel->Init()) {
2617 delete channel;
2618 channel = NULL;
2619 }
2620 return channel;
2621}
2622
2623template<>
2624void ChannelTest<DataTraits>::CreateContent(
2625 int flags,
2626 const cricket::AudioCodec& audio_codec,
2627 const cricket::VideoCodec& video_codec,
2628 cricket::DataContentDescription* data) {
2629 data->AddCodec(kGoogleDataCodec);
2630 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2631 if (flags & SECURE) {
2632 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002633 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2634 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 }
2636}
2637
2638template<>
2639void ChannelTest<DataTraits>::CopyContent(
2640 const cricket::DataContentDescription& source,
2641 cricket::DataContentDescription* data) {
2642 *data = source;
2643}
2644
2645template<>
2646bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2647 const cricket::DataCodec& c2) {
2648 return c1.name == c2.name;
2649}
2650
Peter Boström0c4e06b2015-10-07 12:23:21 +02002651template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002653 uint32_t ssrc,
2654 int flags,
2655 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 data->AddLegacyStream(ssrc);
2657}
2658
2659TEST_F(DataChannelTest, TestInit) {
2660 Base::TestInit();
2661 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2662}
2663
2664TEST_F(DataChannelTest, TestSetContents) {
2665 Base::TestSetContents();
2666}
2667
2668TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2669 Base::TestSetContentsNullOffer();
2670}
2671
2672TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2673 Base::TestSetContentsRtcpMux();
2674}
2675
2676TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2677 Base::TestSetRemoteContentUpdate();
2678}
2679
2680TEST_F(DataChannelTest, TestStreams) {
2681 Base::TestStreams();
2682}
2683
2684TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2685 Base::TestUpdateStreamsInLocalContent();
2686}
2687
2688TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2689 Base::TestUpdateStreamsInRemoteContent();
2690}
2691
2692TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2693 Base::TestChangeStreamParamsInContent();
2694}
2695
2696TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2697 Base::TestPlayoutAndSendingStates();
2698}
2699
2700TEST_F(DataChannelTest, TestMediaContentDirection) {
2701 Base::TestMediaContentDirection();
2702}
2703
2704TEST_F(DataChannelTest, TestCallSetup) {
2705 Base::TestCallSetup();
2706}
2707
2708TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2709 Base::TestCallTeardownRtcpMux();
2710}
2711
2712TEST_F(DataChannelTest, TestOnReadyToSend) {
2713 Base::TestOnReadyToSend();
2714}
2715
2716TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2717 Base::TestOnReadyToSendWithRtcpMux();
2718}
2719
2720TEST_F(DataChannelTest, SendRtpToRtp) {
2721 Base::SendRtpToRtp();
2722}
2723
2724TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2725 Base::SendNoRtcpToNoRtcp();
2726}
2727
2728TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2729 Base::SendNoRtcpToRtcp();
2730}
2731
2732TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2733 Base::SendRtcpToNoRtcp();
2734}
2735
2736TEST_F(DataChannelTest, SendRtcpToRtcp) {
2737 Base::SendRtcpToRtcp();
2738}
2739
2740TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2741 Base::SendRtcpMuxToRtcp();
2742}
2743
2744TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2745 Base::SendRtcpMuxToRtcpMux();
2746}
2747
2748TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2749 Base::SendEarlyRtcpMuxToRtcp();
2750}
2751
2752TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2753 Base::SendEarlyRtcpMuxToRtcpMux();
2754}
2755
2756TEST_F(DataChannelTest, SendSrtpToSrtp) {
2757 Base::SendSrtpToSrtp();
2758}
2759
2760TEST_F(DataChannelTest, SendSrtpToRtp) {
2761 Base::SendSrtpToSrtp();
2762}
2763
2764TEST_F(DataChannelTest, SendSrtcpMux) {
2765 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2766}
2767
2768TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2769 Base::SendRtpToRtpOnThread();
2770}
2771
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2773 Base::SendSrtpToSrtpOnThread();
2774}
2775
2776TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2777 Base::SendWithWritabilityLoss();
2778}
2779
2780TEST_F(DataChannelTest, TestMediaMonitor) {
2781 Base::TestMediaMonitor();
2782}
2783
2784TEST_F(DataChannelTest, TestSendData) {
2785 CreateChannels(0, 0);
2786 EXPECT_TRUE(SendInitiate());
2787 EXPECT_TRUE(SendAccept());
2788
2789 cricket::SendDataParams params;
2790 params.ssrc = 42;
2791 unsigned char data[] = {
2792 'f', 'o', 'o'
2793 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002794 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002795 cricket::SendDataResult result;
2796 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2797 EXPECT_EQ(params.ssrc,
2798 media_channel1_->last_sent_data_params().ssrc);
2799 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2800}
2801
2802// TODO(pthatcher): TestSetReceiver?