blob: b652b74751f99b350ae3df3fac59e241634567ce [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001// libjingle
2// Copyright 2009 Google Inc.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12// 3. The name of the author may not be used to endorse or promote products
13// derived from this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026#include "talk/media/base/fakemediaengine.h"
27#include "talk/media/base/fakertp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000028#include "talk/media/base/fakescreencapturerfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029#include "talk/media/base/fakevideocapturer.h"
30#include "talk/media/base/mediachannel.h"
31#include "talk/media/base/rtpdump.h"
32#include "talk/media/base/screencastid.h"
33#include "talk/media/base/testutils.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000034#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/session/media/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/session/media/mediarecorder.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/session/media/typingmonitor.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000038#include "webrtc/base/fileutils.h"
39#include "webrtc/base/gunit.h"
40#include "webrtc/base/helpers.h"
41#include "webrtc/base/logging.h"
42#include "webrtc/base/pathutils.h"
43#include "webrtc/base/signalthread.h"
44#include "webrtc/base/ssladapter.h"
45#include "webrtc/base/sslidentity.h"
46#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000047
48#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 LOG(LS_INFO) << "Feature disabled... skipping"; \
51 return; \
52 }
53
54using cricket::CA_OFFER;
55using cricket::CA_PRANSWER;
56using cricket::CA_ANSWER;
57using cricket::CA_UPDATE;
58using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::ScreencastId;
60using cricket::StreamParams;
61using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
65static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
67static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
68static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
69static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
70static const uint32 kSsrc1 = 0x1111;
71static const uint32 kSsrc2 = 0x2222;
72static const uint32 kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000073static const int kAudioPts[] = {0, 8};
74static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
76template<class ChannelT,
77 class MediaChannelT,
78 class ContentT,
79 class CodecT,
80 class MediaInfoT>
81class Traits {
82 public:
83 typedef ChannelT Channel;
84 typedef MediaChannelT MediaChannel;
85 typedef ContentT Content;
86 typedef CodecT Codec;
87 typedef MediaInfoT MediaInfo;
88};
89
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090// Controls how long we wait for a session to send messages that we
91// expect, in milliseconds. We put it high to avoid flaky tests.
92static const int kEventTimeout = 5000;
93
94class VoiceTraits : public Traits<cricket::VoiceChannel,
95 cricket::FakeVoiceMediaChannel,
96 cricket::AudioContentDescription,
97 cricket::AudioCodec,
98 cricket::VoiceMediaInfo> {
99};
100
101class VideoTraits : public Traits<cricket::VideoChannel,
102 cricket::FakeVideoMediaChannel,
103 cricket::VideoContentDescription,
104 cricket::VideoCodec,
105 cricket::VideoMediaInfo> {
106};
107
108class DataTraits : public Traits<cricket::DataChannel,
109 cricket::FakeDataMediaChannel,
110 cricket::DataContentDescription,
111 cricket::DataCodec,
112 cricket::DataMediaInfo> {
113};
114
115
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000116rtc::StreamInterface* Open(const std::string& path) {
117 return rtc::Filesystem::OpenFile(
118 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119}
120
121// Base class for Voice/VideoChannel tests
122template<class T>
123class ChannelTest : public testing::Test, public sigslot::has_slots<> {
124 public:
125 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
126 DTLS = 0x10 };
127
128 ChannelTest(const uint8* rtp_data, int rtp_len,
129 const uint8* rtcp_data, int rtcp_len)
130 : session1_(true),
131 session2_(false),
132 media_channel1_(NULL),
133 media_channel2_(NULL),
134 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
135 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
136 media_info_callbacks1_(),
137 media_info_callbacks2_(),
138 mute_callback_recved_(false),
139 mute_callback_value_(false),
140 ssrc_(0),
141 error_(T::MediaChannel::ERROR_NONE) {
142 }
143
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 void CreateChannels(int flags1, int flags2) {
145 CreateChannels(new typename T::MediaChannel(NULL),
146 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000147 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000148 }
149 void CreateChannels(int flags) {
150 CreateChannels(new typename T::MediaChannel(NULL),
151 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000152 flags, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000153 }
154 void CreateChannels(int flags1, int flags2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000155 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156 CreateChannels(new typename T::MediaChannel(NULL),
157 new typename T::MediaChannel(NULL),
158 flags1, flags2, thread);
159 }
160 void CreateChannels(int flags,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000161 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 CreateChannels(new typename T::MediaChannel(NULL),
163 new typename T::MediaChannel(NULL),
164 flags, thread);
165 }
166 void CreateChannels(
167 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000168 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 media_channel1_ = ch1;
170 media_channel2_ = ch2;
171 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
172 (flags1 & RTCP) != 0));
173 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
174 (flags2 & RTCP) != 0));
175 channel1_->SignalMediaMonitor.connect(
176 this, &ChannelTest<T>::OnMediaMonitor);
177 channel2_->SignalMediaMonitor.connect(
178 this, &ChannelTest<T>::OnMediaMonitor);
179 channel1_->SignalMediaError.connect(
180 this, &ChannelTest<T>::OnMediaChannelError);
181 channel2_->SignalMediaError.connect(
182 this, &ChannelTest<T>::OnMediaChannelError);
183 channel1_->SignalAutoMuted.connect(
184 this, &ChannelTest<T>::OnMediaMuted);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000185 if ((flags1 & DTLS) && (flags2 & DTLS)) {
186 flags1 = (flags1 & ~SECURE);
187 flags2 = (flags2 & ~SECURE);
188 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 CreateContent(flags1, kPcmuCodec, kH264Codec,
190 &local_media_content1_);
191 CreateContent(flags2, kPcmuCodec, kH264Codec,
192 &local_media_content2_);
193 CopyContent(local_media_content1_, &remote_media_content1_);
194 CopyContent(local_media_content2_, &remote_media_content2_);
195
196 if (flags1 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000197 identity1_.reset(rtc::SSLIdentity::Generate("session1"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000198 session1_.set_ssl_identity(identity1_.get());
199 }
200 if (flags2 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000201 identity2_.reset(rtc::SSLIdentity::Generate("session2"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000202 session2_.set_ssl_identity(identity2_.get());
203 }
204
205 // Add stream information (SSRC) to the local content but not to the remote
206 // content. This means that we per default know the SSRC of what we send but
207 // not what we receive.
208 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
209 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
210
211 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
212 if (flags1 & SSRC_MUX) {
213 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
214 }
215 if (flags2 & SSRC_MUX) {
216 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
217 }
218 }
219
220 void CreateChannels(
221 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000222 int flags, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000223 media_channel1_ = ch1;
224 media_channel2_ = ch2;
225
226 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
227 (flags & RTCP) != 0));
228 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
229 (flags & RTCP) != 0));
230 channel1_->SignalMediaMonitor.connect(
231 this, &ChannelTest<T>::OnMediaMonitor);
232 channel2_->SignalMediaMonitor.connect(
233 this, &ChannelTest<T>::OnMediaMonitor);
234 channel2_->SignalMediaError.connect(
235 this, &ChannelTest<T>::OnMediaChannelError);
236 CreateContent(flags, kPcmuCodec, kH264Codec,
237 &local_media_content1_);
238 CreateContent(flags, kPcmuCodec, kH264Codec,
239 &local_media_content2_);
240 CopyContent(local_media_content1_, &remote_media_content1_);
241 CopyContent(local_media_content2_, &remote_media_content2_);
242 // Add stream information (SSRC) to the local content but not to the remote
243 // content. This means that we per default know the SSRC of what we send but
244 // not what we receive.
245 AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
246 AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
247
248 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
249 if (flags & SSRC_MUX) {
250 AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
251 AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
252 }
253 }
254
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000255 typename T::Channel* CreateChannel(rtc::Thread* thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256 cricket::MediaEngineInterface* engine,
257 typename T::MediaChannel* ch,
258 cricket::BaseSession* session,
259 bool rtcp) {
260 typename T::Channel* channel = new typename T::Channel(
261 thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
262 if (!channel->Init()) {
263 delete channel;
264 channel = NULL;
265 }
266 return channel;
267 }
268
269 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000270 bool result = channel1_->SetLocalContent(&local_media_content1_,
271 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 if (result) {
273 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000274 result = channel2_->SetRemoteContent(&remote_media_content1_,
275 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 if (result) {
277 session1_.Connect(&session2_);
278
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000279 result = channel2_->SetLocalContent(&local_media_content2_,
280 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281 }
282 }
283 return result;
284 }
285
286 bool SendAccept() {
287 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000288 return channel1_->SetRemoteContent(&remote_media_content2_,
289 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290 }
291
292 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000293 bool result = channel1_->SetLocalContent(&local_media_content1_,
294 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 if (result) {
296 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000297 result = channel2_->SetRemoteContent(&remote_media_content1_,
298 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 }
300 return result;
301 }
302
303 bool SendProvisionalAnswer() {
304 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000305 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 if (result) {
307 channel2_->Enable(true);
308 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000309 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000310 session1_.Connect(&session2_);
311 }
312 return result;
313 }
314
315 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000316 bool result = channel2_->SetLocalContent(&local_media_content2_,
317 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000319 result = channel1_->SetRemoteContent(&remote_media_content2_,
320 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321 return result;
322 }
323
324 bool SendTerminate() {
325 channel1_.reset();
326 channel2_.reset();
327 return true;
328 }
329
330 bool AddStream1(int id) {
331 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
332 }
333 bool RemoveStream1(int id) {
334 return channel1_->RemoveRecvStream(id);
335 }
336
337 cricket::FakeTransport* GetTransport1() {
338 return session1_.GetTransport(channel1_->content_name());
339 }
340 cricket::FakeTransport* GetTransport2() {
341 return session2_.GetTransport(channel2_->content_name());
342 }
343
344 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000345 return media_channel1_->SendRtp(rtp_packet_.c_str(),
346 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 }
348 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000349 return media_channel2_->SendRtp(rtp_packet_.c_str(),
350 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 }
352 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000353 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
354 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 }
356 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000357 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
358 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 }
360 // Methods to send custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000361 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
362 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000363 return media_channel1_->SendRtp(data.c_str(),
364 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000366 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
367 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000368 return media_channel2_->SendRtp(data.c_str(),
369 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 }
371 bool SendCustomRtcp1(uint32 ssrc) {
372 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000373 return media_channel1_->SendRtcp(data.c_str(),
374 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 }
376 bool SendCustomRtcp2(uint32 ssrc) {
377 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000378 return media_channel2_->SendRtcp(data.c_str(),
379 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 }
381 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000382 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
383 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 }
385 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000386 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
387 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 }
389 bool CheckRtcp1() {
390 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000391 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 }
393 bool CheckRtcp2() {
394 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000395 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 }
397 // Methods to check custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000398 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
399 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000400 return media_channel1_->CheckRtp(data.c_str(),
401 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000403 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
404 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000405 return media_channel2_->CheckRtp(data.c_str(),
406 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 }
408 bool CheckCustomRtcp1(uint32 ssrc) {
409 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000410 return media_channel1_->CheckRtcp(data.c_str(),
411 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 }
413 bool CheckCustomRtcp2(uint32 ssrc) {
414 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000415 return media_channel2_->CheckRtcp(data.c_str(),
416 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000418 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 std::string data(rtp_packet_);
420 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000421 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
422 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000423 if (pl_type >= 0) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000424 rtc::Set8(const_cast<char*>(data.c_str()), 1, pl_type);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000425 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 return data;
427 }
428 std::string CreateRtcpData(uint32 ssrc) {
429 std::string data(rtcp_packet_);
430 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000431 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 return data;
433 }
434
435 bool CheckNoRtp1() {
436 return media_channel1_->CheckNoRtp();
437 }
438 bool CheckNoRtp2() {
439 return media_channel2_->CheckNoRtp();
440 }
441 bool CheckNoRtcp1() {
442 return media_channel1_->CheckNoRtcp();
443 }
444 bool CheckNoRtcp2() {
445 return media_channel2_->CheckNoRtcp();
446 }
447
448 void CreateContent(int flags,
449 const cricket::AudioCodec& audio_codec,
450 const cricket::VideoCodec& video_codec,
451 typename T::Content* content) {
452 // overridden in specialized classes
453 }
454 void CopyContent(const typename T::Content& source,
455 typename T::Content* content) {
456 // overridden in specialized classes
457 }
458
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 // Creates a cricket::SessionDescription with one MediaContent and one stream.
460 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
461 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
462 typename T::Content content;
463 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
464 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
465 AddLegacyStreamInContent(ssrc, 0, &content);
466 sdesc->AddContent("DUMMY_CONTENT_NAME",
467 cricket::NS_JINGLE_RTP, content.Copy());
468 return sdesc;
469 }
470
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000471 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000472 public:
473 typedef bool (ChannelTest<T>::*Method)();
474 CallThread(ChannelTest<T>* obj, Method method, bool* result)
475 : obj_(obj),
476 method_(method),
477 result_(result) {
478 *result = false;
479 }
480 virtual void DoWork() {
481 bool result = (*obj_.*method_)();
482 if (result_) {
483 *result_ = result;
484 }
485 }
486 private:
487 ChannelTest<T>* obj_;
488 Method method_;
489 bool* result_;
490 };
491 void CallOnThread(typename CallThread::Method method, bool* result) {
492 CallThread* thread = new CallThread(this, method, result);
493 thread->Start();
494 thread->Release();
495 }
496
497 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
498 bool* result) {
499 CallThread* thread = new CallThread(this, method, result);
500 thread->Start();
501 thread->Destroy(true);
502 }
503
504 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
505 return false; // overridden in specialized classes
506 }
507
508 void OnMediaMonitor(typename T::Channel* channel,
509 const typename T::MediaInfo& info) {
510 if (channel == channel1_.get()) {
511 media_info_callbacks1_++;
512 } else if (channel == channel2_.get()) {
513 media_info_callbacks2_++;
514 }
515 }
516
517 void OnMediaChannelError(typename T::Channel* channel,
518 uint32 ssrc,
519 typename T::MediaChannel::Error error) {
520 ssrc_ = ssrc;
521 error_ = error;
522 }
523
524 void OnMediaMuted(cricket::BaseChannel* channel, bool muted) {
525 mute_callback_recved_ = true;
526 mute_callback_value_ = muted;
527 }
528
529 void AddLegacyStreamInContent(uint32 ssrc, int flags,
530 typename T::Content* content) {
531 // Base implementation.
532 }
533
534 // Tests that can be used by derived classes.
535
536 // Basic sanity check.
537 void TestInit() {
538 CreateChannels(0, 0);
539 EXPECT_FALSE(channel1_->secure());
540 EXPECT_FALSE(media_channel1_->sending());
541 EXPECT_FALSE(media_channel1_->playout());
542 EXPECT_TRUE(media_channel1_->codecs().empty());
543 EXPECT_TRUE(media_channel1_->recv_streams().empty());
544 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
545 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
546 }
547
548 // Test that SetLocalContent and SetRemoteContent properly configure
549 // the codecs.
550 void TestSetContents() {
551 CreateChannels(0, 0);
552 typename T::Content content;
553 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000554 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000556 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000557 ASSERT_EQ(1U, media_channel1_->codecs().size());
558 EXPECT_TRUE(CodecMatches(content.codecs()[0],
559 media_channel1_->codecs()[0]));
560 }
561
562 // Test that SetLocalContent and SetRemoteContent properly deals
563 // with an empty offer.
564 void TestSetContentsNullOffer() {
565 CreateChannels(0, 0);
566 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000567 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 CreateContent(0, kPcmuCodec, kH264Codec, &content);
569 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000570 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 ASSERT_EQ(1U, media_channel1_->codecs().size());
572 EXPECT_TRUE(CodecMatches(content.codecs()[0],
573 media_channel1_->codecs()[0]));
574 }
575
576 // Test that SetLocalContent and SetRemoteContent properly set RTCP
577 // mux.
578 void TestSetContentsRtcpMux() {
579 CreateChannels(RTCP, RTCP);
580 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
581 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
582 typename T::Content content;
583 CreateContent(0, kPcmuCodec, kH264Codec, &content);
584 // Both sides agree on mux. Should no longer be a separate RTCP channel.
585 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000586 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
587 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
589 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000590 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000592 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000593 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
594 }
595
596 // Test that SetLocalContent and SetRemoteContent properly set RTCP
597 // mux when a provisional answer is received.
598 void TestSetContentsRtcpMuxWithPrAnswer() {
599 CreateChannels(RTCP, RTCP);
600 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
601 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
602 typename T::Content content;
603 CreateContent(0, kPcmuCodec, kH264Codec, &content);
604 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000605 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
606 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000608 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 // Both sides agree on mux. Should no longer be a separate RTCP channel.
610 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
611 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000612 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000613 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000614 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
615 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
617 }
618
619 // Test that SetLocalContent and SetRemoteContent properly set
620 // video options to the media channel.
621 void TestSetContentsVideoOptions() {
622 CreateChannels(0, 0);
623 typename T::Content content;
624 CreateContent(0, kPcmuCodec, kH264Codec, &content);
625 content.set_buffered_mode_latency(101);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000626 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 EXPECT_EQ(0U, media_channel1_->codecs().size());
628 cricket::VideoOptions options;
629 ASSERT_TRUE(media_channel1_->GetOptions(&options));
630 int latency = 0;
631 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
632 EXPECT_EQ(101, latency);
633 content.set_buffered_mode_latency(102);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000634 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000635 ASSERT_EQ(1U, media_channel1_->codecs().size());
636 EXPECT_TRUE(CodecMatches(content.codecs()[0],
637 media_channel1_->codecs()[0]));
638 ASSERT_TRUE(media_channel1_->GetOptions(&options));
639 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
640 EXPECT_EQ(102, latency);
641 }
642
643 // Test that SetRemoteContent properly deals with a content update.
644 void TestSetRemoteContentUpdate() {
645 CreateChannels(0, 0);
646 typename T::Content content;
647 CreateContent(RTCP | RTCP_MUX | SECURE,
648 kPcmuCodec, kH264Codec,
649 &content);
650 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000651 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
652 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 ASSERT_EQ(1U, media_channel1_->codecs().size());
654 EXPECT_TRUE(CodecMatches(content.codecs()[0],
655 media_channel1_->codecs()[0]));
656 // Now update with other codecs.
657 typename T::Content update_content;
658 update_content.set_partial(true);
659 CreateContent(0, kIsacCodec, kH264SvcCodec,
660 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000661 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662 ASSERT_EQ(1U, media_channel1_->codecs().size());
663 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
664 media_channel1_->codecs()[0]));
665 // Now update without any codecs. This is ignored.
666 typename T::Content empty_content;
667 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000669 ASSERT_EQ(1U, media_channel1_->codecs().size());
670 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
671 media_channel1_->codecs()[0]));
672 }
673
674 // Test that Add/RemoveStream properly forward to the media channel.
675 void TestStreams() {
676 CreateChannels(0, 0);
677 EXPECT_TRUE(AddStream1(1));
678 EXPECT_TRUE(AddStream1(2));
679 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
680 EXPECT_TRUE(RemoveStream1(2));
681 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
682 EXPECT_TRUE(RemoveStream1(1));
683 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
684 }
685
686 // Test that SetLocalContent properly handles adding and removing StreamParams
687 // to the local content description.
688 // This test uses the CA_UPDATE action that don't require a full
689 // MediaContentDescription to do an update.
690 void TestUpdateStreamsInLocalContent() {
691 cricket::StreamParams stream1;
692 stream1.groupid = "group1";
693 stream1.id = "stream1";
694 stream1.ssrcs.push_back(kSsrc1);
695 stream1.cname = "stream1_cname";
696
697 cricket::StreamParams stream2;
698 stream2.groupid = "group2";
699 stream2.id = "stream2";
700 stream2.ssrcs.push_back(kSsrc2);
701 stream2.cname = "stream2_cname";
702
703 cricket::StreamParams stream3;
704 stream3.groupid = "group3";
705 stream3.id = "stream3";
706 stream3.ssrcs.push_back(kSsrc3);
707 stream3.cname = "stream3_cname";
708
709 CreateChannels(0, 0);
710 typename T::Content content1;
711 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
712 content1.AddStream(stream1);
713 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000714 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715
716 ASSERT_EQ(1u, media_channel1_->send_streams().size());
717 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
718
719 // Update the local streams by adding another sending stream.
720 // Use a partial updated session description.
721 typename T::Content content2;
722 content2.AddStream(stream2);
723 content2.AddStream(stream3);
724 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000725 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 ASSERT_EQ(3u, media_channel1_->send_streams().size());
727 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
728 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
729 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
730
731 // Update the local streams by removing the first sending stream.
732 // This is done by removing all SSRCS for this particular stream.
733 typename T::Content content3;
734 stream1.ssrcs.clear();
735 content3.AddStream(stream1);
736 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000737 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 ASSERT_EQ(2u, media_channel1_->send_streams().size());
739 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
740 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
741
742 // Update the local streams with a stream that does not change.
743 // THe update is ignored.
744 typename T::Content content4;
745 content4.AddStream(stream2);
746 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000747 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 ASSERT_EQ(2u, media_channel1_->send_streams().size());
749 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
750 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
751 }
752
753 // Test that SetRemoteContent properly handles adding and removing
754 // StreamParams to the remote content description.
755 // This test uses the CA_UPDATE action that don't require a full
756 // MediaContentDescription to do an update.
757 void TestUpdateStreamsInRemoteContent() {
758 cricket::StreamParams stream1;
759 stream1.id = "Stream1";
760 stream1.groupid = "1";
761 stream1.ssrcs.push_back(kSsrc1);
762 stream1.cname = "stream1_cname";
763
764 cricket::StreamParams stream2;
765 stream2.id = "Stream2";
766 stream2.groupid = "2";
767 stream2.ssrcs.push_back(kSsrc2);
768 stream2.cname = "stream2_cname";
769
770 cricket::StreamParams stream3;
771 stream3.id = "Stream3";
772 stream3.groupid = "3";
773 stream3.ssrcs.push_back(kSsrc3);
774 stream3.cname = "stream3_cname";
775
776 CreateChannels(0, 0);
777 typename T::Content content1;
778 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
779 content1.AddStream(stream1);
780 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000781 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782
783 ASSERT_EQ(1u, media_channel1_->codecs().size());
784 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
785 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
786
787 // Update the remote streams by adding another sending stream.
788 // Use a partial updated session description.
789 typename T::Content content2;
790 content2.AddStream(stream2);
791 content2.AddStream(stream3);
792 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000793 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
795 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
796 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
797 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
798
799 // Update the remote streams by removing the first stream.
800 // This is done by removing all SSRCS for this particular stream.
801 typename T::Content content3;
802 stream1.ssrcs.clear();
803 content3.AddStream(stream1);
804 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000805 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000806 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
807 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
808 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
809
810 // Update the remote streams with a stream that does not change.
811 // The update is ignored.
812 typename T::Content content4;
813 content4.AddStream(stream2);
814 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000815 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000816 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
817 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
818 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
819 }
820
821 // Test that SetLocalContent and SetRemoteContent properly
822 // handles adding and removing StreamParams when the action is a full
823 // CA_OFFER / CA_ANSWER.
824 void TestChangeStreamParamsInContent() {
825 cricket::StreamParams stream1;
826 stream1.groupid = "group1";
827 stream1.id = "stream1";
828 stream1.ssrcs.push_back(kSsrc1);
829 stream1.cname = "stream1_cname";
830
831 cricket::StreamParams stream2;
832 stream2.groupid = "group1";
833 stream2.id = "stream2";
834 stream2.ssrcs.push_back(kSsrc2);
835 stream2.cname = "stream2_cname";
836
837 // Setup a call where channel 1 send |stream1| to channel 2.
838 CreateChannels(0, 0);
839 typename T::Content content1;
840 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
841 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000842 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000843 EXPECT_TRUE(channel1_->Enable(true));
844 EXPECT_EQ(1u, media_channel1_->send_streams().size());
845
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000846 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000847 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
848 session1_.Connect(&session2_);
849
850 // Channel 2 do not send anything.
851 typename T::Content content2;
852 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000853 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000855 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 EXPECT_TRUE(channel2_->Enable(true));
857 EXPECT_EQ(0u, media_channel2_->send_streams().size());
858
859 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
860 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
861
862 // Let channel 2 update the content by sending |stream2| and enable SRTP.
863 typename T::Content content3;
864 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
865 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000866 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000867 ASSERT_EQ(1u, media_channel2_->send_streams().size());
868 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
869
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000870 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
872 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
873
874 // Channel 1 replies but stop sending stream1.
875 typename T::Content content4;
876 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000877 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 EXPECT_EQ(0u, media_channel1_->send_streams().size());
879
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000880 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
882
883 EXPECT_TRUE(channel1_->secure());
884 EXPECT_TRUE(channel2_->secure());
885 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
886 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
887 }
888
889 // Test that we only start playout and sending at the right times.
890 void TestPlayoutAndSendingStates() {
891 CreateChannels(0, 0);
892 EXPECT_FALSE(media_channel1_->playout());
893 EXPECT_FALSE(media_channel1_->sending());
894 EXPECT_FALSE(media_channel2_->playout());
895 EXPECT_FALSE(media_channel2_->sending());
896 EXPECT_TRUE(channel1_->Enable(true));
897 EXPECT_FALSE(media_channel1_->playout());
898 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000899 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
900 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 EXPECT_TRUE(media_channel1_->playout());
902 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000903 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
904 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 EXPECT_FALSE(media_channel2_->playout());
906 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000907 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
908 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 EXPECT_FALSE(media_channel2_->playout());
910 EXPECT_FALSE(media_channel2_->sending());
911 session1_.Connect(&session2_);
912 EXPECT_TRUE(media_channel1_->playout());
913 EXPECT_FALSE(media_channel1_->sending());
914 EXPECT_FALSE(media_channel2_->playout());
915 EXPECT_FALSE(media_channel2_->sending());
916 EXPECT_TRUE(channel2_->Enable(true));
917 EXPECT_TRUE(media_channel2_->playout());
918 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000919 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
920 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 EXPECT_TRUE(media_channel1_->playout());
922 EXPECT_TRUE(media_channel1_->sending());
923 }
924
925 void TestMuteStream() {
926 CreateChannels(0, 0);
927 // Test that we can Mute the default channel even though the sending SSRC is
928 // unknown.
929 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
930 EXPECT_TRUE(channel1_->MuteStream(0, true));
931 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
932 EXPECT_TRUE(channel1_->MuteStream(0, false));
933 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
934
935 // Test that we can not mute an unknown SSRC.
936 EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true));
937
938 SendInitiate();
939 // After the local session description has been set, we can mute a stream
940 // with its SSRC.
941 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true));
942 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
943 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false));
944 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
945 }
946
947 // Test that changing the MediaContentDirection in the local and remote
948 // session description start playout and sending at the right time.
949 void TestMediaContentDirection() {
950 CreateChannels(0, 0);
951 typename T::Content content1;
952 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
953 typename T::Content content2;
954 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
955 // Set |content2| to be InActive.
956 content2.set_direction(cricket::MD_INACTIVE);
957
958 EXPECT_TRUE(channel1_->Enable(true));
959 EXPECT_TRUE(channel2_->Enable(true));
960 EXPECT_FALSE(media_channel1_->playout());
961 EXPECT_FALSE(media_channel1_->sending());
962 EXPECT_FALSE(media_channel2_->playout());
963 EXPECT_FALSE(media_channel2_->sending());
964
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000965 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
966 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
967 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
968 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 session1_.Connect(&session2_);
970
971 EXPECT_TRUE(media_channel1_->playout());
972 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
973 EXPECT_FALSE(media_channel2_->playout()); // local InActive
974 EXPECT_FALSE(media_channel2_->sending()); // local InActive
975
976 // Update |content2| to be RecvOnly.
977 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000978 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
979 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980
981 EXPECT_TRUE(media_channel1_->playout());
982 EXPECT_TRUE(media_channel1_->sending());
983 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
984 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
985
986 // Update |content2| to be SendRecv.
987 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000988 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
989 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990
991 EXPECT_TRUE(media_channel1_->playout());
992 EXPECT_TRUE(media_channel1_->sending());
993 EXPECT_TRUE(media_channel2_->playout());
994 EXPECT_TRUE(media_channel2_->sending());
995 }
996
997 // Test setting up a call.
998 void TestCallSetup() {
999 CreateChannels(0, 0);
1000 EXPECT_FALSE(channel1_->secure());
1001 EXPECT_TRUE(SendInitiate());
1002 EXPECT_TRUE(media_channel1_->playout());
1003 EXPECT_FALSE(media_channel1_->sending());
1004 EXPECT_TRUE(SendAccept());
1005 EXPECT_FALSE(channel1_->secure());
1006 EXPECT_TRUE(media_channel1_->sending());
1007 EXPECT_EQ(1U, media_channel1_->codecs().size());
1008 EXPECT_TRUE(media_channel2_->playout());
1009 EXPECT_TRUE(media_channel2_->sending());
1010 EXPECT_EQ(1U, media_channel2_->codecs().size());
1011 }
1012
1013 // Test that we don't crash if packets are sent during call teardown
1014 // when RTCP mux is enabled. This is a regression test against a specific
1015 // race condition that would only occur when a RTCP packet was sent during
1016 // teardown of a channel on which RTCP mux was enabled.
1017 void TestCallTeardownRtcpMux() {
1018 class LastWordMediaChannel : public T::MediaChannel {
1019 public:
1020 LastWordMediaChannel() : T::MediaChannel(NULL) {}
1021 ~LastWordMediaChannel() {
1022 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
1023 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1024 }
1025 };
1026 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1027 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001028 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 EXPECT_TRUE(SendInitiate());
1030 EXPECT_TRUE(SendAccept());
1031 EXPECT_TRUE(SendTerminate());
1032 }
1033
1034 // Send voice RTP data to the other side and ensure it gets there.
1035 void SendRtpToRtp() {
1036 CreateChannels(0, 0);
1037 EXPECT_TRUE(SendInitiate());
1038 EXPECT_TRUE(SendAccept());
1039 EXPECT_EQ(1U, GetTransport1()->channels().size());
1040 EXPECT_EQ(1U, GetTransport2()->channels().size());
1041 EXPECT_TRUE(SendRtp1());
1042 EXPECT_TRUE(SendRtp2());
1043 EXPECT_TRUE(CheckRtp1());
1044 EXPECT_TRUE(CheckRtp2());
1045 EXPECT_TRUE(CheckNoRtp1());
1046 EXPECT_TRUE(CheckNoRtp2());
1047 }
1048
1049 // Check that RTCP is not transmitted if both sides don't support RTCP.
1050 void SendNoRtcpToNoRtcp() {
1051 CreateChannels(0, 0);
1052 EXPECT_TRUE(SendInitiate());
1053 EXPECT_TRUE(SendAccept());
1054 EXPECT_EQ(1U, GetTransport1()->channels().size());
1055 EXPECT_EQ(1U, GetTransport2()->channels().size());
1056 EXPECT_FALSE(SendRtcp1());
1057 EXPECT_FALSE(SendRtcp2());
1058 EXPECT_TRUE(CheckNoRtcp1());
1059 EXPECT_TRUE(CheckNoRtcp2());
1060 }
1061
1062 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1063 void SendNoRtcpToRtcp() {
1064 CreateChannels(0, RTCP);
1065 EXPECT_TRUE(SendInitiate());
1066 EXPECT_TRUE(SendAccept());
1067 EXPECT_EQ(1U, GetTransport1()->channels().size());
1068 EXPECT_EQ(2U, GetTransport2()->channels().size());
1069 EXPECT_FALSE(SendRtcp1());
1070 EXPECT_FALSE(SendRtcp2());
1071 EXPECT_TRUE(CheckNoRtcp1());
1072 EXPECT_TRUE(CheckNoRtcp2());
1073 }
1074
1075 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1076 void SendRtcpToNoRtcp() {
1077 CreateChannels(RTCP, 0);
1078 EXPECT_TRUE(SendInitiate());
1079 EXPECT_TRUE(SendAccept());
1080 EXPECT_EQ(2U, GetTransport1()->channels().size());
1081 EXPECT_EQ(1U, GetTransport2()->channels().size());
1082 EXPECT_FALSE(SendRtcp1());
1083 EXPECT_FALSE(SendRtcp2());
1084 EXPECT_TRUE(CheckNoRtcp1());
1085 EXPECT_TRUE(CheckNoRtcp2());
1086 }
1087
1088 // Check that RTCP is transmitted if both sides support RTCP.
1089 void SendRtcpToRtcp() {
1090 CreateChannels(RTCP, RTCP);
1091 EXPECT_TRUE(SendInitiate());
1092 EXPECT_TRUE(SendAccept());
1093 EXPECT_EQ(2U, GetTransport1()->channels().size());
1094 EXPECT_EQ(2U, GetTransport2()->channels().size());
1095 EXPECT_TRUE(SendRtcp1());
1096 EXPECT_TRUE(SendRtcp2());
1097 EXPECT_TRUE(CheckRtcp1());
1098 EXPECT_TRUE(CheckRtcp2());
1099 EXPECT_TRUE(CheckNoRtcp1());
1100 EXPECT_TRUE(CheckNoRtcp2());
1101 }
1102
1103 // Check that RTCP is transmitted if only the initiator supports mux.
1104 void SendRtcpMuxToRtcp() {
1105 CreateChannels(RTCP | RTCP_MUX, RTCP);
1106 EXPECT_TRUE(SendInitiate());
1107 EXPECT_TRUE(SendAccept());
1108 EXPECT_EQ(2U, GetTransport1()->channels().size());
1109 EXPECT_EQ(2U, GetTransport2()->channels().size());
1110 EXPECT_TRUE(SendRtcp1());
1111 EXPECT_TRUE(SendRtcp2());
1112 EXPECT_TRUE(CheckRtcp1());
1113 EXPECT_TRUE(CheckRtcp2());
1114 EXPECT_TRUE(CheckNoRtcp1());
1115 EXPECT_TRUE(CheckNoRtcp2());
1116 }
1117
1118 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1119 void SendRtcpMuxToRtcpMux() {
1120 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1121 EXPECT_TRUE(SendInitiate());
1122 EXPECT_EQ(2U, GetTransport1()->channels().size());
1123 EXPECT_EQ(1U, GetTransport2()->channels().size());
1124 EXPECT_TRUE(SendAccept());
1125 EXPECT_EQ(1U, GetTransport1()->channels().size());
1126 EXPECT_TRUE(SendRtp1());
1127 EXPECT_TRUE(SendRtp2());
1128 EXPECT_TRUE(SendRtcp1());
1129 EXPECT_TRUE(SendRtcp2());
1130 EXPECT_TRUE(CheckRtp1());
1131 EXPECT_TRUE(CheckRtp2());
1132 EXPECT_TRUE(CheckNoRtp1());
1133 EXPECT_TRUE(CheckNoRtp2());
1134 EXPECT_TRUE(CheckRtcp1());
1135 EXPECT_TRUE(CheckRtcp2());
1136 EXPECT_TRUE(CheckNoRtcp1());
1137 EXPECT_TRUE(CheckNoRtcp2());
1138 }
1139
1140 // Check that RTCP data sent by the initiator before the accept is not muxed.
1141 void SendEarlyRtcpMuxToRtcp() {
1142 CreateChannels(RTCP | RTCP_MUX, RTCP);
1143 EXPECT_TRUE(SendInitiate());
1144 EXPECT_EQ(2U, GetTransport1()->channels().size());
1145 EXPECT_EQ(2U, GetTransport2()->channels().size());
1146
1147 // RTCP can be sent before the call is accepted, if the transport is ready.
1148 // It should not be muxed though, as the remote side doesn't support mux.
1149 EXPECT_TRUE(SendRtcp1());
1150 EXPECT_TRUE(CheckNoRtp2());
1151 EXPECT_TRUE(CheckRtcp2());
1152
1153 // Send RTCP packet from callee and verify that it is received.
1154 EXPECT_TRUE(SendRtcp2());
1155 EXPECT_TRUE(CheckNoRtp1());
1156 EXPECT_TRUE(CheckRtcp1());
1157
1158 // Complete call setup and ensure everything is still OK.
1159 EXPECT_TRUE(SendAccept());
1160 EXPECT_EQ(2U, GetTransport1()->channels().size());
1161 EXPECT_TRUE(SendRtcp1());
1162 EXPECT_TRUE(CheckRtcp2());
1163 EXPECT_TRUE(SendRtcp2());
1164 EXPECT_TRUE(CheckRtcp1());
1165 }
1166
1167
1168 // Check that RTCP data is not muxed until both sides have enabled muxing,
1169 // but that we properly demux before we get the accept message, since there
1170 // is a race between RTP data and the jingle accept.
1171 void SendEarlyRtcpMuxToRtcpMux() {
1172 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1173 EXPECT_TRUE(SendInitiate());
1174 EXPECT_EQ(2U, GetTransport1()->channels().size());
1175 EXPECT_EQ(1U, GetTransport2()->channels().size());
1176
1177 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1178 // we haven't yet received the accept that says we should mux.
1179 EXPECT_FALSE(SendRtcp1());
1180
1181 // Send muxed RTCP packet from callee and verify that it is received.
1182 EXPECT_TRUE(SendRtcp2());
1183 EXPECT_TRUE(CheckNoRtp1());
1184 EXPECT_TRUE(CheckRtcp1());
1185
1186 // Complete call setup and ensure everything is still OK.
1187 EXPECT_TRUE(SendAccept());
1188 EXPECT_EQ(1U, GetTransport1()->channels().size());
1189 EXPECT_TRUE(SendRtcp1());
1190 EXPECT_TRUE(CheckRtcp2());
1191 EXPECT_TRUE(SendRtcp2());
1192 EXPECT_TRUE(CheckRtcp1());
1193 }
1194
1195 // Test that we properly send SRTP with RTCP in both directions.
1196 // You can pass in DTLS and/or RTCP_MUX as flags.
1197 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1198 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1199 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1200
1201 int flags1 = RTCP | SECURE | flags1_in;
1202 int flags2 = RTCP | SECURE | flags2_in;
1203 bool dtls1 = !!(flags1_in & DTLS);
1204 bool dtls2 = !!(flags2_in & DTLS);
1205 CreateChannels(flags1, flags2);
1206 EXPECT_FALSE(channel1_->secure());
1207 EXPECT_FALSE(channel2_->secure());
1208 EXPECT_TRUE(SendInitiate());
1209 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1210 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1211 EXPECT_TRUE(SendAccept());
1212 EXPECT_TRUE(channel1_->secure());
1213 EXPECT_TRUE(channel2_->secure());
1214 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1215 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1216 EXPECT_TRUE(SendRtp1());
1217 EXPECT_TRUE(SendRtp2());
1218 EXPECT_TRUE(SendRtcp1());
1219 EXPECT_TRUE(SendRtcp2());
1220 EXPECT_TRUE(CheckRtp1());
1221 EXPECT_TRUE(CheckRtp2());
1222 EXPECT_TRUE(CheckNoRtp1());
1223 EXPECT_TRUE(CheckNoRtp2());
1224 EXPECT_TRUE(CheckRtcp1());
1225 EXPECT_TRUE(CheckRtcp2());
1226 EXPECT_TRUE(CheckNoRtcp1());
1227 EXPECT_TRUE(CheckNoRtcp2());
1228 }
1229
1230 // Test that we properly handling SRTP negotiating down to RTP.
1231 void SendSrtpToRtp() {
1232 CreateChannels(RTCP | SECURE, RTCP);
1233 EXPECT_FALSE(channel1_->secure());
1234 EXPECT_FALSE(channel2_->secure());
1235 EXPECT_TRUE(SendInitiate());
1236 EXPECT_TRUE(SendAccept());
1237 EXPECT_FALSE(channel1_->secure());
1238 EXPECT_FALSE(channel2_->secure());
1239 EXPECT_TRUE(SendRtp1());
1240 EXPECT_TRUE(SendRtp2());
1241 EXPECT_TRUE(SendRtcp1());
1242 EXPECT_TRUE(SendRtcp2());
1243 EXPECT_TRUE(CheckRtp1());
1244 EXPECT_TRUE(CheckRtp2());
1245 EXPECT_TRUE(CheckNoRtp1());
1246 EXPECT_TRUE(CheckNoRtp2());
1247 EXPECT_TRUE(CheckRtcp1());
1248 EXPECT_TRUE(CheckRtcp2());
1249 EXPECT_TRUE(CheckNoRtcp1());
1250 EXPECT_TRUE(CheckNoRtcp2());
1251 }
1252
1253 // Test that we can send and receive early media when a provisional answer is
1254 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1255 void SendEarlyMediaUsingRtcpMuxSrtp() {
1256 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1257
1258 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1259 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1260 EXPECT_TRUE(SendOffer());
1261 EXPECT_TRUE(SendProvisionalAnswer());
1262 EXPECT_TRUE(channel1_->secure());
1263 EXPECT_TRUE(channel2_->secure());
1264 EXPECT_EQ(2U, GetTransport1()->channels().size());
1265 EXPECT_EQ(2U, GetTransport2()->channels().size());
1266 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1267 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1268 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1269 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1270
1271 // Send packets from callee and verify that it is received.
1272 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1273 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1274 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1275 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1276
1277 // Complete call setup and ensure everything is still OK.
1278 EXPECT_TRUE(SendFinalAnswer());
1279 EXPECT_EQ(1U, GetTransport1()->channels().size());
1280 EXPECT_EQ(1U, GetTransport2()->channels().size());
1281 EXPECT_TRUE(channel1_->secure());
1282 EXPECT_TRUE(channel2_->secure());
1283 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1284 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1285 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1286 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1287 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1288 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1289 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1290 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1291 }
1292
1293 // Test that we properly send RTP without SRTP from a thread.
1294 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001295 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1296 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 EXPECT_TRUE(SendInitiate());
1298 EXPECT_TRUE(SendAccept());
1299 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1300 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001301 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1302 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1304 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1305 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1306 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1307 EXPECT_TRUE(CheckNoRtp1());
1308 EXPECT_TRUE(CheckNoRtp2());
1309 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1310 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1311 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1312 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1313 EXPECT_TRUE(CheckNoRtcp1());
1314 EXPECT_TRUE(CheckNoRtcp2());
1315 }
1316
1317 // Test that we properly send SRTP with RTCP from a thread.
1318 void SendSrtpToSrtpOnThread() {
1319 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1320 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1321 EXPECT_TRUE(SendInitiate());
1322 EXPECT_TRUE(SendAccept());
1323 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1324 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1325 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1326 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1327 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1328 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1329 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1330 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1331 EXPECT_TRUE(CheckNoRtp1());
1332 EXPECT_TRUE(CheckNoRtp2());
1333 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1334 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1335 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1336 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1337 EXPECT_TRUE(CheckNoRtcp1());
1338 EXPECT_TRUE(CheckNoRtcp2());
1339 }
1340
1341 // Test that the mediachannel retains its sending state after the transport
1342 // becomes non-writable.
1343 void SendWithWritabilityLoss() {
1344 CreateChannels(0, 0);
1345 EXPECT_TRUE(SendInitiate());
1346 EXPECT_TRUE(SendAccept());
1347 EXPECT_EQ(1U, GetTransport1()->channels().size());
1348 EXPECT_EQ(1U, GetTransport2()->channels().size());
1349 EXPECT_TRUE(SendRtp1());
1350 EXPECT_TRUE(SendRtp2());
1351 EXPECT_TRUE(CheckRtp1());
1352 EXPECT_TRUE(CheckRtp2());
1353 EXPECT_TRUE(CheckNoRtp1());
1354 EXPECT_TRUE(CheckNoRtp2());
1355
wu@webrtc.org97077a32013-10-25 21:18:33 +00001356 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 EXPECT_FALSE(SendRtp1());
1359 EXPECT_TRUE(SendRtp2());
1360 EXPECT_TRUE(CheckRtp1());
1361 EXPECT_TRUE(CheckNoRtp2());
1362
1363 // Regain writability
1364 GetTransport1()->SetWritable(true);
1365 EXPECT_TRUE(media_channel1_->sending());
1366 EXPECT_TRUE(SendRtp1());
1367 EXPECT_TRUE(SendRtp2());
1368 EXPECT_TRUE(CheckRtp1());
1369 EXPECT_TRUE(CheckRtp2());
1370 EXPECT_TRUE(CheckNoRtp1());
1371 EXPECT_TRUE(CheckNoRtp2());
1372
1373 // Lose writability completely
1374 GetTransport1()->SetDestination(NULL);
1375 EXPECT_TRUE(media_channel1_->sending());
1376
wu@webrtc.org97077a32013-10-25 21:18:33 +00001377 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 EXPECT_FALSE(SendRtp1());
1379 EXPECT_TRUE(SendRtp2());
1380 EXPECT_TRUE(CheckRtp1());
1381 EXPECT_TRUE(CheckNoRtp2());
1382
1383 // Gain writability back
1384 GetTransport1()->SetDestination(GetTransport2());
1385 EXPECT_TRUE(media_channel1_->sending());
1386 EXPECT_TRUE(SendRtp1());
1387 EXPECT_TRUE(SendRtp2());
1388 EXPECT_TRUE(CheckRtp1());
1389 EXPECT_TRUE(CheckRtp2());
1390 EXPECT_TRUE(CheckNoRtp1());
1391 EXPECT_TRUE(CheckNoRtp2());
1392 }
1393
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001394 void SendBundleToBundle(
1395 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1396 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001398 // Only pl_type1 was added to the bundle filter for both |channel1_|
1399 // and |channel2_|.
1400 int pl_type1 = pl_types[0];
1401 int pl_type2 = pl_types[1];
1402 int flags = SSRC_MUX | RTCP;
1403 if (secure) flags |= SECURE;
1404 uint32 expected_channels = 2U;
1405 if (rtcp_mux) {
1406 flags |= RTCP_MUX;
1407 expected_channels = 1U;
1408 }
1409 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 EXPECT_TRUE(SendInitiate());
1411 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001412 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001414 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1415 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1416 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1417 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1418 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1419 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1420 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1421 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1422 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1423 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1424 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1425 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1426
1427 // Both channels can receive pl_type1 only.
1428 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1429 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1430 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1431 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1432 EXPECT_TRUE(CheckNoRtp1());
1433 EXPECT_TRUE(CheckNoRtp2());
1434
1435 // RTCP test
1436 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1437 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1438 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1439 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1440
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1442 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1444 EXPECT_TRUE(CheckNoRtcp1());
1445 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1446 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001448 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1449 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1452 }
1453
1454 // Test that the media monitor can be run and gives timely callbacks.
1455 void TestMediaMonitor() {
1456 static const int kTimeout = 500;
1457 CreateChannels(0, 0);
1458 EXPECT_TRUE(SendInitiate());
1459 EXPECT_TRUE(SendAccept());
1460 channel1_->StartMediaMonitor(100);
1461 channel2_->StartMediaMonitor(100);
1462 // Ensure we get callbacks and stop.
1463 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1464 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1465 channel1_->StopMediaMonitor();
1466 channel2_->StopMediaMonitor();
1467 // Ensure a restart of a stopped monitor works.
1468 channel1_->StartMediaMonitor(100);
1469 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1470 channel1_->StopMediaMonitor();
1471 // Ensure stopping a stopped monitor is OK.
1472 channel1_->StopMediaMonitor();
1473 }
1474
1475 void TestMediaSinks() {
1476 CreateChannels(0, 0);
1477 EXPECT_TRUE(SendInitiate());
1478 EXPECT_TRUE(SendAccept());
1479 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1480 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1481 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1482 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1483
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001484 rtc::Pathname path;
1485 EXPECT_TRUE(rtc::Filesystem::GetTemporaryFolder(path, true, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486 path.SetFilename("sink-test.rtpdump");
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001487 rtc::scoped_ptr<cricket::RtpDumpSink> sink(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 new cricket::RtpDumpSink(Open(path.pathname())));
1489 sink->set_packet_filter(cricket::PF_ALL);
1490 EXPECT_TRUE(sink->Enable(true));
1491 channel1_->RegisterSendSink(
1492 sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
1493 EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1494 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1495 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1496 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1497
1498 // The first packet is recorded with header + data.
1499 EXPECT_TRUE(SendRtp1());
1500 // The second packet is recorded with header only.
1501 sink->set_packet_filter(cricket::PF_RTPHEADER);
1502 EXPECT_TRUE(SendRtp1());
1503 // The third packet is not recorded since sink is disabled.
1504 EXPECT_TRUE(sink->Enable(false));
1505 EXPECT_TRUE(SendRtp1());
1506 // The fourth packet is not recorded since sink is unregistered.
1507 EXPECT_TRUE(sink->Enable(true));
1508 channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
1509 EXPECT_TRUE(SendRtp1());
1510 sink.reset(); // This will close the file.
1511
1512 // Read the recorded file and verify two packets.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001513 rtc::scoped_ptr<rtc::StreamInterface> stream(
1514 rtc::Filesystem::OpenFile(path, "rb"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515
1516 cricket::RtpDumpReader reader(stream.get());
1517 cricket::RtpDumpPacket packet;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001518 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001519 std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
1520 packet.data.size());
1521 EXPECT_EQ(rtp_packet_, read_packet);
1522
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001523 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524 size_t len = 0;
1525 packet.GetRtpHeaderLen(&len);
1526 EXPECT_EQ(len, packet.data.size());
1527 EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
1528
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001529 EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530
1531 // Delete the file for media recording.
1532 stream.reset();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001533 EXPECT_TRUE(rtc::Filesystem::DeleteFile(path));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001534 }
1535
1536 void TestSetContentFailure() {
1537 CreateChannels(0, 0);
1538 typename T::Content content;
1539 cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1540 cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1541
1542 // Set up the session description.
1543 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1544 sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1545 new cricket::AudioContentDescription());
1546 sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1547 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001548 session1_.set_local_description(sdesc_loc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001549 sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1550 new cricket::AudioContentDescription());
1551 sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1552 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001553 session1_.set_remote_description(sdesc_rem);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554
1555 // Test failures in SetLocalContent.
1556 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001557 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001558 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1560 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001561 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001562 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1564
1565 // Test failures in SetRemoteContent.
1566 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001567 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001568 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001569 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1570 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001571 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001572 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1574 }
1575
1576 void TestSendTwoOffers() {
1577 CreateChannels(0, 0);
1578
1579 // Set up the initial session description.
1580 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001581 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001583 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001584 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1586 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1587
1588 // Update the local description and set the state again.
1589 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001590 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001591
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001592 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1594 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1595 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1596 }
1597
1598 void TestReceiveTwoOffers() {
1599 CreateChannels(0, 0);
1600
1601 // Set up the initial session description.
1602 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001603 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001605 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001606 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1608 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1609
1610 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001611 session1_.set_remote_description(sdesc);
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001612 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1614 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1615 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1616 }
1617
1618 void TestSendPrAnswer() {
1619 CreateChannels(0, 0);
1620
1621 // Set up the initial session description.
1622 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001623 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001625 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001626 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1628 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1629
1630 // Send PRANSWER
1631 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001632 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001634 session1_.SetState(cricket::Session::STATE_SENTPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1636 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1637 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1638
1639 // Send ACCEPT
1640 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001641 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001643 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1645 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1646 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1647 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1648 }
1649
1650 void TestReceivePrAnswer() {
1651 CreateChannels(0, 0);
1652
1653 // Set up the initial session description.
1654 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001655 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001657 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001658 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1660 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1661
1662 // Receive PRANSWER
1663 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001664 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001666 session1_.SetState(cricket::Session::STATE_RECEIVEDPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1668 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1669 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1670
1671 // Receive ACCEPT
1672 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001673 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674
pthatcher@webrtc.org4cb38562014-12-18 02:28:25 +00001675 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1677 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1678 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1679 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1680 }
1681
1682 void TestFlushRtcp() {
1683 bool send_rtcp1;
1684
1685 CreateChannels(RTCP, RTCP);
1686 EXPECT_TRUE(SendInitiate());
1687 EXPECT_TRUE(SendAccept());
1688 EXPECT_EQ(2U, GetTransport1()->channels().size());
1689 EXPECT_EQ(2U, GetTransport2()->channels().size());
1690
1691 // Send RTCP1 from a different thread.
1692 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1693 EXPECT_TRUE(send_rtcp1);
1694 // The sending message is only posted. channel2_ should be empty.
1695 EXPECT_TRUE(CheckNoRtcp2());
1696
1697 // When channel1_ is deleted, the RTCP packet should be sent out to
1698 // channel2_.
1699 channel1_.reset();
1700 EXPECT_TRUE(CheckRtcp2());
1701 }
1702
1703 void TestChangeStateError() {
1704 CreateChannels(RTCP, RTCP);
1705 EXPECT_TRUE(SendInitiate());
1706 media_channel2_->set_fail_set_send(true);
1707 EXPECT_TRUE(channel2_->Enable(true));
1708 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1709 error_);
1710 }
1711
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001712 void TestSrtpError(int pl_type) {
1713 // For Audio, only pl_type 0 is added to the bundle filter.
1714 // For Video, only pl_type 97 is added to the bundle filter.
1715 // So we need to pass in pl_type so that the packet can pass through
1716 // the bundle filter before it can be processed by the srtp filter.
1717 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001718 unsigned const char kBadPacket[] = {0x84,
1719 static_cast<unsigned char>(pl_type),
1720 0x00,
1721 0x01,
1722 0x00,
1723 0x00,
1724 0x00,
1725 0x00,
1726 0x00,
1727 0x00,
1728 0x00,
1729 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1731 EXPECT_FALSE(channel1_->secure());
1732 EXPECT_FALSE(channel2_->secure());
1733 EXPECT_TRUE(SendInitiate());
1734 EXPECT_TRUE(SendAccept());
1735 EXPECT_TRUE(channel1_->secure());
1736 EXPECT_TRUE(channel2_->secure());
1737 channel2_->set_srtp_signal_silent_time(200);
1738
1739 // Testing failures in sending packets.
1740 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1741 // The first failure will trigger an error.
1742 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1743 error_ = T::MediaChannel::ERROR_NONE;
1744 // The next 1 sec failures will not trigger an error.
1745 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1746 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001747 rtc::Thread::Current()->ProcessMessages(210);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1749 // The error will be triggered again.
1750 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1751 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1752
1753 // Testing failures in receiving packets.
1754 error_ = T::MediaChannel::ERROR_NONE;
1755 cricket::TransportChannel* transport_channel =
1756 channel2_->transport_channel();
1757 transport_channel->SignalReadPacket(
1758 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001759 sizeof(kBadPacket), rtc::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001760 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 }
1762
1763 void TestOnReadyToSend() {
1764 CreateChannels(RTCP, RTCP);
1765 TransportChannel* rtp = channel1_->transport_channel();
1766 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1767 EXPECT_FALSE(media_channel1_->ready_to_send());
1768 rtp->SignalReadyToSend(rtp);
1769 EXPECT_FALSE(media_channel1_->ready_to_send());
1770 rtcp->SignalReadyToSend(rtcp);
1771 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1772 // channel are ready to send.
1773 EXPECT_TRUE(media_channel1_->ready_to_send());
1774
1775 // rtp channel becomes not ready to send will be propagated to mediachannel
1776 channel1_->SetReadyToSend(rtp, false);
1777 EXPECT_FALSE(media_channel1_->ready_to_send());
1778 channel1_->SetReadyToSend(rtp, true);
1779 EXPECT_TRUE(media_channel1_->ready_to_send());
1780
1781 // rtcp channel becomes not ready to send will be propagated to mediachannel
1782 channel1_->SetReadyToSend(rtcp, false);
1783 EXPECT_FALSE(media_channel1_->ready_to_send());
1784 channel1_->SetReadyToSend(rtcp, true);
1785 EXPECT_TRUE(media_channel1_->ready_to_send());
1786 }
1787
1788 void TestOnReadyToSendWithRtcpMux() {
1789 CreateChannels(RTCP, RTCP);
1790 typename T::Content content;
1791 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1792 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1793 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001794 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1795 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1797 TransportChannel* rtp = channel1_->transport_channel();
1798 EXPECT_FALSE(media_channel1_->ready_to_send());
1799 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1800 // should trigger the MediaChannel's OnReadyToSend.
1801 rtp->SignalReadyToSend(rtp);
1802 EXPECT_TRUE(media_channel1_->ready_to_send());
1803 channel1_->SetReadyToSend(rtp, false);
1804 EXPECT_FALSE(media_channel1_->ready_to_send());
1805 }
1806
1807 protected:
1808 cricket::FakeSession session1_;
1809 cricket::FakeSession session2_;
1810 cricket::FakeMediaEngine media_engine_;
1811 // The media channels are owned by the voice channel objects below.
1812 typename T::MediaChannel* media_channel1_;
1813 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001814 rtc::scoped_ptr<typename T::Channel> channel1_;
1815 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 typename T::Content local_media_content1_;
1817 typename T::Content local_media_content2_;
1818 typename T::Content remote_media_content1_;
1819 typename T::Content remote_media_content2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001820 rtc::scoped_ptr<rtc::SSLIdentity> identity1_;
1821 rtc::scoped_ptr<rtc::SSLIdentity> identity2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 // The RTP and RTCP packets to send in the tests.
1823 std::string rtp_packet_;
1824 std::string rtcp_packet_;
1825 int media_info_callbacks1_;
1826 int media_info_callbacks2_;
1827 bool mute_callback_recved_;
1828 bool mute_callback_value_;
1829
1830 uint32 ssrc_;
1831 typename T::MediaChannel::Error error_;
1832};
1833
1834
1835template<>
1836void ChannelTest<VoiceTraits>::CreateContent(
1837 int flags,
1838 const cricket::AudioCodec& audio_codec,
1839 const cricket::VideoCodec& video_codec,
1840 cricket::AudioContentDescription* audio) {
1841 audio->AddCodec(audio_codec);
1842 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1843 if (flags & SECURE) {
1844 audio->AddCrypto(cricket::CryptoParams(
1845 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001846 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 }
1848}
1849
1850template<>
1851void ChannelTest<VoiceTraits>::CopyContent(
1852 const cricket::AudioContentDescription& source,
1853 cricket::AudioContentDescription* audio) {
1854 *audio = source;
1855}
1856
1857template<>
1858bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1859 const cricket::AudioCodec& c2) {
1860 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1861 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1862}
1863
1864template<>
1865void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1866 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1867 audio->AddLegacyStream(ssrc);
1868}
1869
1870class VoiceChannelTest
1871 : public ChannelTest<VoiceTraits> {
1872 public:
1873 typedef ChannelTest<VoiceTraits>
1874 Base;
1875 VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1876 kRtcpReport, sizeof(kRtcpReport)) {
1877 }
1878
1879 void TestSetChannelOptions() {
1880 CreateChannels(0, 0);
1881
1882 cricket::AudioOptions options1;
1883 options1.echo_cancellation.Set(false);
1884 cricket::AudioOptions options2;
1885 options2.echo_cancellation.Set(true);
1886
1887 channel1_->SetChannelOptions(options1);
1888 channel2_->SetChannelOptions(options1);
1889 cricket::AudioOptions actual_options;
1890 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1891 EXPECT_EQ(options1, actual_options);
1892 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1893 EXPECT_EQ(options1, actual_options);
1894
1895 channel1_->SetChannelOptions(options2);
1896 channel2_->SetChannelOptions(options2);
1897 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1898 EXPECT_EQ(options2, actual_options);
1899 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1900 EXPECT_EQ(options2, actual_options);
1901 }
1902};
1903
1904// override to add NULL parameter
1905template<>
1906cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001907 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1909 bool rtcp) {
1910 cricket::VideoChannel* channel = new cricket::VideoChannel(
1911 thread, engine, ch, session, cricket::CN_VIDEO, rtcp, NULL);
1912 if (!channel->Init()) {
1913 delete channel;
1914 channel = NULL;
1915 }
1916 return channel;
1917}
1918
1919// override to add 0 parameter
1920template<>
1921bool ChannelTest<VideoTraits>::AddStream1(int id) {
1922 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1923}
1924
1925template<>
1926void ChannelTest<VideoTraits>::CreateContent(
1927 int flags,
1928 const cricket::AudioCodec& audio_codec,
1929 const cricket::VideoCodec& video_codec,
1930 cricket::VideoContentDescription* video) {
1931 video->AddCodec(video_codec);
1932 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1933 if (flags & SECURE) {
1934 video->AddCrypto(cricket::CryptoParams(
1935 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001936 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001937 }
1938}
1939
1940template<>
1941void ChannelTest<VideoTraits>::CopyContent(
1942 const cricket::VideoContentDescription& source,
1943 cricket::VideoContentDescription* video) {
1944 *video = source;
1945}
1946
1947template<>
1948bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1949 const cricket::VideoCodec& c2) {
1950 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1951 c1.framerate == c2.framerate;
1952}
1953
1954template<>
1955void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1956 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1957 video->AddLegacyStream(ssrc);
1958}
1959
1960class VideoChannelTest
1961 : public ChannelTest<VideoTraits> {
1962 public:
1963 typedef ChannelTest<VideoTraits>
1964 Base;
1965 VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
1966 kRtcpReport, sizeof(kRtcpReport)) {
1967 }
1968
1969 void TestSetChannelOptions() {
1970 CreateChannels(0, 0);
1971
1972 cricket::VideoOptions o1, o2;
1973 o1.video_noise_reduction.Set(true);
1974
1975 channel1_->SetChannelOptions(o1);
1976 channel2_->SetChannelOptions(o1);
1977 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
1978 EXPECT_EQ(o1, o2);
1979 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
1980 EXPECT_EQ(o1, o2);
1981
buildbot@webrtc.org81ddc782014-10-14 22:39:24 +00001982 o1.video_start_bitrate.Set(123);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 channel1_->SetChannelOptions(o1);
1984 channel2_->SetChannelOptions(o1);
1985 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
1986 EXPECT_EQ(o1, o2);
1987 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
1988 EXPECT_EQ(o1, o2);
1989 }
1990};
1991
1992
1993// VoiceChannelTest
1994
1995TEST_F(VoiceChannelTest, TestInit) {
1996 Base::TestInit();
1997 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
1998 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
1999}
2000
2001TEST_F(VoiceChannelTest, TestSetContents) {
2002 Base::TestSetContents();
2003}
2004
2005TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2006 Base::TestSetContentsNullOffer();
2007}
2008
2009TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2010 Base::TestSetContentsRtcpMux();
2011}
2012
2013TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2014 Base::TestSetContentsRtcpMux();
2015}
2016
2017TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2018 Base::TestSetRemoteContentUpdate();
2019}
2020
2021TEST_F(VoiceChannelTest, TestStreams) {
2022 Base::TestStreams();
2023}
2024
2025TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2026 Base::TestUpdateStreamsInLocalContent();
2027}
2028
2029TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2030 Base::TestUpdateStreamsInRemoteContent();
2031}
2032
2033TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2034 Base::TestChangeStreamParamsInContent();
2035}
2036
2037TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2038 Base::TestPlayoutAndSendingStates();
2039}
2040
2041TEST_F(VoiceChannelTest, TestMuteStream) {
2042 Base::TestMuteStream();
2043}
2044
2045TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2046 Base::TestMediaContentDirection();
2047}
2048
2049TEST_F(VoiceChannelTest, TestCallSetup) {
2050 Base::TestCallSetup();
2051}
2052
2053TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2054 Base::TestCallTeardownRtcpMux();
2055}
2056
2057TEST_F(VoiceChannelTest, SendRtpToRtp) {
2058 Base::SendRtpToRtp();
2059}
2060
2061TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2062 Base::SendNoRtcpToNoRtcp();
2063}
2064
2065TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2066 Base::SendNoRtcpToRtcp();
2067}
2068
2069TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2070 Base::SendRtcpToNoRtcp();
2071}
2072
2073TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2074 Base::SendRtcpToRtcp();
2075}
2076
2077TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2078 Base::SendRtcpMuxToRtcp();
2079}
2080
2081TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2082 Base::SendRtcpMuxToRtcpMux();
2083}
2084
2085TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2086 Base::SendEarlyRtcpMuxToRtcp();
2087}
2088
2089TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2090 Base::SendEarlyRtcpMuxToRtcpMux();
2091}
2092
2093TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2094 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2095}
2096
2097TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2098 Base::SendSrtpToSrtp();
2099}
2100
2101TEST_F(VoiceChannelTest, SendSrtcpMux) {
2102 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2103}
2104
2105TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2106 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2107 Base::SendSrtpToSrtp(DTLS, 0);
2108}
2109
2110TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2111 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2112 Base::SendSrtpToSrtp(DTLS, DTLS);
2113}
2114
2115TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2116 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2117 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2118}
2119
2120TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2121 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2122}
2123
2124TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2125 Base::SendRtpToRtpOnThread();
2126}
2127
2128TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2129 Base::SendSrtpToSrtpOnThread();
2130}
2131
2132TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2133 Base::SendWithWritabilityLoss();
2134}
2135
2136TEST_F(VoiceChannelTest, TestMediaMonitor) {
2137 Base::TestMediaMonitor();
2138}
2139
2140// Test that MuteStream properly forwards to the media channel and does
2141// not signal.
2142TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
2143 CreateChannels(0, 0);
2144 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2145 EXPECT_FALSE(mute_callback_recved_);
2146 EXPECT_TRUE(channel1_->MuteStream(0, true));
2147 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2148 EXPECT_FALSE(mute_callback_recved_);
2149 EXPECT_TRUE(channel1_->MuteStream(0, false));
2150 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2151 EXPECT_FALSE(mute_callback_recved_);
2152}
2153
2154// Test that keyboard automute works correctly and signals upwards.
asapersson@webrtc.orgb533a822013-09-23 19:47:49 +00002155TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 CreateChannels(0, 0);
2157 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2158 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
2159
2160 cricket::VoiceMediaChannel::Error e =
2161 cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
2162
2163 // Typing doesn't mute automatically unless typing monitor has been installed
2164 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002165 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 EXPECT_EQ(e, error_);
2167 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2168 EXPECT_FALSE(mute_callback_recved_);
2169
2170 cricket::TypingMonitorOptions o = {0};
2171 o.mute_period = 1500;
2172 channel1_->StartTypingMonitor(o);
2173 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002174 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2176 EXPECT_TRUE(mute_callback_recved_);
2177}
2178
2179// Test that PressDTMF properly forwards to the media channel.
2180TEST_F(VoiceChannelTest, TestDtmf) {
2181 CreateChannels(0, 0);
2182 EXPECT_TRUE(SendInitiate());
2183 EXPECT_TRUE(SendAccept());
2184 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2185
2186 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2187 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2188
2189 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2190 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2191 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2192 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2193 0, 8, 160, cricket::DF_SEND));
2194}
2195
2196// Test that InsertDtmf properly forwards to the media channel.
2197TEST_F(VoiceChannelTest, TestInsertDtmf) {
2198 CreateChannels(0, 0);
2199 EXPECT_TRUE(SendInitiate());
2200 EXPECT_TRUE(SendAccept());
2201 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2204 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2205 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2206 cricket::DF_PLAY | cricket::DF_SEND));
2207
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002208 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002211 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002213 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2215}
2216
2217TEST_F(VoiceChannelTest, TestMediaSinks) {
2218 Base::TestMediaSinks();
2219}
2220
2221TEST_F(VoiceChannelTest, TestSetContentFailure) {
2222 Base::TestSetContentFailure();
2223}
2224
2225TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2226 Base::TestSendTwoOffers();
2227}
2228
2229TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2230 Base::TestReceiveTwoOffers();
2231}
2232
2233TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2234 Base::TestSendPrAnswer();
2235}
2236
2237TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2238 Base::TestReceivePrAnswer();
2239}
2240
2241TEST_F(VoiceChannelTest, TestFlushRtcp) {
2242 Base::TestFlushRtcp();
2243}
2244
2245TEST_F(VoiceChannelTest, TestChangeStateError) {
2246 Base::TestChangeStateError();
2247}
2248
2249TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002250 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251}
2252
2253TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2254 Base::TestOnReadyToSend();
2255}
2256
2257TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2258 Base::TestOnReadyToSendWithRtcpMux();
2259}
2260
2261// Test that we can play a ringback tone properly.
2262TEST_F(VoiceChannelTest, TestRingbackTone) {
2263 CreateChannels(RTCP, RTCP);
2264 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2265 EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
2266 EXPECT_TRUE(SendInitiate());
2267 EXPECT_TRUE(SendAccept());
2268 // Play ringback tone, no loop.
2269 EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
2270 EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
2271 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2272 EXPECT_FALSE(media_channel1_->ringback_tone_loop());
2273 // Stop the ringback tone.
2274 EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
2275 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2276 // Add a stream.
2277 EXPECT_TRUE(AddStream1(1));
2278 // Play ringback tone, looping, on the new stream.
2279 EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
2280 EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
2281 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2282 EXPECT_TRUE(media_channel1_->ringback_tone_loop());
2283 // Stop the ringback tone.
2284 EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
2285 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2286}
2287
2288// Test that we can scale the output volume properly for 1:1 calls.
2289TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2290 CreateChannels(RTCP, RTCP);
2291 EXPECT_TRUE(SendInitiate());
2292 EXPECT_TRUE(SendAccept());
2293 double left, right;
2294
2295 // Default is (1.0, 1.0).
2296 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2297 EXPECT_DOUBLE_EQ(1.0, left);
2298 EXPECT_DOUBLE_EQ(1.0, right);
2299 // invalid ssrc.
2300 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2301
2302 // Set scale to (1.5, 0.5).
2303 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2304 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2305 EXPECT_DOUBLE_EQ(1.5, left);
2306 EXPECT_DOUBLE_EQ(0.5, right);
2307
2308 // Set scale to (0, 0).
2309 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2310 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2311 EXPECT_DOUBLE_EQ(0.0, left);
2312 EXPECT_DOUBLE_EQ(0.0, right);
2313}
2314
2315// Test that we can scale the output volume properly for multiway calls.
2316TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2317 CreateChannels(RTCP, RTCP);
2318 EXPECT_TRUE(SendInitiate());
2319 EXPECT_TRUE(SendAccept());
2320 EXPECT_TRUE(AddStream1(1));
2321 EXPECT_TRUE(AddStream1(2));
2322
2323 double left, right;
2324 // Default is (1.0, 1.0).
2325 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2326 EXPECT_DOUBLE_EQ(1.0, left);
2327 EXPECT_DOUBLE_EQ(1.0, right);
2328 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2329 EXPECT_DOUBLE_EQ(1.0, left);
2330 EXPECT_DOUBLE_EQ(1.0, right);
2331 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2332 EXPECT_DOUBLE_EQ(1.0, left);
2333 EXPECT_DOUBLE_EQ(1.0, right);
2334 // invalid ssrc.
2335 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2336
2337 // Set scale to (1.5, 0.5) for ssrc = 1.
2338 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2339 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2340 EXPECT_DOUBLE_EQ(1.5, left);
2341 EXPECT_DOUBLE_EQ(0.5, right);
2342 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2343 EXPECT_DOUBLE_EQ(1.0, left);
2344 EXPECT_DOUBLE_EQ(1.0, right);
2345 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2346 EXPECT_DOUBLE_EQ(1.0, left);
2347 EXPECT_DOUBLE_EQ(1.0, right);
2348
2349 // Set scale to (0, 0) for all ssrcs.
2350 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2351 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2352 EXPECT_DOUBLE_EQ(0.0, left);
2353 EXPECT_DOUBLE_EQ(0.0, right);
2354 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2355 EXPECT_DOUBLE_EQ(0.0, left);
2356 EXPECT_DOUBLE_EQ(0.0, right);
2357 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2358 EXPECT_DOUBLE_EQ(0.0, left);
2359 EXPECT_DOUBLE_EQ(0.0, right);
2360}
2361
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002362TEST_F(VoiceChannelTest, SendBundleToBundle) {
2363 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364}
2365
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002366TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2367 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2368}
2369
2370TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2371 Base::SendBundleToBundle(
2372 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2373}
2374
2375TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2376 Base::SendBundleToBundle(
2377 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378}
2379
2380TEST_F(VoiceChannelTest, TestSetChannelOptions) {
2381 TestSetChannelOptions();
2382}
2383
2384// VideoChannelTest
2385TEST_F(VideoChannelTest, TestInit) {
2386 Base::TestInit();
2387}
2388
2389TEST_F(VideoChannelTest, TestSetContents) {
2390 Base::TestSetContents();
2391}
2392
2393TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2394 Base::TestSetContentsNullOffer();
2395}
2396
2397TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2398 Base::TestSetContentsRtcpMux();
2399}
2400
2401TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2402 Base::TestSetContentsRtcpMux();
2403}
2404
2405TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
2406 Base::TestSetContentsVideoOptions();
2407}
2408
2409TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2410 Base::TestSetRemoteContentUpdate();
2411}
2412
2413TEST_F(VideoChannelTest, TestStreams) {
2414 Base::TestStreams();
2415}
2416
2417TEST_F(VideoChannelTest, TestScreencastEvents) {
2418 const int kTimeoutMs = 500;
2419 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 cricket::ScreencastEventCatcher catcher;
2421 channel1_->SignalScreencastWindowEvent.connect(
2422 &catcher,
2423 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002424
2425 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2426 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2427 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2428 ScreencastId(WindowId(0)));
2429 ASSERT_TRUE(screen_capturer != NULL);
2430
2431 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2432 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002434
2435 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002436 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002437
2438 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002439 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002440
2441 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002442 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445}
2446
2447TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2448 Base::TestUpdateStreamsInLocalContent();
2449}
2450
2451TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2452 Base::TestUpdateStreamsInRemoteContent();
2453}
2454
2455TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2456 Base::TestChangeStreamParamsInContent();
2457}
2458
2459TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2460 Base::TestPlayoutAndSendingStates();
2461}
2462
2463TEST_F(VideoChannelTest, TestMuteStream) {
2464 Base::TestMuteStream();
2465}
2466
2467TEST_F(VideoChannelTest, TestMediaContentDirection) {
2468 Base::TestMediaContentDirection();
2469}
2470
2471TEST_F(VideoChannelTest, TestCallSetup) {
2472 Base::TestCallSetup();
2473}
2474
2475TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2476 Base::TestCallTeardownRtcpMux();
2477}
2478
2479TEST_F(VideoChannelTest, SendRtpToRtp) {
2480 Base::SendRtpToRtp();
2481}
2482
2483TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2484 Base::SendNoRtcpToNoRtcp();
2485}
2486
2487TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2488 Base::SendNoRtcpToRtcp();
2489}
2490
2491TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2492 Base::SendRtcpToNoRtcp();
2493}
2494
2495TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2496 Base::SendRtcpToRtcp();
2497}
2498
2499TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2500 Base::SendRtcpMuxToRtcp();
2501}
2502
2503TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2504 Base::SendRtcpMuxToRtcpMux();
2505}
2506
2507TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2508 Base::SendEarlyRtcpMuxToRtcp();
2509}
2510
2511TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2512 Base::SendEarlyRtcpMuxToRtcpMux();
2513}
2514
2515TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2516 Base::SendSrtpToSrtp();
2517}
2518
2519TEST_F(VideoChannelTest, SendSrtpToRtp) {
2520 Base::SendSrtpToSrtp();
2521}
2522
2523TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2524 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2525 Base::SendSrtpToSrtp(DTLS, 0);
2526}
2527
2528TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2529 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2530 Base::SendSrtpToSrtp(DTLS, DTLS);
2531}
2532
2533TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2534 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2535 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2536}
2537
2538TEST_F(VideoChannelTest, SendSrtcpMux) {
2539 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2540}
2541
2542TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2543 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2544}
2545
2546TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2547 Base::SendRtpToRtpOnThread();
2548}
2549
2550TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2551 Base::SendSrtpToSrtpOnThread();
2552}
2553
2554TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2555 Base::SendWithWritabilityLoss();
2556}
2557
2558TEST_F(VideoChannelTest, TestMediaMonitor) {
2559 Base::TestMediaMonitor();
2560}
2561
2562TEST_F(VideoChannelTest, TestMediaSinks) {
2563 Base::TestMediaSinks();
2564}
2565
2566TEST_F(VideoChannelTest, TestSetContentFailure) {
2567 Base::TestSetContentFailure();
2568}
2569
2570TEST_F(VideoChannelTest, TestSendTwoOffers) {
2571 Base::TestSendTwoOffers();
2572}
2573
2574TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2575 Base::TestReceiveTwoOffers();
2576}
2577
2578TEST_F(VideoChannelTest, TestSendPrAnswer) {
2579 Base::TestSendPrAnswer();
2580}
2581
2582TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2583 Base::TestReceivePrAnswer();
2584}
2585
2586TEST_F(VideoChannelTest, TestFlushRtcp) {
2587 Base::TestFlushRtcp();
2588}
2589
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002590TEST_F(VideoChannelTest, SendBundleToBundle) {
2591 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592}
2593
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002594TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2595 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2596}
2597
2598TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2599 Base::SendBundleToBundle(
2600 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2601}
2602
2603TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2604 Base::SendBundleToBundle(
2605 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606}
2607
2608// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2609
2610TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002611 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612}
2613
2614TEST_F(VideoChannelTest, TestOnReadyToSend) {
2615 Base::TestOnReadyToSend();
2616}
2617
2618TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2619 Base::TestOnReadyToSendWithRtcpMux();
2620}
2621
2622TEST_F(VideoChannelTest, TestApplyViewRequest) {
2623 CreateChannels(0, 0);
2624 cricket::StreamParams stream2;
2625 stream2.id = "stream2";
2626 stream2.ssrcs.push_back(2222);
2627 local_media_content1_.AddStream(stream2);
2628
2629 EXPECT_TRUE(SendInitiate());
2630 EXPECT_TRUE(SendAccept());
2631
2632 cricket::VideoFormat send_format;
2633 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2634 EXPECT_EQ(640, send_format.width);
2635 EXPECT_EQ(400, send_format.height);
2636 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2637
2638 cricket::ViewRequest request;
2639 // stream1: 320x200x15; stream2: 0x0x0
2640 request.static_video_views.push_back(cricket::StaticVideoView(
2641 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2642 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2643 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2644 EXPECT_EQ(320, send_format.width);
2645 EXPECT_EQ(200, send_format.height);
2646 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2647 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2648 EXPECT_EQ(0, send_format.width);
2649 EXPECT_EQ(0, send_format.height);
2650
2651 // stream1: 160x100x8; stream2: 0x0x0
2652 request.static_video_views.clear();
2653 request.static_video_views.push_back(cricket::StaticVideoView(
2654 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2655 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2656 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2657 EXPECT_EQ(160, send_format.width);
2658 EXPECT_EQ(100, send_format.height);
2659 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2660
2661 // stream1: 0x0x0; stream2: 640x400x30
2662 request.static_video_views.clear();
2663 request.static_video_views.push_back(cricket::StaticVideoView(
2664 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2665 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2666 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2667 EXPECT_EQ(0, send_format.width);
2668 EXPECT_EQ(0, send_format.height);
2669 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2670 EXPECT_EQ(640, send_format.width);
2671 EXPECT_EQ(400, send_format.height);
2672 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2673
2674 // stream1: 0x0x0; stream2: 0x0x0
2675 request.static_video_views.clear();
2676 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2677 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2678 EXPECT_EQ(0, send_format.width);
2679 EXPECT_EQ(0, send_format.height);
2680}
2681
2682TEST_F(VideoChannelTest, TestSetChannelOptions) {
2683 TestSetChannelOptions();
2684}
2685
2686
2687// DataChannelTest
2688
2689class DataChannelTest
2690 : public ChannelTest<DataTraits> {
2691 public:
2692 typedef ChannelTest<DataTraits>
2693 Base;
2694 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2695 kRtcpReport, sizeof(kRtcpReport)) {
2696 }
2697};
2698
2699// Override to avoid engine channel parameter.
2700template<>
2701cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002702 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703 cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2704 bool rtcp) {
2705 cricket::DataChannel* channel = new cricket::DataChannel(
2706 thread, ch, session, cricket::CN_DATA, rtcp);
2707 if (!channel->Init()) {
2708 delete channel;
2709 channel = NULL;
2710 }
2711 return channel;
2712}
2713
2714template<>
2715void ChannelTest<DataTraits>::CreateContent(
2716 int flags,
2717 const cricket::AudioCodec& audio_codec,
2718 const cricket::VideoCodec& video_codec,
2719 cricket::DataContentDescription* data) {
2720 data->AddCodec(kGoogleDataCodec);
2721 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2722 if (flags & SECURE) {
2723 data->AddCrypto(cricket::CryptoParams(
2724 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002725 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002726 }
2727}
2728
2729template<>
2730void ChannelTest<DataTraits>::CopyContent(
2731 const cricket::DataContentDescription& source,
2732 cricket::DataContentDescription* data) {
2733 *data = source;
2734}
2735
2736template<>
2737bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2738 const cricket::DataCodec& c2) {
2739 return c1.name == c2.name;
2740}
2741
2742template<>
2743void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2744 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2745 data->AddLegacyStream(ssrc);
2746}
2747
2748TEST_F(DataChannelTest, TestInit) {
2749 Base::TestInit();
2750 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2751}
2752
2753TEST_F(DataChannelTest, TestSetContents) {
2754 Base::TestSetContents();
2755}
2756
2757TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2758 Base::TestSetContentsNullOffer();
2759}
2760
2761TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2762 Base::TestSetContentsRtcpMux();
2763}
2764
2765TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2766 Base::TestSetRemoteContentUpdate();
2767}
2768
2769TEST_F(DataChannelTest, TestStreams) {
2770 Base::TestStreams();
2771}
2772
2773TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2774 Base::TestUpdateStreamsInLocalContent();
2775}
2776
2777TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2778 Base::TestUpdateStreamsInRemoteContent();
2779}
2780
2781TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2782 Base::TestChangeStreamParamsInContent();
2783}
2784
2785TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2786 Base::TestPlayoutAndSendingStates();
2787}
2788
2789TEST_F(DataChannelTest, TestMediaContentDirection) {
2790 Base::TestMediaContentDirection();
2791}
2792
2793TEST_F(DataChannelTest, TestCallSetup) {
2794 Base::TestCallSetup();
2795}
2796
2797TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2798 Base::TestCallTeardownRtcpMux();
2799}
2800
2801TEST_F(DataChannelTest, TestOnReadyToSend) {
2802 Base::TestOnReadyToSend();
2803}
2804
2805TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2806 Base::TestOnReadyToSendWithRtcpMux();
2807}
2808
2809TEST_F(DataChannelTest, SendRtpToRtp) {
2810 Base::SendRtpToRtp();
2811}
2812
2813TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2814 Base::SendNoRtcpToNoRtcp();
2815}
2816
2817TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2818 Base::SendNoRtcpToRtcp();
2819}
2820
2821TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2822 Base::SendRtcpToNoRtcp();
2823}
2824
2825TEST_F(DataChannelTest, SendRtcpToRtcp) {
2826 Base::SendRtcpToRtcp();
2827}
2828
2829TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2830 Base::SendRtcpMuxToRtcp();
2831}
2832
2833TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2834 Base::SendRtcpMuxToRtcpMux();
2835}
2836
2837TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2838 Base::SendEarlyRtcpMuxToRtcp();
2839}
2840
2841TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2842 Base::SendEarlyRtcpMuxToRtcpMux();
2843}
2844
2845TEST_F(DataChannelTest, SendSrtpToSrtp) {
2846 Base::SendSrtpToSrtp();
2847}
2848
2849TEST_F(DataChannelTest, SendSrtpToRtp) {
2850 Base::SendSrtpToSrtp();
2851}
2852
2853TEST_F(DataChannelTest, SendSrtcpMux) {
2854 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2855}
2856
2857TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2858 Base::SendRtpToRtpOnThread();
2859}
2860
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002861TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2862 Base::SendSrtpToSrtpOnThread();
2863}
2864
2865TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2866 Base::SendWithWritabilityLoss();
2867}
2868
2869TEST_F(DataChannelTest, TestMediaMonitor) {
2870 Base::TestMediaMonitor();
2871}
2872
2873TEST_F(DataChannelTest, TestSendData) {
2874 CreateChannels(0, 0);
2875 EXPECT_TRUE(SendInitiate());
2876 EXPECT_TRUE(SendAccept());
2877
2878 cricket::SendDataParams params;
2879 params.ssrc = 42;
2880 unsigned char data[] = {
2881 'f', 'o', 'o'
2882 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002883 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002884 cricket::SendDataResult result;
2885 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2886 EXPECT_EQ(params.ssrc,
2887 media_channel1_->last_sent_data_params().ssrc);
2888 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2889}
2890
2891// TODO(pthatcher): TestSetReceiver?