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/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"
49 #define MAYBE_SKIP_TEST(feature) \
50 if (!(talk_base::SSLStreamAdapter::feature())) { \
51 LOG(LS_INFO) << "Feature disabled... skipping"; \
55 using cricket::CA_OFFER;
56 using cricket::CA_PRANSWER;
57 using cricket::CA_ANSWER;
58 using cricket::CA_UPDATE;
59 using cricket::FakeVoiceMediaChannel;
60 using cricket::ScreencastId;
61 using cricket::StreamParams;
62 using cricket::TransportChannel;
63 using talk_base::WindowId;
65 static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0);
66 static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0);
67 static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0);
68 static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0);
69 static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0);
70 static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0);
71 static const uint32 kSsrc1 = 0x1111;
72 static const uint32 kSsrc2 = 0x2222;
73 static const uint32 kSsrc3 = 0x3333;
74 static const int kAudioPts[] = {0, 8};
75 static const int kVideoPts[] = {97, 99};
77 template<class ChannelT,
84 typedef ChannelT Channel;
85 typedef MediaChannelT MediaChannel;
86 typedef ContentT Content;
88 typedef MediaInfoT MediaInfo;
91 class FakeScreenCaptureFactory
92 : public cricket::VideoChannel::ScreenCapturerFactory,
93 public sigslot::has_slots<> {
95 FakeScreenCaptureFactory()
96 : window_capturer_(NULL),
97 capture_state_(cricket::CS_STOPPED) {}
99 virtual cricket::VideoCapturer* CreateScreenCapturer(
100 const ScreencastId& window) {
101 if (window_capturer_ != NULL) {
102 // Class is only designed to handle one fake screencapturer.
106 window_capturer_ = new cricket::FakeVideoCapturer;
107 window_capturer_->SignalDestroyed.connect(
109 &FakeScreenCaptureFactory::OnWindowCapturerDestroyed);
110 window_capturer_->SignalStateChange.connect(
112 &FakeScreenCaptureFactory::OnStateChange);
113 return window_capturer_;
116 cricket::FakeVideoCapturer* window_capturer() { return window_capturer_; }
118 cricket::CaptureState capture_state() { return capture_state_; }
121 void OnWindowCapturerDestroyed(cricket::FakeVideoCapturer* capturer) {
122 if (capturer == window_capturer_) {
123 window_capturer_ = NULL;
126 void OnStateChange(cricket::VideoCapturer*, cricket::CaptureState state) {
127 capture_state_ = state;
130 cricket::FakeVideoCapturer* window_capturer_;
131 cricket::CaptureState capture_state_;
134 // Controls how long we wait for a session to send messages that we
135 // expect, in milliseconds. We put it high to avoid flaky tests.
136 static const int kEventTimeout = 5000;
138 class VoiceTraits : public Traits<cricket::VoiceChannel,
139 cricket::FakeVoiceMediaChannel,
140 cricket::AudioContentDescription,
142 cricket::VoiceMediaInfo> {
145 class VideoTraits : public Traits<cricket::VideoChannel,
146 cricket::FakeVideoMediaChannel,
147 cricket::VideoContentDescription,
149 cricket::VideoMediaInfo> {
152 class DataTraits : public Traits<cricket::DataChannel,
153 cricket::FakeDataMediaChannel,
154 cricket::DataContentDescription,
156 cricket::DataMediaInfo> {
160 talk_base::StreamInterface* Open(const std::string& path) {
161 return talk_base::Filesystem::OpenFile(
162 talk_base::Pathname(path), "wb");
165 // Base class for Voice/VideoChannel tests
167 class ChannelTest : public testing::Test, public sigslot::has_slots<> {
169 enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
172 ChannelTest(const uint8* rtp_data, int rtp_len,
173 const uint8* rtcp_data, int rtcp_len)
176 media_channel1_(NULL),
177 media_channel2_(NULL),
178 rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
179 rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
180 media_info_callbacks1_(),
181 media_info_callbacks2_(),
182 mute_callback_recved_(false),
183 mute_callback_value_(false),
185 error_(T::MediaChannel::ERROR_NONE) {
188 static void SetUpTestCase() {
189 talk_base::InitializeSSL();
192 static void TearDownTestCase() {
193 talk_base::CleanupSSL();
196 void CreateChannels(int flags1, int flags2) {
197 CreateChannels(new typename T::MediaChannel(NULL),
198 new typename T::MediaChannel(NULL),
199 flags1, flags2, talk_base::Thread::Current());
201 void CreateChannels(int flags) {
202 CreateChannels(new typename T::MediaChannel(NULL),
203 new typename T::MediaChannel(NULL),
204 flags, talk_base::Thread::Current());
206 void CreateChannels(int flags1, int flags2,
207 talk_base::Thread* thread) {
208 CreateChannels(new typename T::MediaChannel(NULL),
209 new typename T::MediaChannel(NULL),
210 flags1, flags2, thread);
212 void CreateChannels(int flags,
213 talk_base::Thread* thread) {
214 CreateChannels(new typename T::MediaChannel(NULL),
215 new typename T::MediaChannel(NULL),
219 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
220 int flags1, int flags2, talk_base::Thread* thread) {
221 media_channel1_ = ch1;
222 media_channel2_ = ch2;
223 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
224 (flags1 & RTCP) != 0));
225 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
226 (flags2 & RTCP) != 0));
227 channel1_->SignalMediaMonitor.connect(
228 this, &ChannelTest<T>::OnMediaMonitor);
229 channel2_->SignalMediaMonitor.connect(
230 this, &ChannelTest<T>::OnMediaMonitor);
231 channel1_->SignalMediaError.connect(
232 this, &ChannelTest<T>::OnMediaChannelError);
233 channel2_->SignalMediaError.connect(
234 this, &ChannelTest<T>::OnMediaChannelError);
235 channel1_->SignalAutoMuted.connect(
236 this, &ChannelTest<T>::OnMediaMuted);
237 if ((flags1 & DTLS) && (flags2 & DTLS)) {
238 flags1 = (flags1 & ~SECURE);
239 flags2 = (flags2 & ~SECURE);
241 CreateContent(flags1, kPcmuCodec, kH264Codec,
242 &local_media_content1_);
243 CreateContent(flags2, kPcmuCodec, kH264Codec,
244 &local_media_content2_);
245 CopyContent(local_media_content1_, &remote_media_content1_);
246 CopyContent(local_media_content2_, &remote_media_content2_);
249 identity1_.reset(talk_base::SSLIdentity::Generate("session1"));
250 session1_.set_ssl_identity(identity1_.get());
253 identity2_.reset(talk_base::SSLIdentity::Generate("session2"));
254 session2_.set_ssl_identity(identity2_.get());
257 // Add stream information (SSRC) to the local content but not to the remote
258 // content. This means that we per default know the SSRC of what we send but
259 // not what we receive.
260 AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_);
261 AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_);
263 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
264 if (flags1 & SSRC_MUX) {
265 AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_);
267 if (flags2 & SSRC_MUX) {
268 AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
273 typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
274 int flags, talk_base::Thread* thread) {
275 media_channel1_ = ch1;
276 media_channel2_ = ch2;
278 channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
279 (flags & RTCP) != 0));
280 channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session1_,
281 (flags & RTCP) != 0));
282 channel1_->SignalMediaMonitor.connect(
283 this, &ChannelTest<T>::OnMediaMonitor);
284 channel2_->SignalMediaMonitor.connect(
285 this, &ChannelTest<T>::OnMediaMonitor);
286 channel2_->SignalMediaError.connect(
287 this, &ChannelTest<T>::OnMediaChannelError);
288 CreateContent(flags, kPcmuCodec, kH264Codec,
289 &local_media_content1_);
290 CreateContent(flags, kPcmuCodec, kH264Codec,
291 &local_media_content2_);
292 CopyContent(local_media_content1_, &remote_media_content1_);
293 CopyContent(local_media_content2_, &remote_media_content2_);
294 // Add stream information (SSRC) to the local content but not to the remote
295 // content. This means that we per default know the SSRC of what we send but
296 // not what we receive.
297 AddLegacyStreamInContent(kSsrc1, flags, &local_media_content1_);
298 AddLegacyStreamInContent(kSsrc2, flags, &local_media_content2_);
300 // If SSRC_MUX is used we also need to know the SSRC of the incoming stream.
301 if (flags & SSRC_MUX) {
302 AddLegacyStreamInContent(kSsrc1, flags, &remote_media_content1_);
303 AddLegacyStreamInContent(kSsrc2, flags, &remote_media_content2_);
307 typename T::Channel* CreateChannel(talk_base::Thread* thread,
308 cricket::MediaEngineInterface* engine,
309 typename T::MediaChannel* ch,
310 cricket::BaseSession* session,
312 typename T::Channel* channel = new typename T::Channel(
313 thread, engine, ch, session, cricket::CN_AUDIO, rtcp);
314 if (!channel->Init()) {
321 bool SendInitiate() {
322 bool result = channel1_->SetLocalContent(&local_media_content1_,
325 channel1_->Enable(true);
326 result = channel2_->SetRemoteContent(&remote_media_content1_,
329 session1_.Connect(&session2_);
331 result = channel2_->SetLocalContent(&local_media_content2_,
339 channel2_->Enable(true);
340 return channel1_->SetRemoteContent(&remote_media_content2_,
345 bool result = channel1_->SetLocalContent(&local_media_content1_,
348 channel1_->Enable(true);
349 result = channel2_->SetRemoteContent(&remote_media_content1_,
355 bool SendProvisionalAnswer() {
356 bool result = channel2_->SetLocalContent(&local_media_content2_,
359 channel2_->Enable(true);
360 result = channel1_->SetRemoteContent(&remote_media_content2_,
362 session1_.Connect(&session2_);
367 bool SendFinalAnswer() {
368 bool result = channel2_->SetLocalContent(&local_media_content2_,
371 result = channel1_->SetRemoteContent(&remote_media_content2_,
376 bool SendTerminate() {
382 bool AddStream1(int id) {
383 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
385 bool RemoveStream1(int id) {
386 return channel1_->RemoveRecvStream(id);
389 cricket::FakeTransport* GetTransport1() {
390 return session1_.GetTransport(channel1_->content_name());
392 cricket::FakeTransport* GetTransport2() {
393 return session2_.GetTransport(channel2_->content_name());
397 return media_channel1_->SendRtp(rtp_packet_.c_str(),
398 static_cast<int>(rtp_packet_.size()));
401 return media_channel2_->SendRtp(rtp_packet_.c_str(),
402 static_cast<int>(rtp_packet_.size()));
405 return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
406 static_cast<int>(rtcp_packet_.size()));
409 return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
410 static_cast<int>(rtcp_packet_.size()));
412 // Methods to send custom data.
413 bool SendCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1) {
414 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
415 return media_channel1_->SendRtp(data.c_str(),
416 static_cast<int>(data.size()));
418 bool SendCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
419 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
420 return media_channel2_->SendRtp(data.c_str(),
421 static_cast<int>(data.size()));
423 bool SendCustomRtcp1(uint32 ssrc) {
424 std::string data(CreateRtcpData(ssrc));
425 return media_channel1_->SendRtcp(data.c_str(),
426 static_cast<int>(data.size()));
428 bool SendCustomRtcp2(uint32 ssrc) {
429 std::string data(CreateRtcpData(ssrc));
430 return media_channel2_->SendRtcp(data.c_str(),
431 static_cast<int>(data.size()));
434 return media_channel1_->CheckRtp(rtp_packet_.c_str(),
435 static_cast<int>(rtp_packet_.size()));
438 return media_channel2_->CheckRtp(rtp_packet_.c_str(),
439 static_cast<int>(rtp_packet_.size()));
442 return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
443 static_cast<int>(rtcp_packet_.size()));
446 return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
447 static_cast<int>(rtcp_packet_.size()));
449 // Methods to check custom data.
450 bool CheckCustomRtp1(uint32 ssrc, int sequence_number, int pl_type = -1 ) {
451 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
452 return media_channel1_->CheckRtp(data.c_str(),
453 static_cast<int>(data.size()));
455 bool CheckCustomRtp2(uint32 ssrc, int sequence_number, int pl_type = -1) {
456 std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
457 return media_channel2_->CheckRtp(data.c_str(),
458 static_cast<int>(data.size()));
460 bool CheckCustomRtcp1(uint32 ssrc) {
461 std::string data(CreateRtcpData(ssrc));
462 return media_channel1_->CheckRtcp(data.c_str(),
463 static_cast<int>(data.size()));
465 bool CheckCustomRtcp2(uint32 ssrc) {
466 std::string data(CreateRtcpData(ssrc));
467 return media_channel2_->CheckRtcp(data.c_str(),
468 static_cast<int>(data.size()));
470 std::string CreateRtpData(uint32 ssrc, int sequence_number, int pl_type) {
471 std::string data(rtp_packet_);
472 // Set SSRC in the rtp packet copy.
473 talk_base::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
474 talk_base::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
476 talk_base::Set8(const_cast<char*>(data.c_str()), 1, pl_type);
480 std::string CreateRtcpData(uint32 ssrc) {
481 std::string data(rtcp_packet_);
482 // Set SSRC in the rtcp packet copy.
483 talk_base::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
488 return media_channel1_->CheckNoRtp();
491 return media_channel2_->CheckNoRtp();
493 bool CheckNoRtcp1() {
494 return media_channel1_->CheckNoRtcp();
496 bool CheckNoRtcp2() {
497 return media_channel2_->CheckNoRtcp();
500 void CreateContent(int flags,
501 const cricket::AudioCodec& audio_codec,
502 const cricket::VideoCodec& video_codec,
503 typename T::Content* content) {
504 // overridden in specialized classes
506 void CopyContent(const typename T::Content& source,
507 typename T::Content* content) {
508 // overridden in specialized classes
511 // Creates a cricket::SessionDescription with one MediaContent and one stream.
512 // kPcmuCodec is used as audio codec and kH264Codec is used as video codec.
513 cricket::SessionDescription* CreateSessionDescriptionWithStream(uint32 ssrc) {
514 typename T::Content content;
515 cricket::SessionDescription* sdesc = new cricket::SessionDescription();
516 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content);
517 AddLegacyStreamInContent(ssrc, 0, &content);
518 sdesc->AddContent("DUMMY_CONTENT_NAME",
519 cricket::NS_JINGLE_RTP, content.Copy());
523 class CallThread : public talk_base::SignalThread {
525 typedef bool (ChannelTest<T>::*Method)();
526 CallThread(ChannelTest<T>* obj, Method method, bool* result)
532 virtual void DoWork() {
533 bool result = (*obj_.*method_)();
539 ChannelTest<T>* obj_;
543 void CallOnThread(typename CallThread::Method method, bool* result) {
544 CallThread* thread = new CallThread(this, method, result);
549 void CallOnThreadAndWaitForDone(typename CallThread::Method method,
551 CallThread* thread = new CallThread(this, method, result);
553 thread->Destroy(true);
556 bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
557 return false; // overridden in specialized classes
560 void OnMediaMonitor(typename T::Channel* channel,
561 const typename T::MediaInfo& info) {
562 if (channel == channel1_.get()) {
563 media_info_callbacks1_++;
564 } else if (channel == channel2_.get()) {
565 media_info_callbacks2_++;
569 void OnMediaChannelError(typename T::Channel* channel,
571 typename T::MediaChannel::Error error) {
576 void OnMediaMuted(cricket::BaseChannel* channel, bool muted) {
577 mute_callback_recved_ = true;
578 mute_callback_value_ = muted;
581 void AddLegacyStreamInContent(uint32 ssrc, int flags,
582 typename T::Content* content) {
583 // Base implementation.
586 // Tests that can be used by derived classes.
588 // Basic sanity check.
590 CreateChannels(0, 0);
591 EXPECT_FALSE(channel1_->secure());
592 EXPECT_FALSE(media_channel1_->sending());
593 EXPECT_FALSE(media_channel1_->playout());
594 EXPECT_TRUE(media_channel1_->codecs().empty());
595 EXPECT_TRUE(media_channel1_->recv_streams().empty());
596 EXPECT_TRUE(media_channel1_->rtp_packets().empty());
597 EXPECT_TRUE(media_channel1_->rtcp_packets().empty());
600 // Test that SetLocalContent and SetRemoteContent properly configure
602 void TestSetContents() {
603 CreateChannels(0, 0);
604 typename T::Content content;
605 CreateContent(0, kPcmuCodec, kH264Codec, &content);
606 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
607 EXPECT_EQ(0U, media_channel1_->codecs().size());
608 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
609 ASSERT_EQ(1U, media_channel1_->codecs().size());
610 EXPECT_TRUE(CodecMatches(content.codecs()[0],
611 media_channel1_->codecs()[0]));
614 // Test that SetLocalContent and SetRemoteContent properly deals
615 // with an empty offer.
616 void TestSetContentsNullOffer() {
617 CreateChannels(0, 0);
618 typename T::Content content;
619 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
620 CreateContent(0, kPcmuCodec, kH264Codec, &content);
621 EXPECT_EQ(0U, media_channel1_->codecs().size());
622 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
623 ASSERT_EQ(1U, media_channel1_->codecs().size());
624 EXPECT_TRUE(CodecMatches(content.codecs()[0],
625 media_channel1_->codecs()[0]));
628 // Test that SetLocalContent and SetRemoteContent properly set RTCP
630 void TestSetContentsRtcpMux() {
631 CreateChannels(RTCP, RTCP);
632 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
633 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
634 typename T::Content content;
635 CreateContent(0, kPcmuCodec, kH264Codec, &content);
636 // Both sides agree on mux. Should no longer be a separate RTCP channel.
637 content.set_rtcp_mux(true);
638 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
639 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
640 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
641 // Only initiator supports mux. Should still have a separate RTCP channel.
642 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
643 content.set_rtcp_mux(false);
644 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
645 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
648 // Test that SetLocalContent and SetRemoteContent properly set RTCP
649 // mux when a provisional answer is received.
650 void TestSetContentsRtcpMuxWithPrAnswer() {
651 CreateChannels(RTCP, RTCP);
652 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
653 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
654 typename T::Content content;
655 CreateContent(0, kPcmuCodec, kH264Codec, &content);
656 content.set_rtcp_mux(true);
657 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
658 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL));
659 EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL);
660 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
661 // Both sides agree on mux. Should no longer be a separate RTCP channel.
662 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
663 // Only initiator supports mux. Should still have a separate RTCP channel.
664 EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL));
665 content.set_rtcp_mux(false);
666 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL));
667 EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL));
668 EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL);
671 // Test that SetLocalContent and SetRemoteContent properly set
672 // video options to the media channel.
673 void TestSetContentsVideoOptions() {
674 CreateChannels(0, 0);
675 typename T::Content content;
676 CreateContent(0, kPcmuCodec, kH264Codec, &content);
677 content.set_buffered_mode_latency(101);
678 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
679 EXPECT_EQ(0U, media_channel1_->codecs().size());
680 cricket::VideoOptions options;
681 ASSERT_TRUE(media_channel1_->GetOptions(&options));
683 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
684 EXPECT_EQ(101, latency);
685 content.set_buffered_mode_latency(102);
686 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
687 ASSERT_EQ(1U, media_channel1_->codecs().size());
688 EXPECT_TRUE(CodecMatches(content.codecs()[0],
689 media_channel1_->codecs()[0]));
690 ASSERT_TRUE(media_channel1_->GetOptions(&options));
691 EXPECT_TRUE(options.buffered_mode_latency.Get(&latency));
692 EXPECT_EQ(102, latency);
695 // Test that SetRemoteContent properly deals with a content update.
696 void TestSetRemoteContentUpdate() {
697 CreateChannels(0, 0);
698 typename T::Content content;
699 CreateContent(RTCP | RTCP_MUX | SECURE,
700 kPcmuCodec, kH264Codec,
702 EXPECT_EQ(0U, media_channel1_->codecs().size());
703 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
704 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
705 ASSERT_EQ(1U, media_channel1_->codecs().size());
706 EXPECT_TRUE(CodecMatches(content.codecs()[0],
707 media_channel1_->codecs()[0]));
708 // Now update with other codecs.
709 typename T::Content update_content;
710 update_content.set_partial(true);
711 CreateContent(0, kIsacCodec, kH264SvcCodec,
713 EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL));
714 ASSERT_EQ(1U, media_channel1_->codecs().size());
715 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
716 media_channel1_->codecs()[0]));
717 // Now update without any codecs. This is ignored.
718 typename T::Content empty_content;
719 empty_content.set_partial(true);
720 EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL));
721 ASSERT_EQ(1U, media_channel1_->codecs().size());
722 EXPECT_TRUE(CodecMatches(update_content.codecs()[0],
723 media_channel1_->codecs()[0]));
726 // Test that Add/RemoveStream properly forward to the media channel.
728 CreateChannels(0, 0);
729 EXPECT_TRUE(AddStream1(1));
730 EXPECT_TRUE(AddStream1(2));
731 EXPECT_EQ(2U, media_channel1_->recv_streams().size());
732 EXPECT_TRUE(RemoveStream1(2));
733 EXPECT_EQ(1U, media_channel1_->recv_streams().size());
734 EXPECT_TRUE(RemoveStream1(1));
735 EXPECT_EQ(0U, media_channel1_->recv_streams().size());
738 // Test that SetLocalContent properly handles adding and removing StreamParams
739 // to the local content description.
740 // This test uses the CA_UPDATE action that don't require a full
741 // MediaContentDescription to do an update.
742 void TestUpdateStreamsInLocalContent() {
743 cricket::StreamParams stream1;
744 stream1.groupid = "group1";
745 stream1.id = "stream1";
746 stream1.ssrcs.push_back(kSsrc1);
747 stream1.cname = "stream1_cname";
749 cricket::StreamParams stream2;
750 stream2.groupid = "group2";
751 stream2.id = "stream2";
752 stream2.ssrcs.push_back(kSsrc2);
753 stream2.cname = "stream2_cname";
755 cricket::StreamParams stream3;
756 stream3.groupid = "group3";
757 stream3.id = "stream3";
758 stream3.ssrcs.push_back(kSsrc3);
759 stream3.cname = "stream3_cname";
761 CreateChannels(0, 0);
762 typename T::Content content1;
763 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
764 content1.AddStream(stream1);
765 EXPECT_EQ(0u, media_channel1_->send_streams().size());
766 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
768 ASSERT_EQ(1u, media_channel1_->send_streams().size());
769 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
771 // Update the local streams by adding another sending stream.
772 // Use a partial updated session description.
773 typename T::Content content2;
774 content2.AddStream(stream2);
775 content2.AddStream(stream3);
776 content2.set_partial(true);
777 EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL));
778 ASSERT_EQ(3u, media_channel1_->send_streams().size());
779 EXPECT_EQ(stream1, media_channel1_->send_streams()[0]);
780 EXPECT_EQ(stream2, media_channel1_->send_streams()[1]);
781 EXPECT_EQ(stream3, media_channel1_->send_streams()[2]);
783 // Update the local streams by removing the first sending stream.
784 // This is done by removing all SSRCS for this particular stream.
785 typename T::Content content3;
786 stream1.ssrcs.clear();
787 content3.AddStream(stream1);
788 content3.set_partial(true);
789 EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL));
790 ASSERT_EQ(2u, media_channel1_->send_streams().size());
791 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
792 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
794 // Update the local streams with a stream that does not change.
795 // THe update is ignored.
796 typename T::Content content4;
797 content4.AddStream(stream2);
798 content4.set_partial(true);
799 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL));
800 ASSERT_EQ(2u, media_channel1_->send_streams().size());
801 EXPECT_EQ(stream2, media_channel1_->send_streams()[0]);
802 EXPECT_EQ(stream3, media_channel1_->send_streams()[1]);
805 // Test that SetRemoteContent properly handles adding and removing
806 // StreamParams to the remote content description.
807 // This test uses the CA_UPDATE action that don't require a full
808 // MediaContentDescription to do an update.
809 void TestUpdateStreamsInRemoteContent() {
810 cricket::StreamParams stream1;
811 stream1.id = "Stream1";
812 stream1.groupid = "1";
813 stream1.ssrcs.push_back(kSsrc1);
814 stream1.cname = "stream1_cname";
816 cricket::StreamParams stream2;
817 stream2.id = "Stream2";
818 stream2.groupid = "2";
819 stream2.ssrcs.push_back(kSsrc2);
820 stream2.cname = "stream2_cname";
822 cricket::StreamParams stream3;
823 stream3.id = "Stream3";
824 stream3.groupid = "3";
825 stream3.ssrcs.push_back(kSsrc3);
826 stream3.cname = "stream3_cname";
828 CreateChannels(0, 0);
829 typename T::Content content1;
830 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
831 content1.AddStream(stream1);
832 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
833 EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL));
835 ASSERT_EQ(1u, media_channel1_->codecs().size());
836 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
837 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
839 // Update the remote streams by adding another sending stream.
840 // Use a partial updated session description.
841 typename T::Content content2;
842 content2.AddStream(stream2);
843 content2.AddStream(stream3);
844 content2.set_partial(true);
845 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL));
846 ASSERT_EQ(3u, media_channel1_->recv_streams().size());
847 EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]);
848 EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]);
849 EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]);
851 // Update the remote streams by removing the first stream.
852 // This is done by removing all SSRCS for this particular stream.
853 typename T::Content content3;
854 stream1.ssrcs.clear();
855 content3.AddStream(stream1);
856 content3.set_partial(true);
857 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL));
858 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
859 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
860 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
862 // Update the remote streams with a stream that does not change.
863 // The update is ignored.
864 typename T::Content content4;
865 content4.AddStream(stream2);
866 content4.set_partial(true);
867 EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL));
868 ASSERT_EQ(2u, media_channel1_->recv_streams().size());
869 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
870 EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]);
873 // Test that SetLocalContent and SetRemoteContent properly
874 // handles adding and removing StreamParams when the action is a full
875 // CA_OFFER / CA_ANSWER.
876 void TestChangeStreamParamsInContent() {
877 cricket::StreamParams stream1;
878 stream1.groupid = "group1";
879 stream1.id = "stream1";
880 stream1.ssrcs.push_back(kSsrc1);
881 stream1.cname = "stream1_cname";
883 cricket::StreamParams stream2;
884 stream2.groupid = "group1";
885 stream2.id = "stream2";
886 stream2.ssrcs.push_back(kSsrc2);
887 stream2.cname = "stream2_cname";
889 // Setup a call where channel 1 send |stream1| to channel 2.
890 CreateChannels(0, 0);
891 typename T::Content content1;
892 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
893 content1.AddStream(stream1);
894 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
895 EXPECT_TRUE(channel1_->Enable(true));
896 EXPECT_EQ(1u, media_channel1_->send_streams().size());
898 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
899 EXPECT_EQ(1u, media_channel2_->recv_streams().size());
900 session1_.Connect(&session2_);
902 // Channel 2 do not send anything.
903 typename T::Content content2;
904 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
905 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
906 EXPECT_EQ(0u, media_channel1_->recv_streams().size());
907 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
908 EXPECT_TRUE(channel2_->Enable(true));
909 EXPECT_EQ(0u, media_channel2_->send_streams().size());
911 EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
912 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
914 // Let channel 2 update the content by sending |stream2| and enable SRTP.
915 typename T::Content content3;
916 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3);
917 content3.AddStream(stream2);
918 EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL));
919 ASSERT_EQ(1u, media_channel2_->send_streams().size());
920 EXPECT_EQ(stream2, media_channel2_->send_streams()[0]);
922 EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL));
923 ASSERT_EQ(1u, media_channel1_->recv_streams().size());
924 EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]);
926 // Channel 1 replies but stop sending stream1.
927 typename T::Content content4;
928 CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4);
929 EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL));
930 EXPECT_EQ(0u, media_channel1_->send_streams().size());
932 EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL));
933 EXPECT_EQ(0u, media_channel2_->recv_streams().size());
935 EXPECT_TRUE(channel1_->secure());
936 EXPECT_TRUE(channel2_->secure());
937 EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
938 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
941 // Test that we only start playout and sending at the right times.
942 void TestPlayoutAndSendingStates() {
943 CreateChannels(0, 0);
944 EXPECT_FALSE(media_channel1_->playout());
945 EXPECT_FALSE(media_channel1_->sending());
946 EXPECT_FALSE(media_channel2_->playout());
947 EXPECT_FALSE(media_channel2_->sending());
948 EXPECT_TRUE(channel1_->Enable(true));
949 EXPECT_FALSE(media_channel1_->playout());
950 EXPECT_FALSE(media_channel1_->sending());
951 EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_,
953 EXPECT_TRUE(media_channel1_->playout());
954 EXPECT_FALSE(media_channel1_->sending());
955 EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_,
957 EXPECT_FALSE(media_channel2_->playout());
958 EXPECT_FALSE(media_channel2_->sending());
959 EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_,
961 EXPECT_FALSE(media_channel2_->playout());
962 EXPECT_FALSE(media_channel2_->sending());
963 session1_.Connect(&session2_);
964 EXPECT_TRUE(media_channel1_->playout());
965 EXPECT_FALSE(media_channel1_->sending());
966 EXPECT_FALSE(media_channel2_->playout());
967 EXPECT_FALSE(media_channel2_->sending());
968 EXPECT_TRUE(channel2_->Enable(true));
969 EXPECT_TRUE(media_channel2_->playout());
970 EXPECT_TRUE(media_channel2_->sending());
971 EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_,
973 EXPECT_TRUE(media_channel1_->playout());
974 EXPECT_TRUE(media_channel1_->sending());
977 void TestMuteStream() {
978 CreateChannels(0, 0);
979 // Test that we can Mute the default channel even though the sending SSRC is
981 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
982 EXPECT_TRUE(channel1_->MuteStream(0, true));
983 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
984 EXPECT_TRUE(channel1_->MuteStream(0, false));
985 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
987 // Test that we can not mute an unknown SSRC.
988 EXPECT_FALSE(channel1_->MuteStream(kSsrc1, true));
991 // After the local session description has been set, we can mute a stream
993 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, true));
994 EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
995 EXPECT_TRUE(channel1_->MuteStream(kSsrc1, false));
996 EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
999 // Test that changing the MediaContentDirection in the local and remote
1000 // session description start playout and sending at the right time.
1001 void TestMediaContentDirection() {
1002 CreateChannels(0, 0);
1003 typename T::Content content1;
1004 CreateContent(0, kPcmuCodec, kH264Codec, &content1);
1005 typename T::Content content2;
1006 CreateContent(0, kPcmuCodec, kH264Codec, &content2);
1007 // Set |content2| to be InActive.
1008 content2.set_direction(cricket::MD_INACTIVE);
1010 EXPECT_TRUE(channel1_->Enable(true));
1011 EXPECT_TRUE(channel2_->Enable(true));
1012 EXPECT_FALSE(media_channel1_->playout());
1013 EXPECT_FALSE(media_channel1_->sending());
1014 EXPECT_FALSE(media_channel2_->playout());
1015 EXPECT_FALSE(media_channel2_->sending());
1017 EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL));
1018 EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
1019 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
1020 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
1021 session1_.Connect(&session2_);
1023 EXPECT_TRUE(media_channel1_->playout());
1024 EXPECT_FALSE(media_channel1_->sending()); // remote InActive
1025 EXPECT_FALSE(media_channel2_->playout()); // local InActive
1026 EXPECT_FALSE(media_channel2_->sending()); // local InActive
1028 // Update |content2| to be RecvOnly.
1029 content2.set_direction(cricket::MD_RECVONLY);
1030 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
1031 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
1033 EXPECT_TRUE(media_channel1_->playout());
1034 EXPECT_TRUE(media_channel1_->sending());
1035 EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly
1036 EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly
1038 // Update |content2| to be SendRecv.
1039 content2.set_direction(cricket::MD_SENDRECV);
1040 EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL));
1041 EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL));
1043 EXPECT_TRUE(media_channel1_->playout());
1044 EXPECT_TRUE(media_channel1_->sending());
1045 EXPECT_TRUE(media_channel2_->playout());
1046 EXPECT_TRUE(media_channel2_->sending());
1049 // Test setting up a call.
1050 void TestCallSetup() {
1051 CreateChannels(0, 0);
1052 EXPECT_FALSE(channel1_->secure());
1053 EXPECT_TRUE(SendInitiate());
1054 EXPECT_TRUE(media_channel1_->playout());
1055 EXPECT_FALSE(media_channel1_->sending());
1056 EXPECT_TRUE(SendAccept());
1057 EXPECT_FALSE(channel1_->secure());
1058 EXPECT_TRUE(media_channel1_->sending());
1059 EXPECT_EQ(1U, media_channel1_->codecs().size());
1060 EXPECT_TRUE(media_channel2_->playout());
1061 EXPECT_TRUE(media_channel2_->sending());
1062 EXPECT_EQ(1U, media_channel2_->codecs().size());
1065 // Test that we don't crash if packets are sent during call teardown
1066 // when RTCP mux is enabled. This is a regression test against a specific
1067 // race condition that would only occur when a RTCP packet was sent during
1068 // teardown of a channel on which RTCP mux was enabled.
1069 void TestCallTeardownRtcpMux() {
1070 class LastWordMediaChannel : public T::MediaChannel {
1072 LastWordMediaChannel() : T::MediaChannel(NULL) {}
1073 ~LastWordMediaChannel() {
1074 T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame));
1075 T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport));
1078 CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
1079 RTCP | RTCP_MUX, RTCP | RTCP_MUX,
1080 talk_base::Thread::Current());
1081 EXPECT_TRUE(SendInitiate());
1082 EXPECT_TRUE(SendAccept());
1083 EXPECT_TRUE(SendTerminate());
1086 // Send voice RTP data to the other side and ensure it gets there.
1087 void SendRtpToRtp() {
1088 CreateChannels(0, 0);
1089 EXPECT_TRUE(SendInitiate());
1090 EXPECT_TRUE(SendAccept());
1091 EXPECT_EQ(1U, GetTransport1()->channels().size());
1092 EXPECT_EQ(1U, GetTransport2()->channels().size());
1093 EXPECT_TRUE(SendRtp1());
1094 EXPECT_TRUE(SendRtp2());
1095 EXPECT_TRUE(CheckRtp1());
1096 EXPECT_TRUE(CheckRtp2());
1097 EXPECT_TRUE(CheckNoRtp1());
1098 EXPECT_TRUE(CheckNoRtp2());
1101 // Check that RTCP is not transmitted if both sides don't support RTCP.
1102 void SendNoRtcpToNoRtcp() {
1103 CreateChannels(0, 0);
1104 EXPECT_TRUE(SendInitiate());
1105 EXPECT_TRUE(SendAccept());
1106 EXPECT_EQ(1U, GetTransport1()->channels().size());
1107 EXPECT_EQ(1U, GetTransport2()->channels().size());
1108 EXPECT_FALSE(SendRtcp1());
1109 EXPECT_FALSE(SendRtcp2());
1110 EXPECT_TRUE(CheckNoRtcp1());
1111 EXPECT_TRUE(CheckNoRtcp2());
1114 // Check that RTCP is not transmitted if the callee doesn't support RTCP.
1115 void SendNoRtcpToRtcp() {
1116 CreateChannels(0, RTCP);
1117 EXPECT_TRUE(SendInitiate());
1118 EXPECT_TRUE(SendAccept());
1119 EXPECT_EQ(1U, GetTransport1()->channels().size());
1120 EXPECT_EQ(2U, GetTransport2()->channels().size());
1121 EXPECT_FALSE(SendRtcp1());
1122 EXPECT_FALSE(SendRtcp2());
1123 EXPECT_TRUE(CheckNoRtcp1());
1124 EXPECT_TRUE(CheckNoRtcp2());
1127 // Check that RTCP is not transmitted if the caller doesn't support RTCP.
1128 void SendRtcpToNoRtcp() {
1129 CreateChannels(RTCP, 0);
1130 EXPECT_TRUE(SendInitiate());
1131 EXPECT_TRUE(SendAccept());
1132 EXPECT_EQ(2U, GetTransport1()->channels().size());
1133 EXPECT_EQ(1U, GetTransport2()->channels().size());
1134 EXPECT_FALSE(SendRtcp1());
1135 EXPECT_FALSE(SendRtcp2());
1136 EXPECT_TRUE(CheckNoRtcp1());
1137 EXPECT_TRUE(CheckNoRtcp2());
1140 // Check that RTCP is transmitted if both sides support RTCP.
1141 void SendRtcpToRtcp() {
1142 CreateChannels(RTCP, RTCP);
1143 EXPECT_TRUE(SendInitiate());
1144 EXPECT_TRUE(SendAccept());
1145 EXPECT_EQ(2U, GetTransport1()->channels().size());
1146 EXPECT_EQ(2U, GetTransport2()->channels().size());
1147 EXPECT_TRUE(SendRtcp1());
1148 EXPECT_TRUE(SendRtcp2());
1149 EXPECT_TRUE(CheckRtcp1());
1150 EXPECT_TRUE(CheckRtcp2());
1151 EXPECT_TRUE(CheckNoRtcp1());
1152 EXPECT_TRUE(CheckNoRtcp2());
1155 // Check that RTCP is transmitted if only the initiator supports mux.
1156 void SendRtcpMuxToRtcp() {
1157 CreateChannels(RTCP | RTCP_MUX, RTCP);
1158 EXPECT_TRUE(SendInitiate());
1159 EXPECT_TRUE(SendAccept());
1160 EXPECT_EQ(2U, GetTransport1()->channels().size());
1161 EXPECT_EQ(2U, GetTransport2()->channels().size());
1162 EXPECT_TRUE(SendRtcp1());
1163 EXPECT_TRUE(SendRtcp2());
1164 EXPECT_TRUE(CheckRtcp1());
1165 EXPECT_TRUE(CheckRtcp2());
1166 EXPECT_TRUE(CheckNoRtcp1());
1167 EXPECT_TRUE(CheckNoRtcp2());
1170 // Check that RTP and RTCP are transmitted ok when both sides support mux.
1171 void SendRtcpMuxToRtcpMux() {
1172 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1173 EXPECT_TRUE(SendInitiate());
1174 EXPECT_EQ(2U, GetTransport1()->channels().size());
1175 EXPECT_EQ(1U, GetTransport2()->channels().size());
1176 EXPECT_TRUE(SendAccept());
1177 EXPECT_EQ(1U, GetTransport1()->channels().size());
1178 EXPECT_TRUE(SendRtp1());
1179 EXPECT_TRUE(SendRtp2());
1180 EXPECT_TRUE(SendRtcp1());
1181 EXPECT_TRUE(SendRtcp2());
1182 EXPECT_TRUE(CheckRtp1());
1183 EXPECT_TRUE(CheckRtp2());
1184 EXPECT_TRUE(CheckNoRtp1());
1185 EXPECT_TRUE(CheckNoRtp2());
1186 EXPECT_TRUE(CheckRtcp1());
1187 EXPECT_TRUE(CheckRtcp2());
1188 EXPECT_TRUE(CheckNoRtcp1());
1189 EXPECT_TRUE(CheckNoRtcp2());
1192 // Check that RTCP data sent by the initiator before the accept is not muxed.
1193 void SendEarlyRtcpMuxToRtcp() {
1194 CreateChannels(RTCP | RTCP_MUX, RTCP);
1195 EXPECT_TRUE(SendInitiate());
1196 EXPECT_EQ(2U, GetTransport1()->channels().size());
1197 EXPECT_EQ(2U, GetTransport2()->channels().size());
1199 // RTCP can be sent before the call is accepted, if the transport is ready.
1200 // It should not be muxed though, as the remote side doesn't support mux.
1201 EXPECT_TRUE(SendRtcp1());
1202 EXPECT_TRUE(CheckNoRtp2());
1203 EXPECT_TRUE(CheckRtcp2());
1205 // Send RTCP packet from callee and verify that it is received.
1206 EXPECT_TRUE(SendRtcp2());
1207 EXPECT_TRUE(CheckNoRtp1());
1208 EXPECT_TRUE(CheckRtcp1());
1210 // Complete call setup and ensure everything is still OK.
1211 EXPECT_TRUE(SendAccept());
1212 EXPECT_EQ(2U, GetTransport1()->channels().size());
1213 EXPECT_TRUE(SendRtcp1());
1214 EXPECT_TRUE(CheckRtcp2());
1215 EXPECT_TRUE(SendRtcp2());
1216 EXPECT_TRUE(CheckRtcp1());
1220 // Check that RTCP data is not muxed until both sides have enabled muxing,
1221 // but that we properly demux before we get the accept message, since there
1222 // is a race between RTP data and the jingle accept.
1223 void SendEarlyRtcpMuxToRtcpMux() {
1224 CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
1225 EXPECT_TRUE(SendInitiate());
1226 EXPECT_EQ(2U, GetTransport1()->channels().size());
1227 EXPECT_EQ(1U, GetTransport2()->channels().size());
1229 // RTCP can't be sent yet, since the RTCP transport isn't writable, and
1230 // we haven't yet received the accept that says we should mux.
1231 EXPECT_FALSE(SendRtcp1());
1233 // Send muxed RTCP packet from callee and verify that it is received.
1234 EXPECT_TRUE(SendRtcp2());
1235 EXPECT_TRUE(CheckNoRtp1());
1236 EXPECT_TRUE(CheckRtcp1());
1238 // Complete call setup and ensure everything is still OK.
1239 EXPECT_TRUE(SendAccept());
1240 EXPECT_EQ(1U, GetTransport1()->channels().size());
1241 EXPECT_TRUE(SendRtcp1());
1242 EXPECT_TRUE(CheckRtcp2());
1243 EXPECT_TRUE(SendRtcp2());
1244 EXPECT_TRUE(CheckRtcp1());
1247 // Test that we properly send SRTP with RTCP in both directions.
1248 // You can pass in DTLS and/or RTCP_MUX as flags.
1249 void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) {
1250 ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0);
1251 ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0);
1253 int flags1 = RTCP | SECURE | flags1_in;
1254 int flags2 = RTCP | SECURE | flags2_in;
1255 bool dtls1 = !!(flags1_in & DTLS);
1256 bool dtls2 = !!(flags2_in & DTLS);
1257 CreateChannels(flags1, flags2);
1258 EXPECT_FALSE(channel1_->secure());
1259 EXPECT_FALSE(channel2_->secure());
1260 EXPECT_TRUE(SendInitiate());
1261 EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
1262 EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
1263 EXPECT_TRUE(SendAccept());
1264 EXPECT_TRUE(channel1_->secure());
1265 EXPECT_TRUE(channel2_->secure());
1266 EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
1267 EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
1268 EXPECT_TRUE(SendRtp1());
1269 EXPECT_TRUE(SendRtp2());
1270 EXPECT_TRUE(SendRtcp1());
1271 EXPECT_TRUE(SendRtcp2());
1272 EXPECT_TRUE(CheckRtp1());
1273 EXPECT_TRUE(CheckRtp2());
1274 EXPECT_TRUE(CheckNoRtp1());
1275 EXPECT_TRUE(CheckNoRtp2());
1276 EXPECT_TRUE(CheckRtcp1());
1277 EXPECT_TRUE(CheckRtcp2());
1278 EXPECT_TRUE(CheckNoRtcp1());
1279 EXPECT_TRUE(CheckNoRtcp2());
1282 // Test that we properly handling SRTP negotiating down to RTP.
1283 void SendSrtpToRtp() {
1284 CreateChannels(RTCP | SECURE, RTCP);
1285 EXPECT_FALSE(channel1_->secure());
1286 EXPECT_FALSE(channel2_->secure());
1287 EXPECT_TRUE(SendInitiate());
1288 EXPECT_TRUE(SendAccept());
1289 EXPECT_FALSE(channel1_->secure());
1290 EXPECT_FALSE(channel2_->secure());
1291 EXPECT_TRUE(SendRtp1());
1292 EXPECT_TRUE(SendRtp2());
1293 EXPECT_TRUE(SendRtcp1());
1294 EXPECT_TRUE(SendRtcp2());
1295 EXPECT_TRUE(CheckRtp1());
1296 EXPECT_TRUE(CheckRtp2());
1297 EXPECT_TRUE(CheckNoRtp1());
1298 EXPECT_TRUE(CheckNoRtp2());
1299 EXPECT_TRUE(CheckRtcp1());
1300 EXPECT_TRUE(CheckRtcp2());
1301 EXPECT_TRUE(CheckNoRtcp1());
1302 EXPECT_TRUE(CheckNoRtcp2());
1305 // Test that we can send and receive early media when a provisional answer is
1306 // sent and received. The test uses SRTP, RTCP mux and SSRC mux.
1307 void SendEarlyMediaUsingRtcpMuxSrtp() {
1308 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1310 CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE,
1311 SSRC_MUX | RTCP | RTCP_MUX | SECURE);
1312 EXPECT_TRUE(SendOffer());
1313 EXPECT_TRUE(SendProvisionalAnswer());
1314 EXPECT_TRUE(channel1_->secure());
1315 EXPECT_TRUE(channel2_->secure());
1316 EXPECT_EQ(2U, GetTransport1()->channels().size());
1317 EXPECT_EQ(2U, GetTransport2()->channels().size());
1318 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1319 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1320 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1321 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1323 // Send packets from callee and verify that it is received.
1324 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1325 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1326 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1327 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1329 // Complete call setup and ensure everything is still OK.
1330 EXPECT_TRUE(SendFinalAnswer());
1331 EXPECT_EQ(1U, GetTransport1()->channels().size());
1332 EXPECT_EQ(1U, GetTransport2()->channels().size());
1333 EXPECT_TRUE(channel1_->secure());
1334 EXPECT_TRUE(channel2_->secure());
1335 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1336 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1337 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
1338 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
1339 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1340 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1341 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
1342 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
1345 // Test that we properly send RTP without SRTP from a thread.
1346 void SendRtpToRtpOnThread() {
1347 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1348 CreateChannels(RTCP, RTCP);
1349 EXPECT_TRUE(SendInitiate());
1350 EXPECT_TRUE(SendAccept());
1351 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1352 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1353 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1354 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1355 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1356 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1357 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1358 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1359 EXPECT_TRUE(CheckNoRtp1());
1360 EXPECT_TRUE(CheckNoRtp2());
1361 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1362 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1363 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1364 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1365 EXPECT_TRUE(CheckNoRtcp1());
1366 EXPECT_TRUE(CheckNoRtcp2());
1369 // Test that we properly send SRTP with RTCP from a thread.
1370 void SendSrtpToSrtpOnThread() {
1371 bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2;
1372 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1373 EXPECT_TRUE(SendInitiate());
1374 EXPECT_TRUE(SendAccept());
1375 CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1);
1376 CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2);
1377 CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1);
1378 CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2);
1379 EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
1380 EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
1381 EXPECT_TRUE_WAIT(sent_rtp1, 1000);
1382 EXPECT_TRUE_WAIT(sent_rtp2, 1000);
1383 EXPECT_TRUE(CheckNoRtp1());
1384 EXPECT_TRUE(CheckNoRtp2());
1385 EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
1386 EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
1387 EXPECT_TRUE_WAIT(sent_rtcp1, 1000);
1388 EXPECT_TRUE_WAIT(sent_rtcp2, 1000);
1389 EXPECT_TRUE(CheckNoRtcp1());
1390 EXPECT_TRUE(CheckNoRtcp2());
1393 // Test that the mediachannel retains its sending state after the transport
1394 // becomes non-writable.
1395 void SendWithWritabilityLoss() {
1396 CreateChannels(0, 0);
1397 EXPECT_TRUE(SendInitiate());
1398 EXPECT_TRUE(SendAccept());
1399 EXPECT_EQ(1U, GetTransport1()->channels().size());
1400 EXPECT_EQ(1U, GetTransport2()->channels().size());
1401 EXPECT_TRUE(SendRtp1());
1402 EXPECT_TRUE(SendRtp2());
1403 EXPECT_TRUE(CheckRtp1());
1404 EXPECT_TRUE(CheckRtp2());
1405 EXPECT_TRUE(CheckNoRtp1());
1406 EXPECT_TRUE(CheckNoRtp2());
1408 // Lose writability, which should fail.
1409 GetTransport1()->SetWritable(false);
1410 EXPECT_FALSE(SendRtp1());
1411 EXPECT_TRUE(SendRtp2());
1412 EXPECT_TRUE(CheckRtp1());
1413 EXPECT_TRUE(CheckNoRtp2());
1415 // Regain writability
1416 GetTransport1()->SetWritable(true);
1417 EXPECT_TRUE(media_channel1_->sending());
1418 EXPECT_TRUE(SendRtp1());
1419 EXPECT_TRUE(SendRtp2());
1420 EXPECT_TRUE(CheckRtp1());
1421 EXPECT_TRUE(CheckRtp2());
1422 EXPECT_TRUE(CheckNoRtp1());
1423 EXPECT_TRUE(CheckNoRtp2());
1425 // Lose writability completely
1426 GetTransport1()->SetDestination(NULL);
1427 EXPECT_TRUE(media_channel1_->sending());
1429 // Should fail also.
1430 EXPECT_FALSE(SendRtp1());
1431 EXPECT_TRUE(SendRtp2());
1432 EXPECT_TRUE(CheckRtp1());
1433 EXPECT_TRUE(CheckNoRtp2());
1435 // Gain writability back
1436 GetTransport1()->SetDestination(GetTransport2());
1437 EXPECT_TRUE(media_channel1_->sending());
1438 EXPECT_TRUE(SendRtp1());
1439 EXPECT_TRUE(SendRtp2());
1440 EXPECT_TRUE(CheckRtp1());
1441 EXPECT_TRUE(CheckRtp2());
1442 EXPECT_TRUE(CheckNoRtp1());
1443 EXPECT_TRUE(CheckNoRtp2());
1446 void SendBundleToBundle(
1447 const int* pl_types, int len, bool rtcp_mux, bool secure) {
1449 int sequence_number1_1 = 0, sequence_number2_2 = 0;
1450 // Only pl_type1 was added to the bundle filter for both |channel1_|
1452 int pl_type1 = pl_types[0];
1453 int pl_type2 = pl_types[1];
1454 int flags = SSRC_MUX | RTCP;
1455 if (secure) flags |= SECURE;
1456 uint32 expected_channels = 2U;
1459 expected_channels = 1U;
1461 CreateChannels(flags, flags);
1462 EXPECT_TRUE(SendInitiate());
1463 EXPECT_EQ(2U, GetTransport1()->channels().size());
1464 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1465 EXPECT_TRUE(SendAccept());
1466 EXPECT_EQ(expected_channels, GetTransport1()->channels().size());
1467 EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
1468 EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1));
1469 EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1));
1470 EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2));
1471 EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
1472 // channel1 - should only have media_content2 as remote. i.e. kSsrc2
1473 EXPECT_TRUE(channel1_->bundle_filter()->FindStream(kSsrc2));
1474 EXPECT_FALSE(channel1_->bundle_filter()->FindStream(kSsrc1));
1475 // channel2 - should only have media_content1 as remote. i.e. kSsrc1
1476 EXPECT_TRUE(channel2_->bundle_filter()->FindStream(kSsrc1));
1477 EXPECT_FALSE(channel2_->bundle_filter()->FindStream(kSsrc2));
1479 // Both channels can receive pl_type1 only.
1480 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
1481 EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
1482 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
1483 EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
1484 EXPECT_TRUE(CheckNoRtp1());
1485 EXPECT_TRUE(CheckNoRtp2());
1488 EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
1489 EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
1490 EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
1491 EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
1493 EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
1494 EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
1495 EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
1496 EXPECT_TRUE(CheckNoRtcp1());
1497 EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
1498 EXPECT_TRUE(CheckNoRtcp2());
1500 EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
1501 EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
1502 EXPECT_FALSE(CheckCustomRtcp1(kSsrc1));
1503 EXPECT_FALSE(CheckCustomRtcp2(kSsrc2));
1506 // Test that the media monitor can be run and gives timely callbacks.
1507 void TestMediaMonitor() {
1508 static const int kTimeout = 500;
1509 CreateChannels(0, 0);
1510 EXPECT_TRUE(SendInitiate());
1511 EXPECT_TRUE(SendAccept());
1512 channel1_->StartMediaMonitor(100);
1513 channel2_->StartMediaMonitor(100);
1514 // Ensure we get callbacks and stop.
1515 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1516 EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout);
1517 channel1_->StopMediaMonitor();
1518 channel2_->StopMediaMonitor();
1519 // Ensure a restart of a stopped monitor works.
1520 channel1_->StartMediaMonitor(100);
1521 EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout);
1522 channel1_->StopMediaMonitor();
1523 // Ensure stopping a stopped monitor is OK.
1524 channel1_->StopMediaMonitor();
1527 void TestMediaSinks() {
1528 CreateChannels(0, 0);
1529 EXPECT_TRUE(SendInitiate());
1530 EXPECT_TRUE(SendAccept());
1531 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1532 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1533 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1534 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1536 talk_base::Pathname path;
1537 EXPECT_TRUE(talk_base::Filesystem::GetTemporaryFolder(path, true, NULL));
1538 path.SetFilename("sink-test.rtpdump");
1539 talk_base::scoped_ptr<cricket::RtpDumpSink> sink(
1540 new cricket::RtpDumpSink(Open(path.pathname())));
1541 sink->set_packet_filter(cricket::PF_ALL);
1542 EXPECT_TRUE(sink->Enable(true));
1543 channel1_->RegisterSendSink(
1544 sink.get(), &cricket::RtpDumpSink::OnPacket, cricket::SINK_POST_CRYPTO);
1545 EXPECT_TRUE(channel1_->HasSendSinks(cricket::SINK_POST_CRYPTO));
1546 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_POST_CRYPTO));
1547 EXPECT_FALSE(channel1_->HasSendSinks(cricket::SINK_PRE_CRYPTO));
1548 EXPECT_FALSE(channel1_->HasRecvSinks(cricket::SINK_PRE_CRYPTO));
1550 // The first packet is recorded with header + data.
1551 EXPECT_TRUE(SendRtp1());
1552 // The second packet is recorded with header only.
1553 sink->set_packet_filter(cricket::PF_RTPHEADER);
1554 EXPECT_TRUE(SendRtp1());
1555 // The third packet is not recorded since sink is disabled.
1556 EXPECT_TRUE(sink->Enable(false));
1557 EXPECT_TRUE(SendRtp1());
1558 // The fourth packet is not recorded since sink is unregistered.
1559 EXPECT_TRUE(sink->Enable(true));
1560 channel1_->UnregisterSendSink(sink.get(), cricket::SINK_POST_CRYPTO);
1561 EXPECT_TRUE(SendRtp1());
1562 sink.reset(); // This will close the file.
1564 // Read the recorded file and verify two packets.
1565 talk_base::scoped_ptr<talk_base::StreamInterface> stream(
1566 talk_base::Filesystem::OpenFile(path, "rb"));
1568 cricket::RtpDumpReader reader(stream.get());
1569 cricket::RtpDumpPacket packet;
1570 EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
1571 std::string read_packet(reinterpret_cast<const char*>(&packet.data[0]),
1572 packet.data.size());
1573 EXPECT_EQ(rtp_packet_, read_packet);
1575 EXPECT_EQ(talk_base::SR_SUCCESS, reader.ReadPacket(&packet));
1577 packet.GetRtpHeaderLen(&len);
1578 EXPECT_EQ(len, packet.data.size());
1579 EXPECT_EQ(0, memcmp(&packet.data[0], rtp_packet_.c_str(), len));
1581 EXPECT_EQ(talk_base::SR_EOS, reader.ReadPacket(&packet));
1583 // Delete the file for media recording.
1585 EXPECT_TRUE(talk_base::Filesystem::DeleteFile(path));
1588 void TestSetContentFailure() {
1589 CreateChannels(0, 0);
1590 typename T::Content content;
1591 cricket::SessionDescription* sdesc_loc = new cricket::SessionDescription();
1592 cricket::SessionDescription* sdesc_rem = new cricket::SessionDescription();
1594 // Set up the session description.
1595 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1596 sdesc_loc->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1597 new cricket::AudioContentDescription());
1598 sdesc_loc->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1599 new cricket::VideoContentDescription());
1600 EXPECT_TRUE(session1_.set_local_description(sdesc_loc));
1601 sdesc_rem->AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP,
1602 new cricket::AudioContentDescription());
1603 sdesc_rem->AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP,
1604 new cricket::VideoContentDescription());
1605 EXPECT_TRUE(session1_.set_remote_description(sdesc_rem));
1607 // Test failures in SetLocalContent.
1608 media_channel1_->set_fail_set_recv_codecs(true);
1609 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1610 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1611 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1612 media_channel1_->set_fail_set_recv_codecs(true);
1613 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1614 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
1615 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1617 // Test failures in SetRemoteContent.
1618 media_channel1_->set_fail_set_send_codecs(true);
1619 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1620 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1621 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1622 media_channel1_->set_fail_set_send_codecs(true);
1623 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1624 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
1625 EXPECT_EQ(cricket::BaseSession::ERROR_CONTENT, session1_.error());
1628 void TestSendTwoOffers() {
1629 CreateChannels(0, 0);
1631 // Set up the initial session description.
1632 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1633 EXPECT_TRUE(session1_.set_local_description(sdesc));
1635 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1636 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1637 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1638 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1640 // Update the local description and set the state again.
1641 sdesc = CreateSessionDescriptionWithStream(2);
1642 EXPECT_TRUE(session1_.set_local_description(sdesc));
1644 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1645 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1646 EXPECT_FALSE(media_channel1_->HasSendStream(1));
1647 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1650 void TestReceiveTwoOffers() {
1651 CreateChannels(0, 0);
1653 // Set up the initial session description.
1654 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1655 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1657 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1658 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1659 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1660 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1662 sdesc = CreateSessionDescriptionWithStream(2);
1663 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1664 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1665 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1666 EXPECT_FALSE(media_channel1_->HasRecvStream(1));
1667 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1670 void TestSendPrAnswer() {
1671 CreateChannels(0, 0);
1673 // Set up the initial session description.
1674 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1675 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1677 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1678 session1_.SetState(cricket::Session::STATE_RECEIVEDINITIATE);
1679 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1680 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1683 sdesc = CreateSessionDescriptionWithStream(2);
1684 EXPECT_TRUE(session1_.set_local_description(sdesc));
1686 session1_.SetState(cricket::Session::STATE_SENTPRACCEPT);
1687 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1688 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1689 EXPECT_TRUE(media_channel1_->HasSendStream(2));
1692 sdesc = CreateSessionDescriptionWithStream(3);
1693 EXPECT_TRUE(session1_.set_local_description(sdesc));
1695 session1_.SetState(cricket::Session::STATE_SENTACCEPT);
1696 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1697 EXPECT_TRUE(media_channel1_->HasRecvStream(1));
1698 EXPECT_FALSE(media_channel1_->HasSendStream(2));
1699 EXPECT_TRUE(media_channel1_->HasSendStream(3));
1702 void TestReceivePrAnswer() {
1703 CreateChannels(0, 0);
1705 // Set up the initial session description.
1706 cricket::SessionDescription* sdesc = CreateSessionDescriptionWithStream(1);
1707 EXPECT_TRUE(session1_.set_local_description(sdesc));
1709 session1_.SetError(cricket::BaseSession::ERROR_NONE, "");
1710 session1_.SetState(cricket::Session::STATE_SENTINITIATE);
1711 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1712 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1715 sdesc = CreateSessionDescriptionWithStream(2);
1716 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1718 session1_.SetState(cricket::Session::STATE_RECEIVEDPRACCEPT);
1719 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1720 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1721 EXPECT_TRUE(media_channel1_->HasRecvStream(2));
1724 sdesc = CreateSessionDescriptionWithStream(3);
1725 EXPECT_TRUE(session1_.set_remote_description(sdesc));
1727 session1_.SetState(cricket::Session::STATE_RECEIVEDACCEPT);
1728 EXPECT_EQ(cricket::BaseSession::ERROR_NONE, session1_.error());
1729 EXPECT_TRUE(media_channel1_->HasSendStream(1));
1730 EXPECT_FALSE(media_channel1_->HasRecvStream(2));
1731 EXPECT_TRUE(media_channel1_->HasRecvStream(3));
1734 void TestFlushRtcp() {
1737 CreateChannels(RTCP, RTCP);
1738 EXPECT_TRUE(SendInitiate());
1739 EXPECT_TRUE(SendAccept());
1740 EXPECT_EQ(2U, GetTransport1()->channels().size());
1741 EXPECT_EQ(2U, GetTransport2()->channels().size());
1743 // Send RTCP1 from a different thread.
1744 CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
1745 EXPECT_TRUE(send_rtcp1);
1746 // The sending message is only posted. channel2_ should be empty.
1747 EXPECT_TRUE(CheckNoRtcp2());
1749 // When channel1_ is deleted, the RTCP packet should be sent out to
1752 EXPECT_TRUE(CheckRtcp2());
1755 void TestChangeStateError() {
1756 CreateChannels(RTCP, RTCP);
1757 EXPECT_TRUE(SendInitiate());
1758 media_channel2_->set_fail_set_send(true);
1759 EXPECT_TRUE(channel2_->Enable(true));
1760 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_REC_DEVICE_OPEN_FAILED,
1764 void TestSrtpError(int pl_type) {
1765 // For Audio, only pl_type 0 is added to the bundle filter.
1766 // For Video, only pl_type 97 is added to the bundle filter.
1767 // So we need to pass in pl_type so that the packet can pass through
1768 // the bundle filter before it can be processed by the srtp filter.
1769 // The packet is not a valid srtp packet because it is too short.
1770 unsigned const char kBadPacket[] = {
1771 0x84, pl_type, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01
1773 CreateChannels(RTCP | SECURE, RTCP | SECURE);
1774 EXPECT_FALSE(channel1_->secure());
1775 EXPECT_FALSE(channel2_->secure());
1776 EXPECT_TRUE(SendInitiate());
1777 EXPECT_TRUE(SendAccept());
1778 EXPECT_TRUE(channel1_->secure());
1779 EXPECT_TRUE(channel2_->secure());
1780 channel2_->set_srtp_signal_silent_time(200);
1782 // Testing failures in sending packets.
1783 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1784 // The first failure will trigger an error.
1785 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1786 error_ = T::MediaChannel::ERROR_NONE;
1787 // The next 1 sec failures will not trigger an error.
1788 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1789 // Wait for a while to ensure no message comes in.
1790 talk_base::Thread::Current()->ProcessMessages(210);
1791 EXPECT_EQ(T::MediaChannel::ERROR_NONE, error_);
1792 // The error will be triggered again.
1793 EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket)));
1794 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_REC_SRTP_ERROR, error_, 500);
1796 // Testing failures in receiving packets.
1797 error_ = T::MediaChannel::ERROR_NONE;
1798 cricket::TransportChannel* transport_channel =
1799 channel2_->transport_channel();
1800 transport_channel->SignalReadPacket(
1801 transport_channel, reinterpret_cast<const char*>(kBadPacket),
1802 sizeof(kBadPacket), talk_base::PacketTime(), 0);
1803 EXPECT_EQ_WAIT(T::MediaChannel::ERROR_PLAY_SRTP_ERROR, error_, 500);
1806 void TestOnReadyToSend() {
1807 CreateChannels(RTCP, RTCP);
1808 TransportChannel* rtp = channel1_->transport_channel();
1809 TransportChannel* rtcp = channel1_->rtcp_transport_channel();
1810 EXPECT_FALSE(media_channel1_->ready_to_send());
1811 rtp->SignalReadyToSend(rtp);
1812 EXPECT_FALSE(media_channel1_->ready_to_send());
1813 rtcp->SignalReadyToSend(rtcp);
1814 // MediaChannel::OnReadyToSend only be called when both rtp and rtcp
1815 // channel are ready to send.
1816 EXPECT_TRUE(media_channel1_->ready_to_send());
1818 // rtp channel becomes not ready to send will be propagated to mediachannel
1819 channel1_->SetReadyToSend(rtp, false);
1820 EXPECT_FALSE(media_channel1_->ready_to_send());
1821 channel1_->SetReadyToSend(rtp, true);
1822 EXPECT_TRUE(media_channel1_->ready_to_send());
1824 // rtcp channel becomes not ready to send will be propagated to mediachannel
1825 channel1_->SetReadyToSend(rtcp, false);
1826 EXPECT_FALSE(media_channel1_->ready_to_send());
1827 channel1_->SetReadyToSend(rtcp, true);
1828 EXPECT_TRUE(media_channel1_->ready_to_send());
1831 void TestOnReadyToSendWithRtcpMux() {
1832 CreateChannels(RTCP, RTCP);
1833 typename T::Content content;
1834 CreateContent(0, kPcmuCodec, kH264Codec, &content);
1835 // Both sides agree on mux. Should no longer be a separate RTCP channel.
1836 content.set_rtcp_mux(true);
1837 EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL));
1838 EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL));
1839 EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL);
1840 TransportChannel* rtp = channel1_->transport_channel();
1841 EXPECT_FALSE(media_channel1_->ready_to_send());
1842 // In the case of rtcp mux, the SignalReadyToSend() from rtp channel
1843 // should trigger the MediaChannel's OnReadyToSend.
1844 rtp->SignalReadyToSend(rtp);
1845 EXPECT_TRUE(media_channel1_->ready_to_send());
1846 channel1_->SetReadyToSend(rtp, false);
1847 EXPECT_FALSE(media_channel1_->ready_to_send());
1851 cricket::FakeSession session1_;
1852 cricket::FakeSession session2_;
1853 cricket::FakeMediaEngine media_engine_;
1854 // The media channels are owned by the voice channel objects below.
1855 typename T::MediaChannel* media_channel1_;
1856 typename T::MediaChannel* media_channel2_;
1857 talk_base::scoped_ptr<typename T::Channel> channel1_;
1858 talk_base::scoped_ptr<typename T::Channel> channel2_;
1859 typename T::Content local_media_content1_;
1860 typename T::Content local_media_content2_;
1861 typename T::Content remote_media_content1_;
1862 typename T::Content remote_media_content2_;
1863 talk_base::scoped_ptr<talk_base::SSLIdentity> identity1_;
1864 talk_base::scoped_ptr<talk_base::SSLIdentity> identity2_;
1865 // The RTP and RTCP packets to send in the tests.
1866 std::string rtp_packet_;
1867 std::string rtcp_packet_;
1868 int media_info_callbacks1_;
1869 int media_info_callbacks2_;
1870 bool mute_callback_recved_;
1871 bool mute_callback_value_;
1874 typename T::MediaChannel::Error error_;
1879 void ChannelTest<VoiceTraits>::CreateContent(
1881 const cricket::AudioCodec& audio_codec,
1882 const cricket::VideoCodec& video_codec,
1883 cricket::AudioContentDescription* audio) {
1884 audio->AddCodec(audio_codec);
1885 audio->set_rtcp_mux((flags & RTCP_MUX) != 0);
1886 if (flags & SECURE) {
1887 audio->AddCrypto(cricket::CryptoParams(
1888 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
1889 "inline:" + talk_base::CreateRandomString(40), ""));
1894 void ChannelTest<VoiceTraits>::CopyContent(
1895 const cricket::AudioContentDescription& source,
1896 cricket::AudioContentDescription* audio) {
1901 bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1,
1902 const cricket::AudioCodec& c2) {
1903 return c1.name == c2.name && c1.clockrate == c2.clockrate &&
1904 c1.bitrate == c2.bitrate && c1.channels == c2.channels;
1908 void ChannelTest<VoiceTraits>::AddLegacyStreamInContent(
1909 uint32 ssrc, int flags, cricket::AudioContentDescription* audio) {
1910 audio->AddLegacyStream(ssrc);
1913 class VoiceChannelTest
1914 : public ChannelTest<VoiceTraits> {
1916 typedef ChannelTest<VoiceTraits>
1918 VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
1919 kRtcpReport, sizeof(kRtcpReport)) {
1922 void TestSetChannelOptions() {
1923 CreateChannels(0, 0);
1925 cricket::AudioOptions options1;
1926 options1.echo_cancellation.Set(false);
1927 cricket::AudioOptions options2;
1928 options2.echo_cancellation.Set(true);
1930 channel1_->SetChannelOptions(options1);
1931 channel2_->SetChannelOptions(options1);
1932 cricket::AudioOptions actual_options;
1933 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1934 EXPECT_EQ(options1, actual_options);
1935 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1936 EXPECT_EQ(options1, actual_options);
1938 channel1_->SetChannelOptions(options2);
1939 channel2_->SetChannelOptions(options2);
1940 ASSERT_TRUE(media_channel1_->GetOptions(&actual_options));
1941 EXPECT_EQ(options2, actual_options);
1942 ASSERT_TRUE(media_channel2_->GetOptions(&actual_options));
1943 EXPECT_EQ(options2, actual_options);
1947 // override to add NULL parameter
1949 cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
1950 talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
1951 cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
1953 cricket::VideoChannel* channel = new cricket::VideoChannel(
1954 thread, engine, ch, session, cricket::CN_VIDEO, rtcp, NULL);
1955 if (!channel->Init()) {
1962 // override to add 0 parameter
1964 bool ChannelTest<VideoTraits>::AddStream1(int id) {
1965 return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id));
1969 void ChannelTest<VideoTraits>::CreateContent(
1971 const cricket::AudioCodec& audio_codec,
1972 const cricket::VideoCodec& video_codec,
1973 cricket::VideoContentDescription* video) {
1974 video->AddCodec(video_codec);
1975 video->set_rtcp_mux((flags & RTCP_MUX) != 0);
1976 if (flags & SECURE) {
1977 video->AddCrypto(cricket::CryptoParams(
1978 1, cricket::CS_AES_CM_128_HMAC_SHA1_80,
1979 "inline:" + talk_base::CreateRandomString(40), ""));
1984 void ChannelTest<VideoTraits>::CopyContent(
1985 const cricket::VideoContentDescription& source,
1986 cricket::VideoContentDescription* video) {
1991 bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1,
1992 const cricket::VideoCodec& c2) {
1993 return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height &&
1994 c1.framerate == c2.framerate;
1998 void ChannelTest<VideoTraits>::AddLegacyStreamInContent(
1999 uint32 ssrc, int flags, cricket::VideoContentDescription* video) {
2000 video->AddLegacyStream(ssrc);
2003 class VideoChannelTest
2004 : public ChannelTest<VideoTraits> {
2006 typedef ChannelTest<VideoTraits>
2008 VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
2009 kRtcpReport, sizeof(kRtcpReport)) {
2012 void TestSetChannelOptions() {
2013 CreateChannels(0, 0);
2015 cricket::VideoOptions o1, o2;
2016 o1.video_noise_reduction.Set(true);
2018 channel1_->SetChannelOptions(o1);
2019 channel2_->SetChannelOptions(o1);
2020 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2022 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2025 o1.video_leaky_bucket.Set(true);
2026 channel1_->SetChannelOptions(o1);
2027 channel2_->SetChannelOptions(o1);
2028 EXPECT_TRUE(media_channel1_->GetOptions(&o2));
2030 EXPECT_TRUE(media_channel2_->GetOptions(&o2));
2038 TEST_F(VoiceChannelTest, TestInit) {
2040 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2041 EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
2044 TEST_F(VoiceChannelTest, TestSetContents) {
2045 Base::TestSetContents();
2048 TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
2049 Base::TestSetContentsNullOffer();
2052 TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
2053 Base::TestSetContentsRtcpMux();
2056 TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2057 Base::TestSetContentsRtcpMux();
2060 TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
2061 Base::TestSetRemoteContentUpdate();
2064 TEST_F(VoiceChannelTest, TestStreams) {
2065 Base::TestStreams();
2068 TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
2069 Base::TestUpdateStreamsInLocalContent();
2072 TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
2073 Base::TestUpdateStreamsInRemoteContent();
2076 TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
2077 Base::TestChangeStreamParamsInContent();
2080 TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
2081 Base::TestPlayoutAndSendingStates();
2084 TEST_F(VoiceChannelTest, TestMuteStream) {
2085 Base::TestMuteStream();
2088 TEST_F(VoiceChannelTest, TestMediaContentDirection) {
2089 Base::TestMediaContentDirection();
2092 TEST_F(VoiceChannelTest, TestCallSetup) {
2093 Base::TestCallSetup();
2096 TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
2097 Base::TestCallTeardownRtcpMux();
2100 TEST_F(VoiceChannelTest, SendRtpToRtp) {
2101 Base::SendRtpToRtp();
2104 TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
2105 Base::SendNoRtcpToNoRtcp();
2108 TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
2109 Base::SendNoRtcpToRtcp();
2112 TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
2113 Base::SendRtcpToNoRtcp();
2116 TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
2117 Base::SendRtcpToRtcp();
2120 TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
2121 Base::SendRtcpMuxToRtcp();
2124 TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
2125 Base::SendRtcpMuxToRtcpMux();
2128 TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
2129 Base::SendEarlyRtcpMuxToRtcp();
2132 TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2133 Base::SendEarlyRtcpMuxToRtcpMux();
2136 TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
2137 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2140 TEST_F(VoiceChannelTest, SendSrtpToRtp) {
2141 Base::SendSrtpToSrtp();
2144 TEST_F(VoiceChannelTest, SendSrtcpMux) {
2145 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2148 TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
2149 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2150 Base::SendSrtpToSrtp(DTLS, 0);
2153 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
2154 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2155 Base::SendSrtpToSrtp(DTLS, DTLS);
2158 TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2159 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2160 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2163 TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2164 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2167 TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
2168 Base::SendRtpToRtpOnThread();
2171 TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
2172 Base::SendSrtpToSrtpOnThread();
2175 TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
2176 Base::SendWithWritabilityLoss();
2179 TEST_F(VoiceChannelTest, TestMediaMonitor) {
2180 Base::TestMediaMonitor();
2183 // Test that MuteStream properly forwards to the media channel and does
2185 TEST_F(VoiceChannelTest, TestVoiceSpecificMuteStream) {
2186 CreateChannels(0, 0);
2187 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2188 EXPECT_FALSE(mute_callback_recved_);
2189 EXPECT_TRUE(channel1_->MuteStream(0, true));
2190 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2191 EXPECT_FALSE(mute_callback_recved_);
2192 EXPECT_TRUE(channel1_->MuteStream(0, false));
2193 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2194 EXPECT_FALSE(mute_callback_recved_);
2197 // Test that keyboard automute works correctly and signals upwards.
2198 TEST_F(VoiceChannelTest, DISABLED_TestKeyboardMute) {
2199 CreateChannels(0, 0);
2200 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2201 EXPECT_EQ(cricket::VoiceMediaChannel::ERROR_NONE, error_);
2203 cricket::VoiceMediaChannel::Error e =
2204 cricket::VoiceMediaChannel::ERROR_REC_TYPING_NOISE_DETECTED;
2206 // Typing doesn't mute automatically unless typing monitor has been installed
2207 media_channel1_->TriggerError(0, e);
2208 talk_base::Thread::Current()->ProcessMessages(0);
2209 EXPECT_EQ(e, error_);
2210 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2211 EXPECT_FALSE(mute_callback_recved_);
2213 cricket::TypingMonitorOptions o = {0};
2214 o.mute_period = 1500;
2215 channel1_->StartTypingMonitor(o);
2216 media_channel1_->TriggerError(0, e);
2217 talk_base::Thread::Current()->ProcessMessages(0);
2218 EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
2219 EXPECT_TRUE(mute_callback_recved_);
2222 // Test that PressDTMF properly forwards to the media channel.
2223 TEST_F(VoiceChannelTest, TestDtmf) {
2224 CreateChannels(0, 0);
2225 EXPECT_TRUE(SendInitiate());
2226 EXPECT_TRUE(SendAccept());
2227 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2229 EXPECT_TRUE(channel1_->PressDTMF(1, true));
2230 EXPECT_TRUE(channel1_->PressDTMF(8, false));
2232 ASSERT_EQ(2U, media_channel1_->dtmf_info_queue().size());
2233 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2234 0, 1, 160, cricket::DF_PLAY | cricket::DF_SEND));
2235 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2236 0, 8, 160, cricket::DF_SEND));
2239 // Test that InsertDtmf properly forwards to the media channel.
2240 TEST_F(VoiceChannelTest, TestInsertDtmf) {
2241 CreateChannels(0, 0);
2242 EXPECT_TRUE(SendInitiate());
2243 EXPECT_TRUE(SendAccept());
2244 EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
2246 EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100, cricket::DF_SEND));
2247 EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110, cricket::DF_PLAY));
2248 EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120,
2249 cricket::DF_PLAY | cricket::DF_SEND));
2251 ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
2252 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0],
2253 1, 3, 100, cricket::DF_SEND));
2254 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1],
2255 2, 5, 110, cricket::DF_PLAY));
2256 EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2],
2257 3, 7, 120, cricket::DF_PLAY | cricket::DF_SEND));
2260 TEST_F(VoiceChannelTest, TestMediaSinks) {
2261 Base::TestMediaSinks();
2264 TEST_F(VoiceChannelTest, TestSetContentFailure) {
2265 Base::TestSetContentFailure();
2268 TEST_F(VoiceChannelTest, TestSendTwoOffers) {
2269 Base::TestSendTwoOffers();
2272 TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
2273 Base::TestReceiveTwoOffers();
2276 TEST_F(VoiceChannelTest, TestSendPrAnswer) {
2277 Base::TestSendPrAnswer();
2280 TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
2281 Base::TestReceivePrAnswer();
2284 TEST_F(VoiceChannelTest, TestFlushRtcp) {
2285 Base::TestFlushRtcp();
2288 TEST_F(VoiceChannelTest, TestChangeStateError) {
2289 Base::TestChangeStateError();
2292 TEST_F(VoiceChannelTest, TestSrtpError) {
2293 Base::TestSrtpError(kAudioPts[0]);
2296 TEST_F(VoiceChannelTest, TestOnReadyToSend) {
2297 Base::TestOnReadyToSend();
2300 TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
2301 Base::TestOnReadyToSendWithRtcpMux();
2304 // Test that we can play a ringback tone properly.
2305 TEST_F(VoiceChannelTest, TestRingbackTone) {
2306 CreateChannels(RTCP, RTCP);
2307 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2308 EXPECT_TRUE(channel1_->SetRingbackTone("RIFF", 4));
2309 EXPECT_TRUE(SendInitiate());
2310 EXPECT_TRUE(SendAccept());
2311 // Play ringback tone, no loop.
2312 EXPECT_TRUE(channel1_->PlayRingbackTone(0, true, false));
2313 EXPECT_EQ(0U, media_channel1_->ringback_tone_ssrc());
2314 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2315 EXPECT_FALSE(media_channel1_->ringback_tone_loop());
2316 // Stop the ringback tone.
2317 EXPECT_TRUE(channel1_->PlayRingbackTone(0, false, false));
2318 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2320 EXPECT_TRUE(AddStream1(1));
2321 // Play ringback tone, looping, on the new stream.
2322 EXPECT_TRUE(channel1_->PlayRingbackTone(1, true, true));
2323 EXPECT_EQ(1U, media_channel1_->ringback_tone_ssrc());
2324 EXPECT_TRUE(media_channel1_->ringback_tone_play());
2325 EXPECT_TRUE(media_channel1_->ringback_tone_loop());
2326 // Stop the ringback tone.
2327 EXPECT_TRUE(channel1_->PlayRingbackTone(1, false, false));
2328 EXPECT_FALSE(media_channel1_->ringback_tone_play());
2331 // Test that we can scale the output volume properly for 1:1 calls.
2332 TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
2333 CreateChannels(RTCP, RTCP);
2334 EXPECT_TRUE(SendInitiate());
2335 EXPECT_TRUE(SendAccept());
2338 // Default is (1.0, 1.0).
2339 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2340 EXPECT_DOUBLE_EQ(1.0, left);
2341 EXPECT_DOUBLE_EQ(1.0, right);
2343 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2345 // Set scale to (1.5, 0.5).
2346 EXPECT_TRUE(channel1_->SetOutputScaling(0, 1.5, 0.5));
2347 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2348 EXPECT_DOUBLE_EQ(1.5, left);
2349 EXPECT_DOUBLE_EQ(0.5, right);
2351 // Set scale to (0, 0).
2352 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2353 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2354 EXPECT_DOUBLE_EQ(0.0, left);
2355 EXPECT_DOUBLE_EQ(0.0, right);
2358 // Test that we can scale the output volume properly for multiway calls.
2359 TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
2360 CreateChannels(RTCP, RTCP);
2361 EXPECT_TRUE(SendInitiate());
2362 EXPECT_TRUE(SendAccept());
2363 EXPECT_TRUE(AddStream1(1));
2364 EXPECT_TRUE(AddStream1(2));
2367 // Default is (1.0, 1.0).
2368 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2369 EXPECT_DOUBLE_EQ(1.0, left);
2370 EXPECT_DOUBLE_EQ(1.0, right);
2371 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2372 EXPECT_DOUBLE_EQ(1.0, left);
2373 EXPECT_DOUBLE_EQ(1.0, right);
2374 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2375 EXPECT_DOUBLE_EQ(1.0, left);
2376 EXPECT_DOUBLE_EQ(1.0, right);
2378 EXPECT_FALSE(media_channel1_->GetOutputScaling(3, &left, &right));
2380 // Set scale to (1.5, 0.5) for ssrc = 1.
2381 EXPECT_TRUE(channel1_->SetOutputScaling(1, 1.5, 0.5));
2382 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2383 EXPECT_DOUBLE_EQ(1.5, left);
2384 EXPECT_DOUBLE_EQ(0.5, right);
2385 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2386 EXPECT_DOUBLE_EQ(1.0, left);
2387 EXPECT_DOUBLE_EQ(1.0, right);
2388 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2389 EXPECT_DOUBLE_EQ(1.0, left);
2390 EXPECT_DOUBLE_EQ(1.0, right);
2392 // Set scale to (0, 0) for all ssrcs.
2393 EXPECT_TRUE(channel1_->SetOutputScaling(0, 0.0, 0.0));
2394 EXPECT_TRUE(media_channel1_->GetOutputScaling(0, &left, &right));
2395 EXPECT_DOUBLE_EQ(0.0, left);
2396 EXPECT_DOUBLE_EQ(0.0, right);
2397 EXPECT_TRUE(media_channel1_->GetOutputScaling(1, &left, &right));
2398 EXPECT_DOUBLE_EQ(0.0, left);
2399 EXPECT_DOUBLE_EQ(0.0, right);
2400 EXPECT_TRUE(media_channel1_->GetOutputScaling(2, &left, &right));
2401 EXPECT_DOUBLE_EQ(0.0, left);
2402 EXPECT_DOUBLE_EQ(0.0, right);
2405 TEST_F(VoiceChannelTest, SendBundleToBundle) {
2406 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, false);
2409 TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
2410 Base::SendBundleToBundle(kAudioPts, ARRAY_SIZE(kAudioPts), false, true);
2413 TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
2414 Base::SendBundleToBundle(
2415 kAudioPts, ARRAY_SIZE(kAudioPts), true, false);
2418 TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2419 Base::SendBundleToBundle(
2420 kAudioPts, ARRAY_SIZE(kAudioPts), true, true);
2423 TEST_F(VoiceChannelTest, TestSetChannelOptions) {
2424 TestSetChannelOptions();
2428 TEST_F(VideoChannelTest, TestInit) {
2432 TEST_F(VideoChannelTest, TestSetContents) {
2433 Base::TestSetContents();
2436 TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
2437 Base::TestSetContentsNullOffer();
2440 TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
2441 Base::TestSetContentsRtcpMux();
2444 TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
2445 Base::TestSetContentsRtcpMux();
2448 TEST_F(VideoChannelTest, TestSetContentsVideoOptions) {
2449 Base::TestSetContentsVideoOptions();
2452 TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
2453 Base::TestSetRemoteContentUpdate();
2456 TEST_F(VideoChannelTest, TestStreams) {
2457 Base::TestStreams();
2460 TEST_F(VideoChannelTest, TestScreencastEvents) {
2461 const int kTimeoutMs = 500;
2463 FakeScreenCaptureFactory* screencapture_factory =
2464 new FakeScreenCaptureFactory();
2465 channel1_->SetScreenCaptureFactory(screencapture_factory);
2466 cricket::ScreencastEventCatcher catcher;
2467 channel1_->SignalScreencastWindowEvent.connect(
2469 &cricket::ScreencastEventCatcher::OnEvent);
2470 EXPECT_TRUE(channel1_->AddScreencast(0, ScreencastId(WindowId(0))) != NULL);
2471 ASSERT_TRUE(screencapture_factory->window_capturer() != NULL);
2472 EXPECT_EQ_WAIT(cricket::CS_STOPPED, screencapture_factory->capture_state(),
2474 screencapture_factory->window_capturer()->SignalStateChange(
2475 screencapture_factory->window_capturer(), cricket::CS_PAUSED);
2476 EXPECT_EQ_WAIT(talk_base::WE_MINIMIZE, catcher.event(), kTimeoutMs);
2477 screencapture_factory->window_capturer()->SignalStateChange(
2478 screencapture_factory->window_capturer(), cricket::CS_RUNNING);
2479 EXPECT_EQ_WAIT(talk_base::WE_RESTORE, catcher.event(), kTimeoutMs);
2480 screencapture_factory->window_capturer()->SignalStateChange(
2481 screencapture_factory->window_capturer(), cricket::CS_STOPPED);
2482 EXPECT_EQ_WAIT(talk_base::WE_CLOSE, catcher.event(), kTimeoutMs);
2483 EXPECT_TRUE(channel1_->RemoveScreencast(0));
2484 ASSERT_TRUE(screencapture_factory->window_capturer() == NULL);
2487 TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
2488 Base::TestUpdateStreamsInLocalContent();
2491 TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
2492 Base::TestUpdateStreamsInRemoteContent();
2495 TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
2496 Base::TestChangeStreamParamsInContent();
2499 TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
2500 Base::TestPlayoutAndSendingStates();
2503 TEST_F(VideoChannelTest, TestMuteStream) {
2504 Base::TestMuteStream();
2507 TEST_F(VideoChannelTest, TestMediaContentDirection) {
2508 Base::TestMediaContentDirection();
2511 TEST_F(VideoChannelTest, TestCallSetup) {
2512 Base::TestCallSetup();
2515 TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
2516 Base::TestCallTeardownRtcpMux();
2519 TEST_F(VideoChannelTest, SendRtpToRtp) {
2520 Base::SendRtpToRtp();
2523 TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
2524 Base::SendNoRtcpToNoRtcp();
2527 TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
2528 Base::SendNoRtcpToRtcp();
2531 TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
2532 Base::SendRtcpToNoRtcp();
2535 TEST_F(VideoChannelTest, SendRtcpToRtcp) {
2536 Base::SendRtcpToRtcp();
2539 TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
2540 Base::SendRtcpMuxToRtcp();
2543 TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
2544 Base::SendRtcpMuxToRtcpMux();
2547 TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
2548 Base::SendEarlyRtcpMuxToRtcp();
2551 TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2552 Base::SendEarlyRtcpMuxToRtcpMux();
2555 TEST_F(VideoChannelTest, SendSrtpToSrtp) {
2556 Base::SendSrtpToSrtp();
2559 TEST_F(VideoChannelTest, SendSrtpToRtp) {
2560 Base::SendSrtpToSrtp();
2563 TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
2564 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2565 Base::SendSrtpToSrtp(DTLS, 0);
2568 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
2569 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2570 Base::SendSrtpToSrtp(DTLS, DTLS);
2573 TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
2574 MAYBE_SKIP_TEST(HaveDtlsSrtp);
2575 Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
2578 TEST_F(VideoChannelTest, SendSrtcpMux) {
2579 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2582 TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
2583 Base::SendEarlyMediaUsingRtcpMuxSrtp();
2586 TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
2587 Base::SendRtpToRtpOnThread();
2590 TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
2591 Base::SendSrtpToSrtpOnThread();
2594 TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
2595 Base::SendWithWritabilityLoss();
2598 TEST_F(VideoChannelTest, TestMediaMonitor) {
2599 Base::TestMediaMonitor();
2602 TEST_F(VideoChannelTest, TestMediaSinks) {
2603 Base::TestMediaSinks();
2606 TEST_F(VideoChannelTest, TestSetContentFailure) {
2607 Base::TestSetContentFailure();
2610 TEST_F(VideoChannelTest, TestSendTwoOffers) {
2611 Base::TestSendTwoOffers();
2614 TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
2615 Base::TestReceiveTwoOffers();
2618 TEST_F(VideoChannelTest, TestSendPrAnswer) {
2619 Base::TestSendPrAnswer();
2622 TEST_F(VideoChannelTest, TestReceivePrAnswer) {
2623 Base::TestReceivePrAnswer();
2626 TEST_F(VideoChannelTest, TestFlushRtcp) {
2627 Base::TestFlushRtcp();
2630 TEST_F(VideoChannelTest, SendBundleToBundle) {
2631 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, false);
2634 TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
2635 Base::SendBundleToBundle(kVideoPts, ARRAY_SIZE(kVideoPts), false, true);
2638 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
2639 Base::SendBundleToBundle(
2640 kVideoPts, ARRAY_SIZE(kVideoPts), true, false);
2643 TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
2644 Base::SendBundleToBundle(
2645 kVideoPts, ARRAY_SIZE(kVideoPts), true, true);
2648 // TODO(gangji): Add VideoChannelTest.TestChangeStateError.
2650 TEST_F(VideoChannelTest, TestSrtpError) {
2651 Base::TestSrtpError(kVideoPts[0]);
2654 TEST_F(VideoChannelTest, TestOnReadyToSend) {
2655 Base::TestOnReadyToSend();
2658 TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
2659 Base::TestOnReadyToSendWithRtcpMux();
2662 TEST_F(VideoChannelTest, TestApplyViewRequest) {
2663 CreateChannels(0, 0);
2664 cricket::StreamParams stream2;
2665 stream2.id = "stream2";
2666 stream2.ssrcs.push_back(2222);
2667 local_media_content1_.AddStream(stream2);
2669 EXPECT_TRUE(SendInitiate());
2670 EXPECT_TRUE(SendAccept());
2672 cricket::VideoFormat send_format;
2673 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2674 EXPECT_EQ(640, send_format.width);
2675 EXPECT_EQ(400, send_format.height);
2676 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2678 cricket::ViewRequest request;
2679 // stream1: 320x200x15; stream2: 0x0x0
2680 request.static_video_views.push_back(cricket::StaticVideoView(
2681 cricket::StreamSelector(kSsrc1), 320, 200, 15));
2682 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2683 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2684 EXPECT_EQ(320, send_format.width);
2685 EXPECT_EQ(200, send_format.height);
2686 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(15), send_format.interval);
2687 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2688 EXPECT_EQ(0, send_format.width);
2689 EXPECT_EQ(0, send_format.height);
2691 // stream1: 160x100x8; stream2: 0x0x0
2692 request.static_video_views.clear();
2693 request.static_video_views.push_back(cricket::StaticVideoView(
2694 cricket::StreamSelector(kSsrc1), 160, 100, 8));
2695 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2696 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2697 EXPECT_EQ(160, send_format.width);
2698 EXPECT_EQ(100, send_format.height);
2699 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(8), send_format.interval);
2701 // stream1: 0x0x0; stream2: 640x400x30
2702 request.static_video_views.clear();
2703 request.static_video_views.push_back(cricket::StaticVideoView(
2704 cricket::StreamSelector("", stream2.id), 640, 400, 30));
2705 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2706 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2707 EXPECT_EQ(0, send_format.width);
2708 EXPECT_EQ(0, send_format.height);
2709 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(2222, &send_format));
2710 EXPECT_EQ(640, send_format.width);
2711 EXPECT_EQ(400, send_format.height);
2712 EXPECT_EQ(cricket::VideoFormat::FpsToInterval(30), send_format.interval);
2714 // stream1: 0x0x0; stream2: 0x0x0
2715 request.static_video_views.clear();
2716 EXPECT_TRUE(channel1_->ApplyViewRequest(request));
2717 EXPECT_TRUE(media_channel1_->GetSendStreamFormat(kSsrc1, &send_format));
2718 EXPECT_EQ(0, send_format.width);
2719 EXPECT_EQ(0, send_format.height);
2722 TEST_F(VideoChannelTest, TestSetChannelOptions) {
2723 TestSetChannelOptions();
2729 class DataChannelTest
2730 : public ChannelTest<DataTraits> {
2732 typedef ChannelTest<DataTraits>
2734 DataChannelTest() : Base(kDataPacket, sizeof(kDataPacket),
2735 kRtcpReport, sizeof(kRtcpReport)) {
2739 // Override to avoid engine channel parameter.
2741 cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
2742 talk_base::Thread* thread, cricket::MediaEngineInterface* engine,
2743 cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
2745 cricket::DataChannel* channel = new cricket::DataChannel(
2746 thread, ch, session, cricket::CN_DATA, rtcp);
2747 if (!channel->Init()) {
2755 void ChannelTest<DataTraits>::CreateContent(
2757 const cricket::AudioCodec& audio_codec,
2758 const cricket::VideoCodec& video_codec,
2759 cricket::DataContentDescription* data) {
2760 data->AddCodec(kGoogleDataCodec);
2761 data->set_rtcp_mux((flags & RTCP_MUX) != 0);
2762 if (flags & SECURE) {
2763 data->AddCrypto(cricket::CryptoParams(
2764 1, cricket::CS_AES_CM_128_HMAC_SHA1_32,
2765 "inline:" + talk_base::CreateRandomString(40), ""));
2770 void ChannelTest<DataTraits>::CopyContent(
2771 const cricket::DataContentDescription& source,
2772 cricket::DataContentDescription* data) {
2777 bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
2778 const cricket::DataCodec& c2) {
2779 return c1.name == c2.name;
2783 void ChannelTest<DataTraits>::AddLegacyStreamInContent(
2784 uint32 ssrc, int flags, cricket::DataContentDescription* data) {
2785 data->AddLegacyStream(ssrc);
2788 TEST_F(DataChannelTest, TestInit) {
2790 EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
2793 TEST_F(DataChannelTest, TestSetContents) {
2794 Base::TestSetContents();
2797 TEST_F(DataChannelTest, TestSetContentsNullOffer) {
2798 Base::TestSetContentsNullOffer();
2801 TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
2802 Base::TestSetContentsRtcpMux();
2805 TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
2806 Base::TestSetRemoteContentUpdate();
2809 TEST_F(DataChannelTest, TestStreams) {
2810 Base::TestStreams();
2813 TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
2814 Base::TestUpdateStreamsInLocalContent();
2817 TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
2818 Base::TestUpdateStreamsInRemoteContent();
2821 TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
2822 Base::TestChangeStreamParamsInContent();
2825 TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
2826 Base::TestPlayoutAndSendingStates();
2829 TEST_F(DataChannelTest, TestMediaContentDirection) {
2830 Base::TestMediaContentDirection();
2833 TEST_F(DataChannelTest, TestCallSetup) {
2834 Base::TestCallSetup();
2837 TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
2838 Base::TestCallTeardownRtcpMux();
2841 TEST_F(DataChannelTest, TestOnReadyToSend) {
2842 Base::TestOnReadyToSend();
2845 TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
2846 Base::TestOnReadyToSendWithRtcpMux();
2849 TEST_F(DataChannelTest, SendRtpToRtp) {
2850 Base::SendRtpToRtp();
2853 TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
2854 Base::SendNoRtcpToNoRtcp();
2857 TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
2858 Base::SendNoRtcpToRtcp();
2861 TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
2862 Base::SendRtcpToNoRtcp();
2865 TEST_F(DataChannelTest, SendRtcpToRtcp) {
2866 Base::SendRtcpToRtcp();
2869 TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
2870 Base::SendRtcpMuxToRtcp();
2873 TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
2874 Base::SendRtcpMuxToRtcpMux();
2877 TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
2878 Base::SendEarlyRtcpMuxToRtcp();
2881 TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
2882 Base::SendEarlyRtcpMuxToRtcpMux();
2885 TEST_F(DataChannelTest, SendSrtpToSrtp) {
2886 Base::SendSrtpToSrtp();
2889 TEST_F(DataChannelTest, SendSrtpToRtp) {
2890 Base::SendSrtpToSrtp();
2893 TEST_F(DataChannelTest, SendSrtcpMux) {
2894 Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
2897 TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
2898 Base::SendRtpToRtpOnThread();
2901 TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
2902 Base::SendSrtpToSrtpOnThread();
2905 TEST_F(DataChannelTest, SendWithWritabilityLoss) {
2906 Base::SendWithWritabilityLoss();
2909 TEST_F(DataChannelTest, TestMediaMonitor) {
2910 Base::TestMediaMonitor();
2913 TEST_F(DataChannelTest, TestSendData) {
2914 CreateChannels(0, 0);
2915 EXPECT_TRUE(SendInitiate());
2916 EXPECT_TRUE(SendAccept());
2918 cricket::SendDataParams params;
2920 unsigned char data[] = {
2923 talk_base::Buffer payload(data, 3);
2924 cricket::SendDataResult result;
2925 ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
2926 EXPECT_EQ(params.ssrc,
2927 media_channel1_->last_sent_data_params().ssrc);
2928 EXPECT_EQ("foo", media_channel1_->last_sent_data());
2931 // TODO(pthatcher): TestSetReceiver?