blob: b861d0a4efee8f76f6ba21073a4bb368581e8231 [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"
deadbeefcbecd352015-09-23 11:50:27 -070036#include "webrtc/p2p/base/faketransportcontroller.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/session/media/channel.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000038#include "webrtc/base/fileutils.h"
39#include "webrtc/base/gunit.h"
40#include "webrtc/base/helpers.h"
41#include "webrtc/base/logging.h"
42#include "webrtc/base/pathutils.h"
43#include "webrtc/base/signalthread.h"
44#include "webrtc/base/ssladapter.h"
45#include "webrtc/base/sslidentity.h"
46#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 LOG(LS_INFO) << "Feature disabled... skipping"; \
51 return; \
52 }
53
54using cricket::CA_OFFER;
55using cricket::CA_PRANSWER;
56using cricket::CA_ANSWER;
57using cricket::CA_UPDATE;
58using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::ScreencastId;
60using cricket::StreamParams;
61using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
65static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
67static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
68static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
69static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
Peter Boström0c4e06b2015-10-07 12:23:21 +020070static const uint32_t kSsrc1 = 0x1111;
71static const uint32_t kSsrc2 = 0x2222;
72static const uint32_t kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000073static const int kAudioPts[] = {0, 8};
74static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
deadbeefcbecd352015-09-23 11:50:27 -070076template <class ChannelT,
77 class MediaChannelT,
78 class ContentT,
79 class CodecT,
80 class MediaInfoT,
81 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082class Traits {
83 public:
84 typedef ChannelT Channel;
85 typedef MediaChannelT MediaChannel;
86 typedef ContentT Content;
87 typedef CodecT Codec;
88 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020089 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090};
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092// Controls how long we wait for a session to send messages that we
93// expect, in milliseconds. We put it high to avoid flaky tests.
94static const int kEventTimeout = 5000;
95
96class VoiceTraits : public Traits<cricket::VoiceChannel,
97 cricket::FakeVoiceMediaChannel,
98 cricket::AudioContentDescription,
99 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200100 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700101 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
103class VideoTraits : public Traits<cricket::VideoChannel,
104 cricket::FakeVideoMediaChannel,
105 cricket::VideoContentDescription,
106 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200107 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700108 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
110class DataTraits : public Traits<cricket::DataChannel,
111 cricket::FakeDataMediaChannel,
112 cricket::DataContentDescription,
113 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200114 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700115 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000117rtc::StreamInterface* Open(const std::string& path) {
118 return rtc::Filesystem::OpenFile(
119 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120}
121
122// Base class for Voice/VideoChannel tests
123template<class T>
124class ChannelTest : public testing::Test, public sigslot::has_slots<> {
125 public:
126 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
127 DTLS = 0x10 };
128
Peter Boström34fbfff2015-09-24 19:20:30 +0200129 ChannelTest(bool verify_playout,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200130 const uint8_t* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700131 int rtp_len,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200132 const uint8_t* rtcp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700133 int rtcp_len)
Peter Boström34fbfff2015-09-24 19:20:30 +0200134 : verify_playout_(verify_playout),
135 transport_controller1_(cricket::ICEROLE_CONTROLLING),
deadbeefcbecd352015-09-23 11:50:27 -0700136 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 media_channel1_(NULL),
138 media_channel2_(NULL),
139 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
140 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
141 media_info_callbacks1_(),
solenberg5b14b422015-10-01 04:10:31 -0700142 media_info_callbacks2_() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200145 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
146 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 void CreateChannels(
150 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000151 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 media_channel1_ = ch1;
153 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700154 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
155 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700157 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
158 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 (flags2 & RTCP) != 0));
160 channel1_->SignalMediaMonitor.connect(
161 this, &ChannelTest<T>::OnMediaMonitor);
162 channel2_->SignalMediaMonitor.connect(
163 this, &ChannelTest<T>::OnMediaMonitor);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000164 if ((flags1 & DTLS) && (flags2 & DTLS)) {
165 flags1 = (flags1 & ~SECURE);
166 flags2 = (flags2 & ~SECURE);
167 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 CreateContent(flags1, kPcmuCodec, kH264Codec,
169 &local_media_content1_);
170 CreateContent(flags2, kPcmuCodec, kH264Codec,
171 &local_media_content2_);
172 CopyContent(local_media_content1_, &remote_media_content1_);
173 CopyContent(local_media_content2_, &remote_media_content2_);
174
175 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200176 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700177 transport_controller1_.SetLocalCertificate(rtc::RTCCertificate::Create(
178 rtc::scoped_ptr<rtc::SSLIdentity>(
179 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))
180 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 }
182 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200183 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700184 transport_controller2_.SetLocalCertificate(rtc::RTCCertificate::Create(
185 rtc::scoped_ptr<rtc::SSLIdentity>(
186 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))
187 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 }
189
190 // Add stream information (SSRC) to the local content but not to the remote
191 // content. This means that we per default know the SSRC of what we send but
192 // not what we receive.
193 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
194 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
195
196 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
197 if (flags1 & SSRC_MUX) {
198 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
199 }
200 if (flags2 & SSRC_MUX) {
201 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
202 }
203 }
deadbeefcbecd352015-09-23 11:50:27 -0700204 typename T::Channel* CreateChannel(
205 rtc::Thread* thread,
206 cricket::MediaEngineInterface* engine,
207 typename T::MediaChannel* ch,
208 cricket::TransportController* transport_controller,
209 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700211 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 if (!channel->Init()) {
213 delete channel;
214 channel = NULL;
215 }
216 return channel;
217 }
218
219 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000220 bool result = channel1_->SetLocalContent(&local_media_content1_,
221 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 if (result) {
223 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000224 result = channel2_->SetRemoteContent(&remote_media_content1_,
225 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700227 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000229 result = channel2_->SetLocalContent(&local_media_content2_,
230 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 }
232 }
233 return result;
234 }
235
236 bool SendAccept() {
237 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000238 return channel1_->SetRemoteContent(&remote_media_content2_,
239 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 }
241
242 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000243 bool result = channel1_->SetLocalContent(&local_media_content1_,
244 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 if (result) {
246 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 result = channel2_->SetRemoteContent(&remote_media_content1_,
248 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 }
250 return result;
251 }
252
253 bool SendProvisionalAnswer() {
254 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000255 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 if (result) {
257 channel2_->Enable(true);
258 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000259 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700260 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 }
262 return result;
263 }
264
265 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000266 bool result = channel2_->SetLocalContent(&local_media_content2_,
267 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000269 result = channel1_->SetRemoteContent(&remote_media_content2_,
270 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 return result;
272 }
273
274 bool SendTerminate() {
275 channel1_.reset();
276 channel2_.reset();
277 return true;
278 }
279
280 bool AddStream1(int id) {
281 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
282 }
283 bool RemoveStream1(int id) {
284 return channel1_->RemoveRecvStream(id);
285 }
286
deadbeefcbecd352015-09-23 11:50:27 -0700287 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700289 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 }
291 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700292 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 }
294
295 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000296 return media_channel1_->SendRtp(rtp_packet_.c_str(),
297 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 }
299 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000300 return media_channel2_->SendRtp(rtp_packet_.c_str(),
301 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 }
303 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000304 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
305 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 }
307 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000308 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
309 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 }
311 // Methods to send custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200312 bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000313 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000314 return media_channel1_->SendRtp(data.c_str(),
315 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200317 bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000318 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000319 return media_channel2_->SendRtp(data.c_str(),
320 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200322 bool SendCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000324 return media_channel1_->SendRtcp(data.c_str(),
325 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200327 bool SendCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000329 return media_channel2_->SendRtcp(data.c_str(),
330 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
332 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000333 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
334 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 }
336 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000337 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
338 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
340 bool CheckRtcp1() {
341 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000342 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343 }
344 bool CheckRtcp2() {
345 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000346 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 }
348 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200349 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000350 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000351 return media_channel1_->CheckRtp(data.c_str(),
352 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200354 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000355 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000356 return media_channel2_->CheckRtp(data.c_str(),
357 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200359 bool CheckCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000361 return media_channel1_->CheckRtcp(data.c_str(),
362 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200364 bool CheckCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000366 return media_channel2_->CheckRtcp(data.c_str(),
367 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200369 std::string CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 std::string data(rtp_packet_);
371 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000372 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
373 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000374 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000375 rtc::Set8(const_cast<char*>(data.c_str()), 1,
376 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000377 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378 return data;
379 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200380 std::string CreateRtcpData(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 std::string data(rtcp_packet_);
382 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000383 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 return data;
385 }
386
387 bool CheckNoRtp1() {
388 return media_channel1_->CheckNoRtp();
389 }
390 bool CheckNoRtp2() {
391 return media_channel2_->CheckNoRtp();
392 }
393 bool CheckNoRtcp1() {
394 return media_channel1_->CheckNoRtcp();
395 }
396 bool CheckNoRtcp2() {
397 return media_channel2_->CheckNoRtcp();
398 }
399
400 void CreateContent(int flags,
401 const cricket::AudioCodec& audio_codec,
402 const cricket::VideoCodec& video_codec,
403 typename T::Content* content) {
404 // overridden in specialized classes
405 }
406 void CopyContent(const typename T::Content& source,
407 typename T::Content* content) {
408 // overridden in specialized classes
409 }
410
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 // Creates a cricket::SessionDescription with one MediaContent and one stream.
412 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200413 cricket::SessionDescription* CreateSessionDescriptionWithStream(
414 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 typename T::Content content;
416 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
417 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
418 AddLegacyStreamInContent(ssrc, 0, &content);
419 sdesc->AddContent("DUMMY_CONTENT_NAME",
420 cricket::NS_JINGLE_RTP, content.Copy());
421 return sdesc;
422 }
423
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000424 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 public:
426 typedef bool (ChannelTest<T>::*Method)();
427 CallThread(ChannelTest<T>* obj, Method method, bool* result)
428 : obj_(obj),
429 method_(method),
430 result_(result) {
431 *result = false;
432 }
433 virtual void DoWork() {
434 bool result = (*obj_.*method_)();
435 if (result_) {
436 *result_ = result;
437 }
438 }
439 private:
440 ChannelTest<T>* obj_;
441 Method method_;
442 bool* result_;
443 };
444 void CallOnThread(typename CallThread::Method method, bool* result) {
445 CallThread* thread = new CallThread(this, method, result);
446 thread->Start();
447 thread->Release();
448 }
449
450 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
451 bool* result) {
452 CallThread* thread = new CallThread(this, method, result);
453 thread->Start();
454 thread->Destroy(true);
455 }
456
457 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
458 return false; // overridden in specialized classes
459 }
460
461 void OnMediaMonitor(typename T::Channel* channel,
462 const typename T::MediaInfo& info) {
463 if (channel == channel1_.get()) {
464 media_info_callbacks1_++;
465 } else if (channel == channel2_.get()) {
466 media_info_callbacks2_++;
467 }
468 }
469
Peter Boström0c4e06b2015-10-07 12:23:21 +0200470 void AddLegacyStreamInContent(uint32_t ssrc,
471 int flags,
472 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000473 // Base implementation.
474 }
475
476 // Tests that can be used by derived classes.
477
478 // Basic sanity check.
479 void TestInit() {
480 CreateChannels(0, 0);
481 EXPECT_FALSE(channel1_->secure());
482 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200483 if (verify_playout_) {
484 EXPECT_FALSE(media_channel1_->playout());
485 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000486 EXPECT_TRUE(media_channel1_->codecs().empty());
487 EXPECT_TRUE(media_channel1_->recv_streams().empty());
488 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
489 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
490 }
491
492 // Test that SetLocalContent and SetRemoteContent properly configure
493 // the codecs.
494 void TestSetContents() {
495 CreateChannels(0, 0);
496 typename T::Content content;
497 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000498 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000500 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 ASSERT_EQ(1U, media_channel1_->codecs().size());
502 EXPECT_TRUE(CodecMatches(content.codecs()[0],
503 media_channel1_->codecs()[0]));
504 }
505
506 // Test that SetLocalContent and SetRemoteContent properly deals
507 // with an empty offer.
508 void TestSetContentsNullOffer() {
509 CreateChannels(0, 0);
510 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000511 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 CreateContent(0, kPcmuCodec, kH264Codec, &content);
513 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000514 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 ASSERT_EQ(1U, media_channel1_->codecs().size());
516 EXPECT_TRUE(CodecMatches(content.codecs()[0],
517 media_channel1_->codecs()[0]));
518 }
519
520 // Test that SetLocalContent and SetRemoteContent properly set RTCP
521 // mux.
522 void TestSetContentsRtcpMux() {
523 CreateChannels(RTCP, RTCP);
524 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
525 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
526 typename T::Content content;
527 CreateContent(0, kPcmuCodec, kH264Codec, &content);
528 // Both sides agree on mux. Should no longer be a separate RTCP channel.
529 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000530 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
531 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
533 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000534 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000536 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
538 }
539
540 // Test that SetLocalContent and SetRemoteContent properly set RTCP
541 // mux when a provisional answer is received.
542 void TestSetContentsRtcpMuxWithPrAnswer() {
543 CreateChannels(RTCP, RTCP);
544 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
545 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
546 typename T::Content content;
547 CreateContent(0, kPcmuCodec, kH264Codec, &content);
548 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000549 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
550 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000552 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 // Both sides agree on mux. Should no longer be a separate RTCP channel.
554 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
555 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000556 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000558 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
559 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
561 }
562
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 // Test that SetRemoteContent properly deals with a content update.
564 void TestSetRemoteContentUpdate() {
565 CreateChannels(0, 0);
566 typename T::Content content;
567 CreateContent(RTCP | RTCP_MUX | SECURE,
568 kPcmuCodec, kH264Codec,
569 &content);
570 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000571 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
572 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 ASSERT_EQ(1U, media_channel1_->codecs().size());
574 EXPECT_TRUE(CodecMatches(content.codecs()[0],
575 media_channel1_->codecs()[0]));
576 // Now update with other codecs.
577 typename T::Content update_content;
578 update_content.set_partial(true);
579 CreateContent(0, kIsacCodec, kH264SvcCodec,
580 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000581 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 ASSERT_EQ(1U, media_channel1_->codecs().size());
583 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
584 media_channel1_->codecs()[0]));
585 // Now update without any codecs. This is ignored.
586 typename T::Content empty_content;
587 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000588 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000589 ASSERT_EQ(1U, media_channel1_->codecs().size());
590 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
591 media_channel1_->codecs()[0]));
592 }
593
594 // Test that Add/RemoveStream properly forward to the media channel.
595 void TestStreams() {
596 CreateChannels(0, 0);
597 EXPECT_TRUE(AddStream1(1));
598 EXPECT_TRUE(AddStream1(2));
599 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
600 EXPECT_TRUE(RemoveStream1(2));
601 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
602 EXPECT_TRUE(RemoveStream1(1));
603 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
604 }
605
606 // Test that SetLocalContent properly handles adding and removing StreamParams
607 // to the local content description.
608 // This test uses the CA_UPDATE action that don't require a full
609 // MediaContentDescription to do an update.
610 void TestUpdateStreamsInLocalContent() {
611 cricket::StreamParams stream1;
612 stream1.groupid = "group1";
613 stream1.id = "stream1";
614 stream1.ssrcs.push_back(kSsrc1);
615 stream1.cname = "stream1_cname";
616
617 cricket::StreamParams stream2;
618 stream2.groupid = "group2";
619 stream2.id = "stream2";
620 stream2.ssrcs.push_back(kSsrc2);
621 stream2.cname = "stream2_cname";
622
623 cricket::StreamParams stream3;
624 stream3.groupid = "group3";
625 stream3.id = "stream3";
626 stream3.ssrcs.push_back(kSsrc3);
627 stream3.cname = "stream3_cname";
628
629 CreateChannels(0, 0);
630 typename T::Content content1;
631 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
632 content1.AddStream(stream1);
633 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000634 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635
636 ASSERT_EQ(1u, media_channel1_->send_streams().size());
637 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
638
639 // Update the local streams by adding another sending stream.
640 // Use a partial updated session description.
641 typename T::Content content2;
642 content2.AddStream(stream2);
643 content2.AddStream(stream3);
644 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000645 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 ASSERT_EQ(3u, media_channel1_->send_streams().size());
647 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
648 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
649 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
650
651 // Update the local streams by removing the first sending stream.
652 // This is done by removing all SSRCS for this particular stream.
653 typename T::Content content3;
654 stream1.ssrcs.clear();
655 content3.AddStream(stream1);
656 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000657 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 ASSERT_EQ(2u, media_channel1_->send_streams().size());
659 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
660 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
661
662 // Update the local streams with a stream that does not change.
663 // THe update is ignored.
664 typename T::Content content4;
665 content4.AddStream(stream2);
666 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000667 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 ASSERT_EQ(2u, media_channel1_->send_streams().size());
669 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
670 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
671 }
672
673 // Test that SetRemoteContent properly handles adding and removing
674 // StreamParams to the remote content description.
675 // This test uses the CA_UPDATE action that don't require a full
676 // MediaContentDescription to do an update.
677 void TestUpdateStreamsInRemoteContent() {
678 cricket::StreamParams stream1;
679 stream1.id = "Stream1";
680 stream1.groupid = "1";
681 stream1.ssrcs.push_back(kSsrc1);
682 stream1.cname = "stream1_cname";
683
684 cricket::StreamParams stream2;
685 stream2.id = "Stream2";
686 stream2.groupid = "2";
687 stream2.ssrcs.push_back(kSsrc2);
688 stream2.cname = "stream2_cname";
689
690 cricket::StreamParams stream3;
691 stream3.id = "Stream3";
692 stream3.groupid = "3";
693 stream3.ssrcs.push_back(kSsrc3);
694 stream3.cname = "stream3_cname";
695
696 CreateChannels(0, 0);
697 typename T::Content content1;
698 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
699 content1.AddStream(stream1);
700 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000701 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702
703 ASSERT_EQ(1u, media_channel1_->codecs().size());
704 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
705 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
706
707 // Update the remote streams by adding another sending stream.
708 // Use a partial updated session description.
709 typename T::Content content2;
710 content2.AddStream(stream2);
711 content2.AddStream(stream3);
712 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000713 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
715 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
716 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
717 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
718
719 // Update the remote streams by removing the first stream.
720 // This is done by removing all SSRCS for this particular stream.
721 typename T::Content content3;
722 stream1.ssrcs.clear();
723 content3.AddStream(stream1);
724 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000725 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
727 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
728 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
729
730 // Update the remote streams with a stream that does not change.
731 // The update is ignored.
732 typename T::Content content4;
733 content4.AddStream(stream2);
734 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000735 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
737 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
738 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
739 }
740
741 // Test that SetLocalContent and SetRemoteContent properly
742 // handles adding and removing StreamParams when the action is a full
743 // CA_OFFER / CA_ANSWER.
744 void TestChangeStreamParamsInContent() {
745 cricket::StreamParams stream1;
746 stream1.groupid = "group1";
747 stream1.id = "stream1";
748 stream1.ssrcs.push_back(kSsrc1);
749 stream1.cname = "stream1_cname";
750
751 cricket::StreamParams stream2;
752 stream2.groupid = "group1";
753 stream2.id = "stream2";
754 stream2.ssrcs.push_back(kSsrc2);
755 stream2.cname = "stream2_cname";
756
757 // Setup a call where channel 1 send |stream1| to channel 2.
758 CreateChannels(0, 0);
759 typename T::Content content1;
760 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
761 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000762 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 EXPECT_TRUE(channel1_->Enable(true));
764 EXPECT_EQ(1u, media_channel1_->send_streams().size());
765
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000766 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700768 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769
770 // Channel 2 do not send anything.
771 typename T::Content content2;
772 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000773 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000775 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 EXPECT_TRUE(channel2_->Enable(true));
777 EXPECT_EQ(0u, media_channel2_->send_streams().size());
778
779 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
780 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
781
782 // Let channel 2 update the content by sending |stream2| and enable SRTP.
783 typename T::Content content3;
784 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
785 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000786 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 ASSERT_EQ(1u, media_channel2_->send_streams().size());
788 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
789
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000790 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
792 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
793
794 // Channel 1 replies but stop sending stream1.
795 typename T::Content content4;
796 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000797 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 EXPECT_EQ(0u, media_channel1_->send_streams().size());
799
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000800 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
802
803 EXPECT_TRUE(channel1_->secure());
804 EXPECT_TRUE(channel2_->secure());
805 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
806 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
807 }
808
809 // Test that we only start playout and sending at the right times.
810 void TestPlayoutAndSendingStates() {
811 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200812 if (verify_playout_) {
813 EXPECT_FALSE(media_channel1_->playout());
814 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200816 if (verify_playout_) {
817 EXPECT_FALSE(media_channel2_->playout());
818 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 EXPECT_FALSE(media_channel2_->sending());
820 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200821 if (verify_playout_) {
822 EXPECT_FALSE(media_channel1_->playout());
823 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000825 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
826 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200827 if (verify_playout_) {
828 EXPECT_TRUE(media_channel1_->playout());
829 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000831 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
832 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200833 if (verify_playout_) {
834 EXPECT_FALSE(media_channel2_->playout());
835 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000836 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000837 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
838 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200839 if (verify_playout_) {
840 EXPECT_FALSE(media_channel2_->playout());
841 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700843 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200844 if (verify_playout_) {
845 EXPECT_TRUE(media_channel1_->playout());
846 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200848 if (verify_playout_) {
849 EXPECT_FALSE(media_channel2_->playout());
850 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 EXPECT_FALSE(media_channel2_->sending());
852 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200853 if (verify_playout_) {
854 EXPECT_TRUE(media_channel2_->playout());
855 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000857 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
858 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200859 if (verify_playout_) {
860 EXPECT_TRUE(media_channel1_->playout());
861 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 EXPECT_TRUE(media_channel1_->sending());
863 }
864
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000865 // Test that changing the MediaContentDirection in the local and remote
866 // session description start playout and sending at the right time.
867 void TestMediaContentDirection() {
868 CreateChannels(0, 0);
869 typename T::Content content1;
870 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
871 typename T::Content content2;
872 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
873 // Set |content2| to be InActive.
874 content2.set_direction(cricket::MD_INACTIVE);
875
876 EXPECT_TRUE(channel1_->Enable(true));
877 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200878 if (verify_playout_) {
879 EXPECT_FALSE(media_channel1_->playout());
880 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200882 if (verify_playout_) {
883 EXPECT_FALSE(media_channel2_->playout());
884 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 EXPECT_FALSE(media_channel2_->sending());
886
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000887 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
888 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
889 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
890 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700891 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892
Peter Boström34fbfff2015-09-24 19:20:30 +0200893 if (verify_playout_) {
894 EXPECT_TRUE(media_channel1_->playout());
895 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200897 if (verify_playout_) {
898 EXPECT_FALSE(media_channel2_->playout()); // local InActive
899 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 EXPECT_FALSE(media_channel2_->sending()); // local InActive
901
902 // Update |content2| to be RecvOnly.
903 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000904 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
905 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906
Peter Boström34fbfff2015-09-24 19:20:30 +0200907 if (verify_playout_) {
908 EXPECT_TRUE(media_channel1_->playout());
909 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200911 if (verify_playout_) {
912 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
913 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
915
916 // Update |content2| to be SendRecv.
917 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000918 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
919 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920
Peter Boström34fbfff2015-09-24 19:20:30 +0200921 if (verify_playout_) {
922 EXPECT_TRUE(media_channel1_->playout());
923 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200925 if (verify_playout_) {
926 EXPECT_TRUE(media_channel2_->playout());
927 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 EXPECT_TRUE(media_channel2_->sending());
929 }
930
931 // Test setting up a call.
932 void TestCallSetup() {
933 CreateChannels(0, 0);
934 EXPECT_FALSE(channel1_->secure());
935 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200936 if (verify_playout_) {
937 EXPECT_TRUE(media_channel1_->playout());
938 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 EXPECT_FALSE(media_channel1_->sending());
940 EXPECT_TRUE(SendAccept());
941 EXPECT_FALSE(channel1_->secure());
942 EXPECT_TRUE(media_channel1_->sending());
943 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200944 if (verify_playout_) {
945 EXPECT_TRUE(media_channel2_->playout());
946 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947 EXPECT_TRUE(media_channel2_->sending());
948 EXPECT_EQ(1U, media_channel2_->codecs().size());
949 }
950
951 // Test that we don't crash if packets are sent during call teardown
952 // when RTCP mux is enabled. This is a regression test against a specific
953 // race condition that would only occur when a RTCP packet was sent during
954 // teardown of a channel on which RTCP mux was enabled.
955 void TestCallTeardownRtcpMux() {
956 class LastWordMediaChannel : public T::MediaChannel {
957 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200958 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 ~LastWordMediaChannel() {
960 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
961 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
962 }
963 };
964 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
965 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000966 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 EXPECT_TRUE(SendInitiate());
968 EXPECT_TRUE(SendAccept());
969 EXPECT_TRUE(SendTerminate());
970 }
971
972 // Send voice RTP data to the other side and ensure it gets there.
973 void SendRtpToRtp() {
974 CreateChannels(0, 0);
975 EXPECT_TRUE(SendInitiate());
976 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700977 ASSERT_TRUE(GetTransport1());
978 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000979 EXPECT_EQ(1U, GetTransport1()->channels().size());
980 EXPECT_EQ(1U, GetTransport2()->channels().size());
981 EXPECT_TRUE(SendRtp1());
982 EXPECT_TRUE(SendRtp2());
983 EXPECT_TRUE(CheckRtp1());
984 EXPECT_TRUE(CheckRtp2());
985 EXPECT_TRUE(CheckNoRtp1());
986 EXPECT_TRUE(CheckNoRtp2());
987 }
988
989 // Check that RTCP is not transmitted if both sides don't support RTCP.
990 void SendNoRtcpToNoRtcp() {
991 CreateChannels(0, 0);
992 EXPECT_TRUE(SendInitiate());
993 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700994 ASSERT_TRUE(GetTransport1());
995 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 EXPECT_EQ(1U, GetTransport1()->channels().size());
997 EXPECT_EQ(1U, GetTransport2()->channels().size());
998 EXPECT_FALSE(SendRtcp1());
999 EXPECT_FALSE(SendRtcp2());
1000 EXPECT_TRUE(CheckNoRtcp1());
1001 EXPECT_TRUE(CheckNoRtcp2());
1002 }
1003
1004 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1005 void SendNoRtcpToRtcp() {
1006 CreateChannels(0, RTCP);
1007 EXPECT_TRUE(SendInitiate());
1008 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001009 ASSERT_TRUE(GetTransport1());
1010 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 EXPECT_EQ(1U, GetTransport1()->channels().size());
1012 EXPECT_EQ(2U, GetTransport2()->channels().size());
1013 EXPECT_FALSE(SendRtcp1());
1014 EXPECT_FALSE(SendRtcp2());
1015 EXPECT_TRUE(CheckNoRtcp1());
1016 EXPECT_TRUE(CheckNoRtcp2());
1017 }
1018
1019 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1020 void SendRtcpToNoRtcp() {
1021 CreateChannels(RTCP, 0);
1022 EXPECT_TRUE(SendInitiate());
1023 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001024 ASSERT_TRUE(GetTransport1());
1025 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 EXPECT_EQ(2U, GetTransport1()->channels().size());
1027 EXPECT_EQ(1U, GetTransport2()->channels().size());
1028 EXPECT_FALSE(SendRtcp1());
1029 EXPECT_FALSE(SendRtcp2());
1030 EXPECT_TRUE(CheckNoRtcp1());
1031 EXPECT_TRUE(CheckNoRtcp2());
1032 }
1033
1034 // Check that RTCP is transmitted if both sides support RTCP.
1035 void SendRtcpToRtcp() {
1036 CreateChannels(RTCP, RTCP);
1037 EXPECT_TRUE(SendInitiate());
1038 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001039 ASSERT_TRUE(GetTransport1());
1040 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 EXPECT_EQ(2U, GetTransport1()->channels().size());
1042 EXPECT_EQ(2U, GetTransport2()->channels().size());
1043 EXPECT_TRUE(SendRtcp1());
1044 EXPECT_TRUE(SendRtcp2());
1045 EXPECT_TRUE(CheckRtcp1());
1046 EXPECT_TRUE(CheckRtcp2());
1047 EXPECT_TRUE(CheckNoRtcp1());
1048 EXPECT_TRUE(CheckNoRtcp2());
1049 }
1050
1051 // Check that RTCP is transmitted if only the initiator supports mux.
1052 void SendRtcpMuxToRtcp() {
1053 CreateChannels(RTCP | RTCP_MUX, RTCP);
1054 EXPECT_TRUE(SendInitiate());
1055 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001056 ASSERT_TRUE(GetTransport1());
1057 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 EXPECT_EQ(2U, GetTransport1()->channels().size());
1059 EXPECT_EQ(2U, GetTransport2()->channels().size());
1060 EXPECT_TRUE(SendRtcp1());
1061 EXPECT_TRUE(SendRtcp2());
1062 EXPECT_TRUE(CheckRtcp1());
1063 EXPECT_TRUE(CheckRtcp2());
1064 EXPECT_TRUE(CheckNoRtcp1());
1065 EXPECT_TRUE(CheckNoRtcp2());
1066 }
1067
1068 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1069 void SendRtcpMuxToRtcpMux() {
1070 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1071 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001072 ASSERT_TRUE(GetTransport1());
1073 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074 EXPECT_EQ(2U, GetTransport1()->channels().size());
1075 EXPECT_EQ(1U, GetTransport2()->channels().size());
1076 EXPECT_TRUE(SendAccept());
1077 EXPECT_EQ(1U, GetTransport1()->channels().size());
1078 EXPECT_TRUE(SendRtp1());
1079 EXPECT_TRUE(SendRtp2());
1080 EXPECT_TRUE(SendRtcp1());
1081 EXPECT_TRUE(SendRtcp2());
1082 EXPECT_TRUE(CheckRtp1());
1083 EXPECT_TRUE(CheckRtp2());
1084 EXPECT_TRUE(CheckNoRtp1());
1085 EXPECT_TRUE(CheckNoRtp2());
1086 EXPECT_TRUE(CheckRtcp1());
1087 EXPECT_TRUE(CheckRtcp2());
1088 EXPECT_TRUE(CheckNoRtcp1());
1089 EXPECT_TRUE(CheckNoRtcp2());
1090 }
1091
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001092 // Check that RTP and RTCP are transmitted ok when both sides
1093 // support mux and one the offerer requires mux.
1094 void SendRequireRtcpMuxToRtcpMux() {
1095 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1096 channel1_->ActivateRtcpMux();
1097 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001098 ASSERT_TRUE(GetTransport1());
1099 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001100 EXPECT_EQ(1U, GetTransport1()->channels().size());
1101 EXPECT_EQ(1U, GetTransport2()->channels().size());
1102 EXPECT_TRUE(SendAccept());
1103 EXPECT_TRUE(SendRtp1());
1104 EXPECT_TRUE(SendRtp2());
1105 EXPECT_TRUE(SendRtcp1());
1106 EXPECT_TRUE(SendRtcp2());
1107 EXPECT_TRUE(CheckRtp1());
1108 EXPECT_TRUE(CheckRtp2());
1109 EXPECT_TRUE(CheckNoRtp1());
1110 EXPECT_TRUE(CheckNoRtp2());
1111 EXPECT_TRUE(CheckRtcp1());
1112 EXPECT_TRUE(CheckRtcp2());
1113 EXPECT_TRUE(CheckNoRtcp1());
1114 EXPECT_TRUE(CheckNoRtcp2());
1115 }
1116
1117 // Check that RTP and RTCP are transmitted ok when both sides
1118 // support mux and one the answerer requires rtcp mux.
1119 void SendRtcpMuxToRequireRtcpMux() {
1120 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1121 channel2_->ActivateRtcpMux();
1122 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001123 ASSERT_TRUE(GetTransport1());
1124 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001125 EXPECT_EQ(2U, GetTransport1()->channels().size());
1126 EXPECT_EQ(1U, GetTransport2()->channels().size());
1127 EXPECT_TRUE(SendAccept());
1128 EXPECT_EQ(1U, GetTransport1()->channels().size());
1129 EXPECT_TRUE(SendRtp1());
1130 EXPECT_TRUE(SendRtp2());
1131 EXPECT_TRUE(SendRtcp1());
1132 EXPECT_TRUE(SendRtcp2());
1133 EXPECT_TRUE(CheckRtp1());
1134 EXPECT_TRUE(CheckRtp2());
1135 EXPECT_TRUE(CheckNoRtp1());
1136 EXPECT_TRUE(CheckNoRtp2());
1137 EXPECT_TRUE(CheckRtcp1());
1138 EXPECT_TRUE(CheckRtcp2());
1139 EXPECT_TRUE(CheckNoRtcp1());
1140 EXPECT_TRUE(CheckNoRtcp2());
1141 }
1142
1143 // Check that RTP and RTCP are transmitted ok when both sides
1144 // require mux.
1145 void SendRequireRtcpMuxToRequireRtcpMux() {
1146 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1147 channel1_->ActivateRtcpMux();
1148 channel2_->ActivateRtcpMux();
1149 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001150 ASSERT_TRUE(GetTransport1());
1151 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001152 EXPECT_EQ(1U, GetTransport1()->channels().size());
1153 EXPECT_EQ(1U, GetTransport2()->channels().size());
1154 EXPECT_TRUE(SendAccept());
1155 EXPECT_EQ(1U, GetTransport1()->channels().size());
1156 EXPECT_TRUE(SendRtp1());
1157 EXPECT_TRUE(SendRtp2());
1158 EXPECT_TRUE(SendRtcp1());
1159 EXPECT_TRUE(SendRtcp2());
1160 EXPECT_TRUE(CheckRtp1());
1161 EXPECT_TRUE(CheckRtp2());
1162 EXPECT_TRUE(CheckNoRtp1());
1163 EXPECT_TRUE(CheckNoRtp2());
1164 EXPECT_TRUE(CheckRtcp1());
1165 EXPECT_TRUE(CheckRtcp2());
1166 EXPECT_TRUE(CheckNoRtcp1());
1167 EXPECT_TRUE(CheckNoRtcp2());
1168 }
1169
1170 // Check that SendAccept fails if the answerer doesn't support mux
1171 // and the offerer requires it.
1172 void SendRequireRtcpMuxToNoRtcpMux() {
1173 CreateChannels(RTCP | RTCP_MUX, RTCP);
1174 channel1_->ActivateRtcpMux();
1175 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001176 ASSERT_TRUE(GetTransport1());
1177 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001178 EXPECT_EQ(1U, GetTransport1()->channels().size());
1179 EXPECT_EQ(2U, GetTransport2()->channels().size());
1180 EXPECT_FALSE(SendAccept());
1181 }
1182
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183 // Check that RTCP data sent by the initiator before the accept is not muxed.
1184 void SendEarlyRtcpMuxToRtcp() {
1185 CreateChannels(RTCP | RTCP_MUX, RTCP);
1186 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001187 ASSERT_TRUE(GetTransport1());
1188 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001189 EXPECT_EQ(2U, GetTransport1()->channels().size());
1190 EXPECT_EQ(2U, GetTransport2()->channels().size());
1191
1192 // RTCP can be sent before the call is accepted, if the transport is ready.
1193 // It should not be muxed though, as the remote side doesn't support mux.
1194 EXPECT_TRUE(SendRtcp1());
1195 EXPECT_TRUE(CheckNoRtp2());
1196 EXPECT_TRUE(CheckRtcp2());
1197
1198 // Send RTCP packet from callee and verify that it is received.
1199 EXPECT_TRUE(SendRtcp2());
1200 EXPECT_TRUE(CheckNoRtp1());
1201 EXPECT_TRUE(CheckRtcp1());
1202
1203 // Complete call setup and ensure everything is still OK.
1204 EXPECT_TRUE(SendAccept());
1205 EXPECT_EQ(2U, GetTransport1()->channels().size());
1206 EXPECT_TRUE(SendRtcp1());
1207 EXPECT_TRUE(CheckRtcp2());
1208 EXPECT_TRUE(SendRtcp2());
1209 EXPECT_TRUE(CheckRtcp1());
1210 }
1211
1212
1213 // Check that RTCP data is not muxed until both sides have enabled muxing,
1214 // but that we properly demux before we get the accept message, since there
1215 // is a race between RTP data and the jingle accept.
1216 void SendEarlyRtcpMuxToRtcpMux() {
1217 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1218 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001219 ASSERT_TRUE(GetTransport1());
1220 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 EXPECT_EQ(2U, GetTransport1()->channels().size());
1222 EXPECT_EQ(1U, GetTransport2()->channels().size());
1223
1224 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1225 // we haven't yet received the accept that says we should mux.
1226 EXPECT_FALSE(SendRtcp1());
1227
1228 // Send muxed RTCP packet from callee and verify that it is received.
1229 EXPECT_TRUE(SendRtcp2());
1230 EXPECT_TRUE(CheckNoRtp1());
1231 EXPECT_TRUE(CheckRtcp1());
1232
1233 // Complete call setup and ensure everything is still OK.
1234 EXPECT_TRUE(SendAccept());
1235 EXPECT_EQ(1U, GetTransport1()->channels().size());
1236 EXPECT_TRUE(SendRtcp1());
1237 EXPECT_TRUE(CheckRtcp2());
1238 EXPECT_TRUE(SendRtcp2());
1239 EXPECT_TRUE(CheckRtcp1());
1240 }
1241
1242 // Test that we properly send SRTP with RTCP in both directions.
1243 // You can pass in DTLS and/or RTCP_MUX as flags.
1244 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1245 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1246 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1247
1248 int flags1 = RTCP | SECURE | flags1_in;
1249 int flags2 = RTCP | SECURE | flags2_in;
1250 bool dtls1 = !!(flags1_in & DTLS);
1251 bool dtls2 = !!(flags2_in & DTLS);
1252 CreateChannels(flags1, flags2);
1253 EXPECT_FALSE(channel1_->secure());
1254 EXPECT_FALSE(channel2_->secure());
1255 EXPECT_TRUE(SendInitiate());
1256 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1257 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1258 EXPECT_TRUE(SendAccept());
1259 EXPECT_TRUE(channel1_->secure());
1260 EXPECT_TRUE(channel2_->secure());
1261 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1262 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1263 EXPECT_TRUE(SendRtp1());
1264 EXPECT_TRUE(SendRtp2());
1265 EXPECT_TRUE(SendRtcp1());
1266 EXPECT_TRUE(SendRtcp2());
1267 EXPECT_TRUE(CheckRtp1());
1268 EXPECT_TRUE(CheckRtp2());
1269 EXPECT_TRUE(CheckNoRtp1());
1270 EXPECT_TRUE(CheckNoRtp2());
1271 EXPECT_TRUE(CheckRtcp1());
1272 EXPECT_TRUE(CheckRtcp2());
1273 EXPECT_TRUE(CheckNoRtcp1());
1274 EXPECT_TRUE(CheckNoRtcp2());
1275 }
1276
1277 // Test that we properly handling SRTP negotiating down to RTP.
1278 void SendSrtpToRtp() {
1279 CreateChannels(RTCP | SECURE, RTCP);
1280 EXPECT_FALSE(channel1_->secure());
1281 EXPECT_FALSE(channel2_->secure());
1282 EXPECT_TRUE(SendInitiate());
1283 EXPECT_TRUE(SendAccept());
1284 EXPECT_FALSE(channel1_->secure());
1285 EXPECT_FALSE(channel2_->secure());
1286 EXPECT_TRUE(SendRtp1());
1287 EXPECT_TRUE(SendRtp2());
1288 EXPECT_TRUE(SendRtcp1());
1289 EXPECT_TRUE(SendRtcp2());
1290 EXPECT_TRUE(CheckRtp1());
1291 EXPECT_TRUE(CheckRtp2());
1292 EXPECT_TRUE(CheckNoRtp1());
1293 EXPECT_TRUE(CheckNoRtp2());
1294 EXPECT_TRUE(CheckRtcp1());
1295 EXPECT_TRUE(CheckRtcp2());
1296 EXPECT_TRUE(CheckNoRtcp1());
1297 EXPECT_TRUE(CheckNoRtcp2());
1298 }
1299
1300 // Test that we can send and receive early media when a provisional answer is
1301 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1302 void SendEarlyMediaUsingRtcpMuxSrtp() {
1303 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1304
1305 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1306 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1307 EXPECT_TRUE(SendOffer());
1308 EXPECT_TRUE(SendProvisionalAnswer());
1309 EXPECT_TRUE(channel1_->secure());
1310 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001311 ASSERT_TRUE(GetTransport1());
1312 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 EXPECT_EQ(2U, GetTransport1()->channels().size());
1314 EXPECT_EQ(2U, GetTransport2()->channels().size());
1315 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1316 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1317 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1318 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1319
1320 // Send packets from callee and verify that it is received.
1321 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1322 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1323 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1324 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1325
1326 // Complete call setup and ensure everything is still OK.
1327 EXPECT_TRUE(SendFinalAnswer());
1328 EXPECT_EQ(1U, GetTransport1()->channels().size());
1329 EXPECT_EQ(1U, GetTransport2()->channels().size());
1330 EXPECT_TRUE(channel1_->secure());
1331 EXPECT_TRUE(channel2_->secure());
1332 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1333 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1334 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1335 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1336 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1337 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1338 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1339 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1340 }
1341
1342 // Test that we properly send RTP without SRTP from a thread.
1343 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001344 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1345 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 EXPECT_TRUE(SendInitiate());
1347 EXPECT_TRUE(SendAccept());
1348 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1349 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001350 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1351 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1353 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1354 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1355 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1356 EXPECT_TRUE(CheckNoRtp1());
1357 EXPECT_TRUE(CheckNoRtp2());
1358 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1359 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1360 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1361 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1362 EXPECT_TRUE(CheckNoRtcp1());
1363 EXPECT_TRUE(CheckNoRtcp2());
1364 }
1365
1366 // Test that we properly send SRTP with RTCP from a thread.
1367 void SendSrtpToSrtpOnThread() {
1368 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1369 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1370 EXPECT_TRUE(SendInitiate());
1371 EXPECT_TRUE(SendAccept());
1372 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1373 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1374 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1375 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1376 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1377 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1378 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1379 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1380 EXPECT_TRUE(CheckNoRtp1());
1381 EXPECT_TRUE(CheckNoRtp2());
1382 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1383 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1384 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1385 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1386 EXPECT_TRUE(CheckNoRtcp1());
1387 EXPECT_TRUE(CheckNoRtcp2());
1388 }
1389
1390 // Test that the mediachannel retains its sending state after the transport
1391 // becomes non-writable.
1392 void SendWithWritabilityLoss() {
1393 CreateChannels(0, 0);
1394 EXPECT_TRUE(SendInitiate());
1395 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001396 ASSERT_TRUE(GetTransport1());
1397 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398 EXPECT_EQ(1U, GetTransport1()->channels().size());
1399 EXPECT_EQ(1U, GetTransport2()->channels().size());
1400 EXPECT_TRUE(SendRtp1());
1401 EXPECT_TRUE(SendRtp2());
1402 EXPECT_TRUE(CheckRtp1());
1403 EXPECT_TRUE(CheckRtp2());
1404 EXPECT_TRUE(CheckNoRtp1());
1405 EXPECT_TRUE(CheckNoRtp2());
1406
wu@webrtc.org97077a32013-10-25 21:18:33 +00001407 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 EXPECT_FALSE(SendRtp1());
1410 EXPECT_TRUE(SendRtp2());
1411 EXPECT_TRUE(CheckRtp1());
1412 EXPECT_TRUE(CheckNoRtp2());
1413
1414 // Regain writability
1415 GetTransport1()->SetWritable(true);
1416 EXPECT_TRUE(media_channel1_->sending());
1417 EXPECT_TRUE(SendRtp1());
1418 EXPECT_TRUE(SendRtp2());
1419 EXPECT_TRUE(CheckRtp1());
1420 EXPECT_TRUE(CheckRtp2());
1421 EXPECT_TRUE(CheckNoRtp1());
1422 EXPECT_TRUE(CheckNoRtp2());
1423
1424 // Lose writability completely
1425 GetTransport1()->SetDestination(NULL);
1426 EXPECT_TRUE(media_channel1_->sending());
1427
wu@webrtc.org97077a32013-10-25 21:18:33 +00001428 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429 EXPECT_FALSE(SendRtp1());
1430 EXPECT_TRUE(SendRtp2());
1431 EXPECT_TRUE(CheckRtp1());
1432 EXPECT_TRUE(CheckNoRtp2());
1433
1434 // Gain writability back
1435 GetTransport1()->SetDestination(GetTransport2());
1436 EXPECT_TRUE(media_channel1_->sending());
1437 EXPECT_TRUE(SendRtp1());
1438 EXPECT_TRUE(SendRtp2());
1439 EXPECT_TRUE(CheckRtp1());
1440 EXPECT_TRUE(CheckRtp2());
1441 EXPECT_TRUE(CheckNoRtp1());
1442 EXPECT_TRUE(CheckNoRtp2());
1443 }
1444
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001445 void SendBundleToBundle(
1446 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1447 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001449 // Only pl_type1 was added to the bundle filter for both |channel1_|
1450 // and |channel2_|.
1451 int pl_type1 = pl_types[0];
1452 int pl_type2 = pl_types[1];
1453 int flags = SSRC_MUX | RTCP;
1454 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001455 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001456 if (rtcp_mux) {
1457 flags |= RTCP_MUX;
1458 expected_channels = 1U;
1459 }
1460 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001462 ASSERT_TRUE(GetTransport1());
1463 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001465 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001467 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1468 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1469 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1470 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1471 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1472 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1473 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1474 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1475 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1476 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1477 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1478 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1479
1480 // Both channels can receive pl_type1 only.
1481 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1482 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1483 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1484 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1485 EXPECT_TRUE(CheckNoRtp1());
1486 EXPECT_TRUE(CheckNoRtp2());
1487
1488 // RTCP test
1489 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1490 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1491 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1492 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1493
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1495 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1497 EXPECT_TRUE(CheckNoRtcp1());
1498 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1499 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001501 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1502 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1505 }
1506
1507 // Test that the media monitor can be run and gives timely callbacks.
1508 void TestMediaMonitor() {
1509 static const int kTimeout = 500;
1510 CreateChannels(0, 0);
1511 EXPECT_TRUE(SendInitiate());
1512 EXPECT_TRUE(SendAccept());
1513 channel1_->StartMediaMonitor(100);
1514 channel2_->StartMediaMonitor(100);
1515 // Ensure we get callbacks and stop.
1516 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1517 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1518 channel1_->StopMediaMonitor();
1519 channel2_->StopMediaMonitor();
1520 // Ensure a restart of a stopped monitor works.
1521 channel1_->StartMediaMonitor(100);
1522 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1523 channel1_->StopMediaMonitor();
1524 // Ensure stopping a stopped monitor is OK.
1525 channel1_->StopMediaMonitor();
1526 }
1527
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 void TestSetContentFailure() {
1529 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530
Peter Thatchera6d24442015-07-09 21:26:36 -07001531 auto sdesc = cricket::SessionDescription();
1532 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1533 new cricket::AudioContentDescription());
1534 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1535 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536
Peter Thatchera6d24442015-07-09 21:26:36 -07001537 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001539 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1540 &sdesc, cricket::CA_OFFER, &err));
1541 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1542 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001545 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1546 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001548 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1549 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 }
1551
1552 void TestSendTwoOffers() {
1553 CreateChannels(0, 0);
1554
Peter Thatchera6d24442015-07-09 21:26:36 -07001555 std::string err;
1556 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1557 CreateSessionDescriptionWithStream(1));
1558 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1559 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1561
Peter Thatchera6d24442015-07-09 21:26:36 -07001562 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1563 CreateSessionDescriptionWithStream(2));
1564 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1565 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1567 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1568 }
1569
1570 void TestReceiveTwoOffers() {
1571 CreateChannels(0, 0);
1572
Peter Thatchera6d24442015-07-09 21:26:36 -07001573 std::string err;
1574 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1575 CreateSessionDescriptionWithStream(1));
1576 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1577 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1579
Peter Thatchera6d24442015-07-09 21:26:36 -07001580 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1581 CreateSessionDescriptionWithStream(2));
1582 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1583 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1585 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1586 }
1587
1588 void TestSendPrAnswer() {
1589 CreateChannels(0, 0);
1590
Peter Thatchera6d24442015-07-09 21:26:36 -07001591 std::string err;
1592 // Receive offer
1593 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1594 CreateSessionDescriptionWithStream(1));
1595 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1596 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1598
Peter Thatchera6d24442015-07-09 21:26:36 -07001599 // Send PR answer
1600 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1601 CreateSessionDescriptionWithStream(2));
1602 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1603 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1605 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1606
Peter Thatchera6d24442015-07-09 21:26:36 -07001607 // Send answer
1608 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1609 CreateSessionDescriptionWithStream(3));
1610 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1611 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1613 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1614 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1615 }
1616
1617 void TestReceivePrAnswer() {
1618 CreateChannels(0, 0);
1619
Peter Thatchera6d24442015-07-09 21:26:36 -07001620 std::string err;
1621 // Send offer
1622 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1623 CreateSessionDescriptionWithStream(1));
1624 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1625 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1627
Peter Thatchera6d24442015-07-09 21:26:36 -07001628 // Receive PR answer
1629 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1630 CreateSessionDescriptionWithStream(2));
1631 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1632 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1634 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1635
Peter Thatchera6d24442015-07-09 21:26:36 -07001636 // Receive answer
1637 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1638 CreateSessionDescriptionWithStream(3));
1639 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1640 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1642 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1643 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1644 }
1645
1646 void TestFlushRtcp() {
1647 bool send_rtcp1;
1648
1649 CreateChannels(RTCP, RTCP);
1650 EXPECT_TRUE(SendInitiate());
1651 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001652 ASSERT_TRUE(GetTransport1());
1653 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 EXPECT_EQ(2U, GetTransport1()->channels().size());
1655 EXPECT_EQ(2U, GetTransport2()->channels().size());
1656
1657 // Send RTCP1 from a different thread.
1658 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1659 EXPECT_TRUE(send_rtcp1);
1660 // The sending message is only posted. channel2_ should be empty.
1661 EXPECT_TRUE(CheckNoRtcp2());
1662
1663 // When channel1_ is deleted, the RTCP packet should be sent out to
1664 // channel2_.
1665 channel1_.reset();
1666 EXPECT_TRUE(CheckRtcp2());
1667 }
1668
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001669 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001670 struct SrtpErrorHandler : public sigslot::has_slots<> {
1671 SrtpErrorHandler() :
1672 mode_(cricket::SrtpFilter::UNPROTECT),
1673 error_(cricket::SrtpFilter::ERROR_NONE) {}
1674 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1675 cricket::SrtpFilter::Error error) {
1676 mode_ = mode;
1677 error_ = error;
1678 }
1679 cricket::SrtpFilter::Mode mode_;
1680 cricket::SrtpFilter::Error error_;
1681 } error_handler;
1682
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001683 // For Audio, only pl_type 0 is added to the bundle filter.
1684 // For Video, only pl_type 97 is added to the bundle filter.
1685 // So we need to pass in pl_type so that the packet can pass through
1686 // the bundle filter before it can be processed by the srtp filter.
1687 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001688 unsigned const char kBadPacket[] = {0x84,
1689 static_cast<unsigned char>(pl_type),
1690 0x00,
1691 0x01,
1692 0x00,
1693 0x00,
1694 0x00,
1695 0x00,
1696 0x00,
1697 0x00,
1698 0x00,
1699 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1701 EXPECT_FALSE(channel1_->secure());
1702 EXPECT_FALSE(channel2_->secure());
1703 EXPECT_TRUE(SendInitiate());
1704 EXPECT_TRUE(SendAccept());
1705 EXPECT_TRUE(channel1_->secure());
1706 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001707 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001708 channel2_->srtp_filter()->SignalSrtpError.connect(
1709 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710
1711 // Testing failures in sending packets.
1712 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1713 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001714 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1715 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1716 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001717 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1718 // The next 250 ms failures will not trigger an error.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1720 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001721 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001722 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001723 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1724 // Wait for a little more - the error will be triggered again.
1725 rtc::Thread::Current()->ProcessMessages(200);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
solenberg5b14b422015-10-01 04:10:31 -07001727 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1728 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729
1730 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001731 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001732 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001733
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 cricket::TransportChannel* transport_channel =
1735 channel2_->transport_channel();
1736 transport_channel->SignalReadPacket(
1737 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001738 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001739 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1740 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001741 }
1742
1743 void TestOnReadyToSend() {
1744 CreateChannels(RTCP, RTCP);
1745 TransportChannel* rtp = channel1_->transport_channel();
1746 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1747 EXPECT_FALSE(media_channel1_->ready_to_send());
1748 rtp->SignalReadyToSend(rtp);
1749 EXPECT_FALSE(media_channel1_->ready_to_send());
1750 rtcp->SignalReadyToSend(rtcp);
1751 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1752 // channel are ready to send.
1753 EXPECT_TRUE(media_channel1_->ready_to_send());
1754
1755 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001756 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001758 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 EXPECT_TRUE(media_channel1_->ready_to_send());
1760
1761 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001762 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001764 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 EXPECT_TRUE(media_channel1_->ready_to_send());
1766 }
1767
1768 void TestOnReadyToSendWithRtcpMux() {
1769 CreateChannels(RTCP, RTCP);
1770 typename T::Content content;
1771 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1772 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1773 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001774 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1775 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1777 TransportChannel* rtp = channel1_->transport_channel();
1778 EXPECT_FALSE(media_channel1_->ready_to_send());
1779 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1780 // should trigger the MediaChannel's OnReadyToSend.
1781 rtp->SignalReadyToSend(rtp);
1782 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001783 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 EXPECT_FALSE(media_channel1_->ready_to_send());
1785 }
1786
1787 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001788 // TODO(pbos): Remove playout from all media channels and let renderers mute
1789 // themselves.
1790 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001791 cricket::FakeTransportController transport_controller1_;
1792 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 cricket::FakeMediaEngine media_engine_;
1794 // The media channels are owned by the voice channel objects below.
1795 typename T::MediaChannel* media_channel1_;
1796 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001797 rtc::scoped_ptr<typename T::Channel> channel1_;
1798 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 typename T::Content local_media_content1_;
1800 typename T::Content local_media_content2_;
1801 typename T::Content remote_media_content1_;
1802 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 // The RTP and RTCP packets to send in the tests.
1804 std::string rtp_packet_;
1805 std::string rtcp_packet_;
1806 int media_info_callbacks1_;
1807 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808};
1809
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810template<>
1811void ChannelTest<VoiceTraits>::CreateContent(
1812 int flags,
1813 const cricket::AudioCodec& audio_codec,
1814 const cricket::VideoCodec& video_codec,
1815 cricket::AudioContentDescription* audio) {
1816 audio->AddCodec(audio_codec);
1817 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1818 if (flags & SECURE) {
1819 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001820 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1821 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 }
1823}
1824
1825template<>
1826void ChannelTest<VoiceTraits>::CopyContent(
1827 const cricket::AudioContentDescription& source,
1828 cricket::AudioContentDescription* audio) {
1829 *audio = source;
1830}
1831
1832template<>
1833bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1834 const cricket::AudioCodec& c2) {
1835 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1836 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1837}
1838
Peter Boström0c4e06b2015-10-07 12:23:21 +02001839template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001841 uint32_t ssrc,
1842 int flags,
1843 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 audio->AddLegacyStream(ssrc);
1845}
1846
1847class VoiceChannelTest
1848 : public ChannelTest<VoiceTraits> {
1849 public:
solenberg1dd98f32015-09-10 01:57:14 -07001850 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001851 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001852 : Base(true,
1853 kPcmuFrame,
1854 sizeof(kPcmuFrame),
1855 kRtcpReport,
1856 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857};
1858
1859// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001860template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001862 rtc::Thread* thread,
1863 cricket::MediaEngineInterface* engine,
1864 cricket::FakeVideoMediaChannel* ch,
1865 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866 bool rtcp) {
1867 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001868 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001869 if (!channel->Init()) {
1870 delete channel;
1871 channel = NULL;
1872 }
1873 return channel;
1874}
1875
1876// override to add 0 parameter
1877template<>
1878bool ChannelTest<VideoTraits>::AddStream1(int id) {
1879 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1880}
1881
1882template<>
1883void ChannelTest<VideoTraits>::CreateContent(
1884 int flags,
1885 const cricket::AudioCodec& audio_codec,
1886 const cricket::VideoCodec& video_codec,
1887 cricket::VideoContentDescription* video) {
1888 video->AddCodec(video_codec);
1889 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1890 if (flags & SECURE) {
1891 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001892 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1893 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 }
1895}
1896
1897template<>
1898void ChannelTest<VideoTraits>::CopyContent(
1899 const cricket::VideoContentDescription& source,
1900 cricket::VideoContentDescription* video) {
1901 *video = source;
1902}
1903
1904template<>
1905bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1906 const cricket::VideoCodec& c2) {
1907 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1908 c1.framerate == c2.framerate;
1909}
1910
Peter Boström0c4e06b2015-10-07 12:23:21 +02001911template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001913 uint32_t ssrc,
1914 int flags,
1915 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916 video->AddLegacyStream(ssrc);
1917}
1918
1919class VideoChannelTest
1920 : public ChannelTest<VideoTraits> {
1921 public:
solenberg1dd98f32015-09-10 01:57:14 -07001922 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001923 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001924 : Base(false,
1925 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001926 sizeof(kH264Packet),
1927 kRtcpReport,
1928 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929};
1930
1931
1932// VoiceChannelTest
1933
1934TEST_F(VoiceChannelTest, TestInit) {
1935 Base::TestInit();
1936 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1937 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1938}
1939
1940TEST_F(VoiceChannelTest, TestSetContents) {
1941 Base::TestSetContents();
1942}
1943
1944TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1945 Base::TestSetContentsNullOffer();
1946}
1947
1948TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1949 Base::TestSetContentsRtcpMux();
1950}
1951
1952TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1953 Base::TestSetContentsRtcpMux();
1954}
1955
1956TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1957 Base::TestSetRemoteContentUpdate();
1958}
1959
1960TEST_F(VoiceChannelTest, TestStreams) {
1961 Base::TestStreams();
1962}
1963
1964TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1965 Base::TestUpdateStreamsInLocalContent();
1966}
1967
1968TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1969 Base::TestUpdateStreamsInRemoteContent();
1970}
1971
1972TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1973 Base::TestChangeStreamParamsInContent();
1974}
1975
1976TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1977 Base::TestPlayoutAndSendingStates();
1978}
1979
1980TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001981 CreateChannels(0, 0);
1982 // Test that we can Mute the default channel even though the sending SSRC
1983 // is unknown.
1984 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07001985 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001986 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1987 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001988 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1989
1990 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07001991 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001992
1993 SendInitiate();
1994 // After the local session description has been set, we can mute a stream
1995 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07001996 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001997 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
1998 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001999 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000}
2001
2002TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2003 Base::TestMediaContentDirection();
2004}
2005
2006TEST_F(VoiceChannelTest, TestCallSetup) {
2007 Base::TestCallSetup();
2008}
2009
2010TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2011 Base::TestCallTeardownRtcpMux();
2012}
2013
2014TEST_F(VoiceChannelTest, SendRtpToRtp) {
2015 Base::SendRtpToRtp();
2016}
2017
2018TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2019 Base::SendNoRtcpToNoRtcp();
2020}
2021
2022TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2023 Base::SendNoRtcpToRtcp();
2024}
2025
2026TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2027 Base::SendRtcpToNoRtcp();
2028}
2029
2030TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2031 Base::SendRtcpToRtcp();
2032}
2033
2034TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2035 Base::SendRtcpMuxToRtcp();
2036}
2037
2038TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2039 Base::SendRtcpMuxToRtcpMux();
2040}
2041
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002042TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2043 Base::SendRequireRtcpMuxToRtcpMux();
2044}
2045
2046TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2047 Base::SendRtcpMuxToRequireRtcpMux();
2048}
2049
2050TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2051 Base::SendRequireRtcpMuxToRequireRtcpMux();
2052}
2053
2054TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2055 Base::SendRequireRtcpMuxToNoRtcpMux();
2056}
2057
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2059 Base::SendEarlyRtcpMuxToRtcp();
2060}
2061
2062TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2063 Base::SendEarlyRtcpMuxToRtcpMux();
2064}
2065
2066TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2067 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2068}
2069
2070TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2071 Base::SendSrtpToSrtp();
2072}
2073
2074TEST_F(VoiceChannelTest, SendSrtcpMux) {
2075 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2076}
2077
2078TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2079 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2080 Base::SendSrtpToSrtp(DTLS, 0);
2081}
2082
2083TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2084 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2085 Base::SendSrtpToSrtp(DTLS, DTLS);
2086}
2087
2088TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2089 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2090 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2091}
2092
2093TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2094 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2095}
2096
2097TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2098 Base::SendRtpToRtpOnThread();
2099}
2100
2101TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2102 Base::SendSrtpToSrtpOnThread();
2103}
2104
2105TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2106 Base::SendWithWritabilityLoss();
2107}
2108
2109TEST_F(VoiceChannelTest, TestMediaMonitor) {
2110 Base::TestMediaMonitor();
2111}
2112
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113// Test that PressDTMF properly forwards to the media channel.
2114TEST_F(VoiceChannelTest, TestDtmf) {
2115 CreateChannels(0, 0);
2116 EXPECT_TRUE(SendInitiate());
2117 EXPECT_TRUE(SendAccept());
2118 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2119
2120 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2121 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2122
2123 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2124 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2125 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2126 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2127 0, 8, 160, cricket::DF_SEND));
2128}
2129
2130// Test that InsertDtmf properly forwards to the media channel.
2131TEST_F(VoiceChannelTest, TestInsertDtmf) {
2132 CreateChannels(0, 0);
2133 EXPECT_TRUE(SendInitiate());
2134 EXPECT_TRUE(SendAccept());
2135 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2138 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2139 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2140 cricket::DF_PLAY | cricket::DF_SEND));
2141
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002142 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002145 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002147 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002148 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2149}
2150
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151TEST_F(VoiceChannelTest, TestSetContentFailure) {
2152 Base::TestSetContentFailure();
2153}
2154
2155TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2156 Base::TestSendTwoOffers();
2157}
2158
2159TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2160 Base::TestReceiveTwoOffers();
2161}
2162
2163TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2164 Base::TestSendPrAnswer();
2165}
2166
2167TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2168 Base::TestReceivePrAnswer();
2169}
2170
2171TEST_F(VoiceChannelTest, TestFlushRtcp) {
2172 Base::TestFlushRtcp();
2173}
2174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002176 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177}
2178
2179TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2180 Base::TestOnReadyToSend();
2181}
2182
2183TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2184 Base::TestOnReadyToSendWithRtcpMux();
2185}
2186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187// Test that we can scale the output volume properly for 1:1 calls.
2188TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2189 CreateChannels(RTCP, RTCP);
2190 EXPECT_TRUE(SendInitiate());
2191 EXPECT_TRUE(SendAccept());
2192 double left, right;
2193
2194 // Default is (1.0, 1.0).
2195 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2196 EXPECT_DOUBLE_EQ(1.0, left);
2197 EXPECT_DOUBLE_EQ(1.0, right);
2198 // invalid ssrc.
2199 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2200
2201 // Set scale to (1.5, 0.5).
2202 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2203 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2204 EXPECT_DOUBLE_EQ(1.5, left);
2205 EXPECT_DOUBLE_EQ(0.5, right);
2206
2207 // Set scale to (0, 0).
2208 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2209 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2210 EXPECT_DOUBLE_EQ(0.0, left);
2211 EXPECT_DOUBLE_EQ(0.0, right);
2212}
2213
2214// Test that we can scale the output volume properly for multiway calls.
2215TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2216 CreateChannels(RTCP, RTCP);
2217 EXPECT_TRUE(SendInitiate());
2218 EXPECT_TRUE(SendAccept());
2219 EXPECT_TRUE(AddStream1(1));
2220 EXPECT_TRUE(AddStream1(2));
2221
2222 double left, right;
2223 // Default is (1.0, 1.0).
2224 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2225 EXPECT_DOUBLE_EQ(1.0, left);
2226 EXPECT_DOUBLE_EQ(1.0, right);
2227 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2228 EXPECT_DOUBLE_EQ(1.0, left);
2229 EXPECT_DOUBLE_EQ(1.0, right);
2230 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2231 EXPECT_DOUBLE_EQ(1.0, left);
2232 EXPECT_DOUBLE_EQ(1.0, right);
2233 // invalid ssrc.
2234 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2235
2236 // Set scale to (1.5, 0.5) for ssrc = 1.
2237 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2238 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2239 EXPECT_DOUBLE_EQ(1.5, left);
2240 EXPECT_DOUBLE_EQ(0.5, right);
2241 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2242 EXPECT_DOUBLE_EQ(1.0, left);
2243 EXPECT_DOUBLE_EQ(1.0, right);
2244 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2245 EXPECT_DOUBLE_EQ(1.0, left);
2246 EXPECT_DOUBLE_EQ(1.0, right);
2247
2248 // Set scale to (0, 0) for all ssrcs.
2249 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2250 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2251 EXPECT_DOUBLE_EQ(0.0, left);
2252 EXPECT_DOUBLE_EQ(0.0, right);
2253 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2254 EXPECT_DOUBLE_EQ(0.0, left);
2255 EXPECT_DOUBLE_EQ(0.0, right);
2256 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2257 EXPECT_DOUBLE_EQ(0.0, left);
2258 EXPECT_DOUBLE_EQ(0.0, right);
2259}
2260
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002261TEST_F(VoiceChannelTest, SendBundleToBundle) {
2262 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263}
2264
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002265TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2266 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2267}
2268
2269TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2270 Base::SendBundleToBundle(
2271 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2272}
2273
2274TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2275 Base::SendBundleToBundle(
2276 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277}
2278
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279// VideoChannelTest
2280TEST_F(VideoChannelTest, TestInit) {
2281 Base::TestInit();
2282}
2283
2284TEST_F(VideoChannelTest, TestSetContents) {
2285 Base::TestSetContents();
2286}
2287
2288TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2289 Base::TestSetContentsNullOffer();
2290}
2291
2292TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2293 Base::TestSetContentsRtcpMux();
2294}
2295
2296TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2297 Base::TestSetContentsRtcpMux();
2298}
2299
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2301 Base::TestSetRemoteContentUpdate();
2302}
2303
2304TEST_F(VideoChannelTest, TestStreams) {
2305 Base::TestStreams();
2306}
2307
2308TEST_F(VideoChannelTest, TestScreencastEvents) {
2309 const int kTimeoutMs = 500;
2310 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 cricket::ScreencastEventCatcher catcher;
2312 channel1_->SignalScreencastWindowEvent.connect(
2313 &catcher,
2314 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002315
2316 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2317 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2318 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2319 ScreencastId(WindowId(0)));
2320 ASSERT_TRUE(screen_capturer != NULL);
2321
2322 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2323 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002325
2326 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002327 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002328
2329 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002330 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002331
2332 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002333 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002334
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336}
2337
2338TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2339 Base::TestUpdateStreamsInLocalContent();
2340}
2341
2342TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2343 Base::TestUpdateStreamsInRemoteContent();
2344}
2345
2346TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2347 Base::TestChangeStreamParamsInContent();
2348}
2349
2350TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2351 Base::TestPlayoutAndSendingStates();
2352}
2353
2354TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002355 CreateChannels(0, 0);
2356 // Test that we can Mute the default channel even though the sending SSRC
2357 // is unknown.
2358 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002359 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002360 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2361 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002362 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2363 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002364 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002365 SendInitiate();
2366 // After the local session description has been set, we can mute a stream
2367 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002368 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002369 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2370 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002371 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002372}
2373
2374TEST_F(VideoChannelTest, TestMediaContentDirection) {
2375 Base::TestMediaContentDirection();
2376}
2377
2378TEST_F(VideoChannelTest, TestCallSetup) {
2379 Base::TestCallSetup();
2380}
2381
2382TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2383 Base::TestCallTeardownRtcpMux();
2384}
2385
2386TEST_F(VideoChannelTest, SendRtpToRtp) {
2387 Base::SendRtpToRtp();
2388}
2389
2390TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2391 Base::SendNoRtcpToNoRtcp();
2392}
2393
2394TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2395 Base::SendNoRtcpToRtcp();
2396}
2397
2398TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2399 Base::SendRtcpToNoRtcp();
2400}
2401
2402TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2403 Base::SendRtcpToRtcp();
2404}
2405
2406TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2407 Base::SendRtcpMuxToRtcp();
2408}
2409
2410TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2411 Base::SendRtcpMuxToRtcpMux();
2412}
2413
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002414TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2415 Base::SendRequireRtcpMuxToRtcpMux();
2416}
2417
2418TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2419 Base::SendRtcpMuxToRequireRtcpMux();
2420}
2421
2422TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2423 Base::SendRequireRtcpMuxToRequireRtcpMux();
2424}
2425
2426TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2427 Base::SendRequireRtcpMuxToNoRtcpMux();
2428}
2429
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2431 Base::SendEarlyRtcpMuxToRtcp();
2432}
2433
2434TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2435 Base::SendEarlyRtcpMuxToRtcpMux();
2436}
2437
2438TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2439 Base::SendSrtpToSrtp();
2440}
2441
2442TEST_F(VideoChannelTest, SendSrtpToRtp) {
2443 Base::SendSrtpToSrtp();
2444}
2445
2446TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2447 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2448 Base::SendSrtpToSrtp(DTLS, 0);
2449}
2450
2451TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2452 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2453 Base::SendSrtpToSrtp(DTLS, DTLS);
2454}
2455
2456TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2457 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2458 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2459}
2460
2461TEST_F(VideoChannelTest, SendSrtcpMux) {
2462 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2463}
2464
2465TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2466 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2467}
2468
2469TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2470 Base::SendRtpToRtpOnThread();
2471}
2472
2473TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2474 Base::SendSrtpToSrtpOnThread();
2475}
2476
2477TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2478 Base::SendWithWritabilityLoss();
2479}
2480
2481TEST_F(VideoChannelTest, TestMediaMonitor) {
2482 Base::TestMediaMonitor();
2483}
2484
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485TEST_F(VideoChannelTest, TestSetContentFailure) {
2486 Base::TestSetContentFailure();
2487}
2488
2489TEST_F(VideoChannelTest, TestSendTwoOffers) {
2490 Base::TestSendTwoOffers();
2491}
2492
2493TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2494 Base::TestReceiveTwoOffers();
2495}
2496
2497TEST_F(VideoChannelTest, TestSendPrAnswer) {
2498 Base::TestSendPrAnswer();
2499}
2500
2501TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2502 Base::TestReceivePrAnswer();
2503}
2504
2505TEST_F(VideoChannelTest, TestFlushRtcp) {
2506 Base::TestFlushRtcp();
2507}
2508
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002509TEST_F(VideoChannelTest, SendBundleToBundle) {
2510 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511}
2512
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002513TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2514 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2515}
2516
2517TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2518 Base::SendBundleToBundle(
2519 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2520}
2521
2522TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2523 Base::SendBundleToBundle(
2524 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525}
2526
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002528 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002529}
2530
2531TEST_F(VideoChannelTest, TestOnReadyToSend) {
2532 Base::TestOnReadyToSend();
2533}
2534
2535TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2536 Base::TestOnReadyToSendWithRtcpMux();
2537}
2538
2539TEST_F(VideoChannelTest, TestApplyViewRequest) {
2540 CreateChannels(0, 0);
2541 cricket::StreamParams stream2;
2542 stream2.id = "stream2";
2543 stream2.ssrcs.push_back(2222);
2544 local_media_content1_.AddStream(stream2);
2545
2546 EXPECT_TRUE(SendInitiate());
2547 EXPECT_TRUE(SendAccept());
2548
2549 cricket::VideoFormat send_format;
2550 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2551 EXPECT_EQ(640, send_format.width);
2552 EXPECT_EQ(400, send_format.height);
2553 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2554
2555 cricket::ViewRequest request;
2556 // stream1: 320x200x15; stream2: 0x0x0
2557 request.static_video_views.push_back(cricket::StaticVideoView(
2558 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2559 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2560 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2561 EXPECT_EQ(320, send_format.width);
2562 EXPECT_EQ(200, send_format.height);
2563 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2564 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2565 EXPECT_EQ(0, send_format.width);
2566 EXPECT_EQ(0, send_format.height);
2567
2568 // stream1: 160x100x8; stream2: 0x0x0
2569 request.static_video_views.clear();
2570 request.static_video_views.push_back(cricket::StaticVideoView(
2571 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2572 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2573 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2574 EXPECT_EQ(160, send_format.width);
2575 EXPECT_EQ(100, send_format.height);
2576 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2577
2578 // stream1: 0x0x0; stream2: 640x400x30
2579 request.static_video_views.clear();
2580 request.static_video_views.push_back(cricket::StaticVideoView(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002581 cricket::StreamSelector(std::string(), stream2.id), 640, 400, 30));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2583 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2584 EXPECT_EQ(0, send_format.width);
2585 EXPECT_EQ(0, send_format.height);
2586 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2587 EXPECT_EQ(640, send_format.width);
2588 EXPECT_EQ(400, send_format.height);
2589 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2590
2591 // stream1: 0x0x0; stream2: 0x0x0
2592 request.static_video_views.clear();
2593 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2594 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2595 EXPECT_EQ(0, send_format.width);
2596 EXPECT_EQ(0, send_format.height);
2597}
2598
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002599
2600// DataChannelTest
2601
2602class DataChannelTest
2603 : public ChannelTest<DataTraits> {
2604 public:
2605 typedef ChannelTest<DataTraits>
2606 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002607 DataChannelTest()
2608 : Base(true,
2609 kDataPacket,
2610 sizeof(kDataPacket),
2611 kRtcpReport,
2612 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613};
2614
2615// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002616template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002617cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002618 rtc::Thread* thread,
2619 cricket::MediaEngineInterface* engine,
2620 cricket::FakeDataMediaChannel* ch,
2621 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 bool rtcp) {
2623 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002624 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 if (!channel->Init()) {
2626 delete channel;
2627 channel = NULL;
2628 }
2629 return channel;
2630}
2631
2632template<>
2633void ChannelTest<DataTraits>::CreateContent(
2634 int flags,
2635 const cricket::AudioCodec& audio_codec,
2636 const cricket::VideoCodec& video_codec,
2637 cricket::DataContentDescription* data) {
2638 data->AddCodec(kGoogleDataCodec);
2639 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2640 if (flags & SECURE) {
2641 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002642 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2643 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 }
2645}
2646
2647template<>
2648void ChannelTest<DataTraits>::CopyContent(
2649 const cricket::DataContentDescription& source,
2650 cricket::DataContentDescription* data) {
2651 *data = source;
2652}
2653
2654template<>
2655bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2656 const cricket::DataCodec& c2) {
2657 return c1.name == c2.name;
2658}
2659
Peter Boström0c4e06b2015-10-07 12:23:21 +02002660template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002662 uint32_t ssrc,
2663 int flags,
2664 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 data->AddLegacyStream(ssrc);
2666}
2667
2668TEST_F(DataChannelTest, TestInit) {
2669 Base::TestInit();
2670 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2671}
2672
2673TEST_F(DataChannelTest, TestSetContents) {
2674 Base::TestSetContents();
2675}
2676
2677TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2678 Base::TestSetContentsNullOffer();
2679}
2680
2681TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2682 Base::TestSetContentsRtcpMux();
2683}
2684
2685TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2686 Base::TestSetRemoteContentUpdate();
2687}
2688
2689TEST_F(DataChannelTest, TestStreams) {
2690 Base::TestStreams();
2691}
2692
2693TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2694 Base::TestUpdateStreamsInLocalContent();
2695}
2696
2697TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2698 Base::TestUpdateStreamsInRemoteContent();
2699}
2700
2701TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2702 Base::TestChangeStreamParamsInContent();
2703}
2704
2705TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2706 Base::TestPlayoutAndSendingStates();
2707}
2708
2709TEST_F(DataChannelTest, TestMediaContentDirection) {
2710 Base::TestMediaContentDirection();
2711}
2712
2713TEST_F(DataChannelTest, TestCallSetup) {
2714 Base::TestCallSetup();
2715}
2716
2717TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2718 Base::TestCallTeardownRtcpMux();
2719}
2720
2721TEST_F(DataChannelTest, TestOnReadyToSend) {
2722 Base::TestOnReadyToSend();
2723}
2724
2725TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2726 Base::TestOnReadyToSendWithRtcpMux();
2727}
2728
2729TEST_F(DataChannelTest, SendRtpToRtp) {
2730 Base::SendRtpToRtp();
2731}
2732
2733TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2734 Base::SendNoRtcpToNoRtcp();
2735}
2736
2737TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2738 Base::SendNoRtcpToRtcp();
2739}
2740
2741TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2742 Base::SendRtcpToNoRtcp();
2743}
2744
2745TEST_F(DataChannelTest, SendRtcpToRtcp) {
2746 Base::SendRtcpToRtcp();
2747}
2748
2749TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2750 Base::SendRtcpMuxToRtcp();
2751}
2752
2753TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2754 Base::SendRtcpMuxToRtcpMux();
2755}
2756
2757TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2758 Base::SendEarlyRtcpMuxToRtcp();
2759}
2760
2761TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2762 Base::SendEarlyRtcpMuxToRtcpMux();
2763}
2764
2765TEST_F(DataChannelTest, SendSrtpToSrtp) {
2766 Base::SendSrtpToSrtp();
2767}
2768
2769TEST_F(DataChannelTest, SendSrtpToRtp) {
2770 Base::SendSrtpToSrtp();
2771}
2772
2773TEST_F(DataChannelTest, SendSrtcpMux) {
2774 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2775}
2776
2777TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2778 Base::SendRtpToRtpOnThread();
2779}
2780
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002781TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2782 Base::SendSrtpToSrtpOnThread();
2783}
2784
2785TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2786 Base::SendWithWritabilityLoss();
2787}
2788
2789TEST_F(DataChannelTest, TestMediaMonitor) {
2790 Base::TestMediaMonitor();
2791}
2792
2793TEST_F(DataChannelTest, TestSendData) {
2794 CreateChannels(0, 0);
2795 EXPECT_TRUE(SendInitiate());
2796 EXPECT_TRUE(SendAccept());
2797
2798 cricket::SendDataParams params;
2799 params.ssrc = 42;
2800 unsigned char data[] = {
2801 'f', 'o', 'o'
2802 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002803 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002804 cricket::SendDataResult result;
2805 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2806 EXPECT_EQ(params.ssrc,
2807 media_channel1_->last_sent_data_params().ssrc);
2808 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2809}
2810
2811// TODO(pthatcher): TestSetReceiver?