blob: a55f6e8cb03ba6e25e7d8960b41c9527b89f2763 [file] [log] [blame]
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00001/*
2 * libjingle
3 * Copyright 2009 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028#include "talk/media/base/fakemediaengine.h"
29#include "talk/media/base/fakertp.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000030#include "talk/media/base/fakescreencapturerfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/media/base/fakevideocapturer.h"
32#include "talk/media/base/mediachannel.h"
33#include "talk/media/base/rtpdump.h"
34#include "talk/media/base/screencastid.h"
35#include "talk/media/base/testutils.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000036#include "webrtc/p2p/base/fakesession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/session/media/channel.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/session/media/mediarecorder.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/session/media/typingmonitor.h"
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +000040#include "webrtc/base/fileutils.h"
41#include "webrtc/base/gunit.h"
42#include "webrtc/base/helpers.h"
43#include "webrtc/base/logging.h"
44#include "webrtc/base/pathutils.h"
45#include "webrtc/base/signalthread.h"
46#include "webrtc/base/ssladapter.h"
47#include "webrtc/base/sslidentity.h"
48#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049
50#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000051 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052 LOG(LS_INFO) << "Feature disabled... skipping"; \
53 return; \
54 }
55
56using cricket::CA_OFFER;
57using cricket::CA_PRANSWER;
58using cricket::CA_ANSWER;
59using cricket::CA_UPDATE;
60using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061using cricket::ScreencastId;
62using cricket::StreamParams;
63using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000064using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065
66static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
67static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
68static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
69static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
70static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
71static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
72static const uint32 kSsrc1 = 0x1111;
73static const uint32 kSsrc2 = 0x2222;
74static const uint32 kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000075static const int kAudioPts[] = {0, 8};
76static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077
78template<class ChannelT,
79 class MediaChannelT,
80 class ContentT,
81 class CodecT,
82 class MediaInfoT>
83class Traits {
84 public:
85 typedef ChannelT Channel;
86 typedef MediaChannelT MediaChannel;
87 typedef ContentT Content;
88 typedef CodecT Codec;
89 typedef MediaInfoT MediaInfo;
90};
91
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092// Controls how long we wait for a session to send messages that we
93// expect, in milliseconds. We put it high to avoid flaky tests.
94static const int kEventTimeout = 5000;
95
96class VoiceTraits : public Traits<cricket::VoiceChannel,
97 cricket::FakeVoiceMediaChannel,
98 cricket::AudioContentDescription,
99 cricket::AudioCodec,
100 cricket::VoiceMediaInfo> {
101};
102
103class VideoTraits : public Traits<cricket::VideoChannel,
104 cricket::FakeVideoMediaChannel,
105 cricket::VideoContentDescription,
106 cricket::VideoCodec,
107 cricket::VideoMediaInfo> {
108};
109
110class DataTraits : public Traits<cricket::DataChannel,
111 cricket::FakeDataMediaChannel,
112 cricket::DataContentDescription,
113 cricket::DataCodec,
114 cricket::DataMediaInfo> {
115};
116
117
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000118rtc::StreamInterface* Open(const std::string& path) {
119 return rtc::Filesystem::OpenFile(
120 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121}
122
123// Base class for Voice/VideoChannel tests
124template<class T>
125class ChannelTest : public testing::Test, public sigslot::has_slots<> {
126 public:
127 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
128 DTLS = 0x10 };
129
130 ChannelTest(const uint8* rtp_data, int rtp_len,
131 const uint8* rtcp_data, int rtcp_len)
132 : session1_(true),
133 session2_(false),
134 media_channel1_(NULL),
135 media_channel2_(NULL),
136 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
137 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
138 media_info_callbacks1_(),
139 media_info_callbacks2_(),
140 mute_callback_recved_(false),
141 mute_callback_value_(false),
142 ssrc_(0),
143 error_(T::MediaChannel::ERROR_NONE) {
144 }
145
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000146 void CreateChannels(int flags1, int flags2) {
147 CreateChannels(new typename T::MediaChannel(NULL),
148 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000149 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 }
151 void CreateChannels(int flags) {
152 CreateChannels(new typename T::MediaChannel(NULL),
153 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000154 flags, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155 }
156 void CreateChannels(int flags1, int flags2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000157 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158 CreateChannels(new typename T::MediaChannel(NULL),
159 new typename T::MediaChannel(NULL),
160 flags1, flags2, thread);
161 }
162 void CreateChannels(int flags,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000163 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 CreateChannels(new typename T::MediaChannel(NULL),
165 new typename T::MediaChannel(NULL),
166 flags, thread);
167 }
168 void CreateChannels(
169 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000170 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000171 media_channel1_ = ch1;
172 media_channel2_ = ch2;
173 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
174 (flags1 & RTCP) != 0));
175 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
176 (flags2 & RTCP) != 0));
177 channel1_->SignalMediaMonitor.connect(
178 this, &ChannelTest<T>::OnMediaMonitor);
179 channel2_->SignalMediaMonitor.connect(
180 this, &ChannelTest<T>::OnMediaMonitor);
181 channel1_->SignalMediaError.connect(
182 this, &ChannelTest<T>::OnMediaChannelError);
183 channel2_->SignalMediaError.connect(
184 this, &ChannelTest<T>::OnMediaChannelError);
185 channel1_->SignalAutoMuted.connect(
186 this, &ChannelTest<T>::OnMediaMuted);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000187 if ((flags1 & DTLS) && (flags2 & DTLS)) {
188 flags1 = (flags1 & ~SECURE);
189 flags2 = (flags2 & ~SECURE);
190 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 CreateContent(flags1, kPcmuCodec, kH264Codec,
192 &local_media_content1_);
193 CreateContent(flags2, kPcmuCodec, kH264Codec,
194 &local_media_content2_);
195 CopyContent(local_media_content1_, &remote_media_content1_);
196 CopyContent(local_media_content2_, &remote_media_content2_);
197
198 if (flags1 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000199 identity1_.reset(rtc::SSLIdentity::Generate("session1"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 session1_.set_ssl_identity(identity1_.get());
201 }
202 if (flags2 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000203 identity2_.reset(rtc::SSLIdentity::Generate("session2"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 session2_.set_ssl_identity(identity2_.get());
205 }
206
207 // Add stream information (SSRC) to the local content but not to the remote
208 // content. This means that we per default know the SSRC of what we send but
209 // not what we receive.
210 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
211 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
212
213 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
214 if (flags1 & SSRC_MUX) {
215 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
216 }
217 if (flags2 & SSRC_MUX) {
218 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
219 }
220 }
221
222 void CreateChannels(
223 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000224 int flags, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000225 media_channel1_ = ch1;
226 media_channel2_ = ch2;
227
228 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
229 (flags & RTCP) != 0));
230 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
231 (flags & RTCP) != 0));
232 channel1_->SignalMediaMonitor.connect(
233 this, &ChannelTest<T>::OnMediaMonitor);
234 channel2_->SignalMediaMonitor.connect(
235 this, &ChannelTest<T>::OnMediaMonitor);
236 channel2_->SignalMediaError.connect(
237 this, &ChannelTest<T>::OnMediaChannelError);
238 CreateContent(flags, kPcmuCodec, kH264Codec,
239 &local_media_content1_);
240 CreateContent(flags, kPcmuCodec, kH264Codec,
241 &local_media_content2_);
242 CopyContent(local_media_content1_, &remote_media_content1_);
243 CopyContent(local_media_content2_, &remote_media_content2_);
244 // Add stream information (SSRC) to the local content but not to the remote
245 // content. This means that we per default know the SSRC of what we send but
246 // not what we receive.
247 AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
248 AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
249
250 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
251 if (flags & SSRC_MUX) {
252 AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
253 AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
254 }
255 }
256
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000257 typename T::Channel* CreateChannel(rtc::Thread* thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258 cricket::MediaEngineInterface* engine,
259 typename T::MediaChannel* ch,
260 cricket::BaseSession* session,
261 bool rtcp) {
262 typename T::Channel* channel = new typename T::Channel(
263 thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
264 if (!channel->Init()) {
265 delete channel;
266 channel = NULL;
267 }
268 return channel;
269 }
270
271 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000272 bool result = channel1_->SetLocalContent(&local_media_content1_,
273 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 if (result) {
275 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000276 result = channel2_->SetRemoteContent(&remote_media_content1_,
277 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000278 if (result) {
279 session1_.Connect(&session2_);
280
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000281 result = channel2_->SetLocalContent(&local_media_content2_,
282 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283 }
284 }
285 return result;
286 }
287
288 bool SendAccept() {
289 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000290 return channel1_->SetRemoteContent(&remote_media_content2_,
291 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292 }
293
294 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000295 bool result = channel1_->SetLocalContent(&local_media_content1_,
296 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 if (result) {
298 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000299 result = channel2_->SetRemoteContent(&remote_media_content1_,
300 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 }
302 return result;
303 }
304
305 bool SendProvisionalAnswer() {
306 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000307 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 if (result) {
309 channel2_->Enable(true);
310 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000311 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312 session1_.Connect(&session2_);
313 }
314 return result;
315 }
316
317 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000318 bool result = channel2_->SetLocalContent(&local_media_content2_,
319 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000321 result = channel1_->SetRemoteContent(&remote_media_content2_,
322 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 return result;
324 }
325
326 bool SendTerminate() {
327 channel1_.reset();
328 channel2_.reset();
329 return true;
330 }
331
332 bool AddStream1(int id) {
333 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
334 }
335 bool RemoveStream1(int id) {
336 return channel1_->RemoveRecvStream(id);
337 }
338
339 cricket::FakeTransport* GetTransport1() {
340 return session1_.GetTransport(channel1_->content_name());
341 }
342 cricket::FakeTransport* GetTransport2() {
343 return session2_.GetTransport(channel2_->content_name());
344 }
345
346 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000347 return media_channel1_->SendRtp(rtp_packet_.c_str(),
348 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000351 return media_channel2_->SendRtp(rtp_packet_.c_str(),
352 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 }
354 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000355 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
356 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 }
358 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000359 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
360 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 }
362 // Methods to send custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000363 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
364 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000365 return media_channel1_->SendRtp(data.c_str(),
366 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000368 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
369 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000370 return media_channel2_->SendRtp(data.c_str(),
371 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 }
373 bool SendCustomRtcp1(uint32 ssrc) {
374 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000375 return media_channel1_->SendRtcp(data.c_str(),
376 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 }
378 bool SendCustomRtcp2(uint32 ssrc) {
379 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000380 return media_channel2_->SendRtcp(data.c_str(),
381 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 }
383 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000384 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
385 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000386 }
387 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000388 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
389 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000390 }
391 bool CheckRtcp1() {
392 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000393 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 }
395 bool CheckRtcp2() {
396 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000397 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 }
399 // Methods to check custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000400 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
401 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000402 return media_channel1_->CheckRtp(data.c_str(),
403 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000405 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
406 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000407 return media_channel2_->CheckRtp(data.c_str(),
408 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000409 }
410 bool CheckCustomRtcp1(uint32 ssrc) {
411 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000412 return media_channel1_->CheckRtcp(data.c_str(),
413 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 }
415 bool CheckCustomRtcp2(uint32 ssrc) {
416 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000417 return media_channel2_->CheckRtcp(data.c_str(),
418 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000420 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 std::string data(rtp_packet_);
422 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000423 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
424 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000425 if (pl_type >= 0) {
pkasting@chromium.org0e81fdf2015-02-02 23:54:03 +0000426 rtc::Set8(const_cast<char*>(data.c_str()), 1,
427 static_cast<uint8_t>(pl_type));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000428 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429 return data;
430 }
431 std::string CreateRtcpData(uint32 ssrc) {
432 std::string data(rtcp_packet_);
433 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000434 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435 return data;
436 }
437
438 bool CheckNoRtp1() {
439 return media_channel1_->CheckNoRtp();
440 }
441 bool CheckNoRtp2() {
442 return media_channel2_->CheckNoRtp();
443 }
444 bool CheckNoRtcp1() {
445 return media_channel1_->CheckNoRtcp();
446 }
447 bool CheckNoRtcp2() {
448 return media_channel2_->CheckNoRtcp();
449 }
450
451 void CreateContent(int flags,
452 const cricket::AudioCodec& audio_codec,
453 const cricket::VideoCodec& video_codec,
454 typename T::Content* content) {
455 // overridden in specialized classes
456 }
457 void CopyContent(const typename T::Content& source,
458 typename T::Content* content) {
459 // overridden in specialized classes
460 }
461
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000462 // Creates a cricket::SessionDescription with one MediaContent and one stream.
463 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
464 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
465 typename T::Content content;
466 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
467 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
468 AddLegacyStreamInContent(ssrc, 0, &content);
469 sdesc->AddContent("DUMMY_CONTENT_NAME",
470 cricket::NS_JINGLE_RTP, content.Copy());
471 return sdesc;
472 }
473
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000474 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 public:
476 typedef bool (ChannelTest<T>::*Method)();
477 CallThread(ChannelTest<T>* obj, Method method, bool* result)
478 : obj_(obj),
479 method_(method),
480 result_(result) {
481 *result = false;
482 }
483 virtual void DoWork() {
484 bool result = (*obj_.*method_)();
485 if (result_) {
486 *result_ = result;
487 }
488 }
489 private:
490 ChannelTest<T>* obj_;
491 Method method_;
492 bool* result_;
493 };
494 void CallOnThread(typename CallThread::Method method, bool* result) {
495 CallThread* thread = new CallThread(this, method, result);
496 thread->Start();
497 thread->Release();
498 }
499
500 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
501 bool* result) {
502 CallThread* thread = new CallThread(this, method, result);
503 thread->Start();
504 thread->Destroy(true);
505 }
506
507 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
508 return false; // overridden in specialized classes
509 }
510
511 void OnMediaMonitor(typename T::Channel* channel,
512 const typename T::MediaInfo& info) {
513 if (channel == channel1_.get()) {
514 media_info_callbacks1_++;
515 } else if (channel == channel2_.get()) {
516 media_info_callbacks2_++;
517 }
518 }
519
520 void OnMediaChannelError(typename T::Channel* channel,
521 uint32 ssrc,
522 typename T::MediaChannel::Error error) {
523 ssrc_ = ssrc;
524 error_ = error;
525 }
526
527 void OnMediaMuted(cricket::BaseChannel* channel, bool muted) {
528 mute_callback_recved_ = true;
529 mute_callback_value_ = muted;
530 }
531
532 void AddLegacyStreamInContent(uint32 ssrc, int flags,
533 typename T::Content* content) {
534 // Base implementation.
535 }
536
537 // Tests that can be used by derived classes.
538
539 // Basic sanity check.
540 void TestInit() {
541 CreateChannels(0, 0);
542 EXPECT_FALSE(channel1_->secure());
543 EXPECT_FALSE(media_channel1_->sending());
544 EXPECT_FALSE(media_channel1_->playout());
545 EXPECT_TRUE(media_channel1_->codecs().empty());
546 EXPECT_TRUE(media_channel1_->recv_streams().empty());
547 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
548 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
549 }
550
551 // Test that SetLocalContent and SetRemoteContent properly configure
552 // the codecs.
553 void TestSetContents() {
554 CreateChannels(0, 0);
555 typename T::Content content;
556 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000557 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000559 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 ASSERT_EQ(1U, media_channel1_->codecs().size());
561 EXPECT_TRUE(CodecMatches(content.codecs()[0],
562 media_channel1_->codecs()[0]));
563 }
564
565 // Test that SetLocalContent and SetRemoteContent properly deals
566 // with an empty offer.
567 void TestSetContentsNullOffer() {
568 CreateChannels(0, 0);
569 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000570 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 CreateContent(0, kPcmuCodec, kH264Codec, &content);
572 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000573 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 ASSERT_EQ(1U, media_channel1_->codecs().size());
575 EXPECT_TRUE(CodecMatches(content.codecs()[0],
576 media_channel1_->codecs()[0]));
577 }
578
579 // Test that SetLocalContent and SetRemoteContent properly set RTCP
580 // mux.
581 void TestSetContentsRtcpMux() {
582 CreateChannels(RTCP, RTCP);
583 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
584 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
585 typename T::Content content;
586 CreateContent(0, kPcmuCodec, kH264Codec, &content);
587 // Both sides agree on mux. Should no longer be a separate RTCP channel.
588 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000589 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
590 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
592 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000593 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000594 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000595 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000596 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
597 }
598
599 // Test that SetLocalContent and SetRemoteContent properly set RTCP
600 // mux when a provisional answer is received.
601 void TestSetContentsRtcpMuxWithPrAnswer() {
602 CreateChannels(RTCP, RTCP);
603 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
604 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
605 typename T::Content content;
606 CreateContent(0, kPcmuCodec, kH264Codec, &content);
607 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000608 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
609 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000610 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000611 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 // Both sides agree on mux. Should no longer be a separate RTCP channel.
613 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
614 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000615 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000617 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
618 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
620 }
621
622 // Test that SetLocalContent and SetRemoteContent properly set
623 // video options to the media channel.
624 void TestSetContentsVideoOptions() {
625 CreateChannels(0, 0);
626 typename T::Content content;
627 CreateContent(0, kPcmuCodec, kH264Codec, &content);
628 content.set_buffered_mode_latency(101);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000629 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 EXPECT_EQ(0U, media_channel1_->codecs().size());
631 cricket::VideoOptions options;
632 ASSERT_TRUE(media_channel1_->GetOptions(&options));
633 int latency = 0;
634 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
635 EXPECT_EQ(101, latency);
636 content.set_buffered_mode_latency(102);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000637 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638 ASSERT_EQ(1U, media_channel1_->codecs().size());
639 EXPECT_TRUE(CodecMatches(content.codecs()[0],
640 media_channel1_->codecs()[0]));
641 ASSERT_TRUE(media_channel1_->GetOptions(&options));
642 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
643 EXPECT_EQ(102, latency);
644 }
645
646 // Test that SetRemoteContent properly deals with a content update.
647 void TestSetRemoteContentUpdate() {
648 CreateChannels(0, 0);
649 typename T::Content content;
650 CreateContent(RTCP | RTCP_MUX | SECURE,
651 kPcmuCodec, kH264Codec,
652 &content);
653 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000654 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
655 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 ASSERT_EQ(1U, media_channel1_->codecs().size());
657 EXPECT_TRUE(CodecMatches(content.codecs()[0],
658 media_channel1_->codecs()[0]));
659 // Now update with other codecs.
660 typename T::Content update_content;
661 update_content.set_partial(true);
662 CreateContent(0, kIsacCodec, kH264SvcCodec,
663 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000664 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 ASSERT_EQ(1U, media_channel1_->codecs().size());
666 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
667 media_channel1_->codecs()[0]));
668 // Now update without any codecs. This is ignored.
669 typename T::Content empty_content;
670 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000671 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000672 ASSERT_EQ(1U, media_channel1_->codecs().size());
673 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
674 media_channel1_->codecs()[0]));
675 }
676
677 // Test that Add/RemoveStream properly forward to the media channel.
678 void TestStreams() {
679 CreateChannels(0, 0);
680 EXPECT_TRUE(AddStream1(1));
681 EXPECT_TRUE(AddStream1(2));
682 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
683 EXPECT_TRUE(RemoveStream1(2));
684 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
685 EXPECT_TRUE(RemoveStream1(1));
686 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
687 }
688
689 // Test that SetLocalContent properly handles adding and removing StreamParams
690 // to the local content description.
691 // This test uses the CA_UPDATE action that don't require a full
692 // MediaContentDescription to do an update.
693 void TestUpdateStreamsInLocalContent() {
694 cricket::StreamParams stream1;
695 stream1.groupid = "group1";
696 stream1.id = "stream1";
697 stream1.ssrcs.push_back(kSsrc1);
698 stream1.cname = "stream1_cname";
699
700 cricket::StreamParams stream2;
701 stream2.groupid = "group2";
702 stream2.id = "stream2";
703 stream2.ssrcs.push_back(kSsrc2);
704 stream2.cname = "stream2_cname";
705
706 cricket::StreamParams stream3;
707 stream3.groupid = "group3";
708 stream3.id = "stream3";
709 stream3.ssrcs.push_back(kSsrc3);
710 stream3.cname = "stream3_cname";
711
712 CreateChannels(0, 0);
713 typename T::Content content1;
714 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
715 content1.AddStream(stream1);
716 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000717 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718
719 ASSERT_EQ(1u, media_channel1_->send_streams().size());
720 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
721
722 // Update the local streams by adding another sending stream.
723 // Use a partial updated session description.
724 typename T::Content content2;
725 content2.AddStream(stream2);
726 content2.AddStream(stream3);
727 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000728 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000729 ASSERT_EQ(3u, media_channel1_->send_streams().size());
730 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
731 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
732 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
733
734 // Update the local streams by removing the first sending stream.
735 // This is done by removing all SSRCS for this particular stream.
736 typename T::Content content3;
737 stream1.ssrcs.clear();
738 content3.AddStream(stream1);
739 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000740 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 ASSERT_EQ(2u, media_channel1_->send_streams().size());
742 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
743 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
744
745 // Update the local streams with a stream that does not change.
746 // THe update is ignored.
747 typename T::Content content4;
748 content4.AddStream(stream2);
749 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000750 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 ASSERT_EQ(2u, media_channel1_->send_streams().size());
752 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
753 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
754 }
755
756 // Test that SetRemoteContent properly handles adding and removing
757 // StreamParams to the remote content description.
758 // This test uses the CA_UPDATE action that don't require a full
759 // MediaContentDescription to do an update.
760 void TestUpdateStreamsInRemoteContent() {
761 cricket::StreamParams stream1;
762 stream1.id = "Stream1";
763 stream1.groupid = "1";
764 stream1.ssrcs.push_back(kSsrc1);
765 stream1.cname = "stream1_cname";
766
767 cricket::StreamParams stream2;
768 stream2.id = "Stream2";
769 stream2.groupid = "2";
770 stream2.ssrcs.push_back(kSsrc2);
771 stream2.cname = "stream2_cname";
772
773 cricket::StreamParams stream3;
774 stream3.id = "Stream3";
775 stream3.groupid = "3";
776 stream3.ssrcs.push_back(kSsrc3);
777 stream3.cname = "stream3_cname";
778
779 CreateChannels(0, 0);
780 typename T::Content content1;
781 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
782 content1.AddStream(stream1);
783 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000784 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785
786 ASSERT_EQ(1u, media_channel1_->codecs().size());
787 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
788 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
789
790 // Update the remote streams by adding another sending stream.
791 // Use a partial updated session description.
792 typename T::Content content2;
793 content2.AddStream(stream2);
794 content2.AddStream(stream3);
795 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000796 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
798 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
799 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
800 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
801
802 // Update the remote streams by removing the first stream.
803 // This is done by removing all SSRCS for this particular stream.
804 typename T::Content content3;
805 stream1.ssrcs.clear();
806 content3.AddStream(stream1);
807 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000808 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
810 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
811 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
812
813 // Update the remote streams with a stream that does not change.
814 // The update is ignored.
815 typename T::Content content4;
816 content4.AddStream(stream2);
817 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000818 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000819 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
820 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
821 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
822 }
823
824 // Test that SetLocalContent and SetRemoteContent properly
825 // handles adding and removing StreamParams when the action is a full
826 // CA_OFFER / CA_ANSWER.
827 void TestChangeStreamParamsInContent() {
828 cricket::StreamParams stream1;
829 stream1.groupid = "group1";
830 stream1.id = "stream1";
831 stream1.ssrcs.push_back(kSsrc1);
832 stream1.cname = "stream1_cname";
833
834 cricket::StreamParams stream2;
835 stream2.groupid = "group1";
836 stream2.id = "stream2";
837 stream2.ssrcs.push_back(kSsrc2);
838 stream2.cname = "stream2_cname";
839
840 // Setup a call where channel 1 send |stream1| to channel 2.
841 CreateChannels(0, 0);
842 typename T::Content content1;
843 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
844 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000845 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 EXPECT_TRUE(channel1_->Enable(true));
847 EXPECT_EQ(1u, media_channel1_->send_streams().size());
848
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000849 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000850 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
851 session1_.Connect(&session2_);
852
853 // Channel 2 do not send anything.
854 typename T::Content content2;
855 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000856 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000858 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000859 EXPECT_TRUE(channel2_->Enable(true));
860 EXPECT_EQ(0u, media_channel2_->send_streams().size());
861
862 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
863 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
864
865 // Let channel 2 update the content by sending |stream2| and enable SRTP.
866 typename T::Content content3;
867 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
868 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000869 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 ASSERT_EQ(1u, media_channel2_->send_streams().size());
871 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
872
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000873 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
875 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
876
877 // Channel 1 replies but stop sending stream1.
878 typename T::Content content4;
879 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000880 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 EXPECT_EQ(0u, media_channel1_->send_streams().size());
882
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000883 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
885
886 EXPECT_TRUE(channel1_->secure());
887 EXPECT_TRUE(channel2_->secure());
888 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
889 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
890 }
891
892 // Test that we only start playout and sending at the right times.
893 void TestPlayoutAndSendingStates() {
894 CreateChannels(0, 0);
895 EXPECT_FALSE(media_channel1_->playout());
896 EXPECT_FALSE(media_channel1_->sending());
897 EXPECT_FALSE(media_channel2_->playout());
898 EXPECT_FALSE(media_channel2_->sending());
899 EXPECT_TRUE(channel1_->Enable(true));
900 EXPECT_FALSE(media_channel1_->playout());
901 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000902 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
903 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 EXPECT_TRUE(media_channel1_->playout());
905 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000906 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
907 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 EXPECT_FALSE(media_channel2_->playout());
909 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000910 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
911 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 EXPECT_FALSE(media_channel2_->playout());
913 EXPECT_FALSE(media_channel2_->sending());
914 session1_.Connect(&session2_);
915 EXPECT_TRUE(media_channel1_->playout());
916 EXPECT_FALSE(media_channel1_->sending());
917 EXPECT_FALSE(media_channel2_->playout());
918 EXPECT_FALSE(media_channel2_->sending());
919 EXPECT_TRUE(channel2_->Enable(true));
920 EXPECT_TRUE(media_channel2_->playout());
921 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000922 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
923 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 EXPECT_TRUE(media_channel1_->playout());
925 EXPECT_TRUE(media_channel1_->sending());
926 }
927
928 void TestMuteStream() {
929 CreateChannels(0, 0);
930 // Test that we can Mute the default channel even though the sending SSRC is
931 // unknown.
932 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
933 EXPECT_TRUE(channel1_->MuteStream(0, true));
934 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
935 EXPECT_TRUE(channel1_->MuteStream(0, false));
936 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
937
938 // Test that we can not mute an unknown SSRC.
939 EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true));
940
941 SendInitiate();
942 // After the local session description has been set, we can mute a stream
943 // with its SSRC.
944 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true));
945 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
946 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false));
947 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
948 }
949
950 // Test that changing the MediaContentDirection in the local and remote
951 // session description start playout and sending at the right time.
952 void TestMediaContentDirection() {
953 CreateChannels(0, 0);
954 typename T::Content content1;
955 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
956 typename T::Content content2;
957 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
958 // Set |content2| to be InActive.
959 content2.set_direction(cricket::MD_INACTIVE);
960
961 EXPECT_TRUE(channel1_->Enable(true));
962 EXPECT_TRUE(channel2_->Enable(true));
963 EXPECT_FALSE(media_channel1_->playout());
964 EXPECT_FALSE(media_channel1_->sending());
965 EXPECT_FALSE(media_channel2_->playout());
966 EXPECT_FALSE(media_channel2_->sending());
967
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000968 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
969 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
970 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
971 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 session1_.Connect(&session2_);
973
974 EXPECT_TRUE(media_channel1_->playout());
975 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
976 EXPECT_FALSE(media_channel2_->playout()); // local InActive
977 EXPECT_FALSE(media_channel2_->sending()); // local InActive
978
979 // Update |content2| to be RecvOnly.
980 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000981 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
982 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983
984 EXPECT_TRUE(media_channel1_->playout());
985 EXPECT_TRUE(media_channel1_->sending());
986 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
987 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
988
989 // Update |content2| to be SendRecv.
990 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000991 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
992 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993
994 EXPECT_TRUE(media_channel1_->playout());
995 EXPECT_TRUE(media_channel1_->sending());
996 EXPECT_TRUE(media_channel2_->playout());
997 EXPECT_TRUE(media_channel2_->sending());
998 }
999
1000 // Test setting up a call.
1001 void TestCallSetup() {
1002 CreateChannels(0, 0);
1003 EXPECT_FALSE(channel1_->secure());
1004 EXPECT_TRUE(SendInitiate());
1005 EXPECT_TRUE(media_channel1_->playout());
1006 EXPECT_FALSE(media_channel1_->sending());
1007 EXPECT_TRUE(SendAccept());
1008 EXPECT_FALSE(channel1_->secure());
1009 EXPECT_TRUE(media_channel1_->sending());
1010 EXPECT_EQ(1U, media_channel1_->codecs().size());
1011 EXPECT_TRUE(media_channel2_->playout());
1012 EXPECT_TRUE(media_channel2_->sending());
1013 EXPECT_EQ(1U, media_channel2_->codecs().size());
1014 }
1015
1016 // Test that we don't crash if packets are sent during call teardown
1017 // when RTCP mux is enabled. This is a regression test against a specific
1018 // race condition that would only occur when a RTCP packet was sent during
1019 // teardown of a channel on which RTCP mux was enabled.
1020 void TestCallTeardownRtcpMux() {
1021 class LastWordMediaChannel : public T::MediaChannel {
1022 public:
1023 LastWordMediaChannel() : T::MediaChannel(NULL) {}
1024 ~LastWordMediaChannel() {
1025 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
1026 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1027 }
1028 };
1029 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1030 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001031 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 EXPECT_TRUE(SendInitiate());
1033 EXPECT_TRUE(SendAccept());
1034 EXPECT_TRUE(SendTerminate());
1035 }
1036
1037 // Send voice RTP data to the other side and ensure it gets there.
1038 void SendRtpToRtp() {
1039 CreateChannels(0, 0);
1040 EXPECT_TRUE(SendInitiate());
1041 EXPECT_TRUE(SendAccept());
1042 EXPECT_EQ(1U, GetTransport1()->channels().size());
1043 EXPECT_EQ(1U, GetTransport2()->channels().size());
1044 EXPECT_TRUE(SendRtp1());
1045 EXPECT_TRUE(SendRtp2());
1046 EXPECT_TRUE(CheckRtp1());
1047 EXPECT_TRUE(CheckRtp2());
1048 EXPECT_TRUE(CheckNoRtp1());
1049 EXPECT_TRUE(CheckNoRtp2());
1050 }
1051
1052 // Check that RTCP is not transmitted if both sides don't support RTCP.
1053 void SendNoRtcpToNoRtcp() {
1054 CreateChannels(0, 0);
1055 EXPECT_TRUE(SendInitiate());
1056 EXPECT_TRUE(SendAccept());
1057 EXPECT_EQ(1U, GetTransport1()->channels().size());
1058 EXPECT_EQ(1U, GetTransport2()->channels().size());
1059 EXPECT_FALSE(SendRtcp1());
1060 EXPECT_FALSE(SendRtcp2());
1061 EXPECT_TRUE(CheckNoRtcp1());
1062 EXPECT_TRUE(CheckNoRtcp2());
1063 }
1064
1065 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1066 void SendNoRtcpToRtcp() {
1067 CreateChannels(0, RTCP);
1068 EXPECT_TRUE(SendInitiate());
1069 EXPECT_TRUE(SendAccept());
1070 EXPECT_EQ(1U, GetTransport1()->channels().size());
1071 EXPECT_EQ(2U, GetTransport2()->channels().size());
1072 EXPECT_FALSE(SendRtcp1());
1073 EXPECT_FALSE(SendRtcp2());
1074 EXPECT_TRUE(CheckNoRtcp1());
1075 EXPECT_TRUE(CheckNoRtcp2());
1076 }
1077
1078 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1079 void SendRtcpToNoRtcp() {
1080 CreateChannels(RTCP, 0);
1081 EXPECT_TRUE(SendInitiate());
1082 EXPECT_TRUE(SendAccept());
1083 EXPECT_EQ(2U, GetTransport1()->channels().size());
1084 EXPECT_EQ(1U, GetTransport2()->channels().size());
1085 EXPECT_FALSE(SendRtcp1());
1086 EXPECT_FALSE(SendRtcp2());
1087 EXPECT_TRUE(CheckNoRtcp1());
1088 EXPECT_TRUE(CheckNoRtcp2());
1089 }
1090
1091 // Check that RTCP is transmitted if both sides support RTCP.
1092 void SendRtcpToRtcp() {
1093 CreateChannels(RTCP, RTCP);
1094 EXPECT_TRUE(SendInitiate());
1095 EXPECT_TRUE(SendAccept());
1096 EXPECT_EQ(2U, GetTransport1()->channels().size());
1097 EXPECT_EQ(2U, GetTransport2()->channels().size());
1098 EXPECT_TRUE(SendRtcp1());
1099 EXPECT_TRUE(SendRtcp2());
1100 EXPECT_TRUE(CheckRtcp1());
1101 EXPECT_TRUE(CheckRtcp2());
1102 EXPECT_TRUE(CheckNoRtcp1());
1103 EXPECT_TRUE(CheckNoRtcp2());
1104 }
1105
1106 // Check that RTCP is transmitted if only the initiator supports mux.
1107 void SendRtcpMuxToRtcp() {
1108 CreateChannels(RTCP | RTCP_MUX, RTCP);
1109 EXPECT_TRUE(SendInitiate());
1110 EXPECT_TRUE(SendAccept());
1111 EXPECT_EQ(2U, GetTransport1()->channels().size());
1112 EXPECT_EQ(2U, GetTransport2()->channels().size());
1113 EXPECT_TRUE(SendRtcp1());
1114 EXPECT_TRUE(SendRtcp2());
1115 EXPECT_TRUE(CheckRtcp1());
1116 EXPECT_TRUE(CheckRtcp2());
1117 EXPECT_TRUE(CheckNoRtcp1());
1118 EXPECT_TRUE(CheckNoRtcp2());
1119 }
1120
1121 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1122 void SendRtcpMuxToRtcpMux() {
1123 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1124 EXPECT_TRUE(SendInitiate());
1125 EXPECT_EQ(2U, GetTransport1()->channels().size());
1126 EXPECT_EQ(1U, GetTransport2()->channels().size());
1127 EXPECT_TRUE(SendAccept());
1128 EXPECT_EQ(1U, GetTransport1()->channels().size());
1129 EXPECT_TRUE(SendRtp1());
1130 EXPECT_TRUE(SendRtp2());
1131 EXPECT_TRUE(SendRtcp1());
1132 EXPECT_TRUE(SendRtcp2());
1133 EXPECT_TRUE(CheckRtp1());
1134 EXPECT_TRUE(CheckRtp2());
1135 EXPECT_TRUE(CheckNoRtp1());
1136 EXPECT_TRUE(CheckNoRtp2());
1137 EXPECT_TRUE(CheckRtcp1());
1138 EXPECT_TRUE(CheckRtcp2());
1139 EXPECT_TRUE(CheckNoRtcp1());
1140 EXPECT_TRUE(CheckNoRtcp2());
1141 }
1142
1143 // Check that RTCP data sent by the initiator before the accept is not muxed.
1144 void SendEarlyRtcpMuxToRtcp() {
1145 CreateChannels(RTCP | RTCP_MUX, RTCP);
1146 EXPECT_TRUE(SendInitiate());
1147 EXPECT_EQ(2U, GetTransport1()->channels().size());
1148 EXPECT_EQ(2U, GetTransport2()->channels().size());
1149
1150 // RTCP can be sent before the call is accepted, if the transport is ready.
1151 // It should not be muxed though, as the remote side doesn't support mux.
1152 EXPECT_TRUE(SendRtcp1());
1153 EXPECT_TRUE(CheckNoRtp2());
1154 EXPECT_TRUE(CheckRtcp2());
1155
1156 // Send RTCP packet from callee and verify that it is received.
1157 EXPECT_TRUE(SendRtcp2());
1158 EXPECT_TRUE(CheckNoRtp1());
1159 EXPECT_TRUE(CheckRtcp1());
1160
1161 // Complete call setup and ensure everything is still OK.
1162 EXPECT_TRUE(SendAccept());
1163 EXPECT_EQ(2U, GetTransport1()->channels().size());
1164 EXPECT_TRUE(SendRtcp1());
1165 EXPECT_TRUE(CheckRtcp2());
1166 EXPECT_TRUE(SendRtcp2());
1167 EXPECT_TRUE(CheckRtcp1());
1168 }
1169
1170
1171 // Check that RTCP data is not muxed until both sides have enabled muxing,
1172 // but that we properly demux before we get the accept message, since there
1173 // is a race between RTP data and the jingle accept.
1174 void SendEarlyRtcpMuxToRtcpMux() {
1175 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1176 EXPECT_TRUE(SendInitiate());
1177 EXPECT_EQ(2U, GetTransport1()->channels().size());
1178 EXPECT_EQ(1U, GetTransport2()->channels().size());
1179
1180 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1181 // we haven't yet received the accept that says we should mux.
1182 EXPECT_FALSE(SendRtcp1());
1183
1184 // Send muxed RTCP packet from callee and verify that it is received.
1185 EXPECT_TRUE(SendRtcp2());
1186 EXPECT_TRUE(CheckNoRtp1());
1187 EXPECT_TRUE(CheckRtcp1());
1188
1189 // Complete call setup and ensure everything is still OK.
1190 EXPECT_TRUE(SendAccept());
1191 EXPECT_EQ(1U, GetTransport1()->channels().size());
1192 EXPECT_TRUE(SendRtcp1());
1193 EXPECT_TRUE(CheckRtcp2());
1194 EXPECT_TRUE(SendRtcp2());
1195 EXPECT_TRUE(CheckRtcp1());
1196 }
1197
1198 // Test that we properly send SRTP with RTCP in both directions.
1199 // You can pass in DTLS and/or RTCP_MUX as flags.
1200 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1201 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1202 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1203
1204 int flags1 = RTCP | SECURE | flags1_in;
1205 int flags2 = RTCP | SECURE | flags2_in;
1206 bool dtls1 = !!(flags1_in & DTLS);
1207 bool dtls2 = !!(flags2_in & DTLS);
1208 CreateChannels(flags1, flags2);
1209 EXPECT_FALSE(channel1_->secure());
1210 EXPECT_FALSE(channel2_->secure());
1211 EXPECT_TRUE(SendInitiate());
1212 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1213 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1214 EXPECT_TRUE(SendAccept());
1215 EXPECT_TRUE(channel1_->secure());
1216 EXPECT_TRUE(channel2_->secure());
1217 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1218 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1219 EXPECT_TRUE(SendRtp1());
1220 EXPECT_TRUE(SendRtp2());
1221 EXPECT_TRUE(SendRtcp1());
1222 EXPECT_TRUE(SendRtcp2());
1223 EXPECT_TRUE(CheckRtp1());
1224 EXPECT_TRUE(CheckRtp2());
1225 EXPECT_TRUE(CheckNoRtp1());
1226 EXPECT_TRUE(CheckNoRtp2());
1227 EXPECT_TRUE(CheckRtcp1());
1228 EXPECT_TRUE(CheckRtcp2());
1229 EXPECT_TRUE(CheckNoRtcp1());
1230 EXPECT_TRUE(CheckNoRtcp2());
1231 }
1232
1233 // Test that we properly handling SRTP negotiating down to RTP.
1234 void SendSrtpToRtp() {
1235 CreateChannels(RTCP | SECURE, RTCP);
1236 EXPECT_FALSE(channel1_->secure());
1237 EXPECT_FALSE(channel2_->secure());
1238 EXPECT_TRUE(SendInitiate());
1239 EXPECT_TRUE(SendAccept());
1240 EXPECT_FALSE(channel1_->secure());
1241 EXPECT_FALSE(channel2_->secure());
1242 EXPECT_TRUE(SendRtp1());
1243 EXPECT_TRUE(SendRtp2());
1244 EXPECT_TRUE(SendRtcp1());
1245 EXPECT_TRUE(SendRtcp2());
1246 EXPECT_TRUE(CheckRtp1());
1247 EXPECT_TRUE(CheckRtp2());
1248 EXPECT_TRUE(CheckNoRtp1());
1249 EXPECT_TRUE(CheckNoRtp2());
1250 EXPECT_TRUE(CheckRtcp1());
1251 EXPECT_TRUE(CheckRtcp2());
1252 EXPECT_TRUE(CheckNoRtcp1());
1253 EXPECT_TRUE(CheckNoRtcp2());
1254 }
1255
1256 // Test that we can send and receive early media when a provisional answer is
1257 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1258 void SendEarlyMediaUsingRtcpMuxSrtp() {
1259 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1260
1261 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1262 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1263 EXPECT_TRUE(SendOffer());
1264 EXPECT_TRUE(SendProvisionalAnswer());
1265 EXPECT_TRUE(channel1_->secure());
1266 EXPECT_TRUE(channel2_->secure());
1267 EXPECT_EQ(2U, GetTransport1()->channels().size());
1268 EXPECT_EQ(2U, GetTransport2()->channels().size());
1269 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1270 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1271 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1272 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1273
1274 // Send packets from callee and verify that it is received.
1275 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1276 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1277 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1278 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1279
1280 // Complete call setup and ensure everything is still OK.
1281 EXPECT_TRUE(SendFinalAnswer());
1282 EXPECT_EQ(1U, GetTransport1()->channels().size());
1283 EXPECT_EQ(1U, GetTransport2()->channels().size());
1284 EXPECT_TRUE(channel1_->secure());
1285 EXPECT_TRUE(channel2_->secure());
1286 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1287 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1288 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1289 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1290 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1291 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1292 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1293 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1294 }
1295
1296 // Test that we properly send RTP without SRTP from a thread.
1297 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001298 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1299 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 EXPECT_TRUE(SendInitiate());
1301 EXPECT_TRUE(SendAccept());
1302 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1303 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001304 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1305 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1307 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1308 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1309 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1310 EXPECT_TRUE(CheckNoRtp1());
1311 EXPECT_TRUE(CheckNoRtp2());
1312 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1313 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1314 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1315 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1316 EXPECT_TRUE(CheckNoRtcp1());
1317 EXPECT_TRUE(CheckNoRtcp2());
1318 }
1319
1320 // Test that we properly send SRTP with RTCP from a thread.
1321 void SendSrtpToSrtpOnThread() {
1322 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1323 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1324 EXPECT_TRUE(SendInitiate());
1325 EXPECT_TRUE(SendAccept());
1326 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1327 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1328 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1329 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1330 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1331 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1332 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1333 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1334 EXPECT_TRUE(CheckNoRtp1());
1335 EXPECT_TRUE(CheckNoRtp2());
1336 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1337 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1338 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1339 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1340 EXPECT_TRUE(CheckNoRtcp1());
1341 EXPECT_TRUE(CheckNoRtcp2());
1342 }
1343
1344 // Test that the mediachannel retains its sending state after the transport
1345 // becomes non-writable.
1346 void SendWithWritabilityLoss() {
1347 CreateChannels(0, 0);
1348 EXPECT_TRUE(SendInitiate());
1349 EXPECT_TRUE(SendAccept());
1350 EXPECT_EQ(1U, GetTransport1()->channels().size());
1351 EXPECT_EQ(1U, GetTransport2()->channels().size());
1352 EXPECT_TRUE(SendRtp1());
1353 EXPECT_TRUE(SendRtp2());
1354 EXPECT_TRUE(CheckRtp1());
1355 EXPECT_TRUE(CheckRtp2());
1356 EXPECT_TRUE(CheckNoRtp1());
1357 EXPECT_TRUE(CheckNoRtp2());
1358
wu@webrtc.org97077a32013-10-25 21:18:33 +00001359 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 EXPECT_FALSE(SendRtp1());
1362 EXPECT_TRUE(SendRtp2());
1363 EXPECT_TRUE(CheckRtp1());
1364 EXPECT_TRUE(CheckNoRtp2());
1365
1366 // Regain writability
1367 GetTransport1()->SetWritable(true);
1368 EXPECT_TRUE(media_channel1_->sending());
1369 EXPECT_TRUE(SendRtp1());
1370 EXPECT_TRUE(SendRtp2());
1371 EXPECT_TRUE(CheckRtp1());
1372 EXPECT_TRUE(CheckRtp2());
1373 EXPECT_TRUE(CheckNoRtp1());
1374 EXPECT_TRUE(CheckNoRtp2());
1375
1376 // Lose writability completely
1377 GetTransport1()->SetDestination(NULL);
1378 EXPECT_TRUE(media_channel1_->sending());
1379
wu@webrtc.org97077a32013-10-25 21:18:33 +00001380 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001381 EXPECT_FALSE(SendRtp1());
1382 EXPECT_TRUE(SendRtp2());
1383 EXPECT_TRUE(CheckRtp1());
1384 EXPECT_TRUE(CheckNoRtp2());
1385
1386 // Gain writability back
1387 GetTransport1()->SetDestination(GetTransport2());
1388 EXPECT_TRUE(media_channel1_->sending());
1389 EXPECT_TRUE(SendRtp1());
1390 EXPECT_TRUE(SendRtp2());
1391 EXPECT_TRUE(CheckRtp1());
1392 EXPECT_TRUE(CheckRtp2());
1393 EXPECT_TRUE(CheckNoRtp1());
1394 EXPECT_TRUE(CheckNoRtp2());
1395 }
1396
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001397 void SendBundleToBundle(
1398 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1399 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001401 // Only pl_type1 was added to the bundle filter for both |channel1_|
1402 // and |channel2_|.
1403 int pl_type1 = pl_types[0];
1404 int pl_type2 = pl_types[1];
1405 int flags = SSRC_MUX | RTCP;
1406 if (secure) flags |= SECURE;
1407 uint32 expected_channels = 2U;
1408 if (rtcp_mux) {
1409 flags |= RTCP_MUX;
1410 expected_channels = 1U;
1411 }
1412 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 EXPECT_TRUE(SendInitiate());
1414 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001415 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001417 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1418 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1419 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1420 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1421 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1422 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1423 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1424 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1425 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1426 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1427 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1428 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1429
1430 // Both channels can receive pl_type1 only.
1431 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1432 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1433 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1434 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1435 EXPECT_TRUE(CheckNoRtp1());
1436 EXPECT_TRUE(CheckNoRtp2());
1437
1438 // RTCP test
1439 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1440 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1441 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1442 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1445 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1447 EXPECT_TRUE(CheckNoRtcp1());
1448 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1449 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001451 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1452 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1455 }
1456
1457 // Test that the media monitor can be run and gives timely callbacks.
1458 void TestMediaMonitor() {
1459 static const int kTimeout = 500;
1460 CreateChannels(0, 0);
1461 EXPECT_TRUE(SendInitiate());
1462 EXPECT_TRUE(SendAccept());
1463 channel1_->StartMediaMonitor(100);
1464 channel2_->StartMediaMonitor(100);
1465 // Ensure we get callbacks and stop.
1466 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1467 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1468 channel1_->StopMediaMonitor();
1469 channel2_->StopMediaMonitor();
1470 // Ensure a restart of a stopped monitor works.
1471 channel1_->StartMediaMonitor(100);
1472 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1473 channel1_->StopMediaMonitor();
1474 // Ensure stopping a stopped monitor is OK.
1475 channel1_->StopMediaMonitor();
1476 }
1477
1478 void TestMediaSinks() {
1479 CreateChannels(0, 0);
1480 EXPECT_TRUE(SendInitiate());
1481 EXPECT_TRUE(SendAccept());
1482 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1483 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1484 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1485 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1486
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001487 rtc::Pathname path;
1488 EXPECT_TRUE(rtc::Filesystem::GetTemporaryFolder(path, true, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001489 path.SetFilename("sink-test.rtpdump");
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001490 rtc::scoped_ptr<cricket::RtpDumpSink> sink(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 new cricket::RtpDumpSink(Open(path.pathname())));
1492 sink->set_packet_filter(cricket::PF_ALL);
1493 EXPECT_TRUE(sink->Enable(true));
1494 channel1_->RegisterSendSink(
1495 sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
1496 EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1497 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1498 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1499 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1500
1501 // The first packet is recorded with header + data.
1502 EXPECT_TRUE(SendRtp1());
1503 // The second packet is recorded with header only.
1504 sink->set_packet_filter(cricket::PF_RTPHEADER);
1505 EXPECT_TRUE(SendRtp1());
1506 // The third packet is not recorded since sink is disabled.
1507 EXPECT_TRUE(sink->Enable(false));
1508 EXPECT_TRUE(SendRtp1());
1509 // The fourth packet is not recorded since sink is unregistered.
1510 EXPECT_TRUE(sink->Enable(true));
1511 channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
1512 EXPECT_TRUE(SendRtp1());
1513 sink.reset(); // This will close the file.
1514
1515 // Read the recorded file and verify two packets.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001516 rtc::scoped_ptr<rtc::StreamInterface> stream(
1517 rtc::Filesystem::OpenFile(path, "rb"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518
1519 cricket::RtpDumpReader reader(stream.get());
1520 cricket::RtpDumpPacket packet;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001521 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
1523 packet.data.size());
1524 EXPECT_EQ(rtp_packet_, read_packet);
1525
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001526 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 size_t len = 0;
1528 packet.GetRtpHeaderLen(&len);
1529 EXPECT_EQ(len, packet.data.size());
1530 EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
1531
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001532 EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533
1534 // Delete the file for media recording.
1535 stream.reset();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001536 EXPECT_TRUE(rtc::Filesystem::DeleteFile(path));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 }
1538
1539 void TestSetContentFailure() {
1540 CreateChannels(0, 0);
1541 typename T::Content content;
1542 cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1543 cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1544
1545 // Set up the session description.
1546 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1547 sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1548 new cricket::AudioContentDescription());
1549 sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1550 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001551 session1_.set_local_description(sdesc_loc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552 sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1553 new cricket::AudioContentDescription());
1554 sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1555 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001556 session1_.set_remote_description(sdesc_rem);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557
1558 // Test failures in SetLocalContent.
1559 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001560 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001561 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1563 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001564 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001565 session1_.SetState(cricket::BaseSession::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1567
1568 // Test failures in SetRemoteContent.
1569 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001570 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001571 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1573 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001574 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001575 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1577 }
1578
1579 void TestSendTwoOffers() {
1580 CreateChannels(0, 0);
1581
1582 // Set up the initial session description.
1583 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001584 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001586 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001587 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001588 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1589 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1590
1591 // Update the local description and set the state again.
1592 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001593 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001595 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1597 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1598 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1599 }
1600
1601 void TestReceiveTwoOffers() {
1602 CreateChannels(0, 0);
1603
1604 // Set up the initial session description.
1605 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001606 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001608 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001609 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1611 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1612
1613 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001614 session1_.set_remote_description(sdesc);
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001615 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1617 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1618 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1619 }
1620
1621 void TestSendPrAnswer() {
1622 CreateChannels(0, 0);
1623
1624 // Set up the initial session description.
1625 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001626 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001628 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001629 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1631 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1632
1633 // Send PRANSWER
1634 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001635 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001637 session1_.SetState(cricket::BaseSession::STATE_SENTPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1639 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1640 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1641
1642 // Send ACCEPT
1643 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001644 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001646 session1_.SetState(cricket::BaseSession::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1648 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1649 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1650 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1651 }
1652
1653 void TestReceivePrAnswer() {
1654 CreateChannels(0, 0);
1655
1656 // Set up the initial session description.
1657 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001658 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001660 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001661 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1663 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1664
1665 // Receive PRANSWER
1666 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001667 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001669 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1671 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1672 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1673
1674 // Receive ACCEPT
1675 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001676 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001678 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1680 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1681 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1682 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1683 }
1684
1685 void TestFlushRtcp() {
1686 bool send_rtcp1;
1687
1688 CreateChannels(RTCP, RTCP);
1689 EXPECT_TRUE(SendInitiate());
1690 EXPECT_TRUE(SendAccept());
1691 EXPECT_EQ(2U, GetTransport1()->channels().size());
1692 EXPECT_EQ(2U, GetTransport2()->channels().size());
1693
1694 // Send RTCP1 from a different thread.
1695 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1696 EXPECT_TRUE(send_rtcp1);
1697 // The sending message is only posted. channel2_ should be empty.
1698 EXPECT_TRUE(CheckNoRtcp2());
1699
1700 // When channel1_ is deleted, the RTCP packet should be sent out to
1701 // channel2_.
1702 channel1_.reset();
1703 EXPECT_TRUE(CheckRtcp2());
1704 }
1705
1706 void TestChangeStateError() {
1707 CreateChannels(RTCP, RTCP);
1708 EXPECT_TRUE(SendInitiate());
1709 media_channel2_->set_fail_set_send(true);
1710 EXPECT_TRUE(channel2_->Enable(true));
1711 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1712 error_);
1713 }
1714
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001715 void TestSrtpError(int pl_type) {
1716 // For Audio, only pl_type 0 is added to the bundle filter.
1717 // For Video, only pl_type 97 is added to the bundle filter.
1718 // So we need to pass in pl_type so that the packet can pass through
1719 // the bundle filter before it can be processed by the srtp filter.
1720 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001721 unsigned const char kBadPacket[] = {0x84,
1722 static_cast<unsigned char>(pl_type),
1723 0x00,
1724 0x01,
1725 0x00,
1726 0x00,
1727 0x00,
1728 0x00,
1729 0x00,
1730 0x00,
1731 0x00,
1732 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1734 EXPECT_FALSE(channel1_->secure());
1735 EXPECT_FALSE(channel2_->secure());
1736 EXPECT_TRUE(SendInitiate());
1737 EXPECT_TRUE(SendAccept());
1738 EXPECT_TRUE(channel1_->secure());
1739 EXPECT_TRUE(channel2_->secure());
1740 channel2_->set_srtp_signal_silent_time(200);
1741
1742 // Testing failures in sending packets.
1743 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1744 // The first failure will trigger an error.
1745 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1746 error_ = T::MediaChannel::ERROR_NONE;
1747 // The next 1 sec failures will not trigger an error.
1748 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1749 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001750 rtc::Thread::Current()->ProcessMessages(210);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1752 // The error will be triggered again.
1753 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1754 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1755
1756 // Testing failures in receiving packets.
1757 error_ = T::MediaChannel::ERROR_NONE;
1758 cricket::TransportChannel* transport_channel =
1759 channel2_->transport_channel();
1760 transport_channel->SignalReadPacket(
1761 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001762 sizeof(kBadPacket), rtc::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001763 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 }
1765
1766 void TestOnReadyToSend() {
1767 CreateChannels(RTCP, RTCP);
1768 TransportChannel* rtp = channel1_->transport_channel();
1769 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1770 EXPECT_FALSE(media_channel1_->ready_to_send());
1771 rtp->SignalReadyToSend(rtp);
1772 EXPECT_FALSE(media_channel1_->ready_to_send());
1773 rtcp->SignalReadyToSend(rtcp);
1774 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1775 // channel are ready to send.
1776 EXPECT_TRUE(media_channel1_->ready_to_send());
1777
1778 // rtp channel becomes not ready to send will be propagated to mediachannel
1779 channel1_->SetReadyToSend(rtp, false);
1780 EXPECT_FALSE(media_channel1_->ready_to_send());
1781 channel1_->SetReadyToSend(rtp, true);
1782 EXPECT_TRUE(media_channel1_->ready_to_send());
1783
1784 // rtcp channel becomes not ready to send will be propagated to mediachannel
1785 channel1_->SetReadyToSend(rtcp, false);
1786 EXPECT_FALSE(media_channel1_->ready_to_send());
1787 channel1_->SetReadyToSend(rtcp, true);
1788 EXPECT_TRUE(media_channel1_->ready_to_send());
1789 }
1790
1791 void TestOnReadyToSendWithRtcpMux() {
1792 CreateChannels(RTCP, RTCP);
1793 typename T::Content content;
1794 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1795 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1796 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001797 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1798 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1800 TransportChannel* rtp = channel1_->transport_channel();
1801 EXPECT_FALSE(media_channel1_->ready_to_send());
1802 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1803 // should trigger the MediaChannel's OnReadyToSend.
1804 rtp->SignalReadyToSend(rtp);
1805 EXPECT_TRUE(media_channel1_->ready_to_send());
1806 channel1_->SetReadyToSend(rtp, false);
1807 EXPECT_FALSE(media_channel1_->ready_to_send());
1808 }
1809
1810 protected:
1811 cricket::FakeSession session1_;
1812 cricket::FakeSession session2_;
1813 cricket::FakeMediaEngine media_engine_;
1814 // The media channels are owned by the voice channel objects below.
1815 typename T::MediaChannel* media_channel1_;
1816 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001817 rtc::scoped_ptr<typename T::Channel> channel1_;
1818 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 typename T::Content local_media_content1_;
1820 typename T::Content local_media_content2_;
1821 typename T::Content remote_media_content1_;
1822 typename T::Content remote_media_content2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001823 rtc::scoped_ptr<rtc::SSLIdentity> identity1_;
1824 rtc::scoped_ptr<rtc::SSLIdentity> identity2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 // The RTP and RTCP packets to send in the tests.
1826 std::string rtp_packet_;
1827 std::string rtcp_packet_;
1828 int media_info_callbacks1_;
1829 int media_info_callbacks2_;
1830 bool mute_callback_recved_;
1831 bool mute_callback_value_;
1832
1833 uint32 ssrc_;
1834 typename T::MediaChannel::Error error_;
1835};
1836
1837
1838template<>
1839void ChannelTest<VoiceTraits>::CreateContent(
1840 int flags,
1841 const cricket::AudioCodec& audio_codec,
1842 const cricket::VideoCodec& video_codec,
1843 cricket::AudioContentDescription* audio) {
1844 audio->AddCodec(audio_codec);
1845 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1846 if (flags & SECURE) {
1847 audio->AddCrypto(cricket::CryptoParams(
1848 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001849 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 }
1851}
1852
1853template<>
1854void ChannelTest<VoiceTraits>::CopyContent(
1855 const cricket::AudioContentDescription& source,
1856 cricket::AudioContentDescription* audio) {
1857 *audio = source;
1858}
1859
1860template<>
1861bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1862 const cricket::AudioCodec& c2) {
1863 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1864 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1865}
1866
1867template<>
1868void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1869 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1870 audio->AddLegacyStream(ssrc);
1871}
1872
1873class VoiceChannelTest
1874 : public ChannelTest<VoiceTraits> {
1875 public:
1876 typedef ChannelTest<VoiceTraits>
1877 Base;
1878 VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1879 kRtcpReport, sizeof(kRtcpReport)) {
1880 }
1881
1882 void TestSetChannelOptions() {
1883 CreateChannels(0, 0);
1884
1885 cricket::AudioOptions options1;
1886 options1.echo_cancellation.Set(false);
1887 cricket::AudioOptions options2;
1888 options2.echo_cancellation.Set(true);
1889
1890 channel1_->SetChannelOptions(options1);
1891 channel2_->SetChannelOptions(options1);
1892 cricket::AudioOptions actual_options;
1893 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1894 EXPECT_EQ(options1, actual_options);
1895 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1896 EXPECT_EQ(options1, actual_options);
1897
1898 channel1_->SetChannelOptions(options2);
1899 channel2_->SetChannelOptions(options2);
1900 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1901 EXPECT_EQ(options2, actual_options);
1902 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1903 EXPECT_EQ(options2, actual_options);
1904 }
1905};
1906
1907// override to add NULL parameter
1908template<>
1909cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001910 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1912 bool rtcp) {
1913 cricket::VideoChannel* channel = new cricket::VideoChannel(
Fredrik Solenberg7fb711f2015-04-22 15:30:51 +02001914 thread, engine, ch, session, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 if (!channel->Init()) {
1916 delete channel;
1917 channel = NULL;
1918 }
1919 return channel;
1920}
1921
1922// override to add 0 parameter
1923template<>
1924bool ChannelTest<VideoTraits>::AddStream1(int id) {
1925 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1926}
1927
1928template<>
1929void ChannelTest<VideoTraits>::CreateContent(
1930 int flags,
1931 const cricket::AudioCodec& audio_codec,
1932 const cricket::VideoCodec& video_codec,
1933 cricket::VideoContentDescription* video) {
1934 video->AddCodec(video_codec);
1935 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1936 if (flags & SECURE) {
1937 video->AddCrypto(cricket::CryptoParams(
1938 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001939 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001940 }
1941}
1942
1943template<>
1944void ChannelTest<VideoTraits>::CopyContent(
1945 const cricket::VideoContentDescription& source,
1946 cricket::VideoContentDescription* video) {
1947 *video = source;
1948}
1949
1950template<>
1951bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1952 const cricket::VideoCodec& c2) {
1953 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1954 c1.framerate == c2.framerate;
1955}
1956
1957template<>
1958void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1959 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1960 video->AddLegacyStream(ssrc);
1961}
1962
1963class VideoChannelTest
1964 : public ChannelTest<VideoTraits> {
1965 public:
1966 typedef ChannelTest<VideoTraits>
1967 Base;
1968 VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
1969 kRtcpReport, sizeof(kRtcpReport)) {
1970 }
1971
1972 void TestSetChannelOptions() {
1973 CreateChannels(0, 0);
1974
1975 cricket::VideoOptions o1, o2;
1976 o1.video_noise_reduction.Set(true);
1977
1978 channel1_->SetChannelOptions(o1);
1979 channel2_->SetChannelOptions(o1);
1980 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
1981 EXPECT_EQ(o1, o2);
1982 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
1983 EXPECT_EQ(o1, o2);
1984
buildbot@webrtc.org81ddc782014-10-14 22:39:24 +00001985 o1.video_start_bitrate.Set(123);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 channel1_->SetChannelOptions(o1);
1987 channel2_->SetChannelOptions(o1);
1988 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
1989 EXPECT_EQ(o1, o2);
1990 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
1991 EXPECT_EQ(o1, o2);
1992 }
1993};
1994
1995
1996// VoiceChannelTest
1997
1998TEST_F(VoiceChannelTest, TestInit) {
1999 Base::TestInit();
2000 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2001 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2002}
2003
2004TEST_F(VoiceChannelTest, TestSetContents) {
2005 Base::TestSetContents();
2006}
2007
2008TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2009 Base::TestSetContentsNullOffer();
2010}
2011
2012TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2013 Base::TestSetContentsRtcpMux();
2014}
2015
2016TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2017 Base::TestSetContentsRtcpMux();
2018}
2019
2020TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2021 Base::TestSetRemoteContentUpdate();
2022}
2023
2024TEST_F(VoiceChannelTest, TestStreams) {
2025 Base::TestStreams();
2026}
2027
2028TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2029 Base::TestUpdateStreamsInLocalContent();
2030}
2031
2032TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2033 Base::TestUpdateStreamsInRemoteContent();
2034}
2035
2036TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2037 Base::TestChangeStreamParamsInContent();
2038}
2039
2040TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2041 Base::TestPlayoutAndSendingStates();
2042}
2043
2044TEST_F(VoiceChannelTest, TestMuteStream) {
2045 Base::TestMuteStream();
2046}
2047
2048TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2049 Base::TestMediaContentDirection();
2050}
2051
2052TEST_F(VoiceChannelTest, TestCallSetup) {
2053 Base::TestCallSetup();
2054}
2055
2056TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2057 Base::TestCallTeardownRtcpMux();
2058}
2059
2060TEST_F(VoiceChannelTest, SendRtpToRtp) {
2061 Base::SendRtpToRtp();
2062}
2063
2064TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2065 Base::SendNoRtcpToNoRtcp();
2066}
2067
2068TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2069 Base::SendNoRtcpToRtcp();
2070}
2071
2072TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2073 Base::SendRtcpToNoRtcp();
2074}
2075
2076TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2077 Base::SendRtcpToRtcp();
2078}
2079
2080TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2081 Base::SendRtcpMuxToRtcp();
2082}
2083
2084TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2085 Base::SendRtcpMuxToRtcpMux();
2086}
2087
2088TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2089 Base::SendEarlyRtcpMuxToRtcp();
2090}
2091
2092TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2093 Base::SendEarlyRtcpMuxToRtcpMux();
2094}
2095
2096TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2097 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2098}
2099
2100TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2101 Base::SendSrtpToSrtp();
2102}
2103
2104TEST_F(VoiceChannelTest, SendSrtcpMux) {
2105 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2106}
2107
2108TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2109 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2110 Base::SendSrtpToSrtp(DTLS, 0);
2111}
2112
2113TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2114 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2115 Base::SendSrtpToSrtp(DTLS, DTLS);
2116}
2117
2118TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2119 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2120 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2121}
2122
2123TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2124 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2125}
2126
2127TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2128 Base::SendRtpToRtpOnThread();
2129}
2130
2131TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2132 Base::SendSrtpToSrtpOnThread();
2133}
2134
2135TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2136 Base::SendWithWritabilityLoss();
2137}
2138
2139TEST_F(VoiceChannelTest, TestMediaMonitor) {
2140 Base::TestMediaMonitor();
2141}
2142
2143// Test that MuteStream properly forwards to the media channel and does
2144// not signal.
2145TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
2146 CreateChannels(0, 0);
2147 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2148 EXPECT_FALSE(mute_callback_recved_);
2149 EXPECT_TRUE(channel1_->MuteStream(0, true));
2150 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2151 EXPECT_FALSE(mute_callback_recved_);
2152 EXPECT_TRUE(channel1_->MuteStream(0, false));
2153 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2154 EXPECT_FALSE(mute_callback_recved_);
2155}
2156
2157// Test that keyboard automute works correctly and signals upwards.
asapersson@webrtc.orgb533a822013-09-23 19:47:49 +00002158TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 CreateChannels(0, 0);
2160 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2161 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
2162
2163 cricket::VoiceMediaChannel::Error e =
2164 cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
2165
2166 // Typing doesn't mute automatically unless typing monitor has been installed
2167 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002168 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 EXPECT_EQ(e, error_);
2170 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2171 EXPECT_FALSE(mute_callback_recved_);
2172
2173 cricket::TypingMonitorOptions o = {0};
2174 o.mute_period = 1500;
2175 channel1_->StartTypingMonitor(o);
2176 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002177 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2179 EXPECT_TRUE(mute_callback_recved_);
2180}
2181
2182// Test that PressDTMF properly forwards to the media channel.
2183TEST_F(VoiceChannelTest, TestDtmf) {
2184 CreateChannels(0, 0);
2185 EXPECT_TRUE(SendInitiate());
2186 EXPECT_TRUE(SendAccept());
2187 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2188
2189 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2190 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2191
2192 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2193 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2194 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2195 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2196 0, 8, 160, cricket::DF_SEND));
2197}
2198
2199// Test that InsertDtmf properly forwards to the media channel.
2200TEST_F(VoiceChannelTest, TestInsertDtmf) {
2201 CreateChannels(0, 0);
2202 EXPECT_TRUE(SendInitiate());
2203 EXPECT_TRUE(SendAccept());
2204 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2205
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2207 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2208 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2209 cricket::DF_PLAY | cricket::DF_SEND));
2210
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002211 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002214 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002216 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002217 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2218}
2219
2220TEST_F(VoiceChannelTest, TestMediaSinks) {
2221 Base::TestMediaSinks();
2222}
2223
2224TEST_F(VoiceChannelTest, TestSetContentFailure) {
2225 Base::TestSetContentFailure();
2226}
2227
2228TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2229 Base::TestSendTwoOffers();
2230}
2231
2232TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2233 Base::TestReceiveTwoOffers();
2234}
2235
2236TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2237 Base::TestSendPrAnswer();
2238}
2239
2240TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2241 Base::TestReceivePrAnswer();
2242}
2243
2244TEST_F(VoiceChannelTest, TestFlushRtcp) {
2245 Base::TestFlushRtcp();
2246}
2247
2248TEST_F(VoiceChannelTest, TestChangeStateError) {
2249 Base::TestChangeStateError();
2250}
2251
2252TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002253 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002254}
2255
2256TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2257 Base::TestOnReadyToSend();
2258}
2259
2260TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2261 Base::TestOnReadyToSendWithRtcpMux();
2262}
2263
2264// Test that we can play a ringback tone properly.
2265TEST_F(VoiceChannelTest, TestRingbackTone) {
2266 CreateChannels(RTCP, RTCP);
2267 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2268 EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
2269 EXPECT_TRUE(SendInitiate());
2270 EXPECT_TRUE(SendAccept());
2271 // Play ringback tone, no loop.
2272 EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
2273 EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
2274 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2275 EXPECT_FALSE(media_channel1_->ringback_tone_loop());
2276 // Stop the ringback tone.
2277 EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
2278 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2279 // Add a stream.
2280 EXPECT_TRUE(AddStream1(1));
2281 // Play ringback tone, looping, on the new stream.
2282 EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
2283 EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
2284 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2285 EXPECT_TRUE(media_channel1_->ringback_tone_loop());
2286 // Stop the ringback tone.
2287 EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
2288 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2289}
2290
2291// Test that we can scale the output volume properly for 1:1 calls.
2292TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2293 CreateChannels(RTCP, RTCP);
2294 EXPECT_TRUE(SendInitiate());
2295 EXPECT_TRUE(SendAccept());
2296 double left, right;
2297
2298 // Default is (1.0, 1.0).
2299 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2300 EXPECT_DOUBLE_EQ(1.0, left);
2301 EXPECT_DOUBLE_EQ(1.0, right);
2302 // invalid ssrc.
2303 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2304
2305 // Set scale to (1.5, 0.5).
2306 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2307 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2308 EXPECT_DOUBLE_EQ(1.5, left);
2309 EXPECT_DOUBLE_EQ(0.5, right);
2310
2311 // Set scale to (0, 0).
2312 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2313 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2314 EXPECT_DOUBLE_EQ(0.0, left);
2315 EXPECT_DOUBLE_EQ(0.0, right);
2316}
2317
2318// Test that we can scale the output volume properly for multiway calls.
2319TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2320 CreateChannels(RTCP, RTCP);
2321 EXPECT_TRUE(SendInitiate());
2322 EXPECT_TRUE(SendAccept());
2323 EXPECT_TRUE(AddStream1(1));
2324 EXPECT_TRUE(AddStream1(2));
2325
2326 double left, right;
2327 // Default is (1.0, 1.0).
2328 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2329 EXPECT_DOUBLE_EQ(1.0, left);
2330 EXPECT_DOUBLE_EQ(1.0, right);
2331 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2332 EXPECT_DOUBLE_EQ(1.0, left);
2333 EXPECT_DOUBLE_EQ(1.0, right);
2334 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2335 EXPECT_DOUBLE_EQ(1.0, left);
2336 EXPECT_DOUBLE_EQ(1.0, right);
2337 // invalid ssrc.
2338 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2339
2340 // Set scale to (1.5, 0.5) for ssrc = 1.
2341 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2342 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2343 EXPECT_DOUBLE_EQ(1.5, left);
2344 EXPECT_DOUBLE_EQ(0.5, right);
2345 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2346 EXPECT_DOUBLE_EQ(1.0, left);
2347 EXPECT_DOUBLE_EQ(1.0, right);
2348 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2349 EXPECT_DOUBLE_EQ(1.0, left);
2350 EXPECT_DOUBLE_EQ(1.0, right);
2351
2352 // Set scale to (0, 0) for all ssrcs.
2353 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2354 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2355 EXPECT_DOUBLE_EQ(0.0, left);
2356 EXPECT_DOUBLE_EQ(0.0, right);
2357 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2358 EXPECT_DOUBLE_EQ(0.0, left);
2359 EXPECT_DOUBLE_EQ(0.0, right);
2360 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2361 EXPECT_DOUBLE_EQ(0.0, left);
2362 EXPECT_DOUBLE_EQ(0.0, right);
2363}
2364
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002365TEST_F(VoiceChannelTest, SendBundleToBundle) {
2366 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367}
2368
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002369TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2370 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2371}
2372
2373TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2374 Base::SendBundleToBundle(
2375 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2376}
2377
2378TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2379 Base::SendBundleToBundle(
2380 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381}
2382
2383TEST_F(VoiceChannelTest, TestSetChannelOptions) {
2384 TestSetChannelOptions();
2385}
2386
2387// VideoChannelTest
2388TEST_F(VideoChannelTest, TestInit) {
2389 Base::TestInit();
2390}
2391
2392TEST_F(VideoChannelTest, TestSetContents) {
2393 Base::TestSetContents();
2394}
2395
2396TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2397 Base::TestSetContentsNullOffer();
2398}
2399
2400TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2401 Base::TestSetContentsRtcpMux();
2402}
2403
2404TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2405 Base::TestSetContentsRtcpMux();
2406}
2407
2408TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
2409 Base::TestSetContentsVideoOptions();
2410}
2411
2412TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2413 Base::TestSetRemoteContentUpdate();
2414}
2415
2416TEST_F(VideoChannelTest, TestStreams) {
2417 Base::TestStreams();
2418}
2419
2420TEST_F(VideoChannelTest, TestScreencastEvents) {
2421 const int kTimeoutMs = 500;
2422 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 cricket::ScreencastEventCatcher catcher;
2424 channel1_->SignalScreencastWindowEvent.connect(
2425 &catcher,
2426 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002427
2428 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2429 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2430 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2431 ScreencastId(WindowId(0)));
2432 ASSERT_TRUE(screen_capturer != NULL);
2433
2434 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2435 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002437
2438 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002439 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002440
2441 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002442 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002443
2444 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002445 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002446
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002447 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448}
2449
2450TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2451 Base::TestUpdateStreamsInLocalContent();
2452}
2453
2454TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2455 Base::TestUpdateStreamsInRemoteContent();
2456}
2457
2458TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2459 Base::TestChangeStreamParamsInContent();
2460}
2461
2462TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2463 Base::TestPlayoutAndSendingStates();
2464}
2465
2466TEST_F(VideoChannelTest, TestMuteStream) {
2467 Base::TestMuteStream();
2468}
2469
2470TEST_F(VideoChannelTest, TestMediaContentDirection) {
2471 Base::TestMediaContentDirection();
2472}
2473
2474TEST_F(VideoChannelTest, TestCallSetup) {
2475 Base::TestCallSetup();
2476}
2477
2478TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2479 Base::TestCallTeardownRtcpMux();
2480}
2481
2482TEST_F(VideoChannelTest, SendRtpToRtp) {
2483 Base::SendRtpToRtp();
2484}
2485
2486TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2487 Base::SendNoRtcpToNoRtcp();
2488}
2489
2490TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2491 Base::SendNoRtcpToRtcp();
2492}
2493
2494TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2495 Base::SendRtcpToNoRtcp();
2496}
2497
2498TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2499 Base::SendRtcpToRtcp();
2500}
2501
2502TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2503 Base::SendRtcpMuxToRtcp();
2504}
2505
2506TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2507 Base::SendRtcpMuxToRtcpMux();
2508}
2509
2510TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2511 Base::SendEarlyRtcpMuxToRtcp();
2512}
2513
2514TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2515 Base::SendEarlyRtcpMuxToRtcpMux();
2516}
2517
2518TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2519 Base::SendSrtpToSrtp();
2520}
2521
2522TEST_F(VideoChannelTest, SendSrtpToRtp) {
2523 Base::SendSrtpToSrtp();
2524}
2525
2526TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2527 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2528 Base::SendSrtpToSrtp(DTLS, 0);
2529}
2530
2531TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2532 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2533 Base::SendSrtpToSrtp(DTLS, DTLS);
2534}
2535
2536TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2537 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2538 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2539}
2540
2541TEST_F(VideoChannelTest, SendSrtcpMux) {
2542 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2543}
2544
2545TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2546 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2547}
2548
2549TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2550 Base::SendRtpToRtpOnThread();
2551}
2552
2553TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2554 Base::SendSrtpToSrtpOnThread();
2555}
2556
2557TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2558 Base::SendWithWritabilityLoss();
2559}
2560
2561TEST_F(VideoChannelTest, TestMediaMonitor) {
2562 Base::TestMediaMonitor();
2563}
2564
2565TEST_F(VideoChannelTest, TestMediaSinks) {
2566 Base::TestMediaSinks();
2567}
2568
2569TEST_F(VideoChannelTest, TestSetContentFailure) {
2570 Base::TestSetContentFailure();
2571}
2572
2573TEST_F(VideoChannelTest, TestSendTwoOffers) {
2574 Base::TestSendTwoOffers();
2575}
2576
2577TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2578 Base::TestReceiveTwoOffers();
2579}
2580
2581TEST_F(VideoChannelTest, TestSendPrAnswer) {
2582 Base::TestSendPrAnswer();
2583}
2584
2585TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2586 Base::TestReceivePrAnswer();
2587}
2588
2589TEST_F(VideoChannelTest, TestFlushRtcp) {
2590 Base::TestFlushRtcp();
2591}
2592
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002593TEST_F(VideoChannelTest, SendBundleToBundle) {
2594 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595}
2596
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002597TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2598 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2599}
2600
2601TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2602 Base::SendBundleToBundle(
2603 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2604}
2605
2606TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2607 Base::SendBundleToBundle(
2608 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609}
2610
2611// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2612
2613TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002614 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615}
2616
2617TEST_F(VideoChannelTest, TestOnReadyToSend) {
2618 Base::TestOnReadyToSend();
2619}
2620
2621TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2622 Base::TestOnReadyToSendWithRtcpMux();
2623}
2624
2625TEST_F(VideoChannelTest, TestApplyViewRequest) {
2626 CreateChannels(0, 0);
2627 cricket::StreamParams stream2;
2628 stream2.id = "stream2";
2629 stream2.ssrcs.push_back(2222);
2630 local_media_content1_.AddStream(stream2);
2631
2632 EXPECT_TRUE(SendInitiate());
2633 EXPECT_TRUE(SendAccept());
2634
2635 cricket::VideoFormat send_format;
2636 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2637 EXPECT_EQ(640, send_format.width);
2638 EXPECT_EQ(400, send_format.height);
2639 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2640
2641 cricket::ViewRequest request;
2642 // stream1: 320x200x15; stream2: 0x0x0
2643 request.static_video_views.push_back(cricket::StaticVideoView(
2644 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2645 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2646 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2647 EXPECT_EQ(320, send_format.width);
2648 EXPECT_EQ(200, send_format.height);
2649 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2650 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2651 EXPECT_EQ(0, send_format.width);
2652 EXPECT_EQ(0, send_format.height);
2653
2654 // stream1: 160x100x8; stream2: 0x0x0
2655 request.static_video_views.clear();
2656 request.static_video_views.push_back(cricket::StaticVideoView(
2657 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2658 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2659 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2660 EXPECT_EQ(160, send_format.width);
2661 EXPECT_EQ(100, send_format.height);
2662 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2663
2664 // stream1: 0x0x0; stream2: 640x400x30
2665 request.static_video_views.clear();
2666 request.static_video_views.push_back(cricket::StaticVideoView(
2667 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2668 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2669 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2670 EXPECT_EQ(0, send_format.width);
2671 EXPECT_EQ(0, send_format.height);
2672 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2673 EXPECT_EQ(640, send_format.width);
2674 EXPECT_EQ(400, send_format.height);
2675 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2676
2677 // stream1: 0x0x0; stream2: 0x0x0
2678 request.static_video_views.clear();
2679 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2680 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2681 EXPECT_EQ(0, send_format.width);
2682 EXPECT_EQ(0, send_format.height);
2683}
2684
2685TEST_F(VideoChannelTest, TestSetChannelOptions) {
2686 TestSetChannelOptions();
2687}
2688
2689
2690// DataChannelTest
2691
2692class DataChannelTest
2693 : public ChannelTest<DataTraits> {
2694 public:
2695 typedef ChannelTest<DataTraits>
2696 Base;
2697 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2698 kRtcpReport, sizeof(kRtcpReport)) {
2699 }
2700};
2701
2702// Override to avoid engine channel parameter.
2703template<>
2704cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002705 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2707 bool rtcp) {
2708 cricket::DataChannel* channel = new cricket::DataChannel(
2709 thread, ch, session, cricket::CN_DATA, rtcp);
2710 if (!channel->Init()) {
2711 delete channel;
2712 channel = NULL;
2713 }
2714 return channel;
2715}
2716
2717template<>
2718void ChannelTest<DataTraits>::CreateContent(
2719 int flags,
2720 const cricket::AudioCodec& audio_codec,
2721 const cricket::VideoCodec& video_codec,
2722 cricket::DataContentDescription* data) {
2723 data->AddCodec(kGoogleDataCodec);
2724 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2725 if (flags & SECURE) {
2726 data->AddCrypto(cricket::CryptoParams(
2727 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002728 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 }
2730}
2731
2732template<>
2733void ChannelTest<DataTraits>::CopyContent(
2734 const cricket::DataContentDescription& source,
2735 cricket::DataContentDescription* data) {
2736 *data = source;
2737}
2738
2739template<>
2740bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2741 const cricket::DataCodec& c2) {
2742 return c1.name == c2.name;
2743}
2744
2745template<>
2746void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2747 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2748 data->AddLegacyStream(ssrc);
2749}
2750
2751TEST_F(DataChannelTest, TestInit) {
2752 Base::TestInit();
2753 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2754}
2755
2756TEST_F(DataChannelTest, TestSetContents) {
2757 Base::TestSetContents();
2758}
2759
2760TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2761 Base::TestSetContentsNullOffer();
2762}
2763
2764TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2765 Base::TestSetContentsRtcpMux();
2766}
2767
2768TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2769 Base::TestSetRemoteContentUpdate();
2770}
2771
2772TEST_F(DataChannelTest, TestStreams) {
2773 Base::TestStreams();
2774}
2775
2776TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2777 Base::TestUpdateStreamsInLocalContent();
2778}
2779
2780TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2781 Base::TestUpdateStreamsInRemoteContent();
2782}
2783
2784TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2785 Base::TestChangeStreamParamsInContent();
2786}
2787
2788TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2789 Base::TestPlayoutAndSendingStates();
2790}
2791
2792TEST_F(DataChannelTest, TestMediaContentDirection) {
2793 Base::TestMediaContentDirection();
2794}
2795
2796TEST_F(DataChannelTest, TestCallSetup) {
2797 Base::TestCallSetup();
2798}
2799
2800TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2801 Base::TestCallTeardownRtcpMux();
2802}
2803
2804TEST_F(DataChannelTest, TestOnReadyToSend) {
2805 Base::TestOnReadyToSend();
2806}
2807
2808TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2809 Base::TestOnReadyToSendWithRtcpMux();
2810}
2811
2812TEST_F(DataChannelTest, SendRtpToRtp) {
2813 Base::SendRtpToRtp();
2814}
2815
2816TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2817 Base::SendNoRtcpToNoRtcp();
2818}
2819
2820TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2821 Base::SendNoRtcpToRtcp();
2822}
2823
2824TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2825 Base::SendRtcpToNoRtcp();
2826}
2827
2828TEST_F(DataChannelTest, SendRtcpToRtcp) {
2829 Base::SendRtcpToRtcp();
2830}
2831
2832TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2833 Base::SendRtcpMuxToRtcp();
2834}
2835
2836TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2837 Base::SendRtcpMuxToRtcpMux();
2838}
2839
2840TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2841 Base::SendEarlyRtcpMuxToRtcp();
2842}
2843
2844TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2845 Base::SendEarlyRtcpMuxToRtcpMux();
2846}
2847
2848TEST_F(DataChannelTest, SendSrtpToSrtp) {
2849 Base::SendSrtpToSrtp();
2850}
2851
2852TEST_F(DataChannelTest, SendSrtpToRtp) {
2853 Base::SendSrtpToSrtp();
2854}
2855
2856TEST_F(DataChannelTest, SendSrtcpMux) {
2857 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2858}
2859
2860TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2861 Base::SendRtpToRtpOnThread();
2862}
2863
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2865 Base::SendSrtpToSrtpOnThread();
2866}
2867
2868TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2869 Base::SendWithWritabilityLoss();
2870}
2871
2872TEST_F(DataChannelTest, TestMediaMonitor) {
2873 Base::TestMediaMonitor();
2874}
2875
2876TEST_F(DataChannelTest, TestSendData) {
2877 CreateChannels(0, 0);
2878 EXPECT_TRUE(SendInitiate());
2879 EXPECT_TRUE(SendAccept());
2880
2881 cricket::SendDataParams params;
2882 params.ssrc = 42;
2883 unsigned char data[] = {
2884 'f', 'o', 'o'
2885 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002886 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 cricket::SendDataResult result;
2888 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2889 EXPECT_EQ(params.ssrc,
2890 media_channel1_->last_sent_data_params().ssrc);
2891 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2892}
2893
2894// TODO(pthatcher): TestSetReceiver?