blob: 8128190a50e6029a5b76128d95f79068be060e7e [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
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07001143 // Check that RTP and RTCP are transmitted ok when both sides
1144 // support mux and one the offerer requires mux.
1145 void SendRequireRtcpMuxToRtcpMux() {
1146 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1147 channel1_->ActivateRtcpMux();
1148 EXPECT_TRUE(SendInitiate());
1149 EXPECT_EQ(1U, GetTransport1()->channels().size());
1150 EXPECT_EQ(1U, GetTransport2()->channels().size());
1151 EXPECT_TRUE(SendAccept());
1152 EXPECT_TRUE(SendRtp1());
1153 EXPECT_TRUE(SendRtp2());
1154 EXPECT_TRUE(SendRtcp1());
1155 EXPECT_TRUE(SendRtcp2());
1156 EXPECT_TRUE(CheckRtp1());
1157 EXPECT_TRUE(CheckRtp2());
1158 EXPECT_TRUE(CheckNoRtp1());
1159 EXPECT_TRUE(CheckNoRtp2());
1160 EXPECT_TRUE(CheckRtcp1());
1161 EXPECT_TRUE(CheckRtcp2());
1162 EXPECT_TRUE(CheckNoRtcp1());
1163 EXPECT_TRUE(CheckNoRtcp2());
1164 }
1165
1166 // Check that RTP and RTCP are transmitted ok when both sides
1167 // support mux and one the answerer requires rtcp mux.
1168 void SendRtcpMuxToRequireRtcpMux() {
1169 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1170 channel2_->ActivateRtcpMux();
1171 EXPECT_TRUE(SendInitiate());
1172 EXPECT_EQ(2U, GetTransport1()->channels().size());
1173 EXPECT_EQ(1U, GetTransport2()->channels().size());
1174 EXPECT_TRUE(SendAccept());
1175 EXPECT_EQ(1U, GetTransport1()->channels().size());
1176 EXPECT_TRUE(SendRtp1());
1177 EXPECT_TRUE(SendRtp2());
1178 EXPECT_TRUE(SendRtcp1());
1179 EXPECT_TRUE(SendRtcp2());
1180 EXPECT_TRUE(CheckRtp1());
1181 EXPECT_TRUE(CheckRtp2());
1182 EXPECT_TRUE(CheckNoRtp1());
1183 EXPECT_TRUE(CheckNoRtp2());
1184 EXPECT_TRUE(CheckRtcp1());
1185 EXPECT_TRUE(CheckRtcp2());
1186 EXPECT_TRUE(CheckNoRtcp1());
1187 EXPECT_TRUE(CheckNoRtcp2());
1188 }
1189
1190 // Check that RTP and RTCP are transmitted ok when both sides
1191 // require mux.
1192 void SendRequireRtcpMuxToRequireRtcpMux() {
1193 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1194 channel1_->ActivateRtcpMux();
1195 channel2_->ActivateRtcpMux();
1196 EXPECT_TRUE(SendInitiate());
1197 EXPECT_EQ(1U, GetTransport1()->channels().size());
1198 EXPECT_EQ(1U, GetTransport2()->channels().size());
1199 EXPECT_TRUE(SendAccept());
1200 EXPECT_EQ(1U, GetTransport1()->channels().size());
1201 EXPECT_TRUE(SendRtp1());
1202 EXPECT_TRUE(SendRtp2());
1203 EXPECT_TRUE(SendRtcp1());
1204 EXPECT_TRUE(SendRtcp2());
1205 EXPECT_TRUE(CheckRtp1());
1206 EXPECT_TRUE(CheckRtp2());
1207 EXPECT_TRUE(CheckNoRtp1());
1208 EXPECT_TRUE(CheckNoRtp2());
1209 EXPECT_TRUE(CheckRtcp1());
1210 EXPECT_TRUE(CheckRtcp2());
1211 EXPECT_TRUE(CheckNoRtcp1());
1212 EXPECT_TRUE(CheckNoRtcp2());
1213 }
1214
1215 // Check that SendAccept fails if the answerer doesn't support mux
1216 // and the offerer requires it.
1217 void SendRequireRtcpMuxToNoRtcpMux() {
1218 CreateChannels(RTCP | RTCP_MUX, RTCP);
1219 channel1_->ActivateRtcpMux();
1220 EXPECT_TRUE(SendInitiate());
1221 EXPECT_EQ(1U, GetTransport1()->channels().size());
1222 EXPECT_EQ(2U, GetTransport2()->channels().size());
1223 EXPECT_FALSE(SendAccept());
1224 }
1225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226 // Check that RTCP data sent by the initiator before the accept is not muxed.
1227 void SendEarlyRtcpMuxToRtcp() {
1228 CreateChannels(RTCP | RTCP_MUX, RTCP);
1229 EXPECT_TRUE(SendInitiate());
1230 EXPECT_EQ(2U, GetTransport1()->channels().size());
1231 EXPECT_EQ(2U, GetTransport2()->channels().size());
1232
1233 // RTCP can be sent before the call is accepted, if the transport is ready.
1234 // It should not be muxed though, as the remote side doesn't support mux.
1235 EXPECT_TRUE(SendRtcp1());
1236 EXPECT_TRUE(CheckNoRtp2());
1237 EXPECT_TRUE(CheckRtcp2());
1238
1239 // Send RTCP packet from callee and verify that it is received.
1240 EXPECT_TRUE(SendRtcp2());
1241 EXPECT_TRUE(CheckNoRtp1());
1242 EXPECT_TRUE(CheckRtcp1());
1243
1244 // Complete call setup and ensure everything is still OK.
1245 EXPECT_TRUE(SendAccept());
1246 EXPECT_EQ(2U, GetTransport1()->channels().size());
1247 EXPECT_TRUE(SendRtcp1());
1248 EXPECT_TRUE(CheckRtcp2());
1249 EXPECT_TRUE(SendRtcp2());
1250 EXPECT_TRUE(CheckRtcp1());
1251 }
1252
1253
1254 // Check that RTCP data is not muxed until both sides have enabled muxing,
1255 // but that we properly demux before we get the accept message, since there
1256 // is a race between RTP data and the jingle accept.
1257 void SendEarlyRtcpMuxToRtcpMux() {
1258 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1259 EXPECT_TRUE(SendInitiate());
1260 EXPECT_EQ(2U, GetTransport1()->channels().size());
1261 EXPECT_EQ(1U, GetTransport2()->channels().size());
1262
1263 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1264 // we haven't yet received the accept that says we should mux.
1265 EXPECT_FALSE(SendRtcp1());
1266
1267 // Send muxed RTCP packet from callee and verify that it is received.
1268 EXPECT_TRUE(SendRtcp2());
1269 EXPECT_TRUE(CheckNoRtp1());
1270 EXPECT_TRUE(CheckRtcp1());
1271
1272 // Complete call setup and ensure everything is still OK.
1273 EXPECT_TRUE(SendAccept());
1274 EXPECT_EQ(1U, GetTransport1()->channels().size());
1275 EXPECT_TRUE(SendRtcp1());
1276 EXPECT_TRUE(CheckRtcp2());
1277 EXPECT_TRUE(SendRtcp2());
1278 EXPECT_TRUE(CheckRtcp1());
1279 }
1280
1281 // Test that we properly send SRTP with RTCP in both directions.
1282 // You can pass in DTLS and/or RTCP_MUX as flags.
1283 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1284 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1285 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1286
1287 int flags1 = RTCP | SECURE | flags1_in;
1288 int flags2 = RTCP | SECURE | flags2_in;
1289 bool dtls1 = !!(flags1_in & DTLS);
1290 bool dtls2 = !!(flags2_in & DTLS);
1291 CreateChannels(flags1, flags2);
1292 EXPECT_FALSE(channel1_->secure());
1293 EXPECT_FALSE(channel2_->secure());
1294 EXPECT_TRUE(SendInitiate());
1295 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1296 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1297 EXPECT_TRUE(SendAccept());
1298 EXPECT_TRUE(channel1_->secure());
1299 EXPECT_TRUE(channel2_->secure());
1300 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1301 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1302 EXPECT_TRUE(SendRtp1());
1303 EXPECT_TRUE(SendRtp2());
1304 EXPECT_TRUE(SendRtcp1());
1305 EXPECT_TRUE(SendRtcp2());
1306 EXPECT_TRUE(CheckRtp1());
1307 EXPECT_TRUE(CheckRtp2());
1308 EXPECT_TRUE(CheckNoRtp1());
1309 EXPECT_TRUE(CheckNoRtp2());
1310 EXPECT_TRUE(CheckRtcp1());
1311 EXPECT_TRUE(CheckRtcp2());
1312 EXPECT_TRUE(CheckNoRtcp1());
1313 EXPECT_TRUE(CheckNoRtcp2());
1314 }
1315
1316 // Test that we properly handling SRTP negotiating down to RTP.
1317 void SendSrtpToRtp() {
1318 CreateChannels(RTCP | SECURE, RTCP);
1319 EXPECT_FALSE(channel1_->secure());
1320 EXPECT_FALSE(channel2_->secure());
1321 EXPECT_TRUE(SendInitiate());
1322 EXPECT_TRUE(SendAccept());
1323 EXPECT_FALSE(channel1_->secure());
1324 EXPECT_FALSE(channel2_->secure());
1325 EXPECT_TRUE(SendRtp1());
1326 EXPECT_TRUE(SendRtp2());
1327 EXPECT_TRUE(SendRtcp1());
1328 EXPECT_TRUE(SendRtcp2());
1329 EXPECT_TRUE(CheckRtp1());
1330 EXPECT_TRUE(CheckRtp2());
1331 EXPECT_TRUE(CheckNoRtp1());
1332 EXPECT_TRUE(CheckNoRtp2());
1333 EXPECT_TRUE(CheckRtcp1());
1334 EXPECT_TRUE(CheckRtcp2());
1335 EXPECT_TRUE(CheckNoRtcp1());
1336 EXPECT_TRUE(CheckNoRtcp2());
1337 }
1338
1339 // Test that we can send and receive early media when a provisional answer is
1340 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1341 void SendEarlyMediaUsingRtcpMuxSrtp() {
1342 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1343
1344 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1345 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1346 EXPECT_TRUE(SendOffer());
1347 EXPECT_TRUE(SendProvisionalAnswer());
1348 EXPECT_TRUE(channel1_->secure());
1349 EXPECT_TRUE(channel2_->secure());
1350 EXPECT_EQ(2U, GetTransport1()->channels().size());
1351 EXPECT_EQ(2U, GetTransport2()->channels().size());
1352 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1353 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1354 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1355 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1356
1357 // Send packets from callee and verify that it is received.
1358 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1359 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1360 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1361 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1362
1363 // Complete call setup and ensure everything is still OK.
1364 EXPECT_TRUE(SendFinalAnswer());
1365 EXPECT_EQ(1U, GetTransport1()->channels().size());
1366 EXPECT_EQ(1U, GetTransport2()->channels().size());
1367 EXPECT_TRUE(channel1_->secure());
1368 EXPECT_TRUE(channel2_->secure());
1369 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1370 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1371 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1372 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1373 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1374 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1375 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1376 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1377 }
1378
1379 // Test that we properly send RTP without SRTP from a thread.
1380 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001381 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1382 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 EXPECT_TRUE(SendInitiate());
1384 EXPECT_TRUE(SendAccept());
1385 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1386 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001387 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1388 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1390 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1391 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1392 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1393 EXPECT_TRUE(CheckNoRtp1());
1394 EXPECT_TRUE(CheckNoRtp2());
1395 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1396 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1397 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1398 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1399 EXPECT_TRUE(CheckNoRtcp1());
1400 EXPECT_TRUE(CheckNoRtcp2());
1401 }
1402
1403 // Test that we properly send SRTP with RTCP from a thread.
1404 void SendSrtpToSrtpOnThread() {
1405 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1406 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1407 EXPECT_TRUE(SendInitiate());
1408 EXPECT_TRUE(SendAccept());
1409 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1410 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1411 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1412 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1413 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1414 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1415 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1416 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1417 EXPECT_TRUE(CheckNoRtp1());
1418 EXPECT_TRUE(CheckNoRtp2());
1419 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1420 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1421 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1422 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1423 EXPECT_TRUE(CheckNoRtcp1());
1424 EXPECT_TRUE(CheckNoRtcp2());
1425 }
1426
1427 // Test that the mediachannel retains its sending state after the transport
1428 // becomes non-writable.
1429 void SendWithWritabilityLoss() {
1430 CreateChannels(0, 0);
1431 EXPECT_TRUE(SendInitiate());
1432 EXPECT_TRUE(SendAccept());
1433 EXPECT_EQ(1U, GetTransport1()->channels().size());
1434 EXPECT_EQ(1U, GetTransport2()->channels().size());
1435 EXPECT_TRUE(SendRtp1());
1436 EXPECT_TRUE(SendRtp2());
1437 EXPECT_TRUE(CheckRtp1());
1438 EXPECT_TRUE(CheckRtp2());
1439 EXPECT_TRUE(CheckNoRtp1());
1440 EXPECT_TRUE(CheckNoRtp2());
1441
wu@webrtc.org97077a32013-10-25 21:18:33 +00001442 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 EXPECT_FALSE(SendRtp1());
1445 EXPECT_TRUE(SendRtp2());
1446 EXPECT_TRUE(CheckRtp1());
1447 EXPECT_TRUE(CheckNoRtp2());
1448
1449 // Regain writability
1450 GetTransport1()->SetWritable(true);
1451 EXPECT_TRUE(media_channel1_->sending());
1452 EXPECT_TRUE(SendRtp1());
1453 EXPECT_TRUE(SendRtp2());
1454 EXPECT_TRUE(CheckRtp1());
1455 EXPECT_TRUE(CheckRtp2());
1456 EXPECT_TRUE(CheckNoRtp1());
1457 EXPECT_TRUE(CheckNoRtp2());
1458
1459 // Lose writability completely
1460 GetTransport1()->SetDestination(NULL);
1461 EXPECT_TRUE(media_channel1_->sending());
1462
wu@webrtc.org97077a32013-10-25 21:18:33 +00001463 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 EXPECT_FALSE(SendRtp1());
1465 EXPECT_TRUE(SendRtp2());
1466 EXPECT_TRUE(CheckRtp1());
1467 EXPECT_TRUE(CheckNoRtp2());
1468
1469 // Gain writability back
1470 GetTransport1()->SetDestination(GetTransport2());
1471 EXPECT_TRUE(media_channel1_->sending());
1472 EXPECT_TRUE(SendRtp1());
1473 EXPECT_TRUE(SendRtp2());
1474 EXPECT_TRUE(CheckRtp1());
1475 EXPECT_TRUE(CheckRtp2());
1476 EXPECT_TRUE(CheckNoRtp1());
1477 EXPECT_TRUE(CheckNoRtp2());
1478 }
1479
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001480 void SendBundleToBundle(
1481 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1482 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001484 // Only pl_type1 was added to the bundle filter for both |channel1_|
1485 // and |channel2_|.
1486 int pl_type1 = pl_types[0];
1487 int pl_type2 = pl_types[1];
1488 int flags = SSRC_MUX | RTCP;
1489 if (secure) flags |= SECURE;
1490 uint32 expected_channels = 2U;
1491 if (rtcp_mux) {
1492 flags |= RTCP_MUX;
1493 expected_channels = 1U;
1494 }
1495 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 EXPECT_TRUE(SendInitiate());
1497 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001498 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001500 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1501 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1502 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1503 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1504 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1505 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1506 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1507 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1508 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1509 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1510 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1511 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1512
1513 // Both channels can receive pl_type1 only.
1514 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1515 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1516 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1517 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1518 EXPECT_TRUE(CheckNoRtp1());
1519 EXPECT_TRUE(CheckNoRtp2());
1520
1521 // RTCP test
1522 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1523 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1524 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1525 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1526
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1528 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1530 EXPECT_TRUE(CheckNoRtcp1());
1531 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1532 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001534 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1535 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1538 }
1539
1540 // Test that the media monitor can be run and gives timely callbacks.
1541 void TestMediaMonitor() {
1542 static const int kTimeout = 500;
1543 CreateChannels(0, 0);
1544 EXPECT_TRUE(SendInitiate());
1545 EXPECT_TRUE(SendAccept());
1546 channel1_->StartMediaMonitor(100);
1547 channel2_->StartMediaMonitor(100);
1548 // Ensure we get callbacks and stop.
1549 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1550 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1551 channel1_->StopMediaMonitor();
1552 channel2_->StopMediaMonitor();
1553 // Ensure a restart of a stopped monitor works.
1554 channel1_->StartMediaMonitor(100);
1555 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1556 channel1_->StopMediaMonitor();
1557 // Ensure stopping a stopped monitor is OK.
1558 channel1_->StopMediaMonitor();
1559 }
1560
1561 void TestMediaSinks() {
1562 CreateChannels(0, 0);
1563 EXPECT_TRUE(SendInitiate());
1564 EXPECT_TRUE(SendAccept());
1565 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1566 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1567 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1568 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1569
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001570 rtc::Pathname path;
1571 EXPECT_TRUE(rtc::Filesystem::GetTemporaryFolder(path, true, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 path.SetFilename("sink-test.rtpdump");
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001573 rtc::scoped_ptr<cricket::RtpDumpSink> sink(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 new cricket::RtpDumpSink(Open(path.pathname())));
1575 sink->set_packet_filter(cricket::PF_ALL);
1576 EXPECT_TRUE(sink->Enable(true));
1577 channel1_->RegisterSendSink(
1578 sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
1579 EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1580 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1581 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1582 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1583
1584 // The first packet is recorded with header + data.
1585 EXPECT_TRUE(SendRtp1());
1586 // The second packet is recorded with header only.
1587 sink->set_packet_filter(cricket::PF_RTPHEADER);
1588 EXPECT_TRUE(SendRtp1());
1589 // The third packet is not recorded since sink is disabled.
1590 EXPECT_TRUE(sink->Enable(false));
1591 EXPECT_TRUE(SendRtp1());
1592 // The fourth packet is not recorded since sink is unregistered.
1593 EXPECT_TRUE(sink->Enable(true));
1594 channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
1595 EXPECT_TRUE(SendRtp1());
1596 sink.reset(); // This will close the file.
1597
1598 // Read the recorded file and verify two packets.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001599 rtc::scoped_ptr<rtc::StreamInterface> stream(
1600 rtc::Filesystem::OpenFile(path, "rb"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601
1602 cricket::RtpDumpReader reader(stream.get());
1603 cricket::RtpDumpPacket packet;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001604 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
1606 packet.data.size());
1607 EXPECT_EQ(rtp_packet_, read_packet);
1608
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001609 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 size_t len = 0;
1611 packet.GetRtpHeaderLen(&len);
1612 EXPECT_EQ(len, packet.data.size());
1613 EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
1614
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001615 EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616
1617 // Delete the file for media recording.
1618 stream.reset();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001619 EXPECT_TRUE(rtc::Filesystem::DeleteFile(path));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 }
1621
1622 void TestSetContentFailure() {
1623 CreateChannels(0, 0);
1624 typename T::Content content;
1625 cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1626 cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1627
1628 // Set up the session description.
1629 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1630 sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1631 new cricket::AudioContentDescription());
1632 sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1633 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001634 session1_.set_local_description(sdesc_loc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1636 new cricket::AudioContentDescription());
1637 sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1638 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001639 session1_.set_remote_description(sdesc_rem);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640
1641 // Test failures in SetLocalContent.
1642 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001643 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001644 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1646 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001647 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001648 session1_.SetState(cricket::BaseSession::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1650
1651 // Test failures in SetRemoteContent.
1652 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001653 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001654 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1656 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001657 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001658 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1660 }
1661
1662 void TestSendTwoOffers() {
1663 CreateChannels(0, 0);
1664
1665 // Set up the initial session description.
1666 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001667 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001669 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001670 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1672 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1673
1674 // Update the local description and set the state again.
1675 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001676 session1_.set_local_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_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1680 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1681 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1682 }
1683
1684 void TestReceiveTwoOffers() {
1685 CreateChannels(0, 0);
1686
1687 // Set up the initial session description.
1688 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001689 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001691 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001692 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001693 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1694 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1695
1696 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001697 session1_.set_remote_description(sdesc);
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001698 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1700 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1701 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1702 }
1703
1704 void TestSendPrAnswer() {
1705 CreateChannels(0, 0);
1706
1707 // Set up the initial session description.
1708 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001709 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001711 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001712 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1714 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1715
1716 // Send PRANSWER
1717 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001718 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001720 session1_.SetState(cricket::BaseSession::STATE_SENTPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001721 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1722 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1723 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1724
1725 // Send ACCEPT
1726 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001727 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001729 session1_.SetState(cricket::BaseSession::STATE_SENTACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001730 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1731 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1732 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1733 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1734 }
1735
1736 void TestReceivePrAnswer() {
1737 CreateChannels(0, 0);
1738
1739 // Set up the initial session description.
1740 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001741 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001743 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001744 session1_.SetState(cricket::BaseSession::STATE_SENTINITIATE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1746 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1747
1748 // Receive PRANSWER
1749 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001750 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001752 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDPRACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1754 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1755 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1756
1757 // Receive ACCEPT
1758 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001759 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760
pthatcher@webrtc.orgaacc2342014-12-18 20:31:29 +00001761 session1_.SetState(cricket::BaseSession::STATE_RECEIVEDACCEPT);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1763 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1764 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1765 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1766 }
1767
1768 void TestFlushRtcp() {
1769 bool send_rtcp1;
1770
1771 CreateChannels(RTCP, RTCP);
1772 EXPECT_TRUE(SendInitiate());
1773 EXPECT_TRUE(SendAccept());
1774 EXPECT_EQ(2U, GetTransport1()->channels().size());
1775 EXPECT_EQ(2U, GetTransport2()->channels().size());
1776
1777 // Send RTCP1 from a different thread.
1778 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1779 EXPECT_TRUE(send_rtcp1);
1780 // The sending message is only posted. channel2_ should be empty.
1781 EXPECT_TRUE(CheckNoRtcp2());
1782
1783 // When channel1_ is deleted, the RTCP packet should be sent out to
1784 // channel2_.
1785 channel1_.reset();
1786 EXPECT_TRUE(CheckRtcp2());
1787 }
1788
1789 void TestChangeStateError() {
1790 CreateChannels(RTCP, RTCP);
1791 EXPECT_TRUE(SendInitiate());
1792 media_channel2_->set_fail_set_send(true);
1793 EXPECT_TRUE(channel2_->Enable(true));
1794 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1795 error_);
1796 }
1797
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001798 void TestSrtpError(int pl_type) {
1799 // For Audio, only pl_type 0 is added to the bundle filter.
1800 // For Video, only pl_type 97 is added to the bundle filter.
1801 // So we need to pass in pl_type so that the packet can pass through
1802 // the bundle filter before it can be processed by the srtp filter.
1803 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001804 unsigned const char kBadPacket[] = {0x84,
1805 static_cast<unsigned char>(pl_type),
1806 0x00,
1807 0x01,
1808 0x00,
1809 0x00,
1810 0x00,
1811 0x00,
1812 0x00,
1813 0x00,
1814 0x00,
1815 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1817 EXPECT_FALSE(channel1_->secure());
1818 EXPECT_FALSE(channel2_->secure());
1819 EXPECT_TRUE(SendInitiate());
1820 EXPECT_TRUE(SendAccept());
1821 EXPECT_TRUE(channel1_->secure());
1822 EXPECT_TRUE(channel2_->secure());
1823 channel2_->set_srtp_signal_silent_time(200);
1824
1825 // Testing failures in sending packets.
1826 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1827 // The first failure will trigger an error.
1828 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1829 error_ = T::MediaChannel::ERROR_NONE;
1830 // The next 1 sec failures will not trigger an error.
1831 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1832 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001833 rtc::Thread::Current()->ProcessMessages(210);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1835 // The error will be triggered again.
1836 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1837 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1838
1839 // Testing failures in receiving packets.
1840 error_ = T::MediaChannel::ERROR_NONE;
1841 cricket::TransportChannel* transport_channel =
1842 channel2_->transport_channel();
1843 transport_channel->SignalReadPacket(
1844 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001845 sizeof(kBadPacket), rtc::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001846 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 }
1848
1849 void TestOnReadyToSend() {
1850 CreateChannels(RTCP, RTCP);
1851 TransportChannel* rtp = channel1_->transport_channel();
1852 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1853 EXPECT_FALSE(media_channel1_->ready_to_send());
1854 rtp->SignalReadyToSend(rtp);
1855 EXPECT_FALSE(media_channel1_->ready_to_send());
1856 rtcp->SignalReadyToSend(rtcp);
1857 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1858 // channel are ready to send.
1859 EXPECT_TRUE(media_channel1_->ready_to_send());
1860
1861 // rtp channel becomes not ready to send will be propagated to mediachannel
1862 channel1_->SetReadyToSend(rtp, false);
1863 EXPECT_FALSE(media_channel1_->ready_to_send());
1864 channel1_->SetReadyToSend(rtp, true);
1865 EXPECT_TRUE(media_channel1_->ready_to_send());
1866
1867 // rtcp channel becomes not ready to send will be propagated to mediachannel
1868 channel1_->SetReadyToSend(rtcp, false);
1869 EXPECT_FALSE(media_channel1_->ready_to_send());
1870 channel1_->SetReadyToSend(rtcp, true);
1871 EXPECT_TRUE(media_channel1_->ready_to_send());
1872 }
1873
1874 void TestOnReadyToSendWithRtcpMux() {
1875 CreateChannels(RTCP, RTCP);
1876 typename T::Content content;
1877 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1878 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1879 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001880 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1881 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1883 TransportChannel* rtp = channel1_->transport_channel();
1884 EXPECT_FALSE(media_channel1_->ready_to_send());
1885 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1886 // should trigger the MediaChannel's OnReadyToSend.
1887 rtp->SignalReadyToSend(rtp);
1888 EXPECT_TRUE(media_channel1_->ready_to_send());
1889 channel1_->SetReadyToSend(rtp, false);
1890 EXPECT_FALSE(media_channel1_->ready_to_send());
1891 }
1892
1893 protected:
1894 cricket::FakeSession session1_;
1895 cricket::FakeSession session2_;
1896 cricket::FakeMediaEngine media_engine_;
1897 // The media channels are owned by the voice channel objects below.
1898 typename T::MediaChannel* media_channel1_;
1899 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001900 rtc::scoped_ptr<typename T::Channel> channel1_;
1901 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 typename T::Content local_media_content1_;
1903 typename T::Content local_media_content2_;
1904 typename T::Content remote_media_content1_;
1905 typename T::Content remote_media_content2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001906 rtc::scoped_ptr<rtc::SSLIdentity> identity1_;
1907 rtc::scoped_ptr<rtc::SSLIdentity> identity2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 // The RTP and RTCP packets to send in the tests.
1909 std::string rtp_packet_;
1910 std::string rtcp_packet_;
1911 int media_info_callbacks1_;
1912 int media_info_callbacks2_;
1913 bool mute_callback_recved_;
1914 bool mute_callback_value_;
1915
1916 uint32 ssrc_;
1917 typename T::MediaChannel::Error error_;
1918};
1919
1920
1921template<>
1922void ChannelTest<VoiceTraits>::CreateContent(
1923 int flags,
1924 const cricket::AudioCodec& audio_codec,
1925 const cricket::VideoCodec& video_codec,
1926 cricket::AudioContentDescription* audio) {
1927 audio->AddCodec(audio_codec);
1928 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1929 if (flags & SECURE) {
1930 audio->AddCrypto(cricket::CryptoParams(
1931 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001932 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933 }
1934}
1935
1936template<>
1937void ChannelTest<VoiceTraits>::CopyContent(
1938 const cricket::AudioContentDescription& source,
1939 cricket::AudioContentDescription* audio) {
1940 *audio = source;
1941}
1942
1943template<>
1944bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1945 const cricket::AudioCodec& c2) {
1946 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1947 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1948}
1949
1950template<>
1951void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1952 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1953 audio->AddLegacyStream(ssrc);
1954}
1955
1956class VoiceChannelTest
1957 : public ChannelTest<VoiceTraits> {
1958 public:
1959 typedef ChannelTest<VoiceTraits>
1960 Base;
1961 VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1962 kRtcpReport, sizeof(kRtcpReport)) {
1963 }
1964
1965 void TestSetChannelOptions() {
1966 CreateChannels(0, 0);
1967
1968 cricket::AudioOptions options1;
1969 options1.echo_cancellation.Set(false);
1970 cricket::AudioOptions options2;
1971 options2.echo_cancellation.Set(true);
1972
1973 channel1_->SetChannelOptions(options1);
1974 channel2_->SetChannelOptions(options1);
1975 cricket::AudioOptions actual_options;
1976 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1977 EXPECT_EQ(options1, actual_options);
1978 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1979 EXPECT_EQ(options1, actual_options);
1980
1981 channel1_->SetChannelOptions(options2);
1982 channel2_->SetChannelOptions(options2);
1983 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1984 EXPECT_EQ(options2, actual_options);
1985 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1986 EXPECT_EQ(options2, actual_options);
1987 }
1988};
1989
1990// override to add NULL parameter
1991template<>
1992cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001993 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1995 bool rtcp) {
1996 cricket::VideoChannel* channel = new cricket::VideoChannel(
Fredrik Solenberg7fb711f2015-04-22 15:30:51 +02001997 thread, engine, ch, session, cricket::CN_VIDEO, rtcp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 if (!channel->Init()) {
1999 delete channel;
2000 channel = NULL;
2001 }
2002 return channel;
2003}
2004
2005// override to add 0 parameter
2006template<>
2007bool ChannelTest<VideoTraits>::AddStream1(int id) {
2008 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
2009}
2010
2011template<>
2012void ChannelTest<VideoTraits>::CreateContent(
2013 int flags,
2014 const cricket::AudioCodec& audio_codec,
2015 const cricket::VideoCodec& video_codec,
2016 cricket::VideoContentDescription* video) {
2017 video->AddCodec(video_codec);
2018 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
2019 if (flags & SECURE) {
2020 video->AddCrypto(cricket::CryptoParams(
2021 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002022 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 }
2024}
2025
2026template<>
2027void ChannelTest<VideoTraits>::CopyContent(
2028 const cricket::VideoContentDescription& source,
2029 cricket::VideoContentDescription* video) {
2030 *video = source;
2031}
2032
2033template<>
2034bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2035 const cricket::VideoCodec& c2) {
2036 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2037 c1.framerate == c2.framerate;
2038}
2039
2040template<>
2041void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
2042 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
2043 video->AddLegacyStream(ssrc);
2044}
2045
2046class VideoChannelTest
2047 : public ChannelTest<VideoTraits> {
2048 public:
2049 typedef ChannelTest<VideoTraits>
2050 Base;
2051 VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
2052 kRtcpReport, sizeof(kRtcpReport)) {
2053 }
2054
2055 void TestSetChannelOptions() {
2056 CreateChannels(0, 0);
2057
2058 cricket::VideoOptions o1, o2;
2059 o1.video_noise_reduction.Set(true);
2060
2061 channel1_->SetChannelOptions(o1);
2062 channel2_->SetChannelOptions(o1);
2063 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2064 EXPECT_EQ(o1, o2);
2065 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2066 EXPECT_EQ(o1, o2);
2067
buildbot@webrtc.org81ddc782014-10-14 22:39:24 +00002068 o1.video_start_bitrate.Set(123);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 channel1_->SetChannelOptions(o1);
2070 channel2_->SetChannelOptions(o1);
2071 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2072 EXPECT_EQ(o1, o2);
2073 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2074 EXPECT_EQ(o1, o2);
2075 }
2076};
2077
2078
2079// VoiceChannelTest
2080
2081TEST_F(VoiceChannelTest, TestInit) {
2082 Base::TestInit();
2083 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2084 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2085}
2086
2087TEST_F(VoiceChannelTest, TestSetContents) {
2088 Base::TestSetContents();
2089}
2090
2091TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2092 Base::TestSetContentsNullOffer();
2093}
2094
2095TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2096 Base::TestSetContentsRtcpMux();
2097}
2098
2099TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2100 Base::TestSetContentsRtcpMux();
2101}
2102
2103TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2104 Base::TestSetRemoteContentUpdate();
2105}
2106
2107TEST_F(VoiceChannelTest, TestStreams) {
2108 Base::TestStreams();
2109}
2110
2111TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2112 Base::TestUpdateStreamsInLocalContent();
2113}
2114
2115TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2116 Base::TestUpdateStreamsInRemoteContent();
2117}
2118
2119TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2120 Base::TestChangeStreamParamsInContent();
2121}
2122
2123TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2124 Base::TestPlayoutAndSendingStates();
2125}
2126
2127TEST_F(VoiceChannelTest, TestMuteStream) {
2128 Base::TestMuteStream();
2129}
2130
2131TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2132 Base::TestMediaContentDirection();
2133}
2134
2135TEST_F(VoiceChannelTest, TestCallSetup) {
2136 Base::TestCallSetup();
2137}
2138
2139TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2140 Base::TestCallTeardownRtcpMux();
2141}
2142
2143TEST_F(VoiceChannelTest, SendRtpToRtp) {
2144 Base::SendRtpToRtp();
2145}
2146
2147TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2148 Base::SendNoRtcpToNoRtcp();
2149}
2150
2151TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2152 Base::SendNoRtcpToRtcp();
2153}
2154
2155TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2156 Base::SendRtcpToNoRtcp();
2157}
2158
2159TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2160 Base::SendRtcpToRtcp();
2161}
2162
2163TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2164 Base::SendRtcpMuxToRtcp();
2165}
2166
2167TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2168 Base::SendRtcpMuxToRtcpMux();
2169}
2170
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002171TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
2172 Base::SendRequireRtcpMuxToRtcpMux();
2173}
2174
2175TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
2176 Base::SendRtcpMuxToRequireRtcpMux();
2177}
2178
2179TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2180 Base::SendRequireRtcpMuxToRequireRtcpMux();
2181}
2182
2183TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2184 Base::SendRequireRtcpMuxToNoRtcpMux();
2185}
2186
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2188 Base::SendEarlyRtcpMuxToRtcp();
2189}
2190
2191TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2192 Base::SendEarlyRtcpMuxToRtcpMux();
2193}
2194
2195TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2196 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2197}
2198
2199TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2200 Base::SendSrtpToSrtp();
2201}
2202
2203TEST_F(VoiceChannelTest, SendSrtcpMux) {
2204 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2205}
2206
2207TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2208 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2209 Base::SendSrtpToSrtp(DTLS, 0);
2210}
2211
2212TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2213 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2214 Base::SendSrtpToSrtp(DTLS, DTLS);
2215}
2216
2217TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2218 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2219 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2220}
2221
2222TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2223 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2224}
2225
2226TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2227 Base::SendRtpToRtpOnThread();
2228}
2229
2230TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2231 Base::SendSrtpToSrtpOnThread();
2232}
2233
2234TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2235 Base::SendWithWritabilityLoss();
2236}
2237
2238TEST_F(VoiceChannelTest, TestMediaMonitor) {
2239 Base::TestMediaMonitor();
2240}
2241
2242// Test that MuteStream properly forwards to the media channel and does
2243// not signal.
2244TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
2245 CreateChannels(0, 0);
2246 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2247 EXPECT_FALSE(mute_callback_recved_);
2248 EXPECT_TRUE(channel1_->MuteStream(0, true));
2249 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2250 EXPECT_FALSE(mute_callback_recved_);
2251 EXPECT_TRUE(channel1_->MuteStream(0, false));
2252 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2253 EXPECT_FALSE(mute_callback_recved_);
2254}
2255
2256// Test that keyboard automute works correctly and signals upwards.
asapersson@webrtc.orgb533a822013-09-23 19:47:49 +00002257TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 CreateChannels(0, 0);
2259 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2260 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
2261
2262 cricket::VoiceMediaChannel::Error e =
2263 cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
2264
2265 // Typing doesn't mute automatically unless typing monitor has been installed
2266 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002267 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 EXPECT_EQ(e, error_);
2269 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2270 EXPECT_FALSE(mute_callback_recved_);
2271
2272 cricket::TypingMonitorOptions o = {0};
2273 o.mute_period = 1500;
2274 channel1_->StartTypingMonitor(o);
2275 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002276 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002277 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2278 EXPECT_TRUE(mute_callback_recved_);
2279}
2280
2281// Test that PressDTMF properly forwards to the media channel.
2282TEST_F(VoiceChannelTest, TestDtmf) {
2283 CreateChannels(0, 0);
2284 EXPECT_TRUE(SendInitiate());
2285 EXPECT_TRUE(SendAccept());
2286 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2287
2288 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2289 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2290
2291 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2292 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2293 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2294 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2295 0, 8, 160, cricket::DF_SEND));
2296}
2297
2298// Test that InsertDtmf properly forwards to the media channel.
2299TEST_F(VoiceChannelTest, TestInsertDtmf) {
2300 CreateChannels(0, 0);
2301 EXPECT_TRUE(SendInitiate());
2302 EXPECT_TRUE(SendAccept());
2303 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2304
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2306 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2307 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2308 cricket::DF_PLAY | cricket::DF_SEND));
2309
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002310 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002311 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002313 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002314 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002315 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2317}
2318
2319TEST_F(VoiceChannelTest, TestMediaSinks) {
2320 Base::TestMediaSinks();
2321}
2322
2323TEST_F(VoiceChannelTest, TestSetContentFailure) {
2324 Base::TestSetContentFailure();
2325}
2326
2327TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2328 Base::TestSendTwoOffers();
2329}
2330
2331TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2332 Base::TestReceiveTwoOffers();
2333}
2334
2335TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2336 Base::TestSendPrAnswer();
2337}
2338
2339TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2340 Base::TestReceivePrAnswer();
2341}
2342
2343TEST_F(VoiceChannelTest, TestFlushRtcp) {
2344 Base::TestFlushRtcp();
2345}
2346
2347TEST_F(VoiceChannelTest, TestChangeStateError) {
2348 Base::TestChangeStateError();
2349}
2350
2351TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002352 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353}
2354
2355TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2356 Base::TestOnReadyToSend();
2357}
2358
2359TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2360 Base::TestOnReadyToSendWithRtcpMux();
2361}
2362
2363// Test that we can play a ringback tone properly.
2364TEST_F(VoiceChannelTest, TestRingbackTone) {
2365 CreateChannels(RTCP, RTCP);
2366 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2367 EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
2368 EXPECT_TRUE(SendInitiate());
2369 EXPECT_TRUE(SendAccept());
2370 // Play ringback tone, no loop.
2371 EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
2372 EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
2373 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2374 EXPECT_FALSE(media_channel1_->ringback_tone_loop());
2375 // Stop the ringback tone.
2376 EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
2377 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2378 // Add a stream.
2379 EXPECT_TRUE(AddStream1(1));
2380 // Play ringback tone, looping, on the new stream.
2381 EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
2382 EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
2383 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2384 EXPECT_TRUE(media_channel1_->ringback_tone_loop());
2385 // Stop the ringback tone.
2386 EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
2387 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2388}
2389
2390// Test that we can scale the output volume properly for 1:1 calls.
2391TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2392 CreateChannels(RTCP, RTCP);
2393 EXPECT_TRUE(SendInitiate());
2394 EXPECT_TRUE(SendAccept());
2395 double left, right;
2396
2397 // Default is (1.0, 1.0).
2398 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2399 EXPECT_DOUBLE_EQ(1.0, left);
2400 EXPECT_DOUBLE_EQ(1.0, right);
2401 // invalid ssrc.
2402 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2403
2404 // Set scale to (1.5, 0.5).
2405 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2406 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2407 EXPECT_DOUBLE_EQ(1.5, left);
2408 EXPECT_DOUBLE_EQ(0.5, right);
2409
2410 // Set scale to (0, 0).
2411 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2412 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2413 EXPECT_DOUBLE_EQ(0.0, left);
2414 EXPECT_DOUBLE_EQ(0.0, right);
2415}
2416
2417// Test that we can scale the output volume properly for multiway calls.
2418TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2419 CreateChannels(RTCP, RTCP);
2420 EXPECT_TRUE(SendInitiate());
2421 EXPECT_TRUE(SendAccept());
2422 EXPECT_TRUE(AddStream1(1));
2423 EXPECT_TRUE(AddStream1(2));
2424
2425 double left, right;
2426 // Default is (1.0, 1.0).
2427 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2428 EXPECT_DOUBLE_EQ(1.0, left);
2429 EXPECT_DOUBLE_EQ(1.0, right);
2430 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2431 EXPECT_DOUBLE_EQ(1.0, left);
2432 EXPECT_DOUBLE_EQ(1.0, right);
2433 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2434 EXPECT_DOUBLE_EQ(1.0, left);
2435 EXPECT_DOUBLE_EQ(1.0, right);
2436 // invalid ssrc.
2437 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2438
2439 // Set scale to (1.5, 0.5) for ssrc = 1.
2440 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2441 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2442 EXPECT_DOUBLE_EQ(1.5, left);
2443 EXPECT_DOUBLE_EQ(0.5, right);
2444 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2445 EXPECT_DOUBLE_EQ(1.0, left);
2446 EXPECT_DOUBLE_EQ(1.0, right);
2447 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2448 EXPECT_DOUBLE_EQ(1.0, left);
2449 EXPECT_DOUBLE_EQ(1.0, right);
2450
2451 // Set scale to (0, 0) for all ssrcs.
2452 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2453 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2454 EXPECT_DOUBLE_EQ(0.0, left);
2455 EXPECT_DOUBLE_EQ(0.0, right);
2456 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2457 EXPECT_DOUBLE_EQ(0.0, left);
2458 EXPECT_DOUBLE_EQ(0.0, right);
2459 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2460 EXPECT_DOUBLE_EQ(0.0, left);
2461 EXPECT_DOUBLE_EQ(0.0, right);
2462}
2463
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002464TEST_F(VoiceChannelTest, SendBundleToBundle) {
2465 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466}
2467
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002468TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2469 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2470}
2471
2472TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2473 Base::SendBundleToBundle(
2474 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2475}
2476
2477TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2478 Base::SendBundleToBundle(
2479 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480}
2481
2482TEST_F(VoiceChannelTest, TestSetChannelOptions) {
2483 TestSetChannelOptions();
2484}
2485
2486// VideoChannelTest
2487TEST_F(VideoChannelTest, TestInit) {
2488 Base::TestInit();
2489}
2490
2491TEST_F(VideoChannelTest, TestSetContents) {
2492 Base::TestSetContents();
2493}
2494
2495TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2496 Base::TestSetContentsNullOffer();
2497}
2498
2499TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2500 Base::TestSetContentsRtcpMux();
2501}
2502
2503TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2504 Base::TestSetContentsRtcpMux();
2505}
2506
2507TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
2508 Base::TestSetContentsVideoOptions();
2509}
2510
2511TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2512 Base::TestSetRemoteContentUpdate();
2513}
2514
2515TEST_F(VideoChannelTest, TestStreams) {
2516 Base::TestStreams();
2517}
2518
2519TEST_F(VideoChannelTest, TestScreencastEvents) {
2520 const int kTimeoutMs = 500;
2521 TestInit();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522 cricket::ScreencastEventCatcher catcher;
2523 channel1_->SignalScreencastWindowEvent.connect(
2524 &catcher,
2525 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002526
2527 rtc::scoped_ptr<cricket::FakeScreenCapturerFactory>
2528 screen_capturer_factory(new cricket::FakeScreenCapturerFactory());
2529 cricket::VideoCapturer* screen_capturer = screen_capturer_factory->Create(
2530 ScreencastId(WindowId(0)));
2531 ASSERT_TRUE(screen_capturer != NULL);
2532
2533 EXPECT_TRUE(channel1_->AddScreencast(0, screen_capturer));
2534 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screen_capturer_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002535 kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002536
2537 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002538 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002539
2540 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002541 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002542
2543 screen_capturer->SignalStateChange(screen_capturer, cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002544 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org65b98d12014-08-07 22:09:08 +00002545
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 EXPECT_TRUE(channel1_->RemoveScreencast(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547}
2548
2549TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2550 Base::TestUpdateStreamsInLocalContent();
2551}
2552
2553TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2554 Base::TestUpdateStreamsInRemoteContent();
2555}
2556
2557TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2558 Base::TestChangeStreamParamsInContent();
2559}
2560
2561TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2562 Base::TestPlayoutAndSendingStates();
2563}
2564
2565TEST_F(VideoChannelTest, TestMuteStream) {
2566 Base::TestMuteStream();
2567}
2568
2569TEST_F(VideoChannelTest, TestMediaContentDirection) {
2570 Base::TestMediaContentDirection();
2571}
2572
2573TEST_F(VideoChannelTest, TestCallSetup) {
2574 Base::TestCallSetup();
2575}
2576
2577TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2578 Base::TestCallTeardownRtcpMux();
2579}
2580
2581TEST_F(VideoChannelTest, SendRtpToRtp) {
2582 Base::SendRtpToRtp();
2583}
2584
2585TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2586 Base::SendNoRtcpToNoRtcp();
2587}
2588
2589TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2590 Base::SendNoRtcpToRtcp();
2591}
2592
2593TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2594 Base::SendRtcpToNoRtcp();
2595}
2596
2597TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2598 Base::SendRtcpToRtcp();
2599}
2600
2601TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2602 Base::SendRtcpMuxToRtcp();
2603}
2604
2605TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2606 Base::SendRtcpMuxToRtcpMux();
2607}
2608
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002609TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
2610 Base::SendRequireRtcpMuxToRtcpMux();
2611}
2612
2613TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
2614 Base::SendRtcpMuxToRequireRtcpMux();
2615}
2616
2617TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
2618 Base::SendRequireRtcpMuxToRequireRtcpMux();
2619}
2620
2621TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
2622 Base::SendRequireRtcpMuxToNoRtcpMux();
2623}
2624
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2626 Base::SendEarlyRtcpMuxToRtcp();
2627}
2628
2629TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2630 Base::SendEarlyRtcpMuxToRtcpMux();
2631}
2632
2633TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2634 Base::SendSrtpToSrtp();
2635}
2636
2637TEST_F(VideoChannelTest, SendSrtpToRtp) {
2638 Base::SendSrtpToSrtp();
2639}
2640
2641TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2642 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2643 Base::SendSrtpToSrtp(DTLS, 0);
2644}
2645
2646TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2647 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2648 Base::SendSrtpToSrtp(DTLS, DTLS);
2649}
2650
2651TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2652 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2653 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2654}
2655
2656TEST_F(VideoChannelTest, SendSrtcpMux) {
2657 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2658}
2659
2660TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2661 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2662}
2663
2664TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2665 Base::SendRtpToRtpOnThread();
2666}
2667
2668TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2669 Base::SendSrtpToSrtpOnThread();
2670}
2671
2672TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2673 Base::SendWithWritabilityLoss();
2674}
2675
2676TEST_F(VideoChannelTest, TestMediaMonitor) {
2677 Base::TestMediaMonitor();
2678}
2679
2680TEST_F(VideoChannelTest, TestMediaSinks) {
2681 Base::TestMediaSinks();
2682}
2683
2684TEST_F(VideoChannelTest, TestSetContentFailure) {
2685 Base::TestSetContentFailure();
2686}
2687
2688TEST_F(VideoChannelTest, TestSendTwoOffers) {
2689 Base::TestSendTwoOffers();
2690}
2691
2692TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2693 Base::TestReceiveTwoOffers();
2694}
2695
2696TEST_F(VideoChannelTest, TestSendPrAnswer) {
2697 Base::TestSendPrAnswer();
2698}
2699
2700TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2701 Base::TestReceivePrAnswer();
2702}
2703
2704TEST_F(VideoChannelTest, TestFlushRtcp) {
2705 Base::TestFlushRtcp();
2706}
2707
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002708TEST_F(VideoChannelTest, SendBundleToBundle) {
2709 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710}
2711
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002712TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2713 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2714}
2715
2716TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2717 Base::SendBundleToBundle(
2718 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2719}
2720
2721TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2722 Base::SendBundleToBundle(
2723 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002724}
2725
2726// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2727
2728TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002729 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730}
2731
2732TEST_F(VideoChannelTest, TestOnReadyToSend) {
2733 Base::TestOnReadyToSend();
2734}
2735
2736TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2737 Base::TestOnReadyToSendWithRtcpMux();
2738}
2739
2740TEST_F(VideoChannelTest, TestApplyViewRequest) {
2741 CreateChannels(0, 0);
2742 cricket::StreamParams stream2;
2743 stream2.id = "stream2";
2744 stream2.ssrcs.push_back(2222);
2745 local_media_content1_.AddStream(stream2);
2746
2747 EXPECT_TRUE(SendInitiate());
2748 EXPECT_TRUE(SendAccept());
2749
2750 cricket::VideoFormat send_format;
2751 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2752 EXPECT_EQ(640, send_format.width);
2753 EXPECT_EQ(400, send_format.height);
2754 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2755
2756 cricket::ViewRequest request;
2757 // stream1: 320x200x15; stream2: 0x0x0
2758 request.static_video_views.push_back(cricket::StaticVideoView(
2759 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2760 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2761 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2762 EXPECT_EQ(320, send_format.width);
2763 EXPECT_EQ(200, send_format.height);
2764 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2765 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2766 EXPECT_EQ(0, send_format.width);
2767 EXPECT_EQ(0, send_format.height);
2768
2769 // stream1: 160x100x8; stream2: 0x0x0
2770 request.static_video_views.clear();
2771 request.static_video_views.push_back(cricket::StaticVideoView(
2772 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2773 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2774 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2775 EXPECT_EQ(160, send_format.width);
2776 EXPECT_EQ(100, send_format.height);
2777 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2778
2779 // stream1: 0x0x0; stream2: 640x400x30
2780 request.static_video_views.clear();
2781 request.static_video_views.push_back(cricket::StaticVideoView(
2782 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2783 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2784 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2785 EXPECT_EQ(0, send_format.width);
2786 EXPECT_EQ(0, send_format.height);
2787 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2788 EXPECT_EQ(640, send_format.width);
2789 EXPECT_EQ(400, send_format.height);
2790 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2791
2792 // stream1: 0x0x0; stream2: 0x0x0
2793 request.static_video_views.clear();
2794 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2795 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2796 EXPECT_EQ(0, send_format.width);
2797 EXPECT_EQ(0, send_format.height);
2798}
2799
2800TEST_F(VideoChannelTest, TestSetChannelOptions) {
2801 TestSetChannelOptions();
2802}
2803
2804
2805// DataChannelTest
2806
2807class DataChannelTest
2808 : public ChannelTest<DataTraits> {
2809 public:
2810 typedef ChannelTest<DataTraits>
2811 Base;
2812 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2813 kRtcpReport, sizeof(kRtcpReport)) {
2814 }
2815};
2816
2817// Override to avoid engine channel parameter.
2818template<>
2819cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002820 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2822 bool rtcp) {
2823 cricket::DataChannel* channel = new cricket::DataChannel(
2824 thread, ch, session, cricket::CN_DATA, rtcp);
2825 if (!channel->Init()) {
2826 delete channel;
2827 channel = NULL;
2828 }
2829 return channel;
2830}
2831
2832template<>
2833void ChannelTest<DataTraits>::CreateContent(
2834 int flags,
2835 const cricket::AudioCodec& audio_codec,
2836 const cricket::VideoCodec& video_codec,
2837 cricket::DataContentDescription* data) {
2838 data->AddCodec(kGoogleDataCodec);
2839 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2840 if (flags & SECURE) {
2841 data->AddCrypto(cricket::CryptoParams(
2842 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002843 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002844 }
2845}
2846
2847template<>
2848void ChannelTest<DataTraits>::CopyContent(
2849 const cricket::DataContentDescription& source,
2850 cricket::DataContentDescription* data) {
2851 *data = source;
2852}
2853
2854template<>
2855bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2856 const cricket::DataCodec& c2) {
2857 return c1.name == c2.name;
2858}
2859
2860template<>
2861void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2862 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2863 data->AddLegacyStream(ssrc);
2864}
2865
2866TEST_F(DataChannelTest, TestInit) {
2867 Base::TestInit();
2868 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2869}
2870
2871TEST_F(DataChannelTest, TestSetContents) {
2872 Base::TestSetContents();
2873}
2874
2875TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2876 Base::TestSetContentsNullOffer();
2877}
2878
2879TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2880 Base::TestSetContentsRtcpMux();
2881}
2882
2883TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2884 Base::TestSetRemoteContentUpdate();
2885}
2886
2887TEST_F(DataChannelTest, TestStreams) {
2888 Base::TestStreams();
2889}
2890
2891TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2892 Base::TestUpdateStreamsInLocalContent();
2893}
2894
2895TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2896 Base::TestUpdateStreamsInRemoteContent();
2897}
2898
2899TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2900 Base::TestChangeStreamParamsInContent();
2901}
2902
2903TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2904 Base::TestPlayoutAndSendingStates();
2905}
2906
2907TEST_F(DataChannelTest, TestMediaContentDirection) {
2908 Base::TestMediaContentDirection();
2909}
2910
2911TEST_F(DataChannelTest, TestCallSetup) {
2912 Base::TestCallSetup();
2913}
2914
2915TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2916 Base::TestCallTeardownRtcpMux();
2917}
2918
2919TEST_F(DataChannelTest, TestOnReadyToSend) {
2920 Base::TestOnReadyToSend();
2921}
2922
2923TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2924 Base::TestOnReadyToSendWithRtcpMux();
2925}
2926
2927TEST_F(DataChannelTest, SendRtpToRtp) {
2928 Base::SendRtpToRtp();
2929}
2930
2931TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2932 Base::SendNoRtcpToNoRtcp();
2933}
2934
2935TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2936 Base::SendNoRtcpToRtcp();
2937}
2938
2939TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2940 Base::SendRtcpToNoRtcp();
2941}
2942
2943TEST_F(DataChannelTest, SendRtcpToRtcp) {
2944 Base::SendRtcpToRtcp();
2945}
2946
2947TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2948 Base::SendRtcpMuxToRtcp();
2949}
2950
2951TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2952 Base::SendRtcpMuxToRtcpMux();
2953}
2954
2955TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2956 Base::SendEarlyRtcpMuxToRtcp();
2957}
2958
2959TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2960 Base::SendEarlyRtcpMuxToRtcpMux();
2961}
2962
2963TEST_F(DataChannelTest, SendSrtpToSrtp) {
2964 Base::SendSrtpToSrtp();
2965}
2966
2967TEST_F(DataChannelTest, SendSrtpToRtp) {
2968 Base::SendSrtpToSrtp();
2969}
2970
2971TEST_F(DataChannelTest, SendSrtcpMux) {
2972 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2973}
2974
2975TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2976 Base::SendRtpToRtpOnThread();
2977}
2978
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2980 Base::SendSrtpToSrtpOnThread();
2981}
2982
2983TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2984 Base::SendWithWritabilityLoss();
2985}
2986
2987TEST_F(DataChannelTest, TestMediaMonitor) {
2988 Base::TestMediaMonitor();
2989}
2990
2991TEST_F(DataChannelTest, TestSendData) {
2992 CreateChannels(0, 0);
2993 EXPECT_TRUE(SendInitiate());
2994 EXPECT_TRUE(SendAccept());
2995
2996 cricket::SendDataParams params;
2997 params.ssrc = 42;
2998 unsigned char data[] = {
2999 'f', 'o', 'o'
3000 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003001 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002 cricket::SendDataResult result;
3003 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
3004 EXPECT_EQ(params.ssrc,
3005 media_channel1_->last_sent_data_params().ssrc);
3006 EXPECT_EQ("foo", media_channel1_->last_sent_data());
3007}
3008
3009// TODO(pthatcher): TestSetReceiver?