1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/system_wrappers/include/atomic32.h"
12 #include "webrtc/system_wrappers/include/critical_section_wrapper.h"
13 #include "webrtc/system_wrappers/include/event_wrapper.h"
14 #include "webrtc/test/testsupport/fileutils.h"
15 #include "webrtc/voice_engine/test/auto_test/fixtures/after_streaming_fixture.h"
16 #include "webrtc/voice_engine/test/auto_test/voe_standard_test.h"
17
18 class TestRtpObserver : public webrtc::VoERTPObserver {
19 public:
TestRtpObserver()20 TestRtpObserver()
21 : crit_(voetest::CriticalSectionWrapper::CreateCriticalSection()),
22 changed_ssrc_event_(voetest::EventWrapper::Create()) {}
~TestRtpObserver()23 virtual ~TestRtpObserver() {}
OnIncomingCSRCChanged(int channel,unsigned int CSRC,bool added)24 virtual void OnIncomingCSRCChanged(int channel,
25 unsigned int CSRC,
26 bool added) {}
27 virtual void OnIncomingSSRCChanged(int channel,
28 unsigned int SSRC);
WaitForChangedSsrc()29 void WaitForChangedSsrc() {
30 // 10 seconds should be enough.
31 EXPECT_EQ(voetest::kEventSignaled, changed_ssrc_event_->Wait(10*1000));
32 }
SetIncomingSsrc(unsigned int ssrc)33 void SetIncomingSsrc(unsigned int ssrc) {
34 voetest::CriticalSectionScoped lock(crit_.get());
35 incoming_ssrc_ = ssrc;
36 }
37 public:
38 rtc::scoped_ptr<voetest::CriticalSectionWrapper> crit_;
39 unsigned int incoming_ssrc_;
40 rtc::scoped_ptr<voetest::EventWrapper> changed_ssrc_event_;
41 };
42
OnIncomingSSRCChanged(int channel,unsigned int SSRC)43 void TestRtpObserver::OnIncomingSSRCChanged(int channel,
44 unsigned int SSRC) {
45 char msg[128];
46 sprintf(msg, "\n=> OnIncomingSSRCChanged(channel=%d, SSRC=%u)\n", channel,
47 SSRC);
48 TEST_LOG("%s", msg);
49
50 {
51 voetest::CriticalSectionScoped lock(crit_.get());
52 if (incoming_ssrc_ == SSRC)
53 changed_ssrc_event_->Set();
54 }
55 }
56
57 static const char* const RTCP_CNAME = "Whatever";
58
59 class RtpRtcpTest : public AfterStreamingFixture {
60 protected:
SetUp()61 void SetUp() {
62 // We need a second channel for this test, so set it up.
63 second_channel_ = voe_base_->CreateChannel();
64 EXPECT_GE(second_channel_, 0);
65
66 transport_ = new LoopBackTransport(voe_network_, second_channel_);
67 EXPECT_EQ(0, voe_network_->RegisterExternalTransport(second_channel_,
68 *transport_));
69
70 EXPECT_EQ(0, voe_base_->StartReceive(second_channel_));
71 EXPECT_EQ(0, voe_base_->StartPlayout(second_channel_));
72 EXPECT_EQ(0, voe_rtp_rtcp_->SetLocalSSRC(second_channel_, 5678));
73 EXPECT_EQ(0, voe_base_->StartSend(second_channel_));
74
75 // We'll set up the RTCP CNAME and SSRC to something arbitrary here.
76 voe_rtp_rtcp_->SetRTCP_CNAME(channel_, RTCP_CNAME);
77 }
78
TearDown()79 void TearDown() {
80 EXPECT_EQ(0, voe_network_->DeRegisterExternalTransport(second_channel_));
81 voe_base_->DeleteChannel(second_channel_);
82 delete transport_;
83 }
84
85 int second_channel_;
86 LoopBackTransport* transport_;
87 };
88
TEST_F(RtpRtcpTest,RemoteRtcpCnameHasPropagatedToRemoteSide)89 TEST_F(RtpRtcpTest, RemoteRtcpCnameHasPropagatedToRemoteSide) {
90 if (!FLAGS_include_timing_dependent_tests) {
91 TEST_LOG("Skipping test - running in slow execution environment...\n");
92 return;
93 }
94
95 // We need to sleep a bit here for the name to propagate. For instance,
96 // 200 milliseconds is not enough, so we'll go with one second here.
97 Sleep(1000);
98
99 char char_buffer[256];
100 voe_rtp_rtcp_->GetRemoteRTCP_CNAME(channel_, char_buffer);
101 EXPECT_STREQ(RTCP_CNAME, char_buffer);
102 }
103
TEST_F(RtpRtcpTest,SSRCPropagatesCorrectly)104 TEST_F(RtpRtcpTest, SSRCPropagatesCorrectly) {
105 unsigned int local_ssrc = 1234;
106 EXPECT_EQ(0, voe_base_->StopSend(channel_));
107 EXPECT_EQ(0, voe_rtp_rtcp_->SetLocalSSRC(channel_, local_ssrc));
108 EXPECT_EQ(0, voe_base_->StartSend(channel_));
109
110 Sleep(1000);
111
112 unsigned int ssrc;
113 EXPECT_EQ(0, voe_rtp_rtcp_->GetLocalSSRC(channel_, ssrc));
114 EXPECT_EQ(local_ssrc, ssrc);
115
116 EXPECT_EQ(0, voe_rtp_rtcp_->GetRemoteSSRC(channel_, ssrc));
117 EXPECT_EQ(local_ssrc, ssrc);
118 }
119