OLD | NEW |
---|---|
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' }; | |
27 | 29 |
28 class VerifyingAudioReceiver : public NullRtpData { | 30 class VerifyingAudioReceiver : public NullRtpData { |
29 public: | 31 public: |
30 int32_t OnReceivedPayloadData( | 32 int32_t OnReceivedPayloadData( |
31 const uint8_t* payloadData, | 33 const uint8_t* payloadData, |
32 size_t payloadSize, | 34 size_t payloadSize, |
33 const webrtc::WebRtcRTPHeader* rtpHeader) override { | 35 const webrtc::WebRtcRTPHeader* rtpHeader) override { |
34 if (rtpHeader->header.payloadType == 98 || | 36 switch (rtpHeader->header.payloadType) { |
35 rtpHeader->header.payloadType == 99) { | 37 case 96: |
danilchap
2016/10/03 13:51:19
may be define these constants too.
ossu
2016/10/03 14:12:03
Hmm... perhaps I could extract the payload types a
| |
36 EXPECT_EQ(4u, payloadSize); | 38 case 97: { |
37 char str[5]; | 39 EXPECT_EQ(sizeof(kTestPayload), payloadSize); |
38 memcpy(str, payloadData, payloadSize); | 40 // All our test vectors for payload type 96 and 97 even the stereo is on |
39 str[4] = 0; | 41 // a per channel base equal to the 4 chars "test". |
40 // All our test vectors for payload type 96 and 97 even the stereo is on | 42 const size_t min_size = std::min(sizeof(kTestPayload), payloadSize); |
41 // a per channel base equal to the 4 chars "test". | 43 EXPECT_EQ(0, memcmp(payloadData, kTestPayload, min_size)); |
42 // Note there is no null termination so we add that to use the | 44 break; |
43 // test EXPECT_STRCASEEQ. | |
44 EXPECT_STRCASEEQ("test", str); | |
45 return 0; | |
46 } | |
47 if (rtpHeader->header.payloadType == 100 || | |
48 rtpHeader->header.payloadType == 101 || | |
49 rtpHeader->header.payloadType == 102) { | |
50 if (rtpHeader->type.Audio.channel == 1) { | |
51 if (payloadData[0] == 0xff) { | |
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 } | 45 } |
57 ADD_FAILURE() << "This code path should never happen."; | 46 // CNG types should be recognized properly. |
58 return -1; | 47 case 13: |
48 case 103: | |
49 case 104: | |
50 case 105: | |
51 EXPECT_EQ(kAudioFrameCN, rtpHeader->frameType); | |
52 EXPECT_TRUE(rtpHeader->type.Audio.isCNG); | |
53 break; | |
54 default: { | |
55 // Do nothing | |
56 } | |
59 } | 57 } |
60 return 0; | 58 return 0; |
61 } | 59 } |
62 }; | 60 }; |
63 | 61 |
64 class RTPCallback : public NullRtpFeedback { | 62 class RTPCallback : public NullRtpFeedback { |
65 public: | 63 public: |
66 int32_t OnInitializeDecoder(const int8_t payloadType, | 64 int32_t OnInitializeDecoder(const int8_t payloadType, |
67 const char payloadName[RTP_PAYLOAD_NAME_SIZE], | 65 const char payloadName[RTP_PAYLOAD_NAME_SIZE], |
68 const int frequency, | 66 const int frequency, |
69 const size_t channels, | 67 const size_t channels, |
70 const uint32_t rate) override { | 68 const uint32_t rate) override { |
71 if (payloadType == 96) { | 69 if (payloadType == 96) { |
72 EXPECT_EQ(test_rate, rate) << | 70 EXPECT_EQ(kTestRate, rate) << |
73 "The rate should be 64K for this payloadType"; | 71 "The rate should be 64K for this payloadType"; |
74 } | 72 } |
75 return 0; | 73 return 0; |
76 } | 74 } |
77 }; | 75 }; |
78 | 76 |
danilchap
2016/10/03 13:51:19
may be fix tests style by terminating unnamed name
ossu
2016/10/03 14:12:03
Acknowledged.
| |
79 class RtpRtcpAudioTest : public ::testing::Test { | 77 class RtpRtcpAudioTest : public ::testing::Test { |
80 protected: | 78 protected: |
81 RtpRtcpAudioTest() | 79 RtpRtcpAudioTest() |
82 : fake_clock(123456), retransmission_rate_limiter_(&fake_clock, 1000) { | 80 : fake_clock(123456), retransmission_rate_limiter_(&fake_clock, 1000) { |
83 test_CSRC[0] = 1234; | 81 test_CSRC[0] = 1234; |
84 test_CSRC[2] = 2345; | 82 test_CSRC[2] = 2345; |
85 test_ssrc = 3456; | 83 test_ssrc = 3456; |
86 test_timestamp = 4567; | 84 test_timestamp = 4567; |
87 test_sequence_number = 2345; | 85 test_sequence_number = 2345; |
88 } | 86 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 memcpy(voice_codec.plname, "PCMU", 5); | 180 memcpy(voice_codec.plname, "PCMU", 5); |
183 | 181 |
184 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); | 182 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); |
185 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( | 183 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( |
186 voice_codec.plname, | 184 voice_codec.plname, |
187 voice_codec.pltype, | 185 voice_codec.pltype, |
188 voice_codec.plfreq, | 186 voice_codec.plfreq, |
189 voice_codec.channels, | 187 voice_codec.channels, |
190 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); | 188 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); |
191 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec)); | 189 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec)); |
192 voice_codec.rate = test_rate; | 190 voice_codec.rate = kTestRate; |
193 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( | 191 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( |
194 voice_codec.plname, | 192 voice_codec.plname, |
195 voice_codec.pltype, | 193 voice_codec.pltype, |
196 voice_codec.plfreq, | 194 voice_codec.plfreq, |
197 voice_codec.channels, | 195 voice_codec.channels, |
198 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); | 196 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); |
199 | 197 |
200 const uint8_t test[5] = "test"; | 198 EXPECT_EQ(true, module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, 0, |
201 EXPECT_EQ(true, | 199 -1, kTestPayload, 4, nullptr, |
202 module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, 0, -1, | 200 nullptr, nullptr)); |
203 test, 4, nullptr, nullptr, nullptr)); | |
204 | 201 |
205 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); | 202 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); |
206 uint32_t timestamp; | 203 uint32_t timestamp; |
207 EXPECT_TRUE(rtp_receiver2_->Timestamp(×tamp)); | 204 EXPECT_TRUE(rtp_receiver2_->Timestamp(×tamp)); |
208 EXPECT_EQ(test_timestamp, timestamp); | 205 EXPECT_EQ(test_timestamp, timestamp); |
209 } | 206 } |
210 | 207 |
211 TEST_F(RtpRtcpAudioTest, DTMF) { | 208 TEST_F(RtpRtcpAudioTest, DTMF) { |
212 CodecInst voice_codec; | 209 CodecInst voice_codec; |
213 memset(&voice_codec, 0, sizeof(voice_codec)); | 210 memset(&voice_codec, 0, sizeof(voice_codec)); |
214 voice_codec.pltype = 96; | 211 voice_codec.pltype = 96; |
215 voice_codec.plfreq = 8000; | 212 voice_codec.plfreq = 8000; |
216 memcpy(voice_codec.plname, "PCMU", 5); | 213 memcpy(voice_codec.plname, "PCMU", 5); |
217 | 214 |
218 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); | 215 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); |
219 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( | 216 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( |
220 voice_codec.plname, | 217 voice_codec.plname, |
221 voice_codec.pltype, | 218 voice_codec.pltype, |
222 voice_codec.plfreq, | 219 voice_codec.plfreq, |
223 voice_codec.channels, | 220 voice_codec.channels, |
224 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); | 221 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); |
225 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec)); | 222 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec)); |
226 voice_codec.rate = test_rate; | 223 voice_codec.rate = kTestRate; |
227 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( | 224 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( |
228 voice_codec.plname, | 225 voice_codec.plname, |
229 voice_codec.pltype, | 226 voice_codec.pltype, |
230 voice_codec.plfreq, | 227 voice_codec.plfreq, |
231 voice_codec.channels, | 228 voice_codec.channels, |
232 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); | 229 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); |
233 | 230 |
234 module1->SetSSRC(test_ssrc); | 231 module1->SetSSRC(test_ssrc); |
235 module1->SetStartTimestamp(test_timestamp); | 232 module1->SetStartTimestamp(test_timestamp); |
236 EXPECT_EQ(0, module1->SetSendingStatus(true)); | 233 EXPECT_EQ(0, module1->SetSendingStatus(true)); |
(...skipping 13 matching lines...) Expand all Loading... | |
250 | 247 |
251 // Start DTMF test. | 248 // Start DTMF test. |
252 int timeStamp = 160; | 249 int timeStamp = 160; |
253 | 250 |
254 // Send a DTMF tone using RFC 2833 (4733). | 251 // Send a DTMF tone using RFC 2833 (4733). |
255 for (int i = 0; i < 16; i++) { | 252 for (int i = 0; i < 16; i++) { |
256 EXPECT_EQ(0, module1->SendTelephoneEventOutband(i, timeStamp, 10)); | 253 EXPECT_EQ(0, module1->SendTelephoneEventOutband(i, timeStamp, 10)); |
257 } | 254 } |
258 timeStamp += 160; // Prepare for next packet. | 255 timeStamp += 160; // Prepare for next packet. |
259 | 256 |
260 const uint8_t test[9] = "test"; | |
261 | |
262 // Send RTP packets for 16 tones a 160 ms 100ms | 257 // Send RTP packets for 16 tones a 160 ms 100ms |
263 // pause between = 2560ms + 1600ms = 4160ms | 258 // pause between = 2560ms + 1600ms = 4160ms |
264 for (; timeStamp <= 250 * 160; timeStamp += 160) { | 259 for (; timeStamp <= 250 * 160; timeStamp += 160) { |
265 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, | 260 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, |
266 timeStamp, -1, test, 4, nullptr, | 261 timeStamp, -1, kTestPayload, 4, |
267 nullptr, nullptr)); | 262 nullptr, nullptr, nullptr)); |
268 fake_clock.AdvanceTimeMilliseconds(20); | 263 fake_clock.AdvanceTimeMilliseconds(20); |
269 module1->Process(); | 264 module1->Process(); |
270 } | 265 } |
271 EXPECT_EQ(0, module1->SendTelephoneEventOutband(32, 9000, 10)); | 266 EXPECT_EQ(0, module1->SendTelephoneEventOutband(32, 9000, 10)); |
272 | 267 |
273 for (; timeStamp <= 740 * 160; timeStamp += 160) { | 268 for (; timeStamp <= 740 * 160; timeStamp += 160) { |
274 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, | 269 EXPECT_TRUE(module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, |
275 timeStamp, -1, test, 4, nullptr, | 270 timeStamp, -1, kTestPayload, 4, |
276 nullptr, nullptr)); | 271 nullptr, nullptr, nullptr)); |
277 fake_clock.AdvanceTimeMilliseconds(20); | 272 fake_clock.AdvanceTimeMilliseconds(20); |
278 module1->Process(); | 273 module1->Process(); |
279 } | 274 } |
280 } | 275 } |
281 | 276 |
277 | |
278 TEST_F(RtpRtcpAudioTest, CNG) { | |
danilchap
2016/10/03 13:51:19
Can you move all unimportant setup into helper met
ossu
2016/10/03 14:12:03
CNG is short for ComfortNoiseGenerator. In this ca
| |
279 module1->SetSSRC(test_ssrc); | |
280 module1->SetStartTimestamp(test_timestamp); | |
281 | |
282 EXPECT_EQ(0, module1->SetSendingStatus(true)); | |
283 | |
284 // Start basic RTP test. | |
285 | |
286 CodecInst voice_codec; | |
287 memset(&voice_codec, 0, sizeof(voice_codec)); | |
288 voice_codec.pltype = 96; | |
289 voice_codec.plfreq = 8000; | |
290 memcpy(voice_codec.plname, "PCMU", 5); | |
291 | |
292 EXPECT_EQ(0, module1->RegisterSendPayload(voice_codec)); | |
293 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( | |
294 voice_codec.plname, | |
295 voice_codec.pltype, | |
296 voice_codec.plfreq, | |
297 voice_codec.channels, | |
298 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); | |
299 EXPECT_EQ(0, module2->RegisterSendPayload(voice_codec)); | |
300 voice_codec.rate = kTestRate; | |
301 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( | |
302 voice_codec.plname, | |
303 voice_codec.pltype, | |
304 voice_codec.plfreq, | |
305 voice_codec.channels, | |
306 (voice_codec.rate < 0) ? 0 : voice_codec.rate)); | |
307 | |
308 struct CngCodecSpec { | |
309 int payload_type; | |
310 int clockrate_hz; | |
311 }; | |
312 | |
313 CngCodecSpec cng_codecs[] = { | |
314 {13, 8000}, {103, 16000}, {104, 32000}, {105, 48000}}; | |
315 | |
316 for (const auto& c : cng_codecs) { | |
317 CodecInst cng_codec = {0}; | |
318 cng_codec.pltype = c.payload_type; | |
319 cng_codec.plfreq = c.clockrate_hz; | |
320 memcpy(cng_codec.plname, "CN", 3); | |
321 | |
322 EXPECT_EQ(0, module1->RegisterSendPayload(cng_codec)); | |
323 EXPECT_EQ(0, rtp_receiver1_->RegisterReceivePayload( | |
324 cng_codec.plname, | |
325 cng_codec.pltype, | |
326 cng_codec.plfreq, | |
327 cng_codec.channels, | |
328 cng_codec.rate)); | |
329 EXPECT_EQ(0, module2->RegisterSendPayload(cng_codec)); | |
330 EXPECT_EQ(0, rtp_receiver2_->RegisterReceivePayload( | |
331 cng_codec.plname, | |
332 cng_codec.pltype, | |
333 cng_codec.plfreq, | |
334 cng_codec.channels, | |
335 cng_codec.rate)); | |
336 } | |
337 | |
338 uint32_t in_timestamp = 0; | |
339 | |
340 for (const auto& c : cng_codecs) { | |
341 uint32_t timestamp; | |
342 EXPECT_EQ(true, module1->SendOutgoingData(webrtc::kAudioFrameSpeech, 96, | |
343 in_timestamp, -1, kTestPayload, 4, | |
344 nullptr, nullptr, nullptr)); | |
345 | |
346 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); | |
347 EXPECT_TRUE(rtp_receiver2_->Timestamp(×tamp)); | |
348 EXPECT_EQ(test_timestamp + in_timestamp, timestamp); | |
349 in_timestamp += 10; | |
350 | |
351 EXPECT_EQ(true, module1->SendOutgoingData( | |
danilchap
2016/10/03 13:51:19
EXPECT_TRUE(...) instead of EXPECT_EQ(true,...) lo
ossu
2016/10/03 14:12:03
Acknowledged.
| |
352 webrtc::kAudioFrameCN, c.payload_type, in_timestamp, -1, | |
353 kTestPayload, 1, nullptr, nullptr, nullptr)); | |
354 | |
355 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); | |
356 EXPECT_TRUE(rtp_receiver2_->Timestamp(×tamp)); | |
357 EXPECT_EQ(test_timestamp + in_timestamp, timestamp); | |
358 in_timestamp += 10; | |
359 } | |
360 } | |
361 | |
282 } // namespace | 362 } // namespace |
283 } // namespace webrtc | 363 } // namespace webrtc |
OLD | NEW |