Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(45)

Side by Side Diff: webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc

Issue 2378403004: Resurrected test_api_audio.cc (Closed)
Patch Set: Addressed comments. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <memory> 12 #include <memory>
13 #include <vector> 13 #include <vector>
14 #include "webrtc/test/gtest.h" 14 #include "webrtc/test/gtest.h"
15 15
16 #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" 16 #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h"
17 17
18 #include "webrtc/base/rate_limiter.h" 18 #include "webrtc/base/rate_limiter.h"
19 #include "webrtc/common_types.h" 19 #include "webrtc/common_types.h"
20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" 20 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 21 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
22 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" 22 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h"
23 23
24 namespace webrtc { 24 namespace webrtc {
25 namespace { 25 namespace {
26 #define test_rate 64000u 26
27 const uint32_t kTestRate = 64000u;
28 const uint8_t kTestPayload[] = { 't', 'e', 's', 't' };
29 const uint8_t kPcmuPayloadType = 96;
30 const uint8_t kDtmfPayloadType = 97;
31
32 struct CngCodecSpec {
33 int payload_type;
34 int clockrate_hz;
35 };
36
37 CngCodecSpec kCngCodecs[] = {{13, 8000},
danilchap 2016/10/04 13:00:32 add const (or constexpr), to be safe.
hlundin-webrtc 2016/10/04 13:45:03 +1
ossu 2016/10/04 14:55:29 Sure thing!
38 {103, 16000},
39 {104, 32000},
40 {105, 48000}};
27 41
28 class VerifyingAudioReceiver : public NullRtpData { 42 class VerifyingAudioReceiver : public NullRtpData {
29 public: 43 public:
30 int32_t OnReceivedPayloadData( 44 int32_t OnReceivedPayloadData(
31 const uint8_t* payloadData, 45 const uint8_t* payloadData,
32 size_t payloadSize, 46 size_t payloadSize,
33 const webrtc::WebRtcRTPHeader* rtpHeader) override { 47 const webrtc::WebRtcRTPHeader* rtpHeader) override {
34 if (rtpHeader->header.payloadType == 98 || 48 const uint8_t payloadType = rtpHeader->header.payloadType;
danilchap 2016/10/04 13:00:32 payload_type = ...
ossu 2016/10/04 14:55:29 Done.
35 rtpHeader->header.payloadType == 99) { 49 if (payloadType == kPcmuPayloadType || payloadType == kDtmfPayloadType) {
36 EXPECT_EQ(4u, payloadSize); 50 EXPECT_EQ(sizeof(kTestPayload), payloadSize);
37 char str[5];
38 memcpy(str, payloadData, payloadSize);
39 str[4] = 0;
40 // All our test vectors for payload type 96 and 97 even the stereo is on 51 // All our test vectors for payload type 96 and 97 even the stereo is on
41 // a per channel base equal to the 4 chars "test". 52 // a per channel base equal to the 4 chars "test".
42 // Note there is no null termination so we add that to use the 53 const size_t min_size = std::min(sizeof(kTestPayload), payloadSize);
hlundin-webrtc 2016/10/04 13:45:03 Shouldn't it be an error if payloadSize != sizeof(
ossu 2016/10/04 14:55:30 Unfortunately, I can't use ASSERT because the func
danilchap 2016/10/05 08:12:57 Another solution is include gmock and use matchers
hlundin-webrtc 2016/10/05 13:52:42 Right, I didn't think of the non-void return type.
43 // test EXPECT_STRCASEEQ. 54 EXPECT_EQ(0, memcmp(payloadData, kTestPayload, min_size));
44 EXPECT_STRCASEEQ("test", str);
45 return 0;
46 } 55 }
47 if (rtpHeader->header.payloadType == 100 || 56
48 rtpHeader->header.payloadType == 101 || 57 auto is_cng_codec = [] (uint8_t payloadType) {
danilchap 2016/10/04 13:00:32 may be put this helper function near kCngCodecs de
ossu 2016/10/04 14:55:29 Done.
49 rtpHeader->header.payloadType == 102) { 58 for (const auto& c : kCngCodecs) {
50 if (rtpHeader->type.Audio.channel == 1) { 59 if (c.payload_type == payloadType)
51 if (payloadData[0] == 0xff) { 60 return true;
52 // All our test vectors for payload type 100, 101 and 102 have the
53 // first channel data being equal to 0xff.
54 return 0;
55 }
56 } 61 }
57 ADD_FAILURE() << "This code path should never happen."; 62
58 return -1; 63 return false;
64 };
65 if (is_cng_codec(payloadType)) {
66 // CNG types should be recognized properly.
67 EXPECT_EQ(kAudioFrameCN, rtpHeader->frameType);
68 EXPECT_TRUE(rtpHeader->type.Audio.isCNG);
59 } 69 }
60 return 0; 70 return 0;
61 } 71 }
62 }; 72 };
63 73
64 class RTPCallback : public NullRtpFeedback { 74 class RTPCallback : public NullRtpFeedback {
65 public: 75 public:
66 int32_t OnInitializeDecoder(const int8_t payloadType, 76 int32_t OnInitializeDecoder(const int8_t payloadType,
67 const char payloadName[RTP_PAYLOAD_NAME_SIZE], 77 const char payloadName[RTP_PAYLOAD_NAME_SIZE],
68 const int frequency, 78 const int frequency,
69 const size_t channels, 79 const size_t channels,
70 const uint32_t rate) override { 80 const uint32_t rate) override {
71 if (payloadType == 96) { 81 if (payloadType == kPcmuPayloadType) {
72 EXPECT_EQ(test_rate, rate) << 82 EXPECT_EQ(kTestRate, rate) <<
73 "The rate should be 64K for this payloadType"; 83 "The rate should be 64K for this payloadType";
74 } 84 }
75 return 0; 85 return 0;
76 } 86 }
77 }; 87 };
78 88
89 } // namespace
90
79 class RtpRtcpAudioTest : public ::testing::Test { 91 class RtpRtcpAudioTest : public ::testing::Test {
80 protected: 92 protected:
81 RtpRtcpAudioTest() 93 RtpRtcpAudioTest()
82 : fake_clock(123456), retransmission_rate_limiter_(&fake_clock, 1000) { 94 : fake_clock(123456), retransmission_rate_limiter_(&fake_clock, 1000) {
83 test_CSRC[0] = 1234; 95 test_CSRC[0] = 1234;
84 test_CSRC[2] = 2345; 96 test_CSRC[2] = 2345;
85 test_ssrc = 3456; 97 test_ssrc = 3456;
86 test_timestamp = 4567; 98 test_timestamp = 4567;
87 test_sequence_number = 2345; 99 test_sequence_number = 2345;
88 } 100 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 176
165 // Test detection at the end of a DTMF tone. 177 // Test detection at the end of a DTMF tone.
166 // EXPECT_EQ(0, module2->SetTelephoneEventForwardToDecoder(true)); 178 // EXPECT_EQ(0, module2->SetTelephoneEventForwardToDecoder(true));
167 179
168 EXPECT_EQ(0, module1->SetSendingStatus(true)); 180 EXPECT_EQ(0, module1->SetSendingStatus(true));
169 181
170 // Start basic RTP test. 182 // Start basic RTP test.
171 183
172 // Send an empty RTP packet. 184 // Send an empty RTP packet.
173 // Should fail since we have not registered the payload type. 185 // Should fail since we have not registered the payload type.
174 EXPECT_FALSE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, 0, -1, 186 EXPECT_FALSE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech,
175 nullptr, 0, nullptr, nullptr, 187 kPcmuPayloadType, 0, -1, nullptr, 0,
176 nullptr)); 188 nullptr, nullptr, nullptr));
177 189
178 CodecInst voice_codec; 190 CodecInst voice_codec;
179 memset(&voice_codec, 0, sizeof(voice_codec)); 191 memset(&voice_codec, 0, sizeof(voice_codec));
180 voice_codec.pltype = 96; 192 voice_codec.pltype = kPcmuPayloadType;
181 voice_codec.plfreq = 8000; 193 voice_codec.plfreq = 8000;
182 memcpy(voice_codec.plname, "PCMU", 5); 194 memcpy(voice_codec.plname, "PCMU", 5);
183 195
184 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); 196 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec));
185 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( 197 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload(
186 voice_codec.plname, 198 voice_codec.plname,
187 voice_codec.pltype, 199 voice_codec.pltype,
188 voice_codec.plfreq, 200 voice_codec.plfreq,
189 voice_codec.channels, 201 voice_codec.channels,
190 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); 202 (voice_codec.rate < 0) ? 0 : voice_codec.rate));
191 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec)); 203 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec));
192 voice_codec.rate = test_rate; 204 voice_codec.rate = kTestRate;
193 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( 205 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload(
194 voice_codec.plname, 206 voice_codec.plname,
195 voice_codec.pltype, 207 voice_codec.pltype,
196 voice_codec.plfreq, 208 voice_codec.plfreq,
197 voice_codec.channels, 209 voice_codec.channels,
198 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); 210 (voice_codec.rate < 0) ? 0 : voice_codec.rate));
199 211
200 const uint8_t test[5] = "test"; 212 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech,
201 EXPECT_EQ(true, 213 kPcmuPayloadType, 0, -1, kTestPayload,
202 module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, 0, -1, 214 4, nullptr, nullptr, nullptr));
203 test, 4, nullptr, nullptr, nullptr));
204 215
205 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); 216 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC());
206 uint32_t timestamp; 217 uint32_t timestamp;
207 EXPECT_TRUE(rtp_receiver2_->Timestamp(&timestamp)); 218 EXPECT_TRUE(rtp_receiver2_->Timestamp(&timestamp));
208 EXPECT_EQ(test_timestamp, timestamp); 219 EXPECT_EQ(test_timestamp, timestamp);
209 } 220 }
210 221
211 TEST_F(RtpRtcpAudioTest, DTMF) { 222 TEST_F(RtpRtcpAudioTest, DTMF) {
212 CodecInst voice_codec; 223 CodecInst voice_codec;
213 memset(&voice_codec, 0, sizeof(voice_codec)); 224 memset(&voice_codec, 0, sizeof(voice_codec));
214 voice_codec.pltype = 96; 225 voice_codec.pltype = kPcmuPayloadType;
215 voice_codec.plfreq = 8000; 226 voice_codec.plfreq = 8000;
216 memcpy(voice_codec.plname, "PCMU", 5); 227 memcpy(voice_codec.plname, "PCMU", 5);
217 228
218 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); 229 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec));
219 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( 230 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload(
220 voice_codec.plname, 231 voice_codec.plname,
221 voice_codec.pltype, 232 voice_codec.pltype,
222 voice_codec.plfreq, 233 voice_codec.plfreq,
223 voice_codec.channels, 234 voice_codec.channels,
224 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); 235 (voice_codec.rate < 0) ? 0 : voice_codec.rate));
225 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec)); 236 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec));
226 voice_codec.rate = test_rate; 237 voice_codec.rate = kTestRate;
227 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( 238 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload(
228 voice_codec.plname, 239 voice_codec.plname,
229 voice_codec.pltype, 240 voice_codec.pltype,
230 voice_codec.plfreq, 241 voice_codec.plfreq,
231 voice_codec.channels, 242 voice_codec.channels,
232 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); 243 (voice_codec.rate < 0) ? 0 : voice_codec.rate));
233 244
234 module1->SetSSRC(test_ssrc); 245 module1->SetSSRC(test_ssrc);
235 module1->SetStartTimestamp(test_timestamp); 246 module1->SetStartTimestamp(test_timestamp);
236 EXPECT_EQ(0, module1->SetSendingStatus(true)); 247 EXPECT_EQ(0, module1->SetSendingStatus(true));
237 248
238 // Prepare for DTMF. 249 // Prepare for DTMF.
239 voice_codec.pltype = 97; 250 voice_codec.pltype = kDtmfPayloadType;
240 voice_codec.plfreq = 8000; 251 voice_codec.plfreq = 8000;
241 memcpy(voice_codec.plname, "telephone-event", 16); 252 memcpy(voice_codec.plname, "telephone-event", 16);
242 253
243 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); 254 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec));
244 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( 255 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload(
245 voice_codec.plname, 256 voice_codec.plname,
246 voice_codec.pltype, 257 voice_codec.pltype,
247 voice_codec.plfreq, 258 voice_codec.plfreq,
248 voice_codec.channels, 259 voice_codec.channels,
249 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); 260 (voice_codec.rate < 0) ? 0 : voice_codec.rate));
250 261
251 // Start DTMF test. 262 // Start DTMF test.
252 int timeStamp = 160; 263 int timeStamp = 160;
253 264
254 // Send a DTMF tone using RFC 2833 (4733). 265 // Send a DTMF tone using RFC 2833 (4733).
255 for (int i = 0; i < 16; i++) { 266 for (int i = 0; i < 16; i++) {
256 EXPECT_EQ(0, module1->SendTelephoneEventOutband(i, timeStamp, 10)); 267 EXPECT_EQ(0, module1->SendTelephoneEventOutband(i, timeStamp, 10));
257 } 268 }
258 timeStamp += 160; // Prepare for next packet. 269 timeStamp += 160; // Prepare for next packet.
259 270
260 const uint8_t test[9] = "test";
261
262 // Send RTP packets for 16 tones a 160 ms 100ms 271 // Send RTP packets for 16 tones a 160 ms 100ms
263 // pause between = 2560ms + 1600ms = 4160ms 272 // pause between = 2560ms + 1600ms = 4160ms
264 for (; timeStamp <= 250 * 160; timeStamp += 160) { 273 for (; timeStamp <= 250 * 160; timeStamp += 160) {
265 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, 274 EXPECT_TRUE(module1->SendOutgoingData(
266 timeStamp, -1, test, 4, nullptr, 275 webrtc::kAudioFrameSpeech, kPcmuPayloadType, timeStamp, -1,
267 nullptr, nullptr)); 276 kTestPayload, 4, nullptr, nullptr, nullptr));
268 fake_clock.AdvanceTimeMilliseconds(20); 277 fake_clock.AdvanceTimeMilliseconds(20);
269 module1->Process(); 278 module1->Process();
270 } 279 }
271 EXPECT_EQ(0, module1->SendTelephoneEventOutband(32, 9000, 10)); 280 EXPECT_EQ(0, module1->SendTelephoneEventOutband(32, 9000, 10));
272 281
273 for (; timeStamp <= 740 * 160; timeStamp += 160) { 282 for (; timeStamp <= 740 * 160; timeStamp += 160) {
274 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, 283 EXPECT_TRUE(module1->SendOutgoingData(
275 timeStamp, -1, test, 4, nullptr, 284 webrtc::kAudioFrameSpeech, kPcmuPayloadType, timeStamp, -1,
276 nullptr, nullptr)); 285 kTestPayload, 4, nullptr, nullptr, nullptr));
277 fake_clock.AdvanceTimeMilliseconds(20); 286 fake_clock.AdvanceTimeMilliseconds(20);
278 module1->Process(); 287 module1->Process();
279 } 288 }
280 } 289 }
281 290
282 } // namespace 291 TEST_F(RtpRtcpAudioTest, ComfortNoise) {
292 module1->SetSSRC(test_ssrc);
293 module1->SetStartTimestamp(test_timestamp);
294
295 EXPECT_EQ(0, module1->SetSendingStatus(true));
296
297 // Start basic RTP test.
298
299 CodecInst voice_codec;
300 memset(&voice_codec, 0, sizeof(voice_codec));
301 voice_codec.pltype = kPcmuPayloadType;
302 voice_codec.plfreq = 8000;
303 memcpy(voice_codec.plname, "PCMU", 5);
304
305 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec));
306 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload(
307 voice_codec.plname,
308 voice_codec.pltype,
309 voice_codec.plfreq,
310 voice_codec.channels,
311 (voice_codec.rate < 0) ? 0 : voice_codec.rate));
hlundin-webrtc 2016/10/04 13:45:02 voice_codec.rate should be deterministically known
ossu 2016/10/04 14:55:29 I don't know. It was like this when I got here. :)
312 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec));
313 voice_codec.rate = kTestRate;
314 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload(
315 voice_codec.plname,
316 voice_codec.pltype,
317 voice_codec.plfreq,
318 voice_codec.channels,
319 (voice_codec.rate < 0) ? 0 : voice_codec.rate));
hlundin-webrtc 2016/10/04 13:45:02 Same here.
ossu 2016/10/04 14:55:30 Well, alright, it was like this in the test I stol
320
321 for (const auto& c : kCngCodecs) {
322 CodecInst cng_codec = {0};
323 cng_codec.pltype = c.payload_type;
324 cng_codec.plfreq = c.clockrate_hz;
325 memcpy(cng_codec.plname, "CN", 3);
326
327 EXPECT_EQ(0, module1->RegisterSendPayload(cng_codec));
328 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload(
329 cng_codec.plname,
330 cng_codec.pltype,
331 cng_codec.plfreq,
332 cng_codec.channels,
333 cng_codec.rate));
334 EXPECT_EQ(0, module2->RegisterSendPayload(cng_codec));
335 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload(
336 cng_codec.plname,
337 cng_codec.pltype,
338 cng_codec.plfreq,
339 cng_codec.channels,
340 cng_codec.rate));
341 }
342
343 uint32_t in_timestamp = 0;
344
345 for (const auto& c : kCngCodecs) {
346 uint32_t timestamp;
347 EXPECT_TRUE(module1->SendOutgoingData(
348 webrtc::kAudioFrameSpeech, kPcmuPayloadType, in_timestamp, -1,
349 kTestPayload, 4, nullptr, nullptr, nullptr));
350
351 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC());
352 EXPECT_TRUE(rtp_receiver2_->Timestamp(&timestamp));
353 EXPECT_EQ(test_timestamp + in_timestamp, timestamp);
354 in_timestamp += 10;
355
356 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameCN, c.payload_type,
357 in_timestamp, -1, kTestPayload, 1,
358 nullptr, nullptr, nullptr));
359
360 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC());
361 EXPECT_TRUE(rtp_receiver2_->Timestamp(&timestamp));
362 EXPECT_EQ(test_timestamp + in_timestamp, timestamp);
363 in_timestamp += 10;
364 }
365 }
366
283 } // namespace webrtc 367 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698