blob: 18233202b65c818bc7ffc8cba699657c78b6e6fe [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
2 * libjingle
3 * Copyright 2009 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028#include "talk/media/base/fakemediaengine.h"
29#include "talk/media/base/fakertp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000030#include "talk/media/base/fakescreencapturerfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/media/base/fakevideocapturer.h"
32#include "talk/media/base/mediachannel.h"
33#include "talk/media/base/rtpdump.h"
34#include "talk/media/base/screencastid.h"
35#include "talk/media/base/testutils.h"
deadbeefcbecd352015-09-23 11:50:27 -070036#include "webrtc/p2p/base/faketransportcontroller.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/session/media/channel.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000038#include "webrtc/base/fileutils.h"
39#include "webrtc/base/gunit.h"
40#include "webrtc/base/helpers.h"
41#include "webrtc/base/logging.h"
42#include "webrtc/base/pathutils.h"
43#include "webrtc/base/signalthread.h"
44#include "webrtc/base/ssladapter.h"
45#include "webrtc/base/sslidentity.h"
46#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 LOG(LS_INFO) << "Feature disabled... skipping"; \
51 return; \
52 }
53
54using cricket::CA_OFFER;
55using cricket::CA_PRANSWER;
56using cricket::CA_ANSWER;
57using cricket::CA_UPDATE;
58using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::ScreencastId;
60using cricket::StreamParams;
61using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
65static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
67static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
68static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
69static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
Peter Boström0c4e06b2015-10-07 12:23:21 +020070static const uint32_t kSsrc1 = 0x1111;
71static const uint32_t kSsrc2 = 0x2222;
72static const uint32_t kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000073static const int kAudioPts[] = {0, 8};
74static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
deadbeefcbecd352015-09-23 11:50:27 -070076template <class ChannelT,
77 class MediaChannelT,
78 class ContentT,
79 class CodecT,
80 class MediaInfoT,
81 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082class Traits {
83 public:
84 typedef ChannelT Channel;
85 typedef MediaChannelT MediaChannel;
86 typedef ContentT Content;
87 typedef CodecT Codec;
88 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020089 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090};
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092// Controls how long we wait for a session to send messages that we
93// expect, in milliseconds. We put it high to avoid flaky tests.
94static const int kEventTimeout = 5000;
95
96class VoiceTraits : public Traits<cricket::VoiceChannel,
97 cricket::FakeVoiceMediaChannel,
98 cricket::AudioContentDescription,
99 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200100 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700101 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
103class VideoTraits : public Traits<cricket::VideoChannel,
104 cricket::FakeVideoMediaChannel,
105 cricket::VideoContentDescription,
106 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200107 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700108 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
110class DataTraits : public Traits<cricket::DataChannel,
111 cricket::FakeDataMediaChannel,
112 cricket::DataContentDescription,
113 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200114 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700115 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000117rtc::StreamInterface* Open(const std::string& path) {
118 return rtc::Filesystem::OpenFile(
119 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120}
121
122// Base class for Voice/VideoChannel tests
123template<class T>
124class ChannelTest : public testing::Test, public sigslot::has_slots<> {
125 public:
126 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
127 DTLS = 0x10 };
128
Peter Boström34fbfff2015-09-24 19:20:30 +0200129 ChannelTest(bool verify_playout,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200130 const uint8_t* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700131 int rtp_len,
Peter Boström0c4e06b2015-10-07 12:23:21 +0200132 const uint8_t* rtcp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700133 int rtcp_len)
Peter Boström34fbfff2015-09-24 19:20:30 +0200134 : verify_playout_(verify_playout),
135 transport_controller1_(cricket::ICEROLE_CONTROLLING),
deadbeefcbecd352015-09-23 11:50:27 -0700136 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 media_channel1_(NULL),
138 media_channel2_(NULL),
139 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
140 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
141 media_info_callbacks1_(),
solenberg5b14b422015-10-01 04:10:31 -0700142 media_info_callbacks2_() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200145 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
146 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 void CreateChannels(
150 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000151 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 media_channel1_ = ch1;
153 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700154 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
155 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700157 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
158 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 (flags2 & RTCP) != 0));
160 channel1_->SignalMediaMonitor.connect(
161 this, &ChannelTest<T>::OnMediaMonitor);
162 channel2_->SignalMediaMonitor.connect(
163 this, &ChannelTest<T>::OnMediaMonitor);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000164 if ((flags1 & DTLS) && (flags2 & DTLS)) {
165 flags1 = (flags1 & ~SECURE);
166 flags2 = (flags2 & ~SECURE);
167 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 CreateContent(flags1, kPcmuCodec, kH264Codec,
169 &local_media_content1_);
170 CreateContent(flags2, kPcmuCodec, kH264Codec,
171 &local_media_content2_);
172 CopyContent(local_media_content1_, &remote_media_content1_);
173 CopyContent(local_media_content2_, &remote_media_content2_);
174
175 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200176 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700177 transport_controller1_.SetLocalCertificate(rtc::RTCCertificate::Create(
178 rtc::scoped_ptr<rtc::SSLIdentity>(
179 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))
180 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 }
182 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200183 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700184 transport_controller2_.SetLocalCertificate(rtc::RTCCertificate::Create(
185 rtc::scoped_ptr<rtc::SSLIdentity>(
186 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))
187 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 }
189
190 // Add stream information (SSRC) to the local content but not to the remote
191 // content. This means that we per default know the SSRC of what we send but
192 // not what we receive.
193 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
194 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
195
196 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
197 if (flags1 & SSRC_MUX) {
198 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
199 }
200 if (flags2 & SSRC_MUX) {
201 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
202 }
203 }
deadbeefcbecd352015-09-23 11:50:27 -0700204 typename T::Channel* CreateChannel(
205 rtc::Thread* thread,
206 cricket::MediaEngineInterface* engine,
207 typename T::MediaChannel* ch,
208 cricket::TransportController* transport_controller,
209 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700211 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 if (!channel->Init()) {
213 delete channel;
214 channel = NULL;
215 }
216 return channel;
217 }
218
219 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000220 bool result = channel1_->SetLocalContent(&local_media_content1_,
221 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 if (result) {
223 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000224 result = channel2_->SetRemoteContent(&remote_media_content1_,
225 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700227 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000229 result = channel2_->SetLocalContent(&local_media_content2_,
230 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 }
232 }
233 return result;
234 }
235
236 bool SendAccept() {
237 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000238 return channel1_->SetRemoteContent(&remote_media_content2_,
239 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 }
241
242 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000243 bool result = channel1_->SetLocalContent(&local_media_content1_,
244 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 if (result) {
246 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 result = channel2_->SetRemoteContent(&remote_media_content1_,
248 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 }
250 return result;
251 }
252
253 bool SendProvisionalAnswer() {
254 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000255 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 if (result) {
257 channel2_->Enable(true);
258 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000259 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700260 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 }
262 return result;
263 }
264
265 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000266 bool result = channel2_->SetLocalContent(&local_media_content2_,
267 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000269 result = channel1_->SetRemoteContent(&remote_media_content2_,
270 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 return result;
272 }
273
274 bool SendTerminate() {
275 channel1_.reset();
276 channel2_.reset();
277 return true;
278 }
279
280 bool AddStream1(int id) {
281 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
282 }
283 bool RemoveStream1(int id) {
284 return channel1_->RemoveRecvStream(id);
285 }
286
deadbeefcbecd352015-09-23 11:50:27 -0700287 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700289 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 }
291 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700292 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 }
294
295 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000296 return media_channel1_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700297 static_cast<int>(rtp_packet_.size()),
298 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000301 return media_channel2_->SendRtp(rtp_packet_.c_str(),
stefanc1aeaf02015-10-15 07:26:07 -0700302 static_cast<int>(rtp_packet_.size()),
303 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 }
305 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000306 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
307 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 }
309 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000310 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
311 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 }
313 // Methods to send custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200314 bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000315 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700316 return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()),
317 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200319 bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000320 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
stefanc1aeaf02015-10-15 07:26:07 -0700321 return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()),
322 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200324 bool SendCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000326 return media_channel1_->SendRtcp(data.c_str(),
327 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200329 bool SendCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000331 return media_channel2_->SendRtcp(data.c_str(),
332 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
334 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000335 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
336 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 }
338 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000339 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
340 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
342 bool CheckRtcp1() {
343 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000344 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000345 }
346 bool CheckRtcp2() {
347 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000348 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350 // Methods to check custom data.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200351 bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000352 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000353 return media_channel1_->CheckRtp(data.c_str(),
354 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200356 bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000357 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000358 return media_channel2_->CheckRtp(data.c_str(),
359 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200361 bool CheckCustomRtcp1(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000363 return media_channel1_->CheckRtcp(data.c_str(),
364 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200366 bool CheckCustomRtcp2(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000368 return media_channel2_->CheckRtcp(data.c_str(),
369 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200371 std::string CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 std::string data(rtp_packet_);
373 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000374 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
375 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000376 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000377 rtc::Set8(const_cast<char*>(data.c_str()), 1,
378 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000379 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 return data;
381 }
Peter Boström0c4e06b2015-10-07 12:23:21 +0200382 std::string CreateRtcpData(uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000383 std::string data(rtcp_packet_);
384 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000385 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 return data;
387 }
388
389 bool CheckNoRtp1() {
390 return media_channel1_->CheckNoRtp();
391 }
392 bool CheckNoRtp2() {
393 return media_channel2_->CheckNoRtp();
394 }
395 bool CheckNoRtcp1() {
396 return media_channel1_->CheckNoRtcp();
397 }
398 bool CheckNoRtcp2() {
399 return media_channel2_->CheckNoRtcp();
400 }
401
402 void CreateContent(int flags,
403 const cricket::AudioCodec& audio_codec,
404 const cricket::VideoCodec& video_codec,
405 typename T::Content* content) {
406 // overridden in specialized classes
407 }
408 void CopyContent(const typename T::Content& source,
409 typename T::Content* content) {
410 // overridden in specialized classes
411 }
412
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413 // Creates a cricket::SessionDescription with one MediaContent and one stream.
414 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
Peter Boström0c4e06b2015-10-07 12:23:21 +0200415 cricket::SessionDescription* CreateSessionDescriptionWithStream(
416 uint32_t ssrc) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 typename T::Content content;
418 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
419 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
420 AddLegacyStreamInContent(ssrc, 0, &content);
421 sdesc->AddContent("DUMMY_CONTENT_NAME",
422 cricket::NS_JINGLE_RTP, content.Copy());
423 return sdesc;
424 }
425
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000426 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 public:
428 typedef bool (ChannelTest<T>::*Method)();
429 CallThread(ChannelTest<T>* obj, Method method, bool* result)
430 : obj_(obj),
431 method_(method),
432 result_(result) {
433 *result = false;
434 }
435 virtual void DoWork() {
436 bool result = (*obj_.*method_)();
437 if (result_) {
438 *result_ = result;
439 }
440 }
441 private:
442 ChannelTest<T>* obj_;
443 Method method_;
444 bool* result_;
445 };
446 void CallOnThread(typename CallThread::Method method, bool* result) {
447 CallThread* thread = new CallThread(this, method, result);
448 thread->Start();
449 thread->Release();
450 }
451
452 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
453 bool* result) {
454 CallThread* thread = new CallThread(this, method, result);
455 thread->Start();
456 thread->Destroy(true);
457 }
458
459 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
460 return false; // overridden in specialized classes
461 }
462
463 void OnMediaMonitor(typename T::Channel* channel,
464 const typename T::MediaInfo& info) {
465 if (channel == channel1_.get()) {
466 media_info_callbacks1_++;
467 } else if (channel == channel2_.get()) {
468 media_info_callbacks2_++;
469 }
470 }
471
Peter Boström0c4e06b2015-10-07 12:23:21 +0200472 void AddLegacyStreamInContent(uint32_t ssrc,
473 int flags,
474 typename T::Content* content) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 // Base implementation.
476 }
477
478 // Tests that can be used by derived classes.
479
480 // Basic sanity check.
481 void TestInit() {
482 CreateChannels(0, 0);
483 EXPECT_FALSE(channel1_->secure());
484 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200485 if (verify_playout_) {
486 EXPECT_FALSE(media_channel1_->playout());
487 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 EXPECT_TRUE(media_channel1_->codecs().empty());
489 EXPECT_TRUE(media_channel1_->recv_streams().empty());
490 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
491 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
492 }
493
494 // Test that SetLocalContent and SetRemoteContent properly configure
495 // the codecs.
496 void TestSetContents() {
497 CreateChannels(0, 0);
498 typename T::Content content;
499 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000500 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000502 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000503 ASSERT_EQ(1U, media_channel1_->codecs().size());
504 EXPECT_TRUE(CodecMatches(content.codecs()[0],
505 media_channel1_->codecs()[0]));
506 }
507
508 // Test that SetLocalContent and SetRemoteContent properly deals
509 // with an empty offer.
510 void TestSetContentsNullOffer() {
511 CreateChannels(0, 0);
512 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000513 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 CreateContent(0, kPcmuCodec, kH264Codec, &content);
515 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000516 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517 ASSERT_EQ(1U, media_channel1_->codecs().size());
518 EXPECT_TRUE(CodecMatches(content.codecs()[0],
519 media_channel1_->codecs()[0]));
520 }
521
522 // Test that SetLocalContent and SetRemoteContent properly set RTCP
523 // mux.
524 void TestSetContentsRtcpMux() {
525 CreateChannels(RTCP, RTCP);
526 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
527 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
528 typename T::Content content;
529 CreateContent(0, kPcmuCodec, kH264Codec, &content);
530 // Both sides agree on mux. Should no longer be a separate RTCP channel.
531 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000532 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
533 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
535 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000536 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000538 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
540 }
541
542 // Test that SetLocalContent and SetRemoteContent properly set RTCP
543 // mux when a provisional answer is received.
544 void TestSetContentsRtcpMuxWithPrAnswer() {
545 CreateChannels(RTCP, RTCP);
546 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
547 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
548 typename T::Content content;
549 CreateContent(0, kPcmuCodec, kH264Codec, &content);
550 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000551 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
552 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000554 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 // Both sides agree on mux. Should no longer be a separate RTCP channel.
556 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
557 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000558 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000560 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
561 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
563 }
564
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 // Test that SetRemoteContent properly deals with a content update.
566 void TestSetRemoteContentUpdate() {
567 CreateChannels(0, 0);
568 typename T::Content content;
569 CreateContent(RTCP | RTCP_MUX | SECURE,
570 kPcmuCodec, kH264Codec,
571 &content);
572 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000573 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
574 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 ASSERT_EQ(1U, media_channel1_->codecs().size());
576 EXPECT_TRUE(CodecMatches(content.codecs()[0],
577 media_channel1_->codecs()[0]));
578 // Now update with other codecs.
579 typename T::Content update_content;
580 update_content.set_partial(true);
581 CreateContent(0, kIsacCodec, kH264SvcCodec,
582 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000583 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 ASSERT_EQ(1U, media_channel1_->codecs().size());
585 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
586 media_channel1_->codecs()[0]));
587 // Now update without any codecs. This is ignored.
588 typename T::Content empty_content;
589 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000590 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 ASSERT_EQ(1U, media_channel1_->codecs().size());
592 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
593 media_channel1_->codecs()[0]));
594 }
595
596 // Test that Add/RemoveStream properly forward to the media channel.
597 void TestStreams() {
598 CreateChannels(0, 0);
599 EXPECT_TRUE(AddStream1(1));
600 EXPECT_TRUE(AddStream1(2));
601 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
602 EXPECT_TRUE(RemoveStream1(2));
603 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
604 EXPECT_TRUE(RemoveStream1(1));
605 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
606 }
607
608 // Test that SetLocalContent properly handles adding and removing StreamParams
609 // to the local content description.
610 // This test uses the CA_UPDATE action that don't require a full
611 // MediaContentDescription to do an update.
612 void TestUpdateStreamsInLocalContent() {
613 cricket::StreamParams stream1;
614 stream1.groupid = "group1";
615 stream1.id = "stream1";
616 stream1.ssrcs.push_back(kSsrc1);
617 stream1.cname = "stream1_cname";
618
619 cricket::StreamParams stream2;
620 stream2.groupid = "group2";
621 stream2.id = "stream2";
622 stream2.ssrcs.push_back(kSsrc2);
623 stream2.cname = "stream2_cname";
624
625 cricket::StreamParams stream3;
626 stream3.groupid = "group3";
627 stream3.id = "stream3";
628 stream3.ssrcs.push_back(kSsrc3);
629 stream3.cname = "stream3_cname";
630
631 CreateChannels(0, 0);
632 typename T::Content content1;
633 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
634 content1.AddStream(stream1);
635 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000636 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637
638 ASSERT_EQ(1u, media_channel1_->send_streams().size());
639 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
640
641 // Update the local streams by adding another sending stream.
642 // Use a partial updated session description.
643 typename T::Content content2;
644 content2.AddStream(stream2);
645 content2.AddStream(stream3);
646 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000647 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 ASSERT_EQ(3u, media_channel1_->send_streams().size());
649 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
650 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
651 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
652
653 // Update the local streams by removing the first sending stream.
654 // This is done by removing all SSRCS for this particular stream.
655 typename T::Content content3;
656 stream1.ssrcs.clear();
657 content3.AddStream(stream1);
658 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000659 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660 ASSERT_EQ(2u, media_channel1_->send_streams().size());
661 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
662 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
663
664 // Update the local streams with a stream that does not change.
665 // THe update is ignored.
666 typename T::Content content4;
667 content4.AddStream(stream2);
668 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000669 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000670 ASSERT_EQ(2u, media_channel1_->send_streams().size());
671 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
672 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
673 }
674
675 // Test that SetRemoteContent properly handles adding and removing
676 // StreamParams to the remote content description.
677 // This test uses the CA_UPDATE action that don't require a full
678 // MediaContentDescription to do an update.
679 void TestUpdateStreamsInRemoteContent() {
680 cricket::StreamParams stream1;
681 stream1.id = "Stream1";
682 stream1.groupid = "1";
683 stream1.ssrcs.push_back(kSsrc1);
684 stream1.cname = "stream1_cname";
685
686 cricket::StreamParams stream2;
687 stream2.id = "Stream2";
688 stream2.groupid = "2";
689 stream2.ssrcs.push_back(kSsrc2);
690 stream2.cname = "stream2_cname";
691
692 cricket::StreamParams stream3;
693 stream3.id = "Stream3";
694 stream3.groupid = "3";
695 stream3.ssrcs.push_back(kSsrc3);
696 stream3.cname = "stream3_cname";
697
698 CreateChannels(0, 0);
699 typename T::Content content1;
700 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
701 content1.AddStream(stream1);
702 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000703 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704
705 ASSERT_EQ(1u, media_channel1_->codecs().size());
706 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
707 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
708
709 // Update the remote streams by adding another sending stream.
710 // Use a partial updated session description.
711 typename T::Content content2;
712 content2.AddStream(stream2);
713 content2.AddStream(stream3);
714 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000715 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
717 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
718 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
719 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
720
721 // Update the remote streams by removing the first stream.
722 // This is done by removing all SSRCS for this particular stream.
723 typename T::Content content3;
724 stream1.ssrcs.clear();
725 content3.AddStream(stream1);
726 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000727 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
729 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
730 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
731
732 // Update the remote streams with a stream that does not change.
733 // The update is ignored.
734 typename T::Content content4;
735 content4.AddStream(stream2);
736 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000737 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
739 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
740 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
741 }
742
743 // Test that SetLocalContent and SetRemoteContent properly
744 // handles adding and removing StreamParams when the action is a full
745 // CA_OFFER / CA_ANSWER.
746 void TestChangeStreamParamsInContent() {
747 cricket::StreamParams stream1;
748 stream1.groupid = "group1";
749 stream1.id = "stream1";
750 stream1.ssrcs.push_back(kSsrc1);
751 stream1.cname = "stream1_cname";
752
753 cricket::StreamParams stream2;
754 stream2.groupid = "group1";
755 stream2.id = "stream2";
756 stream2.ssrcs.push_back(kSsrc2);
757 stream2.cname = "stream2_cname";
758
759 // Setup a call where channel 1 send |stream1| to channel 2.
760 CreateChannels(0, 0);
761 typename T::Content content1;
762 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
763 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000764 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 EXPECT_TRUE(channel1_->Enable(true));
766 EXPECT_EQ(1u, media_channel1_->send_streams().size());
767
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000768 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700770 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771
772 // Channel 2 do not send anything.
773 typename T::Content content2;
774 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000775 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000777 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 EXPECT_TRUE(channel2_->Enable(true));
779 EXPECT_EQ(0u, media_channel2_->send_streams().size());
780
781 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
782 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
783
784 // Let channel 2 update the content by sending |stream2| and enable SRTP.
785 typename T::Content content3;
786 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
787 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000788 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 ASSERT_EQ(1u, media_channel2_->send_streams().size());
790 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
791
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000792 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
794 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
795
796 // Channel 1 replies but stop sending stream1.
797 typename T::Content content4;
798 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000799 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 EXPECT_EQ(0u, media_channel1_->send_streams().size());
801
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000802 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
804
805 EXPECT_TRUE(channel1_->secure());
806 EXPECT_TRUE(channel2_->secure());
807 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
808 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
809 }
810
811 // Test that we only start playout and sending at the right times.
812 void TestPlayoutAndSendingStates() {
813 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200814 if (verify_playout_) {
815 EXPECT_FALSE(media_channel1_->playout());
816 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200818 if (verify_playout_) {
819 EXPECT_FALSE(media_channel2_->playout());
820 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 EXPECT_FALSE(media_channel2_->sending());
822 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200823 if (verify_playout_) {
824 EXPECT_FALSE(media_channel1_->playout());
825 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000827 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
828 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200829 if (verify_playout_) {
830 EXPECT_TRUE(media_channel1_->playout());
831 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000833 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
834 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200835 if (verify_playout_) {
836 EXPECT_FALSE(media_channel2_->playout());
837 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000839 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
840 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200841 if (verify_playout_) {
842 EXPECT_FALSE(media_channel2_->playout());
843 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700845 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200846 if (verify_playout_) {
847 EXPECT_TRUE(media_channel1_->playout());
848 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200850 if (verify_playout_) {
851 EXPECT_FALSE(media_channel2_->playout());
852 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 EXPECT_FALSE(media_channel2_->sending());
854 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200855 if (verify_playout_) {
856 EXPECT_TRUE(media_channel2_->playout());
857 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000859 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
860 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200861 if (verify_playout_) {
862 EXPECT_TRUE(media_channel1_->playout());
863 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 EXPECT_TRUE(media_channel1_->sending());
865 }
866
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 // Test that changing the MediaContentDirection in the local and remote
868 // session description start playout and sending at the right time.
869 void TestMediaContentDirection() {
870 CreateChannels(0, 0);
871 typename T::Content content1;
872 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
873 typename T::Content content2;
874 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
875 // Set |content2| to be InActive.
876 content2.set_direction(cricket::MD_INACTIVE);
877
878 EXPECT_TRUE(channel1_->Enable(true));
879 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200880 if (verify_playout_) {
881 EXPECT_FALSE(media_channel1_->playout());
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200884 if (verify_playout_) {
885 EXPECT_FALSE(media_channel2_->playout());
886 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 EXPECT_FALSE(media_channel2_->sending());
888
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000889 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
890 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
891 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
892 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700893 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894
Peter Boström34fbfff2015-09-24 19:20:30 +0200895 if (verify_playout_) {
896 EXPECT_TRUE(media_channel1_->playout());
897 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200899 if (verify_playout_) {
900 EXPECT_FALSE(media_channel2_->playout()); // local InActive
901 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 EXPECT_FALSE(media_channel2_->sending()); // local InActive
903
904 // Update |content2| to be RecvOnly.
905 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000906 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
907 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908
Peter Boström34fbfff2015-09-24 19:20:30 +0200909 if (verify_playout_) {
910 EXPECT_TRUE(media_channel1_->playout());
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200913 if (verify_playout_) {
914 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
915 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
917
918 // Update |content2| to be SendRecv.
919 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000920 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
921 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922
Peter Boström34fbfff2015-09-24 19:20:30 +0200923 if (verify_playout_) {
924 EXPECT_TRUE(media_channel1_->playout());
925 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200927 if (verify_playout_) {
928 EXPECT_TRUE(media_channel2_->playout());
929 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 EXPECT_TRUE(media_channel2_->sending());
931 }
932
933 // Test setting up a call.
934 void TestCallSetup() {
935 CreateChannels(0, 0);
936 EXPECT_FALSE(channel1_->secure());
937 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200938 if (verify_playout_) {
939 EXPECT_TRUE(media_channel1_->playout());
940 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 EXPECT_FALSE(media_channel1_->sending());
942 EXPECT_TRUE(SendAccept());
943 EXPECT_FALSE(channel1_->secure());
944 EXPECT_TRUE(media_channel1_->sending());
945 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200946 if (verify_playout_) {
947 EXPECT_TRUE(media_channel2_->playout());
948 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 EXPECT_TRUE(media_channel2_->sending());
950 EXPECT_EQ(1U, media_channel2_->codecs().size());
951 }
952
953 // Test that we don't crash if packets are sent during call teardown
954 // when RTCP mux is enabled. This is a regression test against a specific
955 // race condition that would only occur when a RTCP packet was sent during
956 // teardown of a channel on which RTCP mux was enabled.
957 void TestCallTeardownRtcpMux() {
958 class LastWordMediaChannel : public T::MediaChannel {
959 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200960 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 ~LastWordMediaChannel() {
stefanc1aeaf02015-10-15 07:26:07 -0700962 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame),
963 rtc::PacketOptions());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
965 }
966 };
967 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
968 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000969 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 EXPECT_TRUE(SendInitiate());
971 EXPECT_TRUE(SendAccept());
972 EXPECT_TRUE(SendTerminate());
973 }
974
975 // Send voice RTP data to the other side and ensure it gets there.
976 void SendRtpToRtp() {
977 CreateChannels(0, 0);
978 EXPECT_TRUE(SendInitiate());
979 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700980 ASSERT_TRUE(GetTransport1());
981 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 EXPECT_EQ(1U, GetTransport1()->channels().size());
983 EXPECT_EQ(1U, GetTransport2()->channels().size());
984 EXPECT_TRUE(SendRtp1());
985 EXPECT_TRUE(SendRtp2());
986 EXPECT_TRUE(CheckRtp1());
987 EXPECT_TRUE(CheckRtp2());
988 EXPECT_TRUE(CheckNoRtp1());
989 EXPECT_TRUE(CheckNoRtp2());
990 }
991
992 // Check that RTCP is not transmitted if both sides don't support RTCP.
993 void SendNoRtcpToNoRtcp() {
994 CreateChannels(0, 0);
995 EXPECT_TRUE(SendInitiate());
996 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700997 ASSERT_TRUE(GetTransport1());
998 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 EXPECT_EQ(1U, GetTransport1()->channels().size());
1000 EXPECT_EQ(1U, GetTransport2()->channels().size());
1001 EXPECT_FALSE(SendRtcp1());
1002 EXPECT_FALSE(SendRtcp2());
1003 EXPECT_TRUE(CheckNoRtcp1());
1004 EXPECT_TRUE(CheckNoRtcp2());
1005 }
1006
1007 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1008 void SendNoRtcpToRtcp() {
1009 CreateChannels(0, RTCP);
1010 EXPECT_TRUE(SendInitiate());
1011 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001012 ASSERT_TRUE(GetTransport1());
1013 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 EXPECT_EQ(1U, GetTransport1()->channels().size());
1015 EXPECT_EQ(2U, GetTransport2()->channels().size());
1016 EXPECT_FALSE(SendRtcp1());
1017 EXPECT_FALSE(SendRtcp2());
1018 EXPECT_TRUE(CheckNoRtcp1());
1019 EXPECT_TRUE(CheckNoRtcp2());
1020 }
1021
1022 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1023 void SendRtcpToNoRtcp() {
1024 CreateChannels(RTCP, 0);
1025 EXPECT_TRUE(SendInitiate());
1026 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001027 ASSERT_TRUE(GetTransport1());
1028 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 EXPECT_EQ(2U, GetTransport1()->channels().size());
1030 EXPECT_EQ(1U, GetTransport2()->channels().size());
1031 EXPECT_FALSE(SendRtcp1());
1032 EXPECT_FALSE(SendRtcp2());
1033 EXPECT_TRUE(CheckNoRtcp1());
1034 EXPECT_TRUE(CheckNoRtcp2());
1035 }
1036
1037 // Check that RTCP is transmitted if both sides support RTCP.
1038 void SendRtcpToRtcp() {
1039 CreateChannels(RTCP, RTCP);
1040 EXPECT_TRUE(SendInitiate());
1041 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001042 ASSERT_TRUE(GetTransport1());
1043 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 EXPECT_EQ(2U, GetTransport1()->channels().size());
1045 EXPECT_EQ(2U, GetTransport2()->channels().size());
1046 EXPECT_TRUE(SendRtcp1());
1047 EXPECT_TRUE(SendRtcp2());
1048 EXPECT_TRUE(CheckRtcp1());
1049 EXPECT_TRUE(CheckRtcp2());
1050 EXPECT_TRUE(CheckNoRtcp1());
1051 EXPECT_TRUE(CheckNoRtcp2());
1052 }
1053
1054 // Check that RTCP is transmitted if only the initiator supports mux.
1055 void SendRtcpMuxToRtcp() {
1056 CreateChannels(RTCP | RTCP_MUX, RTCP);
1057 EXPECT_TRUE(SendInitiate());
1058 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001059 ASSERT_TRUE(GetTransport1());
1060 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001061 EXPECT_EQ(2U, GetTransport1()->channels().size());
1062 EXPECT_EQ(2U, GetTransport2()->channels().size());
1063 EXPECT_TRUE(SendRtcp1());
1064 EXPECT_TRUE(SendRtcp2());
1065 EXPECT_TRUE(CheckRtcp1());
1066 EXPECT_TRUE(CheckRtcp2());
1067 EXPECT_TRUE(CheckNoRtcp1());
1068 EXPECT_TRUE(CheckNoRtcp2());
1069 }
1070
1071 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1072 void SendRtcpMuxToRtcpMux() {
1073 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1074 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001075 ASSERT_TRUE(GetTransport1());
1076 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 EXPECT_EQ(2U, GetTransport1()->channels().size());
1078 EXPECT_EQ(1U, GetTransport2()->channels().size());
1079 EXPECT_TRUE(SendAccept());
1080 EXPECT_EQ(1U, GetTransport1()->channels().size());
1081 EXPECT_TRUE(SendRtp1());
1082 EXPECT_TRUE(SendRtp2());
1083 EXPECT_TRUE(SendRtcp1());
1084 EXPECT_TRUE(SendRtcp2());
1085 EXPECT_TRUE(CheckRtp1());
1086 EXPECT_TRUE(CheckRtp2());
1087 EXPECT_TRUE(CheckNoRtp1());
1088 EXPECT_TRUE(CheckNoRtp2());
1089 EXPECT_TRUE(CheckRtcp1());
1090 EXPECT_TRUE(CheckRtcp2());
1091 EXPECT_TRUE(CheckNoRtcp1());
1092 EXPECT_TRUE(CheckNoRtcp2());
1093 }
1094
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001095 // Check that RTP and RTCP are transmitted ok when both sides
1096 // support mux and one the offerer requires mux.
1097 void SendRequireRtcpMuxToRtcpMux() {
1098 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1099 channel1_->ActivateRtcpMux();
1100 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001101 ASSERT_TRUE(GetTransport1());
1102 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001103 EXPECT_EQ(1U, GetTransport1()->channels().size());
1104 EXPECT_EQ(1U, GetTransport2()->channels().size());
1105 EXPECT_TRUE(SendAccept());
1106 EXPECT_TRUE(SendRtp1());
1107 EXPECT_TRUE(SendRtp2());
1108 EXPECT_TRUE(SendRtcp1());
1109 EXPECT_TRUE(SendRtcp2());
1110 EXPECT_TRUE(CheckRtp1());
1111 EXPECT_TRUE(CheckRtp2());
1112 EXPECT_TRUE(CheckNoRtp1());
1113 EXPECT_TRUE(CheckNoRtp2());
1114 EXPECT_TRUE(CheckRtcp1());
1115 EXPECT_TRUE(CheckRtcp2());
1116 EXPECT_TRUE(CheckNoRtcp1());
1117 EXPECT_TRUE(CheckNoRtcp2());
1118 }
1119
1120 // Check that RTP and RTCP are transmitted ok when both sides
1121 // support mux and one the answerer requires rtcp mux.
1122 void SendRtcpMuxToRequireRtcpMux() {
1123 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1124 channel2_->ActivateRtcpMux();
1125 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001126 ASSERT_TRUE(GetTransport1());
1127 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001128 EXPECT_EQ(2U, GetTransport1()->channels().size());
1129 EXPECT_EQ(1U, GetTransport2()->channels().size());
1130 EXPECT_TRUE(SendAccept());
1131 EXPECT_EQ(1U, GetTransport1()->channels().size());
1132 EXPECT_TRUE(SendRtp1());
1133 EXPECT_TRUE(SendRtp2());
1134 EXPECT_TRUE(SendRtcp1());
1135 EXPECT_TRUE(SendRtcp2());
1136 EXPECT_TRUE(CheckRtp1());
1137 EXPECT_TRUE(CheckRtp2());
1138 EXPECT_TRUE(CheckNoRtp1());
1139 EXPECT_TRUE(CheckNoRtp2());
1140 EXPECT_TRUE(CheckRtcp1());
1141 EXPECT_TRUE(CheckRtcp2());
1142 EXPECT_TRUE(CheckNoRtcp1());
1143 EXPECT_TRUE(CheckNoRtcp2());
1144 }
1145
1146 // Check that RTP and RTCP are transmitted ok when both sides
1147 // require mux.
1148 void SendRequireRtcpMuxToRequireRtcpMux() {
1149 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1150 channel1_->ActivateRtcpMux();
1151 channel2_->ActivateRtcpMux();
1152 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001153 ASSERT_TRUE(GetTransport1());
1154 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001155 EXPECT_EQ(1U, GetTransport1()->channels().size());
1156 EXPECT_EQ(1U, GetTransport2()->channels().size());
1157 EXPECT_TRUE(SendAccept());
1158 EXPECT_EQ(1U, GetTransport1()->channels().size());
1159 EXPECT_TRUE(SendRtp1());
1160 EXPECT_TRUE(SendRtp2());
1161 EXPECT_TRUE(SendRtcp1());
1162 EXPECT_TRUE(SendRtcp2());
1163 EXPECT_TRUE(CheckRtp1());
1164 EXPECT_TRUE(CheckRtp2());
1165 EXPECT_TRUE(CheckNoRtp1());
1166 EXPECT_TRUE(CheckNoRtp2());
1167 EXPECT_TRUE(CheckRtcp1());
1168 EXPECT_TRUE(CheckRtcp2());
1169 EXPECT_TRUE(CheckNoRtcp1());
1170 EXPECT_TRUE(CheckNoRtcp2());
1171 }
1172
1173 // Check that SendAccept fails if the answerer doesn't support mux
1174 // and the offerer requires it.
1175 void SendRequireRtcpMuxToNoRtcpMux() {
1176 CreateChannels(RTCP | RTCP_MUX, RTCP);
1177 channel1_->ActivateRtcpMux();
1178 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001179 ASSERT_TRUE(GetTransport1());
1180 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001181 EXPECT_EQ(1U, GetTransport1()->channels().size());
1182 EXPECT_EQ(2U, GetTransport2()->channels().size());
1183 EXPECT_FALSE(SendAccept());
1184 }
1185
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 // Check that RTCP data sent by the initiator before the accept is not muxed.
1187 void SendEarlyRtcpMuxToRtcp() {
1188 CreateChannels(RTCP | RTCP_MUX, RTCP);
1189 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001190 ASSERT_TRUE(GetTransport1());
1191 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001192 EXPECT_EQ(2U, GetTransport1()->channels().size());
1193 EXPECT_EQ(2U, GetTransport2()->channels().size());
1194
1195 // RTCP can be sent before the call is accepted, if the transport is ready.
1196 // It should not be muxed though, as the remote side doesn't support mux.
1197 EXPECT_TRUE(SendRtcp1());
1198 EXPECT_TRUE(CheckNoRtp2());
1199 EXPECT_TRUE(CheckRtcp2());
1200
1201 // Send RTCP packet from callee and verify that it is received.
1202 EXPECT_TRUE(SendRtcp2());
1203 EXPECT_TRUE(CheckNoRtp1());
1204 EXPECT_TRUE(CheckRtcp1());
1205
1206 // Complete call setup and ensure everything is still OK.
1207 EXPECT_TRUE(SendAccept());
1208 EXPECT_EQ(2U, GetTransport1()->channels().size());
1209 EXPECT_TRUE(SendRtcp1());
1210 EXPECT_TRUE(CheckRtcp2());
1211 EXPECT_TRUE(SendRtcp2());
1212 EXPECT_TRUE(CheckRtcp1());
1213 }
1214
1215
1216 // Check that RTCP data is not muxed until both sides have enabled muxing,
1217 // but that we properly demux before we get the accept message, since there
1218 // is a race between RTP data and the jingle accept.
1219 void SendEarlyRtcpMuxToRtcpMux() {
1220 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1221 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001222 ASSERT_TRUE(GetTransport1());
1223 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001224 EXPECT_EQ(2U, GetTransport1()->channels().size());
1225 EXPECT_EQ(1U, GetTransport2()->channels().size());
1226
1227 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1228 // we haven't yet received the accept that says we should mux.
1229 EXPECT_FALSE(SendRtcp1());
1230
1231 // Send muxed RTCP packet from callee and verify that it is received.
1232 EXPECT_TRUE(SendRtcp2());
1233 EXPECT_TRUE(CheckNoRtp1());
1234 EXPECT_TRUE(CheckRtcp1());
1235
1236 // Complete call setup and ensure everything is still OK.
1237 EXPECT_TRUE(SendAccept());
1238 EXPECT_EQ(1U, GetTransport1()->channels().size());
1239 EXPECT_TRUE(SendRtcp1());
1240 EXPECT_TRUE(CheckRtcp2());
1241 EXPECT_TRUE(SendRtcp2());
1242 EXPECT_TRUE(CheckRtcp1());
1243 }
1244
1245 // Test that we properly send SRTP with RTCP in both directions.
1246 // You can pass in DTLS and/or RTCP_MUX as flags.
1247 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1248 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1249 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1250
1251 int flags1 = RTCP | SECURE | flags1_in;
1252 int flags2 = RTCP | SECURE | flags2_in;
1253 bool dtls1 = !!(flags1_in & DTLS);
1254 bool dtls2 = !!(flags2_in & DTLS);
1255 CreateChannels(flags1, flags2);
1256 EXPECT_FALSE(channel1_->secure());
1257 EXPECT_FALSE(channel2_->secure());
1258 EXPECT_TRUE(SendInitiate());
1259 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1260 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1261 EXPECT_TRUE(SendAccept());
1262 EXPECT_TRUE(channel1_->secure());
1263 EXPECT_TRUE(channel2_->secure());
1264 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1265 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1266 EXPECT_TRUE(SendRtp1());
1267 EXPECT_TRUE(SendRtp2());
1268 EXPECT_TRUE(SendRtcp1());
1269 EXPECT_TRUE(SendRtcp2());
1270 EXPECT_TRUE(CheckRtp1());
1271 EXPECT_TRUE(CheckRtp2());
1272 EXPECT_TRUE(CheckNoRtp1());
1273 EXPECT_TRUE(CheckNoRtp2());
1274 EXPECT_TRUE(CheckRtcp1());
1275 EXPECT_TRUE(CheckRtcp2());
1276 EXPECT_TRUE(CheckNoRtcp1());
1277 EXPECT_TRUE(CheckNoRtcp2());
1278 }
1279
1280 // Test that we properly handling SRTP negotiating down to RTP.
1281 void SendSrtpToRtp() {
1282 CreateChannels(RTCP | SECURE, RTCP);
1283 EXPECT_FALSE(channel1_->secure());
1284 EXPECT_FALSE(channel2_->secure());
1285 EXPECT_TRUE(SendInitiate());
1286 EXPECT_TRUE(SendAccept());
1287 EXPECT_FALSE(channel1_->secure());
1288 EXPECT_FALSE(channel2_->secure());
1289 EXPECT_TRUE(SendRtp1());
1290 EXPECT_TRUE(SendRtp2());
1291 EXPECT_TRUE(SendRtcp1());
1292 EXPECT_TRUE(SendRtcp2());
1293 EXPECT_TRUE(CheckRtp1());
1294 EXPECT_TRUE(CheckRtp2());
1295 EXPECT_TRUE(CheckNoRtp1());
1296 EXPECT_TRUE(CheckNoRtp2());
1297 EXPECT_TRUE(CheckRtcp1());
1298 EXPECT_TRUE(CheckRtcp2());
1299 EXPECT_TRUE(CheckNoRtcp1());
1300 EXPECT_TRUE(CheckNoRtcp2());
1301 }
1302
1303 // Test that we can send and receive early media when a provisional answer is
1304 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1305 void SendEarlyMediaUsingRtcpMuxSrtp() {
1306 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1307
1308 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1309 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1310 EXPECT_TRUE(SendOffer());
1311 EXPECT_TRUE(SendProvisionalAnswer());
1312 EXPECT_TRUE(channel1_->secure());
1313 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001314 ASSERT_TRUE(GetTransport1());
1315 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001316 EXPECT_EQ(2U, GetTransport1()->channels().size());
1317 EXPECT_EQ(2U, GetTransport2()->channels().size());
1318 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1319 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1320 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1321 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1322
1323 // Send packets from callee and verify that it is received.
1324 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1325 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1326 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1327 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1328
1329 // Complete call setup and ensure everything is still OK.
1330 EXPECT_TRUE(SendFinalAnswer());
1331 EXPECT_EQ(1U, GetTransport1()->channels().size());
1332 EXPECT_EQ(1U, GetTransport2()->channels().size());
1333 EXPECT_TRUE(channel1_->secure());
1334 EXPECT_TRUE(channel2_->secure());
1335 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1336 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1337 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1338 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1339 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1340 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1341 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1342 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1343 }
1344
1345 // Test that we properly send RTP without SRTP from a thread.
1346 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001347 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1348 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 EXPECT_TRUE(SendInitiate());
1350 EXPECT_TRUE(SendAccept());
1351 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1352 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001353 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1354 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1356 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1357 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1358 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1359 EXPECT_TRUE(CheckNoRtp1());
1360 EXPECT_TRUE(CheckNoRtp2());
1361 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1362 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1363 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1364 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1365 EXPECT_TRUE(CheckNoRtcp1());
1366 EXPECT_TRUE(CheckNoRtcp2());
1367 }
1368
1369 // Test that we properly send SRTP with RTCP from a thread.
1370 void SendSrtpToSrtpOnThread() {
1371 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1372 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1373 EXPECT_TRUE(SendInitiate());
1374 EXPECT_TRUE(SendAccept());
1375 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1376 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1377 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1378 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1379 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1380 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1381 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1382 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1383 EXPECT_TRUE(CheckNoRtp1());
1384 EXPECT_TRUE(CheckNoRtp2());
1385 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1386 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1387 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1388 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1389 EXPECT_TRUE(CheckNoRtcp1());
1390 EXPECT_TRUE(CheckNoRtcp2());
1391 }
1392
1393 // Test that the mediachannel retains its sending state after the transport
1394 // becomes non-writable.
1395 void SendWithWritabilityLoss() {
1396 CreateChannels(0, 0);
1397 EXPECT_TRUE(SendInitiate());
1398 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001399 ASSERT_TRUE(GetTransport1());
1400 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 EXPECT_EQ(1U, GetTransport1()->channels().size());
1402 EXPECT_EQ(1U, GetTransport2()->channels().size());
1403 EXPECT_TRUE(SendRtp1());
1404 EXPECT_TRUE(SendRtp2());
1405 EXPECT_TRUE(CheckRtp1());
1406 EXPECT_TRUE(CheckRtp2());
1407 EXPECT_TRUE(CheckNoRtp1());
1408 EXPECT_TRUE(CheckNoRtp2());
1409
wu@webrtc.org97077a32013-10-25 21:18:33 +00001410 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 EXPECT_FALSE(SendRtp1());
1413 EXPECT_TRUE(SendRtp2());
1414 EXPECT_TRUE(CheckRtp1());
1415 EXPECT_TRUE(CheckNoRtp2());
1416
1417 // Regain writability
1418 GetTransport1()->SetWritable(true);
1419 EXPECT_TRUE(media_channel1_->sending());
1420 EXPECT_TRUE(SendRtp1());
1421 EXPECT_TRUE(SendRtp2());
1422 EXPECT_TRUE(CheckRtp1());
1423 EXPECT_TRUE(CheckRtp2());
1424 EXPECT_TRUE(CheckNoRtp1());
1425 EXPECT_TRUE(CheckNoRtp2());
1426
1427 // Lose writability completely
1428 GetTransport1()->SetDestination(NULL);
1429 EXPECT_TRUE(media_channel1_->sending());
1430
wu@webrtc.org97077a32013-10-25 21:18:33 +00001431 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 EXPECT_FALSE(SendRtp1());
1433 EXPECT_TRUE(SendRtp2());
1434 EXPECT_TRUE(CheckRtp1());
1435 EXPECT_TRUE(CheckNoRtp2());
1436
1437 // Gain writability back
1438 GetTransport1()->SetDestination(GetTransport2());
1439 EXPECT_TRUE(media_channel1_->sending());
1440 EXPECT_TRUE(SendRtp1());
1441 EXPECT_TRUE(SendRtp2());
1442 EXPECT_TRUE(CheckRtp1());
1443 EXPECT_TRUE(CheckRtp2());
1444 EXPECT_TRUE(CheckNoRtp1());
1445 EXPECT_TRUE(CheckNoRtp2());
1446 }
1447
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001448 void SendBundleToBundle(
1449 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1450 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001452 // Only pl_type1 was added to the bundle filter for both |channel1_|
1453 // and |channel2_|.
1454 int pl_type1 = pl_types[0];
1455 int pl_type2 = pl_types[1];
1456 int flags = SSRC_MUX | RTCP;
1457 if (secure) flags |= SECURE;
Peter Boström0c4e06b2015-10-07 12:23:21 +02001458 uint32_t expected_channels = 2U;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001459 if (rtcp_mux) {
1460 flags |= RTCP_MUX;
1461 expected_channels = 1U;
1462 }
1463 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001465 ASSERT_TRUE(GetTransport1());
1466 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001468 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001470 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1471 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1472 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1473 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1474 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1475 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1476 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1477 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1478 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1479 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1480 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1481 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1482
1483 // Both channels can receive pl_type1 only.
1484 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1485 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1486 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1487 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1488 EXPECT_TRUE(CheckNoRtp1());
1489 EXPECT_TRUE(CheckNoRtp2());
1490
1491 // RTCP test
1492 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1493 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1494 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1495 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1496
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1498 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1500 EXPECT_TRUE(CheckNoRtcp1());
1501 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1502 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001504 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1505 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1508 }
1509
1510 // Test that the media monitor can be run and gives timely callbacks.
1511 void TestMediaMonitor() {
1512 static const int kTimeout = 500;
1513 CreateChannels(0, 0);
1514 EXPECT_TRUE(SendInitiate());
1515 EXPECT_TRUE(SendAccept());
1516 channel1_->StartMediaMonitor(100);
1517 channel2_->StartMediaMonitor(100);
1518 // Ensure we get callbacks and stop.
1519 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1520 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1521 channel1_->StopMediaMonitor();
1522 channel2_->StopMediaMonitor();
1523 // Ensure a restart of a stopped monitor works.
1524 channel1_->StartMediaMonitor(100);
1525 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1526 channel1_->StopMediaMonitor();
1527 // Ensure stopping a stopped monitor is OK.
1528 channel1_->StopMediaMonitor();
1529 }
1530
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 void TestSetContentFailure() {
1532 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533
Peter Thatchera6d24442015-07-09 21:26:36 -07001534 auto sdesc = cricket::SessionDescription();
1535 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1536 new cricket::AudioContentDescription());
1537 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1538 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539
Peter Thatchera6d24442015-07-09 21:26:36 -07001540 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001542 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1543 &sdesc, cricket::CA_OFFER, &err));
1544 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1545 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001548 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1549 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001551 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1552 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 }
1554
1555 void TestSendTwoOffers() {
1556 CreateChannels(0, 0);
1557
Peter Thatchera6d24442015-07-09 21:26:36 -07001558 std::string err;
1559 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1560 CreateSessionDescriptionWithStream(1));
1561 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1562 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1564
Peter Thatchera6d24442015-07-09 21:26:36 -07001565 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1566 CreateSessionDescriptionWithStream(2));
1567 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1568 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1570 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1571 }
1572
1573 void TestReceiveTwoOffers() {
1574 CreateChannels(0, 0);
1575
Peter Thatchera6d24442015-07-09 21:26:36 -07001576 std::string err;
1577 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1578 CreateSessionDescriptionWithStream(1));
1579 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1580 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1582
Peter Thatchera6d24442015-07-09 21:26:36 -07001583 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1584 CreateSessionDescriptionWithStream(2));
1585 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1586 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1588 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1589 }
1590
1591 void TestSendPrAnswer() {
1592 CreateChannels(0, 0);
1593
Peter Thatchera6d24442015-07-09 21:26:36 -07001594 std::string err;
1595 // Receive offer
1596 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1597 CreateSessionDescriptionWithStream(1));
1598 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1599 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1601
Peter Thatchera6d24442015-07-09 21:26:36 -07001602 // Send PR answer
1603 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1604 CreateSessionDescriptionWithStream(2));
1605 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1606 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1608 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1609
Peter Thatchera6d24442015-07-09 21:26:36 -07001610 // Send answer
1611 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1612 CreateSessionDescriptionWithStream(3));
1613 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1614 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1616 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1617 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1618 }
1619
1620 void TestReceivePrAnswer() {
1621 CreateChannels(0, 0);
1622
Peter Thatchera6d24442015-07-09 21:26:36 -07001623 std::string err;
1624 // Send offer
1625 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1626 CreateSessionDescriptionWithStream(1));
1627 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1628 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1630
Peter Thatchera6d24442015-07-09 21:26:36 -07001631 // Receive PR answer
1632 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1633 CreateSessionDescriptionWithStream(2));
1634 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1635 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1637 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1638
Peter Thatchera6d24442015-07-09 21:26:36 -07001639 // Receive answer
1640 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1641 CreateSessionDescriptionWithStream(3));
1642 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1643 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1645 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1646 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1647 }
1648
1649 void TestFlushRtcp() {
1650 bool send_rtcp1;
1651
1652 CreateChannels(RTCP, RTCP);
1653 EXPECT_TRUE(SendInitiate());
1654 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001655 ASSERT_TRUE(GetTransport1());
1656 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 EXPECT_EQ(2U, GetTransport1()->channels().size());
1658 EXPECT_EQ(2U, GetTransport2()->channels().size());
1659
1660 // Send RTCP1 from a different thread.
1661 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1662 EXPECT_TRUE(send_rtcp1);
1663 // The sending message is only posted. channel2_ should be empty.
1664 EXPECT_TRUE(CheckNoRtcp2());
1665
1666 // When channel1_ is deleted, the RTCP packet should be sent out to
1667 // channel2_.
1668 channel1_.reset();
1669 EXPECT_TRUE(CheckRtcp2());
1670 }
1671
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001672 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001673 struct SrtpErrorHandler : public sigslot::has_slots<> {
1674 SrtpErrorHandler() :
1675 mode_(cricket::SrtpFilter::UNPROTECT),
1676 error_(cricket::SrtpFilter::ERROR_NONE) {}
1677 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1678 cricket::SrtpFilter::Error error) {
1679 mode_ = mode;
1680 error_ = error;
1681 }
1682 cricket::SrtpFilter::Mode mode_;
1683 cricket::SrtpFilter::Error error_;
1684 } error_handler;
1685
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001686 // For Audio, only pl_type 0 is added to the bundle filter.
1687 // For Video, only pl_type 97 is added to the bundle filter.
1688 // So we need to pass in pl_type so that the packet can pass through
1689 // the bundle filter before it can be processed by the srtp filter.
1690 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001691 unsigned const char kBadPacket[] = {0x84,
1692 static_cast<unsigned char>(pl_type),
1693 0x00,
1694 0x01,
1695 0x00,
1696 0x00,
1697 0x00,
1698 0x00,
1699 0x00,
1700 0x00,
1701 0x00,
1702 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1704 EXPECT_FALSE(channel1_->secure());
1705 EXPECT_FALSE(channel2_->secure());
1706 EXPECT_TRUE(SendInitiate());
1707 EXPECT_TRUE(SendAccept());
1708 EXPECT_TRUE(channel1_->secure());
1709 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001710 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001711 channel2_->srtp_filter()->SignalSrtpError.connect(
1712 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713
1714 // Testing failures in sending packets.
stefanc1aeaf02015-10-15 07:26:07 -07001715 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1716 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001718 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1719 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1720 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001721 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1722 // The next 250 ms failures will not trigger an error.
stefanc1aeaf02015-10-15 07:26:07 -07001723 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1724 rtc::PacketOptions()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001725 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001726 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001727 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001728 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1729 // Wait for a little more - the error will be triggered again.
1730 rtc::Thread::Current()->ProcessMessages(200);
stefanc1aeaf02015-10-15 07:26:07 -07001731 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
1732 rtc::PacketOptions()));
solenberg5b14b422015-10-01 04:10:31 -07001733 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1734 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735
1736 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001737 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001738 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001739
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 cricket::TransportChannel* transport_channel =
1741 channel2_->transport_channel();
1742 transport_channel->SignalReadPacket(
1743 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001744 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001745 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1746 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001747 }
1748
1749 void TestOnReadyToSend() {
1750 CreateChannels(RTCP, RTCP);
1751 TransportChannel* rtp = channel1_->transport_channel();
1752 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1753 EXPECT_FALSE(media_channel1_->ready_to_send());
1754 rtp->SignalReadyToSend(rtp);
1755 EXPECT_FALSE(media_channel1_->ready_to_send());
1756 rtcp->SignalReadyToSend(rtcp);
1757 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1758 // channel are ready to send.
1759 EXPECT_TRUE(media_channel1_->ready_to_send());
1760
1761 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001762 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001764 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 EXPECT_TRUE(media_channel1_->ready_to_send());
1766
1767 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001768 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001769 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001770 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 EXPECT_TRUE(media_channel1_->ready_to_send());
1772 }
1773
1774 void TestOnReadyToSendWithRtcpMux() {
1775 CreateChannels(RTCP, RTCP);
1776 typename T::Content content;
1777 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1778 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1779 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001780 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1781 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1783 TransportChannel* rtp = channel1_->transport_channel();
1784 EXPECT_FALSE(media_channel1_->ready_to_send());
1785 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1786 // should trigger the MediaChannel's OnReadyToSend.
1787 rtp->SignalReadyToSend(rtp);
1788 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001789 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 EXPECT_FALSE(media_channel1_->ready_to_send());
1791 }
1792
1793 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001794 // TODO(pbos): Remove playout from all media channels and let renderers mute
1795 // themselves.
1796 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001797 cricket::FakeTransportController transport_controller1_;
1798 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 cricket::FakeMediaEngine media_engine_;
1800 // The media channels are owned by the voice channel objects below.
1801 typename T::MediaChannel* media_channel1_;
1802 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001803 rtc::scoped_ptr<typename T::Channel> channel1_;
1804 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 typename T::Content local_media_content1_;
1806 typename T::Content local_media_content2_;
1807 typename T::Content remote_media_content1_;
1808 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 // The RTP and RTCP packets to send in the tests.
1810 std::string rtp_packet_;
1811 std::string rtcp_packet_;
1812 int media_info_callbacks1_;
1813 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814};
1815
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816template<>
1817void ChannelTest<VoiceTraits>::CreateContent(
1818 int flags,
1819 const cricket::AudioCodec& audio_codec,
1820 const cricket::VideoCodec& video_codec,
1821 cricket::AudioContentDescription* audio) {
1822 audio->AddCodec(audio_codec);
1823 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1824 if (flags & SECURE) {
1825 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001826 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1827 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 }
1829}
1830
1831template<>
1832void ChannelTest<VoiceTraits>::CopyContent(
1833 const cricket::AudioContentDescription& source,
1834 cricket::AudioContentDescription* audio) {
1835 *audio = source;
1836}
1837
1838template<>
1839bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1840 const cricket::AudioCodec& c2) {
1841 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1842 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1843}
1844
Peter Boström0c4e06b2015-10-07 12:23:21 +02001845template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001847 uint32_t ssrc,
1848 int flags,
1849 cricket::AudioContentDescription* audio) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 audio->AddLegacyStream(ssrc);
1851}
1852
1853class VoiceChannelTest
1854 : public ChannelTest<VoiceTraits> {
1855 public:
solenberg1dd98f32015-09-10 01:57:14 -07001856 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001857 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001858 : Base(true,
1859 kPcmuFrame,
1860 sizeof(kPcmuFrame),
1861 kRtcpReport,
1862 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863};
1864
1865// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001866template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001868 rtc::Thread* thread,
1869 cricket::MediaEngineInterface* engine,
1870 cricket::FakeVideoMediaChannel* ch,
1871 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872 bool rtcp) {
1873 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001874 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875 if (!channel->Init()) {
1876 delete channel;
1877 channel = NULL;
1878 }
1879 return channel;
1880}
1881
1882// override to add 0 parameter
1883template<>
1884bool ChannelTest<VideoTraits>::AddStream1(int id) {
1885 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1886}
1887
1888template<>
1889void ChannelTest<VideoTraits>::CreateContent(
1890 int flags,
1891 const cricket::AudioCodec& audio_codec,
1892 const cricket::VideoCodec& video_codec,
1893 cricket::VideoContentDescription* video) {
1894 video->AddCodec(video_codec);
1895 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1896 if (flags & SECURE) {
1897 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001898 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1899 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900 }
1901}
1902
1903template<>
1904void ChannelTest<VideoTraits>::CopyContent(
1905 const cricket::VideoContentDescription& source,
1906 cricket::VideoContentDescription* video) {
1907 *video = source;
1908}
1909
1910template<>
1911bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1912 const cricket::VideoCodec& c2) {
1913 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1914 c1.framerate == c2.framerate;
1915}
1916
Peter Boström0c4e06b2015-10-07 12:23:21 +02001917template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02001919 uint32_t ssrc,
1920 int flags,
1921 cricket::VideoContentDescription* video) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 video->AddLegacyStream(ssrc);
1923}
1924
1925class VideoChannelTest
1926 : public ChannelTest<VideoTraits> {
1927 public:
solenberg1dd98f32015-09-10 01:57:14 -07001928 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001929 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001930 : Base(false,
1931 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001932 sizeof(kH264Packet),
1933 kRtcpReport,
1934 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935};
1936
1937
1938// VoiceChannelTest
1939
1940TEST_F(VoiceChannelTest, TestInit) {
1941 Base::TestInit();
1942 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1943 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1944}
1945
1946TEST_F(VoiceChannelTest, TestSetContents) {
1947 Base::TestSetContents();
1948}
1949
1950TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1951 Base::TestSetContentsNullOffer();
1952}
1953
1954TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1955 Base::TestSetContentsRtcpMux();
1956}
1957
1958TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1959 Base::TestSetContentsRtcpMux();
1960}
1961
1962TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1963 Base::TestSetRemoteContentUpdate();
1964}
1965
1966TEST_F(VoiceChannelTest, TestStreams) {
1967 Base::TestStreams();
1968}
1969
1970TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1971 Base::TestUpdateStreamsInLocalContent();
1972}
1973
1974TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1975 Base::TestUpdateStreamsInRemoteContent();
1976}
1977
1978TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1979 Base::TestChangeStreamParamsInContent();
1980}
1981
1982TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1983 Base::TestPlayoutAndSendingStates();
1984}
1985
1986TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001987 CreateChannels(0, 0);
1988 // Test that we can Mute the default channel even though the sending SSRC
1989 // is unknown.
1990 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07001991 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001992 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1993 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001994 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1995
1996 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07001997 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001998
1999 SendInitiate();
2000 // After the local session description has been set, we can mute a stream
2001 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002002 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002003 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2004 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002005 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006}
2007
2008TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2009 Base::TestMediaContentDirection();
2010}
2011
2012TEST_F(VoiceChannelTest, TestCallSetup) {
2013 Base::TestCallSetup();
2014}
2015
2016TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2017 Base::TestCallTeardownRtcpMux();
2018}
2019
2020TEST_F(VoiceChannelTest, SendRtpToRtp) {
2021 Base::SendRtpToRtp();
2022}
2023
2024TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2025 Base::SendNoRtcpToNoRtcp();
2026}
2027
2028TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2029 Base::SendNoRtcpToRtcp();
2030}
2031
2032TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2033 Base::SendRtcpToNoRtcp();
2034}
2035
2036TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2037 Base::SendRtcpToRtcp();
2038}
2039
2040TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2041 Base::SendRtcpMuxToRtcp();
2042}
2043
2044TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2045 Base::SendRtcpMuxToRtcpMux();
2046}
2047
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002048TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2049 Base::SendRequireRtcpMuxToRtcpMux();
2050}
2051
2052TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2053 Base::SendRtcpMuxToRequireRtcpMux();
2054}
2055
2056TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2057 Base::SendRequireRtcpMuxToRequireRtcpMux();
2058}
2059
2060TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2061 Base::SendRequireRtcpMuxToNoRtcpMux();
2062}
2063
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2065 Base::SendEarlyRtcpMuxToRtcp();
2066}
2067
2068TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2069 Base::SendEarlyRtcpMuxToRtcpMux();
2070}
2071
2072TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2073 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2074}
2075
2076TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2077 Base::SendSrtpToSrtp();
2078}
2079
2080TEST_F(VoiceChannelTest, SendSrtcpMux) {
2081 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2082}
2083
2084TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2085 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2086 Base::SendSrtpToSrtp(DTLS, 0);
2087}
2088
2089TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2090 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2091 Base::SendSrtpToSrtp(DTLS, DTLS);
2092}
2093
2094TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2095 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2096 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2097}
2098
2099TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2100 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2101}
2102
2103TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2104 Base::SendRtpToRtpOnThread();
2105}
2106
2107TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2108 Base::SendSrtpToSrtpOnThread();
2109}
2110
2111TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2112 Base::SendWithWritabilityLoss();
2113}
2114
2115TEST_F(VoiceChannelTest, TestMediaMonitor) {
2116 Base::TestMediaMonitor();
2117}
2118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119// Test that PressDTMF properly forwards to the media channel.
2120TEST_F(VoiceChannelTest, TestDtmf) {
2121 CreateChannels(0, 0);
2122 EXPECT_TRUE(SendInitiate());
2123 EXPECT_TRUE(SendAccept());
2124 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2125
2126 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2127 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2128
2129 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2130 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2131 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2132 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2133 0, 8, 160, cricket::DF_SEND));
2134}
2135
2136// Test that InsertDtmf properly forwards to the media channel.
2137TEST_F(VoiceChannelTest, TestInsertDtmf) {
2138 CreateChannels(0, 0);
2139 EXPECT_TRUE(SendInitiate());
2140 EXPECT_TRUE(SendAccept());
2141 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2142
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2144 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2145 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2146 cricket::DF_PLAY | cricket::DF_SEND));
2147
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002148 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002151 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002153 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2155}
2156
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157TEST_F(VoiceChannelTest, TestSetContentFailure) {
2158 Base::TestSetContentFailure();
2159}
2160
2161TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2162 Base::TestSendTwoOffers();
2163}
2164
2165TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2166 Base::TestReceiveTwoOffers();
2167}
2168
2169TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2170 Base::TestSendPrAnswer();
2171}
2172
2173TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2174 Base::TestReceivePrAnswer();
2175}
2176
2177TEST_F(VoiceChannelTest, TestFlushRtcp) {
2178 Base::TestFlushRtcp();
2179}
2180
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002182 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183}
2184
2185TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2186 Base::TestOnReadyToSend();
2187}
2188
2189TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2190 Base::TestOnReadyToSendWithRtcpMux();
2191}
2192
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193// Test that we can scale the output volume properly for 1:1 calls.
2194TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2195 CreateChannels(RTCP, RTCP);
2196 EXPECT_TRUE(SendInitiate());
2197 EXPECT_TRUE(SendAccept());
solenberg4bac9c52015-10-09 02:32:53 -07002198 double volume;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199
solenberg4bac9c52015-10-09 02:32:53 -07002200 // Default is (1.0).
2201 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2202 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002204 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205
solenberg4bac9c52015-10-09 02:32:53 -07002206 // Set scale to (1.5).
2207 EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
2208 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2209 EXPECT_DOUBLE_EQ(1.5, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210
solenberg4bac9c52015-10-09 02:32:53 -07002211 // Set scale to (0).
2212 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2213 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2214 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215}
2216
2217// Test that we can scale the output volume properly for multiway calls.
2218TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2219 CreateChannels(RTCP, RTCP);
2220 EXPECT_TRUE(SendInitiate());
2221 EXPECT_TRUE(SendAccept());
2222 EXPECT_TRUE(AddStream1(1));
2223 EXPECT_TRUE(AddStream1(2));
2224
solenberg4bac9c52015-10-09 02:32:53 -07002225 double volume;
2226 // Default is (1.0).
2227 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2228 EXPECT_DOUBLE_EQ(1.0, volume);
2229 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2230 EXPECT_DOUBLE_EQ(1.0, volume);
2231 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2232 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 // invalid ssrc.
solenberg4bac9c52015-10-09 02:32:53 -07002234 EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235
solenberg4bac9c52015-10-09 02:32:53 -07002236 // Set scale to (1.5) for ssrc = 1.
2237 EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
2238 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2239 EXPECT_DOUBLE_EQ(1.5, volume);
2240 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2241 EXPECT_DOUBLE_EQ(1.0, volume);
2242 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2243 EXPECT_DOUBLE_EQ(1.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244
solenberg4bac9c52015-10-09 02:32:53 -07002245 // Set scale to (0) for all ssrcs.
2246 EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
2247 EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
2248 EXPECT_DOUBLE_EQ(0.0, volume);
2249 EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
2250 EXPECT_DOUBLE_EQ(0.0, volume);
2251 EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
2252 EXPECT_DOUBLE_EQ(0.0, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253}
2254
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002255TEST_F(VoiceChannelTest, SendBundleToBundle) {
2256 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257}
2258
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002259TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2260 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2261}
2262
2263TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2264 Base::SendBundleToBundle(
2265 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2266}
2267
2268TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2269 Base::SendBundleToBundle(
2270 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271}
2272
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273// VideoChannelTest
2274TEST_F(VideoChannelTest, TestInit) {
2275 Base::TestInit();
2276}
2277
2278TEST_F(VideoChannelTest, TestSetContents) {
2279 Base::TestSetContents();
2280}
2281
2282TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2283 Base::TestSetContentsNullOffer();
2284}
2285
2286TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2287 Base::TestSetContentsRtcpMux();
2288}
2289
2290TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2291 Base::TestSetContentsRtcpMux();
2292}
2293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2295 Base::TestSetRemoteContentUpdate();
2296}
2297
2298TEST_F(VideoChannelTest, TestStreams) {
2299 Base::TestStreams();
2300}
2301
2302TEST_F(VideoChannelTest, TestScreencastEvents) {
2303 const int kTimeoutMs = 500;
2304 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 cricket::ScreencastEventCatcher catcher;
2306 channel1_->SignalScreencastWindowEvent.connect(
2307 &catcher,
2308 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002309
2310 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2311 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2312 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2313 ScreencastId(WindowId(0)));
2314 ASSERT_TRUE(screen_capturer != NULL);
2315
2316 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2317 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002319
2320 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002321 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002322
2323 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002324 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002325
2326 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002327 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002329 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002330}
2331
2332TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2333 Base::TestUpdateStreamsInLocalContent();
2334}
2335
2336TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2337 Base::TestUpdateStreamsInRemoteContent();
2338}
2339
2340TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2341 Base::TestChangeStreamParamsInContent();
2342}
2343
2344TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2345 Base::TestPlayoutAndSendingStates();
2346}
2347
2348TEST_F(VideoChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07002349 CreateChannels(0, 0);
2350 // Test that we can Mute the default channel even though the sending SSRC
2351 // is unknown.
2352 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07002353 EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002354 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2355 EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002356 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2357 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07002358 EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002359 SendInitiate();
2360 // After the local session description has been set, we can mute a stream
2361 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07002362 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07002363 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
2364 EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07002365 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366}
2367
2368TEST_F(VideoChannelTest, TestMediaContentDirection) {
2369 Base::TestMediaContentDirection();
2370}
2371
2372TEST_F(VideoChannelTest, TestCallSetup) {
2373 Base::TestCallSetup();
2374}
2375
2376TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2377 Base::TestCallTeardownRtcpMux();
2378}
2379
2380TEST_F(VideoChannelTest, SendRtpToRtp) {
2381 Base::SendRtpToRtp();
2382}
2383
2384TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2385 Base::SendNoRtcpToNoRtcp();
2386}
2387
2388TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2389 Base::SendNoRtcpToRtcp();
2390}
2391
2392TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2393 Base::SendRtcpToNoRtcp();
2394}
2395
2396TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2397 Base::SendRtcpToRtcp();
2398}
2399
2400TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2401 Base::SendRtcpMuxToRtcp();
2402}
2403
2404TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2405 Base::SendRtcpMuxToRtcpMux();
2406}
2407
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002408TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2409 Base::SendRequireRtcpMuxToRtcpMux();
2410}
2411
2412TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2413 Base::SendRtcpMuxToRequireRtcpMux();
2414}
2415
2416TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2417 Base::SendRequireRtcpMuxToRequireRtcpMux();
2418}
2419
2420TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2421 Base::SendRequireRtcpMuxToNoRtcpMux();
2422}
2423
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2425 Base::SendEarlyRtcpMuxToRtcp();
2426}
2427
2428TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2429 Base::SendEarlyRtcpMuxToRtcpMux();
2430}
2431
2432TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2433 Base::SendSrtpToSrtp();
2434}
2435
2436TEST_F(VideoChannelTest, SendSrtpToRtp) {
2437 Base::SendSrtpToSrtp();
2438}
2439
2440TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2441 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2442 Base::SendSrtpToSrtp(DTLS, 0);
2443}
2444
2445TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2446 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2447 Base::SendSrtpToSrtp(DTLS, DTLS);
2448}
2449
2450TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2451 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2452 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2453}
2454
2455TEST_F(VideoChannelTest, SendSrtcpMux) {
2456 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2457}
2458
2459TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2460 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2461}
2462
2463TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2464 Base::SendRtpToRtpOnThread();
2465}
2466
2467TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2468 Base::SendSrtpToSrtpOnThread();
2469}
2470
2471TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2472 Base::SendWithWritabilityLoss();
2473}
2474
2475TEST_F(VideoChannelTest, TestMediaMonitor) {
2476 Base::TestMediaMonitor();
2477}
2478
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479TEST_F(VideoChannelTest, TestSetContentFailure) {
2480 Base::TestSetContentFailure();
2481}
2482
2483TEST_F(VideoChannelTest, TestSendTwoOffers) {
2484 Base::TestSendTwoOffers();
2485}
2486
2487TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2488 Base::TestReceiveTwoOffers();
2489}
2490
2491TEST_F(VideoChannelTest, TestSendPrAnswer) {
2492 Base::TestSendPrAnswer();
2493}
2494
2495TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2496 Base::TestReceivePrAnswer();
2497}
2498
2499TEST_F(VideoChannelTest, TestFlushRtcp) {
2500 Base::TestFlushRtcp();
2501}
2502
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002503TEST_F(VideoChannelTest, SendBundleToBundle) {
2504 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505}
2506
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002507TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2508 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2509}
2510
2511TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2512 Base::SendBundleToBundle(
2513 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2514}
2515
2516TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2517 Base::SendBundleToBundle(
2518 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519}
2520
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002522 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523}
2524
2525TEST_F(VideoChannelTest, TestOnReadyToSend) {
2526 Base::TestOnReadyToSend();
2527}
2528
2529TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2530 Base::TestOnReadyToSendWithRtcpMux();
2531}
2532
2533TEST_F(VideoChannelTest, TestApplyViewRequest) {
2534 CreateChannels(0, 0);
2535 cricket::StreamParams stream2;
2536 stream2.id = "stream2";
2537 stream2.ssrcs.push_back(2222);
2538 local_media_content1_.AddStream(stream2);
2539
2540 EXPECT_TRUE(SendInitiate());
2541 EXPECT_TRUE(SendAccept());
2542
2543 cricket::VideoFormat send_format;
2544 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2545 EXPECT_EQ(640, send_format.width);
2546 EXPECT_EQ(400, send_format.height);
2547 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2548
2549 cricket::ViewRequest request;
2550 // stream1: 320x200x15; stream2: 0x0x0
2551 request.static_video_views.push_back(cricket::StaticVideoView(
2552 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2553 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2554 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2555 EXPECT_EQ(320, send_format.width);
2556 EXPECT_EQ(200, send_format.height);
2557 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2558 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2559 EXPECT_EQ(0, send_format.width);
2560 EXPECT_EQ(0, send_format.height);
2561
2562 // stream1: 160x100x8; stream2: 0x0x0
2563 request.static_video_views.clear();
2564 request.static_video_views.push_back(cricket::StaticVideoView(
2565 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2566 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2567 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2568 EXPECT_EQ(160, send_format.width);
2569 EXPECT_EQ(100, send_format.height);
2570 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2571
2572 // stream1: 0x0x0; stream2: 640x400x30
2573 request.static_video_views.clear();
2574 request.static_video_views.push_back(cricket::StaticVideoView(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002575 cricket::StreamSelector(std::string(), stream2.id), 640, 400, 30));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2577 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2578 EXPECT_EQ(0, send_format.width);
2579 EXPECT_EQ(0, send_format.height);
2580 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2581 EXPECT_EQ(640, send_format.width);
2582 EXPECT_EQ(400, send_format.height);
2583 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2584
2585 // stream1: 0x0x0; stream2: 0x0x0
2586 request.static_video_views.clear();
2587 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2588 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2589 EXPECT_EQ(0, send_format.width);
2590 EXPECT_EQ(0, send_format.height);
2591}
2592
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593
2594// DataChannelTest
2595
2596class DataChannelTest
2597 : public ChannelTest<DataTraits> {
2598 public:
2599 typedef ChannelTest<DataTraits>
2600 Base;
Peter Boström34fbfff2015-09-24 19:20:30 +02002601 DataChannelTest()
2602 : Base(true,
2603 kDataPacket,
2604 sizeof(kDataPacket),
2605 kRtcpReport,
2606 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607};
2608
2609// Override to avoid engine channel parameter.
deadbeefcbecd352015-09-23 11:50:27 -07002610template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002612 rtc::Thread* thread,
2613 cricket::MediaEngineInterface* engine,
2614 cricket::FakeDataMediaChannel* ch,
2615 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 bool rtcp) {
2617 cricket::DataChannel* channel = new cricket::DataChannel(
deadbeefcbecd352015-09-23 11:50:27 -07002618 thread, ch, transport_controller, cricket::CN_DATA, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619 if (!channel->Init()) {
2620 delete channel;
2621 channel = NULL;
2622 }
2623 return channel;
2624}
2625
2626template<>
2627void ChannelTest<DataTraits>::CreateContent(
2628 int flags,
2629 const cricket::AudioCodec& audio_codec,
2630 const cricket::VideoCodec& video_codec,
2631 cricket::DataContentDescription* data) {
2632 data->AddCodec(kGoogleDataCodec);
2633 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2634 if (flags & SECURE) {
2635 data->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07002636 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
2637 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 }
2639}
2640
2641template<>
2642void ChannelTest<DataTraits>::CopyContent(
2643 const cricket::DataContentDescription& source,
2644 cricket::DataContentDescription* data) {
2645 *data = source;
2646}
2647
2648template<>
2649bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2650 const cricket::DataCodec& c2) {
2651 return c1.name == c2.name;
2652}
2653
Peter Boström0c4e06b2015-10-07 12:23:21 +02002654template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655void ChannelTest<DataTraits>::AddLegacyStreamInContent(
Peter Boström0c4e06b2015-10-07 12:23:21 +02002656 uint32_t ssrc,
2657 int flags,
2658 cricket::DataContentDescription* data) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002659 data->AddLegacyStream(ssrc);
2660}
2661
2662TEST_F(DataChannelTest, TestInit) {
2663 Base::TestInit();
2664 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2665}
2666
2667TEST_F(DataChannelTest, TestSetContents) {
2668 Base::TestSetContents();
2669}
2670
2671TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2672 Base::TestSetContentsNullOffer();
2673}
2674
2675TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2676 Base::TestSetContentsRtcpMux();
2677}
2678
2679TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2680 Base::TestSetRemoteContentUpdate();
2681}
2682
2683TEST_F(DataChannelTest, TestStreams) {
2684 Base::TestStreams();
2685}
2686
2687TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2688 Base::TestUpdateStreamsInLocalContent();
2689}
2690
2691TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2692 Base::TestUpdateStreamsInRemoteContent();
2693}
2694
2695TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2696 Base::TestChangeStreamParamsInContent();
2697}
2698
2699TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2700 Base::TestPlayoutAndSendingStates();
2701}
2702
2703TEST_F(DataChannelTest, TestMediaContentDirection) {
2704 Base::TestMediaContentDirection();
2705}
2706
2707TEST_F(DataChannelTest, TestCallSetup) {
2708 Base::TestCallSetup();
2709}
2710
2711TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2712 Base::TestCallTeardownRtcpMux();
2713}
2714
2715TEST_F(DataChannelTest, TestOnReadyToSend) {
2716 Base::TestOnReadyToSend();
2717}
2718
2719TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2720 Base::TestOnReadyToSendWithRtcpMux();
2721}
2722
2723TEST_F(DataChannelTest, SendRtpToRtp) {
2724 Base::SendRtpToRtp();
2725}
2726
2727TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2728 Base::SendNoRtcpToNoRtcp();
2729}
2730
2731TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2732 Base::SendNoRtcpToRtcp();
2733}
2734
2735TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2736 Base::SendRtcpToNoRtcp();
2737}
2738
2739TEST_F(DataChannelTest, SendRtcpToRtcp) {
2740 Base::SendRtcpToRtcp();
2741}
2742
2743TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2744 Base::SendRtcpMuxToRtcp();
2745}
2746
2747TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2748 Base::SendRtcpMuxToRtcpMux();
2749}
2750
2751TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2752 Base::SendEarlyRtcpMuxToRtcp();
2753}
2754
2755TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2756 Base::SendEarlyRtcpMuxToRtcpMux();
2757}
2758
2759TEST_F(DataChannelTest, SendSrtpToSrtp) {
2760 Base::SendSrtpToSrtp();
2761}
2762
2763TEST_F(DataChannelTest, SendSrtpToRtp) {
2764 Base::SendSrtpToSrtp();
2765}
2766
2767TEST_F(DataChannelTest, SendSrtcpMux) {
2768 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2769}
2770
2771TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2772 Base::SendRtpToRtpOnThread();
2773}
2774
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2776 Base::SendSrtpToSrtpOnThread();
2777}
2778
2779TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2780 Base::SendWithWritabilityLoss();
2781}
2782
2783TEST_F(DataChannelTest, TestMediaMonitor) {
2784 Base::TestMediaMonitor();
2785}
2786
2787TEST_F(DataChannelTest, TestSendData) {
2788 CreateChannels(0, 0);
2789 EXPECT_TRUE(SendInitiate());
2790 EXPECT_TRUE(SendAccept());
2791
2792 cricket::SendDataParams params;
2793 params.ssrc = 42;
2794 unsigned char data[] = {
2795 'f', 'o', 'o'
2796 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002797 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002798 cricket::SendDataResult result;
2799 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2800 EXPECT_EQ(params.ssrc,
2801 media_channel1_->last_sent_data_params().ssrc);
2802 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2803}
2804
2805// TODO(pthatcher): TestSetReceiver?