Chromium Code Reviews| 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 | 14 |
| 15 #include "webrtc/base/rate_limiter.h" | 15 #include "webrtc/base/rate_limiter.h" |
| 16 #include "webrtc/common_types.h" | 16 #include "webrtc/common_types.h" |
| 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" | 17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h" |
| 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" | 18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 19 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" | 19 #include "webrtc/modules/rtp_rtcp/source/rtp_receiver_audio.h" |
| 20 #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" | 20 #include "webrtc/modules/rtp_rtcp/test/testAPI/test_api.h" |
| 21 #include "webrtc/test/gtest.h" | 21 #include "webrtc/test/gtest.h" |
| 22 | 22 |
| 23 namespace webrtc { | 23 namespace webrtc { |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 const uint32_t kTestRate = 64000u; | 26 const uint32_t kTestRate = 64000u; |
| 27 const uint8_t kTestPayload[] = { 't', 'e', 's', 't' }; | 27 const uint8_t kTestPayload[] = { 't', 'e', 's', 't' }; |
| 28 const uint8_t kPcmuPayloadType = 96; | 28 const uint8_t kPcmuPayloadType = 96; |
| 29 const uint8_t kDtmfPayloadType = 97; | 29 const uint8_t kDtmfPayloadType = 97; |
| 30 const int64_t kContributingSourcesTimeout = 10000; // ms | |
|
hbos
2017/03/30 09:51:54
+ kContributingSourcesTimeoutMs
- // ms
Zhi Huang
2017/03/31 06:44:04
Done.
| |
| 30 | 31 |
| 31 struct CngCodecSpec { | 32 struct CngCodecSpec { |
| 32 int payload_type; | 33 int payload_type; |
| 33 int clockrate_hz; | 34 int clockrate_hz; |
| 34 }; | 35 }; |
| 35 | 36 |
| 36 const CngCodecSpec kCngCodecs[] = {{13, 8000}, | 37 const CngCodecSpec kCngCodecs[] = {{13, 8000}, |
| 37 {103, 16000}, | 38 {103, 16000}, |
| 38 {104, 32000}, | 39 {104, 32000}, |
| 39 {105, 48000}}; | 40 {105, 48000}}; |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 in_timestamp, -1, kTestPayload, 1, | 278 in_timestamp, -1, kTestPayload, 1, |
| 278 nullptr, nullptr, nullptr)); | 279 nullptr, nullptr, nullptr)); |
| 279 | 280 |
| 280 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); | 281 EXPECT_EQ(test_ssrc, rtp_receiver2_->SSRC()); |
| 281 EXPECT_TRUE(rtp_receiver2_->Timestamp(×tamp)); | 282 EXPECT_TRUE(rtp_receiver2_->Timestamp(×tamp)); |
| 282 EXPECT_EQ(test_timestamp + in_timestamp, timestamp); | 283 EXPECT_EQ(test_timestamp + in_timestamp, timestamp); |
| 283 in_timestamp += 10; | 284 in_timestamp += 10; |
| 284 } | 285 } |
| 285 } | 286 } |
| 286 | 287 |
| 288 TEST_F(RtpRtcpAudioTest, GetContributingSources) { | |
| 289 int64_t timestamp = fake_clock.TimeInMilliseconds(); | |
| 290 RTPHeader header; | |
| 291 header.payloadType = kPcmuPayloadType; | |
| 292 header.ssrc = 1; | |
| 293 header.timestamp = timestamp; | |
| 294 header.numCSRCs = 2; | |
| 295 header.arrOfCSRCs[0] = 111; | |
| 296 header.arrOfCSRCs[1] = 222; | |
| 297 | |
| 298 CodecInst voice_codec = {}; | |
| 299 voice_codec.pltype = kPcmuPayloadType; | |
| 300 voice_codec.plfreq = 8000; | |
| 301 voice_codec.rate = kTestRate; | |
| 302 memcpy(voice_codec.plname, "PCMU", 5); | |
| 303 RegisterPayload(voice_codec); | |
| 304 | |
| 305 PayloadUnion payload_specific; | |
| 306 bool in_order = false; | |
| 307 | |
| 308 EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4, | |
| 309 payload_specific, in_order)); | |
| 310 auto sources = rtp_receiver1_->GetContributingSources(); | |
| 311 // Two sources use the CSRCs and one uses the SSRC. | |
| 312 ASSERT_EQ(3u, sources.size()); | |
| 313 EXPECT_EQ(222u, sources[0]->source()); | |
| 314 EXPECT_EQ(timestamp, sources[0]->timestamp()); | |
| 315 EXPECT_EQ(111u, sources[1]->source()); | |
| 316 EXPECT_EQ(timestamp, sources[1]->timestamp()); | |
| 317 EXPECT_EQ(1u, sources[2]->source()); | |
| 318 // The timestamp of the source using the SSRC is always the time when the | |
| 319 // method is called. | |
| 320 EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[2]->timestamp()); | |
| 321 | |
| 322 // Advance the fake clock and the method is expected to return the | |
| 323 // contributing source object with same |source| and updated |timestamp|. | |
| 324 fake_clock.AdvanceTimeMilliseconds(1); | |
| 325 EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4, | |
| 326 payload_specific, in_order)); | |
| 327 sources = rtp_receiver1_->GetContributingSources(); | |
| 328 ASSERT_EQ(3u, sources.size()); | |
| 329 EXPECT_EQ(222u, sources[0]->source()); | |
| 330 EXPECT_EQ(timestamp + 1, sources[0]->timestamp()); | |
| 331 EXPECT_EQ(111u, sources[1]->source()); | |
| 332 EXPECT_EQ(timestamp + 1, sources[1]->timestamp()); | |
| 333 EXPECT_EQ(1u, sources[2]->source()); | |
| 334 EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[2]->timestamp()); | |
| 335 | |
| 336 // Simulate the time out. | |
| 337 fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeout + 1); | |
| 338 sources = rtp_receiver1_->GetContributingSources(); | |
| 339 // The sources using the CSRCs should be out of date. | |
| 340 ASSERT_EQ(1u, sources.size()); | |
| 341 EXPECT_EQ(1u, sources[0]->source()); | |
| 342 EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[0]->timestamp()); | |
| 343 } | |
| 344 | |
| 287 } // namespace webrtc | 345 } // namespace webrtc |
| OLD | NEW |