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