blob: 0a82bef412c5e0d908f5304fb17fc8cde9c1fa1b [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
26#include "talk/base/fileutils.h"
27#include "talk/base/gunit.h"
28#include "talk/base/helpers.h"
29#include "talk/base/logging.h"
30#include "talk/base/pathutils.h"
31#include "talk/base/signalthread.h"
32#include "talk/base/ssladapter.h"
33#include "talk/base/sslidentity.h"
34#include "talk/base/window.h"
35#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) \
50 if (!(talk_base::SSLStreamAdapter::feature())) { \
51 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;
63using talk_base::WindowId;
64
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;
74static const char kCName[] = "a@b.com";
75
76template<class ChannelT,
77 class MediaChannelT,
78 class ContentT,
79 class CodecT,
80 class MediaInfoT>
81class Traits {
82 public:
83 typedef ChannelT Channel;
84 typedef MediaChannelT MediaChannel;
85 typedef ContentT Content;
86 typedef CodecT Codec;
87 typedef MediaInfoT MediaInfo;
88};
89
90class FakeScreenCaptureFactory
91 : public cricket::VideoChannel::ScreenCapturerFactory,
92 public sigslot::has_slots<> {
93 public:
94 FakeScreenCaptureFactory()
95 : window_capturer_(NULL),
96 capture_state_(cricket::CS_STOPPED) {}
97
98 virtual cricket::VideoCapturer* CreateScreenCapturer(
99 const ScreencastId& window) {
100 if (window_capturer_ != NULL) {
101 // Class is only designed to handle one fake screencapturer.
102 ADD_FAILURE();
103 return NULL;
104 }
105 window_capturer_ = new cricket::FakeVideoCapturer;
106 window_capturer_->SignalDestroyed.connect(
107 this,
108 &FakeScreenCaptureFactory::OnWindowCapturerDestroyed);
109 window_capturer_->SignalStateChange.connect(
110 this,
111 &FakeScreenCaptureFactory::OnStateChange);
112 return window_capturer_;
113 }
114
115 cricket::FakeVideoCapturer* window_capturer() { return window_capturer_; }
116
117 cricket::CaptureState capture_state() { return capture_state_; }
118
119 private:
120 void OnWindowCapturerDestroyed(cricket::FakeVideoCapturer* capturer) {
121 if (capturer == window_capturer_) {
122 window_capturer_ = NULL;
123 }
124 }
125 void OnStateChange(cricket::VideoCapturer*, cricket::CaptureState state) {
126 capture_state_ = state;
127 }
128
129 cricket::FakeVideoCapturer* window_capturer_;
130 cricket::CaptureState capture_state_;
131};
132
133// Controls how long we wait for a session to send messages that we
134// expect, in milliseconds. We put it high to avoid flaky tests.
135static const int kEventTimeout = 5000;
136
137class VoiceTraits : public Traits<cricket::VoiceChannel,
138 cricket::FakeVoiceMediaChannel,
139 cricket::AudioContentDescription,
140 cricket::AudioCodec,
141 cricket::VoiceMediaInfo> {
142};
143
144class VideoTraits : public Traits<cricket::VideoChannel,
145 cricket::FakeVideoMediaChannel,
146 cricket::VideoContentDescription,
147 cricket::VideoCodec,
148 cricket::VideoMediaInfo> {
149};
150
151class DataTraits : public Traits<cricket::DataChannel,
152 cricket::FakeDataMediaChannel,
153 cricket::DataContentDescription,
154 cricket::DataCodec,
155 cricket::DataMediaInfo> {
156};
157
158
159talk_base::StreamInterface* Open(const std::string& path) {
160 return talk_base::Filesystem::OpenFile(
161 talk_base::Pathname(path), "wb");
162}
163
164// Base class for Voice/VideoChannel tests
165template<class T>
166class ChannelTest : public testing::Test, public sigslot::has_slots<> {
167 public:
168 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
169 DTLS = 0x10 };
170
171 ChannelTest(const uint8* rtp_data, int rtp_len,
172 const uint8* rtcp_data, int rtcp_len)
173 : session1_(true),
174 session2_(false),
175 media_channel1_(NULL),
176 media_channel2_(NULL),
177 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
178 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
179 media_info_callbacks1_(),
180 media_info_callbacks2_(),
181 mute_callback_recved_(false),
182 mute_callback_value_(false),
183 ssrc_(0),
184 error_(T::MediaChannel::ERROR_NONE) {
185 }
186
187 static void SetUpTestCase() {
188 talk_base::InitializeSSL();
189 }
190
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000191 static void TearDownTestCase() {
192 talk_base::CleanupSSL();
193 }
194
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 void CreateChannels(int flags1, int flags2) {
196 CreateChannels(new typename T::MediaChannel(NULL),
197 new typename T::MediaChannel(NULL),
198 flags1, flags2, talk_base::Thread::Current());
199 }
200 void CreateChannels(int flags) {
201 CreateChannels(new typename T::MediaChannel(NULL),
202 new typename T::MediaChannel(NULL),
203 flags, talk_base::Thread::Current());
204 }
205 void CreateChannels(int flags1, int flags2,
206 talk_base::Thread* thread) {
207 CreateChannels(new typename T::MediaChannel(NULL),
208 new typename T::MediaChannel(NULL),
209 flags1, flags2, thread);
210 }
211 void CreateChannels(int flags,
212 talk_base::Thread* thread) {
213 CreateChannels(new typename T::MediaChannel(NULL),
214 new typename T::MediaChannel(NULL),
215 flags, thread);
216 }
217 void CreateChannels(
218 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
219 int flags1, int flags2, talk_base::Thread* thread) {
220 media_channel1_ = ch1;
221 media_channel2_ = ch2;
222 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
223 (flags1 & RTCP) != 0));
224 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
225 (flags2 & RTCP) != 0));
226 channel1_->SignalMediaMonitor.connect(
227 this, &ChannelTest<T>::OnMediaMonitor);
228 channel2_->SignalMediaMonitor.connect(
229 this, &ChannelTest<T>::OnMediaMonitor);
230 channel1_->SignalMediaError.connect(
231 this, &ChannelTest<T>::OnMediaChannelError);
232 channel2_->SignalMediaError.connect(
233 this, &ChannelTest<T>::OnMediaChannelError);
234 channel1_->SignalAutoMuted.connect(
235 this, &ChannelTest<T>::OnMediaMuted);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000236 if ((flags1 & DTLS) && (flags2 & DTLS)) {
237 flags1 = (flags1 & ~SECURE);
238 flags2 = (flags2 & ~SECURE);
239 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 CreateContent(flags1, kPcmuCodec, kH264Codec,
241 &local_media_content1_);
242 CreateContent(flags2, kPcmuCodec, kH264Codec,
243 &local_media_content2_);
244 CopyContent(local_media_content1_, &remote_media_content1_);
245 CopyContent(local_media_content2_, &remote_media_content2_);
246
247 if (flags1 & DTLS) {
248 identity1_.reset(talk_base::SSLIdentity::Generate("session1"));
249 session1_.set_ssl_identity(identity1_.get());
250 }
251 if (flags2 & DTLS) {
252 identity2_.reset(talk_base::SSLIdentity::Generate("session2"));
253 session2_.set_ssl_identity(identity2_.get());
254 }
255
256 // Add stream information (SSRC) to the local content but not to the remote
257 // content. This means that we per default know the SSRC of what we send but
258 // not what we receive.
259 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
260 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
261
262 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
263 if (flags1 & SSRC_MUX) {
264 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
265 }
266 if (flags2 & SSRC_MUX) {
267 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
268 }
269 }
270
271 void CreateChannels(
272 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
273 int flags, talk_base::Thread* thread) {
274 media_channel1_ = ch1;
275 media_channel2_ = ch2;
276
277 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
278 (flags & RTCP) != 0));
279 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
280 (flags & RTCP) != 0));
281 channel1_->SignalMediaMonitor.connect(
282 this, &ChannelTest<T>::OnMediaMonitor);
283 channel2_->SignalMediaMonitor.connect(
284 this, &ChannelTest<T>::OnMediaMonitor);
285 channel2_->SignalMediaError.connect(
286 this, &ChannelTest<T>::OnMediaChannelError);
287 CreateContent(flags, kPcmuCodec, kH264Codec,
288 &local_media_content1_);
289 CreateContent(flags, kPcmuCodec, kH264Codec,
290 &local_media_content2_);
291 CopyContent(local_media_content1_, &remote_media_content1_);
292 CopyContent(local_media_content2_, &remote_media_content2_);
293 // Add stream information (SSRC) to the local content but not to the remote
294 // content. This means that we per default know the SSRC of what we send but
295 // not what we receive.
296 AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
297 AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
298
299 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
300 if (flags & SSRC_MUX) {
301 AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
302 AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
303 }
304 }
305
306 typename T::Channel* CreateChannel(talk_base::Thread* thread,
307 cricket::MediaEngineInterface* engine,
308 typename T::MediaChannel* ch,
309 cricket::BaseSession* session,
310 bool rtcp) {
311 typename T::Channel* channel = new typename T::Channel(
312 thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
313 if (!channel->Init()) {
314 delete channel;
315 channel = NULL;
316 }
317 return channel;
318 }
319
320 bool SendInitiate() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000321 bool result = channel1_->SetLocalContent(&local_media_content1_,
322 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 if (result) {
324 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000325 result = channel2_->SetRemoteContent(&remote_media_content1_,
326 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 if (result) {
328 session1_.Connect(&session2_);
329
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000330 result = channel2_->SetLocalContent(&local_media_content2_,
331 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 }
333 }
334 return result;
335 }
336
337 bool SendAccept() {
338 channel2_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000339 return channel1_->SetRemoteContent(&remote_media_content2_,
340 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 }
342
343 bool SendOffer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000344 bool result = channel1_->SetLocalContent(&local_media_content1_,
345 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 if (result) {
347 channel1_->Enable(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000348 result = channel2_->SetRemoteContent(&remote_media_content1_,
349 CA_OFFER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 }
351 return result;
352 }
353
354 bool SendProvisionalAnswer() {
355 bool result = channel2_->SetLocalContent(&local_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000356 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 if (result) {
358 channel2_->Enable(true);
359 result = channel1_->SetRemoteContent(&remote_media_content2_,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000360 CA_PRANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 session1_.Connect(&session2_);
362 }
363 return result;
364 }
365
366 bool SendFinalAnswer() {
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000367 bool result = channel2_->SetLocalContent(&local_media_content2_,
368 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 if (result)
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000370 result = channel1_->SetRemoteContent(&remote_media_content2_,
371 CA_ANSWER, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 return result;
373 }
374
375 bool SendTerminate() {
376 channel1_.reset();
377 channel2_.reset();
378 return true;
379 }
380
381 bool AddStream1(int id) {
382 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
383 }
384 bool RemoveStream1(int id) {
385 return channel1_->RemoveRecvStream(id);
386 }
387
388 cricket::FakeTransport* GetTransport1() {
389 return session1_.GetTransport(channel1_->content_name());
390 }
391 cricket::FakeTransport* GetTransport2() {
392 return session2_.GetTransport(channel2_->content_name());
393 }
394
395 bool SendRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000396 return media_channel1_->SendRtp(rtp_packet_.c_str(),
397 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000398 }
399 bool SendRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000400 return media_channel2_->SendRtp(rtp_packet_.c_str(),
401 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 }
403 bool SendRtcp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000404 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
405 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 }
407 bool SendRtcp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000408 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
409 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 }
411 // Methods to send custom data.
412 bool SendCustomRtp1(uint32 ssrc, int sequence_number) {
413 std::string data(CreateRtpData(ssrc, sequence_number));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000414 return media_channel1_->SendRtp(data.c_str(),
415 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 }
417 bool SendCustomRtp2(uint32 ssrc, int sequence_number) {
418 std::string data(CreateRtpData(ssrc, sequence_number));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000419 return media_channel2_->SendRtp(data.c_str(),
420 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 }
422 bool SendCustomRtcp1(uint32 ssrc) {
423 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000424 return media_channel1_->SendRtcp(data.c_str(),
425 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 }
427 bool SendCustomRtcp2(uint32 ssrc) {
428 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000429 return media_channel2_->SendRtcp(data.c_str(),
430 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000431 }
432 bool CheckRtp1() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000433 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
434 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435 }
436 bool CheckRtp2() {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000437 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
438 static_cast<int>(rtp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 }
440 bool CheckRtcp1() {
441 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000442 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000443 }
444 bool CheckRtcp2() {
445 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000446 static_cast<int>(rtcp_packet_.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 }
448 // Methods to check custom data.
449 bool CheckCustomRtp1(uint32 ssrc, int sequence_number) {
450 std::string data(CreateRtpData(ssrc, sequence_number));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000451 return media_channel1_->CheckRtp(data.c_str(),
452 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000453 }
454 bool CheckCustomRtp2(uint32 ssrc, int sequence_number) {
455 std::string data(CreateRtpData(ssrc, sequence_number));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000456 return media_channel2_->CheckRtp(data.c_str(),
457 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000458 }
459 bool CheckCustomRtcp1(uint32 ssrc) {
460 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000461 return media_channel1_->CheckRtcp(data.c_str(),
462 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 }
464 bool CheckCustomRtcp2(uint32 ssrc) {
465 std::string data(CreateRtcpData(ssrc));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000466 return media_channel2_->CheckRtcp(data.c_str(),
467 static_cast<int>(data.size()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 }
469 std::string CreateRtpData(uint32 ssrc, int sequence_number) {
470 std::string data(rtp_packet_);
471 // Set SSRC in the rtp packet copy.
472 talk_base::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
473 talk_base::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
474 return data;
475 }
476 std::string CreateRtcpData(uint32 ssrc) {
477 std::string data(rtcp_packet_);
478 // Set SSRC in the rtcp packet copy.
479 talk_base::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
480 return data;
481 }
482
483 bool CheckNoRtp1() {
484 return media_channel1_->CheckNoRtp();
485 }
486 bool CheckNoRtp2() {
487 return media_channel2_->CheckNoRtp();
488 }
489 bool CheckNoRtcp1() {
490 return media_channel1_->CheckNoRtcp();
491 }
492 bool CheckNoRtcp2() {
493 return media_channel2_->CheckNoRtcp();
494 }
495
496 void CreateContent(int flags,
497 const cricket::AudioCodec& audio_codec,
498 const cricket::VideoCodec& video_codec,
499 typename T::Content* content) {
500 // overridden in specialized classes
501 }
502 void CopyContent(const typename T::Content& source,
503 typename T::Content* content) {
504 // overridden in specialized classes
505 }
506
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507 // Creates a cricket::SessionDescription with one MediaContent and one stream.
508 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
509 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
510 typename T::Content content;
511 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
512 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
513 AddLegacyStreamInContent(ssrc, 0, &content);
514 sdesc->AddContent("DUMMY_CONTENT_NAME",
515 cricket::NS_JINGLE_RTP, content.Copy());
516 return sdesc;
517 }
518
519 class CallThread : public talk_base::SignalThread {
520 public:
521 typedef bool (ChannelTest<T>::*Method)();
522 CallThread(ChannelTest<T>* obj, Method method, bool* result)
523 : obj_(obj),
524 method_(method),
525 result_(result) {
526 *result = false;
527 }
528 virtual void DoWork() {
529 bool result = (*obj_.*method_)();
530 if (result_) {
531 *result_ = result;
532 }
533 }
534 private:
535 ChannelTest<T>* obj_;
536 Method method_;
537 bool* result_;
538 };
539 void CallOnThread(typename CallThread::Method method, bool* result) {
540 CallThread* thread = new CallThread(this, method, result);
541 thread->Start();
542 thread->Release();
543 }
544
545 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
546 bool* result) {
547 CallThread* thread = new CallThread(this, method, result);
548 thread->Start();
549 thread->Destroy(true);
550 }
551
552 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
553 return false; // overridden in specialized classes
554 }
555
556 void OnMediaMonitor(typename T::Channel* channel,
557 const typename T::MediaInfo& info) {
558 if (channel == channel1_.get()) {
559 media_info_callbacks1_++;
560 } else if (channel == channel2_.get()) {
561 media_info_callbacks2_++;
562 }
563 }
564
565 void OnMediaChannelError(typename T::Channel* channel,
566 uint32 ssrc,
567 typename T::MediaChannel::Error error) {
568 ssrc_ = ssrc;
569 error_ = error;
570 }
571
572 void OnMediaMuted(cricket::BaseChannel* channel, bool muted) {
573 mute_callback_recved_ = true;
574 mute_callback_value_ = muted;
575 }
576
577 void AddLegacyStreamInContent(uint32 ssrc, int flags,
578 typename T::Content* content) {
579 // Base implementation.
580 }
581
582 // Tests that can be used by derived classes.
583
584 // Basic sanity check.
585 void TestInit() {
586 CreateChannels(0, 0);
587 EXPECT_FALSE(channel1_->secure());
588 EXPECT_FALSE(media_channel1_->sending());
589 EXPECT_FALSE(media_channel1_->playout());
590 EXPECT_TRUE(media_channel1_->codecs().empty());
591 EXPECT_TRUE(media_channel1_->recv_streams().empty());
592 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
593 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
594 }
595
596 // Test that SetLocalContent and SetRemoteContent properly configure
597 // the codecs.
598 void TestSetContents() {
599 CreateChannels(0, 0);
600 typename T::Content content;
601 CreateContent(0, kPcmuCodec, kH264Codec, &content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000602 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000604 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605 ASSERT_EQ(1U, media_channel1_->codecs().size());
606 EXPECT_TRUE(CodecMatches(content.codecs()[0],
607 media_channel1_->codecs()[0]));
608 }
609
610 // Test that SetLocalContent and SetRemoteContent properly deals
611 // with an empty offer.
612 void TestSetContentsNullOffer() {
613 CreateChannels(0, 0);
614 typename T::Content content;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000615 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000616 CreateContent(0, kPcmuCodec, kH264Codec, &content);
617 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000618 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000619 ASSERT_EQ(1U, media_channel1_->codecs().size());
620 EXPECT_TRUE(CodecMatches(content.codecs()[0],
621 media_channel1_->codecs()[0]));
622 }
623
624 // Test that SetLocalContent and SetRemoteContent properly set RTCP
625 // mux.
626 void TestSetContentsRtcpMux() {
627 CreateChannels(RTCP, RTCP);
628 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
629 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
630 typename T::Content content;
631 CreateContent(0, kPcmuCodec, kH264Codec, &content);
632 // Both sides agree on mux. Should no longer be a separate RTCP channel.
633 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000634 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
635 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000636 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
637 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000638 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000639 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000640 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
642 }
643
644 // Test that SetLocalContent and SetRemoteContent properly set RTCP
645 // mux when a provisional answer is received.
646 void TestSetContentsRtcpMuxWithPrAnswer() {
647 CreateChannels(RTCP, RTCP);
648 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
649 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
650 typename T::Content content;
651 CreateContent(0, kPcmuCodec, kH264Codec, &content);
652 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000653 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
654 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000656 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000657 // Both sides agree on mux. Should no longer be a separate RTCP channel.
658 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
659 // Only initiator supports mux. Should still have a separate RTCP channel.
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000660 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000661 content.set_rtcp_mux(false);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000662 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
663 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
665 }
666
667 // Test that SetLocalContent and SetRemoteContent properly set
668 // video options to the media channel.
669 void TestSetContentsVideoOptions() {
670 CreateChannels(0, 0);
671 typename T::Content content;
672 CreateContent(0, kPcmuCodec, kH264Codec, &content);
673 content.set_buffered_mode_latency(101);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000674 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000675 EXPECT_EQ(0U, media_channel1_->codecs().size());
676 cricket::VideoOptions options;
677 ASSERT_TRUE(media_channel1_->GetOptions(&options));
678 int latency = 0;
679 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
680 EXPECT_EQ(101, latency);
681 content.set_buffered_mode_latency(102);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000682 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 ASSERT_EQ(1U, media_channel1_->codecs().size());
684 EXPECT_TRUE(CodecMatches(content.codecs()[0],
685 media_channel1_->codecs()[0]));
686 ASSERT_TRUE(media_channel1_->GetOptions(&options));
687 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
688 EXPECT_EQ(102, latency);
689 }
690
691 // Test that SetRemoteContent properly deals with a content update.
692 void TestSetRemoteContentUpdate() {
693 CreateChannels(0, 0);
694 typename T::Content content;
695 CreateContent(RTCP | RTCP_MUX | SECURE,
696 kPcmuCodec, kH264Codec,
697 &content);
698 EXPECT_EQ(0U, media_channel1_->codecs().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
700 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 ASSERT_EQ(1U, media_channel1_->codecs().size());
702 EXPECT_TRUE(CodecMatches(content.codecs()[0],
703 media_channel1_->codecs()[0]));
704 // Now update with other codecs.
705 typename T::Content update_content;
706 update_content.set_partial(true);
707 CreateContent(0, kIsacCodec, kH264SvcCodec,
708 &update_content);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000709 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 ASSERT_EQ(1U, media_channel1_->codecs().size());
711 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
712 media_channel1_->codecs()[0]));
713 // Now update without any codecs. This is ignored.
714 typename T::Content empty_content;
715 empty_content.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000716 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 ASSERT_EQ(1U, media_channel1_->codecs().size());
718 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
719 media_channel1_->codecs()[0]));
720 }
721
722 // Test that Add/RemoveStream properly forward to the media channel.
723 void TestStreams() {
724 CreateChannels(0, 0);
725 EXPECT_TRUE(AddStream1(1));
726 EXPECT_TRUE(AddStream1(2));
727 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
728 EXPECT_TRUE(RemoveStream1(2));
729 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
730 EXPECT_TRUE(RemoveStream1(1));
731 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
732 }
733
734 // Test that SetLocalContent properly handles adding and removing StreamParams
735 // to the local content description.
736 // This test uses the CA_UPDATE action that don't require a full
737 // MediaContentDescription to do an update.
738 void TestUpdateStreamsInLocalContent() {
739 cricket::StreamParams stream1;
740 stream1.groupid = "group1";
741 stream1.id = "stream1";
742 stream1.ssrcs.push_back(kSsrc1);
743 stream1.cname = "stream1_cname";
744
745 cricket::StreamParams stream2;
746 stream2.groupid = "group2";
747 stream2.id = "stream2";
748 stream2.ssrcs.push_back(kSsrc2);
749 stream2.cname = "stream2_cname";
750
751 cricket::StreamParams stream3;
752 stream3.groupid = "group3";
753 stream3.id = "stream3";
754 stream3.ssrcs.push_back(kSsrc3);
755 stream3.cname = "stream3_cname";
756
757 CreateChannels(0, 0);
758 typename T::Content content1;
759 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
760 content1.AddStream(stream1);
761 EXPECT_EQ(0u, media_channel1_->send_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000762 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763
764 ASSERT_EQ(1u, media_channel1_->send_streams().size());
765 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
766
767 // Update the local streams by adding another sending stream.
768 // Use a partial updated session description.
769 typename T::Content content2;
770 content2.AddStream(stream2);
771 content2.AddStream(stream3);
772 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000773 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 ASSERT_EQ(3u, media_channel1_->send_streams().size());
775 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
776 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
777 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
778
779 // Update the local streams by removing the first sending stream.
780 // This is done by removing all SSRCS for this particular stream.
781 typename T::Content content3;
782 stream1.ssrcs.clear();
783 content3.AddStream(stream1);
784 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000785 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 ASSERT_EQ(2u, media_channel1_->send_streams().size());
787 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
788 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
789
790 // Update the local streams with a stream that does not change.
791 // THe update is ignored.
792 typename T::Content content4;
793 content4.AddStream(stream2);
794 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000795 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 ASSERT_EQ(2u, media_channel1_->send_streams().size());
797 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
798 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
799 }
800
801 // Test that SetRemoteContent properly handles adding and removing
802 // StreamParams to the remote content description.
803 // This test uses the CA_UPDATE action that don't require a full
804 // MediaContentDescription to do an update.
805 void TestUpdateStreamsInRemoteContent() {
806 cricket::StreamParams stream1;
807 stream1.id = "Stream1";
808 stream1.groupid = "1";
809 stream1.ssrcs.push_back(kSsrc1);
810 stream1.cname = "stream1_cname";
811
812 cricket::StreamParams stream2;
813 stream2.id = "Stream2";
814 stream2.groupid = "2";
815 stream2.ssrcs.push_back(kSsrc2);
816 stream2.cname = "stream2_cname";
817
818 cricket::StreamParams stream3;
819 stream3.id = "Stream3";
820 stream3.groupid = "3";
821 stream3.ssrcs.push_back(kSsrc3);
822 stream3.cname = "stream3_cname";
823
824 CreateChannels(0, 0);
825 typename T::Content content1;
826 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
827 content1.AddStream(stream1);
828 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000829 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830
831 ASSERT_EQ(1u, media_channel1_->codecs().size());
832 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
833 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
834
835 // Update the remote streams by adding another sending stream.
836 // Use a partial updated session description.
837 typename T::Content content2;
838 content2.AddStream(stream2);
839 content2.AddStream(stream3);
840 content2.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000841 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
843 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
844 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
845 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
846
847 // Update the remote streams by removing the first stream.
848 // This is done by removing all SSRCS for this particular stream.
849 typename T::Content content3;
850 stream1.ssrcs.clear();
851 content3.AddStream(stream1);
852 content3.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000853 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
855 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
856 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
857
858 // Update the remote streams with a stream that does not change.
859 // The update is ignored.
860 typename T::Content content4;
861 content4.AddStream(stream2);
862 content4.set_partial(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000863 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
865 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
866 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
867 }
868
869 // Test that SetLocalContent and SetRemoteContent properly
870 // handles adding and removing StreamParams when the action is a full
871 // CA_OFFER / CA_ANSWER.
872 void TestChangeStreamParamsInContent() {
873 cricket::StreamParams stream1;
874 stream1.groupid = "group1";
875 stream1.id = "stream1";
876 stream1.ssrcs.push_back(kSsrc1);
877 stream1.cname = "stream1_cname";
878
879 cricket::StreamParams stream2;
880 stream2.groupid = "group1";
881 stream2.id = "stream2";
882 stream2.ssrcs.push_back(kSsrc2);
883 stream2.cname = "stream2_cname";
884
885 // Setup a call where channel 1 send |stream1| to channel 2.
886 CreateChannels(0, 0);
887 typename T::Content content1;
888 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
889 content1.AddStream(stream1);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000890 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 EXPECT_TRUE(channel1_->Enable(true));
892 EXPECT_EQ(1u, media_channel1_->send_streams().size());
893
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000894 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
896 session1_.Connect(&session2_);
897
898 // Channel 2 do not send anything.
899 typename T::Content content2;
900 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000901 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000903 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 EXPECT_TRUE(channel2_->Enable(true));
905 EXPECT_EQ(0u, media_channel2_->send_streams().size());
906
907 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
908 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
909
910 // Let channel 2 update the content by sending |stream2| and enable SRTP.
911 typename T::Content content3;
912 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
913 content3.AddStream(stream2);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000914 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 ASSERT_EQ(1u, media_channel2_->send_streams().size());
916 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
917
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000918 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
920 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
921
922 // Channel 1 replies but stop sending stream1.
923 typename T::Content content4;
924 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000925 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 EXPECT_EQ(0u, media_channel1_->send_streams().size());
927
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000928 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
930
931 EXPECT_TRUE(channel1_->secure());
932 EXPECT_TRUE(channel2_->secure());
933 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
934 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
935 }
936
937 // Test that we only start playout and sending at the right times.
938 void TestPlayoutAndSendingStates() {
939 CreateChannels(0, 0);
940 EXPECT_FALSE(media_channel1_->playout());
941 EXPECT_FALSE(media_channel1_->sending());
942 EXPECT_FALSE(media_channel2_->playout());
943 EXPECT_FALSE(media_channel2_->sending());
944 EXPECT_TRUE(channel1_->Enable(true));
945 EXPECT_FALSE(media_channel1_->playout());
946 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000947 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
948 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 EXPECT_TRUE(media_channel1_->playout());
950 EXPECT_FALSE(media_channel1_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000951 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
952 CA_OFFER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 EXPECT_FALSE(media_channel2_->playout());
954 EXPECT_FALSE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000955 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
956 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 EXPECT_FALSE(media_channel2_->playout());
958 EXPECT_FALSE(media_channel2_->sending());
959 session1_.Connect(&session2_);
960 EXPECT_TRUE(media_channel1_->playout());
961 EXPECT_FALSE(media_channel1_->sending());
962 EXPECT_FALSE(media_channel2_->playout());
963 EXPECT_FALSE(media_channel2_->sending());
964 EXPECT_TRUE(channel2_->Enable(true));
965 EXPECT_TRUE(media_channel2_->playout());
966 EXPECT_TRUE(media_channel2_->sending());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000967 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
968 CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 EXPECT_TRUE(media_channel1_->playout());
970 EXPECT_TRUE(media_channel1_->sending());
971 }
972
973 void TestMuteStream() {
974 CreateChannels(0, 0);
975 // Test that we can Mute the default channel even though the sending SSRC is
976 // unknown.
977 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
978 EXPECT_TRUE(channel1_->MuteStream(0, true));
979 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
980 EXPECT_TRUE(channel1_->MuteStream(0, false));
981 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
982
983 // Test that we can not mute an unknown SSRC.
984 EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true));
985
986 SendInitiate();
987 // After the local session description has been set, we can mute a stream
988 // with its SSRC.
989 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true));
990 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
991 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false));
992 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
993 }
994
995 // Test that changing the MediaContentDirection in the local and remote
996 // session description start playout and sending at the right time.
997 void TestMediaContentDirection() {
998 CreateChannels(0, 0);
999 typename T::Content content1;
1000 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
1001 typename T::Content content2;
1002 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
1003 // Set |content2| to be InActive.
1004 content2.set_direction(cricket::MD_INACTIVE);
1005
1006 EXPECT_TRUE(channel1_->Enable(true));
1007 EXPECT_TRUE(channel2_->Enable(true));
1008 EXPECT_FALSE(media_channel1_->playout());
1009 EXPECT_FALSE(media_channel1_->sending());
1010 EXPECT_FALSE(media_channel2_->playout());
1011 EXPECT_FALSE(media_channel2_->sending());
1012
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001013 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
1014 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
1015 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
1016 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 session1_.Connect(&session2_);
1018
1019 EXPECT_TRUE(media_channel1_->playout());
1020 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
1021 EXPECT_FALSE(media_channel2_->playout()); // local InActive
1022 EXPECT_FALSE(media_channel2_->sending()); // local InActive
1023
1024 // Update |content2| to be RecvOnly.
1025 content2.set_direction(cricket::MD_RECVONLY);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001026 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
1027 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001028
1029 EXPECT_TRUE(media_channel1_->playout());
1030 EXPECT_TRUE(media_channel1_->sending());
1031 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
1032 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
1033
1034 // Update |content2| to be SendRecv.
1035 content2.set_direction(cricket::MD_SENDRECV);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001036 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
1037 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038
1039 EXPECT_TRUE(media_channel1_->playout());
1040 EXPECT_TRUE(media_channel1_->sending());
1041 EXPECT_TRUE(media_channel2_->playout());
1042 EXPECT_TRUE(media_channel2_->sending());
1043 }
1044
1045 // Test setting up a call.
1046 void TestCallSetup() {
1047 CreateChannels(0, 0);
1048 EXPECT_FALSE(channel1_->secure());
1049 EXPECT_TRUE(SendInitiate());
1050 EXPECT_TRUE(media_channel1_->playout());
1051 EXPECT_FALSE(media_channel1_->sending());
1052 EXPECT_TRUE(SendAccept());
1053 EXPECT_FALSE(channel1_->secure());
1054 EXPECT_TRUE(media_channel1_->sending());
1055 EXPECT_EQ(1U, media_channel1_->codecs().size());
1056 EXPECT_TRUE(media_channel2_->playout());
1057 EXPECT_TRUE(media_channel2_->sending());
1058 EXPECT_EQ(1U, media_channel2_->codecs().size());
1059 }
1060
1061 // Test that we don't crash if packets are sent during call teardown
1062 // when RTCP mux is enabled. This is a regression test against a specific
1063 // race condition that would only occur when a RTCP packet was sent during
1064 // teardown of a channel on which RTCP mux was enabled.
1065 void TestCallTeardownRtcpMux() {
1066 class LastWordMediaChannel : public T::MediaChannel {
1067 public:
1068 LastWordMediaChannel() : T::MediaChannel(NULL) {}
1069 ~LastWordMediaChannel() {
1070 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
1071 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1072 }
1073 };
1074 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1075 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
1076 talk_base::Thread::Current());
1077 EXPECT_TRUE(SendInitiate());
1078 EXPECT_TRUE(SendAccept());
1079 EXPECT_TRUE(SendTerminate());
1080 }
1081
1082 // Send voice RTP data to the other side and ensure it gets there.
1083 void SendRtpToRtp() {
1084 CreateChannels(0, 0);
1085 EXPECT_TRUE(SendInitiate());
1086 EXPECT_TRUE(SendAccept());
1087 EXPECT_EQ(1U, GetTransport1()->channels().size());
1088 EXPECT_EQ(1U, GetTransport2()->channels().size());
1089 EXPECT_TRUE(SendRtp1());
1090 EXPECT_TRUE(SendRtp2());
1091 EXPECT_TRUE(CheckRtp1());
1092 EXPECT_TRUE(CheckRtp2());
1093 EXPECT_TRUE(CheckNoRtp1());
1094 EXPECT_TRUE(CheckNoRtp2());
1095 }
1096
1097 // Check that RTCP is not transmitted if both sides don't support RTCP.
1098 void SendNoRtcpToNoRtcp() {
1099 CreateChannels(0, 0);
1100 EXPECT_TRUE(SendInitiate());
1101 EXPECT_TRUE(SendAccept());
1102 EXPECT_EQ(1U, GetTransport1()->channels().size());
1103 EXPECT_EQ(1U, GetTransport2()->channels().size());
1104 EXPECT_FALSE(SendRtcp1());
1105 EXPECT_FALSE(SendRtcp2());
1106 EXPECT_TRUE(CheckNoRtcp1());
1107 EXPECT_TRUE(CheckNoRtcp2());
1108 }
1109
1110 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1111 void SendNoRtcpToRtcp() {
1112 CreateChannels(0, RTCP);
1113 EXPECT_TRUE(SendInitiate());
1114 EXPECT_TRUE(SendAccept());
1115 EXPECT_EQ(1U, GetTransport1()->channels().size());
1116 EXPECT_EQ(2U, GetTransport2()->channels().size());
1117 EXPECT_FALSE(SendRtcp1());
1118 EXPECT_FALSE(SendRtcp2());
1119 EXPECT_TRUE(CheckNoRtcp1());
1120 EXPECT_TRUE(CheckNoRtcp2());
1121 }
1122
1123 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1124 void SendRtcpToNoRtcp() {
1125 CreateChannels(RTCP, 0);
1126 EXPECT_TRUE(SendInitiate());
1127 EXPECT_TRUE(SendAccept());
1128 EXPECT_EQ(2U, GetTransport1()->channels().size());
1129 EXPECT_EQ(1U, GetTransport2()->channels().size());
1130 EXPECT_FALSE(SendRtcp1());
1131 EXPECT_FALSE(SendRtcp2());
1132 EXPECT_TRUE(CheckNoRtcp1());
1133 EXPECT_TRUE(CheckNoRtcp2());
1134 }
1135
1136 // Check that RTCP is transmitted if both sides support RTCP.
1137 void SendRtcpToRtcp() {
1138 CreateChannels(RTCP, RTCP);
1139 EXPECT_TRUE(SendInitiate());
1140 EXPECT_TRUE(SendAccept());
1141 EXPECT_EQ(2U, GetTransport1()->channels().size());
1142 EXPECT_EQ(2U, GetTransport2()->channels().size());
1143 EXPECT_TRUE(SendRtcp1());
1144 EXPECT_TRUE(SendRtcp2());
1145 EXPECT_TRUE(CheckRtcp1());
1146 EXPECT_TRUE(CheckRtcp2());
1147 EXPECT_TRUE(CheckNoRtcp1());
1148 EXPECT_TRUE(CheckNoRtcp2());
1149 }
1150
1151 // Check that RTCP is transmitted if only the initiator supports mux.
1152 void SendRtcpMuxToRtcp() {
1153 CreateChannels(RTCP | RTCP_MUX, RTCP);
1154 EXPECT_TRUE(SendInitiate());
1155 EXPECT_TRUE(SendAccept());
1156 EXPECT_EQ(2U, GetTransport1()->channels().size());
1157 EXPECT_EQ(2U, GetTransport2()->channels().size());
1158 EXPECT_TRUE(SendRtcp1());
1159 EXPECT_TRUE(SendRtcp2());
1160 EXPECT_TRUE(CheckRtcp1());
1161 EXPECT_TRUE(CheckRtcp2());
1162 EXPECT_TRUE(CheckNoRtcp1());
1163 EXPECT_TRUE(CheckNoRtcp2());
1164 }
1165
1166 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1167 void SendRtcpMuxToRtcpMux() {
1168 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1169 EXPECT_TRUE(SendInitiate());
1170 EXPECT_EQ(2U, GetTransport1()->channels().size());
1171 EXPECT_EQ(1U, GetTransport2()->channels().size());
1172 EXPECT_TRUE(SendAccept());
1173 EXPECT_EQ(1U, GetTransport1()->channels().size());
1174 EXPECT_TRUE(SendRtp1());
1175 EXPECT_TRUE(SendRtp2());
1176 EXPECT_TRUE(SendRtcp1());
1177 EXPECT_TRUE(SendRtcp2());
1178 EXPECT_TRUE(CheckRtp1());
1179 EXPECT_TRUE(CheckRtp2());
1180 EXPECT_TRUE(CheckNoRtp1());
1181 EXPECT_TRUE(CheckNoRtp2());
1182 EXPECT_TRUE(CheckRtcp1());
1183 EXPECT_TRUE(CheckRtcp2());
1184 EXPECT_TRUE(CheckNoRtcp1());
1185 EXPECT_TRUE(CheckNoRtcp2());
1186 }
1187
1188 // Check that RTCP data sent by the initiator before the accept is not muxed.
1189 void SendEarlyRtcpMuxToRtcp() {
1190 CreateChannels(RTCP | RTCP_MUX, RTCP);
1191 EXPECT_TRUE(SendInitiate());
1192 EXPECT_EQ(2U, GetTransport1()->channels().size());
1193 EXPECT_EQ(2U, GetTransport2()->channels().size());
1194
1195 // RTCP can be sent before the call is accepted, if the transport is ready.
1196 // It should not be muxed though, as the remote side doesn't support mux.
1197 EXPECT_TRUE(SendRtcp1());
1198 EXPECT_TRUE(CheckNoRtp2());
1199 EXPECT_TRUE(CheckRtcp2());
1200
1201 // Send RTCP packet from callee and verify that it is received.
1202 EXPECT_TRUE(SendRtcp2());
1203 EXPECT_TRUE(CheckNoRtp1());
1204 EXPECT_TRUE(CheckRtcp1());
1205
1206 // Complete call setup and ensure everything is still OK.
1207 EXPECT_TRUE(SendAccept());
1208 EXPECT_EQ(2U, GetTransport1()->channels().size());
1209 EXPECT_TRUE(SendRtcp1());
1210 EXPECT_TRUE(CheckRtcp2());
1211 EXPECT_TRUE(SendRtcp2());
1212 EXPECT_TRUE(CheckRtcp1());
1213 }
1214
1215
1216 // Check that RTCP data is not muxed until both sides have enabled muxing,
1217 // but that we properly demux before we get the accept message, since there
1218 // is a race between RTP data and the jingle accept.
1219 void SendEarlyRtcpMuxToRtcpMux() {
1220 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1221 EXPECT_TRUE(SendInitiate());
1222 EXPECT_EQ(2U, GetTransport1()->channels().size());
1223 EXPECT_EQ(1U, GetTransport2()->channels().size());
1224
1225 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1226 // we haven't yet received the accept that says we should mux.
1227 EXPECT_FALSE(SendRtcp1());
1228
1229 // Send muxed RTCP packet from callee and verify that it is received.
1230 EXPECT_TRUE(SendRtcp2());
1231 EXPECT_TRUE(CheckNoRtp1());
1232 EXPECT_TRUE(CheckRtcp1());
1233
1234 // Complete call setup and ensure everything is still OK.
1235 EXPECT_TRUE(SendAccept());
1236 EXPECT_EQ(1U, GetTransport1()->channels().size());
1237 EXPECT_TRUE(SendRtcp1());
1238 EXPECT_TRUE(CheckRtcp2());
1239 EXPECT_TRUE(SendRtcp2());
1240 EXPECT_TRUE(CheckRtcp1());
1241 }
1242
1243 // Test that we properly send SRTP with RTCP in both directions.
1244 // You can pass in DTLS and/or RTCP_MUX as flags.
1245 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1246 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1247 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1248
1249 int flags1 = RTCP | SECURE | flags1_in;
1250 int flags2 = RTCP | SECURE | flags2_in;
1251 bool dtls1 = !!(flags1_in & DTLS);
1252 bool dtls2 = !!(flags2_in & DTLS);
1253 CreateChannels(flags1, flags2);
1254 EXPECT_FALSE(channel1_->secure());
1255 EXPECT_FALSE(channel2_->secure());
1256 EXPECT_TRUE(SendInitiate());
1257 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1258 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1259 EXPECT_TRUE(SendAccept());
1260 EXPECT_TRUE(channel1_->secure());
1261 EXPECT_TRUE(channel2_->secure());
1262 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1263 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1264 EXPECT_TRUE(SendRtp1());
1265 EXPECT_TRUE(SendRtp2());
1266 EXPECT_TRUE(SendRtcp1());
1267 EXPECT_TRUE(SendRtcp2());
1268 EXPECT_TRUE(CheckRtp1());
1269 EXPECT_TRUE(CheckRtp2());
1270 EXPECT_TRUE(CheckNoRtp1());
1271 EXPECT_TRUE(CheckNoRtp2());
1272 EXPECT_TRUE(CheckRtcp1());
1273 EXPECT_TRUE(CheckRtcp2());
1274 EXPECT_TRUE(CheckNoRtcp1());
1275 EXPECT_TRUE(CheckNoRtcp2());
1276 }
1277
1278 // Test that we properly handling SRTP negotiating down to RTP.
1279 void SendSrtpToRtp() {
1280 CreateChannels(RTCP | SECURE, RTCP);
1281 EXPECT_FALSE(channel1_->secure());
1282 EXPECT_FALSE(channel2_->secure());
1283 EXPECT_TRUE(SendInitiate());
1284 EXPECT_TRUE(SendAccept());
1285 EXPECT_FALSE(channel1_->secure());
1286 EXPECT_FALSE(channel2_->secure());
1287 EXPECT_TRUE(SendRtp1());
1288 EXPECT_TRUE(SendRtp2());
1289 EXPECT_TRUE(SendRtcp1());
1290 EXPECT_TRUE(SendRtcp2());
1291 EXPECT_TRUE(CheckRtp1());
1292 EXPECT_TRUE(CheckRtp2());
1293 EXPECT_TRUE(CheckNoRtp1());
1294 EXPECT_TRUE(CheckNoRtp2());
1295 EXPECT_TRUE(CheckRtcp1());
1296 EXPECT_TRUE(CheckRtcp2());
1297 EXPECT_TRUE(CheckNoRtcp1());
1298 EXPECT_TRUE(CheckNoRtcp2());
1299 }
1300
1301 // Test that we can send and receive early media when a provisional answer is
1302 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1303 void SendEarlyMediaUsingRtcpMuxSrtp() {
1304 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1305
1306 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1307 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1308 EXPECT_TRUE(SendOffer());
1309 EXPECT_TRUE(SendProvisionalAnswer());
1310 EXPECT_TRUE(channel1_->secure());
1311 EXPECT_TRUE(channel2_->secure());
1312 EXPECT_EQ(2U, GetTransport1()->channels().size());
1313 EXPECT_EQ(2U, GetTransport2()->channels().size());
1314 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1315 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1316 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1317 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1318
1319 // Send packets from callee and verify that it is received.
1320 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1321 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1322 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1323 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1324
1325 // Complete call setup and ensure everything is still OK.
1326 EXPECT_TRUE(SendFinalAnswer());
1327 EXPECT_EQ(1U, GetTransport1()->channels().size());
1328 EXPECT_EQ(1U, GetTransport2()->channels().size());
1329 EXPECT_TRUE(channel1_->secure());
1330 EXPECT_TRUE(channel2_->secure());
1331 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1332 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1333 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1334 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1335 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1336 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1337 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1338 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1339 }
1340
1341 // Test that we properly send RTP without SRTP from a thread.
1342 void SendRtpToRtpOnThread() {
1343 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1344 CreateChannels(RTCP, RTCP);
1345 EXPECT_TRUE(SendInitiate());
1346 EXPECT_TRUE(SendAccept());
1347 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1348 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1349 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1350 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1351 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1352 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1353 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1354 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1355 EXPECT_TRUE(CheckNoRtp1());
1356 EXPECT_TRUE(CheckNoRtp2());
1357 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1358 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1359 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1360 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1361 EXPECT_TRUE(CheckNoRtcp1());
1362 EXPECT_TRUE(CheckNoRtcp2());
1363 }
1364
1365 // Test that we properly send SRTP with RTCP from a thread.
1366 void SendSrtpToSrtpOnThread() {
1367 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1368 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1369 EXPECT_TRUE(SendInitiate());
1370 EXPECT_TRUE(SendAccept());
1371 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1372 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1373 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1374 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1375 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1376 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1377 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1378 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1379 EXPECT_TRUE(CheckNoRtp1());
1380 EXPECT_TRUE(CheckNoRtp2());
1381 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1382 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1383 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1384 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1385 EXPECT_TRUE(CheckNoRtcp1());
1386 EXPECT_TRUE(CheckNoRtcp2());
1387 }
1388
1389 // Test that the mediachannel retains its sending state after the transport
1390 // becomes non-writable.
1391 void SendWithWritabilityLoss() {
1392 CreateChannels(0, 0);
1393 EXPECT_TRUE(SendInitiate());
1394 EXPECT_TRUE(SendAccept());
1395 EXPECT_EQ(1U, GetTransport1()->channels().size());
1396 EXPECT_EQ(1U, GetTransport2()->channels().size());
1397 EXPECT_TRUE(SendRtp1());
1398 EXPECT_TRUE(SendRtp2());
1399 EXPECT_TRUE(CheckRtp1());
1400 EXPECT_TRUE(CheckRtp2());
1401 EXPECT_TRUE(CheckNoRtp1());
1402 EXPECT_TRUE(CheckNoRtp2());
1403
wu@webrtc.org97077a32013-10-25 21:18:33 +00001404 // Lose writability, which should fail.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405 GetTransport1()->SetWritable(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 EXPECT_FALSE(SendRtp1());
1407 EXPECT_TRUE(SendRtp2());
1408 EXPECT_TRUE(CheckRtp1());
1409 EXPECT_TRUE(CheckNoRtp2());
1410
1411 // Regain writability
1412 GetTransport1()->SetWritable(true);
1413 EXPECT_TRUE(media_channel1_->sending());
1414 EXPECT_TRUE(SendRtp1());
1415 EXPECT_TRUE(SendRtp2());
1416 EXPECT_TRUE(CheckRtp1());
1417 EXPECT_TRUE(CheckRtp2());
1418 EXPECT_TRUE(CheckNoRtp1());
1419 EXPECT_TRUE(CheckNoRtp2());
1420
1421 // Lose writability completely
1422 GetTransport1()->SetDestination(NULL);
1423 EXPECT_TRUE(media_channel1_->sending());
1424
wu@webrtc.org97077a32013-10-25 21:18:33 +00001425 // Should fail also.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 EXPECT_FALSE(SendRtp1());
1427 EXPECT_TRUE(SendRtp2());
1428 EXPECT_TRUE(CheckRtp1());
1429 EXPECT_TRUE(CheckNoRtp2());
1430
1431 // Gain writability back
1432 GetTransport1()->SetDestination(GetTransport2());
1433 EXPECT_TRUE(media_channel1_->sending());
1434 EXPECT_TRUE(SendRtp1());
1435 EXPECT_TRUE(SendRtp2());
1436 EXPECT_TRUE(CheckRtp1());
1437 EXPECT_TRUE(CheckRtp2());
1438 EXPECT_TRUE(CheckNoRtp1());
1439 EXPECT_TRUE(CheckNoRtp2());
1440 }
1441
1442 void SendSsrcMuxToSsrcMuxWithRtcpMux() {
1443 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1444 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX, SSRC_MUX | RTCP | RTCP_MUX);
1445 EXPECT_TRUE(SendInitiate());
1446 EXPECT_EQ(2U, GetTransport1()->channels().size());
1447 EXPECT_EQ(1U, GetTransport2()->channels().size());
1448 EXPECT_TRUE(SendAccept());
1449 EXPECT_EQ(1U, GetTransport1()->channels().size());
1450 EXPECT_EQ(1U, GetTransport2()->channels().size());
1451 EXPECT_TRUE(channel1_->ssrc_filter()->IsActive());
1452 // channel1 - should have media_content2 as remote. i.e. kSsrc2
1453 EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2));
1454 EXPECT_TRUE(channel2_->ssrc_filter()->IsActive());
1455 // channel2 - should have media_content1 as remote. i.e. kSsrc1
1456 EXPECT_TRUE(channel2_->ssrc_filter()->FindStream(kSsrc1));
1457 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1458 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1459 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1460 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1461 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1462 EXPECT_TRUE(CheckNoRtp1());
1463 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1464 EXPECT_TRUE(CheckNoRtp2());
1465 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1466 EXPECT_TRUE(CheckNoRtcp1());
1467 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1468 EXPECT_TRUE(CheckNoRtcp2());
1469 }
1470
1471 void SendSsrcMuxToSsrcMux() {
1472 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1473 CreateChannels(SSRC_MUX | RTCP, SSRC_MUX | RTCP);
1474 EXPECT_TRUE(SendInitiate());
1475 EXPECT_EQ(2U, GetTransport1()->channels().size());
1476 EXPECT_EQ(2U, GetTransport2()->channels().size());
1477 EXPECT_TRUE(SendAccept());
1478 EXPECT_EQ(2U, GetTransport1()->channels().size());
1479 EXPECT_EQ(2U, GetTransport2()->channels().size());
1480 EXPECT_TRUE(channel1_->ssrc_filter()->IsActive());
1481 // channel1 - should have media_content2 as remote. i.e. kSsrc2
1482 EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2));
1483 EXPECT_TRUE(channel2_->ssrc_filter()->IsActive());
1484 // channel2 - should have media_content1 as remote. i.e. kSsrc1
1485 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1486 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1487 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1488 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1489 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1490 EXPECT_FALSE(CheckCustomRtp1(kSsrc1, sequence_number2_2));
1491 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1492 EXPECT_FALSE(CheckCustomRtp2(kSsrc2, sequence_number1_1));
1493 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1494 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
1495 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1496 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1497 }
1498
1499 // Test that the media monitor can be run and gives timely callbacks.
1500 void TestMediaMonitor() {
1501 static const int kTimeout = 500;
1502 CreateChannels(0, 0);
1503 EXPECT_TRUE(SendInitiate());
1504 EXPECT_TRUE(SendAccept());
1505 channel1_->StartMediaMonitor(100);
1506 channel2_->StartMediaMonitor(100);
1507 // Ensure we get callbacks and stop.
1508 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1509 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1510 channel1_->StopMediaMonitor();
1511 channel2_->StopMediaMonitor();
1512 // Ensure a restart of a stopped monitor works.
1513 channel1_->StartMediaMonitor(100);
1514 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1515 channel1_->StopMediaMonitor();
1516 // Ensure stopping a stopped monitor is OK.
1517 channel1_->StopMediaMonitor();
1518 }
1519
1520 void TestMediaSinks() {
1521 CreateChannels(0, 0);
1522 EXPECT_TRUE(SendInitiate());
1523 EXPECT_TRUE(SendAccept());
1524 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1525 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1526 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1527 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1528
1529 talk_base::Pathname path;
1530 EXPECT_TRUE(talk_base::Filesystem::GetTemporaryFolder(path, true, NULL));
1531 path.SetFilename("sink-test.rtpdump");
1532 talk_base::scoped_ptr<cricket::RtpDumpSink> sink(
1533 new cricket::RtpDumpSink(Open(path.pathname())));
1534 sink->set_packet_filter(cricket::PF_ALL);
1535 EXPECT_TRUE(sink->Enable(true));
1536 channel1_->RegisterSendSink(
1537 sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
1538 EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1539 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1540 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1541 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1542
1543 // The first packet is recorded with header + data.
1544 EXPECT_TRUE(SendRtp1());
1545 // The second packet is recorded with header only.
1546 sink->set_packet_filter(cricket::PF_RTPHEADER);
1547 EXPECT_TRUE(SendRtp1());
1548 // The third packet is not recorded since sink is disabled.
1549 EXPECT_TRUE(sink->Enable(false));
1550 EXPECT_TRUE(SendRtp1());
1551 // The fourth packet is not recorded since sink is unregistered.
1552 EXPECT_TRUE(sink->Enable(true));
1553 channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
1554 EXPECT_TRUE(SendRtp1());
1555 sink.reset(); // This will close the file.
1556
1557 // Read the recorded file and verify two packets.
1558 talk_base::scoped_ptr<talk_base::StreamInterface> stream(
1559 talk_base::Filesystem::OpenFile(path, "rb"));
1560
1561 cricket::RtpDumpReader reader(stream.get());
1562 cricket::RtpDumpPacket packet;
1563 EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
1564 std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
1565 packet.data.size());
1566 EXPECT_EQ(rtp_packet_, read_packet);
1567
1568 EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
1569 size_t len = 0;
1570 packet.GetRtpHeaderLen(&len);
1571 EXPECT_EQ(len, packet.data.size());
1572 EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
1573
1574 EXPECT_EQ(talk_base::SR_EOS, reader.ReadPacket(&packet));
1575
1576 // Delete the file for media recording.
1577 stream.reset();
1578 EXPECT_TRUE(talk_base::Filesystem::DeleteFile(path));
1579 }
1580
1581 void TestSetContentFailure() {
1582 CreateChannels(0, 0);
1583 typename T::Content content;
1584 cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1585 cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1586
1587 // Set up the session description.
1588 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1589 sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1590 new cricket::AudioContentDescription());
1591 sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1592 new cricket::VideoContentDescription());
1593 EXPECT_TRUE(session1_.set_local_description(sdesc_loc));
1594 sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1595 new cricket::AudioContentDescription());
1596 sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1597 new cricket::VideoContentDescription());
1598 EXPECT_TRUE(session1_.set_remote_description(sdesc_rem));
1599
1600 // Test failures in SetLocalContent.
1601 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001602 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1604 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1605 media_channel1_->set_fail_set_recv_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001606 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
1608 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1609
1610 // Test failures in SetRemoteContent.
1611 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001612 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1614 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1615 media_channel1_->set_fail_set_send_codecs(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001616 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
1618 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1619 }
1620
1621 void TestSendTwoOffers() {
1622 CreateChannels(0, 0);
1623
1624 // Set up the initial session description.
1625 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1626 EXPECT_TRUE(session1_.set_local_description(sdesc));
1627
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001628 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1630 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1631 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1632
1633 // Update the local description and set the state again.
1634 sdesc = CreateSessionDescriptionWithStream(2);
1635 EXPECT_TRUE(session1_.set_local_description(sdesc));
1636
1637 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1638 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1639 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1640 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1641 }
1642
1643 void TestReceiveTwoOffers() {
1644 CreateChannels(0, 0);
1645
1646 // Set up the initial session description.
1647 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1648 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1649
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001650 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1652 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1653 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1654
1655 sdesc = CreateSessionDescriptionWithStream(2);
1656 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1657 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1658 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1659 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1660 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1661 }
1662
1663 void TestSendPrAnswer() {
1664 CreateChannels(0, 0);
1665
1666 // Set up the initial session description.
1667 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1668 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1669
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001670 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1672 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1673 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1674
1675 // Send PRANSWER
1676 sdesc = CreateSessionDescriptionWithStream(2);
1677 EXPECT_TRUE(session1_.set_local_description(sdesc));
1678
1679 session1_.SetState(cricket::Session::STATE_SENTPRACCEPT);
1680 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1681 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1682 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1683
1684 // Send ACCEPT
1685 sdesc = CreateSessionDescriptionWithStream(3);
1686 EXPECT_TRUE(session1_.set_local_description(sdesc));
1687
1688 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
1689 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1690 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1691 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1692 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1693 }
1694
1695 void TestReceivePrAnswer() {
1696 CreateChannels(0, 0);
1697
1698 // Set up the initial session description.
1699 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1700 EXPECT_TRUE(session1_.set_local_description(sdesc));
1701
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001702 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1704 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1705 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1706
1707 // Receive PRANSWER
1708 sdesc = CreateSessionDescriptionWithStream(2);
1709 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1710
1711 session1_.SetState(cricket::Session::STATE_RECEIVEDPRACCEPT);
1712 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1713 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1714 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1715
1716 // Receive ACCEPT
1717 sdesc = CreateSessionDescriptionWithStream(3);
1718 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1719
1720 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
1721 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1722 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1723 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1724 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1725 }
1726
1727 void TestFlushRtcp() {
1728 bool send_rtcp1;
1729
1730 CreateChannels(RTCP, RTCP);
1731 EXPECT_TRUE(SendInitiate());
1732 EXPECT_TRUE(SendAccept());
1733 EXPECT_EQ(2U, GetTransport1()->channels().size());
1734 EXPECT_EQ(2U, GetTransport2()->channels().size());
1735
1736 // Send RTCP1 from a different thread.
1737 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1738 EXPECT_TRUE(send_rtcp1);
1739 // The sending message is only posted. channel2_ should be empty.
1740 EXPECT_TRUE(CheckNoRtcp2());
1741
1742 // When channel1_ is deleted, the RTCP packet should be sent out to
1743 // channel2_.
1744 channel1_.reset();
1745 EXPECT_TRUE(CheckRtcp2());
1746 }
1747
1748 void TestChangeStateError() {
1749 CreateChannels(RTCP, RTCP);
1750 EXPECT_TRUE(SendInitiate());
1751 media_channel2_->set_fail_set_send(true);
1752 EXPECT_TRUE(channel2_->Enable(true));
1753 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1754 error_);
1755 }
1756
1757 void TestSrtpError() {
1758 static const unsigned char kBadPacket[] = {
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001759 0x84, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 };
1761 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1762 EXPECT_FALSE(channel1_->secure());
1763 EXPECT_FALSE(channel2_->secure());
1764 EXPECT_TRUE(SendInitiate());
1765 EXPECT_TRUE(SendAccept());
1766 EXPECT_TRUE(channel1_->secure());
1767 EXPECT_TRUE(channel2_->secure());
1768 channel2_->set_srtp_signal_silent_time(200);
1769
1770 // Testing failures in sending packets.
1771 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1772 // The first failure will trigger an error.
1773 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1774 error_ = T::MediaChannel::ERROR_NONE;
1775 // The next 1 sec failures will not trigger an error.
1776 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1777 // Wait for a while to ensure no message comes in.
1778 talk_base::Thread::Current()->ProcessMessages(210);
1779 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1780 // The error will be triggered again.
1781 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1782 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1783
1784 // Testing failures in receiving packets.
1785 error_ = T::MediaChannel::ERROR_NONE;
1786 cricket::TransportChannel* transport_channel =
1787 channel2_->transport_channel();
1788 transport_channel->SignalReadPacket(
1789 transport_channel, reinterpret_cast<const char*>(kBadPacket),
wu@webrtc.orga9890802013-12-13 00:21:03 +00001790 sizeof(kBadPacket), talk_base::PacketTime(), 0);
mallinath@webrtc.org4d3e8b82013-08-16 00:31:17 +00001791 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 }
1793
1794 void TestOnReadyToSend() {
1795 CreateChannels(RTCP, RTCP);
1796 TransportChannel* rtp = channel1_->transport_channel();
1797 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1798 EXPECT_FALSE(media_channel1_->ready_to_send());
1799 rtp->SignalReadyToSend(rtp);
1800 EXPECT_FALSE(media_channel1_->ready_to_send());
1801 rtcp->SignalReadyToSend(rtcp);
1802 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1803 // channel are ready to send.
1804 EXPECT_TRUE(media_channel1_->ready_to_send());
1805
1806 // rtp channel becomes not ready to send will be propagated to mediachannel
1807 channel1_->SetReadyToSend(rtp, false);
1808 EXPECT_FALSE(media_channel1_->ready_to_send());
1809 channel1_->SetReadyToSend(rtp, true);
1810 EXPECT_TRUE(media_channel1_->ready_to_send());
1811
1812 // rtcp channel becomes not ready to send will be propagated to mediachannel
1813 channel1_->SetReadyToSend(rtcp, false);
1814 EXPECT_FALSE(media_channel1_->ready_to_send());
1815 channel1_->SetReadyToSend(rtcp, true);
1816 EXPECT_TRUE(media_channel1_->ready_to_send());
1817 }
1818
1819 void TestOnReadyToSendWithRtcpMux() {
1820 CreateChannels(RTCP, RTCP);
1821 typename T::Content content;
1822 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1823 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1824 content.set_rtcp_mux(true);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001825 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1826 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1828 TransportChannel* rtp = channel1_->transport_channel();
1829 EXPECT_FALSE(media_channel1_->ready_to_send());
1830 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1831 // should trigger the MediaChannel's OnReadyToSend.
1832 rtp->SignalReadyToSend(rtp);
1833 EXPECT_TRUE(media_channel1_->ready_to_send());
1834 channel1_->SetReadyToSend(rtp, false);
1835 EXPECT_FALSE(media_channel1_->ready_to_send());
1836 }
1837
1838 protected:
1839 cricket::FakeSession session1_;
1840 cricket::FakeSession session2_;
1841 cricket::FakeMediaEngine media_engine_;
1842 // The media channels are owned by the voice channel objects below.
1843 typename T::MediaChannel* media_channel1_;
1844 typename T::MediaChannel* media_channel2_;
1845 talk_base::scoped_ptr<typename T::Channel> channel1_;
1846 talk_base::scoped_ptr<typename T::Channel> channel2_;
1847 typename T::Content local_media_content1_;
1848 typename T::Content local_media_content2_;
1849 typename T::Content remote_media_content1_;
1850 typename T::Content remote_media_content2_;
1851 talk_base::scoped_ptr<talk_base::SSLIdentity> identity1_;
1852 talk_base::scoped_ptr<talk_base::SSLIdentity> identity2_;
1853 // The RTP and RTCP packets to send in the tests.
1854 std::string rtp_packet_;
1855 std::string rtcp_packet_;
1856 int media_info_callbacks1_;
1857 int media_info_callbacks2_;
1858 bool mute_callback_recved_;
1859 bool mute_callback_value_;
1860
1861 uint32 ssrc_;
1862 typename T::MediaChannel::Error error_;
1863};
1864
1865
1866template<>
1867void ChannelTest<VoiceTraits>::CreateContent(
1868 int flags,
1869 const cricket::AudioCodec& audio_codec,
1870 const cricket::VideoCodec& video_codec,
1871 cricket::AudioContentDescription* audio) {
1872 audio->AddCodec(audio_codec);
1873 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1874 if (flags & SECURE) {
1875 audio->AddCrypto(cricket::CryptoParams(
1876 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
1877 "inline:" + talk_base::CreateRandomString(40), ""));
1878 }
1879}
1880
1881template<>
1882void ChannelTest<VoiceTraits>::CopyContent(
1883 const cricket::AudioContentDescription& source,
1884 cricket::AudioContentDescription* audio) {
1885 *audio = source;
1886}
1887
1888template<>
1889bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1890 const cricket::AudioCodec& c2) {
1891 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1892 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1893}
1894
1895template<>
1896void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1897 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1898 audio->AddLegacyStream(ssrc);
1899}
1900
1901class VoiceChannelTest
1902 : public ChannelTest<VoiceTraits> {
1903 public:
1904 typedef ChannelTest<VoiceTraits>
1905 Base;
1906 VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1907 kRtcpReport, sizeof(kRtcpReport)) {
1908 }
1909
1910 void TestSetChannelOptions() {
1911 CreateChannels(0, 0);
1912
1913 cricket::AudioOptions options1;
1914 options1.echo_cancellation.Set(false);
1915 cricket::AudioOptions options2;
1916 options2.echo_cancellation.Set(true);
1917
1918 channel1_->SetChannelOptions(options1);
1919 channel2_->SetChannelOptions(options1);
1920 cricket::AudioOptions actual_options;
1921 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1922 EXPECT_EQ(options1, actual_options);
1923 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1924 EXPECT_EQ(options1, actual_options);
1925
1926 channel1_->SetChannelOptions(options2);
1927 channel2_->SetChannelOptions(options2);
1928 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1929 EXPECT_EQ(options2, actual_options);
1930 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1931 EXPECT_EQ(options2, actual_options);
1932 }
1933};
1934
1935// override to add NULL parameter
1936template<>
1937cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
1938 talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
1939 cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1940 bool rtcp) {
1941 cricket::VideoChannel* channel = new cricket::VideoChannel(
1942 thread, engine, ch, session, cricket::CN_VIDEO, rtcp, NULL);
1943 if (!channel->Init()) {
1944 delete channel;
1945 channel = NULL;
1946 }
1947 return channel;
1948}
1949
1950// override to add 0 parameter
1951template<>
1952bool ChannelTest<VideoTraits>::AddStream1(int id) {
1953 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1954}
1955
1956template<>
1957void ChannelTest<VideoTraits>::CreateContent(
1958 int flags,
1959 const cricket::AudioCodec& audio_codec,
1960 const cricket::VideoCodec& video_codec,
1961 cricket::VideoContentDescription* video) {
1962 video->AddCodec(video_codec);
1963 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1964 if (flags & SECURE) {
1965 video->AddCrypto(cricket::CryptoParams(
1966 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
1967 "inline:" + talk_base::CreateRandomString(40), ""));
1968 }
1969}
1970
1971template<>
1972void ChannelTest<VideoTraits>::CopyContent(
1973 const cricket::VideoContentDescription& source,
1974 cricket::VideoContentDescription* video) {
1975 *video = source;
1976}
1977
1978template<>
1979bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1980 const cricket::VideoCodec& c2) {
1981 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1982 c1.framerate == c2.framerate;
1983}
1984
1985template<>
1986void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1987 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1988 video->AddLegacyStream(ssrc);
1989}
1990
1991class VideoChannelTest
1992 : public ChannelTest<VideoTraits> {
1993 public:
1994 typedef ChannelTest<VideoTraits>
1995 Base;
1996 VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
1997 kRtcpReport, sizeof(kRtcpReport)) {
1998 }
1999
2000 void TestSetChannelOptions() {
2001 CreateChannels(0, 0);
2002
2003 cricket::VideoOptions o1, o2;
2004 o1.video_noise_reduction.Set(true);
2005
2006 channel1_->SetChannelOptions(o1);
2007 channel2_->SetChannelOptions(o1);
2008 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2009 EXPECT_EQ(o1, o2);
2010 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2011 EXPECT_EQ(o1, o2);
2012
2013 o1.video_leaky_bucket.Set(true);
2014 channel1_->SetChannelOptions(o1);
2015 channel2_->SetChannelOptions(o1);
2016 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2017 EXPECT_EQ(o1, o2);
2018 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2019 EXPECT_EQ(o1, o2);
2020 }
2021};
2022
2023
2024// VoiceChannelTest
2025
2026TEST_F(VoiceChannelTest, TestInit) {
2027 Base::TestInit();
2028 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2029 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2030}
2031
2032TEST_F(VoiceChannelTest, TestSetContents) {
2033 Base::TestSetContents();
2034}
2035
2036TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2037 Base::TestSetContentsNullOffer();
2038}
2039
2040TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2041 Base::TestSetContentsRtcpMux();
2042}
2043
2044TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2045 Base::TestSetContentsRtcpMux();
2046}
2047
2048TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2049 Base::TestSetRemoteContentUpdate();
2050}
2051
2052TEST_F(VoiceChannelTest, TestStreams) {
2053 Base::TestStreams();
2054}
2055
2056TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2057 Base::TestUpdateStreamsInLocalContent();
2058}
2059
2060TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2061 Base::TestUpdateStreamsInRemoteContent();
2062}
2063
2064TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2065 Base::TestChangeStreamParamsInContent();
2066}
2067
2068TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2069 Base::TestPlayoutAndSendingStates();
2070}
2071
2072TEST_F(VoiceChannelTest, TestMuteStream) {
2073 Base::TestMuteStream();
2074}
2075
2076TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2077 Base::TestMediaContentDirection();
2078}
2079
2080TEST_F(VoiceChannelTest, TestCallSetup) {
2081 Base::TestCallSetup();
2082}
2083
2084TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2085 Base::TestCallTeardownRtcpMux();
2086}
2087
2088TEST_F(VoiceChannelTest, SendRtpToRtp) {
2089 Base::SendRtpToRtp();
2090}
2091
2092TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2093 Base::SendNoRtcpToNoRtcp();
2094}
2095
2096TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2097 Base::SendNoRtcpToRtcp();
2098}
2099
2100TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2101 Base::SendRtcpToNoRtcp();
2102}
2103
2104TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2105 Base::SendRtcpToRtcp();
2106}
2107
2108TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2109 Base::SendRtcpMuxToRtcp();
2110}
2111
2112TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2113 Base::SendRtcpMuxToRtcpMux();
2114}
2115
2116TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2117 Base::SendEarlyRtcpMuxToRtcp();
2118}
2119
2120TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2121 Base::SendEarlyRtcpMuxToRtcpMux();
2122}
2123
2124TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2125 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2126}
2127
2128TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2129 Base::SendSrtpToSrtp();
2130}
2131
2132TEST_F(VoiceChannelTest, SendSrtcpMux) {
2133 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2134}
2135
2136TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2137 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2138 Base::SendSrtpToSrtp(DTLS, 0);
2139}
2140
2141TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2142 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2143 Base::SendSrtpToSrtp(DTLS, DTLS);
2144}
2145
2146TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2147 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2148 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2149}
2150
2151TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2152 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2153}
2154
2155TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2156 Base::SendRtpToRtpOnThread();
2157}
2158
2159TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2160 Base::SendSrtpToSrtpOnThread();
2161}
2162
2163TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2164 Base::SendWithWritabilityLoss();
2165}
2166
2167TEST_F(VoiceChannelTest, TestMediaMonitor) {
2168 Base::TestMediaMonitor();
2169}
2170
2171// Test that MuteStream properly forwards to the media channel and does
2172// not signal.
2173TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
2174 CreateChannels(0, 0);
2175 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2176 EXPECT_FALSE(mute_callback_recved_);
2177 EXPECT_TRUE(channel1_->MuteStream(0, true));
2178 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2179 EXPECT_FALSE(mute_callback_recved_);
2180 EXPECT_TRUE(channel1_->MuteStream(0, false));
2181 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2182 EXPECT_FALSE(mute_callback_recved_);
2183}
2184
2185// Test that keyboard automute works correctly and signals upwards.
asapersson@webrtc.orgb533a822013-09-23 19:47:49 +00002186TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187 CreateChannels(0, 0);
2188 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2189 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
2190
2191 cricket::VoiceMediaChannel::Error e =
2192 cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
2193
2194 // Typing doesn't mute automatically unless typing monitor has been installed
2195 media_channel1_->TriggerError(0, e);
2196 talk_base::Thread::Current()->ProcessMessages(0);
2197 EXPECT_EQ(e, error_);
2198 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2199 EXPECT_FALSE(mute_callback_recved_);
2200
2201 cricket::TypingMonitorOptions o = {0};
2202 o.mute_period = 1500;
2203 channel1_->StartTypingMonitor(o);
2204 media_channel1_->TriggerError(0, e);
2205 talk_base::Thread::Current()->ProcessMessages(0);
2206 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2207 EXPECT_TRUE(mute_callback_recved_);
2208}
2209
2210// Test that PressDTMF properly forwards to the media channel.
2211TEST_F(VoiceChannelTest, TestDtmf) {
2212 CreateChannels(0, 0);
2213 EXPECT_TRUE(SendInitiate());
2214 EXPECT_TRUE(SendAccept());
2215 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2216
2217 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2218 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2219
2220 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2221 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2222 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2223 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2224 0, 8, 160, cricket::DF_SEND));
2225}
2226
2227// Test that InsertDtmf properly forwards to the media channel.
2228TEST_F(VoiceChannelTest, TestInsertDtmf) {
2229 CreateChannels(0, 0);
2230 EXPECT_TRUE(SendInitiate());
2231 EXPECT_TRUE(SendAccept());
2232 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002234 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2235 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2236 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2237 cricket::DF_PLAY | cricket::DF_SEND));
2238
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002239 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002240 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 1, 3, 100, cricket::DF_SEND));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002242 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243 2, 5, 110, cricket::DF_PLAY));
henrike@webrtc.org9de257d2013-07-17 14:42:53 +00002244 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2246}
2247
2248TEST_F(VoiceChannelTest, TestMediaSinks) {
2249 Base::TestMediaSinks();
2250}
2251
2252TEST_F(VoiceChannelTest, TestSetContentFailure) {
2253 Base::TestSetContentFailure();
2254}
2255
2256TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2257 Base::TestSendTwoOffers();
2258}
2259
2260TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2261 Base::TestReceiveTwoOffers();
2262}
2263
2264TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2265 Base::TestSendPrAnswer();
2266}
2267
2268TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2269 Base::TestReceivePrAnswer();
2270}
2271
2272TEST_F(VoiceChannelTest, TestFlushRtcp) {
2273 Base::TestFlushRtcp();
2274}
2275
2276TEST_F(VoiceChannelTest, TestChangeStateError) {
2277 Base::TestChangeStateError();
2278}
2279
2280TEST_F(VoiceChannelTest, TestSrtpError) {
2281 Base::TestSrtpError();
2282}
2283
2284TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2285 Base::TestOnReadyToSend();
2286}
2287
2288TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2289 Base::TestOnReadyToSendWithRtcpMux();
2290}
2291
2292// Test that we can play a ringback tone properly.
2293TEST_F(VoiceChannelTest, TestRingbackTone) {
2294 CreateChannels(RTCP, RTCP);
2295 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2296 EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
2297 EXPECT_TRUE(SendInitiate());
2298 EXPECT_TRUE(SendAccept());
2299 // Play ringback tone, no loop.
2300 EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
2301 EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
2302 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2303 EXPECT_FALSE(media_channel1_->ringback_tone_loop());
2304 // Stop the ringback tone.
2305 EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
2306 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2307 // Add a stream.
2308 EXPECT_TRUE(AddStream1(1));
2309 // Play ringback tone, looping, on the new stream.
2310 EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
2311 EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
2312 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2313 EXPECT_TRUE(media_channel1_->ringback_tone_loop());
2314 // Stop the ringback tone.
2315 EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
2316 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2317}
2318
2319// Test that we can scale the output volume properly for 1:1 calls.
2320TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2321 CreateChannels(RTCP, RTCP);
2322 EXPECT_TRUE(SendInitiate());
2323 EXPECT_TRUE(SendAccept());
2324 double left, right;
2325
2326 // Default is (1.0, 1.0).
2327 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2328 EXPECT_DOUBLE_EQ(1.0, left);
2329 EXPECT_DOUBLE_EQ(1.0, right);
2330 // invalid ssrc.
2331 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2332
2333 // Set scale to (1.5, 0.5).
2334 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2335 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2336 EXPECT_DOUBLE_EQ(1.5, left);
2337 EXPECT_DOUBLE_EQ(0.5, right);
2338
2339 // Set scale to (0, 0).
2340 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2341 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2342 EXPECT_DOUBLE_EQ(0.0, left);
2343 EXPECT_DOUBLE_EQ(0.0, right);
2344}
2345
2346// Test that we can scale the output volume properly for multiway calls.
2347TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2348 CreateChannels(RTCP, RTCP);
2349 EXPECT_TRUE(SendInitiate());
2350 EXPECT_TRUE(SendAccept());
2351 EXPECT_TRUE(AddStream1(1));
2352 EXPECT_TRUE(AddStream1(2));
2353
2354 double left, right;
2355 // Default is (1.0, 1.0).
2356 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2357 EXPECT_DOUBLE_EQ(1.0, left);
2358 EXPECT_DOUBLE_EQ(1.0, right);
2359 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2360 EXPECT_DOUBLE_EQ(1.0, left);
2361 EXPECT_DOUBLE_EQ(1.0, right);
2362 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2363 EXPECT_DOUBLE_EQ(1.0, left);
2364 EXPECT_DOUBLE_EQ(1.0, right);
2365 // invalid ssrc.
2366 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2367
2368 // Set scale to (1.5, 0.5) for ssrc = 1.
2369 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2370 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2371 EXPECT_DOUBLE_EQ(1.5, left);
2372 EXPECT_DOUBLE_EQ(0.5, right);
2373 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2374 EXPECT_DOUBLE_EQ(1.0, left);
2375 EXPECT_DOUBLE_EQ(1.0, right);
2376 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2377 EXPECT_DOUBLE_EQ(1.0, left);
2378 EXPECT_DOUBLE_EQ(1.0, right);
2379
2380 // Set scale to (0, 0) for all ssrcs.
2381 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2382 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2383 EXPECT_DOUBLE_EQ(0.0, left);
2384 EXPECT_DOUBLE_EQ(0.0, right);
2385 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2386 EXPECT_DOUBLE_EQ(0.0, left);
2387 EXPECT_DOUBLE_EQ(0.0, right);
2388 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2389 EXPECT_DOUBLE_EQ(0.0, left);
2390 EXPECT_DOUBLE_EQ(0.0, right);
2391}
2392
2393TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMux) {
2394 Base::SendSsrcMuxToSsrcMux();
2395}
2396
2397TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) {
2398 Base::SendSsrcMuxToSsrcMuxWithRtcpMux();
2399}
2400
2401TEST_F(VoiceChannelTest, TestSetChannelOptions) {
2402 TestSetChannelOptions();
2403}
2404
2405// VideoChannelTest
2406TEST_F(VideoChannelTest, TestInit) {
2407 Base::TestInit();
2408}
2409
2410TEST_F(VideoChannelTest, TestSetContents) {
2411 Base::TestSetContents();
2412}
2413
2414TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2415 Base::TestSetContentsNullOffer();
2416}
2417
2418TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2419 Base::TestSetContentsRtcpMux();
2420}
2421
2422TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2423 Base::TestSetContentsRtcpMux();
2424}
2425
2426TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
2427 Base::TestSetContentsVideoOptions();
2428}
2429
2430TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2431 Base::TestSetRemoteContentUpdate();
2432}
2433
2434TEST_F(VideoChannelTest, TestStreams) {
2435 Base::TestStreams();
2436}
2437
2438TEST_F(VideoChannelTest, TestScreencastEvents) {
2439 const int kTimeoutMs = 500;
2440 TestInit();
2441 FakeScreenCaptureFactory* screencapture_factory =
2442 new FakeScreenCaptureFactory();
2443 channel1_->SetScreenCaptureFactory(screencapture_factory);
2444 cricket::ScreencastEventCatcher catcher;
2445 channel1_->SignalScreencastWindowEvent.connect(
2446 &catcher,
2447 &cricket::ScreencastEventCatcher::OnEvent);
2448 EXPECT_TRUE(channel1_->AddScreencast(0, ScreencastId(WindowId(0))) != NULL);
2449 ASSERT_TRUE(screencapture_factory->window_capturer() != NULL);
2450 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screencapture_factory->capture_state(),
2451 kTimeoutMs);
2452 screencapture_factory->window_capturer()->SignalStateChange(
2453 screencapture_factory->window_capturer(), cricket::CS_PAUSED);
2454 EXPECT_EQ_WAIT(talk_base::WE_MINIMIZE, catcher.event(), kTimeoutMs);
2455 screencapture_factory->window_capturer()->SignalStateChange(
2456 screencapture_factory->window_capturer(), cricket::CS_RUNNING);
2457 EXPECT_EQ_WAIT(talk_base::WE_RESTORE, catcher.event(), kTimeoutMs);
2458 screencapture_factory->window_capturer()->SignalStateChange(
2459 screencapture_factory->window_capturer(), cricket::CS_STOPPED);
2460 EXPECT_EQ_WAIT(talk_base::WE_CLOSE, catcher.event(), kTimeoutMs);
2461 EXPECT_TRUE(channel1_->RemoveScreencast(0));
2462 ASSERT_TRUE(screencapture_factory->window_capturer() == NULL);
2463}
2464
2465TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2466 Base::TestUpdateStreamsInLocalContent();
2467}
2468
2469TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2470 Base::TestUpdateStreamsInRemoteContent();
2471}
2472
2473TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2474 Base::TestChangeStreamParamsInContent();
2475}
2476
2477TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2478 Base::TestPlayoutAndSendingStates();
2479}
2480
2481TEST_F(VideoChannelTest, TestMuteStream) {
2482 Base::TestMuteStream();
2483}
2484
2485TEST_F(VideoChannelTest, TestMediaContentDirection) {
2486 Base::TestMediaContentDirection();
2487}
2488
2489TEST_F(VideoChannelTest, TestCallSetup) {
2490 Base::TestCallSetup();
2491}
2492
2493TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2494 Base::TestCallTeardownRtcpMux();
2495}
2496
2497TEST_F(VideoChannelTest, SendRtpToRtp) {
2498 Base::SendRtpToRtp();
2499}
2500
2501TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2502 Base::SendNoRtcpToNoRtcp();
2503}
2504
2505TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2506 Base::SendNoRtcpToRtcp();
2507}
2508
2509TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2510 Base::SendRtcpToNoRtcp();
2511}
2512
2513TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2514 Base::SendRtcpToRtcp();
2515}
2516
2517TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2518 Base::SendRtcpMuxToRtcp();
2519}
2520
2521TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2522 Base::SendRtcpMuxToRtcpMux();
2523}
2524
2525TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2526 Base::SendEarlyRtcpMuxToRtcp();
2527}
2528
2529TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2530 Base::SendEarlyRtcpMuxToRtcpMux();
2531}
2532
2533TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2534 Base::SendSrtpToSrtp();
2535}
2536
2537TEST_F(VideoChannelTest, SendSrtpToRtp) {
2538 Base::SendSrtpToSrtp();
2539}
2540
2541TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2542 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2543 Base::SendSrtpToSrtp(DTLS, 0);
2544}
2545
2546TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2547 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2548 Base::SendSrtpToSrtp(DTLS, DTLS);
2549}
2550
2551TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2552 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2553 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2554}
2555
2556TEST_F(VideoChannelTest, SendSrtcpMux) {
2557 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2558}
2559
2560TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2561 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2562}
2563
2564TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2565 Base::SendRtpToRtpOnThread();
2566}
2567
2568TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2569 Base::SendSrtpToSrtpOnThread();
2570}
2571
2572TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2573 Base::SendWithWritabilityLoss();
2574}
2575
2576TEST_F(VideoChannelTest, TestMediaMonitor) {
2577 Base::TestMediaMonitor();
2578}
2579
2580TEST_F(VideoChannelTest, TestMediaSinks) {
2581 Base::TestMediaSinks();
2582}
2583
2584TEST_F(VideoChannelTest, TestSetContentFailure) {
2585 Base::TestSetContentFailure();
2586}
2587
2588TEST_F(VideoChannelTest, TestSendTwoOffers) {
2589 Base::TestSendTwoOffers();
2590}
2591
2592TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2593 Base::TestReceiveTwoOffers();
2594}
2595
2596TEST_F(VideoChannelTest, TestSendPrAnswer) {
2597 Base::TestSendPrAnswer();
2598}
2599
2600TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2601 Base::TestReceivePrAnswer();
2602}
2603
2604TEST_F(VideoChannelTest, TestFlushRtcp) {
2605 Base::TestFlushRtcp();
2606}
2607
2608TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMux) {
2609 Base::SendSsrcMuxToSsrcMux();
2610}
2611
2612TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) {
2613 Base::SendSsrcMuxToSsrcMuxWithRtcpMux();
2614}
2615
2616// TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2617
2618TEST_F(VideoChannelTest, TestSrtpError) {
2619 Base::TestSrtpError();
2620}
2621
2622TEST_F(VideoChannelTest, TestOnReadyToSend) {
2623 Base::TestOnReadyToSend();
2624}
2625
2626TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2627 Base::TestOnReadyToSendWithRtcpMux();
2628}
2629
2630TEST_F(VideoChannelTest, TestApplyViewRequest) {
2631 CreateChannels(0, 0);
2632 cricket::StreamParams stream2;
2633 stream2.id = "stream2";
2634 stream2.ssrcs.push_back(2222);
2635 local_media_content1_.AddStream(stream2);
2636
2637 EXPECT_TRUE(SendInitiate());
2638 EXPECT_TRUE(SendAccept());
2639
2640 cricket::VideoFormat send_format;
2641 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2642 EXPECT_EQ(640, send_format.width);
2643 EXPECT_EQ(400, send_format.height);
2644 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2645
2646 cricket::ViewRequest request;
2647 // stream1: 320x200x15; stream2: 0x0x0
2648 request.static_video_views.push_back(cricket::StaticVideoView(
2649 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2650 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2651 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2652 EXPECT_EQ(320, send_format.width);
2653 EXPECT_EQ(200, send_format.height);
2654 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2655 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2656 EXPECT_EQ(0, send_format.width);
2657 EXPECT_EQ(0, send_format.height);
2658
2659 // stream1: 160x100x8; stream2: 0x0x0
2660 request.static_video_views.clear();
2661 request.static_video_views.push_back(cricket::StaticVideoView(
2662 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2663 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2664 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2665 EXPECT_EQ(160, send_format.width);
2666 EXPECT_EQ(100, send_format.height);
2667 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2668
2669 // stream1: 0x0x0; stream2: 640x400x30
2670 request.static_video_views.clear();
2671 request.static_video_views.push_back(cricket::StaticVideoView(
2672 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2673 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2674 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2675 EXPECT_EQ(0, send_format.width);
2676 EXPECT_EQ(0, send_format.height);
2677 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2678 EXPECT_EQ(640, send_format.width);
2679 EXPECT_EQ(400, send_format.height);
2680 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2681
2682 // stream1: 0x0x0; stream2: 0x0x0
2683 request.static_video_views.clear();
2684 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2685 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2686 EXPECT_EQ(0, send_format.width);
2687 EXPECT_EQ(0, send_format.height);
2688}
2689
2690TEST_F(VideoChannelTest, TestSetChannelOptions) {
2691 TestSetChannelOptions();
2692}
2693
2694
2695// DataChannelTest
2696
2697class DataChannelTest
2698 : public ChannelTest<DataTraits> {
2699 public:
2700 typedef ChannelTest<DataTraits>
2701 Base;
2702 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2703 kRtcpReport, sizeof(kRtcpReport)) {
2704 }
2705};
2706
2707// Override to avoid engine channel parameter.
2708template<>
2709cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
2710 talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
2711 cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2712 bool rtcp) {
2713 cricket::DataChannel* channel = new cricket::DataChannel(
2714 thread, ch, session, cricket::CN_DATA, rtcp);
2715 if (!channel->Init()) {
2716 delete channel;
2717 channel = NULL;
2718 }
2719 return channel;
2720}
2721
2722template<>
2723void ChannelTest<DataTraits>::CreateContent(
2724 int flags,
2725 const cricket::AudioCodec& audio_codec,
2726 const cricket::VideoCodec& video_codec,
2727 cricket::DataContentDescription* data) {
2728 data->AddCodec(kGoogleDataCodec);
2729 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2730 if (flags & SECURE) {
2731 data->AddCrypto(cricket::CryptoParams(
2732 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
2733 "inline:" + talk_base::CreateRandomString(40), ""));
2734 }
2735}
2736
2737template<>
2738void ChannelTest<DataTraits>::CopyContent(
2739 const cricket::DataContentDescription& source,
2740 cricket::DataContentDescription* data) {
2741 *data = source;
2742}
2743
2744template<>
2745bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2746 const cricket::DataCodec& c2) {
2747 return c1.name == c2.name;
2748}
2749
2750template<>
2751void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2752 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2753 data->AddLegacyStream(ssrc);
2754}
2755
2756TEST_F(DataChannelTest, TestInit) {
2757 Base::TestInit();
2758 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2759}
2760
2761TEST_F(DataChannelTest, TestSetContents) {
2762 Base::TestSetContents();
2763}
2764
2765TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2766 Base::TestSetContentsNullOffer();
2767}
2768
2769TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2770 Base::TestSetContentsRtcpMux();
2771}
2772
2773TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2774 Base::TestSetRemoteContentUpdate();
2775}
2776
2777TEST_F(DataChannelTest, TestStreams) {
2778 Base::TestStreams();
2779}
2780
2781TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2782 Base::TestUpdateStreamsInLocalContent();
2783}
2784
2785TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2786 Base::TestUpdateStreamsInRemoteContent();
2787}
2788
2789TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2790 Base::TestChangeStreamParamsInContent();
2791}
2792
2793TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2794 Base::TestPlayoutAndSendingStates();
2795}
2796
2797TEST_F(DataChannelTest, TestMediaContentDirection) {
2798 Base::TestMediaContentDirection();
2799}
2800
2801TEST_F(DataChannelTest, TestCallSetup) {
2802 Base::TestCallSetup();
2803}
2804
2805TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2806 Base::TestCallTeardownRtcpMux();
2807}
2808
2809TEST_F(DataChannelTest, TestOnReadyToSend) {
2810 Base::TestOnReadyToSend();
2811}
2812
2813TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2814 Base::TestOnReadyToSendWithRtcpMux();
2815}
2816
2817TEST_F(DataChannelTest, SendRtpToRtp) {
2818 Base::SendRtpToRtp();
2819}
2820
2821TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2822 Base::SendNoRtcpToNoRtcp();
2823}
2824
2825TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2826 Base::SendNoRtcpToRtcp();
2827}
2828
2829TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2830 Base::SendRtcpToNoRtcp();
2831}
2832
2833TEST_F(DataChannelTest, SendRtcpToRtcp) {
2834 Base::SendRtcpToRtcp();
2835}
2836
2837TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2838 Base::SendRtcpMuxToRtcp();
2839}
2840
2841TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2842 Base::SendRtcpMuxToRtcpMux();
2843}
2844
2845TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2846 Base::SendEarlyRtcpMuxToRtcp();
2847}
2848
2849TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2850 Base::SendEarlyRtcpMuxToRtcpMux();
2851}
2852
2853TEST_F(DataChannelTest, SendSrtpToSrtp) {
2854 Base::SendSrtpToSrtp();
2855}
2856
2857TEST_F(DataChannelTest, SendSrtpToRtp) {
2858 Base::SendSrtpToSrtp();
2859}
2860
2861TEST_F(DataChannelTest, SendSrtcpMux) {
2862 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2863}
2864
2865TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2866 Base::SendRtpToRtpOnThread();
2867}
2868
2869TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2870 Base::SendSrtpToSrtpOnThread();
2871}
2872
2873TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2874 Base::SendWithWritabilityLoss();
2875}
2876
2877TEST_F(DataChannelTest, TestMediaMonitor) {
2878 Base::TestMediaMonitor();
2879}
2880
2881TEST_F(DataChannelTest, TestSendData) {
2882 CreateChannels(0, 0);
2883 EXPECT_TRUE(SendInitiate());
2884 EXPECT_TRUE(SendAccept());
2885
2886 cricket::SendDataParams params;
2887 params.ssrc = 42;
2888 unsigned char data[] = {
2889 'f', 'o', 'o'
2890 };
2891 talk_base::Buffer payload(data, 3);
2892 cricket::SendDataResult result;
2893 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2894 EXPECT_EQ(params.ssrc,
2895 media_channel1_->last_sent_data_params().ssrc);
2896 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2897}
2898
2899// TODO(pthatcher): TestSetReceiver?