blob: 7f76e167d352088476d74a06345d57b00d5ff557 [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);
70static const uint32 kSsrc1 = 0x1111;
71static const uint32 kSsrc2 = 0x2222;
72static const uint32 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,
130 const uint8* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700131 int rtp_len,
132 const uint8* rtcp_data,
133 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.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000312 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
313 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 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000317 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
318 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 }
322 bool SendCustomRtcp1(uint32 ssrc) {
323 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 }
327 bool SendCustomRtcp2(uint32 ssrc) {
328 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.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000349 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
350 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 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000354 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
355 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 }
359 bool CheckCustomRtcp1(uint32 ssrc) {
360 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 }
364 bool CheckCustomRtcp2(uint32 ssrc) {
365 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 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000369 std::string CreateRtpData(uint32 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 }
380 std::string CreateRtcpData(uint32 ssrc) {
381 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.
413 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
414 typename T::Content content;
415 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
416 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
417 AddLegacyStreamInContent(ssrc, 0, &content);
418 sdesc->AddContent("DUMMY_CONTENT_NAME",
419 cricket::NS_JINGLE_RTP, content.Copy());
420 return sdesc;
421 }
422
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000423 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 public:
425 typedef bool (ChannelTest<T>::*Method)();
426 CallThread(ChannelTest<T>* obj, Method method, bool* result)
427 : obj_(obj),
428 method_(method),
429 result_(result) {
430 *result = false;
431 }
432 virtual void DoWork() {
433 bool result = (*obj_.*method_)();
434 if (result_) {
435 *result_ = result;
436 }
437 }
438 private:
439 ChannelTest<T>* obj_;
440 Method method_;
441 bool* result_;
442 };
443 void CallOnThread(typename CallThread::Method method, bool* result) {
444 CallThread* thread = new CallThread(this, method, result);
445 thread->Start();
446 thread->Release();
447 }
448
449 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
450 bool* result) {
451 CallThread* thread = new CallThread(this, method, result);
452 thread->Start();
453 thread->Destroy(true);
454 }
455
456 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
457 return false; // overridden in specialized classes
458 }
459
460 void OnMediaMonitor(typename T::Channel* channel,
461 const typename T::MediaInfo& info) {
462 if (channel == channel1_.get()) {
463 media_info_callbacks1_++;
464 } else if (channel == channel2_.get()) {
465 media_info_callbacks2_++;
466 }
467 }
468
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 void AddLegacyStreamInContent(uint32 ssrc, int flags,
470 typename T::Content* content) {
471 // Base implementation.
472 }
473
474 // Tests that can be used by derived classes.
475
476 // Basic sanity check.
477 void TestInit() {
478 CreateChannels(0, 0);
479 EXPECT_FALSE(channel1_->secure());
480 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200481 if (verify_playout_) {
482 EXPECT_FALSE(media_channel1_->playout());
483 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 EXPECT_TRUE(media_channel1_->codecs().empty());
485 EXPECT_TRUE(media_channel1_->recv_streams().empty());
486 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
487 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
488 }
489
490 // Test that SetLocalContent and SetRemoteContent properly configure
491 // the codecs.
492 void TestSetContents() {
493 CreateChannels(0, 0);
494 typename T::Content content;
495 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000496 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000497 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000498 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 ASSERT_EQ(1U, media_channel1_->codecs().size());
500 EXPECT_TRUE(CodecMatches(content.codecs()[0],
501 media_channel1_->codecs()[0]));
502 }
503
504 // Test that SetLocalContent and SetRemoteContent properly deals
505 // with an empty offer.
506 void TestSetContentsNullOffer() {
507 CreateChannels(0, 0);
508 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000509 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 CreateContent(0, kPcmuCodec, kH264Codec, &content);
511 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000512 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 ASSERT_EQ(1U, media_channel1_->codecs().size());
514 EXPECT_TRUE(CodecMatches(content.codecs()[0],
515 media_channel1_->codecs()[0]));
516 }
517
518 // Test that SetLocalContent and SetRemoteContent properly set RTCP
519 // mux.
520 void TestSetContentsRtcpMux() {
521 CreateChannels(RTCP, RTCP);
522 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
523 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
524 typename T::Content content;
525 CreateContent(0, kPcmuCodec, kH264Codec, &content);
526 // Both sides agree on mux. Should no longer be a separate RTCP channel.
527 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000528 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
529 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
531 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000532 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000534 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
536 }
537
538 // Test that SetLocalContent and SetRemoteContent properly set RTCP
539 // mux when a provisional answer is received.
540 void TestSetContentsRtcpMuxWithPrAnswer() {
541 CreateChannels(RTCP, RTCP);
542 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
543 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
544 typename T::Content content;
545 CreateContent(0, kPcmuCodec, kH264Codec, &content);
546 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000547 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
548 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000550 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 // Both sides agree on mux. Should no longer be a separate RTCP channel.
552 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
553 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000554 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000556 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
557 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
559 }
560
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 // Test that SetRemoteContent properly deals with a content update.
562 void TestSetRemoteContentUpdate() {
563 CreateChannels(0, 0);
564 typename T::Content content;
565 CreateContent(RTCP | RTCP_MUX | SECURE,
566 kPcmuCodec, kH264Codec,
567 &content);
568 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000569 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
570 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 ASSERT_EQ(1U, media_channel1_->codecs().size());
572 EXPECT_TRUE(CodecMatches(content.codecs()[0],
573 media_channel1_->codecs()[0]));
574 // Now update with other codecs.
575 typename T::Content update_content;
576 update_content.set_partial(true);
577 CreateContent(0, kIsacCodec, kH264SvcCodec,
578 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000579 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 ASSERT_EQ(1U, media_channel1_->codecs().size());
581 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
582 media_channel1_->codecs()[0]));
583 // Now update without any codecs. This is ignored.
584 typename T::Content empty_content;
585 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000586 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 ASSERT_EQ(1U, media_channel1_->codecs().size());
588 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
589 media_channel1_->codecs()[0]));
590 }
591
592 // Test that Add/RemoveStream properly forward to the media channel.
593 void TestStreams() {
594 CreateChannels(0, 0);
595 EXPECT_TRUE(AddStream1(1));
596 EXPECT_TRUE(AddStream1(2));
597 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
598 EXPECT_TRUE(RemoveStream1(2));
599 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
600 EXPECT_TRUE(RemoveStream1(1));
601 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
602 }
603
604 // Test that SetLocalContent properly handles adding and removing StreamParams
605 // to the local content description.
606 // This test uses the CA_UPDATE action that don't require a full
607 // MediaContentDescription to do an update.
608 void TestUpdateStreamsInLocalContent() {
609 cricket::StreamParams stream1;
610 stream1.groupid = "group1";
611 stream1.id = "stream1";
612 stream1.ssrcs.push_back(kSsrc1);
613 stream1.cname = "stream1_cname";
614
615 cricket::StreamParams stream2;
616 stream2.groupid = "group2";
617 stream2.id = "stream2";
618 stream2.ssrcs.push_back(kSsrc2);
619 stream2.cname = "stream2_cname";
620
621 cricket::StreamParams stream3;
622 stream3.groupid = "group3";
623 stream3.id = "stream3";
624 stream3.ssrcs.push_back(kSsrc3);
625 stream3.cname = "stream3_cname";
626
627 CreateChannels(0, 0);
628 typename T::Content content1;
629 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
630 content1.AddStream(stream1);
631 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000632 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
634 ASSERT_EQ(1u, media_channel1_->send_streams().size());
635 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
636
637 // Update the local streams by adding another sending stream.
638 // Use a partial updated session description.
639 typename T::Content content2;
640 content2.AddStream(stream2);
641 content2.AddStream(stream3);
642 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000643 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 ASSERT_EQ(3u, media_channel1_->send_streams().size());
645 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
646 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
647 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
648
649 // Update the local streams by removing the first sending stream.
650 // This is done by removing all SSRCS for this particular stream.
651 typename T::Content content3;
652 stream1.ssrcs.clear();
653 content3.AddStream(stream1);
654 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000655 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 ASSERT_EQ(2u, media_channel1_->send_streams().size());
657 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
658 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
659
660 // Update the local streams with a stream that does not change.
661 // THe update is ignored.
662 typename T::Content content4;
663 content4.AddStream(stream2);
664 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000665 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 ASSERT_EQ(2u, media_channel1_->send_streams().size());
667 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
668 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
669 }
670
671 // Test that SetRemoteContent properly handles adding and removing
672 // StreamParams to the remote content description.
673 // This test uses the CA_UPDATE action that don't require a full
674 // MediaContentDescription to do an update.
675 void TestUpdateStreamsInRemoteContent() {
676 cricket::StreamParams stream1;
677 stream1.id = "Stream1";
678 stream1.groupid = "1";
679 stream1.ssrcs.push_back(kSsrc1);
680 stream1.cname = "stream1_cname";
681
682 cricket::StreamParams stream2;
683 stream2.id = "Stream2";
684 stream2.groupid = "2";
685 stream2.ssrcs.push_back(kSsrc2);
686 stream2.cname = "stream2_cname";
687
688 cricket::StreamParams stream3;
689 stream3.id = "Stream3";
690 stream3.groupid = "3";
691 stream3.ssrcs.push_back(kSsrc3);
692 stream3.cname = "stream3_cname";
693
694 CreateChannels(0, 0);
695 typename T::Content content1;
696 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
697 content1.AddStream(stream1);
698 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700
701 ASSERT_EQ(1u, media_channel1_->codecs().size());
702 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
703 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
704
705 // Update the remote streams by adding another sending stream.
706 // Use a partial updated session description.
707 typename T::Content content2;
708 content2.AddStream(stream2);
709 content2.AddStream(stream3);
710 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000711 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
713 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
714 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
715 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
716
717 // Update the remote streams by removing the first stream.
718 // This is done by removing all SSRCS for this particular stream.
719 typename T::Content content3;
720 stream1.ssrcs.clear();
721 content3.AddStream(stream1);
722 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000723 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
725 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
726 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
727
728 // Update the remote streams with a stream that does not change.
729 // The update is ignored.
730 typename T::Content content4;
731 content4.AddStream(stream2);
732 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000733 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
735 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
736 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
737 }
738
739 // Test that SetLocalContent and SetRemoteContent properly
740 // handles adding and removing StreamParams when the action is a full
741 // CA_OFFER / CA_ANSWER.
742 void TestChangeStreamParamsInContent() {
743 cricket::StreamParams stream1;
744 stream1.groupid = "group1";
745 stream1.id = "stream1";
746 stream1.ssrcs.push_back(kSsrc1);
747 stream1.cname = "stream1_cname";
748
749 cricket::StreamParams stream2;
750 stream2.groupid = "group1";
751 stream2.id = "stream2";
752 stream2.ssrcs.push_back(kSsrc2);
753 stream2.cname = "stream2_cname";
754
755 // Setup a call where channel 1 send |stream1| to channel 2.
756 CreateChannels(0, 0);
757 typename T::Content content1;
758 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
759 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000760 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 EXPECT_TRUE(channel1_->Enable(true));
762 EXPECT_EQ(1u, media_channel1_->send_streams().size());
763
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000764 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700766 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767
768 // Channel 2 do not send anything.
769 typename T::Content content2;
770 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000771 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000773 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 EXPECT_TRUE(channel2_->Enable(true));
775 EXPECT_EQ(0u, media_channel2_->send_streams().size());
776
777 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
778 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
779
780 // Let channel 2 update the content by sending |stream2| and enable SRTP.
781 typename T::Content content3;
782 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
783 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000784 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 ASSERT_EQ(1u, media_channel2_->send_streams().size());
786 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
787
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000788 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
790 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
791
792 // Channel 1 replies but stop sending stream1.
793 typename T::Content content4;
794 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000795 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 EXPECT_EQ(0u, media_channel1_->send_streams().size());
797
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000798 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
800
801 EXPECT_TRUE(channel1_->secure());
802 EXPECT_TRUE(channel2_->secure());
803 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
804 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
805 }
806
807 // Test that we only start playout and sending at the right times.
808 void TestPlayoutAndSendingStates() {
809 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200810 if (verify_playout_) {
811 EXPECT_FALSE(media_channel1_->playout());
812 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200814 if (verify_playout_) {
815 EXPECT_FALSE(media_channel2_->playout());
816 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_FALSE(media_channel2_->sending());
818 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200819 if (verify_playout_) {
820 EXPECT_FALSE(media_channel1_->playout());
821 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000823 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
824 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200825 if (verify_playout_) {
826 EXPECT_TRUE(media_channel1_->playout());
827 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000829 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
830 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200831 if (verify_playout_) {
832 EXPECT_FALSE(media_channel2_->playout());
833 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000835 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
836 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200837 if (verify_playout_) {
838 EXPECT_FALSE(media_channel2_->playout());
839 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700841 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200842 if (verify_playout_) {
843 EXPECT_TRUE(media_channel1_->playout());
844 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200846 if (verify_playout_) {
847 EXPECT_FALSE(media_channel2_->playout());
848 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 EXPECT_FALSE(media_channel2_->sending());
850 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200851 if (verify_playout_) {
852 EXPECT_TRUE(media_channel2_->playout());
853 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000855 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
856 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200857 if (verify_playout_) {
858 EXPECT_TRUE(media_channel1_->playout());
859 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 EXPECT_TRUE(media_channel1_->sending());
861 }
862
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 // Test that changing the MediaContentDirection in the local and remote
864 // session description start playout and sending at the right time.
865 void TestMediaContentDirection() {
866 CreateChannels(0, 0);
867 typename T::Content content1;
868 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
869 typename T::Content content2;
870 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
871 // Set |content2| to be InActive.
872 content2.set_direction(cricket::MD_INACTIVE);
873
874 EXPECT_TRUE(channel1_->Enable(true));
875 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200876 if (verify_playout_) {
877 EXPECT_FALSE(media_channel1_->playout());
878 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200880 if (verify_playout_) {
881 EXPECT_FALSE(media_channel2_->playout());
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_FALSE(media_channel2_->sending());
884
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000885 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
886 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
887 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
888 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700889 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890
Peter Boström34fbfff2015-09-24 19:20:30 +0200891 if (verify_playout_) {
892 EXPECT_TRUE(media_channel1_->playout());
893 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200895 if (verify_playout_) {
896 EXPECT_FALSE(media_channel2_->playout()); // local InActive
897 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 EXPECT_FALSE(media_channel2_->sending()); // local InActive
899
900 // Update |content2| to be RecvOnly.
901 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000902 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
903 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
Peter Boström34fbfff2015-09-24 19:20:30 +0200905 if (verify_playout_) {
906 EXPECT_TRUE(media_channel1_->playout());
907 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200909 if (verify_playout_) {
910 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
913
914 // Update |content2| to be SendRecv.
915 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000916 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
917 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918
Peter Boström34fbfff2015-09-24 19:20:30 +0200919 if (verify_playout_) {
920 EXPECT_TRUE(media_channel1_->playout());
921 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200923 if (verify_playout_) {
924 EXPECT_TRUE(media_channel2_->playout());
925 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 EXPECT_TRUE(media_channel2_->sending());
927 }
928
929 // Test setting up a call.
930 void TestCallSetup() {
931 CreateChannels(0, 0);
932 EXPECT_FALSE(channel1_->secure());
933 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200934 if (verify_playout_) {
935 EXPECT_TRUE(media_channel1_->playout());
936 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 EXPECT_FALSE(media_channel1_->sending());
938 EXPECT_TRUE(SendAccept());
939 EXPECT_FALSE(channel1_->secure());
940 EXPECT_TRUE(media_channel1_->sending());
941 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200942 if (verify_playout_) {
943 EXPECT_TRUE(media_channel2_->playout());
944 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 EXPECT_TRUE(media_channel2_->sending());
946 EXPECT_EQ(1U, media_channel2_->codecs().size());
947 }
948
949 // Test that we don't crash if packets are sent during call teardown
950 // when RTCP mux is enabled. This is a regression test against a specific
951 // race condition that would only occur when a RTCP packet was sent during
952 // teardown of a channel on which RTCP mux was enabled.
953 void TestCallTeardownRtcpMux() {
954 class LastWordMediaChannel : public T::MediaChannel {
955 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200956 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 ~LastWordMediaChannel() {
958 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
959 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
960 }
961 };
962 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
963 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000964 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 EXPECT_TRUE(SendInitiate());
966 EXPECT_TRUE(SendAccept());
967 EXPECT_TRUE(SendTerminate());
968 }
969
970 // Send voice RTP data to the other side and ensure it gets there.
971 void SendRtpToRtp() {
972 CreateChannels(0, 0);
973 EXPECT_TRUE(SendInitiate());
974 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700975 ASSERT_TRUE(GetTransport1());
976 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 EXPECT_EQ(1U, GetTransport1()->channels().size());
978 EXPECT_EQ(1U, GetTransport2()->channels().size());
979 EXPECT_TRUE(SendRtp1());
980 EXPECT_TRUE(SendRtp2());
981 EXPECT_TRUE(CheckRtp1());
982 EXPECT_TRUE(CheckRtp2());
983 EXPECT_TRUE(CheckNoRtp1());
984 EXPECT_TRUE(CheckNoRtp2());
985 }
986
987 // Check that RTCP is not transmitted if both sides don't support RTCP.
988 void SendNoRtcpToNoRtcp() {
989 CreateChannels(0, 0);
990 EXPECT_TRUE(SendInitiate());
991 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700992 ASSERT_TRUE(GetTransport1());
993 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 EXPECT_EQ(1U, GetTransport1()->channels().size());
995 EXPECT_EQ(1U, GetTransport2()->channels().size());
996 EXPECT_FALSE(SendRtcp1());
997 EXPECT_FALSE(SendRtcp2());
998 EXPECT_TRUE(CheckNoRtcp1());
999 EXPECT_TRUE(CheckNoRtcp2());
1000 }
1001
1002 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1003 void SendNoRtcpToRtcp() {
1004 CreateChannels(0, RTCP);
1005 EXPECT_TRUE(SendInitiate());
1006 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001007 ASSERT_TRUE(GetTransport1());
1008 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 EXPECT_EQ(1U, GetTransport1()->channels().size());
1010 EXPECT_EQ(2U, GetTransport2()->channels().size());
1011 EXPECT_FALSE(SendRtcp1());
1012 EXPECT_FALSE(SendRtcp2());
1013 EXPECT_TRUE(CheckNoRtcp1());
1014 EXPECT_TRUE(CheckNoRtcp2());
1015 }
1016
1017 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1018 void SendRtcpToNoRtcp() {
1019 CreateChannels(RTCP, 0);
1020 EXPECT_TRUE(SendInitiate());
1021 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001022 ASSERT_TRUE(GetTransport1());
1023 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 EXPECT_EQ(2U, GetTransport1()->channels().size());
1025 EXPECT_EQ(1U, GetTransport2()->channels().size());
1026 EXPECT_FALSE(SendRtcp1());
1027 EXPECT_FALSE(SendRtcp2());
1028 EXPECT_TRUE(CheckNoRtcp1());
1029 EXPECT_TRUE(CheckNoRtcp2());
1030 }
1031
1032 // Check that RTCP is transmitted if both sides support RTCP.
1033 void SendRtcpToRtcp() {
1034 CreateChannels(RTCP, RTCP);
1035 EXPECT_TRUE(SendInitiate());
1036 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001037 ASSERT_TRUE(GetTransport1());
1038 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 EXPECT_EQ(2U, GetTransport1()->channels().size());
1040 EXPECT_EQ(2U, GetTransport2()->channels().size());
1041 EXPECT_TRUE(SendRtcp1());
1042 EXPECT_TRUE(SendRtcp2());
1043 EXPECT_TRUE(CheckRtcp1());
1044 EXPECT_TRUE(CheckRtcp2());
1045 EXPECT_TRUE(CheckNoRtcp1());
1046 EXPECT_TRUE(CheckNoRtcp2());
1047 }
1048
1049 // Check that RTCP is transmitted if only the initiator supports mux.
1050 void SendRtcpMuxToRtcp() {
1051 CreateChannels(RTCP | RTCP_MUX, RTCP);
1052 EXPECT_TRUE(SendInitiate());
1053 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001054 ASSERT_TRUE(GetTransport1());
1055 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 EXPECT_EQ(2U, GetTransport1()->channels().size());
1057 EXPECT_EQ(2U, GetTransport2()->channels().size());
1058 EXPECT_TRUE(SendRtcp1());
1059 EXPECT_TRUE(SendRtcp2());
1060 EXPECT_TRUE(CheckRtcp1());
1061 EXPECT_TRUE(CheckRtcp2());
1062 EXPECT_TRUE(CheckNoRtcp1());
1063 EXPECT_TRUE(CheckNoRtcp2());
1064 }
1065
1066 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1067 void SendRtcpMuxToRtcpMux() {
1068 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1069 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001070 ASSERT_TRUE(GetTransport1());
1071 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 EXPECT_EQ(2U, GetTransport1()->channels().size());
1073 EXPECT_EQ(1U, GetTransport2()->channels().size());
1074 EXPECT_TRUE(SendAccept());
1075 EXPECT_EQ(1U, GetTransport1()->channels().size());
1076 EXPECT_TRUE(SendRtp1());
1077 EXPECT_TRUE(SendRtp2());
1078 EXPECT_TRUE(SendRtcp1());
1079 EXPECT_TRUE(SendRtcp2());
1080 EXPECT_TRUE(CheckRtp1());
1081 EXPECT_TRUE(CheckRtp2());
1082 EXPECT_TRUE(CheckNoRtp1());
1083 EXPECT_TRUE(CheckNoRtp2());
1084 EXPECT_TRUE(CheckRtcp1());
1085 EXPECT_TRUE(CheckRtcp2());
1086 EXPECT_TRUE(CheckNoRtcp1());
1087 EXPECT_TRUE(CheckNoRtcp2());
1088 }
1089
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001090 // Check that RTP and RTCP are transmitted ok when both sides
1091 // support mux and one the offerer requires mux.
1092 void SendRequireRtcpMuxToRtcpMux() {
1093 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1094 channel1_->ActivateRtcpMux();
1095 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001096 ASSERT_TRUE(GetTransport1());
1097 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001098 EXPECT_EQ(1U, GetTransport1()->channels().size());
1099 EXPECT_EQ(1U, GetTransport2()->channels().size());
1100 EXPECT_TRUE(SendAccept());
1101 EXPECT_TRUE(SendRtp1());
1102 EXPECT_TRUE(SendRtp2());
1103 EXPECT_TRUE(SendRtcp1());
1104 EXPECT_TRUE(SendRtcp2());
1105 EXPECT_TRUE(CheckRtp1());
1106 EXPECT_TRUE(CheckRtp2());
1107 EXPECT_TRUE(CheckNoRtp1());
1108 EXPECT_TRUE(CheckNoRtp2());
1109 EXPECT_TRUE(CheckRtcp1());
1110 EXPECT_TRUE(CheckRtcp2());
1111 EXPECT_TRUE(CheckNoRtcp1());
1112 EXPECT_TRUE(CheckNoRtcp2());
1113 }
1114
1115 // Check that RTP and RTCP are transmitted ok when both sides
1116 // support mux and one the answerer requires rtcp mux.
1117 void SendRtcpMuxToRequireRtcpMux() {
1118 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1119 channel2_->ActivateRtcpMux();
1120 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001121 ASSERT_TRUE(GetTransport1());
1122 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001123 EXPECT_EQ(2U, GetTransport1()->channels().size());
1124 EXPECT_EQ(1U, GetTransport2()->channels().size());
1125 EXPECT_TRUE(SendAccept());
1126 EXPECT_EQ(1U, GetTransport1()->channels().size());
1127 EXPECT_TRUE(SendRtp1());
1128 EXPECT_TRUE(SendRtp2());
1129 EXPECT_TRUE(SendRtcp1());
1130 EXPECT_TRUE(SendRtcp2());
1131 EXPECT_TRUE(CheckRtp1());
1132 EXPECT_TRUE(CheckRtp2());
1133 EXPECT_TRUE(CheckNoRtp1());
1134 EXPECT_TRUE(CheckNoRtp2());
1135 EXPECT_TRUE(CheckRtcp1());
1136 EXPECT_TRUE(CheckRtcp2());
1137 EXPECT_TRUE(CheckNoRtcp1());
1138 EXPECT_TRUE(CheckNoRtcp2());
1139 }
1140
1141 // Check that RTP and RTCP are transmitted ok when both sides
1142 // require mux.
1143 void SendRequireRtcpMuxToRequireRtcpMux() {
1144 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1145 channel1_->ActivateRtcpMux();
1146 channel2_->ActivateRtcpMux();
1147 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001148 ASSERT_TRUE(GetTransport1());
1149 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001150 EXPECT_EQ(1U, GetTransport1()->channels().size());
1151 EXPECT_EQ(1U, GetTransport2()->channels().size());
1152 EXPECT_TRUE(SendAccept());
1153 EXPECT_EQ(1U, GetTransport1()->channels().size());
1154 EXPECT_TRUE(SendRtp1());
1155 EXPECT_TRUE(SendRtp2());
1156 EXPECT_TRUE(SendRtcp1());
1157 EXPECT_TRUE(SendRtcp2());
1158 EXPECT_TRUE(CheckRtp1());
1159 EXPECT_TRUE(CheckRtp2());
1160 EXPECT_TRUE(CheckNoRtp1());
1161 EXPECT_TRUE(CheckNoRtp2());
1162 EXPECT_TRUE(CheckRtcp1());
1163 EXPECT_TRUE(CheckRtcp2());
1164 EXPECT_TRUE(CheckNoRtcp1());
1165 EXPECT_TRUE(CheckNoRtcp2());
1166 }
1167
1168 // Check that SendAccept fails if the answerer doesn't support mux
1169 // and the offerer requires it.
1170 void SendRequireRtcpMuxToNoRtcpMux() {
1171 CreateChannels(RTCP | RTCP_MUX, RTCP);
1172 channel1_->ActivateRtcpMux();
1173 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001174 ASSERT_TRUE(GetTransport1());
1175 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001176 EXPECT_EQ(1U, GetTransport1()->channels().size());
1177 EXPECT_EQ(2U, GetTransport2()->channels().size());
1178 EXPECT_FALSE(SendAccept());
1179 }
1180
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181 // Check that RTCP data sent by the initiator before the accept is not muxed.
1182 void SendEarlyRtcpMuxToRtcp() {
1183 CreateChannels(RTCP | RTCP_MUX, RTCP);
1184 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001185 ASSERT_TRUE(GetTransport1());
1186 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 EXPECT_EQ(2U, GetTransport1()->channels().size());
1188 EXPECT_EQ(2U, GetTransport2()->channels().size());
1189
1190 // RTCP can be sent before the call is accepted, if the transport is ready.
1191 // It should not be muxed though, as the remote side doesn't support mux.
1192 EXPECT_TRUE(SendRtcp1());
1193 EXPECT_TRUE(CheckNoRtp2());
1194 EXPECT_TRUE(CheckRtcp2());
1195
1196 // Send RTCP packet from callee and verify that it is received.
1197 EXPECT_TRUE(SendRtcp2());
1198 EXPECT_TRUE(CheckNoRtp1());
1199 EXPECT_TRUE(CheckRtcp1());
1200
1201 // Complete call setup and ensure everything is still OK.
1202 EXPECT_TRUE(SendAccept());
1203 EXPECT_EQ(2U, GetTransport1()->channels().size());
1204 EXPECT_TRUE(SendRtcp1());
1205 EXPECT_TRUE(CheckRtcp2());
1206 EXPECT_TRUE(SendRtcp2());
1207 EXPECT_TRUE(CheckRtcp1());
1208 }
1209
1210
1211 // Check that RTCP data is not muxed until both sides have enabled muxing,
1212 // but that we properly demux before we get the accept message, since there
1213 // is a race between RTP data and the jingle accept.
1214 void SendEarlyRtcpMuxToRtcpMux() {
1215 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1216 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001217 ASSERT_TRUE(GetTransport1());
1218 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 EXPECT_EQ(2U, GetTransport1()->channels().size());
1220 EXPECT_EQ(1U, GetTransport2()->channels().size());
1221
1222 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1223 // we haven't yet received the accept that says we should mux.
1224 EXPECT_FALSE(SendRtcp1());
1225
1226 // Send muxed RTCP packet from callee and verify that it is received.
1227 EXPECT_TRUE(SendRtcp2());
1228 EXPECT_TRUE(CheckNoRtp1());
1229 EXPECT_TRUE(CheckRtcp1());
1230
1231 // Complete call setup and ensure everything is still OK.
1232 EXPECT_TRUE(SendAccept());
1233 EXPECT_EQ(1U, GetTransport1()->channels().size());
1234 EXPECT_TRUE(SendRtcp1());
1235 EXPECT_TRUE(CheckRtcp2());
1236 EXPECT_TRUE(SendRtcp2());
1237 EXPECT_TRUE(CheckRtcp1());
1238 }
1239
1240 // Test that we properly send SRTP with RTCP in both directions.
1241 // You can pass in DTLS and/or RTCP_MUX as flags.
1242 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1243 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1244 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1245
1246 int flags1 = RTCP | SECURE | flags1_in;
1247 int flags2 = RTCP | SECURE | flags2_in;
1248 bool dtls1 = !!(flags1_in & DTLS);
1249 bool dtls2 = !!(flags2_in & DTLS);
1250 CreateChannels(flags1, flags2);
1251 EXPECT_FALSE(channel1_->secure());
1252 EXPECT_FALSE(channel2_->secure());
1253 EXPECT_TRUE(SendInitiate());
1254 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1255 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1256 EXPECT_TRUE(SendAccept());
1257 EXPECT_TRUE(channel1_->secure());
1258 EXPECT_TRUE(channel2_->secure());
1259 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1260 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1261 EXPECT_TRUE(SendRtp1());
1262 EXPECT_TRUE(SendRtp2());
1263 EXPECT_TRUE(SendRtcp1());
1264 EXPECT_TRUE(SendRtcp2());
1265 EXPECT_TRUE(CheckRtp1());
1266 EXPECT_TRUE(CheckRtp2());
1267 EXPECT_TRUE(CheckNoRtp1());
1268 EXPECT_TRUE(CheckNoRtp2());
1269 EXPECT_TRUE(CheckRtcp1());
1270 EXPECT_TRUE(CheckRtcp2());
1271 EXPECT_TRUE(CheckNoRtcp1());
1272 EXPECT_TRUE(CheckNoRtcp2());
1273 }
1274
1275 // Test that we properly handling SRTP negotiating down to RTP.
1276 void SendSrtpToRtp() {
1277 CreateChannels(RTCP | SECURE, RTCP);
1278 EXPECT_FALSE(channel1_->secure());
1279 EXPECT_FALSE(channel2_->secure());
1280 EXPECT_TRUE(SendInitiate());
1281 EXPECT_TRUE(SendAccept());
1282 EXPECT_FALSE(channel1_->secure());
1283 EXPECT_FALSE(channel2_->secure());
1284 EXPECT_TRUE(SendRtp1());
1285 EXPECT_TRUE(SendRtp2());
1286 EXPECT_TRUE(SendRtcp1());
1287 EXPECT_TRUE(SendRtcp2());
1288 EXPECT_TRUE(CheckRtp1());
1289 EXPECT_TRUE(CheckRtp2());
1290 EXPECT_TRUE(CheckNoRtp1());
1291 EXPECT_TRUE(CheckNoRtp2());
1292 EXPECT_TRUE(CheckRtcp1());
1293 EXPECT_TRUE(CheckRtcp2());
1294 EXPECT_TRUE(CheckNoRtcp1());
1295 EXPECT_TRUE(CheckNoRtcp2());
1296 }
1297
1298 // Test that we can send and receive early media when a provisional answer is
1299 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1300 void SendEarlyMediaUsingRtcpMuxSrtp() {
1301 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1302
1303 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1304 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1305 EXPECT_TRUE(SendOffer());
1306 EXPECT_TRUE(SendProvisionalAnswer());
1307 EXPECT_TRUE(channel1_->secure());
1308 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001309 ASSERT_TRUE(GetTransport1());
1310 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_EQ(2U, GetTransport1()->channels().size());
1312 EXPECT_EQ(2U, GetTransport2()->channels().size());
1313 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1314 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1315 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1316 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1317
1318 // Send packets from callee and verify that it is received.
1319 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1320 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1321 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1322 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1323
1324 // Complete call setup and ensure everything is still OK.
1325 EXPECT_TRUE(SendFinalAnswer());
1326 EXPECT_EQ(1U, GetTransport1()->channels().size());
1327 EXPECT_EQ(1U, GetTransport2()->channels().size());
1328 EXPECT_TRUE(channel1_->secure());
1329 EXPECT_TRUE(channel2_->secure());
1330 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1331 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1332 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1333 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1334 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1335 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1336 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1337 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1338 }
1339
1340 // Test that we properly send RTP without SRTP from a thread.
1341 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001342 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1343 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 EXPECT_TRUE(SendInitiate());
1345 EXPECT_TRUE(SendAccept());
1346 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1347 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001348 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1349 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1351 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1352 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1353 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1354 EXPECT_TRUE(CheckNoRtp1());
1355 EXPECT_TRUE(CheckNoRtp2());
1356 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1357 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1358 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1359 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1360 EXPECT_TRUE(CheckNoRtcp1());
1361 EXPECT_TRUE(CheckNoRtcp2());
1362 }
1363
1364 // Test that we properly send SRTP with RTCP from a thread.
1365 void SendSrtpToSrtpOnThread() {
1366 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1367 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1368 EXPECT_TRUE(SendInitiate());
1369 EXPECT_TRUE(SendAccept());
1370 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1371 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1372 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1373 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1374 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1375 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1376 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1377 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1378 EXPECT_TRUE(CheckNoRtp1());
1379 EXPECT_TRUE(CheckNoRtp2());
1380 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1381 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1382 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1383 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1384 EXPECT_TRUE(CheckNoRtcp1());
1385 EXPECT_TRUE(CheckNoRtcp2());
1386 }
1387
1388 // Test that the mediachannel retains its sending state after the transport
1389 // becomes non-writable.
1390 void SendWithWritabilityLoss() {
1391 CreateChannels(0, 0);
1392 EXPECT_TRUE(SendInitiate());
1393 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001394 ASSERT_TRUE(GetTransport1());
1395 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 EXPECT_EQ(1U, GetTransport1()->channels().size());
1397 EXPECT_EQ(1U, GetTransport2()->channels().size());
1398 EXPECT_TRUE(SendRtp1());
1399 EXPECT_TRUE(SendRtp2());
1400 EXPECT_TRUE(CheckRtp1());
1401 EXPECT_TRUE(CheckRtp2());
1402 EXPECT_TRUE(CheckNoRtp1());
1403 EXPECT_TRUE(CheckNoRtp2());
1404
wu@webrtc.org97077a32013-10-25 21:18:33 +00001405 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 EXPECT_FALSE(SendRtp1());
1408 EXPECT_TRUE(SendRtp2());
1409 EXPECT_TRUE(CheckRtp1());
1410 EXPECT_TRUE(CheckNoRtp2());
1411
1412 // Regain writability
1413 GetTransport1()->SetWritable(true);
1414 EXPECT_TRUE(media_channel1_->sending());
1415 EXPECT_TRUE(SendRtp1());
1416 EXPECT_TRUE(SendRtp2());
1417 EXPECT_TRUE(CheckRtp1());
1418 EXPECT_TRUE(CheckRtp2());
1419 EXPECT_TRUE(CheckNoRtp1());
1420 EXPECT_TRUE(CheckNoRtp2());
1421
1422 // Lose writability completely
1423 GetTransport1()->SetDestination(NULL);
1424 EXPECT_TRUE(media_channel1_->sending());
1425
wu@webrtc.org97077a32013-10-25 21:18:33 +00001426 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 EXPECT_FALSE(SendRtp1());
1428 EXPECT_TRUE(SendRtp2());
1429 EXPECT_TRUE(CheckRtp1());
1430 EXPECT_TRUE(CheckNoRtp2());
1431
1432 // Gain writability back
1433 GetTransport1()->SetDestination(GetTransport2());
1434 EXPECT_TRUE(media_channel1_->sending());
1435 EXPECT_TRUE(SendRtp1());
1436 EXPECT_TRUE(SendRtp2());
1437 EXPECT_TRUE(CheckRtp1());
1438 EXPECT_TRUE(CheckRtp2());
1439 EXPECT_TRUE(CheckNoRtp1());
1440 EXPECT_TRUE(CheckNoRtp2());
1441 }
1442
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001443 void SendBundleToBundle(
1444 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1445 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001447 // Only pl_type1 was added to the bundle filter for both |channel1_|
1448 // and |channel2_|.
1449 int pl_type1 = pl_types[0];
1450 int pl_type2 = pl_types[1];
1451 int flags = SSRC_MUX | RTCP;
1452 if (secure) flags |= SECURE;
1453 uint32 expected_channels = 2U;
1454 if (rtcp_mux) {
1455 flags |= RTCP_MUX;
1456 expected_channels = 1U;
1457 }
1458 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001460 ASSERT_TRUE(GetTransport1());
1461 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001463 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001465 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1466 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1467 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1468 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1469 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1470 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1471 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1472 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1473 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1474 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1475 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1476 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1477
1478 // Both channels can receive pl_type1 only.
1479 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1480 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1481 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1482 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1483 EXPECT_TRUE(CheckNoRtp1());
1484 EXPECT_TRUE(CheckNoRtp2());
1485
1486 // RTCP test
1487 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1488 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1489 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1490 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1491
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1493 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1495 EXPECT_TRUE(CheckNoRtcp1());
1496 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1497 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001499 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1500 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1503 }
1504
1505 // Test that the media monitor can be run and gives timely callbacks.
1506 void TestMediaMonitor() {
1507 static const int kTimeout = 500;
1508 CreateChannels(0, 0);
1509 EXPECT_TRUE(SendInitiate());
1510 EXPECT_TRUE(SendAccept());
1511 channel1_->StartMediaMonitor(100);
1512 channel2_->StartMediaMonitor(100);
1513 // Ensure we get callbacks and stop.
1514 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1515 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1516 channel1_->StopMediaMonitor();
1517 channel2_->StopMediaMonitor();
1518 // Ensure a restart of a stopped monitor works.
1519 channel1_->StartMediaMonitor(100);
1520 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1521 channel1_->StopMediaMonitor();
1522 // Ensure stopping a stopped monitor is OK.
1523 channel1_->StopMediaMonitor();
1524 }
1525
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 void TestSetContentFailure() {
1527 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528
Peter Thatchera6d24442015-07-09 21:26:36 -07001529 auto sdesc = cricket::SessionDescription();
1530 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1531 new cricket::AudioContentDescription());
1532 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1533 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534
Peter Thatchera6d24442015-07-09 21:26:36 -07001535 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001537 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1538 &sdesc, cricket::CA_OFFER, &err));
1539 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1540 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001543 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1544 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001546 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1547 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 }
1549
1550 void TestSendTwoOffers() {
1551 CreateChannels(0, 0);
1552
Peter Thatchera6d24442015-07-09 21:26:36 -07001553 std::string err;
1554 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1555 CreateSessionDescriptionWithStream(1));
1556 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1557 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1559
Peter Thatchera6d24442015-07-09 21:26:36 -07001560 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1561 CreateSessionDescriptionWithStream(2));
1562 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1563 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1565 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1566 }
1567
1568 void TestReceiveTwoOffers() {
1569 CreateChannels(0, 0);
1570
Peter Thatchera6d24442015-07-09 21:26:36 -07001571 std::string err;
1572 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1573 CreateSessionDescriptionWithStream(1));
1574 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1575 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1577
Peter Thatchera6d24442015-07-09 21:26:36 -07001578 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1579 CreateSessionDescriptionWithStream(2));
1580 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1581 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1583 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1584 }
1585
1586 void TestSendPrAnswer() {
1587 CreateChannels(0, 0);
1588
Peter Thatchera6d24442015-07-09 21:26:36 -07001589 std::string err;
1590 // Receive offer
1591 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1592 CreateSessionDescriptionWithStream(1));
1593 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1594 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1596
Peter Thatchera6d24442015-07-09 21:26:36 -07001597 // Send PR answer
1598 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1599 CreateSessionDescriptionWithStream(2));
1600 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1601 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1603 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1604
Peter Thatchera6d24442015-07-09 21:26:36 -07001605 // Send answer
1606 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1607 CreateSessionDescriptionWithStream(3));
1608 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1609 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1611 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1612 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1613 }
1614
1615 void TestReceivePrAnswer() {
1616 CreateChannels(0, 0);
1617
Peter Thatchera6d24442015-07-09 21:26:36 -07001618 std::string err;
1619 // Send offer
1620 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1621 CreateSessionDescriptionWithStream(1));
1622 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1623 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1625
Peter Thatchera6d24442015-07-09 21:26:36 -07001626 // Receive PR answer
1627 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1628 CreateSessionDescriptionWithStream(2));
1629 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1630 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1632 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1633
Peter Thatchera6d24442015-07-09 21:26:36 -07001634 // Receive answer
1635 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1636 CreateSessionDescriptionWithStream(3));
1637 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1638 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1640 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1641 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1642 }
1643
1644 void TestFlushRtcp() {
1645 bool send_rtcp1;
1646
1647 CreateChannels(RTCP, RTCP);
1648 EXPECT_TRUE(SendInitiate());
1649 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001650 ASSERT_TRUE(GetTransport1());
1651 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 EXPECT_EQ(2U, GetTransport1()->channels().size());
1653 EXPECT_EQ(2U, GetTransport2()->channels().size());
1654
1655 // Send RTCP1 from a different thread.
1656 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1657 EXPECT_TRUE(send_rtcp1);
1658 // The sending message is only posted. channel2_ should be empty.
1659 EXPECT_TRUE(CheckNoRtcp2());
1660
1661 // When channel1_ is deleted, the RTCP packet should be sent out to
1662 // channel2_.
1663 channel1_.reset();
1664 EXPECT_TRUE(CheckRtcp2());
1665 }
1666
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001667 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001668 struct SrtpErrorHandler : public sigslot::has_slots<> {
1669 SrtpErrorHandler() :
1670 mode_(cricket::SrtpFilter::UNPROTECT),
1671 error_(cricket::SrtpFilter::ERROR_NONE) {}
1672 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1673 cricket::SrtpFilter::Error error) {
1674 mode_ = mode;
1675 error_ = error;
1676 }
1677 cricket::SrtpFilter::Mode mode_;
1678 cricket::SrtpFilter::Error error_;
1679 } error_handler;
1680
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001681 // For Audio, only pl_type 0 is added to the bundle filter.
1682 // For Video, only pl_type 97 is added to the bundle filter.
1683 // So we need to pass in pl_type so that the packet can pass through
1684 // the bundle filter before it can be processed by the srtp filter.
1685 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001686 unsigned const char kBadPacket[] = {0x84,
1687 static_cast<unsigned char>(pl_type),
1688 0x00,
1689 0x01,
1690 0x00,
1691 0x00,
1692 0x00,
1693 0x00,
1694 0x00,
1695 0x00,
1696 0x00,
1697 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1699 EXPECT_FALSE(channel1_->secure());
1700 EXPECT_FALSE(channel2_->secure());
1701 EXPECT_TRUE(SendInitiate());
1702 EXPECT_TRUE(SendAccept());
1703 EXPECT_TRUE(channel1_->secure());
1704 EXPECT_TRUE(channel2_->secure());
solenberg5b14b422015-10-01 04:10:31 -07001705
1706 channel2_->srtp_filter()->SignalSrtpError.connect(
1707 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708
1709 // Testing failures in sending packets.
1710 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1711 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001712 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1713 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1714 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 // The next 1 sec failures will not trigger an error.
1716 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1717 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001718 rtc::Thread::Current()->ProcessMessages(210);
solenberg5b14b422015-10-01 04:10:31 -07001719 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 // The error will be triggered again.
1721 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
solenberg5b14b422015-10-01 04:10:31 -07001722 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1723 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724
1725 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001726 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
1727
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 cricket::TransportChannel* transport_channel =
1729 channel2_->transport_channel();
1730 transport_channel->SignalReadPacket(
1731 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001732 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001733 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1734 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735 }
1736
1737 void TestOnReadyToSend() {
1738 CreateChannels(RTCP, RTCP);
1739 TransportChannel* rtp = channel1_->transport_channel();
1740 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1741 EXPECT_FALSE(media_channel1_->ready_to_send());
1742 rtp->SignalReadyToSend(rtp);
1743 EXPECT_FALSE(media_channel1_->ready_to_send());
1744 rtcp->SignalReadyToSend(rtcp);
1745 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1746 // channel are ready to send.
1747 EXPECT_TRUE(media_channel1_->ready_to_send());
1748
1749 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001750 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001752 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 EXPECT_TRUE(media_channel1_->ready_to_send());
1754
1755 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001756 channel1_->SetReadyToSend(true, 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(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759 EXPECT_TRUE(media_channel1_->ready_to_send());
1760 }
1761
1762 void TestOnReadyToSendWithRtcpMux() {
1763 CreateChannels(RTCP, RTCP);
1764 typename T::Content content;
1765 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1766 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1767 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001768 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1769 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001770 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1771 TransportChannel* rtp = channel1_->transport_channel();
1772 EXPECT_FALSE(media_channel1_->ready_to_send());
1773 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1774 // should trigger the MediaChannel's OnReadyToSend.
1775 rtp->SignalReadyToSend(rtp);
1776 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001777 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 EXPECT_FALSE(media_channel1_->ready_to_send());
1779 }
1780
1781 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001782 // TODO(pbos): Remove playout from all media channels and let renderers mute
1783 // themselves.
1784 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001785 cricket::FakeTransportController transport_controller1_;
1786 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 cricket::FakeMediaEngine media_engine_;
1788 // The media channels are owned by the voice channel objects below.
1789 typename T::MediaChannel* media_channel1_;
1790 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001791 rtc::scoped_ptr<typename T::Channel> channel1_;
1792 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 typename T::Content local_media_content1_;
1794 typename T::Content local_media_content2_;
1795 typename T::Content remote_media_content1_;
1796 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 // The RTP and RTCP packets to send in the tests.
1798 std::string rtp_packet_;
1799 std::string rtcp_packet_;
1800 int media_info_callbacks1_;
1801 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802};
1803
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804template<>
1805void ChannelTest<VoiceTraits>::CreateContent(
1806 int flags,
1807 const cricket::AudioCodec& audio_codec,
1808 const cricket::VideoCodec& video_codec,
1809 cricket::AudioContentDescription* audio) {
1810 audio->AddCodec(audio_codec);
1811 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1812 if (flags & SECURE) {
1813 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001814 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1815 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 }
1817}
1818
1819template<>
1820void ChannelTest<VoiceTraits>::CopyContent(
1821 const cricket::AudioContentDescription& source,
1822 cricket::AudioContentDescription* audio) {
1823 *audio = source;
1824}
1825
1826template<>
1827bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1828 const cricket::AudioCodec& c2) {
1829 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1830 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1831}
1832
1833template<>
1834void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1835 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1836 audio->AddLegacyStream(ssrc);
1837}
1838
1839class VoiceChannelTest
1840 : public ChannelTest<VoiceTraits> {
1841 public:
solenberg1dd98f32015-09-10 01:57:14 -07001842 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001843 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001844 : Base(true,
1845 kPcmuFrame,
1846 sizeof(kPcmuFrame),
1847 kRtcpReport,
1848 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849};
1850
1851// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001852template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001854 rtc::Thread* thread,
1855 cricket::MediaEngineInterface* engine,
1856 cricket::FakeVideoMediaChannel* ch,
1857 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 bool rtcp) {
1859 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001860 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 if (!channel->Init()) {
1862 delete channel;
1863 channel = NULL;
1864 }
1865 return channel;
1866}
1867
1868// override to add 0 parameter
1869template<>
1870bool ChannelTest<VideoTraits>::AddStream1(int id) {
1871 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1872}
1873
1874template<>
1875void ChannelTest<VideoTraits>::CreateContent(
1876 int flags,
1877 const cricket::AudioCodec& audio_codec,
1878 const cricket::VideoCodec& video_codec,
1879 cricket::VideoContentDescription* video) {
1880 video->AddCodec(video_codec);
1881 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1882 if (flags & SECURE) {
1883 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001884 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1885 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886 }
1887}
1888
1889template<>
1890void ChannelTest<VideoTraits>::CopyContent(
1891 const cricket::VideoContentDescription& source,
1892 cricket::VideoContentDescription* video) {
1893 *video = source;
1894}
1895
1896template<>
1897bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1898 const cricket::VideoCodec& c2) {
1899 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1900 c1.framerate == c2.framerate;
1901}
1902
1903template<>
1904void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1905 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1906 video->AddLegacyStream(ssrc);
1907}
1908
1909class VideoChannelTest
1910 : public ChannelTest<VideoTraits> {
1911 public:
solenberg1dd98f32015-09-10 01:57:14 -07001912 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001913 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001914 : Base(false,
1915 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001916 sizeof(kH264Packet),
1917 kRtcpReport,
1918 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919};
1920
1921
1922// VoiceChannelTest
1923
1924TEST_F(VoiceChannelTest, TestInit) {
1925 Base::TestInit();
1926 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1927 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1928}
1929
1930TEST_F(VoiceChannelTest, TestSetContents) {
1931 Base::TestSetContents();
1932}
1933
1934TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1935 Base::TestSetContentsNullOffer();
1936}
1937
1938TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1939 Base::TestSetContentsRtcpMux();
1940}
1941
1942TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1943 Base::TestSetContentsRtcpMux();
1944}
1945
1946TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1947 Base::TestSetRemoteContentUpdate();
1948}
1949
1950TEST_F(VoiceChannelTest, TestStreams) {
1951 Base::TestStreams();
1952}
1953
1954TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1955 Base::TestUpdateStreamsInLocalContent();
1956}
1957
1958TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1959 Base::TestUpdateStreamsInRemoteContent();
1960}
1961
1962TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1963 Base::TestChangeStreamParamsInContent();
1964}
1965
1966TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1967 Base::TestPlayoutAndSendingStates();
1968}
1969
1970TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001971 CreateChannels(0, 0);
1972 // Test that we can Mute the default channel even though the sending SSRC
1973 // is unknown.
1974 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07001975 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001976 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1977 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001978 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1979
1980 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07001981 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001982
1983 SendInitiate();
1984 // After the local session description has been set, we can mute a stream
1985 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07001986 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001987 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
1988 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001989 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990}
1991
1992TEST_F(VoiceChannelTest, TestMediaContentDirection) {
1993 Base::TestMediaContentDirection();
1994}
1995
1996TEST_F(VoiceChannelTest, TestCallSetup) {
1997 Base::TestCallSetup();
1998}
1999
2000TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2001 Base::TestCallTeardownRtcpMux();
2002}
2003
2004TEST_F(VoiceChannelTest, SendRtpToRtp) {
2005 Base::SendRtpToRtp();
2006}
2007
2008TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2009 Base::SendNoRtcpToNoRtcp();
2010}
2011
2012TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2013 Base::SendNoRtcpToRtcp();
2014}
2015
2016TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2017 Base::SendRtcpToNoRtcp();
2018}
2019
2020TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2021 Base::SendRtcpToRtcp();
2022}
2023
2024TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2025 Base::SendRtcpMuxToRtcp();
2026}
2027
2028TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2029 Base::SendRtcpMuxToRtcpMux();
2030}
2031
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002032TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2033 Base::SendRequireRtcpMuxToRtcpMux();
2034}
2035
2036TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2037 Base::SendRtcpMuxToRequireRtcpMux();
2038}
2039
2040TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2041 Base::SendRequireRtcpMuxToRequireRtcpMux();
2042}
2043
2044TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2045 Base::SendRequireRtcpMuxToNoRtcpMux();
2046}
2047
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2049 Base::SendEarlyRtcpMuxToRtcp();
2050}
2051
2052TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2053 Base::SendEarlyRtcpMuxToRtcpMux();
2054}
2055
2056TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2057 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2058}
2059
2060TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2061 Base::SendSrtpToSrtp();
2062}
2063
2064TEST_F(VoiceChannelTest, SendSrtcpMux) {
2065 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2066}
2067
2068TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2069 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2070 Base::SendSrtpToSrtp(DTLS, 0);
2071}
2072
2073TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2074 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2075 Base::SendSrtpToSrtp(DTLS, DTLS);
2076}
2077
2078TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2079 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2080 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2081}
2082
2083TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2084 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2085}
2086
2087TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2088 Base::SendRtpToRtpOnThread();
2089}
2090
2091TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2092 Base::SendSrtpToSrtpOnThread();
2093}
2094
2095TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2096 Base::SendWithWritabilityLoss();
2097}
2098
2099TEST_F(VoiceChannelTest, TestMediaMonitor) {
2100 Base::TestMediaMonitor();
2101}
2102
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103// Test that PressDTMF properly forwards to the media channel.
2104TEST_F(VoiceChannelTest, TestDtmf) {
2105 CreateChannels(0, 0);
2106 EXPECT_TRUE(SendInitiate());
2107 EXPECT_TRUE(SendAccept());
2108 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2109
2110 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2111 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2112
2113 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2114 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2115 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2116 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2117 0, 8, 160, cricket::DF_SEND));
2118}
2119
2120// Test that InsertDtmf properly forwards to the media channel.
2121TEST_F(VoiceChannelTest, TestInsertDtmf) {
2122 CreateChannels(0, 0);
2123 EXPECT_TRUE(SendInitiate());
2124 EXPECT_TRUE(SendAccept());
2125 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2126
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2128 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2129 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2130 cricket::DF_PLAY | cricket::DF_SEND));
2131
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002132 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002135 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002137 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2139}
2140
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141TEST_F(VoiceChannelTest, TestSetContentFailure) {
2142 Base::TestSetContentFailure();
2143}
2144
2145TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2146 Base::TestSendTwoOffers();
2147}
2148
2149TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2150 Base::TestReceiveTwoOffers();
2151}
2152
2153TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2154 Base::TestSendPrAnswer();
2155}
2156
2157TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2158 Base::TestReceivePrAnswer();
2159}
2160
2161TEST_F(VoiceChannelTest, TestFlushRtcp) {
2162 Base::TestFlushRtcp();
2163}
2164
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002166 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167}
2168
2169TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2170 Base::TestOnReadyToSend();
2171}
2172
2173TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2174 Base::TestOnReadyToSendWithRtcpMux();
2175}
2176
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177// Test that we can scale the output volume properly for 1:1 calls.
2178TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2179 CreateChannels(RTCP, RTCP);
2180 EXPECT_TRUE(SendInitiate());
2181 EXPECT_TRUE(SendAccept());
2182 double left, right;
2183
2184 // Default is (1.0, 1.0).
2185 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2186 EXPECT_DOUBLE_EQ(1.0, left);
2187 EXPECT_DOUBLE_EQ(1.0, right);
2188 // invalid ssrc.
2189 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2190
2191 // Set scale to (1.5, 0.5).
2192 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2193 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2194 EXPECT_DOUBLE_EQ(1.5, left);
2195 EXPECT_DOUBLE_EQ(0.5, right);
2196
2197 // Set scale to (0, 0).
2198 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2199 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2200 EXPECT_DOUBLE_EQ(0.0, left);
2201 EXPECT_DOUBLE_EQ(0.0, right);
2202}
2203
2204// Test that we can scale the output volume properly for multiway calls.
2205TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2206 CreateChannels(RTCP, RTCP);
2207 EXPECT_TRUE(SendInitiate());
2208 EXPECT_TRUE(SendAccept());
2209 EXPECT_TRUE(AddStream1(1));
2210 EXPECT_TRUE(AddStream1(2));
2211
2212 double left, right;
2213 // Default is (1.0, 1.0).
2214 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2215 EXPECT_DOUBLE_EQ(1.0, left);
2216 EXPECT_DOUBLE_EQ(1.0, right);
2217 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2218 EXPECT_DOUBLE_EQ(1.0, left);
2219 EXPECT_DOUBLE_EQ(1.0, right);
2220 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2221 EXPECT_DOUBLE_EQ(1.0, left);
2222 EXPECT_DOUBLE_EQ(1.0, right);
2223 // invalid ssrc.
2224 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2225
2226 // Set scale to (1.5, 0.5) for ssrc = 1.
2227 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2228 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2229 EXPECT_DOUBLE_EQ(1.5, left);
2230 EXPECT_DOUBLE_EQ(0.5, right);
2231 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2232 EXPECT_DOUBLE_EQ(1.0, left);
2233 EXPECT_DOUBLE_EQ(1.0, right);
2234 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2235 EXPECT_DOUBLE_EQ(1.0, left);
2236 EXPECT_DOUBLE_EQ(1.0, right);
2237
2238 // Set scale to (0, 0) for all ssrcs.
2239 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2240 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2241 EXPECT_DOUBLE_EQ(0.0, left);
2242 EXPECT_DOUBLE_EQ(0.0, right);
2243 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2244 EXPECT_DOUBLE_EQ(0.0, left);
2245 EXPECT_DOUBLE_EQ(0.0, right);
2246 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2247 EXPECT_DOUBLE_EQ(0.0, left);
2248 EXPECT_DOUBLE_EQ(0.0, right);
2249}
2250
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002251TEST_F(VoiceChannelTest, SendBundleToBundle) {
2252 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253}
2254
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002255TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2256 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2257}
2258
2259TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2260 Base::SendBundleToBundle(
2261 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2262}
2263
2264TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2265 Base::SendBundleToBundle(
2266 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267}
2268
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269// VideoChannelTest
2270TEST_F(VideoChannelTest, TestInit) {
2271 Base::TestInit();
2272}
2273
2274TEST_F(VideoChannelTest, TestSetContents) {
2275 Base::TestSetContents();
2276}
2277
2278TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2279 Base::TestSetContentsNullOffer();
2280}
2281
2282TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2283 Base::TestSetContentsRtcpMux();
2284}
2285
2286TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2287 Base::TestSetContentsRtcpMux();
2288}
2289
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2291 Base::TestSetRemoteContentUpdate();
2292}
2293
2294TEST_F(VideoChannelTest, TestStreams) {
2295 Base::TestStreams();
2296}
2297
2298TEST_F(VideoChannelTest, TestScreencastEvents) {
2299 const int kTimeoutMs = 500;
2300 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 cricket::ScreencastEventCatcher catcher;
2302 channel1_->SignalScreencastWindowEvent.connect(
2303 &catcher,
2304 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002305
2306 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2307 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2308 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2309 ScreencastId(WindowId(0)));
2310 ASSERT_TRUE(screen_capturer != NULL);
2311
2312 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2313 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002315
2316 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002317 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002318
2319 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002320 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002321
2322 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002323 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002324
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326}
2327
2328TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2329 Base::TestUpdateStreamsInLocalContent();
2330}
2331
2332TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2333 Base::TestUpdateStreamsInRemoteContent();
2334}
2335
2336TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2337 Base::TestChangeStreamParamsInContent();
2338}
2339
2340TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2341 Base::TestPlayoutAndSendingStates();
2342}
2343
2344TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002345 CreateChannels(0, 0);
2346 // Test that we can Mute the default channel even though the sending SSRC
2347 // is unknown.
2348 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002349 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002350 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2351 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002352 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2353 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002354 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002355 SendInitiate();
2356 // After the local session description has been set, we can mute a stream
2357 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002358 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002359 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2360 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002361 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362}
2363
2364TEST_F(VideoChannelTest, TestMediaContentDirection) {
2365 Base::TestMediaContentDirection();
2366}
2367
2368TEST_F(VideoChannelTest, TestCallSetup) {
2369 Base::TestCallSetup();
2370}
2371
2372TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2373 Base::TestCallTeardownRtcpMux();
2374}
2375
2376TEST_F(VideoChannelTest, SendRtpToRtp) {
2377 Base::SendRtpToRtp();
2378}
2379
2380TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2381 Base::SendNoRtcpToNoRtcp();
2382}
2383
2384TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2385 Base::SendNoRtcpToRtcp();
2386}
2387
2388TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2389 Base::SendRtcpToNoRtcp();
2390}
2391
2392TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2393 Base::SendRtcpToRtcp();
2394}
2395
2396TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2397 Base::SendRtcpMuxToRtcp();
2398}
2399
2400TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2401 Base::SendRtcpMuxToRtcpMux();
2402}
2403
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002404TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2405 Base::SendRequireRtcpMuxToRtcpMux();
2406}
2407
2408TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2409 Base::SendRtcpMuxToRequireRtcpMux();
2410}
2411
2412TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2413 Base::SendRequireRtcpMuxToRequireRtcpMux();
2414}
2415
2416TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2417 Base::SendRequireRtcpMuxToNoRtcpMux();
2418}
2419
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2421 Base::SendEarlyRtcpMuxToRtcp();
2422}
2423
2424TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2425 Base::SendEarlyRtcpMuxToRtcpMux();
2426}
2427
2428TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2429 Base::SendSrtpToSrtp();
2430}
2431
2432TEST_F(VideoChannelTest, SendSrtpToRtp) {
2433 Base::SendSrtpToSrtp();
2434}
2435
2436TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2437 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2438 Base::SendSrtpToSrtp(DTLS, 0);
2439}
2440
2441TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2442 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2443 Base::SendSrtpToSrtp(DTLS, DTLS);
2444}
2445
2446TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2447 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2448 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2449}
2450
2451TEST_F(VideoChannelTest, SendSrtcpMux) {
2452 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2453}
2454
2455TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2456 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2457}
2458
2459TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2460 Base::SendRtpToRtpOnThread();
2461}
2462
2463TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2464 Base::SendSrtpToSrtpOnThread();
2465}
2466
2467TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2468 Base::SendWithWritabilityLoss();
2469}
2470
2471TEST_F(VideoChannelTest, TestMediaMonitor) {
2472 Base::TestMediaMonitor();
2473}
2474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475TEST_F(VideoChannelTest, TestSetContentFailure) {
2476 Base::TestSetContentFailure();
2477}
2478
2479TEST_F(VideoChannelTest, TestSendTwoOffers) {
2480 Base::TestSendTwoOffers();
2481}
2482
2483TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2484 Base::TestReceiveTwoOffers();
2485}
2486
2487TEST_F(VideoChannelTest, TestSendPrAnswer) {
2488 Base::TestSendPrAnswer();
2489}
2490
2491TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2492 Base::TestReceivePrAnswer();
2493}
2494
2495TEST_F(VideoChannelTest, TestFlushRtcp) {
2496 Base::TestFlushRtcp();
2497}
2498
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002499TEST_F(VideoChannelTest, SendBundleToBundle) {
2500 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501}
2502
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002503TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2504 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2505}
2506
2507TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2508 Base::SendBundleToBundle(
2509 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2510}
2511
2512TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2513 Base::SendBundleToBundle(
2514 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515}
2516
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002518 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519}
2520
2521TEST_F(VideoChannelTest, TestOnReadyToSend) {
2522 Base::TestOnReadyToSend();
2523}
2524
2525TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2526 Base::TestOnReadyToSendWithRtcpMux();
2527}
2528
2529TEST_F(VideoChannelTest, TestApplyViewRequest) {
2530 CreateChannels(0, 0);
2531 cricket::StreamParams stream2;
2532 stream2.id = "stream2";
2533 stream2.ssrcs.push_back(2222);
2534 local_media_content1_.AddStream(stream2);
2535
2536 EXPECT_TRUE(SendInitiate());
2537 EXPECT_TRUE(SendAccept());
2538
2539 cricket::VideoFormat send_format;
2540 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2541 EXPECT_EQ(640, send_format.width);
2542 EXPECT_EQ(400, send_format.height);
2543 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2544
2545 cricket::ViewRequest request;
2546 // stream1: 320x200x15; stream2: 0x0x0
2547 request.static_video_views.push_back(cricket::StaticVideoView(
2548 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2549 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2550 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2551 EXPECT_EQ(320, send_format.width);
2552 EXPECT_EQ(200, send_format.height);
2553 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2554 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2555 EXPECT_EQ(0, send_format.width);
2556 EXPECT_EQ(0, send_format.height);
2557
2558 // stream1: 160x100x8; stream2: 0x0x0
2559 request.static_video_views.clear();
2560 request.static_video_views.push_back(cricket::StaticVideoView(
2561 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2562 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2563 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2564 EXPECT_EQ(160, send_format.width);
2565 EXPECT_EQ(100, send_format.height);
2566 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2567
2568 // stream1: 0x0x0; stream2: 640x400x30
2569 request.static_video_views.clear();
2570 request.static_video_views.push_back(cricket::StaticVideoView(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002571 cricket::StreamSelector(std::string(), stream2.id), 640, 400, 30));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2573 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2574 EXPECT_EQ(0, send_format.width);
2575 EXPECT_EQ(0, send_format.height);
2576 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2577 EXPECT_EQ(640, send_format.width);
2578 EXPECT_EQ(400, send_format.height);
2579 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2580
2581 // stream1: 0x0x0; stream2: 0x0x0
2582 request.static_video_views.clear();
2583 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2584 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2585 EXPECT_EQ(0, send_format.width);
2586 EXPECT_EQ(0, send_format.height);
2587}
2588
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589
2590// DataChannelTest
2591
2592class DataChannelTest
2593 : public ChannelTest<DataTraits> {
2594 public:
2595 typedef ChannelTest<DataTraits>
2596 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002597 DataChannelTest()
2598 : Base(true,
2599 kDataPacket,
2600 sizeof(kDataPacket),
2601 kRtcpReport,
2602 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002603};
2604
2605// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002606template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002608 rtc::Thread* thread,
2609 cricket::MediaEngineInterface* engine,
2610 cricket::FakeDataMediaChannel* ch,
2611 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 bool rtcp) {
2613 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002614 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615 if (!channel->Init()) {
2616 delete channel;
2617 channel = NULL;
2618 }
2619 return channel;
2620}
2621
2622template<>
2623void ChannelTest<DataTraits>::CreateContent(
2624 int flags,
2625 const cricket::AudioCodec& audio_codec,
2626 const cricket::VideoCodec& video_codec,
2627 cricket::DataContentDescription* data) {
2628 data->AddCodec(kGoogleDataCodec);
2629 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2630 if (flags & SECURE) {
2631 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002632 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2633 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 }
2635}
2636
2637template<>
2638void ChannelTest<DataTraits>::CopyContent(
2639 const cricket::DataContentDescription& source,
2640 cricket::DataContentDescription* data) {
2641 *data = source;
2642}
2643
2644template<>
2645bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2646 const cricket::DataCodec& c2) {
2647 return c1.name == c2.name;
2648}
2649
2650template<>
2651void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2652 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2653 data->AddLegacyStream(ssrc);
2654}
2655
2656TEST_F(DataChannelTest, TestInit) {
2657 Base::TestInit();
2658 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2659}
2660
2661TEST_F(DataChannelTest, TestSetContents) {
2662 Base::TestSetContents();
2663}
2664
2665TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2666 Base::TestSetContentsNullOffer();
2667}
2668
2669TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2670 Base::TestSetContentsRtcpMux();
2671}
2672
2673TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2674 Base::TestSetRemoteContentUpdate();
2675}
2676
2677TEST_F(DataChannelTest, TestStreams) {
2678 Base::TestStreams();
2679}
2680
2681TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2682 Base::TestUpdateStreamsInLocalContent();
2683}
2684
2685TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2686 Base::TestUpdateStreamsInRemoteContent();
2687}
2688
2689TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2690 Base::TestChangeStreamParamsInContent();
2691}
2692
2693TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2694 Base::TestPlayoutAndSendingStates();
2695}
2696
2697TEST_F(DataChannelTest, TestMediaContentDirection) {
2698 Base::TestMediaContentDirection();
2699}
2700
2701TEST_F(DataChannelTest, TestCallSetup) {
2702 Base::TestCallSetup();
2703}
2704
2705TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2706 Base::TestCallTeardownRtcpMux();
2707}
2708
2709TEST_F(DataChannelTest, TestOnReadyToSend) {
2710 Base::TestOnReadyToSend();
2711}
2712
2713TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2714 Base::TestOnReadyToSendWithRtcpMux();
2715}
2716
2717TEST_F(DataChannelTest, SendRtpToRtp) {
2718 Base::SendRtpToRtp();
2719}
2720
2721TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2722 Base::SendNoRtcpToNoRtcp();
2723}
2724
2725TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2726 Base::SendNoRtcpToRtcp();
2727}
2728
2729TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2730 Base::SendRtcpToNoRtcp();
2731}
2732
2733TEST_F(DataChannelTest, SendRtcpToRtcp) {
2734 Base::SendRtcpToRtcp();
2735}
2736
2737TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2738 Base::SendRtcpMuxToRtcp();
2739}
2740
2741TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2742 Base::SendRtcpMuxToRtcpMux();
2743}
2744
2745TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2746 Base::SendEarlyRtcpMuxToRtcp();
2747}
2748
2749TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2750 Base::SendEarlyRtcpMuxToRtcpMux();
2751}
2752
2753TEST_F(DataChannelTest, SendSrtpToSrtp) {
2754 Base::SendSrtpToSrtp();
2755}
2756
2757TEST_F(DataChannelTest, SendSrtpToRtp) {
2758 Base::SendSrtpToSrtp();
2759}
2760
2761TEST_F(DataChannelTest, SendSrtcpMux) {
2762 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2763}
2764
2765TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2766 Base::SendRtpToRtpOnThread();
2767}
2768
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2770 Base::SendSrtpToSrtpOnThread();
2771}
2772
2773TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2774 Base::SendWithWritabilityLoss();
2775}
2776
2777TEST_F(DataChannelTest, TestMediaMonitor) {
2778 Base::TestMediaMonitor();
2779}
2780
2781TEST_F(DataChannelTest, TestSendData) {
2782 CreateChannels(0, 0);
2783 EXPECT_TRUE(SendInitiate());
2784 EXPECT_TRUE(SendAccept());
2785
2786 cricket::SendDataParams params;
2787 params.ssrc = 42;
2788 unsigned char data[] = {
2789 'f', 'o', 'o'
2790 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002791 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 cricket::SendDataResult result;
2793 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2794 EXPECT_EQ(params.ssrc,
2795 media_channel1_->last_sent_data_params().ssrc);
2796 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2797}
2798
2799// TODO(pthatcher): TestSetReceiver?