blob: 3f96c3350ff13a6ccc7be72b9f7d4c9987ccdb7c [file] [log] [blame]
solenberg18f54272017-09-15 09:56:08 -07001/*
2 * Copyright (c) 2017 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 "test/call_test.h"
12#include "test/gtest.h"
13#include "test/rtcp_packet_parser.h"
14
15namespace webrtc {
16namespace test {
17namespace {
18
19class AudioSendTest : public SendTest {
20 public:
21 AudioSendTest() : SendTest(CallTest::kDefaultTimeoutMs) {}
22
23 size_t GetNumVideoStreams() const override {
24 return 0;
25 }
26 size_t GetNumAudioStreams() const override {
27 return 1;
28 }
29 size_t GetNumFlexfecStreams() const override {
30 return 0;
31 }
32};
33} // namespace
34
35using AudioSendStreamCallTest = CallTest;
36
37TEST_F(AudioSendStreamCallTest, SupportsCName) {
38 static std::string kCName = "PjqatC14dGfbVwGPUOA9IH7RlsFDbWl4AhXEiDsBizo=";
39 class CNameObserver : public AudioSendTest {
40 public:
41 CNameObserver() = default;
42
43 private:
44 Action OnSendRtcp(const uint8_t* packet, size_t length) override {
45 RtcpPacketParser parser;
46 EXPECT_TRUE(parser.Parse(packet, length));
47 if (parser.sdes()->num_packets() > 0) {
48 EXPECT_EQ(1u, parser.sdes()->chunks().size());
49 EXPECT_EQ(kCName, parser.sdes()->chunks()[0].cname);
50
51 observation_complete_.Set();
52 }
53
54 return SEND_PACKET;
55 }
56
57 void ModifyAudioConfigs(
58 AudioSendStream::Config* send_config,
59 std::vector<AudioReceiveStream::Config>* receive_configs) override {
60 send_config->rtp.c_name = kCName;
61 }
62
63 void PerformTest() override {
64 EXPECT_TRUE(Wait()) << "Timed out while waiting for RTCP with CNAME.";
65 }
66 } test;
67
68 RunBaseTest(&test);
69}
70
71TEST_F(AudioSendStreamCallTest, NoExtensionsByDefault) {
72 class NoExtensionsObserver : public AudioSendTest {
73 public:
74 NoExtensionsObserver() = default;
75
76 private:
77 Action OnSendRtp(const uint8_t* packet, size_t length) override {
78 RTPHeader header;
79 EXPECT_TRUE(parser_->Parse(packet, length, &header));
80
81 EXPECT_FALSE(header.extension.hasTransmissionTimeOffset);
82 EXPECT_FALSE(header.extension.hasAbsoluteSendTime);
83 EXPECT_FALSE(header.extension.hasTransportSequenceNumber);
84 EXPECT_FALSE(header.extension.hasAudioLevel);
85 EXPECT_FALSE(header.extension.hasVideoRotation);
86 EXPECT_FALSE(header.extension.hasVideoContentType);
87 observation_complete_.Set();
88
89 return SEND_PACKET;
90 }
91
92 void ModifyAudioConfigs(
93 AudioSendStream::Config* send_config,
94 std::vector<AudioReceiveStream::Config>* receive_configs) override {
95 send_config->rtp.extensions.clear();
96 }
97
98 void PerformTest() override {
99 EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet.";
100 }
101 } test;
102
103 RunBaseTest(&test);
104}
105
106TEST_F(AudioSendStreamCallTest, SupportsAudioLevel) {
107 class AudioLevelObserver : public AudioSendTest {
108 public:
109 AudioLevelObserver() : AudioSendTest() {
110 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
111 kRtpExtensionAudioLevel, test::kAudioLevelExtensionId));
112 }
113
114 Action OnSendRtp(const uint8_t* packet, size_t length) override {
115 RTPHeader header;
116 EXPECT_TRUE(parser_->Parse(packet, length, &header));
117
118 EXPECT_TRUE(header.extension.hasAudioLevel);
119 if (header.extension.audioLevel != 0) {
120 // Wait for at least one packet with a non-zero level.
121 observation_complete_.Set();
122 } else {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100123 RTC_LOG(LS_WARNING) << "Got a packet with zero audioLevel - waiting"
124 " for another packet...";
solenberg18f54272017-09-15 09:56:08 -0700125 }
126
127 return SEND_PACKET;
128 }
129
130 void ModifyAudioConfigs(
131 AudioSendStream::Config* send_config,
132 std::vector<AudioReceiveStream::Config>* receive_configs) override {
133 send_config->rtp.extensions.clear();
134 send_config->rtp.extensions.push_back(RtpExtension(
135 RtpExtension::kAudioLevelUri, test::kAudioLevelExtensionId));
136 }
137
138 void PerformTest() override {
139 EXPECT_TRUE(Wait()) << "Timed out while waiting for single RTP packet.";
140 }
141 } test;
142
143 RunBaseTest(&test);
144}
145
146TEST_F(AudioSendStreamCallTest, SupportsTransportWideSequenceNumbers) {
147 static const uint8_t kExtensionId = test::kTransportSequenceNumberExtensionId;
148 class TransportWideSequenceNumberObserver : public AudioSendTest {
149 public:
150 TransportWideSequenceNumberObserver() : AudioSendTest() {
151 EXPECT_TRUE(parser_->RegisterRtpHeaderExtension(
152 kRtpExtensionTransportSequenceNumber, kExtensionId));
153 }
154
155 private:
156 Action OnSendRtp(const uint8_t* packet, size_t length) override {
157 RTPHeader header;
158 EXPECT_TRUE(parser_->Parse(packet, length, &header));
159
160 EXPECT_TRUE(header.extension.hasTransportSequenceNumber);
161 EXPECT_FALSE(header.extension.hasTransmissionTimeOffset);
162 EXPECT_FALSE(header.extension.hasAbsoluteSendTime);
163
164 observation_complete_.Set();
165
166 return SEND_PACKET;
167 }
168
169 void ModifyAudioConfigs(
170 AudioSendStream::Config* send_config,
171 std::vector<AudioReceiveStream::Config>* receive_configs) override {
172 send_config->rtp.extensions.clear();
173 send_config->rtp.extensions.push_back(RtpExtension(
174 RtpExtension::kTransportSequenceNumberUri, kExtensionId));
175 }
176
177 void PerformTest() override {
178 EXPECT_TRUE(Wait()) << "Timed out while waiting for a single RTP packet.";
179 }
180 } test;
181
182 RunBaseTest(&test);
183}
184
185TEST_F(AudioSendStreamCallTest, SendDtmf) {
186 static const uint8_t kDtmfPayloadType = 120;
187 static const int kDtmfPayloadFrequency = 8000;
188 static const int kDtmfEventFirst = 12;
189 static const int kDtmfEventLast = 31;
190 static const int kDtmfDuration = 50;
191 class DtmfObserver : public AudioSendTest {
192 public:
193 DtmfObserver() = default;
194
195 private:
196 Action OnSendRtp(const uint8_t* packet, size_t length) override {
197 RTPHeader header;
198 EXPECT_TRUE(parser_->Parse(packet, length, &header));
199
200 if (header.payloadType == kDtmfPayloadType) {
201 EXPECT_EQ(12u, header.headerLength);
202 EXPECT_EQ(16u, length);
203 const int event = packet[12];
204 if (event != expected_dtmf_event_) {
205 ++expected_dtmf_event_;
206 EXPECT_EQ(event, expected_dtmf_event_);
207 if (expected_dtmf_event_ == kDtmfEventLast) {
208 observation_complete_.Set();
209 }
210 }
211 }
212
213 return SEND_PACKET;
214 }
215
216 void OnAudioStreamsCreated(
217 AudioSendStream* send_stream,
218 const std::vector<AudioReceiveStream*>& receive_streams) override {
219 // Need to start stream here, else DTMF events are dropped.
220 send_stream->Start();
221 for (int event = kDtmfEventFirst; event <= kDtmfEventLast; ++event) {
222 send_stream->SendTelephoneEvent(kDtmfPayloadType, kDtmfPayloadFrequency,
223 event, kDtmfDuration);
224 }
225 }
226
227 void PerformTest() override {
228 EXPECT_TRUE(Wait()) << "Timed out while waiting for DTMF stream.";
229 }
230
231 int expected_dtmf_event_ = kDtmfEventFirst;
232 } test;
233
234 RunBaseTest(&test);
235}
236
237} // namespace test
238} // namespace webrtc