blob: d6f25922ce9a88ecbad13560cdbe4365177b1ece [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
2 * libjingle
3 * Copyright 2009 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028#include "talk/media/base/fakemediaengine.h"
29#include "talk/media/base/fakertp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000030#include "talk/media/base/fakescreencapturerfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/media/base/fakevideocapturer.h"
32#include "talk/media/base/mediachannel.h"
33#include "talk/media/base/rtpdump.h"
34#include "talk/media/base/screencastid.h"
35#include "talk/media/base/testutils.h"
deadbeefcbecd352015-09-23 11:50:27 -070036#include "webrtc/p2p/base/faketransportcontroller.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/session/media/channel.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000038#include "webrtc/base/fileutils.h"
39#include "webrtc/base/gunit.h"
40#include "webrtc/base/helpers.h"
41#include "webrtc/base/logging.h"
42#include "webrtc/base/pathutils.h"
43#include "webrtc/base/signalthread.h"
44#include "webrtc/base/ssladapter.h"
45#include "webrtc/base/sslidentity.h"
46#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 LOG(LS_INFO) << "Feature disabled... skipping"; \
51 return; \
52 }
53
54using cricket::CA_OFFER;
55using cricket::CA_PRANSWER;
56using cricket::CA_ANSWER;
57using cricket::CA_UPDATE;
58using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::ScreencastId;
60using cricket::StreamParams;
61using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
65static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
67static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
68static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
69static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
70static const uint32 kSsrc1 = 0x1111;
71static const uint32 kSsrc2 = 0x2222;
72static const uint32 kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000073static const int kAudioPts[] = {0, 8};
74static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
deadbeefcbecd352015-09-23 11:50:27 -070076template <class ChannelT,
77 class MediaChannelT,
78 class ContentT,
79 class CodecT,
80 class MediaInfoT,
81 class OptionsT>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082class Traits {
83 public:
84 typedef ChannelT Channel;
85 typedef MediaChannelT MediaChannel;
86 typedef ContentT Content;
87 typedef CodecT Codec;
88 typedef MediaInfoT MediaInfo;
Fredrik Solenbergb071a192015-09-17 16:42:56 +020089 typedef OptionsT Options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090};
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092// Controls how long we wait for a session to send messages that we
93// expect, in milliseconds. We put it high to avoid flaky tests.
94static const int kEventTimeout = 5000;
95
96class VoiceTraits : public Traits<cricket::VoiceChannel,
97 cricket::FakeVoiceMediaChannel,
98 cricket::AudioContentDescription,
99 cricket::AudioCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200100 cricket::VoiceMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700101 cricket::AudioOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
103class VideoTraits : public Traits<cricket::VideoChannel,
104 cricket::FakeVideoMediaChannel,
105 cricket::VideoContentDescription,
106 cricket::VideoCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200107 cricket::VideoMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700108 cricket::VideoOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000109
110class DataTraits : public Traits<cricket::DataChannel,
111 cricket::FakeDataMediaChannel,
112 cricket::DataContentDescription,
113 cricket::DataCodec,
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200114 cricket::DataMediaInfo,
deadbeefcbecd352015-09-23 11:50:27 -0700115 cricket::DataOptions> {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000117rtc::StreamInterface* Open(const std::string& path) {
118 return rtc::Filesystem::OpenFile(
119 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120}
121
122// Base class for Voice/VideoChannel tests
123template<class T>
124class ChannelTest : public testing::Test, public sigslot::has_slots<> {
125 public:
126 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
127 DTLS = 0x10 };
128
Peter Boström34fbfff2015-09-24 19:20:30 +0200129 ChannelTest(bool verify_playout,
130 const uint8* rtp_data,
deadbeefcbecd352015-09-23 11:50:27 -0700131 int rtp_len,
132 const uint8* rtcp_data,
133 int rtcp_len)
Peter Boström34fbfff2015-09-24 19:20:30 +0200134 : verify_playout_(verify_playout),
135 transport_controller1_(cricket::ICEROLE_CONTROLLING),
deadbeefcbecd352015-09-23 11:50:27 -0700136 transport_controller2_(cricket::ICEROLE_CONTROLLED),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 media_channel1_(NULL),
138 media_channel2_(NULL),
139 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
140 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
141 media_info_callbacks1_(),
solenberg5b14b422015-10-01 04:10:31 -0700142 media_info_callbacks2_() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000143
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 void CreateChannels(int flags1, int flags2) {
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200145 CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
146 new typename T::MediaChannel(NULL, typename T::Options()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 void CreateChannels(
150 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000151 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152 media_channel1_ = ch1;
153 media_channel2_ = ch2;
deadbeefcbecd352015-09-23 11:50:27 -0700154 channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
155 &transport_controller1_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 (flags1 & RTCP) != 0));
deadbeefcbecd352015-09-23 11:50:27 -0700157 channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
158 &transport_controller2_,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159 (flags2 & RTCP) != 0));
160 channel1_->SignalMediaMonitor.connect(
161 this, &ChannelTest<T>::OnMediaMonitor);
162 channel2_->SignalMediaMonitor.connect(
163 this, &ChannelTest<T>::OnMediaMonitor);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000164 if ((flags1 & DTLS) && (flags2 & DTLS)) {
165 flags1 = (flags1 & ~SECURE);
166 flags2 = (flags2 & ~SECURE);
167 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 CreateContent(flags1, kPcmuCodec, kH264Codec,
169 &local_media_content1_);
170 CreateContent(flags2, kPcmuCodec, kH264Codec,
171 &local_media_content2_);
172 CopyContent(local_media_content1_, &remote_media_content1_);
173 CopyContent(local_media_content2_, &remote_media_content2_);
174
175 if (flags1 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200176 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700177 transport_controller1_.SetLocalCertificate(rtc::RTCCertificate::Create(
178 rtc::scoped_ptr<rtc::SSLIdentity>(
179 rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))
180 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 }
182 if (flags2 & DTLS) {
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200183 // Confirmed to work with KT_RSA and KT_ECDSA.
deadbeefcbecd352015-09-23 11:50:27 -0700184 transport_controller2_.SetLocalCertificate(rtc::RTCCertificate::Create(
185 rtc::scoped_ptr<rtc::SSLIdentity>(
186 rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))
187 .Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 }
189
190 // Add stream information (SSRC) to the local content but not to the remote
191 // content. This means that we per default know the SSRC of what we send but
192 // not what we receive.
193 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
194 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
195
196 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
197 if (flags1 & SSRC_MUX) {
198 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
199 }
200 if (flags2 & SSRC_MUX) {
201 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
202 }
203 }
deadbeefcbecd352015-09-23 11:50:27 -0700204 typename T::Channel* CreateChannel(
205 rtc::Thread* thread,
206 cricket::MediaEngineInterface* engine,
207 typename T::MediaChannel* ch,
208 cricket::TransportController* transport_controller,
209 bool rtcp) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 typename T::Channel* channel = new typename T::Channel(
deadbeefcbecd352015-09-23 11:50:27 -0700211 thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 if (!channel->Init()) {
213 delete channel;
214 channel = NULL;
215 }
216 return channel;
217 }
218
219 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000220 bool result = channel1_->SetLocalContent(&local_media_content1_,
221 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 if (result) {
223 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000224 result = channel2_->SetRemoteContent(&remote_media_content1_,
225 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000226 if (result) {
deadbeefcbecd352015-09-23 11:50:27 -0700227 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000228
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000229 result = channel2_->SetLocalContent(&local_media_content2_,
230 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000231 }
232 }
233 return result;
234 }
235
236 bool SendAccept() {
237 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000238 return channel1_->SetRemoteContent(&remote_media_content2_,
239 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 }
241
242 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000243 bool result = channel1_->SetLocalContent(&local_media_content1_,
244 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 if (result) {
246 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000247 result = channel2_->SetRemoteContent(&remote_media_content1_,
248 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249 }
250 return result;
251 }
252
253 bool SendProvisionalAnswer() {
254 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000255 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 if (result) {
257 channel2_->Enable(true);
258 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000259 CA_PRANSWER, NULL);
deadbeefcbecd352015-09-23 11:50:27 -0700260 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 }
262 return result;
263 }
264
265 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000266 bool result = channel2_->SetLocalContent(&local_media_content2_,
267 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000268 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000269 result = channel1_->SetRemoteContent(&remote_media_content2_,
270 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000271 return result;
272 }
273
274 bool SendTerminate() {
275 channel1_.reset();
276 channel2_.reset();
277 return true;
278 }
279
280 bool AddStream1(int id) {
281 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
282 }
283 bool RemoveStream1(int id) {
284 return channel1_->RemoveRecvStream(id);
285 }
286
deadbeefcbecd352015-09-23 11:50:27 -0700287 // Calling "_w" method here is ok since we only use one thread for this test
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288 cricket::FakeTransport* GetTransport1() {
deadbeefcbecd352015-09-23 11:50:27 -0700289 return transport_controller1_.GetTransport_w(channel1_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 }
291 cricket::FakeTransport* GetTransport2() {
deadbeefcbecd352015-09-23 11:50:27 -0700292 return transport_controller2_.GetTransport_w(channel2_->content_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293 }
294
295 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000296 return media_channel1_->SendRtp(rtp_packet_.c_str(),
297 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 }
299 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000300 return media_channel2_->SendRtp(rtp_packet_.c_str(),
301 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302 }
303 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000304 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
305 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 }
307 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000308 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
309 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 }
311 // Methods to send custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000312 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
313 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000314 return media_channel1_->SendRtp(data.c_str(),
315 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000317 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
318 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000319 return media_channel2_->SendRtp(data.c_str(),
320 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 }
322 bool SendCustomRtcp1(uint32 ssrc) {
323 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000324 return media_channel1_->SendRtcp(data.c_str(),
325 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 }
327 bool SendCustomRtcp2(uint32 ssrc) {
328 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000329 return media_channel2_->SendRtcp(data.c_str(),
330 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
332 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000333 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
334 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 }
336 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000337 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
338 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339 }
340 bool CheckRtcp1() {
341 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000342 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343 }
344 bool CheckRtcp2() {
345 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000346 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 }
348 // Methods to check custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000349 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
350 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000351 return media_channel1_->CheckRtp(data.c_str(),
352 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000354 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
355 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000356 return media_channel2_->CheckRtp(data.c_str(),
357 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 }
359 bool CheckCustomRtcp1(uint32 ssrc) {
360 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000361 return media_channel1_->CheckRtcp(data.c_str(),
362 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 }
364 bool CheckCustomRtcp2(uint32 ssrc) {
365 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000366 return media_channel2_->CheckRtcp(data.c_str(),
367 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000369 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 std::string data(rtp_packet_);
371 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000372 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
373 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000374 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000375 rtc::Set8(const_cast<char*>(data.c_str()), 1,
376 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000377 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378 return data;
379 }
380 std::string CreateRtcpData(uint32 ssrc) {
381 std::string data(rtcp_packet_);
382 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000383 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 return data;
385 }
386
387 bool CheckNoRtp1() {
388 return media_channel1_->CheckNoRtp();
389 }
390 bool CheckNoRtp2() {
391 return media_channel2_->CheckNoRtp();
392 }
393 bool CheckNoRtcp1() {
394 return media_channel1_->CheckNoRtcp();
395 }
396 bool CheckNoRtcp2() {
397 return media_channel2_->CheckNoRtcp();
398 }
399
400 void CreateContent(int flags,
401 const cricket::AudioCodec& audio_codec,
402 const cricket::VideoCodec& video_codec,
403 typename T::Content* content) {
404 // overridden in specialized classes
405 }
406 void CopyContent(const typename T::Content& source,
407 typename T::Content* content) {
408 // overridden in specialized classes
409 }
410
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 // Creates a cricket::SessionDescription with one MediaContent and one stream.
412 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
413 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
414 typename T::Content content;
415 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
416 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
417 AddLegacyStreamInContent(ssrc, 0, &content);
418 sdesc->AddContent("DUMMY_CONTENT_NAME",
419 cricket::NS_JINGLE_RTP, content.Copy());
420 return sdesc;
421 }
422
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000423 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 public:
425 typedef bool (ChannelTest<T>::*Method)();
426 CallThread(ChannelTest<T>* obj, Method method, bool* result)
427 : obj_(obj),
428 method_(method),
429 result_(result) {
430 *result = false;
431 }
432 virtual void DoWork() {
433 bool result = (*obj_.*method_)();
434 if (result_) {
435 *result_ = result;
436 }
437 }
438 private:
439 ChannelTest<T>* obj_;
440 Method method_;
441 bool* result_;
442 };
443 void CallOnThread(typename CallThread::Method method, bool* result) {
444 CallThread* thread = new CallThread(this, method, result);
445 thread->Start();
446 thread->Release();
447 }
448
449 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
450 bool* result) {
451 CallThread* thread = new CallThread(this, method, result);
452 thread->Start();
453 thread->Destroy(true);
454 }
455
456 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
457 return false; // overridden in specialized classes
458 }
459
460 void OnMediaMonitor(typename T::Channel* channel,
461 const typename T::MediaInfo& info) {
462 if (channel == channel1_.get()) {
463 media_info_callbacks1_++;
464 } else if (channel == channel2_.get()) {
465 media_info_callbacks2_++;
466 }
467 }
468
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 void AddLegacyStreamInContent(uint32 ssrc, int flags,
470 typename T::Content* content) {
471 // Base implementation.
472 }
473
474 // Tests that can be used by derived classes.
475
476 // Basic sanity check.
477 void TestInit() {
478 CreateChannels(0, 0);
479 EXPECT_FALSE(channel1_->secure());
480 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200481 if (verify_playout_) {
482 EXPECT_FALSE(media_channel1_->playout());
483 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 EXPECT_TRUE(media_channel1_->codecs().empty());
485 EXPECT_TRUE(media_channel1_->recv_streams().empty());
486 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
487 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
488 }
489
490 // Test that SetLocalContent and SetRemoteContent properly configure
491 // the codecs.
492 void TestSetContents() {
493 CreateChannels(0, 0);
494 typename T::Content content;
495 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000496 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000497 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000498 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 ASSERT_EQ(1U, media_channel1_->codecs().size());
500 EXPECT_TRUE(CodecMatches(content.codecs()[0],
501 media_channel1_->codecs()[0]));
502 }
503
504 // Test that SetLocalContent and SetRemoteContent properly deals
505 // with an empty offer.
506 void TestSetContentsNullOffer() {
507 CreateChannels(0, 0);
508 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000509 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 CreateContent(0, kPcmuCodec, kH264Codec, &content);
511 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000512 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 ASSERT_EQ(1U, media_channel1_->codecs().size());
514 EXPECT_TRUE(CodecMatches(content.codecs()[0],
515 media_channel1_->codecs()[0]));
516 }
517
518 // Test that SetLocalContent and SetRemoteContent properly set RTCP
519 // mux.
520 void TestSetContentsRtcpMux() {
521 CreateChannels(RTCP, RTCP);
522 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
523 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
524 typename T::Content content;
525 CreateContent(0, kPcmuCodec, kH264Codec, &content);
526 // Both sides agree on mux. Should no longer be a separate RTCP channel.
527 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000528 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
529 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000530 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
531 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000532 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000533 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000534 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
536 }
537
538 // Test that SetLocalContent and SetRemoteContent properly set RTCP
539 // mux when a provisional answer is received.
540 void TestSetContentsRtcpMuxWithPrAnswer() {
541 CreateChannels(RTCP, RTCP);
542 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
543 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
544 typename T::Content content;
545 CreateContent(0, kPcmuCodec, kH264Codec, &content);
546 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000547 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
548 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000550 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 // Both sides agree on mux. Should no longer be a separate RTCP channel.
552 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
553 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000554 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000556 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
557 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
559 }
560
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 // Test that SetRemoteContent properly deals with a content update.
562 void TestSetRemoteContentUpdate() {
563 CreateChannels(0, 0);
564 typename T::Content content;
565 CreateContent(RTCP | RTCP_MUX | SECURE,
566 kPcmuCodec, kH264Codec,
567 &content);
568 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000569 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
570 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 ASSERT_EQ(1U, media_channel1_->codecs().size());
572 EXPECT_TRUE(CodecMatches(content.codecs()[0],
573 media_channel1_->codecs()[0]));
574 // Now update with other codecs.
575 typename T::Content update_content;
576 update_content.set_partial(true);
577 CreateContent(0, kIsacCodec, kH264SvcCodec,
578 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000579 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 ASSERT_EQ(1U, media_channel1_->codecs().size());
581 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
582 media_channel1_->codecs()[0]));
583 // Now update without any codecs. This is ignored.
584 typename T::Content empty_content;
585 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000586 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 ASSERT_EQ(1U, media_channel1_->codecs().size());
588 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
589 media_channel1_->codecs()[0]));
590 }
591
592 // Test that Add/RemoveStream properly forward to the media channel.
593 void TestStreams() {
594 CreateChannels(0, 0);
595 EXPECT_TRUE(AddStream1(1));
596 EXPECT_TRUE(AddStream1(2));
597 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
598 EXPECT_TRUE(RemoveStream1(2));
599 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
600 EXPECT_TRUE(RemoveStream1(1));
601 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
602 }
603
604 // Test that SetLocalContent properly handles adding and removing StreamParams
605 // to the local content description.
606 // This test uses the CA_UPDATE action that don't require a full
607 // MediaContentDescription to do an update.
608 void TestUpdateStreamsInLocalContent() {
609 cricket::StreamParams stream1;
610 stream1.groupid = "group1";
611 stream1.id = "stream1";
612 stream1.ssrcs.push_back(kSsrc1);
613 stream1.cname = "stream1_cname";
614
615 cricket::StreamParams stream2;
616 stream2.groupid = "group2";
617 stream2.id = "stream2";
618 stream2.ssrcs.push_back(kSsrc2);
619 stream2.cname = "stream2_cname";
620
621 cricket::StreamParams stream3;
622 stream3.groupid = "group3";
623 stream3.id = "stream3";
624 stream3.ssrcs.push_back(kSsrc3);
625 stream3.cname = "stream3_cname";
626
627 CreateChannels(0, 0);
628 typename T::Content content1;
629 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
630 content1.AddStream(stream1);
631 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000632 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000633
634 ASSERT_EQ(1u, media_channel1_->send_streams().size());
635 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
636
637 // Update the local streams by adding another sending stream.
638 // Use a partial updated session description.
639 typename T::Content content2;
640 content2.AddStream(stream2);
641 content2.AddStream(stream3);
642 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000643 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000644 ASSERT_EQ(3u, media_channel1_->send_streams().size());
645 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
646 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
647 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
648
649 // Update the local streams by removing the first sending stream.
650 // This is done by removing all SSRCS for this particular stream.
651 typename T::Content content3;
652 stream1.ssrcs.clear();
653 content3.AddStream(stream1);
654 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000655 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 ASSERT_EQ(2u, media_channel1_->send_streams().size());
657 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
658 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
659
660 // Update the local streams with a stream that does not change.
661 // THe update is ignored.
662 typename T::Content content4;
663 content4.AddStream(stream2);
664 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000665 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 ASSERT_EQ(2u, media_channel1_->send_streams().size());
667 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
668 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
669 }
670
671 // Test that SetRemoteContent properly handles adding and removing
672 // StreamParams to the remote content description.
673 // This test uses the CA_UPDATE action that don't require a full
674 // MediaContentDescription to do an update.
675 void TestUpdateStreamsInRemoteContent() {
676 cricket::StreamParams stream1;
677 stream1.id = "Stream1";
678 stream1.groupid = "1";
679 stream1.ssrcs.push_back(kSsrc1);
680 stream1.cname = "stream1_cname";
681
682 cricket::StreamParams stream2;
683 stream2.id = "Stream2";
684 stream2.groupid = "2";
685 stream2.ssrcs.push_back(kSsrc2);
686 stream2.cname = "stream2_cname";
687
688 cricket::StreamParams stream3;
689 stream3.id = "Stream3";
690 stream3.groupid = "3";
691 stream3.ssrcs.push_back(kSsrc3);
692 stream3.cname = "stream3_cname";
693
694 CreateChannels(0, 0);
695 typename T::Content content1;
696 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
697 content1.AddStream(stream1);
698 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000700
701 ASSERT_EQ(1u, media_channel1_->codecs().size());
702 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
703 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
704
705 // Update the remote streams by adding another sending stream.
706 // Use a partial updated session description.
707 typename T::Content content2;
708 content2.AddStream(stream2);
709 content2.AddStream(stream3);
710 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000711 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
713 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
714 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
715 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
716
717 // Update the remote streams by removing the first stream.
718 // This is done by removing all SSRCS for this particular stream.
719 typename T::Content content3;
720 stream1.ssrcs.clear();
721 content3.AddStream(stream1);
722 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000723 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
725 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
726 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
727
728 // Update the remote streams with a stream that does not change.
729 // The update is ignored.
730 typename T::Content content4;
731 content4.AddStream(stream2);
732 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000733 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
735 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
736 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
737 }
738
739 // Test that SetLocalContent and SetRemoteContent properly
740 // handles adding and removing StreamParams when the action is a full
741 // CA_OFFER / CA_ANSWER.
742 void TestChangeStreamParamsInContent() {
743 cricket::StreamParams stream1;
744 stream1.groupid = "group1";
745 stream1.id = "stream1";
746 stream1.ssrcs.push_back(kSsrc1);
747 stream1.cname = "stream1_cname";
748
749 cricket::StreamParams stream2;
750 stream2.groupid = "group1";
751 stream2.id = "stream2";
752 stream2.ssrcs.push_back(kSsrc2);
753 stream2.cname = "stream2_cname";
754
755 // Setup a call where channel 1 send |stream1| to channel 2.
756 CreateChannels(0, 0);
757 typename T::Content content1;
758 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
759 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000760 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 EXPECT_TRUE(channel1_->Enable(true));
762 EXPECT_EQ(1u, media_channel1_->send_streams().size());
763
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000764 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000765 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
deadbeefcbecd352015-09-23 11:50:27 -0700766 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767
768 // Channel 2 do not send anything.
769 typename T::Content content2;
770 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000771 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000773 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 EXPECT_TRUE(channel2_->Enable(true));
775 EXPECT_EQ(0u, media_channel2_->send_streams().size());
776
777 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
778 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
779
780 // Let channel 2 update the content by sending |stream2| and enable SRTP.
781 typename T::Content content3;
782 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
783 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000784 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 ASSERT_EQ(1u, media_channel2_->send_streams().size());
786 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
787
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000788 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
790 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
791
792 // Channel 1 replies but stop sending stream1.
793 typename T::Content content4;
794 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000795 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 EXPECT_EQ(0u, media_channel1_->send_streams().size());
797
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000798 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
800
801 EXPECT_TRUE(channel1_->secure());
802 EXPECT_TRUE(channel2_->secure());
803 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
804 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
805 }
806
807 // Test that we only start playout and sending at the right times.
808 void TestPlayoutAndSendingStates() {
809 CreateChannels(0, 0);
Peter Boström34fbfff2015-09-24 19:20:30 +0200810 if (verify_playout_) {
811 EXPECT_FALSE(media_channel1_->playout());
812 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200814 if (verify_playout_) {
815 EXPECT_FALSE(media_channel2_->playout());
816 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 EXPECT_FALSE(media_channel2_->sending());
818 EXPECT_TRUE(channel1_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200819 if (verify_playout_) {
820 EXPECT_FALSE(media_channel1_->playout());
821 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000823 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
824 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200825 if (verify_playout_) {
826 EXPECT_TRUE(media_channel1_->playout());
827 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000829 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
830 CA_OFFER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200831 if (verify_playout_) {
832 EXPECT_FALSE(media_channel2_->playout());
833 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000835 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
836 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200837 if (verify_playout_) {
838 EXPECT_FALSE(media_channel2_->playout());
839 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 EXPECT_FALSE(media_channel2_->sending());
deadbeefcbecd352015-09-23 11:50:27 -0700841 transport_controller1_.Connect(&transport_controller2_);
Peter Boström34fbfff2015-09-24 19:20:30 +0200842 if (verify_playout_) {
843 EXPECT_TRUE(media_channel1_->playout());
844 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200846 if (verify_playout_) {
847 EXPECT_FALSE(media_channel2_->playout());
848 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 EXPECT_FALSE(media_channel2_->sending());
850 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200851 if (verify_playout_) {
852 EXPECT_TRUE(media_channel2_->playout());
853 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000855 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
856 CA_ANSWER, NULL));
Peter Boström34fbfff2015-09-24 19:20:30 +0200857 if (verify_playout_) {
858 EXPECT_TRUE(media_channel1_->playout());
859 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000860 EXPECT_TRUE(media_channel1_->sending());
861 }
862
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 // Test that changing the MediaContentDirection in the local and remote
864 // session description start playout and sending at the right time.
865 void TestMediaContentDirection() {
866 CreateChannels(0, 0);
867 typename T::Content content1;
868 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
869 typename T::Content content2;
870 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
871 // Set |content2| to be InActive.
872 content2.set_direction(cricket::MD_INACTIVE);
873
874 EXPECT_TRUE(channel1_->Enable(true));
875 EXPECT_TRUE(channel2_->Enable(true));
Peter Boström34fbfff2015-09-24 19:20:30 +0200876 if (verify_playout_) {
877 EXPECT_FALSE(media_channel1_->playout());
878 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 EXPECT_FALSE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200880 if (verify_playout_) {
881 EXPECT_FALSE(media_channel2_->playout());
882 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_FALSE(media_channel2_->sending());
884
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000885 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
886 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
887 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
888 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700889 transport_controller1_.Connect(&transport_controller2_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890
Peter Boström34fbfff2015-09-24 19:20:30 +0200891 if (verify_playout_) {
892 EXPECT_TRUE(media_channel1_->playout());
893 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
Peter Boström34fbfff2015-09-24 19:20:30 +0200895 if (verify_playout_) {
896 EXPECT_FALSE(media_channel2_->playout()); // local InActive
897 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 EXPECT_FALSE(media_channel2_->sending()); // local InActive
899
900 // Update |content2| to be RecvOnly.
901 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000902 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
903 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904
Peter Boström34fbfff2015-09-24 19:20:30 +0200905 if (verify_playout_) {
906 EXPECT_TRUE(media_channel1_->playout());
907 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200909 if (verify_playout_) {
910 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
911 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
913
914 // Update |content2| to be SendRecv.
915 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000916 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
917 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918
Peter Boström34fbfff2015-09-24 19:20:30 +0200919 if (verify_playout_) {
920 EXPECT_TRUE(media_channel1_->playout());
921 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 EXPECT_TRUE(media_channel1_->sending());
Peter Boström34fbfff2015-09-24 19:20:30 +0200923 if (verify_playout_) {
924 EXPECT_TRUE(media_channel2_->playout());
925 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 EXPECT_TRUE(media_channel2_->sending());
927 }
928
929 // Test setting up a call.
930 void TestCallSetup() {
931 CreateChannels(0, 0);
932 EXPECT_FALSE(channel1_->secure());
933 EXPECT_TRUE(SendInitiate());
Peter Boström34fbfff2015-09-24 19:20:30 +0200934 if (verify_playout_) {
935 EXPECT_TRUE(media_channel1_->playout());
936 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 EXPECT_FALSE(media_channel1_->sending());
938 EXPECT_TRUE(SendAccept());
939 EXPECT_FALSE(channel1_->secure());
940 EXPECT_TRUE(media_channel1_->sending());
941 EXPECT_EQ(1U, media_channel1_->codecs().size());
Peter Boström34fbfff2015-09-24 19:20:30 +0200942 if (verify_playout_) {
943 EXPECT_TRUE(media_channel2_->playout());
944 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 EXPECT_TRUE(media_channel2_->sending());
946 EXPECT_EQ(1U, media_channel2_->codecs().size());
947 }
948
949 // Test that we don't crash if packets are sent during call teardown
950 // when RTCP mux is enabled. This is a regression test against a specific
951 // race condition that would only occur when a RTCP packet was sent during
952 // teardown of a channel on which RTCP mux was enabled.
953 void TestCallTeardownRtcpMux() {
954 class LastWordMediaChannel : public T::MediaChannel {
955 public:
Fredrik Solenbergb071a192015-09-17 16:42:56 +0200956 LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 ~LastWordMediaChannel() {
958 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
959 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
960 }
961 };
962 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
963 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000964 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 EXPECT_TRUE(SendInitiate());
966 EXPECT_TRUE(SendAccept());
967 EXPECT_TRUE(SendTerminate());
968 }
969
970 // Send voice RTP data to the other side and ensure it gets there.
971 void SendRtpToRtp() {
972 CreateChannels(0, 0);
973 EXPECT_TRUE(SendInitiate());
974 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700975 ASSERT_TRUE(GetTransport1());
976 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 EXPECT_EQ(1U, GetTransport1()->channels().size());
978 EXPECT_EQ(1U, GetTransport2()->channels().size());
979 EXPECT_TRUE(SendRtp1());
980 EXPECT_TRUE(SendRtp2());
981 EXPECT_TRUE(CheckRtp1());
982 EXPECT_TRUE(CheckRtp2());
983 EXPECT_TRUE(CheckNoRtp1());
984 EXPECT_TRUE(CheckNoRtp2());
985 }
986
987 // Check that RTCP is not transmitted if both sides don't support RTCP.
988 void SendNoRtcpToNoRtcp() {
989 CreateChannels(0, 0);
990 EXPECT_TRUE(SendInitiate());
991 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -0700992 ASSERT_TRUE(GetTransport1());
993 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994 EXPECT_EQ(1U, GetTransport1()->channels().size());
995 EXPECT_EQ(1U, GetTransport2()->channels().size());
996 EXPECT_FALSE(SendRtcp1());
997 EXPECT_FALSE(SendRtcp2());
998 EXPECT_TRUE(CheckNoRtcp1());
999 EXPECT_TRUE(CheckNoRtcp2());
1000 }
1001
1002 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1003 void SendNoRtcpToRtcp() {
1004 CreateChannels(0, RTCP);
1005 EXPECT_TRUE(SendInitiate());
1006 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001007 ASSERT_TRUE(GetTransport1());
1008 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 EXPECT_EQ(1U, GetTransport1()->channels().size());
1010 EXPECT_EQ(2U, GetTransport2()->channels().size());
1011 EXPECT_FALSE(SendRtcp1());
1012 EXPECT_FALSE(SendRtcp2());
1013 EXPECT_TRUE(CheckNoRtcp1());
1014 EXPECT_TRUE(CheckNoRtcp2());
1015 }
1016
1017 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1018 void SendRtcpToNoRtcp() {
1019 CreateChannels(RTCP, 0);
1020 EXPECT_TRUE(SendInitiate());
1021 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001022 ASSERT_TRUE(GetTransport1());
1023 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001024 EXPECT_EQ(2U, GetTransport1()->channels().size());
1025 EXPECT_EQ(1U, GetTransport2()->channels().size());
1026 EXPECT_FALSE(SendRtcp1());
1027 EXPECT_FALSE(SendRtcp2());
1028 EXPECT_TRUE(CheckNoRtcp1());
1029 EXPECT_TRUE(CheckNoRtcp2());
1030 }
1031
1032 // Check that RTCP is transmitted if both sides support RTCP.
1033 void SendRtcpToRtcp() {
1034 CreateChannels(RTCP, RTCP);
1035 EXPECT_TRUE(SendInitiate());
1036 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001037 ASSERT_TRUE(GetTransport1());
1038 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 EXPECT_EQ(2U, GetTransport1()->channels().size());
1040 EXPECT_EQ(2U, GetTransport2()->channels().size());
1041 EXPECT_TRUE(SendRtcp1());
1042 EXPECT_TRUE(SendRtcp2());
1043 EXPECT_TRUE(CheckRtcp1());
1044 EXPECT_TRUE(CheckRtcp2());
1045 EXPECT_TRUE(CheckNoRtcp1());
1046 EXPECT_TRUE(CheckNoRtcp2());
1047 }
1048
1049 // Check that RTCP is transmitted if only the initiator supports mux.
1050 void SendRtcpMuxToRtcp() {
1051 CreateChannels(RTCP | RTCP_MUX, RTCP);
1052 EXPECT_TRUE(SendInitiate());
1053 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001054 ASSERT_TRUE(GetTransport1());
1055 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 EXPECT_EQ(2U, GetTransport1()->channels().size());
1057 EXPECT_EQ(2U, GetTransport2()->channels().size());
1058 EXPECT_TRUE(SendRtcp1());
1059 EXPECT_TRUE(SendRtcp2());
1060 EXPECT_TRUE(CheckRtcp1());
1061 EXPECT_TRUE(CheckRtcp2());
1062 EXPECT_TRUE(CheckNoRtcp1());
1063 EXPECT_TRUE(CheckNoRtcp2());
1064 }
1065
1066 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1067 void SendRtcpMuxToRtcpMux() {
1068 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1069 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001070 ASSERT_TRUE(GetTransport1());
1071 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 EXPECT_EQ(2U, GetTransport1()->channels().size());
1073 EXPECT_EQ(1U, GetTransport2()->channels().size());
1074 EXPECT_TRUE(SendAccept());
1075 EXPECT_EQ(1U, GetTransport1()->channels().size());
1076 EXPECT_TRUE(SendRtp1());
1077 EXPECT_TRUE(SendRtp2());
1078 EXPECT_TRUE(SendRtcp1());
1079 EXPECT_TRUE(SendRtcp2());
1080 EXPECT_TRUE(CheckRtp1());
1081 EXPECT_TRUE(CheckRtp2());
1082 EXPECT_TRUE(CheckNoRtp1());
1083 EXPECT_TRUE(CheckNoRtp2());
1084 EXPECT_TRUE(CheckRtcp1());
1085 EXPECT_TRUE(CheckRtcp2());
1086 EXPECT_TRUE(CheckNoRtcp1());
1087 EXPECT_TRUE(CheckNoRtcp2());
1088 }
1089
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001090 // Check that RTP and RTCP are transmitted ok when both sides
1091 // support mux and one the offerer requires mux.
1092 void SendRequireRtcpMuxToRtcpMux() {
1093 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1094 channel1_->ActivateRtcpMux();
1095 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001096 ASSERT_TRUE(GetTransport1());
1097 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001098 EXPECT_EQ(1U, GetTransport1()->channels().size());
1099 EXPECT_EQ(1U, GetTransport2()->channels().size());
1100 EXPECT_TRUE(SendAccept());
1101 EXPECT_TRUE(SendRtp1());
1102 EXPECT_TRUE(SendRtp2());
1103 EXPECT_TRUE(SendRtcp1());
1104 EXPECT_TRUE(SendRtcp2());
1105 EXPECT_TRUE(CheckRtp1());
1106 EXPECT_TRUE(CheckRtp2());
1107 EXPECT_TRUE(CheckNoRtp1());
1108 EXPECT_TRUE(CheckNoRtp2());
1109 EXPECT_TRUE(CheckRtcp1());
1110 EXPECT_TRUE(CheckRtcp2());
1111 EXPECT_TRUE(CheckNoRtcp1());
1112 EXPECT_TRUE(CheckNoRtcp2());
1113 }
1114
1115 // Check that RTP and RTCP are transmitted ok when both sides
1116 // support mux and one the answerer requires rtcp mux.
1117 void SendRtcpMuxToRequireRtcpMux() {
1118 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1119 channel2_->ActivateRtcpMux();
1120 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001121 ASSERT_TRUE(GetTransport1());
1122 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001123 EXPECT_EQ(2U, GetTransport1()->channels().size());
1124 EXPECT_EQ(1U, GetTransport2()->channels().size());
1125 EXPECT_TRUE(SendAccept());
1126 EXPECT_EQ(1U, GetTransport1()->channels().size());
1127 EXPECT_TRUE(SendRtp1());
1128 EXPECT_TRUE(SendRtp2());
1129 EXPECT_TRUE(SendRtcp1());
1130 EXPECT_TRUE(SendRtcp2());
1131 EXPECT_TRUE(CheckRtp1());
1132 EXPECT_TRUE(CheckRtp2());
1133 EXPECT_TRUE(CheckNoRtp1());
1134 EXPECT_TRUE(CheckNoRtp2());
1135 EXPECT_TRUE(CheckRtcp1());
1136 EXPECT_TRUE(CheckRtcp2());
1137 EXPECT_TRUE(CheckNoRtcp1());
1138 EXPECT_TRUE(CheckNoRtcp2());
1139 }
1140
1141 // Check that RTP and RTCP are transmitted ok when both sides
1142 // require mux.
1143 void SendRequireRtcpMuxToRequireRtcpMux() {
1144 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1145 channel1_->ActivateRtcpMux();
1146 channel2_->ActivateRtcpMux();
1147 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001148 ASSERT_TRUE(GetTransport1());
1149 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001150 EXPECT_EQ(1U, GetTransport1()->channels().size());
1151 EXPECT_EQ(1U, GetTransport2()->channels().size());
1152 EXPECT_TRUE(SendAccept());
1153 EXPECT_EQ(1U, GetTransport1()->channels().size());
1154 EXPECT_TRUE(SendRtp1());
1155 EXPECT_TRUE(SendRtp2());
1156 EXPECT_TRUE(SendRtcp1());
1157 EXPECT_TRUE(SendRtcp2());
1158 EXPECT_TRUE(CheckRtp1());
1159 EXPECT_TRUE(CheckRtp2());
1160 EXPECT_TRUE(CheckNoRtp1());
1161 EXPECT_TRUE(CheckNoRtp2());
1162 EXPECT_TRUE(CheckRtcp1());
1163 EXPECT_TRUE(CheckRtcp2());
1164 EXPECT_TRUE(CheckNoRtcp1());
1165 EXPECT_TRUE(CheckNoRtcp2());
1166 }
1167
1168 // Check that SendAccept fails if the answerer doesn't support mux
1169 // and the offerer requires it.
1170 void SendRequireRtcpMuxToNoRtcpMux() {
1171 CreateChannels(RTCP | RTCP_MUX, RTCP);
1172 channel1_->ActivateRtcpMux();
1173 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001174 ASSERT_TRUE(GetTransport1());
1175 ASSERT_TRUE(GetTransport2());
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001176 EXPECT_EQ(1U, GetTransport1()->channels().size());
1177 EXPECT_EQ(2U, GetTransport2()->channels().size());
1178 EXPECT_FALSE(SendAccept());
1179 }
1180
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181 // Check that RTCP data sent by the initiator before the accept is not muxed.
1182 void SendEarlyRtcpMuxToRtcp() {
1183 CreateChannels(RTCP | RTCP_MUX, RTCP);
1184 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001185 ASSERT_TRUE(GetTransport1());
1186 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 EXPECT_EQ(2U, GetTransport1()->channels().size());
1188 EXPECT_EQ(2U, GetTransport2()->channels().size());
1189
1190 // RTCP can be sent before the call is accepted, if the transport is ready.
1191 // It should not be muxed though, as the remote side doesn't support mux.
1192 EXPECT_TRUE(SendRtcp1());
1193 EXPECT_TRUE(CheckNoRtp2());
1194 EXPECT_TRUE(CheckRtcp2());
1195
1196 // Send RTCP packet from callee and verify that it is received.
1197 EXPECT_TRUE(SendRtcp2());
1198 EXPECT_TRUE(CheckNoRtp1());
1199 EXPECT_TRUE(CheckRtcp1());
1200
1201 // Complete call setup and ensure everything is still OK.
1202 EXPECT_TRUE(SendAccept());
1203 EXPECT_EQ(2U, GetTransport1()->channels().size());
1204 EXPECT_TRUE(SendRtcp1());
1205 EXPECT_TRUE(CheckRtcp2());
1206 EXPECT_TRUE(SendRtcp2());
1207 EXPECT_TRUE(CheckRtcp1());
1208 }
1209
1210
1211 // Check that RTCP data is not muxed until both sides have enabled muxing,
1212 // but that we properly demux before we get the accept message, since there
1213 // is a race between RTP data and the jingle accept.
1214 void SendEarlyRtcpMuxToRtcpMux() {
1215 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1216 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001217 ASSERT_TRUE(GetTransport1());
1218 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001219 EXPECT_EQ(2U, GetTransport1()->channels().size());
1220 EXPECT_EQ(1U, GetTransport2()->channels().size());
1221
1222 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1223 // we haven't yet received the accept that says we should mux.
1224 EXPECT_FALSE(SendRtcp1());
1225
1226 // Send muxed RTCP packet from callee and verify that it is received.
1227 EXPECT_TRUE(SendRtcp2());
1228 EXPECT_TRUE(CheckNoRtp1());
1229 EXPECT_TRUE(CheckRtcp1());
1230
1231 // Complete call setup and ensure everything is still OK.
1232 EXPECT_TRUE(SendAccept());
1233 EXPECT_EQ(1U, GetTransport1()->channels().size());
1234 EXPECT_TRUE(SendRtcp1());
1235 EXPECT_TRUE(CheckRtcp2());
1236 EXPECT_TRUE(SendRtcp2());
1237 EXPECT_TRUE(CheckRtcp1());
1238 }
1239
1240 // Test that we properly send SRTP with RTCP in both directions.
1241 // You can pass in DTLS and/or RTCP_MUX as flags.
1242 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1243 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1244 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1245
1246 int flags1 = RTCP | SECURE | flags1_in;
1247 int flags2 = RTCP | SECURE | flags2_in;
1248 bool dtls1 = !!(flags1_in & DTLS);
1249 bool dtls2 = !!(flags2_in & DTLS);
1250 CreateChannels(flags1, flags2);
1251 EXPECT_FALSE(channel1_->secure());
1252 EXPECT_FALSE(channel2_->secure());
1253 EXPECT_TRUE(SendInitiate());
1254 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1255 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1256 EXPECT_TRUE(SendAccept());
1257 EXPECT_TRUE(channel1_->secure());
1258 EXPECT_TRUE(channel2_->secure());
1259 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1260 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1261 EXPECT_TRUE(SendRtp1());
1262 EXPECT_TRUE(SendRtp2());
1263 EXPECT_TRUE(SendRtcp1());
1264 EXPECT_TRUE(SendRtcp2());
1265 EXPECT_TRUE(CheckRtp1());
1266 EXPECT_TRUE(CheckRtp2());
1267 EXPECT_TRUE(CheckNoRtp1());
1268 EXPECT_TRUE(CheckNoRtp2());
1269 EXPECT_TRUE(CheckRtcp1());
1270 EXPECT_TRUE(CheckRtcp2());
1271 EXPECT_TRUE(CheckNoRtcp1());
1272 EXPECT_TRUE(CheckNoRtcp2());
1273 }
1274
1275 // Test that we properly handling SRTP negotiating down to RTP.
1276 void SendSrtpToRtp() {
1277 CreateChannels(RTCP | SECURE, RTCP);
1278 EXPECT_FALSE(channel1_->secure());
1279 EXPECT_FALSE(channel2_->secure());
1280 EXPECT_TRUE(SendInitiate());
1281 EXPECT_TRUE(SendAccept());
1282 EXPECT_FALSE(channel1_->secure());
1283 EXPECT_FALSE(channel2_->secure());
1284 EXPECT_TRUE(SendRtp1());
1285 EXPECT_TRUE(SendRtp2());
1286 EXPECT_TRUE(SendRtcp1());
1287 EXPECT_TRUE(SendRtcp2());
1288 EXPECT_TRUE(CheckRtp1());
1289 EXPECT_TRUE(CheckRtp2());
1290 EXPECT_TRUE(CheckNoRtp1());
1291 EXPECT_TRUE(CheckNoRtp2());
1292 EXPECT_TRUE(CheckRtcp1());
1293 EXPECT_TRUE(CheckRtcp2());
1294 EXPECT_TRUE(CheckNoRtcp1());
1295 EXPECT_TRUE(CheckNoRtcp2());
1296 }
1297
1298 // Test that we can send and receive early media when a provisional answer is
1299 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1300 void SendEarlyMediaUsingRtcpMuxSrtp() {
1301 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1302
1303 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1304 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1305 EXPECT_TRUE(SendOffer());
1306 EXPECT_TRUE(SendProvisionalAnswer());
1307 EXPECT_TRUE(channel1_->secure());
1308 EXPECT_TRUE(channel2_->secure());
deadbeefcbecd352015-09-23 11:50:27 -07001309 ASSERT_TRUE(GetTransport1());
1310 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 EXPECT_EQ(2U, GetTransport1()->channels().size());
1312 EXPECT_EQ(2U, GetTransport2()->channels().size());
1313 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1314 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1315 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1316 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1317
1318 // Send packets from callee and verify that it is received.
1319 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1320 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1321 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1322 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1323
1324 // Complete call setup and ensure everything is still OK.
1325 EXPECT_TRUE(SendFinalAnswer());
1326 EXPECT_EQ(1U, GetTransport1()->channels().size());
1327 EXPECT_EQ(1U, GetTransport2()->channels().size());
1328 EXPECT_TRUE(channel1_->secure());
1329 EXPECT_TRUE(channel2_->secure());
1330 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1331 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1332 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1333 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1334 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1335 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1336 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1337 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1338 }
1339
1340 // Test that we properly send RTP without SRTP from a thread.
1341 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001342 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1343 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 EXPECT_TRUE(SendInitiate());
1345 EXPECT_TRUE(SendAccept());
1346 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1347 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001348 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1349 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1351 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1352 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1353 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1354 EXPECT_TRUE(CheckNoRtp1());
1355 EXPECT_TRUE(CheckNoRtp2());
1356 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1357 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1358 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1359 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1360 EXPECT_TRUE(CheckNoRtcp1());
1361 EXPECT_TRUE(CheckNoRtcp2());
1362 }
1363
1364 // Test that we properly send SRTP with RTCP from a thread.
1365 void SendSrtpToSrtpOnThread() {
1366 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1367 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1368 EXPECT_TRUE(SendInitiate());
1369 EXPECT_TRUE(SendAccept());
1370 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1371 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1372 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1373 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1374 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1375 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1376 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1377 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1378 EXPECT_TRUE(CheckNoRtp1());
1379 EXPECT_TRUE(CheckNoRtp2());
1380 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1381 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1382 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1383 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1384 EXPECT_TRUE(CheckNoRtcp1());
1385 EXPECT_TRUE(CheckNoRtcp2());
1386 }
1387
1388 // Test that the mediachannel retains its sending state after the transport
1389 // becomes non-writable.
1390 void SendWithWritabilityLoss() {
1391 CreateChannels(0, 0);
1392 EXPECT_TRUE(SendInitiate());
1393 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001394 ASSERT_TRUE(GetTransport1());
1395 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 EXPECT_EQ(1U, GetTransport1()->channels().size());
1397 EXPECT_EQ(1U, GetTransport2()->channels().size());
1398 EXPECT_TRUE(SendRtp1());
1399 EXPECT_TRUE(SendRtp2());
1400 EXPECT_TRUE(CheckRtp1());
1401 EXPECT_TRUE(CheckRtp2());
1402 EXPECT_TRUE(CheckNoRtp1());
1403 EXPECT_TRUE(CheckNoRtp2());
1404
wu@webrtc.org97077a32013-10-25 21:18:33 +00001405 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 EXPECT_FALSE(SendRtp1());
1408 EXPECT_TRUE(SendRtp2());
1409 EXPECT_TRUE(CheckRtp1());
1410 EXPECT_TRUE(CheckNoRtp2());
1411
1412 // Regain writability
1413 GetTransport1()->SetWritable(true);
1414 EXPECT_TRUE(media_channel1_->sending());
1415 EXPECT_TRUE(SendRtp1());
1416 EXPECT_TRUE(SendRtp2());
1417 EXPECT_TRUE(CheckRtp1());
1418 EXPECT_TRUE(CheckRtp2());
1419 EXPECT_TRUE(CheckNoRtp1());
1420 EXPECT_TRUE(CheckNoRtp2());
1421
1422 // Lose writability completely
1423 GetTransport1()->SetDestination(NULL);
1424 EXPECT_TRUE(media_channel1_->sending());
1425
wu@webrtc.org97077a32013-10-25 21:18:33 +00001426 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 EXPECT_FALSE(SendRtp1());
1428 EXPECT_TRUE(SendRtp2());
1429 EXPECT_TRUE(CheckRtp1());
1430 EXPECT_TRUE(CheckNoRtp2());
1431
1432 // Gain writability back
1433 GetTransport1()->SetDestination(GetTransport2());
1434 EXPECT_TRUE(media_channel1_->sending());
1435 EXPECT_TRUE(SendRtp1());
1436 EXPECT_TRUE(SendRtp2());
1437 EXPECT_TRUE(CheckRtp1());
1438 EXPECT_TRUE(CheckRtp2());
1439 EXPECT_TRUE(CheckNoRtp1());
1440 EXPECT_TRUE(CheckNoRtp2());
1441 }
1442
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001443 void SendBundleToBundle(
1444 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1445 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001447 // Only pl_type1 was added to the bundle filter for both |channel1_|
1448 // and |channel2_|.
1449 int pl_type1 = pl_types[0];
1450 int pl_type2 = pl_types[1];
1451 int flags = SSRC_MUX | RTCP;
1452 if (secure) flags |= SECURE;
1453 uint32 expected_channels = 2U;
1454 if (rtcp_mux) {
1455 flags |= RTCP_MUX;
1456 expected_channels = 1U;
1457 }
1458 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459 EXPECT_TRUE(SendInitiate());
deadbeefcbecd352015-09-23 11:50:27 -07001460 ASSERT_TRUE(GetTransport1());
1461 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001463 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001465 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1466 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1467 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1468 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1469 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1470 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1471 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1472 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1473 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1474 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1475 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1476 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1477
1478 // Both channels can receive pl_type1 only.
1479 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1480 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1481 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1482 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1483 EXPECT_TRUE(CheckNoRtp1());
1484 EXPECT_TRUE(CheckNoRtp2());
1485
1486 // RTCP test
1487 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1488 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1489 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1490 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1491
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001492 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1493 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001494 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1495 EXPECT_TRUE(CheckNoRtcp1());
1496 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1497 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001499 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1500 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1503 }
1504
1505 // Test that the media monitor can be run and gives timely callbacks.
1506 void TestMediaMonitor() {
1507 static const int kTimeout = 500;
1508 CreateChannels(0, 0);
1509 EXPECT_TRUE(SendInitiate());
1510 EXPECT_TRUE(SendAccept());
1511 channel1_->StartMediaMonitor(100);
1512 channel2_->StartMediaMonitor(100);
1513 // Ensure we get callbacks and stop.
1514 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1515 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1516 channel1_->StopMediaMonitor();
1517 channel2_->StopMediaMonitor();
1518 // Ensure a restart of a stopped monitor works.
1519 channel1_->StartMediaMonitor(100);
1520 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1521 channel1_->StopMediaMonitor();
1522 // Ensure stopping a stopped monitor is OK.
1523 channel1_->StopMediaMonitor();
1524 }
1525
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 void TestSetContentFailure() {
1527 CreateChannels(0, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528
Peter Thatchera6d24442015-07-09 21:26:36 -07001529 auto sdesc = cricket::SessionDescription();
1530 sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1531 new cricket::AudioContentDescription());
1532 sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1533 new cricket::VideoContentDescription());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534
Peter Thatchera6d24442015-07-09 21:26:36 -07001535 std::string err;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 media_channel1_->set_fail_set_recv_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001537 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1538 &sdesc, cricket::CA_OFFER, &err));
1539 EXPECT_FALSE(channel1_->PushdownLocalDescription(
1540 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001543 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1544 &sdesc, cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 media_channel1_->set_fail_set_send_codecs(true);
Peter Thatchera6d24442015-07-09 21:26:36 -07001546 EXPECT_FALSE(channel1_->PushdownRemoteDescription(
1547 &sdesc, cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 }
1549
1550 void TestSendTwoOffers() {
1551 CreateChannels(0, 0);
1552
Peter Thatchera6d24442015-07-09 21:26:36 -07001553 std::string err;
1554 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1555 CreateSessionDescriptionWithStream(1));
1556 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1557 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1559
Peter Thatchera6d24442015-07-09 21:26:36 -07001560 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1561 CreateSessionDescriptionWithStream(2));
1562 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1563 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1565 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1566 }
1567
1568 void TestReceiveTwoOffers() {
1569 CreateChannels(0, 0);
1570
Peter Thatchera6d24442015-07-09 21:26:36 -07001571 std::string err;
1572 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1573 CreateSessionDescriptionWithStream(1));
1574 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1575 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1577
Peter Thatchera6d24442015-07-09 21:26:36 -07001578 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1579 CreateSessionDescriptionWithStream(2));
1580 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1581 sdesc2.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1583 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1584 }
1585
1586 void TestSendPrAnswer() {
1587 CreateChannels(0, 0);
1588
Peter Thatchera6d24442015-07-09 21:26:36 -07001589 std::string err;
1590 // Receive offer
1591 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1592 CreateSessionDescriptionWithStream(1));
1593 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1594 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1596
Peter Thatchera6d24442015-07-09 21:26:36 -07001597 // Send PR answer
1598 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1599 CreateSessionDescriptionWithStream(2));
1600 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1601 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1603 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1604
Peter Thatchera6d24442015-07-09 21:26:36 -07001605 // Send answer
1606 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1607 CreateSessionDescriptionWithStream(3));
1608 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1609 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1611 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1612 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1613 }
1614
1615 void TestReceivePrAnswer() {
1616 CreateChannels(0, 0);
1617
Peter Thatchera6d24442015-07-09 21:26:36 -07001618 std::string err;
1619 // Send offer
1620 rtc::scoped_ptr<cricket::SessionDescription> sdesc1(
1621 CreateSessionDescriptionWithStream(1));
1622 EXPECT_TRUE(channel1_->PushdownLocalDescription(
1623 sdesc1.get(), cricket::CA_OFFER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1625
Peter Thatchera6d24442015-07-09 21:26:36 -07001626 // Receive PR answer
1627 rtc::scoped_ptr<cricket::SessionDescription> sdesc2(
1628 CreateSessionDescriptionWithStream(2));
1629 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1630 sdesc2.get(), cricket::CA_PRANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1632 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1633
Peter Thatchera6d24442015-07-09 21:26:36 -07001634 // Receive answer
1635 rtc::scoped_ptr<cricket::SessionDescription> sdesc3(
1636 CreateSessionDescriptionWithStream(3));
1637 EXPECT_TRUE(channel1_->PushdownRemoteDescription(
1638 sdesc3.get(), cricket::CA_ANSWER, &err));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1640 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1641 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1642 }
1643
1644 void TestFlushRtcp() {
1645 bool send_rtcp1;
1646
1647 CreateChannels(RTCP, RTCP);
1648 EXPECT_TRUE(SendInitiate());
1649 EXPECT_TRUE(SendAccept());
deadbeefcbecd352015-09-23 11:50:27 -07001650 ASSERT_TRUE(GetTransport1());
1651 ASSERT_TRUE(GetTransport2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 EXPECT_EQ(2U, GetTransport1()->channels().size());
1653 EXPECT_EQ(2U, GetTransport2()->channels().size());
1654
1655 // Send RTCP1 from a different thread.
1656 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1657 EXPECT_TRUE(send_rtcp1);
1658 // The sending message is only posted. channel2_ should be empty.
1659 EXPECT_TRUE(CheckNoRtcp2());
1660
1661 // When channel1_ is deleted, the RTCP packet should be sent out to
1662 // channel2_.
1663 channel1_.reset();
1664 EXPECT_TRUE(CheckRtcp2());
1665 }
1666
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001667 void TestSrtpError(int pl_type) {
solenberg5b14b422015-10-01 04:10:31 -07001668 struct SrtpErrorHandler : public sigslot::has_slots<> {
1669 SrtpErrorHandler() :
1670 mode_(cricket::SrtpFilter::UNPROTECT),
1671 error_(cricket::SrtpFilter::ERROR_NONE) {}
1672 void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode,
1673 cricket::SrtpFilter::Error error) {
1674 mode_ = mode;
1675 error_ = error;
1676 }
1677 cricket::SrtpFilter::Mode mode_;
1678 cricket::SrtpFilter::Error error_;
1679 } error_handler;
1680
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001681 // For Audio, only pl_type 0 is added to the bundle filter.
1682 // For Video, only pl_type 97 is added to the bundle filter.
1683 // So we need to pass in pl_type so that the packet can pass through
1684 // the bundle filter before it can be processed by the srtp filter.
1685 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001686 unsigned const char kBadPacket[] = {0x84,
1687 static_cast<unsigned char>(pl_type),
1688 0x00,
1689 0x01,
1690 0x00,
1691 0x00,
1692 0x00,
1693 0x00,
1694 0x00,
1695 0x00,
1696 0x00,
1697 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1699 EXPECT_FALSE(channel1_->secure());
1700 EXPECT_FALSE(channel2_->secure());
1701 EXPECT_TRUE(SendInitiate());
1702 EXPECT_TRUE(SendAccept());
1703 EXPECT_TRUE(channel1_->secure());
1704 EXPECT_TRUE(channel2_->secure());
solenberg5629a1d2015-10-01 08:45:57 -07001705 channel2_->srtp_filter()->set_signal_silent_time(250);
solenberg5b14b422015-10-01 04:10:31 -07001706 channel2_->srtp_filter()->SignalSrtpError.connect(
1707 &error_handler, &SrtpErrorHandler::OnSrtpError);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708
1709 // Testing failures in sending packets.
1710 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1711 // The first failure will trigger an error.
solenberg5b14b422015-10-01 04:10:31 -07001712 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1713 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
1714 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001715 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
1716 // The next 250 ms failures will not trigger an error.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1718 // Wait for a while to ensure no message comes in.
solenberg5629a1d2015-10-01 08:45:57 -07001719 rtc::Thread::Current()->ProcessMessages(200);
solenberg5b14b422015-10-01 04:10:31 -07001720 EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
solenberg5629a1d2015-10-01 08:45:57 -07001721 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
1722 // Wait for a little more - the error will be triggered again.
1723 rtc::Thread::Current()->ProcessMessages(200);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
solenberg5b14b422015-10-01 04:10:31 -07001725 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1726 EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727
1728 // Testing failures in receiving packets.
solenberg5b14b422015-10-01 04:10:31 -07001729 error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
solenberg5629a1d2015-10-01 08:45:57 -07001730 error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
solenberg5b14b422015-10-01 04:10:31 -07001731
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 cricket::TransportChannel* transport_channel =
1733 channel2_->transport_channel();
1734 transport_channel->SignalReadPacket(
1735 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001736 sizeof(kBadPacket), rtc::PacketTime(), 0);
solenberg5b14b422015-10-01 04:10:31 -07001737 EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
1738 EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 }
1740
1741 void TestOnReadyToSend() {
1742 CreateChannels(RTCP, RTCP);
1743 TransportChannel* rtp = channel1_->transport_channel();
1744 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1745 EXPECT_FALSE(media_channel1_->ready_to_send());
1746 rtp->SignalReadyToSend(rtp);
1747 EXPECT_FALSE(media_channel1_->ready_to_send());
1748 rtcp->SignalReadyToSend(rtcp);
1749 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1750 // channel are ready to send.
1751 EXPECT_TRUE(media_channel1_->ready_to_send());
1752
1753 // rtp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001754 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001756 channel1_->SetReadyToSend(false, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 EXPECT_TRUE(media_channel1_->ready_to_send());
1758
1759 // rtcp channel becomes not ready to send will be propagated to mediachannel
deadbeefcbecd352015-09-23 11:50:27 -07001760 channel1_->SetReadyToSend(true, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 EXPECT_FALSE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001762 channel1_->SetReadyToSend(true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 EXPECT_TRUE(media_channel1_->ready_to_send());
1764 }
1765
1766 void TestOnReadyToSendWithRtcpMux() {
1767 CreateChannels(RTCP, RTCP);
1768 typename T::Content content;
1769 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1770 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1771 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001772 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1773 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1775 TransportChannel* rtp = channel1_->transport_channel();
1776 EXPECT_FALSE(media_channel1_->ready_to_send());
1777 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1778 // should trigger the MediaChannel's OnReadyToSend.
1779 rtp->SignalReadyToSend(rtp);
1780 EXPECT_TRUE(media_channel1_->ready_to_send());
deadbeefcbecd352015-09-23 11:50:27 -07001781 channel1_->SetReadyToSend(false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 EXPECT_FALSE(media_channel1_->ready_to_send());
1783 }
1784
1785 protected:
Peter Boström34fbfff2015-09-24 19:20:30 +02001786 // TODO(pbos): Remove playout from all media channels and let renderers mute
1787 // themselves.
1788 const bool verify_playout_;
deadbeefcbecd352015-09-23 11:50:27 -07001789 cricket::FakeTransportController transport_controller1_;
1790 cricket::FakeTransportController transport_controller2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 cricket::FakeMediaEngine media_engine_;
1792 // The media channels are owned by the voice channel objects below.
1793 typename T::MediaChannel* media_channel1_;
1794 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001795 rtc::scoped_ptr<typename T::Channel> channel1_;
1796 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 typename T::Content local_media_content1_;
1798 typename T::Content local_media_content2_;
1799 typename T::Content remote_media_content1_;
1800 typename T::Content remote_media_content2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 // The RTP and RTCP packets to send in the tests.
1802 std::string rtp_packet_;
1803 std::string rtcp_packet_;
1804 int media_info_callbacks1_;
1805 int media_info_callbacks2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806};
1807
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808template<>
1809void ChannelTest<VoiceTraits>::CreateContent(
1810 int flags,
1811 const cricket::AudioCodec& audio_codec,
1812 const cricket::VideoCodec& video_codec,
1813 cricket::AudioContentDescription* audio) {
1814 audio->AddCodec(audio_codec);
1815 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1816 if (flags & SECURE) {
1817 audio->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001818 1, rtc::CS_AES_CM_128_HMAC_SHA1_32,
1819 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 }
1821}
1822
1823template<>
1824void ChannelTest<VoiceTraits>::CopyContent(
1825 const cricket::AudioContentDescription& source,
1826 cricket::AudioContentDescription* audio) {
1827 *audio = source;
1828}
1829
1830template<>
1831bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1832 const cricket::AudioCodec& c2) {
1833 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1834 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1835}
1836
1837template<>
1838void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1839 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1840 audio->AddLegacyStream(ssrc);
1841}
1842
1843class VoiceChannelTest
1844 : public ChannelTest<VoiceTraits> {
1845 public:
solenberg1dd98f32015-09-10 01:57:14 -07001846 typedef ChannelTest<VoiceTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001847 VoiceChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001848 : Base(true,
1849 kPcmuFrame,
1850 sizeof(kPcmuFrame),
1851 kRtcpReport,
1852 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853};
1854
1855// override to add NULL parameter
deadbeefcbecd352015-09-23 11:50:27 -07001856template <>
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001858 rtc::Thread* thread,
1859 cricket::MediaEngineInterface* engine,
1860 cricket::FakeVideoMediaChannel* ch,
1861 cricket::TransportController* transport_controller,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 bool rtcp) {
1863 cricket::VideoChannel* channel = new cricket::VideoChannel(
deadbeefcbecd352015-09-23 11:50:27 -07001864 thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 if (!channel->Init()) {
1866 delete channel;
1867 channel = NULL;
1868 }
1869 return channel;
1870}
1871
1872// override to add 0 parameter
1873template<>
1874bool ChannelTest<VideoTraits>::AddStream1(int id) {
1875 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1876}
1877
1878template<>
1879void ChannelTest<VideoTraits>::CreateContent(
1880 int flags,
1881 const cricket::AudioCodec& audio_codec,
1882 const cricket::VideoCodec& video_codec,
1883 cricket::VideoContentDescription* video) {
1884 video->AddCodec(video_codec);
1885 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1886 if (flags & SECURE) {
1887 video->AddCrypto(cricket::CryptoParams(
Guo-wei Shieh456696a2015-09-30 21:48:54 -07001888 1, rtc::CS_AES_CM_128_HMAC_SHA1_80,
1889 "inline:" + rtc::CreateRandomString(40), std::string()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 }
1891}
1892
1893template<>
1894void ChannelTest<VideoTraits>::CopyContent(
1895 const cricket::VideoContentDescription& source,
1896 cricket::VideoContentDescription* video) {
1897 *video = source;
1898}
1899
1900template<>
1901bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1902 const cricket::VideoCodec& c2) {
1903 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1904 c1.framerate == c2.framerate;
1905}
1906
1907template<>
1908void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1909 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1910 video->AddLegacyStream(ssrc);
1911}
1912
1913class VideoChannelTest
1914 : public ChannelTest<VideoTraits> {
1915 public:
solenberg1dd98f32015-09-10 01:57:14 -07001916 typedef ChannelTest<VideoTraits> Base;
deadbeefcbecd352015-09-23 11:50:27 -07001917 VideoChannelTest()
Peter Boström34fbfff2015-09-24 19:20:30 +02001918 : Base(false,
1919 kH264Packet,
deadbeefcbecd352015-09-23 11:50:27 -07001920 sizeof(kH264Packet),
1921 kRtcpReport,
1922 sizeof(kRtcpReport)) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001923};
1924
1925
1926// VoiceChannelTest
1927
1928TEST_F(VoiceChannelTest, TestInit) {
1929 Base::TestInit();
1930 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1931 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1932}
1933
1934TEST_F(VoiceChannelTest, TestSetContents) {
1935 Base::TestSetContents();
1936}
1937
1938TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1939 Base::TestSetContentsNullOffer();
1940}
1941
1942TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1943 Base::TestSetContentsRtcpMux();
1944}
1945
1946TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
1947 Base::TestSetContentsRtcpMux();
1948}
1949
1950TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1951 Base::TestSetRemoteContentUpdate();
1952}
1953
1954TEST_F(VoiceChannelTest, TestStreams) {
1955 Base::TestStreams();
1956}
1957
1958TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1959 Base::TestUpdateStreamsInLocalContent();
1960}
1961
1962TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1963 Base::TestUpdateStreamsInRemoteContent();
1964}
1965
1966TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1967 Base::TestChangeStreamParamsInContent();
1968}
1969
1970TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1971 Base::TestPlayoutAndSendingStates();
1972}
1973
1974TEST_F(VoiceChannelTest, TestMuteStream) {
solenberg1dd98f32015-09-10 01:57:14 -07001975 CreateChannels(0, 0);
1976 // Test that we can Mute the default channel even though the sending SSRC
1977 // is unknown.
1978 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
solenberg1dd98f32015-09-10 01:57:14 -07001979 EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001980 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
1981 EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001982 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1983
1984 // Test that we can not mute an unknown SSRC.
solenbergdfc8f4f2015-10-01 02:31:10 -07001985 EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001986
1987 SendInitiate();
1988 // After the local session description has been set, we can mute a stream
1989 // with its SSRC.
solenberg1dd98f32015-09-10 01:57:14 -07001990 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
solenbergdfc8f4f2015-10-01 02:31:10 -07001991 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
1992 EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
solenberg1dd98f32015-09-10 01:57:14 -07001993 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994}
1995
1996TEST_F(VoiceChannelTest, TestMediaContentDirection) {
1997 Base::TestMediaContentDirection();
1998}
1999
2000TEST_F(VoiceChannelTest, TestCallSetup) {
2001 Base::TestCallSetup();
2002}
2003
2004TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2005 Base::TestCallTeardownRtcpMux();
2006}
2007
2008TEST_F(VoiceChannelTest, SendRtpToRtp) {
2009 Base::SendRtpToRtp();
2010}
2011
2012TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2013 Base::SendNoRtcpToNoRtcp();
2014}
2015
2016TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2017 Base::SendNoRtcpToRtcp();
2018}
2019
2020TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2021 Base::SendRtcpToNoRtcp();
2022}
2023
2024TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2025 Base::SendRtcpToRtcp();
2026}
2027
2028TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2029 Base::SendRtcpMuxToRtcp();
2030}
2031
2032TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2033 Base::SendRtcpMuxToRtcpMux();
2034}
2035
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002036TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2037 Base::SendRequireRtcpMuxToRtcpMux();
2038}
2039
2040TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2041 Base::SendRtcpMuxToRequireRtcpMux();
2042}
2043
2044TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2045 Base::SendRequireRtcpMuxToRequireRtcpMux();
2046}
2047
2048TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2049 Base::SendRequireRtcpMuxToNoRtcpMux();
2050}
2051
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2053 Base::SendEarlyRtcpMuxToRtcp();
2054}
2055
2056TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2057 Base::SendEarlyRtcpMuxToRtcpMux();
2058}
2059
2060TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2061 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2062}
2063
2064TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2065 Base::SendSrtpToSrtp();
2066}
2067
2068TEST_F(VoiceChannelTest, SendSrtcpMux) {
2069 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2070}
2071
2072TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2073 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2074 Base::SendSrtpToSrtp(DTLS, 0);
2075}
2076
2077TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2078 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2079 Base::SendSrtpToSrtp(DTLS, DTLS);
2080}
2081
2082TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2083 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2084 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2085}
2086
2087TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2088 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2089}
2090
2091TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2092 Base::SendRtpToRtpOnThread();
2093}
2094
2095TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2096 Base::SendSrtpToSrtpOnThread();
2097}
2098
2099TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2100 Base::SendWithWritabilityLoss();
2101}
2102
2103TEST_F(VoiceChannelTest, TestMediaMonitor) {
2104 Base::TestMediaMonitor();
2105}
2106
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107// Test that PressDTMF properly forwards to the media channel.
2108TEST_F(VoiceChannelTest, TestDtmf) {
2109 CreateChannels(0, 0);
2110 EXPECT_TRUE(SendInitiate());
2111 EXPECT_TRUE(SendAccept());
2112 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2113
2114 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2115 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2116
2117 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2118 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2119 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2120 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2121 0, 8, 160, cricket::DF_SEND));
2122}
2123
2124// Test that InsertDtmf properly forwards to the media channel.
2125TEST_F(VoiceChannelTest, TestInsertDtmf) {
2126 CreateChannels(0, 0);
2127 EXPECT_TRUE(SendInitiate());
2128 EXPECT_TRUE(SendAccept());
2129 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2130
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2132 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2133 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2134 cricket::DF_PLAY | cricket::DF_SEND));
2135
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002136 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002139 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002141 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2143}
2144
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145TEST_F(VoiceChannelTest, TestSetContentFailure) {
2146 Base::TestSetContentFailure();
2147}
2148
2149TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2150 Base::TestSendTwoOffers();
2151}
2152
2153TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2154 Base::TestReceiveTwoOffers();
2155}
2156
2157TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2158 Base::TestSendPrAnswer();
2159}
2160
2161TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2162 Base::TestReceivePrAnswer();
2163}
2164
2165TEST_F(VoiceChannelTest, TestFlushRtcp) {
2166 Base::TestFlushRtcp();
2167}
2168
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002170 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171}
2172
2173TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2174 Base::TestOnReadyToSend();
2175}
2176
2177TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2178 Base::TestOnReadyToSendWithRtcpMux();
2179}
2180
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181// Test that we can scale the output volume properly for 1:1 calls.
2182TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2183 CreateChannels(RTCP, RTCP);
2184 EXPECT_TRUE(SendInitiate());
2185 EXPECT_TRUE(SendAccept());
2186 double left, right;
2187
2188 // Default is (1.0, 1.0).
2189 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2190 EXPECT_DOUBLE_EQ(1.0, left);
2191 EXPECT_DOUBLE_EQ(1.0, right);
2192 // invalid ssrc.
2193 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2194
2195 // Set scale to (1.5, 0.5).
2196 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2197 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2198 EXPECT_DOUBLE_EQ(1.5, left);
2199 EXPECT_DOUBLE_EQ(0.5, right);
2200
2201 // Set scale to (0, 0).
2202 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2203 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2204 EXPECT_DOUBLE_EQ(0.0, left);
2205 EXPECT_DOUBLE_EQ(0.0, right);
2206}
2207
2208// Test that we can scale the output volume properly for multiway calls.
2209TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2210 CreateChannels(RTCP, RTCP);
2211 EXPECT_TRUE(SendInitiate());
2212 EXPECT_TRUE(SendAccept());
2213 EXPECT_TRUE(AddStream1(1));
2214 EXPECT_TRUE(AddStream1(2));
2215
2216 double left, right;
2217 // Default is (1.0, 1.0).
2218 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2219 EXPECT_DOUBLE_EQ(1.0, left);
2220 EXPECT_DOUBLE_EQ(1.0, right);
2221 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2222 EXPECT_DOUBLE_EQ(1.0, left);
2223 EXPECT_DOUBLE_EQ(1.0, right);
2224 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2225 EXPECT_DOUBLE_EQ(1.0, left);
2226 EXPECT_DOUBLE_EQ(1.0, right);
2227 // invalid ssrc.
2228 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2229
2230 // Set scale to (1.5, 0.5) for ssrc = 1.
2231 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2232 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2233 EXPECT_DOUBLE_EQ(1.5, left);
2234 EXPECT_DOUBLE_EQ(0.5, right);
2235 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2236 EXPECT_DOUBLE_EQ(1.0, left);
2237 EXPECT_DOUBLE_EQ(1.0, right);
2238 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2239 EXPECT_DOUBLE_EQ(1.0, left);
2240 EXPECT_DOUBLE_EQ(1.0, right);
2241
2242 // Set scale to (0, 0) for all ssrcs.
2243 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2244 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2245 EXPECT_DOUBLE_EQ(0.0, left);
2246 EXPECT_DOUBLE_EQ(0.0, right);
2247 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2248 EXPECT_DOUBLE_EQ(0.0, left);
2249 EXPECT_DOUBLE_EQ(0.0, right);
2250 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2251 EXPECT_DOUBLE_EQ(0.0, left);
2252 EXPECT_DOUBLE_EQ(0.0, right);
2253}
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
2654template<>
2655void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2656 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2657 data->AddLegacyStream(ssrc);
2658}
2659
2660TEST_F(DataChannelTest, TestInit) {
2661 Base::TestInit();
2662 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2663}
2664
2665TEST_F(DataChannelTest, TestSetContents) {
2666 Base::TestSetContents();
2667}
2668
2669TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2670 Base::TestSetContentsNullOffer();
2671}
2672
2673TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2674 Base::TestSetContentsRtcpMux();
2675}
2676
2677TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2678 Base::TestSetRemoteContentUpdate();
2679}
2680
2681TEST_F(DataChannelTest, TestStreams) {
2682 Base::TestStreams();
2683}
2684
2685TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2686 Base::TestUpdateStreamsInLocalContent();
2687}
2688
2689TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2690 Base::TestUpdateStreamsInRemoteContent();
2691}
2692
2693TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2694 Base::TestChangeStreamParamsInContent();
2695}
2696
2697TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2698 Base::TestPlayoutAndSendingStates();
2699}
2700
2701TEST_F(DataChannelTest, TestMediaContentDirection) {
2702 Base::TestMediaContentDirection();
2703}
2704
2705TEST_F(DataChannelTest, TestCallSetup) {
2706 Base::TestCallSetup();
2707}
2708
2709TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2710 Base::TestCallTeardownRtcpMux();
2711}
2712
2713TEST_F(DataChannelTest, TestOnReadyToSend) {
2714 Base::TestOnReadyToSend();
2715}
2716
2717TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2718 Base::TestOnReadyToSendWithRtcpMux();
2719}
2720
2721TEST_F(DataChannelTest, SendRtpToRtp) {
2722 Base::SendRtpToRtp();
2723}
2724
2725TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2726 Base::SendNoRtcpToNoRtcp();
2727}
2728
2729TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2730 Base::SendNoRtcpToRtcp();
2731}
2732
2733TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2734 Base::SendRtcpToNoRtcp();
2735}
2736
2737TEST_F(DataChannelTest, SendRtcpToRtcp) {
2738 Base::SendRtcpToRtcp();
2739}
2740
2741TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2742 Base::SendRtcpMuxToRtcp();
2743}
2744
2745TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2746 Base::SendRtcpMuxToRtcpMux();
2747}
2748
2749TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2750 Base::SendEarlyRtcpMuxToRtcp();
2751}
2752
2753TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2754 Base::SendEarlyRtcpMuxToRtcpMux();
2755}
2756
2757TEST_F(DataChannelTest, SendSrtpToSrtp) {
2758 Base::SendSrtpToSrtp();
2759}
2760
2761TEST_F(DataChannelTest, SendSrtpToRtp) {
2762 Base::SendSrtpToSrtp();
2763}
2764
2765TEST_F(DataChannelTest, SendSrtcpMux) {
2766 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2767}
2768
2769TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2770 Base::SendRtpToRtpOnThread();
2771}
2772
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002773TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2774 Base::SendSrtpToSrtpOnThread();
2775}
2776
2777TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2778 Base::SendWithWritabilityLoss();
2779}
2780
2781TEST_F(DataChannelTest, TestMediaMonitor) {
2782 Base::TestMediaMonitor();
2783}
2784
2785TEST_F(DataChannelTest, TestSendData) {
2786 CreateChannels(0, 0);
2787 EXPECT_TRUE(SendInitiate());
2788 EXPECT_TRUE(SendAccept());
2789
2790 cricket::SendDataParams params;
2791 params.ssrc = 42;
2792 unsigned char data[] = {
2793 'f', 'o', 'o'
2794 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002795 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002796 cricket::SendDataResult result;
2797 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2798 EXPECT_EQ(params.ssrc,
2799 media_channel1_->last_sent_data_params().ssrc);
2800 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2801}
2802
2803// TODO(pthatcher): TestSetReceiver?