2
// Copyright 2009 Google Inc.
4
// Redistribution and use in source and binary forms, with or without
5
// modification, are permitted provided that the following conditions are met:
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.
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.
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/p2p/base/fakesession.h"
33
#include "talk/session/phone/channel.h"
34
#include "talk/session/phone/fakemediaengine.h"
35
#include "talk/session/phone/fakertp.h"
36
#include "talk/session/phone/mediamessages.h"
37
#include "talk/session/phone/mediasessionclient.h"
38
#include "talk/session/phone/mediarecorder.h"
39
#include "talk/session/phone/rtpdump.h"
41
using cricket::CA_OFFER;
42
using cricket::CA_ANSWER;
43
using cricket::CA_UPDATE;
44
using cricket::StreamParams;
46
static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
47
static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
48
static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
49
static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
50
static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
51
static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
52
static const uint32 kSsrc1 = 0x1111;
53
static const uint32 kSsrc2 = 0x2222;
54
static const uint32 kSsrc3 = 0x3333;
55
static const char kCName[] = "a@b.com";
57
template<class ChannelT,
64
typedef ChannelT Channel;
65
typedef MediaChannelT MediaChannel;
66
typedef ContentT Content;
68
typedef MediaInfoT MediaInfo;
71
class VoiceTraits : public Traits<cricket::VoiceChannel,
72
cricket::FakeVoiceMediaChannel,
73
cricket::AudioContentDescription,
75
cricket::VoiceMediaInfo> {
78
class VideoTraits : public Traits<cricket::VideoChannel,
79
cricket::FakeVideoMediaChannel,
80
cricket::VideoContentDescription,
82
cricket::VideoMediaInfo> {
85
class DataTraits : public Traits<cricket::DataChannel,
86
cricket::FakeDataMediaChannel,
87
cricket::DataContentDescription,
89
cricket::DataMediaInfo> {
92
// Base class for Voice/VideoChannel tests
94
class ChannelTest : public testing::Test, public sigslot::has_slots<> {
96
enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8 };
97
ChannelTest(const uint8* rtp_data, int rtp_len,
98
const uint8* rtcp_data, int rtcp_len)
99
: media_channel1_(NULL),
100
media_channel2_(NULL),
101
rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
102
rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
103
media_info_callbacks1_(),
104
media_info_callbacks2_(),
106
error_(T::MediaChannel::ERROR_NONE) {
109
void CreateChannels(int flags1, int flags2) {
110
CreateChannels(new typename T::MediaChannel(NULL),
111
new typename T::MediaChannel(NULL),
112
flags1, flags2, talk_base::Thread::Current());
114
void CreateChannels(int flags) {
115
CreateChannels(new typename T::MediaChannel(NULL),
116
new typename T::MediaChannel(NULL),
117
flags, talk_base::Thread::Current());
119
void CreateChannels(int flags1, int flags2,
120
talk_base::Thread* thread) {
121
CreateChannels(new typename T::MediaChannel(NULL),
122
new typename T::MediaChannel(NULL),
123
flags1, flags2, thread);
125
void CreateChannels(int flags,
126
talk_base::Thread* thread) {
127
CreateChannels(new typename T::MediaChannel(NULL),
128
new typename T::MediaChannel(NULL),
132
typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
133
int flags1, int flags2, talk_base::Thread* thread) {
134
media_channel1_ = ch1;
135
media_channel2_ = ch2;
136
channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
137
(flags1 & RTCP) != 0));
138
channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
139
(flags2 & RTCP) != 0));
140
channel1_->SignalMediaMonitor.connect(
141
this, &ChannelTest<T>::OnMediaMonitor);
142
channel2_->SignalMediaMonitor.connect(
143
this, &ChannelTest<T>::OnMediaMonitor);
144
channel1_->SignalMediaError.connect(
145
this, &ChannelTest<T>::OnMediaChannelError);
146
channel2_->SignalMediaError.connect(
147
this, &ChannelTest<T>::OnMediaChannelError);
148
CreateContent(flags1, kPcmuCodec, kH264Codec,
149
&local_media_content1_);
150
CreateContent(flags2, kPcmuCodec, kH264Codec,
151
&local_media_content2_);
152
CopyContent(local_media_content1_, &remote_media_content1_);
153
CopyContent(local_media_content2_, &remote_media_content2_);
154
// Add stream information (SSRC) to the local content but not to the remote
155
// content. This means that we per default know the SSRC of what we send but
156
// not what we receive.
157
AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
158
AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
160
// If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
161
if (flags1 & SSRC_MUX) {
162
AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
164
if (flags2 & SSRC_MUX) {
165
AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
170
typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
171
int flags, talk_base::Thread* thread) {
172
media_channel1_ = ch1;
173
media_channel2_ = ch2;
174
channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
175
(flags & RTCP) != 0));
176
channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
177
(flags & RTCP) != 0));
178
channel1_->SignalMediaMonitor.connect(
179
this, &ChannelTest<T>::OnMediaMonitor);
180
channel2_->SignalMediaMonitor.connect(
181
this, &ChannelTest<T>::OnMediaMonitor);
182
channel2_->SignalMediaError.connect(
183
this, &ChannelTest<T>::OnMediaChannelError);
184
CreateContent(flags, kPcmuCodec, kH264Codec,
185
&local_media_content1_);
186
CreateContent(flags, kPcmuCodec, kH264Codec,
187
&local_media_content2_);
188
CopyContent(local_media_content1_, &remote_media_content1_);
189
CopyContent(local_media_content2_, &remote_media_content2_);
190
// Add stream information (SSRC) to the local content but not to the remote
191
// content. This means that we per default know the SSRC of what we send but
192
// not what we receive.
193
AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
194
AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
196
// If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
197
if (flags & SSRC_MUX) {
198
AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
199
AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
203
typename T::Channel* CreateChannel(talk_base::Thread* thread,
204
cricket::MediaEngineInterface* engine,
205
typename T::MediaChannel* ch,
206
cricket::BaseSession* session,
208
typename T::Channel* channel = new typename T::Channel(
209
thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
210
if (!channel->Init()) {
217
bool SendInitiate() {
218
bool result = channel1_->SetLocalContent(&local_media_content1_, CA_OFFER);
220
channel1_->Enable(true);
221
result = channel2_->SetRemoteContent(&remote_media_content1_, CA_OFFER);
223
result = channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER);
225
session1_.Connect(&session2_);
232
channel2_->Enable(true);
233
return channel1_->SetRemoteContent(&remote_media_content2_, CA_ANSWER);
235
bool SendTerminate() {
241
bool AddStream1(int id) {
242
return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
244
bool RemoveStream1(int id) {
245
return channel1_->RemoveRecvStream(id);
248
cricket::FakeTransport* GetTransport1() {
249
return session1_.GetTransport(channel1_->content_name());
251
cricket::FakeTransport* GetTransport2() {
252
return session2_.GetTransport(channel2_->content_name());
256
return media_channel1_->SendRtp(rtp_packet_.c_str(), rtp_packet_.size());
259
return media_channel2_->SendRtp(rtp_packet_.c_str(), rtp_packet_.size());
262
return media_channel1_->SendRtcp(rtcp_packet_.c_str(), rtcp_packet_.size());
265
return media_channel2_->SendRtcp(rtcp_packet_.c_str(), rtcp_packet_.size());
267
// Methods to send custom data.
268
bool SendCustomRtp1(uint32 ssrc) {
269
std::string data(CreateRtpData(ssrc));
270
return media_channel1_->SendRtp(data.c_str(), data.size());
272
bool SendCustomRtp2(uint32 ssrc) {
273
std::string data(CreateRtpData(ssrc));
274
return media_channel2_->SendRtp(data.c_str(), data.size());
276
bool SendCustomRtcp1(uint32 ssrc) {
277
std::string data(CreateRtcpData(ssrc));
278
return media_channel1_->SendRtcp(data.c_str(), data.size());
280
bool SendCustomRtcp2(uint32 ssrc) {
281
std::string data(CreateRtcpData(ssrc));
282
return media_channel2_->SendRtcp(data.c_str(), data.size());
285
return media_channel1_->CheckRtp(rtp_packet_.c_str(), rtp_packet_.size());
288
return media_channel2_->CheckRtp(rtp_packet_.c_str(), rtp_packet_.size());
291
return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
292
rtcp_packet_.size());
295
return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
296
rtcp_packet_.size());
298
// Methods to check custom data.
299
bool CheckCustomRtp1(uint32 ssrc) {
300
std::string data(CreateRtpData(ssrc));
301
return media_channel1_->CheckRtp(data.c_str(), data.size());
303
bool CheckCustomRtp2(uint32 ssrc) {
304
std::string data(CreateRtpData(ssrc));
305
return media_channel2_->CheckRtp(data.c_str(), data.size());
307
bool CheckCustomRtcp1(uint32 ssrc) {
308
std::string data(CreateRtcpData(ssrc));
309
return media_channel1_->CheckRtcp(data.c_str(), data.size());
311
bool CheckCustomRtcp2(uint32 ssrc) {
312
std::string data(CreateRtcpData(ssrc));
313
return media_channel2_->CheckRtcp(data.c_str(), data.size());
315
std::string CreateRtpData(uint32 ssrc) {
316
std::string data(rtp_packet_);
317
// Set SSRC in the rtp packet copy.
318
talk_base::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
321
std::string CreateRtcpData(uint32 ssrc) {
322
std::string data(rtcp_packet_);
323
// Set SSRC in the rtcp packet copy.
324
talk_base::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
329
return media_channel1_->CheckNoRtp();
332
return media_channel2_->CheckNoRtp();
334
bool CheckNoRtcp1() {
335
return media_channel1_->CheckNoRtcp();
337
bool CheckNoRtcp2() {
338
return media_channel2_->CheckNoRtcp();
341
void CreateContent(int flags,
342
const cricket::AudioCodec& audio_codec,
343
const cricket::VideoCodec& video_codec,
344
typename T::Content* content) {
345
// overridden in specialized classes
347
void CopyContent(const typename T::Content& source,
348
typename T::Content* content) {
349
// overridden in specialized classes
352
class CallThread : public talk_base::SignalThread {
354
typedef bool (ChannelTest<T>::*Method)();
355
CallThread(ChannelTest<T>* obj, Method method, bool* result)
361
virtual void DoWork() {
362
bool result = (*obj_.*method_)();
368
ChannelTest<T>* obj_;
372
void CallOnThread(typename CallThread::Method method, bool* result) {
373
CallThread* thread = new CallThread(this, method, result);
378
void CallOnThreadAndWaitForDone(typename CallThread::Method method,
380
CallThread* thread = new CallThread(this, method, result);
382
thread->Destroy(true);
385
bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
386
return false; // overridden in specialized classes
389
void OnMediaMonitor(typename T::Channel* channel,
390
const typename T::MediaInfo& info) {
391
if (channel == channel1_.get()) {
392
media_info_callbacks1_++;
393
} else if (channel == channel2_.get()) {
394
media_info_callbacks2_++;
398
void OnMediaChannelError(typename T::Channel* channel,
400
typename T::MediaChannel::Error error) {
405
void AddLegacyStreamInContent(uint32 ssrc, int flags,
406
typename T::Content* content) {
407
// Base implementation.
410
// Tests that can be used by derived classes.
412
// Basic sanity check.
414
CreateChannels(0, 0);
415
EXPECT_FALSE(channel1_->secure());
416
EXPECT_FALSE(media_channel1_->sending());
417
EXPECT_FALSE(media_channel1_->playout());
418
EXPECT_TRUE(media_channel1_->codecs().empty());
419
EXPECT_TRUE(media_channel1_->recv_streams().empty());
420
EXPECT_TRUE(media_channel1_->rtp_packets().empty());
421
EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
424
// Test that SetLocalContent and SetRemoteContent properly configure
426
void TestSetContents() {
427
CreateChannels(0, 0);
428
typename T::Content content;
429
CreateContent(0, kPcmuCodec, kH264Codec, &content);
430
EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
431
EXPECT_EQ(0U, media_channel1_->codecs().size());
432
EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
433
ASSERT_EQ(1U, media_channel1_->codecs().size());
434
EXPECT_TRUE(CodecMatches(content.codecs()[0],
435
media_channel1_->codecs()[0]));
438
// Test that SetLocalContent and SetRemoteContent properly deals
439
// with an empty offer.
440
void TestSetContentsNullOffer() {
441
CreateChannels(0, 0);
442
typename T::Content content;
443
EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
444
CreateContent(0, kPcmuCodec, kH264Codec, &content);
445
EXPECT_EQ(0U, media_channel1_->codecs().size());
446
EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
447
ASSERT_EQ(1U, media_channel1_->codecs().size());
448
EXPECT_TRUE(CodecMatches(content.codecs()[0],
449
media_channel1_->codecs()[0]));
452
// Test that SetLocalContent and SetRemoteContent properly set RTCP
454
void TestSetContentsRtcpMux() {
455
CreateChannels(RTCP, RTCP);
456
EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
457
EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
458
typename T::Content content;
459
CreateContent(0, kPcmuCodec, kH264Codec, &content);
460
// Both sides agree on mux. Should no longer be a separate RTCP channel.
461
content.set_rtcp_mux(true);
462
EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
463
EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
464
EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
465
// Only initiator supports mux. Should still have a separate RTCP channel.
466
EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER));
467
content.set_rtcp_mux(false);
468
EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER));
469
EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
472
// Test that SetRemoteContent properly deals with a content update.
473
void TestSetRemoteContentUpdate() {
474
CreateChannels(0, 0);
475
typename T::Content content;
476
CreateContent(RTCP | RTCP_MUX | SECURE,
477
kPcmuCodec, kH264Codec,
479
EXPECT_EQ(0U, media_channel1_->codecs().size());
480
EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER));
481
EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER));
482
ASSERT_EQ(1U, media_channel1_->codecs().size());
483
EXPECT_TRUE(CodecMatches(content.codecs()[0],
484
media_channel1_->codecs()[0]));
485
// Now update with other codecs.
486
typename T::Content update_content;
487
update_content.set_partial(true);
488
CreateContent(0, kIsacCodec, kH264SvcCodec,
490
EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE));
491
ASSERT_EQ(1U, media_channel1_->codecs().size());
492
EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
493
media_channel1_->codecs()[0]));
494
// Now update without any codecs. This is ignored.
495
typename T::Content empty_content;
496
empty_content.set_partial(true);
497
EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE));
498
ASSERT_EQ(1U, media_channel1_->codecs().size());
499
EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
500
media_channel1_->codecs()[0]));
503
// Test that Add/RemoveStream properly forward to the media channel.
505
CreateChannels(0, 0);
506
EXPECT_TRUE(AddStream1(1));
507
EXPECT_TRUE(AddStream1(2));
508
EXPECT_EQ(2U, media_channel1_->recv_streams().size());
509
EXPECT_TRUE(RemoveStream1(2));
510
EXPECT_EQ(1U, media_channel1_->recv_streams().size());
511
EXPECT_TRUE(RemoveStream1(1));
512
EXPECT_EQ(0U, media_channel1_->recv_streams().size());
515
// Test that SetLocalContent properly handles adding and removing StreamParams
516
// to the local content description.
517
// This test uses the CA_UPDATE action that don't require a full
518
// MediaContentDescription to do an update.
519
void TestUpdateStreamsInLocalContent() {
520
cricket::StreamParams stream1;
521
stream1.name = "Stream1";
523
stream1.ssrcs.push_back(kSsrc1);
524
stream1.cname = "stream1_cname";
526
cricket::StreamParams stream2;
527
stream2.name = "Stream2";
529
stream2.ssrcs.push_back(kSsrc2);
530
stream2.cname = "stream2_cname";
532
cricket::StreamParams stream3;
533
stream3.name = "Stream3";
535
stream3.ssrcs.push_back(kSsrc3);
536
stream3.cname = "stream3_cname";
538
CreateChannels(0, 0);
539
typename T::Content content1;
540
CreateContent(0, kPcmuCodec, kH264Codec, &content1);
541
content1.AddStream(stream1);
542
EXPECT_EQ(0u, media_channel1_->send_streams().size());
543
EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER));
545
ASSERT_EQ(1u, media_channel1_->send_streams().size());
546
EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
548
// Update the local streams by adding another sending stream.
549
// Use a partial updated session description.
550
typename T::Content content2;
551
content2.AddStream(stream2);
552
content2.AddStream(stream3);
553
content2.set_partial(true);
554
EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE));
555
ASSERT_EQ(3u, media_channel1_->send_streams().size());
556
EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
557
EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
558
EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
560
// Update the local streams by removing the first sending stream.
561
// This is done by removing all SSRCS for this particular stream.
562
typename T::Content content3;
563
stream1.ssrcs.clear();
564
content3.AddStream(stream1);
565
content3.set_partial(true);
566
EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE));
567
ASSERT_EQ(2u, media_channel1_->send_streams().size());
568
EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
569
EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
571
// Update the local streams with a stream that does not change.
572
// THe update is ignored.
573
typename T::Content content4;
574
content4.AddStream(stream2);
575
content4.set_partial(true);
576
EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE));
577
ASSERT_EQ(2u, media_channel1_->send_streams().size());
578
EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
579
EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
582
// Test that SetRemoteContent properly handles adding and removing
583
// StreamParams to the remote content description.
584
// This test uses the CA_UPDATE action that don't require a full
585
// MediaContentDescription to do an update.
586
void TestUpdateStreamsInRemoteContent() {
587
cricket::StreamParams stream1;
588
stream1.name = "Stream1";
590
stream1.ssrcs.push_back(kSsrc1);
591
stream1.cname = "stream1_cname";
593
cricket::StreamParams stream2;
594
stream2.name = "Stream2";
596
stream2.ssrcs.push_back(kSsrc2);
597
stream2.cname = "stream2_cname";
599
cricket::StreamParams stream3;
600
stream3.name = "Stream3";
602
stream3.ssrcs.push_back(kSsrc3);
603
stream3.cname = "stream3_cname";
605
CreateChannels(0, 0);
606
typename T::Content content1;
607
CreateContent(0, kPcmuCodec, kH264Codec, &content1);
608
content1.AddStream(stream1);
609
EXPECT_EQ(0u, media_channel1_->recv_streams().size());
610
EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER));
612
ASSERT_EQ(1u, media_channel1_->codecs().size());
613
ASSERT_EQ(1u, media_channel1_->recv_streams().size());
614
EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
616
// Update the remote streams by adding another sending stream.
617
// Use a partial updated session description.
618
typename T::Content content2;
619
content2.AddStream(stream2);
620
content2.AddStream(stream3);
621
content2.set_partial(true);
622
EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE));
623
ASSERT_EQ(3u, media_channel1_->recv_streams().size());
624
EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
625
EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
626
EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
628
// Update the remote streams by removing the first stream.
629
// This is done by removing all SSRCS for this particular stream.
630
typename T::Content content3;
631
stream1.ssrcs.clear();
632
content3.AddStream(stream1);
633
content3.set_partial(true);
634
EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE));
635
ASSERT_EQ(2u, media_channel1_->recv_streams().size());
636
EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
637
EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
639
// Update the remote streams with a stream that does not change.
640
// The update is ignored.
641
typename T::Content content4;
642
content4.AddStream(stream2);
643
content4.set_partial(true);
644
EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE));
645
ASSERT_EQ(2u, media_channel1_->recv_streams().size());
646
EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
647
EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
650
// Test that SetLocalContent and SetRemoteContent properly
651
// handles adding and removing StreamParams when the action is a full
652
// CA_OFFER / CA_ANSWER.
653
void TestChangeStreamParamsInContent() {
654
cricket::StreamParams stream1;
655
stream1.name = "Stream1";
656
stream1.ssrcs.push_back(kSsrc1);
657
stream1.cname = "stream1_cname";
659
cricket::StreamParams stream2;
660
stream2.name = "Stream2";
661
stream2.ssrcs.push_back(kSsrc2);
662
stream2.cname = "stream2_cname";
664
// Setup a call where channel 1 send |stream1| to channel 2.
665
CreateChannels(0, 0);
666
typename T::Content content1;
667
CreateContent(0, kPcmuCodec, kH264Codec, &content1);
668
content1.AddStream(stream1);
669
EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER));
670
EXPECT_TRUE(channel1_->Enable(true));
671
EXPECT_EQ(1u, media_channel1_->send_streams().size());
673
EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER));
674
EXPECT_EQ(1u, media_channel2_->recv_streams().size());
675
session1_.Connect(&session2_);
677
// Channel 2 do not send anything.
678
typename T::Content content2;
679
CreateContent(0, kPcmuCodec, kH264Codec, &content2);
680
EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER));
681
EXPECT_EQ(0u, media_channel1_->recv_streams().size());
682
EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER));
683
EXPECT_TRUE(channel2_->Enable(true));
684
EXPECT_EQ(0u, media_channel2_->send_streams().size());
686
EXPECT_TRUE(SendCustomRtp1(kSsrc1));
687
EXPECT_TRUE(CheckCustomRtp2(kSsrc1));
689
// Let channel 2 update the content by sending |stream2| and enable SRTP.
690
typename T::Content content3;
691
CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
692
content3.AddStream(stream2);
693
EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER));
694
ASSERT_EQ(1u, media_channel2_->send_streams().size());
695
EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
697
EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER));
698
ASSERT_EQ(1u, media_channel1_->recv_streams().size());
699
EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
701
// Channel 1 replies but stop sending stream1.
702
typename T::Content content4;
703
CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
704
EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER));
705
EXPECT_EQ(0u, media_channel1_->send_streams().size());
707
EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER));
708
EXPECT_EQ(0u, media_channel2_->recv_streams().size());
710
EXPECT_TRUE(channel1_->secure());
711
EXPECT_TRUE(channel2_->secure());
712
EXPECT_TRUE(SendCustomRtp2(kSsrc2));
713
EXPECT_TRUE(CheckCustomRtp1(kSsrc2));
716
// Test that we only start playout and sending at the right times.
717
void TestPlayoutAndSendingStates() {
718
CreateChannels(0, 0);
719
EXPECT_FALSE(media_channel1_->playout());
720
EXPECT_FALSE(media_channel1_->sending());
721
EXPECT_FALSE(media_channel2_->playout());
722
EXPECT_FALSE(media_channel2_->sending());
723
EXPECT_TRUE(channel1_->Enable(true));
724
EXPECT_FALSE(media_channel1_->playout());
725
EXPECT_FALSE(media_channel1_->sending());
726
EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_, CA_OFFER));
727
EXPECT_TRUE(media_channel1_->playout());
728
EXPECT_FALSE(media_channel1_->sending());
729
EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_, CA_OFFER));
730
EXPECT_FALSE(media_channel2_->playout());
731
EXPECT_FALSE(media_channel2_->sending());
732
EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_, CA_ANSWER));
733
EXPECT_FALSE(media_channel2_->playout());
734
EXPECT_FALSE(media_channel2_->sending());
735
session1_.Connect(&session2_);
736
EXPECT_TRUE(media_channel1_->playout());
737
EXPECT_FALSE(media_channel1_->sending());
738
EXPECT_FALSE(media_channel2_->playout());
739
EXPECT_FALSE(media_channel2_->sending());
740
EXPECT_TRUE(channel2_->Enable(true));
741
EXPECT_TRUE(media_channel2_->playout());
742
EXPECT_TRUE(media_channel2_->sending());
743
EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_, CA_ANSWER));
744
EXPECT_TRUE(media_channel1_->playout());
745
EXPECT_TRUE(media_channel1_->sending());
748
// Test setting up a call.
749
void TestCallSetup() {
750
CreateChannels(0, 0);
751
EXPECT_FALSE(channel1_->secure());
752
EXPECT_TRUE(SendInitiate());
753
EXPECT_TRUE(media_channel1_->playout());
754
EXPECT_FALSE(media_channel1_->sending());
755
EXPECT_TRUE(SendAccept());
756
EXPECT_FALSE(channel1_->secure());
757
EXPECT_TRUE(media_channel1_->sending());
758
EXPECT_EQ(1U, media_channel1_->codecs().size());
759
EXPECT_TRUE(media_channel2_->playout());
760
EXPECT_TRUE(media_channel2_->sending());
761
EXPECT_EQ(1U, media_channel2_->codecs().size());
764
// Test that we don't crash if packets are sent during call teardown
765
// when RTCP mux is enabled. This is a regression test against a specific
766
// race condition that would only occur when a RTCP packet was sent during
767
// teardown of a channel on which RTCP mux was enabled.
768
void TestCallTeardownRtcpMux() {
769
class LastWordMediaChannel : public T::MediaChannel {
771
LastWordMediaChannel() : T::MediaChannel(NULL) {}
772
~LastWordMediaChannel() {
773
T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
774
T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
777
CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
778
RTCP | RTCP_MUX, RTCP | RTCP_MUX,
779
talk_base::Thread::Current());
780
EXPECT_TRUE(SendInitiate());
781
EXPECT_TRUE(SendAccept());
782
EXPECT_TRUE(SendTerminate());
785
// Send voice RTP data to the other side and ensure it gets there.
786
void SendRtpToRtp() {
787
CreateChannels(0, 0);
788
EXPECT_TRUE(SendInitiate());
789
EXPECT_TRUE(SendAccept());
790
EXPECT_EQ(1U, GetTransport1()->channels().size());
791
EXPECT_EQ(1U, GetTransport2()->channels().size());
792
EXPECT_TRUE(SendRtp1());
793
EXPECT_TRUE(SendRtp2());
794
EXPECT_TRUE(CheckRtp1());
795
EXPECT_TRUE(CheckRtp2());
796
EXPECT_TRUE(CheckNoRtp1());
797
EXPECT_TRUE(CheckNoRtp2());
800
// Check that RTCP is not transmitted if both sides don't support RTCP.
801
void SendNoRtcpToNoRtcp() {
802
CreateChannels(0, 0);
803
EXPECT_TRUE(SendInitiate());
804
EXPECT_TRUE(SendAccept());
805
EXPECT_EQ(1U, GetTransport1()->channels().size());
806
EXPECT_EQ(1U, GetTransport2()->channels().size());
807
EXPECT_FALSE(SendRtcp1());
808
EXPECT_FALSE(SendRtcp2());
809
EXPECT_TRUE(CheckNoRtcp1());
810
EXPECT_TRUE(CheckNoRtcp2());
813
// Check that RTCP is not transmitted if the callee doesn't support RTCP.
814
void SendNoRtcpToRtcp() {
815
CreateChannels(0, RTCP);
816
EXPECT_TRUE(SendInitiate());
817
EXPECT_TRUE(SendAccept());
818
EXPECT_EQ(1U, GetTransport1()->channels().size());
819
EXPECT_EQ(2U, GetTransport2()->channels().size());
820
EXPECT_FALSE(SendRtcp1());
821
EXPECT_FALSE(SendRtcp2());
822
EXPECT_TRUE(CheckNoRtcp1());
823
EXPECT_TRUE(CheckNoRtcp2());
826
// Check that RTCP is not transmitted if the caller doesn't support RTCP.
827
void SendRtcpToNoRtcp() {
828
CreateChannels(RTCP, 0);
829
EXPECT_TRUE(SendInitiate());
830
EXPECT_TRUE(SendAccept());
831
EXPECT_EQ(2U, GetTransport1()->channels().size());
832
EXPECT_EQ(1U, GetTransport2()->channels().size());
833
EXPECT_FALSE(SendRtcp1());
834
EXPECT_FALSE(SendRtcp2());
835
EXPECT_TRUE(CheckNoRtcp1());
836
EXPECT_TRUE(CheckNoRtcp2());
839
// Check that RTCP is transmitted if both sides support RTCP.
840
void SendRtcpToRtcp() {
841
CreateChannels(RTCP, RTCP);
842
EXPECT_TRUE(SendInitiate());
843
EXPECT_TRUE(SendAccept());
844
EXPECT_EQ(2U, GetTransport1()->channels().size());
845
EXPECT_EQ(2U, GetTransport2()->channels().size());
846
EXPECT_TRUE(SendRtcp1());
847
EXPECT_TRUE(SendRtcp2());
848
EXPECT_TRUE(CheckRtcp1());
849
EXPECT_TRUE(CheckRtcp2());
850
EXPECT_TRUE(CheckNoRtcp1());
851
EXPECT_TRUE(CheckNoRtcp2());
854
// Check that RTCP is transmitted if only the initiator supports mux.
855
void SendRtcpMuxToRtcp() {
856
CreateChannels(RTCP | RTCP_MUX, RTCP);
857
EXPECT_TRUE(SendInitiate());
858
EXPECT_TRUE(SendAccept());
859
EXPECT_EQ(2U, GetTransport1()->channels().size());
860
EXPECT_EQ(2U, GetTransport2()->channels().size());
861
EXPECT_TRUE(SendRtcp1());
862
EXPECT_TRUE(SendRtcp2());
863
EXPECT_TRUE(CheckRtcp1());
864
EXPECT_TRUE(CheckRtcp2());
865
EXPECT_TRUE(CheckNoRtcp1());
866
EXPECT_TRUE(CheckNoRtcp2());
869
// Check that RTP and RTCP are transmitted ok when both sides support mux.
870
void SendRtcpMuxToRtcpMux() {
871
CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
872
EXPECT_TRUE(SendInitiate());
873
EXPECT_EQ(2U, GetTransport1()->channels().size());
874
EXPECT_EQ(1U, GetTransport2()->channels().size());
875
EXPECT_TRUE(SendAccept());
876
EXPECT_EQ(1U, GetTransport1()->channels().size());
877
EXPECT_TRUE(SendRtp1());
878
EXPECT_TRUE(SendRtp2());
879
EXPECT_TRUE(SendRtcp1());
880
EXPECT_TRUE(SendRtcp2());
881
EXPECT_TRUE(CheckRtp1());
882
EXPECT_TRUE(CheckRtp2());
883
EXPECT_TRUE(CheckNoRtp1());
884
EXPECT_TRUE(CheckNoRtp2());
885
EXPECT_TRUE(CheckRtcp1());
886
EXPECT_TRUE(CheckRtcp2());
887
EXPECT_TRUE(CheckNoRtcp1());
888
EXPECT_TRUE(CheckNoRtcp2());
891
// Check that RTCP data sent by the initiator before the accept is not muxed.
892
void SendEarlyRtcpMuxToRtcp() {
893
CreateChannels(RTCP | RTCP_MUX, RTCP);
894
EXPECT_TRUE(SendInitiate());
895
EXPECT_EQ(2U, GetTransport1()->channels().size());
896
EXPECT_EQ(2U, GetTransport2()->channels().size());
898
// RTCP can be sent before the call is accepted, if the transport is ready.
899
// It should not be muxed though, as the remote side doesn't support mux.
900
EXPECT_TRUE(SendRtcp1());
901
EXPECT_TRUE(CheckNoRtp2());
902
EXPECT_TRUE(CheckRtcp2());
904
// Send RTCP packet from callee and verify that it is received.
905
EXPECT_TRUE(SendRtcp2());
906
EXPECT_TRUE(CheckNoRtp1());
907
EXPECT_TRUE(CheckRtcp1());
909
// Complete call setup and ensure everything is still OK.
910
EXPECT_TRUE(SendAccept());
911
EXPECT_EQ(2U, GetTransport1()->channels().size());
912
EXPECT_TRUE(SendRtcp1());
913
EXPECT_TRUE(CheckRtcp2());
914
EXPECT_TRUE(SendRtcp2());
915
EXPECT_TRUE(CheckRtcp1());
919
// Check that RTCP data is not muxed until both sides have enabled muxing,
920
// but that we properly demux before we get the accept message, since there
921
// is a race between RTP data and the jingle accept.
922
void SendEarlyRtcpMuxToRtcpMux() {
923
CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
924
EXPECT_TRUE(SendInitiate());
925
EXPECT_EQ(2U, GetTransport1()->channels().size());
926
EXPECT_EQ(1U, GetTransport2()->channels().size());
928
// RTCP can't be sent yet, since the RTCP transport isn't writable, and
929
// we haven't yet received the accept that says we should mux.
930
EXPECT_FALSE(SendRtcp1());
932
// Send muxed RTCP packet from callee and verify that it is received.
933
EXPECT_TRUE(SendRtcp2());
934
EXPECT_TRUE(CheckNoRtp1());
935
EXPECT_TRUE(CheckRtcp1());
937
// Complete call setup and ensure everything is still OK.
938
EXPECT_TRUE(SendAccept());
939
EXPECT_EQ(1U, GetTransport1()->channels().size());
940
EXPECT_TRUE(SendRtcp1());
941
EXPECT_TRUE(CheckRtcp2());
942
EXPECT_TRUE(SendRtcp2());
943
EXPECT_TRUE(CheckRtcp1());
946
// Test that we properly send SRTP with RTCP in both directions.
947
void SendSrtpToSrtp() {
948
CreateChannels(RTCP | SECURE, RTCP | SECURE);
949
EXPECT_FALSE(channel1_->secure());
950
EXPECT_FALSE(channel2_->secure());
951
EXPECT_TRUE(SendInitiate());
952
EXPECT_TRUE(SendAccept());
953
EXPECT_TRUE(channel1_->secure());
954
EXPECT_TRUE(channel2_->secure());
955
EXPECT_TRUE(SendRtp1());
956
EXPECT_TRUE(SendRtp2());
957
EXPECT_TRUE(SendRtcp1());
958
EXPECT_TRUE(SendRtcp2());
959
EXPECT_TRUE(CheckRtp1());
960
EXPECT_TRUE(CheckRtp2());
961
EXPECT_TRUE(CheckNoRtp1());
962
EXPECT_TRUE(CheckNoRtp2());
963
EXPECT_TRUE(CheckRtcp1());
964
EXPECT_TRUE(CheckRtcp2());
965
EXPECT_TRUE(CheckNoRtcp1());
966
EXPECT_TRUE(CheckNoRtcp2());
969
// Test that we properly handling SRTP negotiating down to RTP.
970
void SendSrtpToRtp() {
971
CreateChannels(RTCP | SECURE, RTCP);
972
EXPECT_FALSE(channel1_->secure());
973
EXPECT_FALSE(channel2_->secure());
974
EXPECT_TRUE(SendInitiate());
975
EXPECT_TRUE(SendAccept());
976
EXPECT_FALSE(channel1_->secure());
977
EXPECT_FALSE(channel2_->secure());
978
EXPECT_TRUE(SendRtp1());
979
EXPECT_TRUE(SendRtp2());
980
EXPECT_TRUE(SendRtcp1());
981
EXPECT_TRUE(SendRtcp2());
982
EXPECT_TRUE(CheckRtp1());
983
EXPECT_TRUE(CheckRtp2());
984
EXPECT_TRUE(CheckNoRtp1());
985
EXPECT_TRUE(CheckNoRtp2());
986
EXPECT_TRUE(CheckRtcp1());
987
EXPECT_TRUE(CheckRtcp2());
988
EXPECT_TRUE(CheckNoRtcp1());
989
EXPECT_TRUE(CheckNoRtcp2());
992
// Test that we properly send SRTP with RTCP mux in both directions.
993
void SendSrtcpMux() {
994
CreateChannels(RTCP | RTCP_MUX | SECURE, RTCP | RTCP_MUX | SECURE);
995
EXPECT_TRUE(SendInitiate());
996
EXPECT_TRUE(SendAccept());
997
EXPECT_TRUE(SendRtp1());
998
EXPECT_TRUE(SendRtp2());
999
EXPECT_TRUE(SendRtcp1());
1000
EXPECT_TRUE(SendRtcp2());
1001
EXPECT_TRUE(CheckRtp1());
1002
EXPECT_TRUE(CheckRtp2());
1003
EXPECT_TRUE(CheckNoRtp1());
1004
EXPECT_TRUE(CheckNoRtp2());
1005
EXPECT_TRUE(CheckRtcp1());
1006
EXPECT_TRUE(CheckRtcp2());
1007
EXPECT_TRUE(CheckNoRtcp1());
1008
EXPECT_TRUE(CheckNoRtcp2());
1011
// Test that we properly send RTP without SRTP from a thread.
1012
void SendRtpToRtpOnThread() {
1013
bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1014
CreateChannels(RTCP, RTCP);
1015
EXPECT_TRUE(SendInitiate());
1016
EXPECT_TRUE(SendAccept());
1017
CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1018
CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1019
CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1020
CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1021
EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1022
EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1023
EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1024
EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1025
EXPECT_TRUE(CheckNoRtp1());
1026
EXPECT_TRUE(CheckNoRtp2());
1027
EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1028
EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1029
EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1030
EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1031
EXPECT_TRUE(CheckNoRtcp1());
1032
EXPECT_TRUE(CheckNoRtcp2());
1035
// Test that we properly send SRTP with RTCP from a thread.
1036
void SendSrtpToSrtpOnThread() {
1037
bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1038
CreateChannels(RTCP | SECURE, RTCP | SECURE);
1039
EXPECT_TRUE(SendInitiate());
1040
EXPECT_TRUE(SendAccept());
1041
CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1042
CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1043
CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1044
CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1045
EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1046
EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1047
EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1048
EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1049
EXPECT_TRUE(CheckNoRtp1());
1050
EXPECT_TRUE(CheckNoRtp2());
1051
EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1052
EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1053
EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1054
EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1055
EXPECT_TRUE(CheckNoRtcp1());
1056
EXPECT_TRUE(CheckNoRtcp2());
1059
// Test that the mediachannel retains its sending state after the transport
1060
// becomes non-writable.
1061
void SendWithWritabilityLoss() {
1062
CreateChannels(0, 0);
1063
EXPECT_TRUE(SendInitiate());
1064
EXPECT_TRUE(SendAccept());
1065
EXPECT_EQ(1U, GetTransport1()->channels().size());
1066
EXPECT_EQ(1U, GetTransport2()->channels().size());
1067
EXPECT_TRUE(SendRtp1());
1068
EXPECT_TRUE(SendRtp2());
1069
EXPECT_TRUE(CheckRtp1());
1070
EXPECT_TRUE(CheckRtp2());
1071
EXPECT_TRUE(CheckNoRtp1());
1072
EXPECT_TRUE(CheckNoRtp2());
1074
GetTransport1()->SetDestination(NULL);
1075
EXPECT_TRUE(media_channel1_->sending());
1076
EXPECT_FALSE(SendRtp1());
1077
EXPECT_TRUE(SendRtp2());
1078
EXPECT_TRUE(CheckRtp1());
1079
EXPECT_TRUE(CheckNoRtp2());
1081
GetTransport1()->SetDestination(GetTransport2());
1082
EXPECT_TRUE(media_channel1_->sending());
1083
EXPECT_TRUE(SendRtp1());
1084
EXPECT_TRUE(SendRtp2());
1085
EXPECT_TRUE(CheckRtp1());
1086
EXPECT_TRUE(CheckRtp2());
1087
EXPECT_TRUE(CheckNoRtp1());
1088
EXPECT_TRUE(CheckNoRtp2());
1091
void SendSsrcMuxToSsrcMuxWithRtcpMux() {
1092
CreateChannels(SSRC_MUX | RTCP | RTCP_MUX, SSRC_MUX | RTCP | RTCP_MUX);
1093
EXPECT_TRUE(SendInitiate());
1094
EXPECT_EQ(2U, GetTransport1()->channels().size());
1095
EXPECT_EQ(1U, GetTransport2()->channels().size());
1096
EXPECT_TRUE(SendAccept());
1097
EXPECT_EQ(1U, GetTransport1()->channels().size());
1098
EXPECT_EQ(1U, GetTransport2()->channels().size());
1099
EXPECT_TRUE(channel1_->ssrc_filter()->IsActive());
1100
// channel1 - should have media_content2 as remote. i.e. kSsrc2
1101
EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2));
1102
EXPECT_TRUE(channel2_->ssrc_filter()->IsActive());
1103
// channel2 - should have media_content1 as remote. i.e. kSsrc1
1104
EXPECT_TRUE(channel2_->ssrc_filter()->FindStream(kSsrc1));
1105
EXPECT_TRUE(SendCustomRtp1(kSsrc1));
1106
EXPECT_TRUE(SendCustomRtp2(kSsrc2));
1107
EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1108
EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1109
EXPECT_TRUE(CheckCustomRtp1(kSsrc2));
1110
EXPECT_TRUE(CheckNoRtp1());
1111
EXPECT_TRUE(CheckCustomRtp2(kSsrc1));
1112
EXPECT_TRUE(CheckNoRtp2());
1113
EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1114
EXPECT_TRUE(CheckNoRtcp1());
1115
EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1116
EXPECT_TRUE(CheckNoRtcp2());
1119
void SendSsrcMuxToSsrcMux() {
1120
CreateChannels(SSRC_MUX | RTCP, SSRC_MUX | RTCP);
1121
EXPECT_TRUE(SendInitiate());
1122
EXPECT_EQ(2U, GetTransport1()->channels().size());
1123
EXPECT_EQ(2U, GetTransport2()->channels().size());
1124
EXPECT_TRUE(SendAccept());
1125
EXPECT_EQ(2U, GetTransport1()->channels().size());
1126
EXPECT_EQ(2U, GetTransport2()->channels().size());
1127
EXPECT_TRUE(channel1_->ssrc_filter()->IsActive());
1128
// channel1 - should have media_content2 as remote. i.e. kSsrc2
1129
EXPECT_TRUE(channel1_->ssrc_filter()->FindStream(kSsrc2));
1130
EXPECT_TRUE(channel2_->ssrc_filter()->IsActive());
1131
// channel2 - should have media_content1 as remote. i.e. kSsrc1
1132
EXPECT_TRUE(SendCustomRtp1(kSsrc1));
1133
EXPECT_TRUE(SendCustomRtp2(kSsrc2));
1134
EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1135
EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1136
EXPECT_TRUE(CheckCustomRtp1(kSsrc2));
1137
EXPECT_FALSE(CheckCustomRtp1(kSsrc1));
1138
EXPECT_TRUE(CheckCustomRtp2(kSsrc1));
1139
EXPECT_FALSE(CheckCustomRtp2(kSsrc2));
1140
EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1141
EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
1142
EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1143
EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1146
// Test that the media monitor can be run and gives timely callbacks.
1147
void TestMediaMonitor() {
1148
static const int kTimeout = 500;
1149
CreateChannels(0, 0);
1150
EXPECT_TRUE(SendInitiate());
1151
EXPECT_TRUE(SendAccept());
1152
channel1_->StartMediaMonitor(100);
1153
channel2_->StartMediaMonitor(100);
1154
// Ensure we get callbacks and stop.
1155
EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1156
EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1157
channel1_->StopMediaMonitor();
1158
channel2_->StopMediaMonitor();
1159
// Ensure a restart of a stopped monitor works.
1160
channel1_->StartMediaMonitor(100);
1161
EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1162
channel1_->StopMediaMonitor();
1163
// Ensure stopping a stopped monitor is OK.
1164
channel1_->StopMediaMonitor();
1167
void TestMediaSinks() {
1168
CreateChannels(0, 0);
1169
EXPECT_TRUE(SendInitiate());
1170
EXPECT_TRUE(SendAccept());
1171
EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1172
EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1173
EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1174
EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1176
talk_base::Pathname path;
1177
EXPECT_TRUE(talk_base::Filesystem::GetTemporaryFolder(path, true, NULL));
1178
path.SetFilename("sink-test.rtpdump");
1179
talk_base::scoped_ptr<cricket::RtpDumpSink> sink(
1180
new cricket::RtpDumpSink(path.pathname()));
1181
sink->set_packet_filter(cricket::PF_ALL);
1182
EXPECT_TRUE(sink->Enable(true));
1183
channel1_->RegisterSendSink(
1184
sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
1185
EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1186
EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1187
EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1188
EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1190
// The first packet is recorded with header + data.
1191
EXPECT_TRUE(SendRtp1());
1192
// The second packet is recorded with header only.
1193
sink->set_packet_filter(cricket::PF_RTPHEADER);
1194
EXPECT_TRUE(SendRtp1());
1195
// The third packet is not recorded since sink is disabled.
1196
EXPECT_TRUE(sink->Enable(false));
1197
EXPECT_TRUE(SendRtp1());
1198
// The fourth packet is not recorded since sink is unregistered.
1199
EXPECT_TRUE(sink->Enable(true));
1200
channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
1201
EXPECT_TRUE(SendRtp1());
1202
sink.reset(); // This will close the file.
1204
// Read the recorded file and verify two packets.
1205
talk_base::scoped_ptr<talk_base::StreamInterface> stream(
1206
talk_base::Filesystem::OpenFile(path, "rb"));
1208
cricket::RtpDumpReader reader(stream.get());
1209
cricket::RtpDumpPacket packet;
1210
EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
1211
std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
1212
packet.data.size());
1213
EXPECT_EQ(rtp_packet_, read_packet);
1215
EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
1217
packet.GetRtpHeaderLen(&len);
1218
EXPECT_EQ(len, packet.data.size());
1219
EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
1221
EXPECT_EQ(talk_base::SR_EOS, reader.ReadPacket(&packet));
1223
// Delete the file for media recording.
1225
EXPECT_TRUE(talk_base::Filesystem::DeleteFile(path));
1228
void TestSetContentFailure() {
1229
CreateChannels(0, 0);
1230
typename T::Content content;
1231
cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1232
cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1234
// Set up the session description.
1235
CreateContent(0, kPcmuCodec, kH264Codec, &content);
1236
sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1237
new cricket::AudioContentDescription());
1238
sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1239
new cricket::VideoContentDescription());
1240
EXPECT_TRUE(session1_.set_local_description(sdesc_loc));
1241
sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1242
new cricket::AudioContentDescription());
1243
sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1244
new cricket::VideoContentDescription());
1245
EXPECT_TRUE(session1_.set_remote_description(sdesc_rem));
1247
// Test failures in SetLocalContent.
1248
media_channel1_->set_fail_set_recv_codecs(true);
1249
session1_.SetError(cricket::BaseSession::ERROR_NONE);
1250
session1_.SignalState(&session1_, cricket::Session::STATE_SENTINITIATE);
1251
EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1252
media_channel1_->set_fail_set_recv_codecs(true);
1253
session1_.SetError(cricket::BaseSession::ERROR_NONE);
1254
session1_.SignalState(&session1_, cricket::Session::STATE_SENTACCEPT);
1255
EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1257
// Test failures in SetRemoteContent.
1258
media_channel1_->set_fail_set_send_codecs(true);
1259
session1_.SetError(cricket::BaseSession::ERROR_NONE);
1260
session1_.SignalState(&session1_, cricket::Session::STATE_RECEIVEDINITIATE);
1261
EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1262
media_channel1_->set_fail_set_send_codecs(true);
1263
session1_.SetError(cricket::BaseSession::ERROR_NONE);
1264
session1_.SignalState(&session1_, cricket::Session::STATE_RECEIVEDACCEPT);
1265
EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1268
void TestFlushRtcp() {
1271
CreateChannels(RTCP, RTCP);
1272
EXPECT_TRUE(SendInitiate());
1273
EXPECT_TRUE(SendAccept());
1274
EXPECT_EQ(2U, GetTransport1()->channels().size());
1275
EXPECT_EQ(2U, GetTransport2()->channels().size());
1277
// Send RTCP1 from a different thread.
1278
CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1279
EXPECT_TRUE(send_rtcp1);
1280
// The sending message is only posted. channel2_ should be empty.
1281
EXPECT_TRUE(CheckNoRtcp2());
1283
// When channel1_ is deleted, the RTCP packet should be sent out to
1286
EXPECT_TRUE(CheckRtcp2());
1289
void TestChangeStateError() {
1290
CreateChannels(RTCP, RTCP);
1291
EXPECT_TRUE(SendInitiate());
1292
media_channel2_->set_fail_set_send(true);
1293
EXPECT_TRUE(channel2_->Enable(true));
1294
EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1298
void TestSrtpError() {
1299
static const unsigned char kBadPacket[] = {
1300
0x90, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
1302
CreateChannels(RTCP | SECURE, RTCP | SECURE);
1303
EXPECT_FALSE(channel1_->secure());
1304
EXPECT_FALSE(channel2_->secure());
1305
EXPECT_TRUE(SendInitiate());
1306
EXPECT_TRUE(SendAccept());
1307
EXPECT_TRUE(channel1_->secure());
1308
EXPECT_TRUE(channel2_->secure());
1309
channel2_->set_srtp_signal_silent_time(200);
1311
// Testing failures in sending packets.
1312
EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1313
// The first failure will trigger an error.
1314
EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1315
error_ = T::MediaChannel::ERROR_NONE;
1316
// The next 1 sec failures will not trigger an error.
1317
EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1318
// Wait for a while to ensure no message comes in.
1319
talk_base::Thread::Current()->ProcessMessages(210);
1320
EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1321
// The error will be triggered again.
1322
EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1323
EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1325
// Testing failures in receiving packets.
1326
error_ = T::MediaChannel::ERROR_NONE;
1327
cricket::TransportChannel* transport_channel =
1328
channel2_->transport_channel();
1329
transport_channel->SignalReadPacket(
1330
transport_channel, reinterpret_cast<const char*>(kBadPacket),
1331
sizeof(kBadPacket));
1332
EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_AUTH_FAILED, error_, 500);
1335
void TestSetChannelOptions(bool options_should_change) {
1336
CreateChannels(0, 0);
1338
channel1_->SetChannelOptions(1);
1339
channel2_->SetChannelOptions(1);
1340
if (options_should_change) {
1341
EXPECT_EQ(1, media_channel1_->GetOptions());
1342
EXPECT_EQ(1, media_channel2_->GetOptions());
1344
EXPECT_EQ(0, media_channel1_->GetOptions());
1345
EXPECT_EQ(0, media_channel2_->GetOptions());
1348
channel1_->SetChannelOptions(2);
1349
channel2_->SetChannelOptions(2);
1350
if (options_should_change) {
1351
EXPECT_EQ(2, media_channel1_->GetOptions());
1352
EXPECT_EQ(2, media_channel2_->GetOptions());
1354
EXPECT_EQ(0, media_channel1_->GetOptions());
1355
EXPECT_EQ(0, media_channel2_->GetOptions());
1360
cricket::FakeSession session1_;
1361
cricket::FakeSession session2_;
1362
cricket::FakeMediaEngine media_engine_;
1363
// The media channels are owned by the voice channel objects below.
1364
typename T::MediaChannel* media_channel1_;
1365
typename T::MediaChannel* media_channel2_;
1366
talk_base::scoped_ptr<typename T::Channel> channel1_;
1367
talk_base::scoped_ptr<typename T::Channel> channel2_;
1368
typename T::Content local_media_content1_;
1369
typename T::Content local_media_content2_;
1370
typename T::Content remote_media_content1_;
1371
typename T::Content remote_media_content2_;
1372
// The RTP and RTCP packets to send in the tests.
1373
std::string rtp_packet_;
1374
std::string rtcp_packet_;
1375
int media_info_callbacks1_;
1376
int media_info_callbacks2_;
1378
typename T::MediaChannel::Error error_;
1383
void ChannelTest<VoiceTraits>::CreateContent(
1385
const cricket::AudioCodec& audio_codec,
1386
const cricket::VideoCodec& video_codec,
1387
cricket::AudioContentDescription* audio) {
1388
audio->AddCodec(audio_codec);
1389
audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1390
if (flags & SECURE) {
1391
audio->AddCrypto(cricket::CryptoParams(
1392
1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
1393
"inline:" + talk_base::CreateRandomString(40), ""));
1398
void ChannelTest<VoiceTraits>::CopyContent(
1399
const cricket::AudioContentDescription& source,
1400
cricket::AudioContentDescription* audio) {
1405
bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1406
const cricket::AudioCodec& c2) {
1407
return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1408
c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1412
void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1413
uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1414
audio->AddLegacyStream(ssrc);
1417
class VoiceChannelTest
1418
: public ChannelTest<VoiceTraits> {
1420
typedef ChannelTest<VoiceTraits>
1422
VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1423
kRtcpReport, sizeof(kRtcpReport)) {
1427
// override to add NULL parameter
1429
cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
1430
talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
1431
cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1433
cricket::VideoChannel* channel = new cricket::VideoChannel(
1434
thread, engine, ch, session, cricket::CN_VIDEO, rtcp, NULL);
1435
if (!channel->Init()) {
1442
// override to add 0 parameter
1444
bool ChannelTest<VideoTraits>::AddStream1(int id) {
1445
return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1449
void ChannelTest<VideoTraits>::CreateContent(
1451
const cricket::AudioCodec& audio_codec,
1452
const cricket::VideoCodec& video_codec,
1453
cricket::VideoContentDescription* video) {
1454
video->AddCodec(video_codec);
1455
video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1456
if (flags & SECURE) {
1457
video->AddCrypto(cricket::CryptoParams(
1458
1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
1459
"inline:" + talk_base::CreateRandomString(40), ""));
1464
void ChannelTest<VideoTraits>::CopyContent(
1465
const cricket::VideoContentDescription& source,
1466
cricket::VideoContentDescription* video) {
1471
bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1472
const cricket::VideoCodec& c2) {
1473
return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1474
c1.framerate == c2.framerate;
1478
void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1479
uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
1480
video->AddLegacyStream(ssrc);
1483
class VideoChannelTest
1484
: public ChannelTest<VideoTraits> {
1486
typedef ChannelTest<VideoTraits>
1488
VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
1489
kRtcpReport, sizeof(kRtcpReport)) {
1496
TEST_F(VoiceChannelTest, TestInit) {
1498
EXPECT_FALSE(media_channel1_->muted());
1499
EXPECT_TRUE(media_channel1_->dtmf_queue().empty());
1502
TEST_F(VoiceChannelTest, TestSetContents) {
1503
Base::TestSetContents();
1506
TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
1507
Base::TestSetContentsNullOffer();
1510
TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
1511
Base::TestSetContentsRtcpMux();
1514
TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
1515
Base::TestSetRemoteContentUpdate();
1518
TEST_F(VoiceChannelTest, TestStreams) {
1519
Base::TestStreams();
1522
TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
1523
Base::TestUpdateStreamsInLocalContent();
1526
TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
1527
Base::TestUpdateStreamsInRemoteContent();
1530
TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
1531
Base::TestChangeStreamParamsInContent();
1534
TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
1535
Base::TestPlayoutAndSendingStates();
1538
TEST_F(VoiceChannelTest, TestCallSetup) {
1539
Base::TestCallSetup();
1542
TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
1543
Base::TestCallTeardownRtcpMux();
1546
TEST_F(VoiceChannelTest, SendRtpToRtp) {
1547
Base::SendRtpToRtp();
1550
TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
1551
Base::SendNoRtcpToNoRtcp();
1554
TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
1555
Base::SendNoRtcpToRtcp();
1558
TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
1559
Base::SendRtcpToNoRtcp();
1562
TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
1563
Base::SendRtcpToRtcp();
1566
TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
1567
Base::SendRtcpMuxToRtcp();
1570
TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
1571
Base::SendRtcpMuxToRtcpMux();
1574
TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
1575
Base::SendEarlyRtcpMuxToRtcp();
1578
TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
1579
Base::SendEarlyRtcpMuxToRtcpMux();
1582
TEST_F(VoiceChannelTest, SendSrtpToSrtp) {
1583
Base::SendSrtpToSrtp();
1586
TEST_F(VoiceChannelTest, SendSrtpToRtp) {
1587
Base::SendSrtpToSrtp();
1590
TEST_F(VoiceChannelTest, SendSrtcpMux) {
1591
Base::SendSrtcpMux();
1594
TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
1595
Base::SendRtpToRtpOnThread();
1598
TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
1599
Base::SendSrtpToSrtpOnThread();
1602
TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
1603
Base::SendWithWritabilityLoss();
1606
TEST_F(VoiceChannelTest, TestMediaMonitor) {
1607
Base::TestMediaMonitor();
1610
// Test that Mute properly forwards to the media channel.
1611
TEST_F(VoiceChannelTest, TestMute) {
1612
CreateChannels(0, 0);
1613
EXPECT_FALSE(media_channel1_->muted());
1614
EXPECT_TRUE(channel1_->Mute(true));
1615
EXPECT_TRUE(media_channel1_->muted());
1616
EXPECT_TRUE(channel1_->Mute(false));
1617
EXPECT_FALSE(media_channel1_->muted());
1620
// Test that keyboard automute works correctly.
1621
TEST_F(VoiceChannelTest, TestKeyboardMute) {
1622
CreateChannels(0, 0);
1623
EXPECT_FALSE(media_channel1_->muted());
1624
EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
1626
cricket::VoiceMediaChannel::Error e =
1627
cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
1629
// Typing doesn't mute automatically
1630
media_channel1_->TriggerError(0, e);
1631
talk_base::Thread::Current()->ProcessMessages(0);
1632
EXPECT_EQ(e, error_);
1633
EXPECT_FALSE(media_channel1_->muted());
1635
// But it does when enabled
1636
channel1_->set_mute_on_type(true, 200);
1637
media_channel1_->TriggerError(0, e);
1638
error_ = cricket::VoiceMediaChannel::ERROR_NONE;
1639
EXPECT_TRUE_WAIT(error_ == e, 100);
1640
EXPECT_TRUE(media_channel1_->muted());
1641
EXPECT_TRUE_WAIT(!media_channel1_->muted(), 250); // And resets.
1643
// Muting manually preemts auto-unmute
1644
media_channel1_->TriggerError(0, e);
1645
error_ = cricket::VoiceMediaChannel::ERROR_NONE;
1646
EXPECT_TRUE_WAIT(error_ == e, 100);
1647
EXPECT_TRUE(media_channel1_->muted());
1648
EXPECT_TRUE(channel1_->Mute(true));
1649
talk_base::Thread::Current()->ProcessMessages(250);
1650
EXPECT_TRUE(media_channel1_->muted());
1653
// Test that PressDTMF properly forwards to the media channel.
1654
TEST_F(VoiceChannelTest, TestDtmf) {
1655
CreateChannels(0, 0);
1656
EXPECT_TRUE(SendInitiate());
1657
EXPECT_TRUE(SendAccept());
1658
EXPECT_EQ(0U, media_channel1_->dtmf_queue().size());
1659
EXPECT_TRUE(channel1_->PressDTMF(1, true));
1660
EXPECT_TRUE(channel1_->PressDTMF(8, false));
1661
ASSERT_EQ(2U, media_channel1_->dtmf_queue().size());
1662
EXPECT_EQ(1, media_channel1_->dtmf_queue()[0].first);
1663
EXPECT_EQ(true, media_channel1_->dtmf_queue()[0].second);
1664
EXPECT_EQ(8, media_channel1_->dtmf_queue()[1].first);
1665
EXPECT_FALSE(media_channel1_->dtmf_queue()[1].second);
1668
TEST_F(VoiceChannelTest, TestMediaSinks) {
1669
Base::TestMediaSinks();
1672
TEST_F(VoiceChannelTest, TestSetContentFailure) {
1673
Base::TestSetContentFailure();
1676
TEST_F(VoiceChannelTest, TestFlushRtcp) {
1677
Base::TestFlushRtcp();
1680
TEST_F(VoiceChannelTest, TestChangeStateError) {
1681
Base::TestChangeStateError();
1684
TEST_F(VoiceChannelTest, TestSrtpError) {
1685
Base::TestSrtpError();
1688
// Test that we can play a ringback tone properly.
1689
TEST_F(VoiceChannelTest, TestRingbackTone) {
1690
CreateChannels(RTCP, RTCP);
1691
EXPECT_FALSE(media_channel1_->ringback_tone_play());
1692
EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
1693
EXPECT_TRUE(SendInitiate());
1694
EXPECT_TRUE(SendAccept());
1695
// Play ringback tone, no loop.
1696
EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
1697
EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
1698
EXPECT_TRUE(media_channel1_->ringback_tone_play());
1699
EXPECT_FALSE(media_channel1_->ringback_tone_loop());
1700
// Stop the ringback tone.
1701
EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
1702
EXPECT_FALSE(media_channel1_->ringback_tone_play());
1704
EXPECT_TRUE(AddStream1(1));
1705
// Play ringback tone, looping, on the new stream.
1706
EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
1707
EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
1708
EXPECT_TRUE(media_channel1_->ringback_tone_play());
1709
EXPECT_TRUE(media_channel1_->ringback_tone_loop());
1710
// Stop the ringback tone.
1711
EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
1712
EXPECT_FALSE(media_channel1_->ringback_tone_play());
1715
// Test that we can scale the output volume properly for 1:1 calls.
1716
TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
1717
CreateChannels(RTCP, RTCP);
1718
EXPECT_TRUE(SendInitiate());
1719
EXPECT_TRUE(SendAccept());
1722
// Default is (1.0, 1.0).
1723
EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
1724
EXPECT_DOUBLE_EQ(1.0, left);
1725
EXPECT_DOUBLE_EQ(1.0, right);
1727
EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
1729
// Set scale to (1.5, 0.5).
1730
EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
1731
EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
1732
EXPECT_DOUBLE_EQ(1.5, left);
1733
EXPECT_DOUBLE_EQ(0.5, right);
1735
// Set scale to (0, 0).
1736
EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
1737
EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
1738
EXPECT_DOUBLE_EQ(0.0, left);
1739
EXPECT_DOUBLE_EQ(0.0, right);
1742
// Test that we can scale the output volume properly for multiway calls.
1743
TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
1744
CreateChannels(RTCP, RTCP);
1745
EXPECT_TRUE(SendInitiate());
1746
EXPECT_TRUE(SendAccept());
1747
EXPECT_TRUE(AddStream1(1));
1748
EXPECT_TRUE(AddStream1(2));
1751
// Default is (1.0, 1.0).
1752
EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
1753
EXPECT_DOUBLE_EQ(1.0, left);
1754
EXPECT_DOUBLE_EQ(1.0, right);
1755
EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
1756
EXPECT_DOUBLE_EQ(1.0, left);
1757
EXPECT_DOUBLE_EQ(1.0, right);
1758
EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
1759
EXPECT_DOUBLE_EQ(1.0, left);
1760
EXPECT_DOUBLE_EQ(1.0, right);
1762
EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
1764
// Set scale to (1.5, 0.5) for ssrc = 1.
1765
EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
1766
EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
1767
EXPECT_DOUBLE_EQ(1.5, left);
1768
EXPECT_DOUBLE_EQ(0.5, right);
1769
EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
1770
EXPECT_DOUBLE_EQ(1.0, left);
1771
EXPECT_DOUBLE_EQ(1.0, right);
1772
EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
1773
EXPECT_DOUBLE_EQ(1.0, left);
1774
EXPECT_DOUBLE_EQ(1.0, right);
1776
// Set scale to (0, 0) for all ssrcs.
1777
EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
1778
EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
1779
EXPECT_DOUBLE_EQ(0.0, left);
1780
EXPECT_DOUBLE_EQ(0.0, right);
1781
EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
1782
EXPECT_DOUBLE_EQ(0.0, left);
1783
EXPECT_DOUBLE_EQ(0.0, right);
1784
EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
1785
EXPECT_DOUBLE_EQ(0.0, left);
1786
EXPECT_DOUBLE_EQ(0.0, right);
1789
TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMux) {
1790
Base::SendSsrcMuxToSsrcMux();
1793
TEST_F(VoiceChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) {
1794
Base::SendSsrcMuxToSsrcMuxWithRtcpMux();
1797
TEST_F(VoiceChannelTest, TestSetChannelOptions) {
1798
// SetChannelOptions should do nothing on voice channel.
1799
Base::TestSetChannelOptions(false);
1803
TEST_F(VideoChannelTest, TestInit) {
1807
TEST_F(VideoChannelTest, TestSetContents) {
1808
Base::TestSetContents();
1811
TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
1812
Base::TestSetContentsNullOffer();
1815
TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
1816
Base::TestSetContentsRtcpMux();
1819
TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
1820
Base::TestSetRemoteContentUpdate();
1823
TEST_F(VideoChannelTest, TestStreams) {
1824
Base::TestStreams();
1827
TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
1828
Base::TestUpdateStreamsInLocalContent();
1831
TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
1832
Base::TestUpdateStreamsInRemoteContent();
1835
TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
1836
Base::TestChangeStreamParamsInContent();
1839
TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
1840
Base::TestPlayoutAndSendingStates();
1843
TEST_F(VideoChannelTest, TestCallSetup) {
1844
Base::TestCallSetup();
1847
TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
1848
Base::TestCallTeardownRtcpMux();
1851
TEST_F(VideoChannelTest, SendRtpToRtp) {
1852
Base::SendRtpToRtp();
1855
TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
1856
Base::SendNoRtcpToNoRtcp();
1859
TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
1860
Base::SendNoRtcpToRtcp();
1863
TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
1864
Base::SendRtcpToNoRtcp();
1867
TEST_F(VideoChannelTest, SendRtcpToRtcp) {
1868
Base::SendRtcpToRtcp();
1871
TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
1872
Base::SendRtcpMuxToRtcp();
1875
TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
1876
Base::SendRtcpMuxToRtcpMux();
1879
TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
1880
Base::SendEarlyRtcpMuxToRtcp();
1883
TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
1884
Base::SendEarlyRtcpMuxToRtcpMux();
1887
TEST_F(VideoChannelTest, SendSrtpToSrtp) {
1888
Base::SendSrtpToSrtp();
1891
TEST_F(VideoChannelTest, SendSrtpToRtp) {
1892
Base::SendSrtpToSrtp();
1895
TEST_F(VideoChannelTest, SendSrtcpMux) {
1896
Base::SendSrtcpMux();
1899
TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
1900
Base::SendRtpToRtpOnThread();
1903
TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
1904
Base::SendSrtpToSrtpOnThread();
1907
TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
1908
Base::SendWithWritabilityLoss();
1911
TEST_F(VideoChannelTest, TestMediaMonitor) {
1912
Base::TestMediaMonitor();
1915
TEST_F(VideoChannelTest, TestMediaSinks) {
1916
Base::TestMediaSinks();
1919
TEST_F(VideoChannelTest, TestSetContentFailure) {
1920
Base::TestSetContentFailure();
1923
TEST_F(VideoChannelTest, TestFlushRtcp) {
1924
Base::TestFlushRtcp();
1927
TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMux) {
1928
Base::SendSsrcMuxToSsrcMux();
1931
TEST_F(VideoChannelTest, SendSsrcMuxToSsrcMuxWithRtcpMux) {
1932
Base::SendSsrcMuxToSsrcMuxWithRtcpMux();
1935
// TODO: Add VideoChannelTest.TestChangeStateError.
1937
TEST_F(VideoChannelTest, TestSrtpError) {
1938
Base::TestSrtpError();
1941
TEST_F(VideoChannelTest, TestApplyViewRequest) {
1942
CreateChannels(0, 0);
1943
EXPECT_TRUE(SendInitiate());
1944
EXPECT_TRUE(SendAccept());
1946
cricket::VideoFormat send_format;
1947
EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
1948
EXPECT_EQ(640, send_format.width);
1949
EXPECT_EQ(400, send_format.height);
1950
EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
1952
cricket::ViewRequest request;
1953
request.static_video_views.push_back(
1954
cricket::StaticVideoView(kSsrc1, 320, 200, 15));
1955
EXPECT_TRUE(channel1_->ApplyViewRequest(request));
1956
EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
1957
EXPECT_EQ(320, send_format.width);
1958
EXPECT_EQ(200, send_format.height);
1959
EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
1961
// Short term hack for view request with SSRC 0. TODO: Remove this
1962
// once Reflector uses the correct SSRC in view request (b/5977302).
1963
request.static_video_views.clear();
1964
request.static_video_views.push_back(
1965
cricket::StaticVideoView(0, 160, 100, 8));
1966
EXPECT_TRUE(channel1_->ApplyViewRequest(request));
1967
EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
1968
EXPECT_EQ(160, send_format.width);
1969
EXPECT_EQ(100, send_format.height);
1970
EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
1972
request.static_video_views.clear();
1973
EXPECT_TRUE(channel1_->ApplyViewRequest(request));
1974
EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
1975
EXPECT_EQ(0, send_format.width);
1976
EXPECT_EQ(0, send_format.height);
1979
TEST_F(VideoChannelTest, TestSetChannelOptions) {
1980
Base::TestSetChannelOptions(true);
1986
class DataChannelTest
1987
: public ChannelTest<DataTraits> {
1989
typedef ChannelTest<DataTraits>
1991
DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
1992
kRtcpReport, sizeof(kRtcpReport)) {
1996
// Override to avoid engine channel parameter.
1998
cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
1999
talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
2000
cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2002
cricket::DataChannel* channel = new cricket::DataChannel(
2003
thread, ch, session, cricket::CN_DATA, rtcp);
2004
if (!channel->Init()) {
2012
void ChannelTest<DataTraits>::CreateContent(
2014
const cricket::AudioCodec& audio_codec,
2015
const cricket::VideoCodec& video_codec,
2016
cricket::DataContentDescription* data) {
2017
data->AddCodec(kGoogleDataCodec);
2018
data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2019
if (flags & SECURE) {
2020
data->AddCrypto(cricket::CryptoParams(
2021
1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
2022
"inline:" + talk_base::CreateRandomString(40), ""));
2027
void ChannelTest<DataTraits>::CopyContent(
2028
const cricket::DataContentDescription& source,
2029
cricket::DataContentDescription* data) {
2034
bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2035
const cricket::DataCodec& c2) {
2036
return c1.name == c2.name;
2040
void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2041
uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2042
data->AddLegacyStream(ssrc);
2045
TEST_F(DataChannelTest, TestInit) {
2047
EXPECT_FALSE(media_channel1_->muted());
2050
TEST_F(DataChannelTest, TestSetContents) {
2051
Base::TestSetContents();
2054
TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2055
Base::TestSetContentsNullOffer();
2058
TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2059
Base::TestSetContentsRtcpMux();
2062
TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2063
Base::TestSetRemoteContentUpdate();
2066
TEST_F(DataChannelTest, TestStreams) {
2067
Base::TestStreams();
2070
TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2071
Base::TestUpdateStreamsInLocalContent();
2074
TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2075
Base::TestUpdateStreamsInRemoteContent();
2078
TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2079
Base::TestChangeStreamParamsInContent();
2082
TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2083
Base::TestPlayoutAndSendingStates();
2086
TEST_F(DataChannelTest, TestCallSetup) {
2087
Base::TestCallSetup();
2090
TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2091
Base::TestCallTeardownRtcpMux();
2094
TEST_F(DataChannelTest, SendRtpToRtp) {
2095
Base::SendRtpToRtp();
2098
TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2099
Base::SendNoRtcpToNoRtcp();
2102
TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2103
Base::SendNoRtcpToRtcp();
2106
TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2107
Base::SendRtcpToNoRtcp();
2110
TEST_F(DataChannelTest, SendRtcpToRtcp) {
2111
Base::SendRtcpToRtcp();
2114
TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2115
Base::SendRtcpMuxToRtcp();
2118
TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2119
Base::SendRtcpMuxToRtcpMux();
2122
TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2123
Base::SendEarlyRtcpMuxToRtcp();
2126
TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2127
Base::SendEarlyRtcpMuxToRtcpMux();
2130
TEST_F(DataChannelTest, SendSrtpToSrtp) {
2131
Base::SendSrtpToSrtp();
2134
TEST_F(DataChannelTest, SendSrtpToRtp) {
2135
Base::SendSrtpToSrtp();
2138
TEST_F(DataChannelTest, SendSrtcpMux) {
2139
Base::SendSrtcpMux();
2142
TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2143
Base::SendRtpToRtpOnThread();
2146
TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2147
Base::SendSrtpToSrtpOnThread();
2150
TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2151
Base::SendWithWritabilityLoss();
2154
TEST_F(DataChannelTest, TestMediaMonitor) {
2155
Base::TestMediaMonitor();
2158
TEST_F(DataChannelTest, TestSendData) {
2159
CreateChannels(0, 0);
2160
EXPECT_TRUE(SendInitiate());
2161
EXPECT_TRUE(SendAccept());
2163
cricket::DataMediaChannel::SendDataParams params;
2165
std::string data = "foo";
2166
ASSERT_TRUE(media_channel1_->SendData(params, data));
2167
EXPECT_EQ(params.ssrc,
2168
media_channel1_->last_sent_data_params().ssrc);
2169
EXPECT_EQ(data, media_channel1_->last_sent_data());
2172
// TODO: TestSetReceiver?