blob: 4a82f551c32c303a4d6f30894c7271b0db6ee02c [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
2 * libjingle
3 * Copyright 2009 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028#include "talk/media/base/fakemediaengine.h"
29#include "talk/media/base/fakertp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000030#include "talk/media/base/fakescreencapturerfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/media/base/fakevideocapturer.h"
32#include "talk/media/base/mediachannel.h"
33#include "talk/media/base/rtpdump.h"
34#include "talk/media/base/screencastid.h"
35#include "talk/media/base/testutils.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000036#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/session/media/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/session/media/typingmonitor.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000039#include "webrtc/base/fileutils.h"
40#include "webrtc/base/gunit.h"
41#include "webrtc/base/helpers.h"
42#include "webrtc/base/logging.h"
43#include "webrtc/base/pathutils.h"
44#include "webrtc/base/signalthread.h"
45#include "webrtc/base/ssladapter.h"
46#include "webrtc/base/sslidentity.h"
47#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000048
49#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000050 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051 LOG(LS_INFO) << "Feature disabled... skipping"; \
52 return; \
53 }
54
55using cricket::CA_OFFER;
56using cricket::CA_PRANSWER;
57using cricket::CA_ANSWER;
58using cricket::CA_UPDATE;
59using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::ScreencastId;
61using cricket::StreamParams;
62using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000063using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064
65static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
67static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
68static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
69static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
70static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
71static const uint32 kSsrc1 = 0x1111;
72static const uint32 kSsrc2 = 0x2222;
73static const uint32 kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000074static const int kAudioPts[] = {0, 8};
75static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
77template<class ChannelT,
78 class MediaChannelT,
79 class ContentT,
80 class CodecT,
81 class MediaInfoT>
82class Traits {
83 public:
84 typedef ChannelT Channel;
85 typedef MediaChannelT MediaChannel;
86 typedef ContentT Content;
87 typedef CodecT Codec;
88 typedef MediaInfoT MediaInfo;
89};
90
henrike@webrtc.org28e20752013-07-10 00:45:36 +000091// Controls how long we wait for a session to send messages that we
92// expect, in milliseconds. We put it high to avoid flaky tests.
93static const int kEventTimeout = 5000;
94
95class VoiceTraits : public Traits<cricket::VoiceChannel,
96 cricket::FakeVoiceMediaChannel,
97 cricket::AudioContentDescription,
98 cricket::AudioCodec,
99 cricket::VoiceMediaInfo> {
100};
101
102class VideoTraits : public Traits<cricket::VideoChannel,
103 cricket::FakeVideoMediaChannel,
104 cricket::VideoContentDescription,
105 cricket::VideoCodec,
106 cricket::VideoMediaInfo> {
107};
108
109class DataTraits : public Traits<cricket::DataChannel,
110 cricket::FakeDataMediaChannel,
111 cricket::DataContentDescription,
112 cricket::DataCodec,
113 cricket::DataMediaInfo> {
114};
115
116
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
129 ChannelTest(const uint8* rtp_data, int rtp_len,
130 const uint8* rtcp_data, int rtcp_len)
131 : session1_(true),
132 session2_(false),
133 media_channel1_(NULL),
134 media_channel2_(NULL),
135 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
136 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
137 media_info_callbacks1_(),
138 media_info_callbacks2_(),
139 mute_callback_recved_(false),
140 mute_callback_value_(false),
141 ssrc_(0),
142 error_(T::MediaChannel::ERROR_NONE) {
143 }
144
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 void CreateChannels(int flags1, int flags2) {
146 CreateChannels(new typename T::MediaChannel(NULL),
147 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000148 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000149 }
150 void CreateChannels(int flags) {
151 CreateChannels(new typename T::MediaChannel(NULL),
152 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000153 flags, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000154 }
155 void CreateChannels(int flags1, int flags2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000156 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000157 CreateChannels(new typename T::MediaChannel(NULL),
158 new typename T::MediaChannel(NULL),
159 flags1, flags2, thread);
160 }
161 void CreateChannels(int flags,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000162 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163 CreateChannels(new typename T::MediaChannel(NULL),
164 new typename T::MediaChannel(NULL),
165 flags, thread);
166 }
167 void CreateChannels(
168 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000169 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 media_channel1_ = ch1;
171 media_channel2_ = ch2;
172 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
173 (flags1 & RTCP) != 0));
174 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
175 (flags2 & RTCP) != 0));
176 channel1_->SignalMediaMonitor.connect(
177 this, &ChannelTest<T>::OnMediaMonitor);
178 channel2_->SignalMediaMonitor.connect(
179 this, &ChannelTest<T>::OnMediaMonitor);
180 channel1_->SignalMediaError.connect(
181 this, &ChannelTest<T>::OnMediaChannelError);
182 channel2_->SignalMediaError.connect(
183 this, &ChannelTest<T>::OnMediaChannelError);
184 channel1_->SignalAutoMuted.connect(
185 this, &ChannelTest<T>::OnMediaMuted);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000186 if ((flags1 & DTLS) && (flags2 & DTLS)) {
187 flags1 = (flags1 & ~SECURE);
188 flags2 = (flags2 & ~SECURE);
189 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 CreateContent(flags1, kPcmuCodec, kH264Codec,
191 &local_media_content1_);
192 CreateContent(flags2, kPcmuCodec, kH264Codec,
193 &local_media_content2_);
194 CopyContent(local_media_content1_, &remote_media_content1_);
195 CopyContent(local_media_content2_, &remote_media_content2_);
196
197 if (flags1 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000198 identity1_.reset(rtc::SSLIdentity::Generate("session1"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 session1_.set_ssl_identity(identity1_.get());
200 }
201 if (flags2 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000202 identity2_.reset(rtc::SSLIdentity::Generate("session2"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000203 session2_.set_ssl_identity(identity2_.get());
204 }
205
206 // Add stream information (SSRC) to the local content but not to the remote
207 // content. This means that we per default know the SSRC of what we send but
208 // not what we receive.
209 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
210 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
211
212 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
213 if (flags1 & SSRC_MUX) {
214 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
215 }
216 if (flags2 & SSRC_MUX) {
217 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
218 }
219 }
220
221 void CreateChannels(
222 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000223 int flags, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000224 media_channel1_ = ch1;
225 media_channel2_ = ch2;
226
227 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
228 (flags & RTCP) != 0));
229 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
230 (flags & RTCP) != 0));
231 channel1_->SignalMediaMonitor.connect(
232 this, &ChannelTest<T>::OnMediaMonitor);
233 channel2_->SignalMediaMonitor.connect(
234 this, &ChannelTest<T>::OnMediaMonitor);
235 channel2_->SignalMediaError.connect(
236 this, &ChannelTest<T>::OnMediaChannelError);
237 CreateContent(flags, kPcmuCodec, kH264Codec,
238 &local_media_content1_);
239 CreateContent(flags, kPcmuCodec, kH264Codec,
240 &local_media_content2_);
241 CopyContent(local_media_content1_, &remote_media_content1_);
242 CopyContent(local_media_content2_, &remote_media_content2_);
243 // Add stream information (SSRC) to the local content but not to the remote
244 // content. This means that we per default know the SSRC of what we send but
245 // not what we receive.
246 AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
247 AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
248
249 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
250 if (flags & SSRC_MUX) {
251 AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
252 AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
253 }
254 }
255
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 typename T::Channel* CreateChannel(rtc::Thread* thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 cricket::MediaEngineInterface* engine,
258 typename T::MediaChannel* ch,
259 cricket::BaseSession* session,
260 bool rtcp) {
261 typename T::Channel* channel = new typename T::Channel(
262 thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
263 if (!channel->Init()) {
264 delete channel;
265 channel = NULL;
266 }
267 return channel;
268 }
269
270 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000271 bool result = channel1_->SetLocalContent(&local_media_content1_,
272 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 if (result) {
274 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000275 result = channel2_->SetRemoteContent(&remote_media_content1_,
276 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 if (result) {
278 session1_.Connect(&session2_);
279
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000280 result = channel2_->SetLocalContent(&local_media_content2_,
281 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 }
283 }
284 return result;
285 }
286
287 bool SendAccept() {
288 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000289 return channel1_->SetRemoteContent(&remote_media_content2_,
290 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000291 }
292
293 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000294 bool result = channel1_->SetLocalContent(&local_media_content1_,
295 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 if (result) {
297 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000298 result = channel2_->SetRemoteContent(&remote_media_content1_,
299 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 }
301 return result;
302 }
303
304 bool SendProvisionalAnswer() {
305 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000306 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 if (result) {
308 channel2_->Enable(true);
309 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000310 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 session1_.Connect(&session2_);
312 }
313 return result;
314 }
315
316 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000317 bool result = channel2_->SetLocalContent(&local_media_content2_,
318 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000320 result = channel1_->SetRemoteContent(&remote_media_content2_,
321 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 return result;
323 }
324
325 bool SendTerminate() {
326 channel1_.reset();
327 channel2_.reset();
328 return true;
329 }
330
331 bool AddStream1(int id) {
332 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
333 }
334 bool RemoveStream1(int id) {
335 return channel1_->RemoveRecvStream(id);
336 }
337
338 cricket::FakeTransport* GetTransport1() {
339 return session1_.GetTransport(channel1_->content_name());
340 }
341 cricket::FakeTransport* GetTransport2() {
342 return session2_.GetTransport(channel2_->content_name());
343 }
344
345 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000346 return media_channel1_->SendRtp(rtp_packet_.c_str(),
347 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 }
349 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000350 return media_channel2_->SendRtp(rtp_packet_.c_str(),
351 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 }
353 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000354 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
355 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
357 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000358 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
359 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 }
361 // Methods to send custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000362 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
363 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000364 return media_channel1_->SendRtp(data.c_str(),
365 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000367 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
368 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000369 return media_channel2_->SendRtp(data.c_str(),
370 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 }
372 bool SendCustomRtcp1(uint32 ssrc) {
373 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000374 return media_channel1_->SendRtcp(data.c_str(),
375 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000376 }
377 bool SendCustomRtcp2(uint32 ssrc) {
378 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000379 return media_channel2_->SendRtcp(data.c_str(),
380 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 }
382 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000383 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
384 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 }
386 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000387 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
388 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000389 }
390 bool CheckRtcp1() {
391 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000392 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000393 }
394 bool CheckRtcp2() {
395 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000396 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000397 }
398 // Methods to check custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000399 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
400 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000401 return media_channel1_->CheckRtp(data.c_str(),
402 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000404 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
405 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000406 return media_channel2_->CheckRtp(data.c_str(),
407 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 }
409 bool CheckCustomRtcp1(uint32 ssrc) {
410 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000411 return media_channel1_->CheckRtcp(data.c_str(),
412 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413 }
414 bool CheckCustomRtcp2(uint32 ssrc) {
415 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000416 return media_channel2_->CheckRtcp(data.c_str(),
417 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000418 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000419 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 std::string data(rtp_packet_);
421 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000422 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
423 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000424 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000425 rtc::Set8(const_cast<char*>(data.c_str()), 1,
426 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000427 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000428 return data;
429 }
430 std::string CreateRtcpData(uint32 ssrc) {
431 std::string data(rtcp_packet_);
432 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000433 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 return data;
435 }
436
437 bool CheckNoRtp1() {
438 return media_channel1_->CheckNoRtp();
439 }
440 bool CheckNoRtp2() {
441 return media_channel2_->CheckNoRtp();
442 }
443 bool CheckNoRtcp1() {
444 return media_channel1_->CheckNoRtcp();
445 }
446 bool CheckNoRtcp2() {
447 return media_channel2_->CheckNoRtcp();
448 }
449
450 void CreateContent(int flags,
451 const cricket::AudioCodec& audio_codec,
452 const cricket::VideoCodec& video_codec,
453 typename T::Content* content) {
454 // overridden in specialized classes
455 }
456 void CopyContent(const typename T::Content& source,
457 typename T::Content* content) {
458 // overridden in specialized classes
459 }
460
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 // Creates a cricket::SessionDescription with one MediaContent and one stream.
462 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
463 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
464 typename T::Content content;
465 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
466 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
467 AddLegacyStreamInContent(ssrc, 0, &content);
468 sdesc->AddContent("DUMMY_CONTENT_NAME",
469 cricket::NS_JINGLE_RTP, content.Copy());
470 return sdesc;
471 }
472
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000473 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000474 public:
475 typedef bool (ChannelTest<T>::*Method)();
476 CallThread(ChannelTest<T>* obj, Method method, bool* result)
477 : obj_(obj),
478 method_(method),
479 result_(result) {
480 *result = false;
481 }
482 virtual void DoWork() {
483 bool result = (*obj_.*method_)();
484 if (result_) {
485 *result_ = result;
486 }
487 }
488 private:
489 ChannelTest<T>* obj_;
490 Method method_;
491 bool* result_;
492 };
493 void CallOnThread(typename CallThread::Method method, bool* result) {
494 CallThread* thread = new CallThread(this, method, result);
495 thread->Start();
496 thread->Release();
497 }
498
499 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
500 bool* result) {
501 CallThread* thread = new CallThread(this, method, result);
502 thread->Start();
503 thread->Destroy(true);
504 }
505
506 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
507 return false; // overridden in specialized classes
508 }
509
510 void OnMediaMonitor(typename T::Channel* channel,
511 const typename T::MediaInfo& info) {
512 if (channel == channel1_.get()) {
513 media_info_callbacks1_++;
514 } else if (channel == channel2_.get()) {
515 media_info_callbacks2_++;
516 }
517 }
518
519 void OnMediaChannelError(typename T::Channel* channel,
520 uint32 ssrc,
521 typename T::MediaChannel::Error error) {
522 ssrc_ = ssrc;
523 error_ = error;
524 }
525
526 void OnMediaMuted(cricket::BaseChannel* channel, bool muted) {
527 mute_callback_recved_ = true;
528 mute_callback_value_ = muted;
529 }
530
531 void AddLegacyStreamInContent(uint32 ssrc, int flags,
532 typename T::Content* content) {
533 // Base implementation.
534 }
535
536 // Tests that can be used by derived classes.
537
538 // Basic sanity check.
539 void TestInit() {
540 CreateChannels(0, 0);
541 EXPECT_FALSE(channel1_->secure());
542 EXPECT_FALSE(media_channel1_->sending());
543 EXPECT_FALSE(media_channel1_->playout());
544 EXPECT_TRUE(media_channel1_->codecs().empty());
545 EXPECT_TRUE(media_channel1_->recv_streams().empty());
546 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
547 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
548 }
549
550 // Test that SetLocalContent and SetRemoteContent properly configure
551 // the codecs.
552 void TestSetContents() {
553 CreateChannels(0, 0);
554 typename T::Content content;
555 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000556 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000558 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 ASSERT_EQ(1U, media_channel1_->codecs().size());
560 EXPECT_TRUE(CodecMatches(content.codecs()[0],
561 media_channel1_->codecs()[0]));
562 }
563
564 // Test that SetLocalContent and SetRemoteContent properly deals
565 // with an empty offer.
566 void TestSetContentsNullOffer() {
567 CreateChannels(0, 0);
568 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000569 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000570 CreateContent(0, kPcmuCodec, kH264Codec, &content);
571 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000572 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000573 ASSERT_EQ(1U, media_channel1_->codecs().size());
574 EXPECT_TRUE(CodecMatches(content.codecs()[0],
575 media_channel1_->codecs()[0]));
576 }
577
578 // Test that SetLocalContent and SetRemoteContent properly set RTCP
579 // mux.
580 void TestSetContentsRtcpMux() {
581 CreateChannels(RTCP, RTCP);
582 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
583 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
584 typename T::Content content;
585 CreateContent(0, kPcmuCodec, kH264Codec, &content);
586 // Both sides agree on mux. Should no longer be a separate RTCP channel.
587 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000588 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
589 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000590 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
591 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000592 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000594 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
596 }
597
598 // Test that SetLocalContent and SetRemoteContent properly set RTCP
599 // mux when a provisional answer is received.
600 void TestSetContentsRtcpMuxWithPrAnswer() {
601 CreateChannels(RTCP, RTCP);
602 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
603 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
604 typename T::Content content;
605 CreateContent(0, kPcmuCodec, kH264Codec, &content);
606 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000607 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
608 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000610 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 // Both sides agree on mux. Should no longer be a separate RTCP channel.
612 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
613 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000614 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000615 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000616 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
617 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
619 }
620
621 // Test that SetLocalContent and SetRemoteContent properly set
622 // video options to the media channel.
623 void TestSetContentsVideoOptions() {
624 CreateChannels(0, 0);
625 typename T::Content content;
626 CreateContent(0, kPcmuCodec, kH264Codec, &content);
627 content.set_buffered_mode_latency(101);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000628 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 EXPECT_EQ(0U, media_channel1_->codecs().size());
630 cricket::VideoOptions options;
631 ASSERT_TRUE(media_channel1_->GetOptions(&options));
632 int latency = 0;
633 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
634 EXPECT_EQ(101, latency);
635 content.set_buffered_mode_latency(102);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000636 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000637 ASSERT_EQ(1U, media_channel1_->codecs().size());
638 EXPECT_TRUE(CodecMatches(content.codecs()[0],
639 media_channel1_->codecs()[0]));
640 ASSERT_TRUE(media_channel1_->GetOptions(&options));
641 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
642 EXPECT_EQ(102, latency);
643 }
644
645 // Test that SetRemoteContent properly deals with a content update.
646 void TestSetRemoteContentUpdate() {
647 CreateChannels(0, 0);
648 typename T::Content content;
649 CreateContent(RTCP | RTCP_MUX | SECURE,
650 kPcmuCodec, kH264Codec,
651 &content);
652 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000653 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
654 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 ASSERT_EQ(1U, media_channel1_->codecs().size());
656 EXPECT_TRUE(CodecMatches(content.codecs()[0],
657 media_channel1_->codecs()[0]));
658 // Now update with other codecs.
659 typename T::Content update_content;
660 update_content.set_partial(true);
661 CreateContent(0, kIsacCodec, kH264SvcCodec,
662 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000663 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 ASSERT_EQ(1U, media_channel1_->codecs().size());
665 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
666 media_channel1_->codecs()[0]));
667 // Now update without any codecs. This is ignored.
668 typename T::Content empty_content;
669 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000670 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 ASSERT_EQ(1U, media_channel1_->codecs().size());
672 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
673 media_channel1_->codecs()[0]));
674 }
675
676 // Test that Add/RemoveStream properly forward to the media channel.
677 void TestStreams() {
678 CreateChannels(0, 0);
679 EXPECT_TRUE(AddStream1(1));
680 EXPECT_TRUE(AddStream1(2));
681 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
682 EXPECT_TRUE(RemoveStream1(2));
683 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
684 EXPECT_TRUE(RemoveStream1(1));
685 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
686 }
687
688 // Test that SetLocalContent properly handles adding and removing StreamParams
689 // to the local content description.
690 // This test uses the CA_UPDATE action that don't require a full
691 // MediaContentDescription to do an update.
692 void TestUpdateStreamsInLocalContent() {
693 cricket::StreamParams stream1;
694 stream1.groupid = "group1";
695 stream1.id = "stream1";
696 stream1.ssrcs.push_back(kSsrc1);
697 stream1.cname = "stream1_cname";
698
699 cricket::StreamParams stream2;
700 stream2.groupid = "group2";
701 stream2.id = "stream2";
702 stream2.ssrcs.push_back(kSsrc2);
703 stream2.cname = "stream2_cname";
704
705 cricket::StreamParams stream3;
706 stream3.groupid = "group3";
707 stream3.id = "stream3";
708 stream3.ssrcs.push_back(kSsrc3);
709 stream3.cname = "stream3_cname";
710
711 CreateChannels(0, 0);
712 typename T::Content content1;
713 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
714 content1.AddStream(stream1);
715 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000716 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717
718 ASSERT_EQ(1u, media_channel1_->send_streams().size());
719 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
720
721 // Update the local streams by adding another sending stream.
722 // Use a partial updated session description.
723 typename T::Content content2;
724 content2.AddStream(stream2);
725 content2.AddStream(stream3);
726 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000727 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 ASSERT_EQ(3u, media_channel1_->send_streams().size());
729 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
730 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
731 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
732
733 // Update the local streams by removing the first sending stream.
734 // This is done by removing all SSRCS for this particular stream.
735 typename T::Content content3;
736 stream1.ssrcs.clear();
737 content3.AddStream(stream1);
738 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000739 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 ASSERT_EQ(2u, media_channel1_->send_streams().size());
741 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
742 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
743
744 // Update the local streams with a stream that does not change.
745 // THe update is ignored.
746 typename T::Content content4;
747 content4.AddStream(stream2);
748 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000749 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 ASSERT_EQ(2u, media_channel1_->send_streams().size());
751 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
752 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
753 }
754
755 // Test that SetRemoteContent properly handles adding and removing
756 // StreamParams to the remote content description.
757 // This test uses the CA_UPDATE action that don't require a full
758 // MediaContentDescription to do an update.
759 void TestUpdateStreamsInRemoteContent() {
760 cricket::StreamParams stream1;
761 stream1.id = "Stream1";
762 stream1.groupid = "1";
763 stream1.ssrcs.push_back(kSsrc1);
764 stream1.cname = "stream1_cname";
765
766 cricket::StreamParams stream2;
767 stream2.id = "Stream2";
768 stream2.groupid = "2";
769 stream2.ssrcs.push_back(kSsrc2);
770 stream2.cname = "stream2_cname";
771
772 cricket::StreamParams stream3;
773 stream3.id = "Stream3";
774 stream3.groupid = "3";
775 stream3.ssrcs.push_back(kSsrc3);
776 stream3.cname = "stream3_cname";
777
778 CreateChannels(0, 0);
779 typename T::Content content1;
780 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
781 content1.AddStream(stream1);
782 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000783 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784
785 ASSERT_EQ(1u, media_channel1_->codecs().size());
786 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
787 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
788
789 // Update the remote streams by adding another sending stream.
790 // Use a partial updated session description.
791 typename T::Content content2;
792 content2.AddStream(stream2);
793 content2.AddStream(stream3);
794 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000795 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
797 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
798 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
799 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
800
801 // Update the remote streams by removing the first stream.
802 // This is done by removing all SSRCS for this particular stream.
803 typename T::Content content3;
804 stream1.ssrcs.clear();
805 content3.AddStream(stream1);
806 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000807 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
809 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
810 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
811
812 // Update the remote streams with a stream that does not change.
813 // The update is ignored.
814 typename T::Content content4;
815 content4.AddStream(stream2);
816 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000817 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
819 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
820 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
821 }
822
823 // Test that SetLocalContent and SetRemoteContent properly
824 // handles adding and removing StreamParams when the action is a full
825 // CA_OFFER / CA_ANSWER.
826 void TestChangeStreamParamsInContent() {
827 cricket::StreamParams stream1;
828 stream1.groupid = "group1";
829 stream1.id = "stream1";
830 stream1.ssrcs.push_back(kSsrc1);
831 stream1.cname = "stream1_cname";
832
833 cricket::StreamParams stream2;
834 stream2.groupid = "group1";
835 stream2.id = "stream2";
836 stream2.ssrcs.push_back(kSsrc2);
837 stream2.cname = "stream2_cname";
838
839 // Setup a call where channel 1 send |stream1| to channel 2.
840 CreateChannels(0, 0);
841 typename T::Content content1;
842 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
843 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000844 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 EXPECT_TRUE(channel1_->Enable(true));
846 EXPECT_EQ(1u, media_channel1_->send_streams().size());
847
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000848 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000849 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
850 session1_.Connect(&session2_);
851
852 // Channel 2 do not send anything.
853 typename T::Content content2;
854 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000855 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000857 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 EXPECT_TRUE(channel2_->Enable(true));
859 EXPECT_EQ(0u, media_channel2_->send_streams().size());
860
861 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
862 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
863
864 // Let channel 2 update the content by sending |stream2| and enable SRTP.
865 typename T::Content content3;
866 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
867 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000868 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 ASSERT_EQ(1u, media_channel2_->send_streams().size());
870 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
871
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000872 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000873 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
874 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
875
876 // Channel 1 replies but stop sending stream1.
877 typename T::Content content4;
878 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000879 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 EXPECT_EQ(0u, media_channel1_->send_streams().size());
881
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000882 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
884
885 EXPECT_TRUE(channel1_->secure());
886 EXPECT_TRUE(channel2_->secure());
887 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
888 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
889 }
890
891 // Test that we only start playout and sending at the right times.
892 void TestPlayoutAndSendingStates() {
893 CreateChannels(0, 0);
894 EXPECT_FALSE(media_channel1_->playout());
895 EXPECT_FALSE(media_channel1_->sending());
896 EXPECT_FALSE(media_channel2_->playout());
897 EXPECT_FALSE(media_channel2_->sending());
898 EXPECT_TRUE(channel1_->Enable(true));
899 EXPECT_FALSE(media_channel1_->playout());
900 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000901 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
902 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 EXPECT_TRUE(media_channel1_->playout());
904 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000905 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
906 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 EXPECT_FALSE(media_channel2_->playout());
908 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000909 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
910 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000911 EXPECT_FALSE(media_channel2_->playout());
912 EXPECT_FALSE(media_channel2_->sending());
913 session1_.Connect(&session2_);
914 EXPECT_TRUE(media_channel1_->playout());
915 EXPECT_FALSE(media_channel1_->sending());
916 EXPECT_FALSE(media_channel2_->playout());
917 EXPECT_FALSE(media_channel2_->sending());
918 EXPECT_TRUE(channel2_->Enable(true));
919 EXPECT_TRUE(media_channel2_->playout());
920 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000921 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
922 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 EXPECT_TRUE(media_channel1_->playout());
924 EXPECT_TRUE(media_channel1_->sending());
925 }
926
927 void TestMuteStream() {
928 CreateChannels(0, 0);
929 // Test that we can Mute the default channel even though the sending SSRC is
930 // unknown.
931 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
932 EXPECT_TRUE(channel1_->MuteStream(0, true));
933 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
934 EXPECT_TRUE(channel1_->MuteStream(0, false));
935 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
936
937 // Test that we can not mute an unknown SSRC.
938 EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true));
939
940 SendInitiate();
941 // After the local session description has been set, we can mute a stream
942 // with its SSRC.
943 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true));
944 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
945 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false));
946 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
947 }
948
949 // Test that changing the MediaContentDirection in the local and remote
950 // session description start playout and sending at the right time.
951 void TestMediaContentDirection() {
952 CreateChannels(0, 0);
953 typename T::Content content1;
954 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
955 typename T::Content content2;
956 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
957 // Set |content2| to be InActive.
958 content2.set_direction(cricket::MD_INACTIVE);
959
960 EXPECT_TRUE(channel1_->Enable(true));
961 EXPECT_TRUE(channel2_->Enable(true));
962 EXPECT_FALSE(media_channel1_->playout());
963 EXPECT_FALSE(media_channel1_->sending());
964 EXPECT_FALSE(media_channel2_->playout());
965 EXPECT_FALSE(media_channel2_->sending());
966
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000967 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
968 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
969 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
970 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 session1_.Connect(&session2_);
972
973 EXPECT_TRUE(media_channel1_->playout());
974 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
975 EXPECT_FALSE(media_channel2_->playout()); // local InActive
976 EXPECT_FALSE(media_channel2_->sending()); // local InActive
977
978 // Update |content2| to be RecvOnly.
979 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000980 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
981 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982
983 EXPECT_TRUE(media_channel1_->playout());
984 EXPECT_TRUE(media_channel1_->sending());
985 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
986 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
987
988 // Update |content2| to be SendRecv.
989 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000990 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
991 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992
993 EXPECT_TRUE(media_channel1_->playout());
994 EXPECT_TRUE(media_channel1_->sending());
995 EXPECT_TRUE(media_channel2_->playout());
996 EXPECT_TRUE(media_channel2_->sending());
997 }
998
999 // Test setting up a call.
1000 void TestCallSetup() {
1001 CreateChannels(0, 0);
1002 EXPECT_FALSE(channel1_->secure());
1003 EXPECT_TRUE(SendInitiate());
1004 EXPECT_TRUE(media_channel1_->playout());
1005 EXPECT_FALSE(media_channel1_->sending());
1006 EXPECT_TRUE(SendAccept());
1007 EXPECT_FALSE(channel1_->secure());
1008 EXPECT_TRUE(media_channel1_->sending());
1009 EXPECT_EQ(1U, media_channel1_->codecs().size());
1010 EXPECT_TRUE(media_channel2_->playout());
1011 EXPECT_TRUE(media_channel2_->sending());
1012 EXPECT_EQ(1U, media_channel2_->codecs().size());
1013 }
1014
1015 // Test that we don't crash if packets are sent during call teardown
1016 // when RTCP mux is enabled. This is a regression test against a specific
1017 // race condition that would only occur when a RTCP packet was sent during
1018 // teardown of a channel on which RTCP mux was enabled.
1019 void TestCallTeardownRtcpMux() {
1020 class LastWordMediaChannel : public T::MediaChannel {
1021 public:
1022 LastWordMediaChannel() : T::MediaChannel(NULL) {}
1023 ~LastWordMediaChannel() {
1024 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
1025 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1026 }
1027 };
1028 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1029 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001030 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 EXPECT_TRUE(SendInitiate());
1032 EXPECT_TRUE(SendAccept());
1033 EXPECT_TRUE(SendTerminate());
1034 }
1035
1036 // Send voice RTP data to the other side and ensure it gets there.
1037 void SendRtpToRtp() {
1038 CreateChannels(0, 0);
1039 EXPECT_TRUE(SendInitiate());
1040 EXPECT_TRUE(SendAccept());
1041 EXPECT_EQ(1U, GetTransport1()->channels().size());
1042 EXPECT_EQ(1U, GetTransport2()->channels().size());
1043 EXPECT_TRUE(SendRtp1());
1044 EXPECT_TRUE(SendRtp2());
1045 EXPECT_TRUE(CheckRtp1());
1046 EXPECT_TRUE(CheckRtp2());
1047 EXPECT_TRUE(CheckNoRtp1());
1048 EXPECT_TRUE(CheckNoRtp2());
1049 }
1050
1051 // Check that RTCP is not transmitted if both sides don't support RTCP.
1052 void SendNoRtcpToNoRtcp() {
1053 CreateChannels(0, 0);
1054 EXPECT_TRUE(SendInitiate());
1055 EXPECT_TRUE(SendAccept());
1056 EXPECT_EQ(1U, GetTransport1()->channels().size());
1057 EXPECT_EQ(1U, GetTransport2()->channels().size());
1058 EXPECT_FALSE(SendRtcp1());
1059 EXPECT_FALSE(SendRtcp2());
1060 EXPECT_TRUE(CheckNoRtcp1());
1061 EXPECT_TRUE(CheckNoRtcp2());
1062 }
1063
1064 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1065 void SendNoRtcpToRtcp() {
1066 CreateChannels(0, RTCP);
1067 EXPECT_TRUE(SendInitiate());
1068 EXPECT_TRUE(SendAccept());
1069 EXPECT_EQ(1U, GetTransport1()->channels().size());
1070 EXPECT_EQ(2U, GetTransport2()->channels().size());
1071 EXPECT_FALSE(SendRtcp1());
1072 EXPECT_FALSE(SendRtcp2());
1073 EXPECT_TRUE(CheckNoRtcp1());
1074 EXPECT_TRUE(CheckNoRtcp2());
1075 }
1076
1077 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1078 void SendRtcpToNoRtcp() {
1079 CreateChannels(RTCP, 0);
1080 EXPECT_TRUE(SendInitiate());
1081 EXPECT_TRUE(SendAccept());
1082 EXPECT_EQ(2U, GetTransport1()->channels().size());
1083 EXPECT_EQ(1U, GetTransport2()->channels().size());
1084 EXPECT_FALSE(SendRtcp1());
1085 EXPECT_FALSE(SendRtcp2());
1086 EXPECT_TRUE(CheckNoRtcp1());
1087 EXPECT_TRUE(CheckNoRtcp2());
1088 }
1089
1090 // Check that RTCP is transmitted if both sides support RTCP.
1091 void SendRtcpToRtcp() {
1092 CreateChannels(RTCP, RTCP);
1093 EXPECT_TRUE(SendInitiate());
1094 EXPECT_TRUE(SendAccept());
1095 EXPECT_EQ(2U, GetTransport1()->channels().size());
1096 EXPECT_EQ(2U, GetTransport2()->channels().size());
1097 EXPECT_TRUE(SendRtcp1());
1098 EXPECT_TRUE(SendRtcp2());
1099 EXPECT_TRUE(CheckRtcp1());
1100 EXPECT_TRUE(CheckRtcp2());
1101 EXPECT_TRUE(CheckNoRtcp1());
1102 EXPECT_TRUE(CheckNoRtcp2());
1103 }
1104
1105 // Check that RTCP is transmitted if only the initiator supports mux.
1106 void SendRtcpMuxToRtcp() {
1107 CreateChannels(RTCP | RTCP_MUX, RTCP);
1108 EXPECT_TRUE(SendInitiate());
1109 EXPECT_TRUE(SendAccept());
1110 EXPECT_EQ(2U, GetTransport1()->channels().size());
1111 EXPECT_EQ(2U, GetTransport2()->channels().size());
1112 EXPECT_TRUE(SendRtcp1());
1113 EXPECT_TRUE(SendRtcp2());
1114 EXPECT_TRUE(CheckRtcp1());
1115 EXPECT_TRUE(CheckRtcp2());
1116 EXPECT_TRUE(CheckNoRtcp1());
1117 EXPECT_TRUE(CheckNoRtcp2());
1118 }
1119
1120 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1121 void SendRtcpMuxToRtcpMux() {
1122 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1123 EXPECT_TRUE(SendInitiate());
1124 EXPECT_EQ(2U, GetTransport1()->channels().size());
1125 EXPECT_EQ(1U, GetTransport2()->channels().size());
1126 EXPECT_TRUE(SendAccept());
1127 EXPECT_EQ(1U, GetTransport1()->channels().size());
1128 EXPECT_TRUE(SendRtp1());
1129 EXPECT_TRUE(SendRtp2());
1130 EXPECT_TRUE(SendRtcp1());
1131 EXPECT_TRUE(SendRtcp2());
1132 EXPECT_TRUE(CheckRtp1());
1133 EXPECT_TRUE(CheckRtp2());
1134 EXPECT_TRUE(CheckNoRtp1());
1135 EXPECT_TRUE(CheckNoRtp2());
1136 EXPECT_TRUE(CheckRtcp1());
1137 EXPECT_TRUE(CheckRtcp2());
1138 EXPECT_TRUE(CheckNoRtcp1());
1139 EXPECT_TRUE(CheckNoRtcp2());
1140 }
1141
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001142 // Check that RTP and RTCP are transmitted ok when both sides
1143 // support mux and one the offerer requires mux.
1144 void SendRequireRtcpMuxToRtcpMux() {
1145 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1146 channel1_->ActivateRtcpMux();
1147 EXPECT_TRUE(SendInitiate());
1148 EXPECT_EQ(1U, GetTransport1()->channels().size());
1149 EXPECT_EQ(1U, GetTransport2()->channels().size());
1150 EXPECT_TRUE(SendAccept());
1151 EXPECT_TRUE(SendRtp1());
1152 EXPECT_TRUE(SendRtp2());
1153 EXPECT_TRUE(SendRtcp1());
1154 EXPECT_TRUE(SendRtcp2());
1155 EXPECT_TRUE(CheckRtp1());
1156 EXPECT_TRUE(CheckRtp2());
1157 EXPECT_TRUE(CheckNoRtp1());
1158 EXPECT_TRUE(CheckNoRtp2());
1159 EXPECT_TRUE(CheckRtcp1());
1160 EXPECT_TRUE(CheckRtcp2());
1161 EXPECT_TRUE(CheckNoRtcp1());
1162 EXPECT_TRUE(CheckNoRtcp2());
1163 }
1164
1165 // Check that RTP and RTCP are transmitted ok when both sides
1166 // support mux and one the answerer requires rtcp mux.
1167 void SendRtcpMuxToRequireRtcpMux() {
1168 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1169 channel2_->ActivateRtcpMux();
1170 EXPECT_TRUE(SendInitiate());
1171 EXPECT_EQ(2U, GetTransport1()->channels().size());
1172 EXPECT_EQ(1U, GetTransport2()->channels().size());
1173 EXPECT_TRUE(SendAccept());
1174 EXPECT_EQ(1U, GetTransport1()->channels().size());
1175 EXPECT_TRUE(SendRtp1());
1176 EXPECT_TRUE(SendRtp2());
1177 EXPECT_TRUE(SendRtcp1());
1178 EXPECT_TRUE(SendRtcp2());
1179 EXPECT_TRUE(CheckRtp1());
1180 EXPECT_TRUE(CheckRtp2());
1181 EXPECT_TRUE(CheckNoRtp1());
1182 EXPECT_TRUE(CheckNoRtp2());
1183 EXPECT_TRUE(CheckRtcp1());
1184 EXPECT_TRUE(CheckRtcp2());
1185 EXPECT_TRUE(CheckNoRtcp1());
1186 EXPECT_TRUE(CheckNoRtcp2());
1187 }
1188
1189 // Check that RTP and RTCP are transmitted ok when both sides
1190 // require mux.
1191 void SendRequireRtcpMuxToRequireRtcpMux() {
1192 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1193 channel1_->ActivateRtcpMux();
1194 channel2_->ActivateRtcpMux();
1195 EXPECT_TRUE(SendInitiate());
1196 EXPECT_EQ(1U, GetTransport1()->channels().size());
1197 EXPECT_EQ(1U, GetTransport2()->channels().size());
1198 EXPECT_TRUE(SendAccept());
1199 EXPECT_EQ(1U, GetTransport1()->channels().size());
1200 EXPECT_TRUE(SendRtp1());
1201 EXPECT_TRUE(SendRtp2());
1202 EXPECT_TRUE(SendRtcp1());
1203 EXPECT_TRUE(SendRtcp2());
1204 EXPECT_TRUE(CheckRtp1());
1205 EXPECT_TRUE(CheckRtp2());
1206 EXPECT_TRUE(CheckNoRtp1());
1207 EXPECT_TRUE(CheckNoRtp2());
1208 EXPECT_TRUE(CheckRtcp1());
1209 EXPECT_TRUE(CheckRtcp2());
1210 EXPECT_TRUE(CheckNoRtcp1());
1211 EXPECT_TRUE(CheckNoRtcp2());
1212 }
1213
1214 // Check that SendAccept fails if the answerer doesn't support mux
1215 // and the offerer requires it.
1216 void SendRequireRtcpMuxToNoRtcpMux() {
1217 CreateChannels(RTCP | RTCP_MUX, RTCP);
1218 channel1_->ActivateRtcpMux();
1219 EXPECT_TRUE(SendInitiate());
1220 EXPECT_EQ(1U, GetTransport1()->channels().size());
1221 EXPECT_EQ(2U, GetTransport2()->channels().size());
1222 EXPECT_FALSE(SendAccept());
1223 }
1224
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 // Check that RTCP data sent by the initiator before the accept is not muxed.
1226 void SendEarlyRtcpMuxToRtcp() {
1227 CreateChannels(RTCP | RTCP_MUX, RTCP);
1228 EXPECT_TRUE(SendInitiate());
1229 EXPECT_EQ(2U, GetTransport1()->channels().size());
1230 EXPECT_EQ(2U, GetTransport2()->channels().size());
1231
1232 // RTCP can be sent before the call is accepted, if the transport is ready.
1233 // It should not be muxed though, as the remote side doesn't support mux.
1234 EXPECT_TRUE(SendRtcp1());
1235 EXPECT_TRUE(CheckNoRtp2());
1236 EXPECT_TRUE(CheckRtcp2());
1237
1238 // Send RTCP packet from callee and verify that it is received.
1239 EXPECT_TRUE(SendRtcp2());
1240 EXPECT_TRUE(CheckNoRtp1());
1241 EXPECT_TRUE(CheckRtcp1());
1242
1243 // Complete call setup and ensure everything is still OK.
1244 EXPECT_TRUE(SendAccept());
1245 EXPECT_EQ(2U, GetTransport1()->channels().size());
1246 EXPECT_TRUE(SendRtcp1());
1247 EXPECT_TRUE(CheckRtcp2());
1248 EXPECT_TRUE(SendRtcp2());
1249 EXPECT_TRUE(CheckRtcp1());
1250 }
1251
1252
1253 // Check that RTCP data is not muxed until both sides have enabled muxing,
1254 // but that we properly demux before we get the accept message, since there
1255 // is a race between RTP data and the jingle accept.
1256 void SendEarlyRtcpMuxToRtcpMux() {
1257 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1258 EXPECT_TRUE(SendInitiate());
1259 EXPECT_EQ(2U, GetTransport1()->channels().size());
1260 EXPECT_EQ(1U, GetTransport2()->channels().size());
1261
1262 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1263 // we haven't yet received the accept that says we should mux.
1264 EXPECT_FALSE(SendRtcp1());
1265
1266 // Send muxed RTCP packet from callee and verify that it is received.
1267 EXPECT_TRUE(SendRtcp2());
1268 EXPECT_TRUE(CheckNoRtp1());
1269 EXPECT_TRUE(CheckRtcp1());
1270
1271 // Complete call setup and ensure everything is still OK.
1272 EXPECT_TRUE(SendAccept());
1273 EXPECT_EQ(1U, GetTransport1()->channels().size());
1274 EXPECT_TRUE(SendRtcp1());
1275 EXPECT_TRUE(CheckRtcp2());
1276 EXPECT_TRUE(SendRtcp2());
1277 EXPECT_TRUE(CheckRtcp1());
1278 }
1279
1280 // Test that we properly send SRTP with RTCP in both directions.
1281 // You can pass in DTLS and/or RTCP_MUX as flags.
1282 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1283 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1284 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1285
1286 int flags1 = RTCP | SECURE | flags1_in;
1287 int flags2 = RTCP | SECURE | flags2_in;
1288 bool dtls1 = !!(flags1_in & DTLS);
1289 bool dtls2 = !!(flags2_in & DTLS);
1290 CreateChannels(flags1, flags2);
1291 EXPECT_FALSE(channel1_->secure());
1292 EXPECT_FALSE(channel2_->secure());
1293 EXPECT_TRUE(SendInitiate());
1294 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1295 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1296 EXPECT_TRUE(SendAccept());
1297 EXPECT_TRUE(channel1_->secure());
1298 EXPECT_TRUE(channel2_->secure());
1299 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1300 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1301 EXPECT_TRUE(SendRtp1());
1302 EXPECT_TRUE(SendRtp2());
1303 EXPECT_TRUE(SendRtcp1());
1304 EXPECT_TRUE(SendRtcp2());
1305 EXPECT_TRUE(CheckRtp1());
1306 EXPECT_TRUE(CheckRtp2());
1307 EXPECT_TRUE(CheckNoRtp1());
1308 EXPECT_TRUE(CheckNoRtp2());
1309 EXPECT_TRUE(CheckRtcp1());
1310 EXPECT_TRUE(CheckRtcp2());
1311 EXPECT_TRUE(CheckNoRtcp1());
1312 EXPECT_TRUE(CheckNoRtcp2());
1313 }
1314
1315 // Test that we properly handling SRTP negotiating down to RTP.
1316 void SendSrtpToRtp() {
1317 CreateChannels(RTCP | SECURE, RTCP);
1318 EXPECT_FALSE(channel1_->secure());
1319 EXPECT_FALSE(channel2_->secure());
1320 EXPECT_TRUE(SendInitiate());
1321 EXPECT_TRUE(SendAccept());
1322 EXPECT_FALSE(channel1_->secure());
1323 EXPECT_FALSE(channel2_->secure());
1324 EXPECT_TRUE(SendRtp1());
1325 EXPECT_TRUE(SendRtp2());
1326 EXPECT_TRUE(SendRtcp1());
1327 EXPECT_TRUE(SendRtcp2());
1328 EXPECT_TRUE(CheckRtp1());
1329 EXPECT_TRUE(CheckRtp2());
1330 EXPECT_TRUE(CheckNoRtp1());
1331 EXPECT_TRUE(CheckNoRtp2());
1332 EXPECT_TRUE(CheckRtcp1());
1333 EXPECT_TRUE(CheckRtcp2());
1334 EXPECT_TRUE(CheckNoRtcp1());
1335 EXPECT_TRUE(CheckNoRtcp2());
1336 }
1337
1338 // Test that we can send and receive early media when a provisional answer is
1339 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1340 void SendEarlyMediaUsingRtcpMuxSrtp() {
1341 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1342
1343 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1344 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1345 EXPECT_TRUE(SendOffer());
1346 EXPECT_TRUE(SendProvisionalAnswer());
1347 EXPECT_TRUE(channel1_->secure());
1348 EXPECT_TRUE(channel2_->secure());
1349 EXPECT_EQ(2U, GetTransport1()->channels().size());
1350 EXPECT_EQ(2U, GetTransport2()->channels().size());
1351 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1352 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1353 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1354 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1355
1356 // Send packets from callee and verify that it is received.
1357 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1358 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1359 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1360 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1361
1362 // Complete call setup and ensure everything is still OK.
1363 EXPECT_TRUE(SendFinalAnswer());
1364 EXPECT_EQ(1U, GetTransport1()->channels().size());
1365 EXPECT_EQ(1U, GetTransport2()->channels().size());
1366 EXPECT_TRUE(channel1_->secure());
1367 EXPECT_TRUE(channel2_->secure());
1368 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1369 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1370 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1371 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1372 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1373 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1374 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1375 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1376 }
1377
1378 // Test that we properly send RTP without SRTP from a thread.
1379 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001380 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1381 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382 EXPECT_TRUE(SendInitiate());
1383 EXPECT_TRUE(SendAccept());
1384 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1385 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001386 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1387 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1389 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1390 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1391 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1392 EXPECT_TRUE(CheckNoRtp1());
1393 EXPECT_TRUE(CheckNoRtp2());
1394 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1395 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1396 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1397 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1398 EXPECT_TRUE(CheckNoRtcp1());
1399 EXPECT_TRUE(CheckNoRtcp2());
1400 }
1401
1402 // Test that we properly send SRTP with RTCP from a thread.
1403 void SendSrtpToSrtpOnThread() {
1404 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1405 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1406 EXPECT_TRUE(SendInitiate());
1407 EXPECT_TRUE(SendAccept());
1408 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1409 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1410 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1411 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1412 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1413 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1414 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1415 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1416 EXPECT_TRUE(CheckNoRtp1());
1417 EXPECT_TRUE(CheckNoRtp2());
1418 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1419 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1420 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1421 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1422 EXPECT_TRUE(CheckNoRtcp1());
1423 EXPECT_TRUE(CheckNoRtcp2());
1424 }
1425
1426 // Test that the mediachannel retains its sending state after the transport
1427 // becomes non-writable.
1428 void SendWithWritabilityLoss() {
1429 CreateChannels(0, 0);
1430 EXPECT_TRUE(SendInitiate());
1431 EXPECT_TRUE(SendAccept());
1432 EXPECT_EQ(1U, GetTransport1()->channels().size());
1433 EXPECT_EQ(1U, GetTransport2()->channels().size());
1434 EXPECT_TRUE(SendRtp1());
1435 EXPECT_TRUE(SendRtp2());
1436 EXPECT_TRUE(CheckRtp1());
1437 EXPECT_TRUE(CheckRtp2());
1438 EXPECT_TRUE(CheckNoRtp1());
1439 EXPECT_TRUE(CheckNoRtp2());
1440
wu@webrtc.org97077a32013-10-25 21:18:33 +00001441 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 EXPECT_FALSE(SendRtp1());
1444 EXPECT_TRUE(SendRtp2());
1445 EXPECT_TRUE(CheckRtp1());
1446 EXPECT_TRUE(CheckNoRtp2());
1447
1448 // Regain writability
1449 GetTransport1()->SetWritable(true);
1450 EXPECT_TRUE(media_channel1_->sending());
1451 EXPECT_TRUE(SendRtp1());
1452 EXPECT_TRUE(SendRtp2());
1453 EXPECT_TRUE(CheckRtp1());
1454 EXPECT_TRUE(CheckRtp2());
1455 EXPECT_TRUE(CheckNoRtp1());
1456 EXPECT_TRUE(CheckNoRtp2());
1457
1458 // Lose writability completely
1459 GetTransport1()->SetDestination(NULL);
1460 EXPECT_TRUE(media_channel1_->sending());
1461
wu@webrtc.org97077a32013-10-25 21:18:33 +00001462 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463 EXPECT_FALSE(SendRtp1());
1464 EXPECT_TRUE(SendRtp2());
1465 EXPECT_TRUE(CheckRtp1());
1466 EXPECT_TRUE(CheckNoRtp2());
1467
1468 // Gain writability back
1469 GetTransport1()->SetDestination(GetTransport2());
1470 EXPECT_TRUE(media_channel1_->sending());
1471 EXPECT_TRUE(SendRtp1());
1472 EXPECT_TRUE(SendRtp2());
1473 EXPECT_TRUE(CheckRtp1());
1474 EXPECT_TRUE(CheckRtp2());
1475 EXPECT_TRUE(CheckNoRtp1());
1476 EXPECT_TRUE(CheckNoRtp2());
1477 }
1478
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001479 void SendBundleToBundle(
1480 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1481 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001483 // Only pl_type1 was added to the bundle filter for both |channel1_|
1484 // and |channel2_|.
1485 int pl_type1 = pl_types[0];
1486 int pl_type2 = pl_types[1];
1487 int flags = SSRC_MUX | RTCP;
1488 if (secure) flags |= SECURE;
1489 uint32 expected_channels = 2U;
1490 if (rtcp_mux) {
1491 flags |= RTCP_MUX;
1492 expected_channels = 1U;
1493 }
1494 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 EXPECT_TRUE(SendInitiate());
1496 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001497 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001499 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1500 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1501 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1502 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1503 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1504 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1505 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1506 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1507 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1508 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1509 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1510 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1511
1512 // Both channels can receive pl_type1 only.
1513 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1514 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1515 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1516 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1517 EXPECT_TRUE(CheckNoRtp1());
1518 EXPECT_TRUE(CheckNoRtp2());
1519
1520 // RTCP test
1521 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1522 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1523 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1524 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1525
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1527 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1529 EXPECT_TRUE(CheckNoRtcp1());
1530 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1531 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001533 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1534 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1537 }
1538
1539 // Test that the media monitor can be run and gives timely callbacks.
1540 void TestMediaMonitor() {
1541 static const int kTimeout = 500;
1542 CreateChannels(0, 0);
1543 EXPECT_TRUE(SendInitiate());
1544 EXPECT_TRUE(SendAccept());
1545 channel1_->StartMediaMonitor(100);
1546 channel2_->StartMediaMonitor(100);
1547 // Ensure we get callbacks and stop.
1548 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1549 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1550 channel1_->StopMediaMonitor();
1551 channel2_->StopMediaMonitor();
1552 // Ensure a restart of a stopped monitor works.
1553 channel1_->StartMediaMonitor(100);
1554 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1555 channel1_->StopMediaMonitor();
1556 // Ensure stopping a stopped monitor is OK.
1557 channel1_->StopMediaMonitor();
1558 }
1559
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001560 void TestSetContentFailure() {
1561 CreateChannels(0, 0);
1562 typename T::Content content;
1563 cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1564 cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1565
1566 // Set up the session description.
1567 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1568 sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1569 new cricket::AudioContentDescription());
1570 sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1571 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001572 session1_.set_local_description(sdesc_loc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1574 new cricket::AudioContentDescription());
1575 sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1576 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001577 session1_.set_remote_description(sdesc_rem);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578
1579 // Test failures in SetLocalContent.
1580 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001581 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001582 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1584 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001585 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001586 session1_.SetState(cricket::BaseSession::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1588
1589 // Test failures in SetRemoteContent.
1590 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001591 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001592 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1594 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001595 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001596 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1598 }
1599
1600 void TestSendTwoOffers() {
1601 CreateChannels(0, 0);
1602
1603 // Set up the initial session description.
1604 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001605 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001607 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001608 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001609 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1610 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1611
1612 // Update the local description and set the state again.
1613 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001614 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001616 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1618 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1619 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1620 }
1621
1622 void TestReceiveTwoOffers() {
1623 CreateChannels(0, 0);
1624
1625 // Set up the initial session description.
1626 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001627 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001629 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001630 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1632 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1633
1634 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001635 session1_.set_remote_description(sdesc);
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001636 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1638 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1639 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1640 }
1641
1642 void TestSendPrAnswer() {
1643 CreateChannels(0, 0);
1644
1645 // Set up the initial session description.
1646 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001647 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001649 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001650 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1652 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1653
1654 // Send PRANSWER
1655 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001656 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001658 session1_.SetState(cricket::BaseSession::STATE_SENTPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1660 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1661 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1662
1663 // Send ACCEPT
1664 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001665 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001667 session1_.SetState(cricket::BaseSession::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1669 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1670 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1671 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1672 }
1673
1674 void TestReceivePrAnswer() {
1675 CreateChannels(0, 0);
1676
1677 // Set up the initial session description.
1678 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001679 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001681 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001682 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1684 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1685
1686 // Receive PRANSWER
1687 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001688 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001690 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1692 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1693 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1694
1695 // Receive ACCEPT
1696 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001697 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001698
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001699 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1701 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1702 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1703 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1704 }
1705
1706 void TestFlushRtcp() {
1707 bool send_rtcp1;
1708
1709 CreateChannels(RTCP, RTCP);
1710 EXPECT_TRUE(SendInitiate());
1711 EXPECT_TRUE(SendAccept());
1712 EXPECT_EQ(2U, GetTransport1()->channels().size());
1713 EXPECT_EQ(2U, GetTransport2()->channels().size());
1714
1715 // Send RTCP1 from a different thread.
1716 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1717 EXPECT_TRUE(send_rtcp1);
1718 // The sending message is only posted. channel2_ should be empty.
1719 EXPECT_TRUE(CheckNoRtcp2());
1720
1721 // When channel1_ is deleted, the RTCP packet should be sent out to
1722 // channel2_.
1723 channel1_.reset();
1724 EXPECT_TRUE(CheckRtcp2());
1725 }
1726
1727 void TestChangeStateError() {
1728 CreateChannels(RTCP, RTCP);
1729 EXPECT_TRUE(SendInitiate());
1730 media_channel2_->set_fail_set_send(true);
1731 EXPECT_TRUE(channel2_->Enable(true));
1732 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1733 error_);
1734 }
1735
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001736 void TestSrtpError(int pl_type) {
1737 // For Audio, only pl_type 0 is added to the bundle filter.
1738 // For Video, only pl_type 97 is added to the bundle filter.
1739 // So we need to pass in pl_type so that the packet can pass through
1740 // the bundle filter before it can be processed by the srtp filter.
1741 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001742 unsigned const char kBadPacket[] = {0x84,
1743 static_cast<unsigned char>(pl_type),
1744 0x00,
1745 0x01,
1746 0x00,
1747 0x00,
1748 0x00,
1749 0x00,
1750 0x00,
1751 0x00,
1752 0x00,
1753 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1755 EXPECT_FALSE(channel1_->secure());
1756 EXPECT_FALSE(channel2_->secure());
1757 EXPECT_TRUE(SendInitiate());
1758 EXPECT_TRUE(SendAccept());
1759 EXPECT_TRUE(channel1_->secure());
1760 EXPECT_TRUE(channel2_->secure());
1761 channel2_->set_srtp_signal_silent_time(200);
1762
1763 // Testing failures in sending packets.
1764 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1765 // The first failure will trigger an error.
1766 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1767 error_ = T::MediaChannel::ERROR_NONE;
1768 // The next 1 sec failures will not trigger an error.
1769 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1770 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001771 rtc::Thread::Current()->ProcessMessages(210);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1773 // The error will be triggered again.
1774 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1775 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1776
1777 // Testing failures in receiving packets.
1778 error_ = T::MediaChannel::ERROR_NONE;
1779 cricket::TransportChannel* transport_channel =
1780 channel2_->transport_channel();
1781 transport_channel->SignalReadPacket(
1782 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001783 sizeof(kBadPacket), rtc::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001784 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 }
1786
1787 void TestOnReadyToSend() {
1788 CreateChannels(RTCP, RTCP);
1789 TransportChannel* rtp = channel1_->transport_channel();
1790 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1791 EXPECT_FALSE(media_channel1_->ready_to_send());
1792 rtp->SignalReadyToSend(rtp);
1793 EXPECT_FALSE(media_channel1_->ready_to_send());
1794 rtcp->SignalReadyToSend(rtcp);
1795 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1796 // channel are ready to send.
1797 EXPECT_TRUE(media_channel1_->ready_to_send());
1798
1799 // rtp channel becomes not ready to send will be propagated to mediachannel
1800 channel1_->SetReadyToSend(rtp, false);
1801 EXPECT_FALSE(media_channel1_->ready_to_send());
1802 channel1_->SetReadyToSend(rtp, true);
1803 EXPECT_TRUE(media_channel1_->ready_to_send());
1804
1805 // rtcp channel becomes not ready to send will be propagated to mediachannel
1806 channel1_->SetReadyToSend(rtcp, false);
1807 EXPECT_FALSE(media_channel1_->ready_to_send());
1808 channel1_->SetReadyToSend(rtcp, true);
1809 EXPECT_TRUE(media_channel1_->ready_to_send());
1810 }
1811
1812 void TestOnReadyToSendWithRtcpMux() {
1813 CreateChannels(RTCP, RTCP);
1814 typename T::Content content;
1815 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1816 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1817 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001818 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1819 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1821 TransportChannel* rtp = channel1_->transport_channel();
1822 EXPECT_FALSE(media_channel1_->ready_to_send());
1823 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1824 // should trigger the MediaChannel's OnReadyToSend.
1825 rtp->SignalReadyToSend(rtp);
1826 EXPECT_TRUE(media_channel1_->ready_to_send());
1827 channel1_->SetReadyToSend(rtp, false);
1828 EXPECT_FALSE(media_channel1_->ready_to_send());
1829 }
1830
1831 protected:
1832 cricket::FakeSession session1_;
1833 cricket::FakeSession session2_;
1834 cricket::FakeMediaEngine media_engine_;
1835 // The media channels are owned by the voice channel objects below.
1836 typename T::MediaChannel* media_channel1_;
1837 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001838 rtc::scoped_ptr<typename T::Channel> channel1_;
1839 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 typename T::Content local_media_content1_;
1841 typename T::Content local_media_content2_;
1842 typename T::Content remote_media_content1_;
1843 typename T::Content remote_media_content2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001844 rtc::scoped_ptr<rtc::SSLIdentity> identity1_;
1845 rtc::scoped_ptr<rtc::SSLIdentity> identity2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 // The RTP and RTCP packets to send in the tests.
1847 std::string rtp_packet_;
1848 std::string rtcp_packet_;
1849 int media_info_callbacks1_;
1850 int media_info_callbacks2_;
1851 bool mute_callback_recved_;
1852 bool mute_callback_value_;
1853
1854 uint32 ssrc_;
1855 typename T::MediaChannel::Error error_;
1856};
1857
1858
1859template<>
1860void ChannelTest<VoiceTraits>::CreateContent(
1861 int flags,
1862 const cricket::AudioCodec& audio_codec,
1863 const cricket::VideoCodec& video_codec,
1864 cricket::AudioContentDescription* audio) {
1865 audio->AddCodec(audio_codec);
1866 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1867 if (flags & SECURE) {
1868 audio->AddCrypto(cricket::CryptoParams(
1869 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001870 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 }
1872}
1873
1874template<>
1875void ChannelTest<VoiceTraits>::CopyContent(
1876 const cricket::AudioContentDescription& source,
1877 cricket::AudioContentDescription* audio) {
1878 *audio = source;
1879}
1880
1881template<>
1882bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1883 const cricket::AudioCodec& c2) {
1884 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1885 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1886}
1887
1888template<>
1889void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1890 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1891 audio->AddLegacyStream(ssrc);
1892}
1893
1894class VoiceChannelTest
1895 : public ChannelTest<VoiceTraits> {
1896 public:
1897 typedef ChannelTest<VoiceTraits>
1898 Base;
1899 VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1900 kRtcpReport, sizeof(kRtcpReport)) {
1901 }
1902
1903 void TestSetChannelOptions() {
1904 CreateChannels(0, 0);
1905
1906 cricket::AudioOptions options1;
1907 options1.echo_cancellation.Set(false);
1908 cricket::AudioOptions options2;
1909 options2.echo_cancellation.Set(true);
1910
1911 channel1_->SetChannelOptions(options1);
1912 channel2_->SetChannelOptions(options1);
1913 cricket::AudioOptions actual_options;
1914 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1915 EXPECT_EQ(options1, actual_options);
1916 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1917 EXPECT_EQ(options1, actual_options);
1918
1919 channel1_->SetChannelOptions(options2);
1920 channel2_->SetChannelOptions(options2);
1921 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1922 EXPECT_EQ(options2, actual_options);
1923 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1924 EXPECT_EQ(options2, actual_options);
1925 }
1926};
1927
1928// override to add NULL parameter
1929template<>
1930cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001931 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001932 cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1933 bool rtcp) {
1934 cricket::VideoChannel* channel = new cricket::VideoChannel(
Fredrik Solenberg7fb711f2015-04-22 15:30:51 +02001935 thread, engine, ch, session, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001936 if (!channel->Init()) {
1937 delete channel;
1938 channel = NULL;
1939 }
1940 return channel;
1941}
1942
1943// override to add 0 parameter
1944template<>
1945bool ChannelTest<VideoTraits>::AddStream1(int id) {
1946 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1947}
1948
1949template<>
1950void ChannelTest<VideoTraits>::CreateContent(
1951 int flags,
1952 const cricket::AudioCodec& audio_codec,
1953 const cricket::VideoCodec& video_codec,
1954 cricket::VideoContentDescription* video) {
1955 video->AddCodec(video_codec);
1956 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1957 if (flags & SECURE) {
1958 video->AddCrypto(cricket::CryptoParams(
1959 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001960 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 }
1962}
1963
1964template<>
1965void ChannelTest<VideoTraits>::CopyContent(
1966 const cricket::VideoContentDescription& source,
1967 cricket::VideoContentDescription* video) {
1968 *video = source;
1969}
1970
1971template<>
1972bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1973 const cricket::VideoCodec& c2) {
1974 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1975 c1.framerate == c2.framerate;
1976}
1977
1978template<>
1979void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1980 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1981 video->AddLegacyStream(ssrc);
1982}
1983
1984class VideoChannelTest
1985 : public ChannelTest<VideoTraits> {
1986 public:
1987 typedef ChannelTest<VideoTraits>
1988 Base;
1989 VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
1990 kRtcpReport, sizeof(kRtcpReport)) {
1991 }
1992
1993 void TestSetChannelOptions() {
1994 CreateChannels(0, 0);
1995
1996 cricket::VideoOptions o1, o2;
1997 o1.video_noise_reduction.Set(true);
1998
1999 channel1_->SetChannelOptions(o1);
2000 channel2_->SetChannelOptions(o1);
2001 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2002 EXPECT_EQ(o1, o2);
2003 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2004 EXPECT_EQ(o1, o2);
2005
buildbot@webrtc.org81ddc782014-10-14 22:39:24 +00002006 o1.video_start_bitrate.Set(123);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002007 channel1_->SetChannelOptions(o1);
2008 channel2_->SetChannelOptions(o1);
2009 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2010 EXPECT_EQ(o1, o2);
2011 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2012 EXPECT_EQ(o1, o2);
2013 }
2014};
2015
2016
2017// VoiceChannelTest
2018
2019TEST_F(VoiceChannelTest, TestInit) {
2020 Base::TestInit();
2021 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2022 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2023}
2024
2025TEST_F(VoiceChannelTest, TestSetContents) {
2026 Base::TestSetContents();
2027}
2028
2029TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2030 Base::TestSetContentsNullOffer();
2031}
2032
2033TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2034 Base::TestSetContentsRtcpMux();
2035}
2036
2037TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2038 Base::TestSetContentsRtcpMux();
2039}
2040
2041TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2042 Base::TestSetRemoteContentUpdate();
2043}
2044
2045TEST_F(VoiceChannelTest, TestStreams) {
2046 Base::TestStreams();
2047}
2048
2049TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2050 Base::TestUpdateStreamsInLocalContent();
2051}
2052
2053TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2054 Base::TestUpdateStreamsInRemoteContent();
2055}
2056
2057TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2058 Base::TestChangeStreamParamsInContent();
2059}
2060
2061TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2062 Base::TestPlayoutAndSendingStates();
2063}
2064
2065TEST_F(VoiceChannelTest, TestMuteStream) {
2066 Base::TestMuteStream();
2067}
2068
2069TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2070 Base::TestMediaContentDirection();
2071}
2072
2073TEST_F(VoiceChannelTest, TestCallSetup) {
2074 Base::TestCallSetup();
2075}
2076
2077TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2078 Base::TestCallTeardownRtcpMux();
2079}
2080
2081TEST_F(VoiceChannelTest, SendRtpToRtp) {
2082 Base::SendRtpToRtp();
2083}
2084
2085TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2086 Base::SendNoRtcpToNoRtcp();
2087}
2088
2089TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2090 Base::SendNoRtcpToRtcp();
2091}
2092
2093TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2094 Base::SendRtcpToNoRtcp();
2095}
2096
2097TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2098 Base::SendRtcpToRtcp();
2099}
2100
2101TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2102 Base::SendRtcpMuxToRtcp();
2103}
2104
2105TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2106 Base::SendRtcpMuxToRtcpMux();
2107}
2108
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002109TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2110 Base::SendRequireRtcpMuxToRtcpMux();
2111}
2112
2113TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2114 Base::SendRtcpMuxToRequireRtcpMux();
2115}
2116
2117TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2118 Base::SendRequireRtcpMuxToRequireRtcpMux();
2119}
2120
2121TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2122 Base::SendRequireRtcpMuxToNoRtcpMux();
2123}
2124
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2126 Base::SendEarlyRtcpMuxToRtcp();
2127}
2128
2129TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2130 Base::SendEarlyRtcpMuxToRtcpMux();
2131}
2132
2133TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2134 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2135}
2136
2137TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2138 Base::SendSrtpToSrtp();
2139}
2140
2141TEST_F(VoiceChannelTest, SendSrtcpMux) {
2142 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2143}
2144
2145TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2146 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2147 Base::SendSrtpToSrtp(DTLS, 0);
2148}
2149
2150TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2151 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2152 Base::SendSrtpToSrtp(DTLS, DTLS);
2153}
2154
2155TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2156 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2157 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2158}
2159
2160TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2161 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2162}
2163
2164TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2165 Base::SendRtpToRtpOnThread();
2166}
2167
2168TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2169 Base::SendSrtpToSrtpOnThread();
2170}
2171
2172TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2173 Base::SendWithWritabilityLoss();
2174}
2175
2176TEST_F(VoiceChannelTest, TestMediaMonitor) {
2177 Base::TestMediaMonitor();
2178}
2179
2180// Test that MuteStream properly forwards to the media channel and does
2181// not signal.
2182TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
2183 CreateChannels(0, 0);
2184 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2185 EXPECT_FALSE(mute_callback_recved_);
2186 EXPECT_TRUE(channel1_->MuteStream(0, true));
2187 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2188 EXPECT_FALSE(mute_callback_recved_);
2189 EXPECT_TRUE(channel1_->MuteStream(0, false));
2190 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2191 EXPECT_FALSE(mute_callback_recved_);
2192}
2193
2194// Test that keyboard automute works correctly and signals upwards.
asapersson@webrtc.orgb533a822013-09-23 19:47:49 +00002195TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196 CreateChannels(0, 0);
2197 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2198 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
2199
2200 cricket::VoiceMediaChannel::Error e =
2201 cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
2202
2203 // Typing doesn't mute automatically unless typing monitor has been installed
2204 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002205 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 EXPECT_EQ(e, error_);
2207 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2208 EXPECT_FALSE(mute_callback_recved_);
2209
2210 cricket::TypingMonitorOptions o = {0};
2211 o.mute_period = 1500;
2212 channel1_->StartTypingMonitor(o);
2213 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002214 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2216 EXPECT_TRUE(mute_callback_recved_);
2217}
2218
2219// Test that PressDTMF properly forwards to the media channel.
2220TEST_F(VoiceChannelTest, TestDtmf) {
2221 CreateChannels(0, 0);
2222 EXPECT_TRUE(SendInitiate());
2223 EXPECT_TRUE(SendAccept());
2224 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2225
2226 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2227 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2228
2229 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2230 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2231 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2232 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2233 0, 8, 160, cricket::DF_SEND));
2234}
2235
2236// Test that InsertDtmf properly forwards to the media channel.
2237TEST_F(VoiceChannelTest, TestInsertDtmf) {
2238 CreateChannels(0, 0);
2239 EXPECT_TRUE(SendInitiate());
2240 EXPECT_TRUE(SendAccept());
2241 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2242
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2244 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2245 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2246 cricket::DF_PLAY | cricket::DF_SEND));
2247
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002248 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002251 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002253 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2255}
2256
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257TEST_F(VoiceChannelTest, TestSetContentFailure) {
2258 Base::TestSetContentFailure();
2259}
2260
2261TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2262 Base::TestSendTwoOffers();
2263}
2264
2265TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2266 Base::TestReceiveTwoOffers();
2267}
2268
2269TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2270 Base::TestSendPrAnswer();
2271}
2272
2273TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2274 Base::TestReceivePrAnswer();
2275}
2276
2277TEST_F(VoiceChannelTest, TestFlushRtcp) {
2278 Base::TestFlushRtcp();
2279}
2280
2281TEST_F(VoiceChannelTest, TestChangeStateError) {
2282 Base::TestChangeStateError();
2283}
2284
2285TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002286 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287}
2288
2289TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2290 Base::TestOnReadyToSend();
2291}
2292
2293TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2294 Base::TestOnReadyToSendWithRtcpMux();
2295}
2296
2297// Test that we can play a ringback tone properly.
2298TEST_F(VoiceChannelTest, TestRingbackTone) {
2299 CreateChannels(RTCP, RTCP);
2300 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2301 EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
2302 EXPECT_TRUE(SendInitiate());
2303 EXPECT_TRUE(SendAccept());
2304 // Play ringback tone, no loop.
2305 EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
2306 EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
2307 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2308 EXPECT_FALSE(media_channel1_->ringback_tone_loop());
2309 // Stop the ringback tone.
2310 EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
2311 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2312 // Add a stream.
2313 EXPECT_TRUE(AddStream1(1));
2314 // Play ringback tone, looping, on the new stream.
2315 EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
2316 EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
2317 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2318 EXPECT_TRUE(media_channel1_->ringback_tone_loop());
2319 // Stop the ringback tone.
2320 EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
2321 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2322}
2323
2324// Test that we can scale the output volume properly for 1:1 calls.
2325TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2326 CreateChannels(RTCP, RTCP);
2327 EXPECT_TRUE(SendInitiate());
2328 EXPECT_TRUE(SendAccept());
2329 double left, right;
2330
2331 // Default is (1.0, 1.0).
2332 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2333 EXPECT_DOUBLE_EQ(1.0, left);
2334 EXPECT_DOUBLE_EQ(1.0, right);
2335 // invalid ssrc.
2336 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2337
2338 // Set scale to (1.5, 0.5).
2339 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2340 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2341 EXPECT_DOUBLE_EQ(1.5, left);
2342 EXPECT_DOUBLE_EQ(0.5, right);
2343
2344 // Set scale to (0, 0).
2345 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2346 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2347 EXPECT_DOUBLE_EQ(0.0, left);
2348 EXPECT_DOUBLE_EQ(0.0, right);
2349}
2350
2351// Test that we can scale the output volume properly for multiway calls.
2352TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2353 CreateChannels(RTCP, RTCP);
2354 EXPECT_TRUE(SendInitiate());
2355 EXPECT_TRUE(SendAccept());
2356 EXPECT_TRUE(AddStream1(1));
2357 EXPECT_TRUE(AddStream1(2));
2358
2359 double left, right;
2360 // Default is (1.0, 1.0).
2361 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2362 EXPECT_DOUBLE_EQ(1.0, left);
2363 EXPECT_DOUBLE_EQ(1.0, right);
2364 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2365 EXPECT_DOUBLE_EQ(1.0, left);
2366 EXPECT_DOUBLE_EQ(1.0, right);
2367 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2368 EXPECT_DOUBLE_EQ(1.0, left);
2369 EXPECT_DOUBLE_EQ(1.0, right);
2370 // invalid ssrc.
2371 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2372
2373 // Set scale to (1.5, 0.5) for ssrc = 1.
2374 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2375 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2376 EXPECT_DOUBLE_EQ(1.5, left);
2377 EXPECT_DOUBLE_EQ(0.5, right);
2378 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2379 EXPECT_DOUBLE_EQ(1.0, left);
2380 EXPECT_DOUBLE_EQ(1.0, right);
2381 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2382 EXPECT_DOUBLE_EQ(1.0, left);
2383 EXPECT_DOUBLE_EQ(1.0, right);
2384
2385 // Set scale to (0, 0) for all ssrcs.
2386 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2387 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2388 EXPECT_DOUBLE_EQ(0.0, left);
2389 EXPECT_DOUBLE_EQ(0.0, right);
2390 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2391 EXPECT_DOUBLE_EQ(0.0, left);
2392 EXPECT_DOUBLE_EQ(0.0, right);
2393 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2394 EXPECT_DOUBLE_EQ(0.0, left);
2395 EXPECT_DOUBLE_EQ(0.0, right);
2396}
2397
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002398TEST_F(VoiceChannelTest, SendBundleToBundle) {
2399 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400}
2401
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002402TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2403 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2404}
2405
2406TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2407 Base::SendBundleToBundle(
2408 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2409}
2410
2411TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2412 Base::SendBundleToBundle(
2413 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414}
2415
2416TEST_F(VoiceChannelTest, TestSetChannelOptions) {
2417 TestSetChannelOptions();
2418}
2419
2420// VideoChannelTest
2421TEST_F(VideoChannelTest, TestInit) {
2422 Base::TestInit();
2423}
2424
2425TEST_F(VideoChannelTest, TestSetContents) {
2426 Base::TestSetContents();
2427}
2428
2429TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2430 Base::TestSetContentsNullOffer();
2431}
2432
2433TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2434 Base::TestSetContentsRtcpMux();
2435}
2436
2437TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2438 Base::TestSetContentsRtcpMux();
2439}
2440
2441TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
2442 Base::TestSetContentsVideoOptions();
2443}
2444
2445TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2446 Base::TestSetRemoteContentUpdate();
2447}
2448
2449TEST_F(VideoChannelTest, TestStreams) {
2450 Base::TestStreams();
2451}
2452
2453TEST_F(VideoChannelTest, TestScreencastEvents) {
2454 const int kTimeoutMs = 500;
2455 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 cricket::ScreencastEventCatcher catcher;
2457 channel1_->SignalScreencastWindowEvent.connect(
2458 &catcher,
2459 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002460
2461 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2462 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2463 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2464 ScreencastId(WindowId(0)));
2465 ASSERT_TRUE(screen_capturer != NULL);
2466
2467 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2468 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002470
2471 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002472 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002473
2474 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002475 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002476
2477 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002478 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002479
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481}
2482
2483TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2484 Base::TestUpdateStreamsInLocalContent();
2485}
2486
2487TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2488 Base::TestUpdateStreamsInRemoteContent();
2489}
2490
2491TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2492 Base::TestChangeStreamParamsInContent();
2493}
2494
2495TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2496 Base::TestPlayoutAndSendingStates();
2497}
2498
2499TEST_F(VideoChannelTest, TestMuteStream) {
2500 Base::TestMuteStream();
2501}
2502
2503TEST_F(VideoChannelTest, TestMediaContentDirection) {
2504 Base::TestMediaContentDirection();
2505}
2506
2507TEST_F(VideoChannelTest, TestCallSetup) {
2508 Base::TestCallSetup();
2509}
2510
2511TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2512 Base::TestCallTeardownRtcpMux();
2513}
2514
2515TEST_F(VideoChannelTest, SendRtpToRtp) {
2516 Base::SendRtpToRtp();
2517}
2518
2519TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2520 Base::SendNoRtcpToNoRtcp();
2521}
2522
2523TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2524 Base::SendNoRtcpToRtcp();
2525}
2526
2527TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2528 Base::SendRtcpToNoRtcp();
2529}
2530
2531TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2532 Base::SendRtcpToRtcp();
2533}
2534
2535TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2536 Base::SendRtcpMuxToRtcp();
2537}
2538
2539TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2540 Base::SendRtcpMuxToRtcpMux();
2541}
2542
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002543TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2544 Base::SendRequireRtcpMuxToRtcpMux();
2545}
2546
2547TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2548 Base::SendRtcpMuxToRequireRtcpMux();
2549}
2550
2551TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2552 Base::SendRequireRtcpMuxToRequireRtcpMux();
2553}
2554
2555TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2556 Base::SendRequireRtcpMuxToNoRtcpMux();
2557}
2558
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2560 Base::SendEarlyRtcpMuxToRtcp();
2561}
2562
2563TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2564 Base::SendEarlyRtcpMuxToRtcpMux();
2565}
2566
2567TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2568 Base::SendSrtpToSrtp();
2569}
2570
2571TEST_F(VideoChannelTest, SendSrtpToRtp) {
2572 Base::SendSrtpToSrtp();
2573}
2574
2575TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2576 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2577 Base::SendSrtpToSrtp(DTLS, 0);
2578}
2579
2580TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2581 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2582 Base::SendSrtpToSrtp(DTLS, DTLS);
2583}
2584
2585TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2586 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2587 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2588}
2589
2590TEST_F(VideoChannelTest, SendSrtcpMux) {
2591 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2592}
2593
2594TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2595 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2596}
2597
2598TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2599 Base::SendRtpToRtpOnThread();
2600}
2601
2602TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2603 Base::SendSrtpToSrtpOnThread();
2604}
2605
2606TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2607 Base::SendWithWritabilityLoss();
2608}
2609
2610TEST_F(VideoChannelTest, TestMediaMonitor) {
2611 Base::TestMediaMonitor();
2612}
2613
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614TEST_F(VideoChannelTest, TestSetContentFailure) {
2615 Base::TestSetContentFailure();
2616}
2617
2618TEST_F(VideoChannelTest, TestSendTwoOffers) {
2619 Base::TestSendTwoOffers();
2620}
2621
2622TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2623 Base::TestReceiveTwoOffers();
2624}
2625
2626TEST_F(VideoChannelTest, TestSendPrAnswer) {
2627 Base::TestSendPrAnswer();
2628}
2629
2630TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2631 Base::TestReceivePrAnswer();
2632}
2633
2634TEST_F(VideoChannelTest, TestFlushRtcp) {
2635 Base::TestFlushRtcp();
2636}
2637
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002638TEST_F(VideoChannelTest, SendBundleToBundle) {
2639 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640}
2641
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002642TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2643 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2644}
2645
2646TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2647 Base::SendBundleToBundle(
2648 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2649}
2650
2651TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2652 Base::SendBundleToBundle(
2653 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654}
2655
2656// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2657
2658TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002659 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660}
2661
2662TEST_F(VideoChannelTest, TestOnReadyToSend) {
2663 Base::TestOnReadyToSend();
2664}
2665
2666TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2667 Base::TestOnReadyToSendWithRtcpMux();
2668}
2669
2670TEST_F(VideoChannelTest, TestApplyViewRequest) {
2671 CreateChannels(0, 0);
2672 cricket::StreamParams stream2;
2673 stream2.id = "stream2";
2674 stream2.ssrcs.push_back(2222);
2675 local_media_content1_.AddStream(stream2);
2676
2677 EXPECT_TRUE(SendInitiate());
2678 EXPECT_TRUE(SendAccept());
2679
2680 cricket::VideoFormat send_format;
2681 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2682 EXPECT_EQ(640, send_format.width);
2683 EXPECT_EQ(400, send_format.height);
2684 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2685
2686 cricket::ViewRequest request;
2687 // stream1: 320x200x15; stream2: 0x0x0
2688 request.static_video_views.push_back(cricket::StaticVideoView(
2689 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2690 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2691 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2692 EXPECT_EQ(320, send_format.width);
2693 EXPECT_EQ(200, send_format.height);
2694 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2695 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2696 EXPECT_EQ(0, send_format.width);
2697 EXPECT_EQ(0, send_format.height);
2698
2699 // stream1: 160x100x8; stream2: 0x0x0
2700 request.static_video_views.clear();
2701 request.static_video_views.push_back(cricket::StaticVideoView(
2702 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2703 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2704 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2705 EXPECT_EQ(160, send_format.width);
2706 EXPECT_EQ(100, send_format.height);
2707 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2708
2709 // stream1: 0x0x0; stream2: 640x400x30
2710 request.static_video_views.clear();
2711 request.static_video_views.push_back(cricket::StaticVideoView(
2712 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2713 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2714 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2715 EXPECT_EQ(0, send_format.width);
2716 EXPECT_EQ(0, send_format.height);
2717 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2718 EXPECT_EQ(640, send_format.width);
2719 EXPECT_EQ(400, send_format.height);
2720 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2721
2722 // stream1: 0x0x0; stream2: 0x0x0
2723 request.static_video_views.clear();
2724 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2725 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2726 EXPECT_EQ(0, send_format.width);
2727 EXPECT_EQ(0, send_format.height);
2728}
2729
2730TEST_F(VideoChannelTest, TestSetChannelOptions) {
2731 TestSetChannelOptions();
2732}
2733
2734
2735// DataChannelTest
2736
2737class DataChannelTest
2738 : public ChannelTest<DataTraits> {
2739 public:
2740 typedef ChannelTest<DataTraits>
2741 Base;
2742 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2743 kRtcpReport, sizeof(kRtcpReport)) {
2744 }
2745};
2746
2747// Override to avoid engine channel parameter.
2748template<>
2749cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002750 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2752 bool rtcp) {
2753 cricket::DataChannel* channel = new cricket::DataChannel(
2754 thread, ch, session, cricket::CN_DATA, rtcp);
2755 if (!channel->Init()) {
2756 delete channel;
2757 channel = NULL;
2758 }
2759 return channel;
2760}
2761
2762template<>
2763void ChannelTest<DataTraits>::CreateContent(
2764 int flags,
2765 const cricket::AudioCodec& audio_codec,
2766 const cricket::VideoCodec& video_codec,
2767 cricket::DataContentDescription* data) {
2768 data->AddCodec(kGoogleDataCodec);
2769 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2770 if (flags & SECURE) {
2771 data->AddCrypto(cricket::CryptoParams(
2772 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002773 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774 }
2775}
2776
2777template<>
2778void ChannelTest<DataTraits>::CopyContent(
2779 const cricket::DataContentDescription& source,
2780 cricket::DataContentDescription* data) {
2781 *data = source;
2782}
2783
2784template<>
2785bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2786 const cricket::DataCodec& c2) {
2787 return c1.name == c2.name;
2788}
2789
2790template<>
2791void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2792 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2793 data->AddLegacyStream(ssrc);
2794}
2795
2796TEST_F(DataChannelTest, TestInit) {
2797 Base::TestInit();
2798 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2799}
2800
2801TEST_F(DataChannelTest, TestSetContents) {
2802 Base::TestSetContents();
2803}
2804
2805TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2806 Base::TestSetContentsNullOffer();
2807}
2808
2809TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2810 Base::TestSetContentsRtcpMux();
2811}
2812
2813TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2814 Base::TestSetRemoteContentUpdate();
2815}
2816
2817TEST_F(DataChannelTest, TestStreams) {
2818 Base::TestStreams();
2819}
2820
2821TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2822 Base::TestUpdateStreamsInLocalContent();
2823}
2824
2825TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2826 Base::TestUpdateStreamsInRemoteContent();
2827}
2828
2829TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2830 Base::TestChangeStreamParamsInContent();
2831}
2832
2833TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2834 Base::TestPlayoutAndSendingStates();
2835}
2836
2837TEST_F(DataChannelTest, TestMediaContentDirection) {
2838 Base::TestMediaContentDirection();
2839}
2840
2841TEST_F(DataChannelTest, TestCallSetup) {
2842 Base::TestCallSetup();
2843}
2844
2845TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2846 Base::TestCallTeardownRtcpMux();
2847}
2848
2849TEST_F(DataChannelTest, TestOnReadyToSend) {
2850 Base::TestOnReadyToSend();
2851}
2852
2853TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2854 Base::TestOnReadyToSendWithRtcpMux();
2855}
2856
2857TEST_F(DataChannelTest, SendRtpToRtp) {
2858 Base::SendRtpToRtp();
2859}
2860
2861TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2862 Base::SendNoRtcpToNoRtcp();
2863}
2864
2865TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2866 Base::SendNoRtcpToRtcp();
2867}
2868
2869TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2870 Base::SendRtcpToNoRtcp();
2871}
2872
2873TEST_F(DataChannelTest, SendRtcpToRtcp) {
2874 Base::SendRtcpToRtcp();
2875}
2876
2877TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2878 Base::SendRtcpMuxToRtcp();
2879}
2880
2881TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2882 Base::SendRtcpMuxToRtcpMux();
2883}
2884
2885TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2886 Base::SendEarlyRtcpMuxToRtcp();
2887}
2888
2889TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2890 Base::SendEarlyRtcpMuxToRtcpMux();
2891}
2892
2893TEST_F(DataChannelTest, SendSrtpToSrtp) {
2894 Base::SendSrtpToSrtp();
2895}
2896
2897TEST_F(DataChannelTest, SendSrtpToRtp) {
2898 Base::SendSrtpToSrtp();
2899}
2900
2901TEST_F(DataChannelTest, SendSrtcpMux) {
2902 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2903}
2904
2905TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2906 Base::SendRtpToRtpOnThread();
2907}
2908
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2910 Base::SendSrtpToSrtpOnThread();
2911}
2912
2913TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2914 Base::SendWithWritabilityLoss();
2915}
2916
2917TEST_F(DataChannelTest, TestMediaMonitor) {
2918 Base::TestMediaMonitor();
2919}
2920
2921TEST_F(DataChannelTest, TestSendData) {
2922 CreateChannels(0, 0);
2923 EXPECT_TRUE(SendInitiate());
2924 EXPECT_TRUE(SendAccept());
2925
2926 cricket::SendDataParams params;
2927 params.ssrc = 42;
2928 unsigned char data[] = {
2929 'f', 'o', 'o'
2930 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002931 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002932 cricket::SendDataResult result;
2933 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2934 EXPECT_EQ(params.ssrc,
2935 media_channel1_->last_sent_data_params().ssrc);
2936 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2937}
2938
2939// TODO(pthatcher): TestSetReceiver?