blob: cf0aad8dd9d7e28a01f422bfb21b60b807f1e74d [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001// libjingle
2// Copyright 2009 Google Inc.
3//
4// Redistribution and use in source and binary forms, with or without
5// modification, are permitted provided that the following conditions are met:
6//
7// 1. Redistributions of source code must retain the above copyright notice,
8// this list of conditions and the following disclaimer.
9// 2. Redistributions in binary form must reproduce the above copyright notice,
10// this list of conditions and the following disclaimer in the documentation
11// and/or other materials provided with the distribution.
12// 3. The name of the author may not be used to endorse or promote products
13// derived from this software without specific prior written permission.
14//
15// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
16// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
17// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
18// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
21// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
23// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
24// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +000026#include "webrtc/base/fileutils.h"
27#include "webrtc/base/gunit.h"
28#include "webrtc/base/helpers.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/pathutils.h"
31#include "webrtc/base/signalthread.h"
32#include "webrtc/base/ssladapter.h"
33#include "webrtc/base/sslidentity.h"
34#include "webrtc/base/window.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035#include "talk/media/base/fakemediaengine.h"
36#include "talk/media/base/fakertp.h"
37#include "talk/media/base/fakevideocapturer.h"
38#include "talk/media/base/mediachannel.h"
39#include "talk/media/base/rtpdump.h"
40#include "talk/media/base/screencastid.h"
41#include "talk/media/base/testutils.h"
42#include "talk/p2p/base/fakesession.h"
43#include "talk/session/media/channel.h"
44#include "talk/session/media/mediamessages.h"
45#include "talk/session/media/mediarecorder.h"
46#include "talk/session/media/mediasessionclient.h"
47#include "talk/session/media/typingmonitor.h"
48
49#define MAYBE_SKIP_TEST(feature) \
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000050 if (!(rtc::SSLStreamAdapter::feature())) { \
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051 LOG(LS_INFO) << "Feature disabled... skipping"; \
52 return; \
53 }
54
55using cricket::CA_OFFER;
56using cricket::CA_PRANSWER;
57using cricket::CA_ANSWER;
58using cricket::CA_UPDATE;
59using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::ScreencastId;
61using cricket::StreamParams;
62using cricket::TransportChannel;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000063using rtc::WindowId;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064
65static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
66static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
67static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
68static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
69static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
70static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
71static const uint32 kSsrc1 = 0x1111;
72static const uint32 kSsrc2 = 0x2222;
73static const uint32 kSsrc3 = 0x3333;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000074static const int kAudioPts[] = {0, 8};
75static const int kVideoPts[] = {97, 99};
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
77template<class ChannelT,
78 class MediaChannelT,
79 class ContentT,
80 class CodecT,
81 class MediaInfoT>
82class Traits {
83 public:
84 typedef ChannelT Channel;
85 typedef MediaChannelT MediaChannel;
86 typedef ContentT Content;
87 typedef CodecT Codec;
88 typedef MediaInfoT MediaInfo;
89};
90
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +000091class FakeScreenCaptureFactory
92 : public cricket::VideoChannel::ScreenCapturerFactory,
93 public sigslot::has_slots<> {
94 public:
95 FakeScreenCaptureFactory()
96 : window_capturer_(NULL),
97 capture_state_(cricket::CS_STOPPED) {}
98
99 virtual cricket::VideoCapturer* CreateScreenCapturer(
100 const ScreencastId& window) {
101 if (window_capturer_ != NULL) {
102 // Class is only designed to handle one fake screencapturer.
103 ADD_FAILURE();
104 return NULL;
105 }
106 window_capturer_ = new cricket::FakeVideoCapturer;
107 window_capturer_->SignalDestroyed.connect(
108 this,
109 &FakeScreenCaptureFactory::OnWindowCapturerDestroyed);
110 window_capturer_->SignalStateChange.connect(
111 this,
112 &FakeScreenCaptureFactory::OnStateChange);
113 return window_capturer_;
114 }
115
116 cricket::FakeVideoCapturer* window_capturer() { return window_capturer_; }
117
118 cricket::CaptureState capture_state() { return capture_state_; }
119
120 private:
121 void OnWindowCapturerDestroyed(cricket::FakeVideoCapturer* capturer) {
122 if (capturer == window_capturer_) {
123 window_capturer_ = NULL;
124 }
125 }
126 void OnStateChange(cricket::VideoCapturer*, cricket::CaptureState state) {
127 capture_state_ = state;
128 }
129
130 cricket::FakeVideoCapturer* window_capturer_;
131 cricket::CaptureState capture_state_;
132};
133
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134// Controls how long we wait for a session to send messages that we
135// expect, in milliseconds. We put it high to avoid flaky tests.
136static const int kEventTimeout = 5000;
137
138class VoiceTraits : public Traits<cricket::VoiceChannel,
139 cricket::FakeVoiceMediaChannel,
140 cricket::AudioContentDescription,
141 cricket::AudioCodec,
142 cricket::VoiceMediaInfo> {
143};
144
145class VideoTraits : public Traits<cricket::VideoChannel,
146 cricket::FakeVideoMediaChannel,
147 cricket::VideoContentDescription,
148 cricket::VideoCodec,
149 cricket::VideoMediaInfo> {
150};
151
152class DataTraits : public Traits<cricket::DataChannel,
153 cricket::FakeDataMediaChannel,
154 cricket::DataContentDescription,
155 cricket::DataCodec,
156 cricket::DataMediaInfo> {
157};
158
159
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000160rtc::StreamInterface* Open(const std::string& path) {
161 return rtc::Filesystem::OpenFile(
162 rtc::Pathname(path), "wb");
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163}
164
165// Base class for Voice/VideoChannel tests
166template<class T>
167class ChannelTest : public testing::Test, public sigslot::has_slots<> {
168 public:
169 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
170 DTLS = 0x10 };
171
172 ChannelTest(const uint8* rtp_data, int rtp_len,
173 const uint8* rtcp_data, int rtcp_len)
174 : session1_(true),
175 session2_(false),
176 media_channel1_(NULL),
177 media_channel2_(NULL),
178 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
179 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
180 media_info_callbacks1_(),
181 media_info_callbacks2_(),
182 mute_callback_recved_(false),
183 mute_callback_value_(false),
184 ssrc_(0),
185 error_(T::MediaChannel::ERROR_NONE) {
186 }
187
188 static void SetUpTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000189 rtc::InitializeSSL();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000190 }
191
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000192 static void TearDownTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000193 rtc::CleanupSSL();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000194 }
195
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000196 void CreateChannels(int flags1, int flags2) {
197 CreateChannels(new typename T::MediaChannel(NULL),
198 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000199 flags1, flags2, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 }
201 void CreateChannels(int flags) {
202 CreateChannels(new typename T::MediaChannel(NULL),
203 new typename T::MediaChannel(NULL),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000204 flags, rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 }
206 void CreateChannels(int flags1, int flags2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000207 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 CreateChannels(new typename T::MediaChannel(NULL),
209 new typename T::MediaChannel(NULL),
210 flags1, flags2, thread);
211 }
212 void CreateChannels(int flags,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000213 rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 CreateChannels(new typename T::MediaChannel(NULL),
215 new typename T::MediaChannel(NULL),
216 flags, thread);
217 }
218 void CreateChannels(
219 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000220 int flags1, int flags2, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000221 media_channel1_ = ch1;
222 media_channel2_ = ch2;
223 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
224 (flags1 & RTCP) != 0));
225 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
226 (flags2 & RTCP) != 0));
227 channel1_->SignalMediaMonitor.connect(
228 this, &ChannelTest<T>::OnMediaMonitor);
229 channel2_->SignalMediaMonitor.connect(
230 this, &ChannelTest<T>::OnMediaMonitor);
231 channel1_->SignalMediaError.connect(
232 this, &ChannelTest<T>::OnMediaChannelError);
233 channel2_->SignalMediaError.connect(
234 this, &ChannelTest<T>::OnMediaChannelError);
235 channel1_->SignalAutoMuted.connect(
236 this, &ChannelTest<T>::OnMediaMuted);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000237 if ((flags1 & DTLS) && (flags2 & DTLS)) {
238 flags1 = (flags1 & ~SECURE);
239 flags2 = (flags2 & ~SECURE);
240 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241 CreateContent(flags1, kPcmuCodec, kH264Codec,
242 &local_media_content1_);
243 CreateContent(flags2, kPcmuCodec, kH264Codec,
244 &local_media_content2_);
245 CopyContent(local_media_content1_, &remote_media_content1_);
246 CopyContent(local_media_content2_, &remote_media_content2_);
247
248 if (flags1 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000249 identity1_.reset(rtc::SSLIdentity::Generate("session1"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250 session1_.set_ssl_identity(identity1_.get());
251 }
252 if (flags2 & DTLS) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000253 identity2_.reset(rtc::SSLIdentity::Generate("session2"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 session2_.set_ssl_identity(identity2_.get());
255 }
256
257 // Add stream information (SSRC) to the local content but not to the remote
258 // content. This means that we per default know the SSRC of what we send but
259 // not what we receive.
260 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
261 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
262
263 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
264 if (flags1 & SSRC_MUX) {
265 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
266 }
267 if (flags2 & SSRC_MUX) {
268 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
269 }
270 }
271
272 void CreateChannels(
273 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000274 int flags, rtc::Thread* thread) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 media_channel1_ = ch1;
276 media_channel2_ = ch2;
277
278 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
279 (flags & RTCP) != 0));
280 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
281 (flags & RTCP) != 0));
282 channel1_->SignalMediaMonitor.connect(
283 this, &ChannelTest<T>::OnMediaMonitor);
284 channel2_->SignalMediaMonitor.connect(
285 this, &ChannelTest<T>::OnMediaMonitor);
286 channel2_->SignalMediaError.connect(
287 this, &ChannelTest<T>::OnMediaChannelError);
288 CreateContent(flags, kPcmuCodec, kH264Codec,
289 &local_media_content1_);
290 CreateContent(flags, kPcmuCodec, kH264Codec,
291 &local_media_content2_);
292 CopyContent(local_media_content1_, &remote_media_content1_);
293 CopyContent(local_media_content2_, &remote_media_content2_);
294 // Add stream information (SSRC) to the local content but not to the remote
295 // content. This means that we per default know the SSRC of what we send but
296 // not what we receive.
297 AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
298 AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
299
300 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
301 if (flags & SSRC_MUX) {
302 AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
303 AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
304 }
305 }
306
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000307 typename T::Channel* CreateChannel(rtc::Thread* thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000308 cricket::MediaEngineInterface* engine,
309 typename T::MediaChannel* ch,
310 cricket::BaseSession* session,
311 bool rtcp) {
312 typename T::Channel* channel = new typename T::Channel(
313 thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
314 if (!channel->Init()) {
315 delete channel;
316 channel = NULL;
317 }
318 return channel;
319 }
320
321 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000322 bool result = channel1_->SetLocalContent(&local_media_content1_,
323 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 if (result) {
325 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000326 result = channel2_->SetRemoteContent(&remote_media_content1_,
327 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 if (result) {
329 session1_.Connect(&session2_);
330
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000331 result = channel2_->SetLocalContent(&local_media_content2_,
332 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 }
334 }
335 return result;
336 }
337
338 bool SendAccept() {
339 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000340 return channel1_->SetRemoteContent(&remote_media_content2_,
341 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 }
343
344 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000345 bool result = channel1_->SetLocalContent(&local_media_content1_,
346 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 if (result) {
348 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000349 result = channel2_->SetRemoteContent(&remote_media_content1_,
350 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 }
352 return result;
353 }
354
355 bool SendProvisionalAnswer() {
356 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000357 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 if (result) {
359 channel2_->Enable(true);
360 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000361 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 session1_.Connect(&session2_);
363 }
364 return result;
365 }
366
367 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000368 bool result = channel2_->SetLocalContent(&local_media_content2_,
369 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000371 result = channel1_->SetRemoteContent(&remote_media_content2_,
372 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 return result;
374 }
375
376 bool SendTerminate() {
377 channel1_.reset();
378 channel2_.reset();
379 return true;
380 }
381
382 bool AddStream1(int id) {
383 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
384 }
385 bool RemoveStream1(int id) {
386 return channel1_->RemoveRecvStream(id);
387 }
388
389 cricket::FakeTransport* GetTransport1() {
390 return session1_.GetTransport(channel1_->content_name());
391 }
392 cricket::FakeTransport* GetTransport2() {
393 return session2_.GetTransport(channel2_->content_name());
394 }
395
396 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000397 return media_channel1_->SendRtp(rtp_packet_.c_str(),
398 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 }
400 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000401 return media_channel2_->SendRtp(rtp_packet_.c_str(),
402 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 }
404 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000405 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
406 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000407 }
408 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000409 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
410 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 }
412 // Methods to send custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000413 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
414 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000415 return media_channel1_->SendRtp(data.c_str(),
416 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000418 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
419 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000420 return media_channel2_->SendRtp(data.c_str(),
421 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 }
423 bool SendCustomRtcp1(uint32 ssrc) {
424 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000425 return media_channel1_->SendRtcp(data.c_str(),
426 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 }
428 bool SendCustomRtcp2(uint32 ssrc) {
429 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000430 return media_channel2_->SendRtcp(data.c_str(),
431 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 }
433 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000434 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
435 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436 }
437 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000438 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
439 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 }
441 bool CheckRtcp1() {
442 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000443 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000444 }
445 bool CheckRtcp2() {
446 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000447 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000448 }
449 // Methods to check custom data.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000450 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
451 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000452 return media_channel1_->CheckRtp(data.c_str(),
453 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000454 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000455 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
456 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000457 return media_channel2_->CheckRtp(data.c_str(),
458 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000459 }
460 bool CheckCustomRtcp1(uint32 ssrc) {
461 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000462 return media_channel1_->CheckRtcp(data.c_str(),
463 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 }
465 bool CheckCustomRtcp2(uint32 ssrc) {
466 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000467 return media_channel2_->CheckRtcp(data.c_str(),
468 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 }
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000470 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 std::string data(rtp_packet_);
472 // Set SSRC in the rtp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000473 rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
474 rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000475 if (pl_type >= 0) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000476 rtc::Set8(const_cast<char*>(data.c_str()), 1, pl_type);
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +0000477 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000478 return data;
479 }
480 std::string CreateRtcpData(uint32 ssrc) {
481 std::string data(rtcp_packet_);
482 // Set SSRC in the rtcp packet copy.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000483 rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 return data;
485 }
486
487 bool CheckNoRtp1() {
488 return media_channel1_->CheckNoRtp();
489 }
490 bool CheckNoRtp2() {
491 return media_channel2_->CheckNoRtp();
492 }
493 bool CheckNoRtcp1() {
494 return media_channel1_->CheckNoRtcp();
495 }
496 bool CheckNoRtcp2() {
497 return media_channel2_->CheckNoRtcp();
498 }
499
500 void CreateContent(int flags,
501 const cricket::AudioCodec& audio_codec,
502 const cricket::VideoCodec& video_codec,
503 typename T::Content* content) {
504 // overridden in specialized classes
505 }
506 void CopyContent(const typename T::Content& source,
507 typename T::Content* content) {
508 // overridden in specialized classes
509 }
510
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511 // Creates a cricket::SessionDescription with one MediaContent and one stream.
512 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
513 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
514 typename T::Content content;
515 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
516 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
517 AddLegacyStreamInContent(ssrc, 0, &content);
518 sdesc->AddContent("DUMMY_CONTENT_NAME",
519 cricket::NS_JINGLE_RTP, content.Copy());
520 return sdesc;
521 }
522
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000523 class CallThread : public rtc::SignalThread {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000524 public:
525 typedef bool (ChannelTest<T>::*Method)();
526 CallThread(ChannelTest<T>* obj, Method method, bool* result)
527 : obj_(obj),
528 method_(method),
529 result_(result) {
530 *result = false;
531 }
532 virtual void DoWork() {
533 bool result = (*obj_.*method_)();
534 if (result_) {
535 *result_ = result;
536 }
537 }
538 private:
539 ChannelTest<T>* obj_;
540 Method method_;
541 bool* result_;
542 };
543 void CallOnThread(typename CallThread::Method method, bool* result) {
544 CallThread* thread = new CallThread(this, method, result);
545 thread->Start();
546 thread->Release();
547 }
548
549 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
550 bool* result) {
551 CallThread* thread = new CallThread(this, method, result);
552 thread->Start();
553 thread->Destroy(true);
554 }
555
556 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
557 return false; // overridden in specialized classes
558 }
559
560 void OnMediaMonitor(typename T::Channel* channel,
561 const typename T::MediaInfo& info) {
562 if (channel == channel1_.get()) {
563 media_info_callbacks1_++;
564 } else if (channel == channel2_.get()) {
565 media_info_callbacks2_++;
566 }
567 }
568
569 void OnMediaChannelError(typename T::Channel* channel,
570 uint32 ssrc,
571 typename T::MediaChannel::Error error) {
572 ssrc_ = ssrc;
573 error_ = error;
574 }
575
576 void OnMediaMuted(cricket::BaseChannel* channel, bool muted) {
577 mute_callback_recved_ = true;
578 mute_callback_value_ = muted;
579 }
580
581 void AddLegacyStreamInContent(uint32 ssrc, int flags,
582 typename T::Content* content) {
583 // Base implementation.
584 }
585
586 // Tests that can be used by derived classes.
587
588 // Basic sanity check.
589 void TestInit() {
590 CreateChannels(0, 0);
591 EXPECT_FALSE(channel1_->secure());
592 EXPECT_FALSE(media_channel1_->sending());
593 EXPECT_FALSE(media_channel1_->playout());
594 EXPECT_TRUE(media_channel1_->codecs().empty());
595 EXPECT_TRUE(media_channel1_->recv_streams().empty());
596 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
597 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
598 }
599
600 // Test that SetLocalContent and SetRemoteContent properly configure
601 // the codecs.
602 void TestSetContents() {
603 CreateChannels(0, 0);
604 typename T::Content content;
605 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000606 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000608 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000609 ASSERT_EQ(1U, media_channel1_->codecs().size());
610 EXPECT_TRUE(CodecMatches(content.codecs()[0],
611 media_channel1_->codecs()[0]));
612 }
613
614 // Test that SetLocalContent and SetRemoteContent properly deals
615 // with an empty offer.
616 void TestSetContentsNullOffer() {
617 CreateChannels(0, 0);
618 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000619 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 CreateContent(0, kPcmuCodec, kH264Codec, &content);
621 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000622 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 ASSERT_EQ(1U, media_channel1_->codecs().size());
624 EXPECT_TRUE(CodecMatches(content.codecs()[0],
625 media_channel1_->codecs()[0]));
626 }
627
628 // Test that SetLocalContent and SetRemoteContent properly set RTCP
629 // mux.
630 void TestSetContentsRtcpMux() {
631 CreateChannels(RTCP, RTCP);
632 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
633 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
634 typename T::Content content;
635 CreateContent(0, kPcmuCodec, kH264Codec, &content);
636 // Both sides agree on mux. Should no longer be a separate RTCP channel.
637 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000638 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
639 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
641 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000642 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000644 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
646 }
647
648 // Test that SetLocalContent and SetRemoteContent properly set RTCP
649 // mux when a provisional answer is received.
650 void TestSetContentsRtcpMuxWithPrAnswer() {
651 CreateChannels(RTCP, RTCP);
652 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
653 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
654 typename T::Content content;
655 CreateContent(0, kPcmuCodec, kH264Codec, &content);
656 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000657 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
658 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000659 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000660 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 // Both sides agree on mux. Should no longer be a separate RTCP channel.
662 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
663 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000664 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000666 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
667 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
669 }
670
671 // Test that SetLocalContent and SetRemoteContent properly set
672 // video options to the media channel.
673 void TestSetContentsVideoOptions() {
674 CreateChannels(0, 0);
675 typename T::Content content;
676 CreateContent(0, kPcmuCodec, kH264Codec, &content);
677 content.set_buffered_mode_latency(101);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000678 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000679 EXPECT_EQ(0U, media_channel1_->codecs().size());
680 cricket::VideoOptions options;
681 ASSERT_TRUE(media_channel1_->GetOptions(&options));
682 int latency = 0;
683 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
684 EXPECT_EQ(101, latency);
685 content.set_buffered_mode_latency(102);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000686 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 ASSERT_EQ(1U, media_channel1_->codecs().size());
688 EXPECT_TRUE(CodecMatches(content.codecs()[0],
689 media_channel1_->codecs()[0]));
690 ASSERT_TRUE(media_channel1_->GetOptions(&options));
691 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
692 EXPECT_EQ(102, latency);
693 }
694
695 // Test that SetRemoteContent properly deals with a content update.
696 void TestSetRemoteContentUpdate() {
697 CreateChannels(0, 0);
698 typename T::Content content;
699 CreateContent(RTCP | RTCP_MUX | SECURE,
700 kPcmuCodec, kH264Codec,
701 &content);
702 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000703 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
704 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 ASSERT_EQ(1U, media_channel1_->codecs().size());
706 EXPECT_TRUE(CodecMatches(content.codecs()[0],
707 media_channel1_->codecs()[0]));
708 // Now update with other codecs.
709 typename T::Content update_content;
710 update_content.set_partial(true);
711 CreateContent(0, kIsacCodec, kH264SvcCodec,
712 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000713 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 ASSERT_EQ(1U, media_channel1_->codecs().size());
715 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
716 media_channel1_->codecs()[0]));
717 // Now update without any codecs. This is ignored.
718 typename T::Content empty_content;
719 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000720 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 ASSERT_EQ(1U, media_channel1_->codecs().size());
722 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
723 media_channel1_->codecs()[0]));
724 }
725
726 // Test that Add/RemoveStream properly forward to the media channel.
727 void TestStreams() {
728 CreateChannels(0, 0);
729 EXPECT_TRUE(AddStream1(1));
730 EXPECT_TRUE(AddStream1(2));
731 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
732 EXPECT_TRUE(RemoveStream1(2));
733 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
734 EXPECT_TRUE(RemoveStream1(1));
735 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
736 }
737
738 // Test that SetLocalContent properly handles adding and removing StreamParams
739 // to the local content description.
740 // This test uses the CA_UPDATE action that don't require a full
741 // MediaContentDescription to do an update.
742 void TestUpdateStreamsInLocalContent() {
743 cricket::StreamParams stream1;
744 stream1.groupid = "group1";
745 stream1.id = "stream1";
746 stream1.ssrcs.push_back(kSsrc1);
747 stream1.cname = "stream1_cname";
748
749 cricket::StreamParams stream2;
750 stream2.groupid = "group2";
751 stream2.id = "stream2";
752 stream2.ssrcs.push_back(kSsrc2);
753 stream2.cname = "stream2_cname";
754
755 cricket::StreamParams stream3;
756 stream3.groupid = "group3";
757 stream3.id = "stream3";
758 stream3.ssrcs.push_back(kSsrc3);
759 stream3.cname = "stream3_cname";
760
761 CreateChannels(0, 0);
762 typename T::Content content1;
763 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
764 content1.AddStream(stream1);
765 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000766 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767
768 ASSERT_EQ(1u, media_channel1_->send_streams().size());
769 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
770
771 // Update the local streams by adding another sending stream.
772 // Use a partial updated session description.
773 typename T::Content content2;
774 content2.AddStream(stream2);
775 content2.AddStream(stream3);
776 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000777 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000778 ASSERT_EQ(3u, media_channel1_->send_streams().size());
779 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
780 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
781 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
782
783 // Update the local streams by removing the first sending stream.
784 // This is done by removing all SSRCS for this particular stream.
785 typename T::Content content3;
786 stream1.ssrcs.clear();
787 content3.AddStream(stream1);
788 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000789 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 ASSERT_EQ(2u, media_channel1_->send_streams().size());
791 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
792 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
793
794 // Update the local streams with a stream that does not change.
795 // THe update is ignored.
796 typename T::Content content4;
797 content4.AddStream(stream2);
798 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000799 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 ASSERT_EQ(2u, media_channel1_->send_streams().size());
801 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
802 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
803 }
804
805 // Test that SetRemoteContent properly handles adding and removing
806 // StreamParams to the remote content description.
807 // This test uses the CA_UPDATE action that don't require a full
808 // MediaContentDescription to do an update.
809 void TestUpdateStreamsInRemoteContent() {
810 cricket::StreamParams stream1;
811 stream1.id = "Stream1";
812 stream1.groupid = "1";
813 stream1.ssrcs.push_back(kSsrc1);
814 stream1.cname = "stream1_cname";
815
816 cricket::StreamParams stream2;
817 stream2.id = "Stream2";
818 stream2.groupid = "2";
819 stream2.ssrcs.push_back(kSsrc2);
820 stream2.cname = "stream2_cname";
821
822 cricket::StreamParams stream3;
823 stream3.id = "Stream3";
824 stream3.groupid = "3";
825 stream3.ssrcs.push_back(kSsrc3);
826 stream3.cname = "stream3_cname";
827
828 CreateChannels(0, 0);
829 typename T::Content content1;
830 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
831 content1.AddStream(stream1);
832 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000833 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000834
835 ASSERT_EQ(1u, media_channel1_->codecs().size());
836 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
837 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
838
839 // Update the remote streams by adding another sending stream.
840 // Use a partial updated session description.
841 typename T::Content content2;
842 content2.AddStream(stream2);
843 content2.AddStream(stream3);
844 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000845 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
847 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
848 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
849 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
850
851 // Update the remote streams by removing the first stream.
852 // This is done by removing all SSRCS for this particular stream.
853 typename T::Content content3;
854 stream1.ssrcs.clear();
855 content3.AddStream(stream1);
856 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000857 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
859 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
860 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
861
862 // Update the remote streams with a stream that does not change.
863 // The update is ignored.
864 typename T::Content content4;
865 content4.AddStream(stream2);
866 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000867 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
869 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
870 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
871 }
872
873 // Test that SetLocalContent and SetRemoteContent properly
874 // handles adding and removing StreamParams when the action is a full
875 // CA_OFFER / CA_ANSWER.
876 void TestChangeStreamParamsInContent() {
877 cricket::StreamParams stream1;
878 stream1.groupid = "group1";
879 stream1.id = "stream1";
880 stream1.ssrcs.push_back(kSsrc1);
881 stream1.cname = "stream1_cname";
882
883 cricket::StreamParams stream2;
884 stream2.groupid = "group1";
885 stream2.id = "stream2";
886 stream2.ssrcs.push_back(kSsrc2);
887 stream2.cname = "stream2_cname";
888
889 // Setup a call where channel 1 send |stream1| to channel 2.
890 CreateChannels(0, 0);
891 typename T::Content content1;
892 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
893 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000894 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 EXPECT_TRUE(channel1_->Enable(true));
896 EXPECT_EQ(1u, media_channel1_->send_streams().size());
897
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000898 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000899 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
900 session1_.Connect(&session2_);
901
902 // Channel 2 do not send anything.
903 typename T::Content content2;
904 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000905 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000907 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 EXPECT_TRUE(channel2_->Enable(true));
909 EXPECT_EQ(0u, media_channel2_->send_streams().size());
910
911 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
912 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
913
914 // Let channel 2 update the content by sending |stream2| and enable SRTP.
915 typename T::Content content3;
916 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
917 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000918 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 ASSERT_EQ(1u, media_channel2_->send_streams().size());
920 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
921
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000922 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
924 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
925
926 // Channel 1 replies but stop sending stream1.
927 typename T::Content content4;
928 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000929 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 EXPECT_EQ(0u, media_channel1_->send_streams().size());
931
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000932 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
934
935 EXPECT_TRUE(channel1_->secure());
936 EXPECT_TRUE(channel2_->secure());
937 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
938 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
939 }
940
941 // Test that we only start playout and sending at the right times.
942 void TestPlayoutAndSendingStates() {
943 CreateChannels(0, 0);
944 EXPECT_FALSE(media_channel1_->playout());
945 EXPECT_FALSE(media_channel1_->sending());
946 EXPECT_FALSE(media_channel2_->playout());
947 EXPECT_FALSE(media_channel2_->sending());
948 EXPECT_TRUE(channel1_->Enable(true));
949 EXPECT_FALSE(media_channel1_->playout());
950 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000951 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
952 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 EXPECT_TRUE(media_channel1_->playout());
954 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000955 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
956 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 EXPECT_FALSE(media_channel2_->playout());
958 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000959 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
960 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 EXPECT_FALSE(media_channel2_->playout());
962 EXPECT_FALSE(media_channel2_->sending());
963 session1_.Connect(&session2_);
964 EXPECT_TRUE(media_channel1_->playout());
965 EXPECT_FALSE(media_channel1_->sending());
966 EXPECT_FALSE(media_channel2_->playout());
967 EXPECT_FALSE(media_channel2_->sending());
968 EXPECT_TRUE(channel2_->Enable(true));
969 EXPECT_TRUE(media_channel2_->playout());
970 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000971 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
972 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 EXPECT_TRUE(media_channel1_->playout());
974 EXPECT_TRUE(media_channel1_->sending());
975 }
976
977 void TestMuteStream() {
978 CreateChannels(0, 0);
979 // Test that we can Mute the default channel even though the sending SSRC is
980 // unknown.
981 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
982 EXPECT_TRUE(channel1_->MuteStream(0, true));
983 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
984 EXPECT_TRUE(channel1_->MuteStream(0, false));
985 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
986
987 // Test that we can not mute an unknown SSRC.
988 EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true));
989
990 SendInitiate();
991 // After the local session description has been set, we can mute a stream
992 // with its SSRC.
993 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true));
994 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
995 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false));
996 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
997 }
998
999 // Test that changing the MediaContentDirection in the local and remote
1000 // session description start playout and sending at the right time.
1001 void TestMediaContentDirection() {
1002 CreateChannels(0, 0);
1003 typename T::Content content1;
1004 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
1005 typename T::Content content2;
1006 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
1007 // Set |content2| to be InActive.
1008 content2.set_direction(cricket::MD_INACTIVE);
1009
1010 EXPECT_TRUE(channel1_->Enable(true));
1011 EXPECT_TRUE(channel2_->Enable(true));
1012 EXPECT_FALSE(media_channel1_->playout());
1013 EXPECT_FALSE(media_channel1_->sending());
1014 EXPECT_FALSE(media_channel2_->playout());
1015 EXPECT_FALSE(media_channel2_->sending());
1016
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001017 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
1018 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
1019 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
1020 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 session1_.Connect(&session2_);
1022
1023 EXPECT_TRUE(media_channel1_->playout());
1024 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
1025 EXPECT_FALSE(media_channel2_->playout()); // local InActive
1026 EXPECT_FALSE(media_channel2_->sending()); // local InActive
1027
1028 // Update |content2| to be RecvOnly.
1029 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001030 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
1031 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032
1033 EXPECT_TRUE(media_channel1_->playout());
1034 EXPECT_TRUE(media_channel1_->sending());
1035 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
1036 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
1037
1038 // Update |content2| to be SendRecv.
1039 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001040 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
1041 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001042
1043 EXPECT_TRUE(media_channel1_->playout());
1044 EXPECT_TRUE(media_channel1_->sending());
1045 EXPECT_TRUE(media_channel2_->playout());
1046 EXPECT_TRUE(media_channel2_->sending());
1047 }
1048
1049 // Test setting up a call.
1050 void TestCallSetup() {
1051 CreateChannels(0, 0);
1052 EXPECT_FALSE(channel1_->secure());
1053 EXPECT_TRUE(SendInitiate());
1054 EXPECT_TRUE(media_channel1_->playout());
1055 EXPECT_FALSE(media_channel1_->sending());
1056 EXPECT_TRUE(SendAccept());
1057 EXPECT_FALSE(channel1_->secure());
1058 EXPECT_TRUE(media_channel1_->sending());
1059 EXPECT_EQ(1U, media_channel1_->codecs().size());
1060 EXPECT_TRUE(media_channel2_->playout());
1061 EXPECT_TRUE(media_channel2_->sending());
1062 EXPECT_EQ(1U, media_channel2_->codecs().size());
1063 }
1064
1065 // Test that we don't crash if packets are sent during call teardown
1066 // when RTCP mux is enabled. This is a regression test against a specific
1067 // race condition that would only occur when a RTCP packet was sent during
1068 // teardown of a channel on which RTCP mux was enabled.
1069 void TestCallTeardownRtcpMux() {
1070 class LastWordMediaChannel : public T::MediaChannel {
1071 public:
1072 LastWordMediaChannel() : T::MediaChannel(NULL) {}
1073 ~LastWordMediaChannel() {
1074 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
1075 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1076 }
1077 };
1078 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1079 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001080 rtc::Thread::Current());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 EXPECT_TRUE(SendInitiate());
1082 EXPECT_TRUE(SendAccept());
1083 EXPECT_TRUE(SendTerminate());
1084 }
1085
1086 // Send voice RTP data to the other side and ensure it gets there.
1087 void SendRtpToRtp() {
1088 CreateChannels(0, 0);
1089 EXPECT_TRUE(SendInitiate());
1090 EXPECT_TRUE(SendAccept());
1091 EXPECT_EQ(1U, GetTransport1()->channels().size());
1092 EXPECT_EQ(1U, GetTransport2()->channels().size());
1093 EXPECT_TRUE(SendRtp1());
1094 EXPECT_TRUE(SendRtp2());
1095 EXPECT_TRUE(CheckRtp1());
1096 EXPECT_TRUE(CheckRtp2());
1097 EXPECT_TRUE(CheckNoRtp1());
1098 EXPECT_TRUE(CheckNoRtp2());
1099 }
1100
1101 // Check that RTCP is not transmitted if both sides don't support RTCP.
1102 void SendNoRtcpToNoRtcp() {
1103 CreateChannels(0, 0);
1104 EXPECT_TRUE(SendInitiate());
1105 EXPECT_TRUE(SendAccept());
1106 EXPECT_EQ(1U, GetTransport1()->channels().size());
1107 EXPECT_EQ(1U, GetTransport2()->channels().size());
1108 EXPECT_FALSE(SendRtcp1());
1109 EXPECT_FALSE(SendRtcp2());
1110 EXPECT_TRUE(CheckNoRtcp1());
1111 EXPECT_TRUE(CheckNoRtcp2());
1112 }
1113
1114 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1115 void SendNoRtcpToRtcp() {
1116 CreateChannels(0, RTCP);
1117 EXPECT_TRUE(SendInitiate());
1118 EXPECT_TRUE(SendAccept());
1119 EXPECT_EQ(1U, GetTransport1()->channels().size());
1120 EXPECT_EQ(2U, GetTransport2()->channels().size());
1121 EXPECT_FALSE(SendRtcp1());
1122 EXPECT_FALSE(SendRtcp2());
1123 EXPECT_TRUE(CheckNoRtcp1());
1124 EXPECT_TRUE(CheckNoRtcp2());
1125 }
1126
1127 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1128 void SendRtcpToNoRtcp() {
1129 CreateChannels(RTCP, 0);
1130 EXPECT_TRUE(SendInitiate());
1131 EXPECT_TRUE(SendAccept());
1132 EXPECT_EQ(2U, GetTransport1()->channels().size());
1133 EXPECT_EQ(1U, GetTransport2()->channels().size());
1134 EXPECT_FALSE(SendRtcp1());
1135 EXPECT_FALSE(SendRtcp2());
1136 EXPECT_TRUE(CheckNoRtcp1());
1137 EXPECT_TRUE(CheckNoRtcp2());
1138 }
1139
1140 // Check that RTCP is transmitted if both sides support RTCP.
1141 void SendRtcpToRtcp() {
1142 CreateChannels(RTCP, RTCP);
1143 EXPECT_TRUE(SendInitiate());
1144 EXPECT_TRUE(SendAccept());
1145 EXPECT_EQ(2U, GetTransport1()->channels().size());
1146 EXPECT_EQ(2U, GetTransport2()->channels().size());
1147 EXPECT_TRUE(SendRtcp1());
1148 EXPECT_TRUE(SendRtcp2());
1149 EXPECT_TRUE(CheckRtcp1());
1150 EXPECT_TRUE(CheckRtcp2());
1151 EXPECT_TRUE(CheckNoRtcp1());
1152 EXPECT_TRUE(CheckNoRtcp2());
1153 }
1154
1155 // Check that RTCP is transmitted if only the initiator supports mux.
1156 void SendRtcpMuxToRtcp() {
1157 CreateChannels(RTCP | RTCP_MUX, RTCP);
1158 EXPECT_TRUE(SendInitiate());
1159 EXPECT_TRUE(SendAccept());
1160 EXPECT_EQ(2U, GetTransport1()->channels().size());
1161 EXPECT_EQ(2U, GetTransport2()->channels().size());
1162 EXPECT_TRUE(SendRtcp1());
1163 EXPECT_TRUE(SendRtcp2());
1164 EXPECT_TRUE(CheckRtcp1());
1165 EXPECT_TRUE(CheckRtcp2());
1166 EXPECT_TRUE(CheckNoRtcp1());
1167 EXPECT_TRUE(CheckNoRtcp2());
1168 }
1169
1170 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1171 void SendRtcpMuxToRtcpMux() {
1172 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1173 EXPECT_TRUE(SendInitiate());
1174 EXPECT_EQ(2U, GetTransport1()->channels().size());
1175 EXPECT_EQ(1U, GetTransport2()->channels().size());
1176 EXPECT_TRUE(SendAccept());
1177 EXPECT_EQ(1U, GetTransport1()->channels().size());
1178 EXPECT_TRUE(SendRtp1());
1179 EXPECT_TRUE(SendRtp2());
1180 EXPECT_TRUE(SendRtcp1());
1181 EXPECT_TRUE(SendRtcp2());
1182 EXPECT_TRUE(CheckRtp1());
1183 EXPECT_TRUE(CheckRtp2());
1184 EXPECT_TRUE(CheckNoRtp1());
1185 EXPECT_TRUE(CheckNoRtp2());
1186 EXPECT_TRUE(CheckRtcp1());
1187 EXPECT_TRUE(CheckRtcp2());
1188 EXPECT_TRUE(CheckNoRtcp1());
1189 EXPECT_TRUE(CheckNoRtcp2());
1190 }
1191
1192 // Check that RTCP data sent by the initiator before the accept is not muxed.
1193 void SendEarlyRtcpMuxToRtcp() {
1194 CreateChannels(RTCP | RTCP_MUX, RTCP);
1195 EXPECT_TRUE(SendInitiate());
1196 EXPECT_EQ(2U, GetTransport1()->channels().size());
1197 EXPECT_EQ(2U, GetTransport2()->channels().size());
1198
1199 // RTCP can be sent before the call is accepted, if the transport is ready.
1200 // It should not be muxed though, as the remote side doesn't support mux.
1201 EXPECT_TRUE(SendRtcp1());
1202 EXPECT_TRUE(CheckNoRtp2());
1203 EXPECT_TRUE(CheckRtcp2());
1204
1205 // Send RTCP packet from callee and verify that it is received.
1206 EXPECT_TRUE(SendRtcp2());
1207 EXPECT_TRUE(CheckNoRtp1());
1208 EXPECT_TRUE(CheckRtcp1());
1209
1210 // Complete call setup and ensure everything is still OK.
1211 EXPECT_TRUE(SendAccept());
1212 EXPECT_EQ(2U, GetTransport1()->channels().size());
1213 EXPECT_TRUE(SendRtcp1());
1214 EXPECT_TRUE(CheckRtcp2());
1215 EXPECT_TRUE(SendRtcp2());
1216 EXPECT_TRUE(CheckRtcp1());
1217 }
1218
1219
1220 // Check that RTCP data is not muxed until both sides have enabled muxing,
1221 // but that we properly demux before we get the accept message, since there
1222 // is a race between RTP data and the jingle accept.
1223 void SendEarlyRtcpMuxToRtcpMux() {
1224 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1225 EXPECT_TRUE(SendInitiate());
1226 EXPECT_EQ(2U, GetTransport1()->channels().size());
1227 EXPECT_EQ(1U, GetTransport2()->channels().size());
1228
1229 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1230 // we haven't yet received the accept that says we should mux.
1231 EXPECT_FALSE(SendRtcp1());
1232
1233 // Send muxed RTCP packet from callee and verify that it is received.
1234 EXPECT_TRUE(SendRtcp2());
1235 EXPECT_TRUE(CheckNoRtp1());
1236 EXPECT_TRUE(CheckRtcp1());
1237
1238 // Complete call setup and ensure everything is still OK.
1239 EXPECT_TRUE(SendAccept());
1240 EXPECT_EQ(1U, GetTransport1()->channels().size());
1241 EXPECT_TRUE(SendRtcp1());
1242 EXPECT_TRUE(CheckRtcp2());
1243 EXPECT_TRUE(SendRtcp2());
1244 EXPECT_TRUE(CheckRtcp1());
1245 }
1246
1247 // Test that we properly send SRTP with RTCP in both directions.
1248 // You can pass in DTLS and/or RTCP_MUX as flags.
1249 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1250 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1251 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1252
1253 int flags1 = RTCP | SECURE | flags1_in;
1254 int flags2 = RTCP | SECURE | flags2_in;
1255 bool dtls1 = !!(flags1_in & DTLS);
1256 bool dtls2 = !!(flags2_in & DTLS);
1257 CreateChannels(flags1, flags2);
1258 EXPECT_FALSE(channel1_->secure());
1259 EXPECT_FALSE(channel2_->secure());
1260 EXPECT_TRUE(SendInitiate());
1261 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1262 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1263 EXPECT_TRUE(SendAccept());
1264 EXPECT_TRUE(channel1_->secure());
1265 EXPECT_TRUE(channel2_->secure());
1266 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1267 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1268 EXPECT_TRUE(SendRtp1());
1269 EXPECT_TRUE(SendRtp2());
1270 EXPECT_TRUE(SendRtcp1());
1271 EXPECT_TRUE(SendRtcp2());
1272 EXPECT_TRUE(CheckRtp1());
1273 EXPECT_TRUE(CheckRtp2());
1274 EXPECT_TRUE(CheckNoRtp1());
1275 EXPECT_TRUE(CheckNoRtp2());
1276 EXPECT_TRUE(CheckRtcp1());
1277 EXPECT_TRUE(CheckRtcp2());
1278 EXPECT_TRUE(CheckNoRtcp1());
1279 EXPECT_TRUE(CheckNoRtcp2());
1280 }
1281
1282 // Test that we properly handling SRTP negotiating down to RTP.
1283 void SendSrtpToRtp() {
1284 CreateChannels(RTCP | SECURE, RTCP);
1285 EXPECT_FALSE(channel1_->secure());
1286 EXPECT_FALSE(channel2_->secure());
1287 EXPECT_TRUE(SendInitiate());
1288 EXPECT_TRUE(SendAccept());
1289 EXPECT_FALSE(channel1_->secure());
1290 EXPECT_FALSE(channel2_->secure());
1291 EXPECT_TRUE(SendRtp1());
1292 EXPECT_TRUE(SendRtp2());
1293 EXPECT_TRUE(SendRtcp1());
1294 EXPECT_TRUE(SendRtcp2());
1295 EXPECT_TRUE(CheckRtp1());
1296 EXPECT_TRUE(CheckRtp2());
1297 EXPECT_TRUE(CheckNoRtp1());
1298 EXPECT_TRUE(CheckNoRtp2());
1299 EXPECT_TRUE(CheckRtcp1());
1300 EXPECT_TRUE(CheckRtcp2());
1301 EXPECT_TRUE(CheckNoRtcp1());
1302 EXPECT_TRUE(CheckNoRtcp2());
1303 }
1304
1305 // Test that we can send and receive early media when a provisional answer is
1306 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1307 void SendEarlyMediaUsingRtcpMuxSrtp() {
1308 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1309
1310 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1311 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1312 EXPECT_TRUE(SendOffer());
1313 EXPECT_TRUE(SendProvisionalAnswer());
1314 EXPECT_TRUE(channel1_->secure());
1315 EXPECT_TRUE(channel2_->secure());
1316 EXPECT_EQ(2U, GetTransport1()->channels().size());
1317 EXPECT_EQ(2U, GetTransport2()->channels().size());
1318 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1319 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1320 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1321 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1322
1323 // Send packets from callee and verify that it is received.
1324 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1325 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1326 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1327 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1328
1329 // Complete call setup and ensure everything is still OK.
1330 EXPECT_TRUE(SendFinalAnswer());
1331 EXPECT_EQ(1U, GetTransport1()->channels().size());
1332 EXPECT_EQ(1U, GetTransport2()->channels().size());
1333 EXPECT_TRUE(channel1_->secure());
1334 EXPECT_TRUE(channel2_->secure());
1335 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1336 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1337 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1338 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1339 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1340 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1341 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1342 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1343 }
1344
1345 // Test that we properly send RTP without SRTP from a thread.
1346 void SendRtpToRtpOnThread() {
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001347 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1348 CreateChannels(RTCP, RTCP);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 EXPECT_TRUE(SendInitiate());
1350 EXPECT_TRUE(SendAccept());
1351 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1352 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
buildbot@webrtc.org6bfd6192014-05-15 16:15:59 +00001353 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1354 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001355 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1356 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1357 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1358 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1359 EXPECT_TRUE(CheckNoRtp1());
1360 EXPECT_TRUE(CheckNoRtp2());
1361 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1362 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1363 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1364 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1365 EXPECT_TRUE(CheckNoRtcp1());
1366 EXPECT_TRUE(CheckNoRtcp2());
1367 }
1368
1369 // Test that we properly send SRTP with RTCP from a thread.
1370 void SendSrtpToSrtpOnThread() {
1371 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1372 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1373 EXPECT_TRUE(SendInitiate());
1374 EXPECT_TRUE(SendAccept());
1375 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1376 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1377 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1378 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1379 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1380 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1381 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1382 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1383 EXPECT_TRUE(CheckNoRtp1());
1384 EXPECT_TRUE(CheckNoRtp2());
1385 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1386 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1387 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1388 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1389 EXPECT_TRUE(CheckNoRtcp1());
1390 EXPECT_TRUE(CheckNoRtcp2());
1391 }
1392
1393 // Test that the mediachannel retains its sending state after the transport
1394 // becomes non-writable.
1395 void SendWithWritabilityLoss() {
1396 CreateChannels(0, 0);
1397 EXPECT_TRUE(SendInitiate());
1398 EXPECT_TRUE(SendAccept());
1399 EXPECT_EQ(1U, GetTransport1()->channels().size());
1400 EXPECT_EQ(1U, GetTransport2()->channels().size());
1401 EXPECT_TRUE(SendRtp1());
1402 EXPECT_TRUE(SendRtp2());
1403 EXPECT_TRUE(CheckRtp1());
1404 EXPECT_TRUE(CheckRtp2());
1405 EXPECT_TRUE(CheckNoRtp1());
1406 EXPECT_TRUE(CheckNoRtp2());
1407
wu@webrtc.org97077a32013-10-25 21:18:33 +00001408 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 EXPECT_FALSE(SendRtp1());
1411 EXPECT_TRUE(SendRtp2());
1412 EXPECT_TRUE(CheckRtp1());
1413 EXPECT_TRUE(CheckNoRtp2());
1414
1415 // Regain writability
1416 GetTransport1()->SetWritable(true);
1417 EXPECT_TRUE(media_channel1_->sending());
1418 EXPECT_TRUE(SendRtp1());
1419 EXPECT_TRUE(SendRtp2());
1420 EXPECT_TRUE(CheckRtp1());
1421 EXPECT_TRUE(CheckRtp2());
1422 EXPECT_TRUE(CheckNoRtp1());
1423 EXPECT_TRUE(CheckNoRtp2());
1424
1425 // Lose writability completely
1426 GetTransport1()->SetDestination(NULL);
1427 EXPECT_TRUE(media_channel1_->sending());
1428
wu@webrtc.org97077a32013-10-25 21:18:33 +00001429 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 EXPECT_FALSE(SendRtp1());
1431 EXPECT_TRUE(SendRtp2());
1432 EXPECT_TRUE(CheckRtp1());
1433 EXPECT_TRUE(CheckNoRtp2());
1434
1435 // Gain writability back
1436 GetTransport1()->SetDestination(GetTransport2());
1437 EXPECT_TRUE(media_channel1_->sending());
1438 EXPECT_TRUE(SendRtp1());
1439 EXPECT_TRUE(SendRtp2());
1440 EXPECT_TRUE(CheckRtp1());
1441 EXPECT_TRUE(CheckRtp2());
1442 EXPECT_TRUE(CheckNoRtp1());
1443 EXPECT_TRUE(CheckNoRtp2());
1444 }
1445
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001446 void SendBundleToBundle(
1447 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1448 ASSERT_EQ(2, len);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449 int sequence_number1_1 = 0, sequence_number2_2 = 0;
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001450 // Only pl_type1 was added to the bundle filter for both |channel1_|
1451 // and |channel2_|.
1452 int pl_type1 = pl_types[0];
1453 int pl_type2 = pl_types[1];
1454 int flags = SSRC_MUX | RTCP;
1455 if (secure) flags |= SECURE;
1456 uint32 expected_channels = 2U;
1457 if (rtcp_mux) {
1458 flags |= RTCP_MUX;
1459 expected_channels = 1U;
1460 }
1461 CreateChannels(flags, flags);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 EXPECT_TRUE(SendInitiate());
1463 EXPECT_EQ(2U, GetTransport1()->channels().size());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001464 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 EXPECT_TRUE(SendAccept());
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001466 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1467 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1468 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1469 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1470 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1471 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1472 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1473 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1474 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1475 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1476 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1477 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1478
1479 // Both channels can receive pl_type1 only.
1480 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1481 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1482 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1483 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1484 EXPECT_TRUE(CheckNoRtp1());
1485 EXPECT_TRUE(CheckNoRtp2());
1486
1487 // RTCP test
1488 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1489 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1490 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1491 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1492
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1494 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1496 EXPECT_TRUE(CheckNoRtcp1());
1497 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1498 EXPECT_TRUE(CheckNoRtcp2());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001500 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1501 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1504 }
1505
1506 // Test that the media monitor can be run and gives timely callbacks.
1507 void TestMediaMonitor() {
1508 static const int kTimeout = 500;
1509 CreateChannels(0, 0);
1510 EXPECT_TRUE(SendInitiate());
1511 EXPECT_TRUE(SendAccept());
1512 channel1_->StartMediaMonitor(100);
1513 channel2_->StartMediaMonitor(100);
1514 // Ensure we get callbacks and stop.
1515 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1516 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1517 channel1_->StopMediaMonitor();
1518 channel2_->StopMediaMonitor();
1519 // Ensure a restart of a stopped monitor works.
1520 channel1_->StartMediaMonitor(100);
1521 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1522 channel1_->StopMediaMonitor();
1523 // Ensure stopping a stopped monitor is OK.
1524 channel1_->StopMediaMonitor();
1525 }
1526
1527 void TestMediaSinks() {
1528 CreateChannels(0, 0);
1529 EXPECT_TRUE(SendInitiate());
1530 EXPECT_TRUE(SendAccept());
1531 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1532 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1533 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1534 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1535
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001536 rtc::Pathname path;
1537 EXPECT_TRUE(rtc::Filesystem::GetTemporaryFolder(path, true, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 path.SetFilename("sink-test.rtpdump");
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001539 rtc::scoped_ptr<cricket::RtpDumpSink> sink(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 new cricket::RtpDumpSink(Open(path.pathname())));
1541 sink->set_packet_filter(cricket::PF_ALL);
1542 EXPECT_TRUE(sink->Enable(true));
1543 channel1_->RegisterSendSink(
1544 sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
1545 EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1546 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1547 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1548 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1549
1550 // The first packet is recorded with header + data.
1551 EXPECT_TRUE(SendRtp1());
1552 // The second packet is recorded with header only.
1553 sink->set_packet_filter(cricket::PF_RTPHEADER);
1554 EXPECT_TRUE(SendRtp1());
1555 // The third packet is not recorded since sink is disabled.
1556 EXPECT_TRUE(sink->Enable(false));
1557 EXPECT_TRUE(SendRtp1());
1558 // The fourth packet is not recorded since sink is unregistered.
1559 EXPECT_TRUE(sink->Enable(true));
1560 channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
1561 EXPECT_TRUE(SendRtp1());
1562 sink.reset(); // This will close the file.
1563
1564 // Read the recorded file and verify two packets.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001565 rtc::scoped_ptr<rtc::StreamInterface> stream(
1566 rtc::Filesystem::OpenFile(path, "rb"));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567
1568 cricket::RtpDumpReader reader(stream.get());
1569 cricket::RtpDumpPacket packet;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001570 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
1572 packet.data.size());
1573 EXPECT_EQ(rtp_packet_, read_packet);
1574
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001575 EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 size_t len = 0;
1577 packet.GetRtpHeaderLen(&len);
1578 EXPECT_EQ(len, packet.data.size());
1579 EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
1580
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001581 EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582
1583 // Delete the file for media recording.
1584 stream.reset();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001585 EXPECT_TRUE(rtc::Filesystem::DeleteFile(path));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 }
1587
1588 void TestSetContentFailure() {
1589 CreateChannels(0, 0);
1590 typename T::Content content;
1591 cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1592 cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1593
1594 // Set up the session description.
1595 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1596 sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1597 new cricket::AudioContentDescription());
1598 sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1599 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001600 session1_.set_local_description(sdesc_loc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1602 new cricket::AudioContentDescription());
1603 sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1604 new cricket::VideoContentDescription());
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001605 session1_.set_remote_description(sdesc_rem);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606
1607 // Test failures in SetLocalContent.
1608 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001609 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1611 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1612 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001613 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
1615 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1616
1617 // Test failures in SetRemoteContent.
1618 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001619 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1621 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1622 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001623 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
1625 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1626 }
1627
1628 void TestSendTwoOffers() {
1629 CreateChannels(0, 0);
1630
1631 // Set up the initial session description.
1632 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001633 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001635 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1637 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1638 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1639
1640 // Update the local description and set the state again.
1641 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001642 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643
1644 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1645 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1646 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1647 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1648 }
1649
1650 void TestReceiveTwoOffers() {
1651 CreateChannels(0, 0);
1652
1653 // Set up the initial session description.
1654 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001655 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001657 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1659 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1660 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1661
1662 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001663 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001664 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1665 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1666 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1667 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1668 }
1669
1670 void TestSendPrAnswer() {
1671 CreateChannels(0, 0);
1672
1673 // Set up the initial session description.
1674 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001675 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001677 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1679 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1680 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1681
1682 // Send PRANSWER
1683 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001684 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685
1686 session1_.SetState(cricket::Session::STATE_SENTPRACCEPT);
1687 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1688 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1689 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1690
1691 // Send ACCEPT
1692 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001693 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694
1695 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
1696 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1697 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1698 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1699 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1700 }
1701
1702 void TestReceivePrAnswer() {
1703 CreateChannels(0, 0);
1704
1705 // Set up the initial session description.
1706 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001707 session1_.set_local_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001709 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1711 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1712 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1713
1714 // Receive PRANSWER
1715 sdesc = CreateSessionDescriptionWithStream(2);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001716 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001717
1718 session1_.SetState(cricket::Session::STATE_RECEIVEDPRACCEPT);
1719 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1720 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1721 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1722
1723 // Receive ACCEPT
1724 sdesc = CreateSessionDescriptionWithStream(3);
tommi@webrtc.orgb5348c62014-07-14 20:11:49 +00001725 session1_.set_remote_description(sdesc);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726
1727 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
1728 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1729 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1730 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1731 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1732 }
1733
1734 void TestFlushRtcp() {
1735 bool send_rtcp1;
1736
1737 CreateChannels(RTCP, RTCP);
1738 EXPECT_TRUE(SendInitiate());
1739 EXPECT_TRUE(SendAccept());
1740 EXPECT_EQ(2U, GetTransport1()->channels().size());
1741 EXPECT_EQ(2U, GetTransport2()->channels().size());
1742
1743 // Send RTCP1 from a different thread.
1744 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1745 EXPECT_TRUE(send_rtcp1);
1746 // The sending message is only posted. channel2_ should be empty.
1747 EXPECT_TRUE(CheckNoRtcp2());
1748
1749 // When channel1_ is deleted, the RTCP packet should be sent out to
1750 // channel2_.
1751 channel1_.reset();
1752 EXPECT_TRUE(CheckRtcp2());
1753 }
1754
1755 void TestChangeStateError() {
1756 CreateChannels(RTCP, RTCP);
1757 EXPECT_TRUE(SendInitiate());
1758 media_channel2_->set_fail_set_send(true);
1759 EXPECT_TRUE(channel2_->Enable(true));
1760 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1761 error_);
1762 }
1763
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001764 void TestSrtpError(int pl_type) {
1765 // For Audio, only pl_type 0 is added to the bundle filter.
1766 // For Video, only pl_type 97 is added to the bundle filter.
1767 // So we need to pass in pl_type so that the packet can pass through
1768 // the bundle filter before it can be processed by the srtp filter.
1769 // The packet is not a valid srtp packet because it is too short.
pbos@webrtc.org910473b2014-06-06 15:44:00 +00001770 unsigned const char kBadPacket[] = {0x84,
1771 static_cast<unsigned char>(pl_type),
1772 0x00,
1773 0x01,
1774 0x00,
1775 0x00,
1776 0x00,
1777 0x00,
1778 0x00,
1779 0x00,
1780 0x00,
1781 0x01};
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1783 EXPECT_FALSE(channel1_->secure());
1784 EXPECT_FALSE(channel2_->secure());
1785 EXPECT_TRUE(SendInitiate());
1786 EXPECT_TRUE(SendAccept());
1787 EXPECT_TRUE(channel1_->secure());
1788 EXPECT_TRUE(channel2_->secure());
1789 channel2_->set_srtp_signal_silent_time(200);
1790
1791 // Testing failures in sending packets.
1792 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1793 // The first failure will trigger an error.
1794 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1795 error_ = T::MediaChannel::ERROR_NONE;
1796 // The next 1 sec failures will not trigger an error.
1797 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1798 // Wait for a while to ensure no message comes in.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001799 rtc::Thread::Current()->ProcessMessages(210);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1801 // The error will be triggered again.
1802 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1803 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1804
1805 // Testing failures in receiving packets.
1806 error_ = T::MediaChannel::ERROR_NONE;
1807 cricket::TransportChannel* transport_channel =
1808 channel2_->transport_channel();
1809 transport_channel->SignalReadPacket(
1810 transport_channel, reinterpret_cast<const char*>(kBadPacket),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001811 sizeof(kBadPacket), rtc::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001812 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 }
1814
1815 void TestOnReadyToSend() {
1816 CreateChannels(RTCP, RTCP);
1817 TransportChannel* rtp = channel1_->transport_channel();
1818 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1819 EXPECT_FALSE(media_channel1_->ready_to_send());
1820 rtp->SignalReadyToSend(rtp);
1821 EXPECT_FALSE(media_channel1_->ready_to_send());
1822 rtcp->SignalReadyToSend(rtcp);
1823 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1824 // channel are ready to send.
1825 EXPECT_TRUE(media_channel1_->ready_to_send());
1826
1827 // rtp channel becomes not ready to send will be propagated to mediachannel
1828 channel1_->SetReadyToSend(rtp, false);
1829 EXPECT_FALSE(media_channel1_->ready_to_send());
1830 channel1_->SetReadyToSend(rtp, true);
1831 EXPECT_TRUE(media_channel1_->ready_to_send());
1832
1833 // rtcp channel becomes not ready to send will be propagated to mediachannel
1834 channel1_->SetReadyToSend(rtcp, false);
1835 EXPECT_FALSE(media_channel1_->ready_to_send());
1836 channel1_->SetReadyToSend(rtcp, true);
1837 EXPECT_TRUE(media_channel1_->ready_to_send());
1838 }
1839
1840 void TestOnReadyToSendWithRtcpMux() {
1841 CreateChannels(RTCP, RTCP);
1842 typename T::Content content;
1843 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1844 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1845 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001846 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1847 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1849 TransportChannel* rtp = channel1_->transport_channel();
1850 EXPECT_FALSE(media_channel1_->ready_to_send());
1851 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1852 // should trigger the MediaChannel's OnReadyToSend.
1853 rtp->SignalReadyToSend(rtp);
1854 EXPECT_TRUE(media_channel1_->ready_to_send());
1855 channel1_->SetReadyToSend(rtp, false);
1856 EXPECT_FALSE(media_channel1_->ready_to_send());
1857 }
1858
1859 protected:
1860 cricket::FakeSession session1_;
1861 cricket::FakeSession session2_;
1862 cricket::FakeMediaEngine media_engine_;
1863 // The media channels are owned by the voice channel objects below.
1864 typename T::MediaChannel* media_channel1_;
1865 typename T::MediaChannel* media_channel2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001866 rtc::scoped_ptr<typename T::Channel> channel1_;
1867 rtc::scoped_ptr<typename T::Channel> channel2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 typename T::Content local_media_content1_;
1869 typename T::Content local_media_content2_;
1870 typename T::Content remote_media_content1_;
1871 typename T::Content remote_media_content2_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001872 rtc::scoped_ptr<rtc::SSLIdentity> identity1_;
1873 rtc::scoped_ptr<rtc::SSLIdentity> identity2_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 // The RTP and RTCP packets to send in the tests.
1875 std::string rtp_packet_;
1876 std::string rtcp_packet_;
1877 int media_info_callbacks1_;
1878 int media_info_callbacks2_;
1879 bool mute_callback_recved_;
1880 bool mute_callback_value_;
1881
1882 uint32 ssrc_;
1883 typename T::MediaChannel::Error error_;
1884};
1885
1886
1887template<>
1888void ChannelTest<VoiceTraits>::CreateContent(
1889 int flags,
1890 const cricket::AudioCodec& audio_codec,
1891 const cricket::VideoCodec& video_codec,
1892 cricket::AudioContentDescription* audio) {
1893 audio->AddCodec(audio_codec);
1894 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1895 if (flags & SECURE) {
1896 audio->AddCrypto(cricket::CryptoParams(
1897 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001898 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 }
1900}
1901
1902template<>
1903void ChannelTest<VoiceTraits>::CopyContent(
1904 const cricket::AudioContentDescription& source,
1905 cricket::AudioContentDescription* audio) {
1906 *audio = source;
1907}
1908
1909template<>
1910bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1911 const cricket::AudioCodec& c2) {
1912 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1913 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1914}
1915
1916template<>
1917void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1918 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1919 audio->AddLegacyStream(ssrc);
1920}
1921
1922class VoiceChannelTest
1923 : public ChannelTest<VoiceTraits> {
1924 public:
1925 typedef ChannelTest<VoiceTraits>
1926 Base;
1927 VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1928 kRtcpReport, sizeof(kRtcpReport)) {
1929 }
1930
1931 void TestSetChannelOptions() {
1932 CreateChannels(0, 0);
1933
1934 cricket::AudioOptions options1;
1935 options1.echo_cancellation.Set(false);
1936 cricket::AudioOptions options2;
1937 options2.echo_cancellation.Set(true);
1938
1939 channel1_->SetChannelOptions(options1);
1940 channel2_->SetChannelOptions(options1);
1941 cricket::AudioOptions actual_options;
1942 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1943 EXPECT_EQ(options1, actual_options);
1944 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1945 EXPECT_EQ(options1, actual_options);
1946
1947 channel1_->SetChannelOptions(options2);
1948 channel2_->SetChannelOptions(options2);
1949 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1950 EXPECT_EQ(options2, actual_options);
1951 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1952 EXPECT_EQ(options2, actual_options);
1953 }
1954};
1955
1956// override to add NULL parameter
1957template<>
1958cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001959 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1961 bool rtcp) {
1962 cricket::VideoChannel* channel = new cricket::VideoChannel(
1963 thread, engine, ch, session, cricket::CN_VIDEO, rtcp, NULL);
1964 if (!channel->Init()) {
1965 delete channel;
1966 channel = NULL;
1967 }
1968 return channel;
1969}
1970
1971// override to add 0 parameter
1972template<>
1973bool ChannelTest<VideoTraits>::AddStream1(int id) {
1974 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1975}
1976
1977template<>
1978void ChannelTest<VideoTraits>::CreateContent(
1979 int flags,
1980 const cricket::AudioCodec& audio_codec,
1981 const cricket::VideoCodec& video_codec,
1982 cricket::VideoContentDescription* video) {
1983 video->AddCodec(video_codec);
1984 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1985 if (flags & SECURE) {
1986 video->AddCrypto(cricket::CryptoParams(
1987 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001988 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 }
1990}
1991
1992template<>
1993void ChannelTest<VideoTraits>::CopyContent(
1994 const cricket::VideoContentDescription& source,
1995 cricket::VideoContentDescription* video) {
1996 *video = source;
1997}
1998
1999template<>
2000bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
2001 const cricket::VideoCodec& c2) {
2002 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
2003 c1.framerate == c2.framerate;
2004}
2005
2006template<>
2007void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
2008 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
2009 video->AddLegacyStream(ssrc);
2010}
2011
2012class VideoChannelTest
2013 : public ChannelTest<VideoTraits> {
2014 public:
2015 typedef ChannelTest<VideoTraits>
2016 Base;
2017 VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
2018 kRtcpReport, sizeof(kRtcpReport)) {
2019 }
2020
2021 void TestSetChannelOptions() {
2022 CreateChannels(0, 0);
2023
2024 cricket::VideoOptions o1, o2;
2025 o1.video_noise_reduction.Set(true);
2026
2027 channel1_->SetChannelOptions(o1);
2028 channel2_->SetChannelOptions(o1);
2029 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2030 EXPECT_EQ(o1, o2);
2031 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2032 EXPECT_EQ(o1, o2);
2033
2034 o1.video_leaky_bucket.Set(true);
2035 channel1_->SetChannelOptions(o1);
2036 channel2_->SetChannelOptions(o1);
2037 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2038 EXPECT_EQ(o1, o2);
2039 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2040 EXPECT_EQ(o1, o2);
2041 }
2042};
2043
2044
2045// VoiceChannelTest
2046
2047TEST_F(VoiceChannelTest, TestInit) {
2048 Base::TestInit();
2049 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2050 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2051}
2052
2053TEST_F(VoiceChannelTest, TestSetContents) {
2054 Base::TestSetContents();
2055}
2056
2057TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2058 Base::TestSetContentsNullOffer();
2059}
2060
2061TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2062 Base::TestSetContentsRtcpMux();
2063}
2064
2065TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2066 Base::TestSetContentsRtcpMux();
2067}
2068
2069TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2070 Base::TestSetRemoteContentUpdate();
2071}
2072
2073TEST_F(VoiceChannelTest, TestStreams) {
2074 Base::TestStreams();
2075}
2076
2077TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2078 Base::TestUpdateStreamsInLocalContent();
2079}
2080
2081TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2082 Base::TestUpdateStreamsInRemoteContent();
2083}
2084
2085TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2086 Base::TestChangeStreamParamsInContent();
2087}
2088
2089TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2090 Base::TestPlayoutAndSendingStates();
2091}
2092
2093TEST_F(VoiceChannelTest, TestMuteStream) {
2094 Base::TestMuteStream();
2095}
2096
2097TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2098 Base::TestMediaContentDirection();
2099}
2100
2101TEST_F(VoiceChannelTest, TestCallSetup) {
2102 Base::TestCallSetup();
2103}
2104
2105TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2106 Base::TestCallTeardownRtcpMux();
2107}
2108
2109TEST_F(VoiceChannelTest, SendRtpToRtp) {
2110 Base::SendRtpToRtp();
2111}
2112
2113TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2114 Base::SendNoRtcpToNoRtcp();
2115}
2116
2117TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2118 Base::SendNoRtcpToRtcp();
2119}
2120
2121TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2122 Base::SendRtcpToNoRtcp();
2123}
2124
2125TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2126 Base::SendRtcpToRtcp();
2127}
2128
2129TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2130 Base::SendRtcpMuxToRtcp();
2131}
2132
2133TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2134 Base::SendRtcpMuxToRtcpMux();
2135}
2136
2137TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2138 Base::SendEarlyRtcpMuxToRtcp();
2139}
2140
2141TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2142 Base::SendEarlyRtcpMuxToRtcpMux();
2143}
2144
2145TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2146 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2147}
2148
2149TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2150 Base::SendSrtpToSrtp();
2151}
2152
2153TEST_F(VoiceChannelTest, SendSrtcpMux) {
2154 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2155}
2156
2157TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2158 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2159 Base::SendSrtpToSrtp(DTLS, 0);
2160}
2161
2162TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2163 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2164 Base::SendSrtpToSrtp(DTLS, DTLS);
2165}
2166
2167TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2168 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2169 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2170}
2171
2172TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2173 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2174}
2175
2176TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2177 Base::SendRtpToRtpOnThread();
2178}
2179
2180TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2181 Base::SendSrtpToSrtpOnThread();
2182}
2183
2184TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2185 Base::SendWithWritabilityLoss();
2186}
2187
2188TEST_F(VoiceChannelTest, TestMediaMonitor) {
2189 Base::TestMediaMonitor();
2190}
2191
2192// Test that MuteStream properly forwards to the media channel and does
2193// not signal.
2194TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
2195 CreateChannels(0, 0);
2196 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2197 EXPECT_FALSE(mute_callback_recved_);
2198 EXPECT_TRUE(channel1_->MuteStream(0, true));
2199 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2200 EXPECT_FALSE(mute_callback_recved_);
2201 EXPECT_TRUE(channel1_->MuteStream(0, false));
2202 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2203 EXPECT_FALSE(mute_callback_recved_);
2204}
2205
2206// Test that keyboard automute works correctly and signals upwards.
asapersson@webrtc.orgb533a822013-09-23 19:47:49 +00002207TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 CreateChannels(0, 0);
2209 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2210 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
2211
2212 cricket::VoiceMediaChannel::Error e =
2213 cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
2214
2215 // Typing doesn't mute automatically unless typing monitor has been installed
2216 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002217 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 EXPECT_EQ(e, error_);
2219 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2220 EXPECT_FALSE(mute_callback_recved_);
2221
2222 cricket::TypingMonitorOptions o = {0};
2223 o.mute_period = 1500;
2224 channel1_->StartTypingMonitor(o);
2225 media_channel1_->TriggerError(0, e);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002226 rtc::Thread::Current()->ProcessMessages(0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2228 EXPECT_TRUE(mute_callback_recved_);
2229}
2230
2231// Test that PressDTMF properly forwards to the media channel.
2232TEST_F(VoiceChannelTest, TestDtmf) {
2233 CreateChannels(0, 0);
2234 EXPECT_TRUE(SendInitiate());
2235 EXPECT_TRUE(SendAccept());
2236 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2237
2238 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2239 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2240
2241 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2242 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2243 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2244 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2245 0, 8, 160, cricket::DF_SEND));
2246}
2247
2248// Test that InsertDtmf properly forwards to the media channel.
2249TEST_F(VoiceChannelTest, TestInsertDtmf) {
2250 CreateChannels(0, 0);
2251 EXPECT_TRUE(SendInitiate());
2252 EXPECT_TRUE(SendAccept());
2253 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2254
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2256 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2257 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2258 cricket::DF_PLAY | cricket::DF_SEND));
2259
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002260 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002263 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002265 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2267}
2268
2269TEST_F(VoiceChannelTest, TestMediaSinks) {
2270 Base::TestMediaSinks();
2271}
2272
2273TEST_F(VoiceChannelTest, TestSetContentFailure) {
2274 Base::TestSetContentFailure();
2275}
2276
2277TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2278 Base::TestSendTwoOffers();
2279}
2280
2281TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2282 Base::TestReceiveTwoOffers();
2283}
2284
2285TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2286 Base::TestSendPrAnswer();
2287}
2288
2289TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2290 Base::TestReceivePrAnswer();
2291}
2292
2293TEST_F(VoiceChannelTest, TestFlushRtcp) {
2294 Base::TestFlushRtcp();
2295}
2296
2297TEST_F(VoiceChannelTest, TestChangeStateError) {
2298 Base::TestChangeStateError();
2299}
2300
2301TEST_F(VoiceChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002302 Base::TestSrtpError(kAudioPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303}
2304
2305TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2306 Base::TestOnReadyToSend();
2307}
2308
2309TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2310 Base::TestOnReadyToSendWithRtcpMux();
2311}
2312
2313// Test that we can play a ringback tone properly.
2314TEST_F(VoiceChannelTest, TestRingbackTone) {
2315 CreateChannels(RTCP, RTCP);
2316 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2317 EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
2318 EXPECT_TRUE(SendInitiate());
2319 EXPECT_TRUE(SendAccept());
2320 // Play ringback tone, no loop.
2321 EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
2322 EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
2323 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2324 EXPECT_FALSE(media_channel1_->ringback_tone_loop());
2325 // Stop the ringback tone.
2326 EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
2327 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2328 // Add a stream.
2329 EXPECT_TRUE(AddStream1(1));
2330 // Play ringback tone, looping, on the new stream.
2331 EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
2332 EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
2333 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2334 EXPECT_TRUE(media_channel1_->ringback_tone_loop());
2335 // Stop the ringback tone.
2336 EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
2337 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2338}
2339
2340// Test that we can scale the output volume properly for 1:1 calls.
2341TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2342 CreateChannels(RTCP, RTCP);
2343 EXPECT_TRUE(SendInitiate());
2344 EXPECT_TRUE(SendAccept());
2345 double left, right;
2346
2347 // Default is (1.0, 1.0).
2348 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2349 EXPECT_DOUBLE_EQ(1.0, left);
2350 EXPECT_DOUBLE_EQ(1.0, right);
2351 // invalid ssrc.
2352 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2353
2354 // Set scale to (1.5, 0.5).
2355 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2356 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2357 EXPECT_DOUBLE_EQ(1.5, left);
2358 EXPECT_DOUBLE_EQ(0.5, right);
2359
2360 // Set scale to (0, 0).
2361 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2362 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2363 EXPECT_DOUBLE_EQ(0.0, left);
2364 EXPECT_DOUBLE_EQ(0.0, right);
2365}
2366
2367// Test that we can scale the output volume properly for multiway calls.
2368TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2369 CreateChannels(RTCP, RTCP);
2370 EXPECT_TRUE(SendInitiate());
2371 EXPECT_TRUE(SendAccept());
2372 EXPECT_TRUE(AddStream1(1));
2373 EXPECT_TRUE(AddStream1(2));
2374
2375 double left, right;
2376 // Default is (1.0, 1.0).
2377 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2378 EXPECT_DOUBLE_EQ(1.0, left);
2379 EXPECT_DOUBLE_EQ(1.0, right);
2380 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2381 EXPECT_DOUBLE_EQ(1.0, left);
2382 EXPECT_DOUBLE_EQ(1.0, right);
2383 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2384 EXPECT_DOUBLE_EQ(1.0, left);
2385 EXPECT_DOUBLE_EQ(1.0, right);
2386 // invalid ssrc.
2387 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2388
2389 // Set scale to (1.5, 0.5) for ssrc = 1.
2390 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2391 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2392 EXPECT_DOUBLE_EQ(1.5, left);
2393 EXPECT_DOUBLE_EQ(0.5, right);
2394 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2395 EXPECT_DOUBLE_EQ(1.0, left);
2396 EXPECT_DOUBLE_EQ(1.0, right);
2397 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2398 EXPECT_DOUBLE_EQ(1.0, left);
2399 EXPECT_DOUBLE_EQ(1.0, right);
2400
2401 // Set scale to (0, 0) for all ssrcs.
2402 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2403 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2404 EXPECT_DOUBLE_EQ(0.0, left);
2405 EXPECT_DOUBLE_EQ(0.0, right);
2406 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2407 EXPECT_DOUBLE_EQ(0.0, left);
2408 EXPECT_DOUBLE_EQ(0.0, right);
2409 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2410 EXPECT_DOUBLE_EQ(0.0, left);
2411 EXPECT_DOUBLE_EQ(0.0, right);
2412}
2413
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002414TEST_F(VoiceChannelTest, SendBundleToBundle) {
2415 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416}
2417
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002418TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2419 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2420}
2421
2422TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2423 Base::SendBundleToBundle(
2424 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2425}
2426
2427TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2428 Base::SendBundleToBundle(
2429 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430}
2431
2432TEST_F(VoiceChannelTest, TestSetChannelOptions) {
2433 TestSetChannelOptions();
2434}
2435
2436// VideoChannelTest
2437TEST_F(VideoChannelTest, TestInit) {
2438 Base::TestInit();
2439}
2440
2441TEST_F(VideoChannelTest, TestSetContents) {
2442 Base::TestSetContents();
2443}
2444
2445TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2446 Base::TestSetContentsNullOffer();
2447}
2448
2449TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2450 Base::TestSetContentsRtcpMux();
2451}
2452
2453TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2454 Base::TestSetContentsRtcpMux();
2455}
2456
2457TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
2458 Base::TestSetContentsVideoOptions();
2459}
2460
2461TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2462 Base::TestSetRemoteContentUpdate();
2463}
2464
2465TEST_F(VideoChannelTest, TestStreams) {
2466 Base::TestStreams();
2467}
2468
2469TEST_F(VideoChannelTest, TestScreencastEvents) {
2470 const int kTimeoutMs = 500;
2471 TestInit();
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +00002472 FakeScreenCaptureFactory* screencapture_factory =
2473 new FakeScreenCaptureFactory();
2474 channel1_->SetScreenCaptureFactory(screencapture_factory);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 cricket::ScreencastEventCatcher catcher;
2476 channel1_->SignalScreencastWindowEvent.connect(
2477 &catcher,
2478 &cricket::ScreencastEventCatcher::OnEvent);
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +00002479 EXPECT_TRUE(channel1_->AddScreencast(0, ScreencastId(WindowId(0))) != NULL);
2480 ASSERT_TRUE(screencapture_factory->window_capturer() != NULL);
2481 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screencapture_factory->capture_state(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 kTimeoutMs);
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +00002483 screencapture_factory->window_capturer()->SignalStateChange(
2484 screencapture_factory->window_capturer(), cricket::CS_PAUSED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002485 EXPECT_EQ_WAIT(rtc::WE_MINIMIZE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +00002486 screencapture_factory->window_capturer()->SignalStateChange(
2487 screencapture_factory->window_capturer(), cricket::CS_RUNNING);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002488 EXPECT_EQ_WAIT(rtc::WE_RESTORE, catcher.event(), kTimeoutMs);
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +00002489 screencapture_factory->window_capturer()->SignalStateChange(
2490 screencapture_factory->window_capturer(), cricket::CS_STOPPED);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002491 EXPECT_EQ_WAIT(rtc::WE_CLOSE, catcher.event(), kTimeoutMs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 EXPECT_TRUE(channel1_->RemoveScreencast(0));
buildbot@webrtc.org5b1ebac2014-08-07 17:18:00 +00002493 ASSERT_TRUE(screencapture_factory->window_capturer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494}
2495
2496TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2497 Base::TestUpdateStreamsInLocalContent();
2498}
2499
2500TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2501 Base::TestUpdateStreamsInRemoteContent();
2502}
2503
2504TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2505 Base::TestChangeStreamParamsInContent();
2506}
2507
2508TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2509 Base::TestPlayoutAndSendingStates();
2510}
2511
2512TEST_F(VideoChannelTest, TestMuteStream) {
2513 Base::TestMuteStream();
2514}
2515
2516TEST_F(VideoChannelTest, TestMediaContentDirection) {
2517 Base::TestMediaContentDirection();
2518}
2519
2520TEST_F(VideoChannelTest, TestCallSetup) {
2521 Base::TestCallSetup();
2522}
2523
2524TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2525 Base::TestCallTeardownRtcpMux();
2526}
2527
2528TEST_F(VideoChannelTest, SendRtpToRtp) {
2529 Base::SendRtpToRtp();
2530}
2531
2532TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2533 Base::SendNoRtcpToNoRtcp();
2534}
2535
2536TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2537 Base::SendNoRtcpToRtcp();
2538}
2539
2540TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2541 Base::SendRtcpToNoRtcp();
2542}
2543
2544TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2545 Base::SendRtcpToRtcp();
2546}
2547
2548TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2549 Base::SendRtcpMuxToRtcp();
2550}
2551
2552TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2553 Base::SendRtcpMuxToRtcpMux();
2554}
2555
2556TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2557 Base::SendEarlyRtcpMuxToRtcp();
2558}
2559
2560TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2561 Base::SendEarlyRtcpMuxToRtcpMux();
2562}
2563
2564TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2565 Base::SendSrtpToSrtp();
2566}
2567
2568TEST_F(VideoChannelTest, SendSrtpToRtp) {
2569 Base::SendSrtpToSrtp();
2570}
2571
2572TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2573 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2574 Base::SendSrtpToSrtp(DTLS, 0);
2575}
2576
2577TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2578 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2579 Base::SendSrtpToSrtp(DTLS, DTLS);
2580}
2581
2582TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2583 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2584 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2585}
2586
2587TEST_F(VideoChannelTest, SendSrtcpMux) {
2588 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2589}
2590
2591TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2592 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2593}
2594
2595TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2596 Base::SendRtpToRtpOnThread();
2597}
2598
2599TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2600 Base::SendSrtpToSrtpOnThread();
2601}
2602
2603TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2604 Base::SendWithWritabilityLoss();
2605}
2606
2607TEST_F(VideoChannelTest, TestMediaMonitor) {
2608 Base::TestMediaMonitor();
2609}
2610
2611TEST_F(VideoChannelTest, TestMediaSinks) {
2612 Base::TestMediaSinks();
2613}
2614
2615TEST_F(VideoChannelTest, TestSetContentFailure) {
2616 Base::TestSetContentFailure();
2617}
2618
2619TEST_F(VideoChannelTest, TestSendTwoOffers) {
2620 Base::TestSendTwoOffers();
2621}
2622
2623TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2624 Base::TestReceiveTwoOffers();
2625}
2626
2627TEST_F(VideoChannelTest, TestSendPrAnswer) {
2628 Base::TestSendPrAnswer();
2629}
2630
2631TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2632 Base::TestReceivePrAnswer();
2633}
2634
2635TEST_F(VideoChannelTest, TestFlushRtcp) {
2636 Base::TestFlushRtcp();
2637}
2638
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002639TEST_F(VideoChannelTest, SendBundleToBundle) {
2640 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641}
2642
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002643TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2644 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2645}
2646
2647TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2648 Base::SendBundleToBundle(
2649 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2650}
2651
2652TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2653 Base::SendBundleToBundle(
2654 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002655}
2656
2657// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2658
2659TEST_F(VideoChannelTest, TestSrtpError) {
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00002660 Base::TestSrtpError(kVideoPts[0]);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661}
2662
2663TEST_F(VideoChannelTest, TestOnReadyToSend) {
2664 Base::TestOnReadyToSend();
2665}
2666
2667TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2668 Base::TestOnReadyToSendWithRtcpMux();
2669}
2670
2671TEST_F(VideoChannelTest, TestApplyViewRequest) {
2672 CreateChannels(0, 0);
2673 cricket::StreamParams stream2;
2674 stream2.id = "stream2";
2675 stream2.ssrcs.push_back(2222);
2676 local_media_content1_.AddStream(stream2);
2677
2678 EXPECT_TRUE(SendInitiate());
2679 EXPECT_TRUE(SendAccept());
2680
2681 cricket::VideoFormat send_format;
2682 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2683 EXPECT_EQ(640, send_format.width);
2684 EXPECT_EQ(400, send_format.height);
2685 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2686
2687 cricket::ViewRequest request;
2688 // stream1: 320x200x15; stream2: 0x0x0
2689 request.static_video_views.push_back(cricket::StaticVideoView(
2690 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2691 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2692 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2693 EXPECT_EQ(320, send_format.width);
2694 EXPECT_EQ(200, send_format.height);
2695 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2696 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2697 EXPECT_EQ(0, send_format.width);
2698 EXPECT_EQ(0, send_format.height);
2699
2700 // stream1: 160x100x8; stream2: 0x0x0
2701 request.static_video_views.clear();
2702 request.static_video_views.push_back(cricket::StaticVideoView(
2703 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2704 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2705 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2706 EXPECT_EQ(160, send_format.width);
2707 EXPECT_EQ(100, send_format.height);
2708 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2709
2710 // stream1: 0x0x0; stream2: 640x400x30
2711 request.static_video_views.clear();
2712 request.static_video_views.push_back(cricket::StaticVideoView(
2713 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2714 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2715 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2716 EXPECT_EQ(0, send_format.width);
2717 EXPECT_EQ(0, send_format.height);
2718 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2719 EXPECT_EQ(640, send_format.width);
2720 EXPECT_EQ(400, send_format.height);
2721 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2722
2723 // stream1: 0x0x0; stream2: 0x0x0
2724 request.static_video_views.clear();
2725 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2726 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2727 EXPECT_EQ(0, send_format.width);
2728 EXPECT_EQ(0, send_format.height);
2729}
2730
2731TEST_F(VideoChannelTest, TestSetChannelOptions) {
2732 TestSetChannelOptions();
2733}
2734
2735
2736// DataChannelTest
2737
2738class DataChannelTest
2739 : public ChannelTest<DataTraits> {
2740 public:
2741 typedef ChannelTest<DataTraits>
2742 Base;
2743 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2744 kRtcpReport, sizeof(kRtcpReport)) {
2745 }
2746};
2747
2748// Override to avoid engine channel parameter.
2749template<>
2750cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002751 rtc::Thread* thread, cricket::MediaEngineInterface* engine,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752 cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2753 bool rtcp) {
2754 cricket::DataChannel* channel = new cricket::DataChannel(
2755 thread, ch, session, cricket::CN_DATA, rtcp);
2756 if (!channel->Init()) {
2757 delete channel;
2758 channel = NULL;
2759 }
2760 return channel;
2761}
2762
2763template<>
2764void ChannelTest<DataTraits>::CreateContent(
2765 int flags,
2766 const cricket::AudioCodec& audio_codec,
2767 const cricket::VideoCodec& video_codec,
2768 cricket::DataContentDescription* data) {
2769 data->AddCodec(kGoogleDataCodec);
2770 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2771 if (flags & SECURE) {
2772 data->AddCrypto(cricket::CryptoParams(
2773 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002774 "inline:" + rtc::CreateRandomString(40), ""));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775 }
2776}
2777
2778template<>
2779void ChannelTest<DataTraits>::CopyContent(
2780 const cricket::DataContentDescription& source,
2781 cricket::DataContentDescription* data) {
2782 *data = source;
2783}
2784
2785template<>
2786bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2787 const cricket::DataCodec& c2) {
2788 return c1.name == c2.name;
2789}
2790
2791template<>
2792void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2793 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2794 data->AddLegacyStream(ssrc);
2795}
2796
2797TEST_F(DataChannelTest, TestInit) {
2798 Base::TestInit();
2799 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2800}
2801
2802TEST_F(DataChannelTest, TestSetContents) {
2803 Base::TestSetContents();
2804}
2805
2806TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2807 Base::TestSetContentsNullOffer();
2808}
2809
2810TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2811 Base::TestSetContentsRtcpMux();
2812}
2813
2814TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2815 Base::TestSetRemoteContentUpdate();
2816}
2817
2818TEST_F(DataChannelTest, TestStreams) {
2819 Base::TestStreams();
2820}
2821
2822TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2823 Base::TestUpdateStreamsInLocalContent();
2824}
2825
2826TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2827 Base::TestUpdateStreamsInRemoteContent();
2828}
2829
2830TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2831 Base::TestChangeStreamParamsInContent();
2832}
2833
2834TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2835 Base::TestPlayoutAndSendingStates();
2836}
2837
2838TEST_F(DataChannelTest, TestMediaContentDirection) {
2839 Base::TestMediaContentDirection();
2840}
2841
2842TEST_F(DataChannelTest, TestCallSetup) {
2843 Base::TestCallSetup();
2844}
2845
2846TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2847 Base::TestCallTeardownRtcpMux();
2848}
2849
2850TEST_F(DataChannelTest, TestOnReadyToSend) {
2851 Base::TestOnReadyToSend();
2852}
2853
2854TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2855 Base::TestOnReadyToSendWithRtcpMux();
2856}
2857
2858TEST_F(DataChannelTest, SendRtpToRtp) {
2859 Base::SendRtpToRtp();
2860}
2861
2862TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2863 Base::SendNoRtcpToNoRtcp();
2864}
2865
2866TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2867 Base::SendNoRtcpToRtcp();
2868}
2869
2870TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2871 Base::SendRtcpToNoRtcp();
2872}
2873
2874TEST_F(DataChannelTest, SendRtcpToRtcp) {
2875 Base::SendRtcpToRtcp();
2876}
2877
2878TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2879 Base::SendRtcpMuxToRtcp();
2880}
2881
2882TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2883 Base::SendRtcpMuxToRtcpMux();
2884}
2885
2886TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2887 Base::SendEarlyRtcpMuxToRtcp();
2888}
2889
2890TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2891 Base::SendEarlyRtcpMuxToRtcpMux();
2892}
2893
2894TEST_F(DataChannelTest, SendSrtpToSrtp) {
2895 Base::SendSrtpToSrtp();
2896}
2897
2898TEST_F(DataChannelTest, SendSrtpToRtp) {
2899 Base::SendSrtpToSrtp();
2900}
2901
2902TEST_F(DataChannelTest, SendSrtcpMux) {
2903 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2904}
2905
2906TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2907 Base::SendRtpToRtpOnThread();
2908}
2909
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2911 Base::SendSrtpToSrtpOnThread();
2912}
2913
2914TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2915 Base::SendWithWritabilityLoss();
2916}
2917
2918TEST_F(DataChannelTest, TestMediaMonitor) {
2919 Base::TestMediaMonitor();
2920}
2921
2922TEST_F(DataChannelTest, TestSendData) {
2923 CreateChannels(0, 0);
2924 EXPECT_TRUE(SendInitiate());
2925 EXPECT_TRUE(SendAccept());
2926
2927 cricket::SendDataParams params;
2928 params.ssrc = 42;
2929 unsigned char data[] = {
2930 'f', 'o', 'o'
2931 };
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002932 rtc::Buffer payload(data, 3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002933 cricket::SendDataResult result;
2934 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2935 EXPECT_EQ(params.ssrc,
2936 media_channel1_->last_sent_data_params().ssrc);
2937 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2938}
2939
2940// TODO(pthatcher): TestSetReceiver?