Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc |
| diff --git a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc |
| index 5e5d8eea49c04b89f9a13fd96bd62df7597d27f7..18aad7e1e62dbde8566c95217e9ae75e867a55e5 100644 |
| --- a/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc |
| +++ b/webrtc/modules/rtp_rtcp/test/testAPI/test_api_audio.cc |
| @@ -27,6 +27,7 @@ const uint32_t kTestRate = 64000u; |
| const uint8_t kTestPayload[] = { 't', 'e', 's', 't' }; |
| const uint8_t kPcmuPayloadType = 96; |
| const uint8_t kDtmfPayloadType = 97; |
| +const int64_t kContributingSourcesTimeout = 10000; // ms |
|
hbos
2017/03/30 09:51:54
+ kContributingSourcesTimeoutMs
- // ms
Zhi Huang
2017/03/31 06:44:04
Done.
|
| struct CngCodecSpec { |
| int payload_type; |
| @@ -284,4 +285,61 @@ TEST_F(RtpRtcpAudioTest, ComfortNoise) { |
| } |
| } |
| +TEST_F(RtpRtcpAudioTest, GetContributingSources) { |
| + int64_t timestamp = fake_clock.TimeInMilliseconds(); |
| + RTPHeader header; |
| + header.payloadType = kPcmuPayloadType; |
| + header.ssrc = 1; |
| + header.timestamp = timestamp; |
| + header.numCSRCs = 2; |
| + header.arrOfCSRCs[0] = 111; |
| + header.arrOfCSRCs[1] = 222; |
| + |
| + CodecInst voice_codec = {}; |
| + voice_codec.pltype = kPcmuPayloadType; |
| + voice_codec.plfreq = 8000; |
| + voice_codec.rate = kTestRate; |
| + memcpy(voice_codec.plname, "PCMU", 5); |
| + RegisterPayload(voice_codec); |
| + |
| + PayloadUnion payload_specific; |
| + bool in_order = false; |
| + |
| + EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4, |
| + payload_specific, in_order)); |
| + auto sources = rtp_receiver1_->GetContributingSources(); |
| + // Two sources use the CSRCs and one uses the SSRC. |
| + ASSERT_EQ(3u, sources.size()); |
| + EXPECT_EQ(222u, sources[0]->source()); |
| + EXPECT_EQ(timestamp, sources[0]->timestamp()); |
| + EXPECT_EQ(111u, sources[1]->source()); |
| + EXPECT_EQ(timestamp, sources[1]->timestamp()); |
| + EXPECT_EQ(1u, sources[2]->source()); |
| + // The timestamp of the source using the SSRC is always the time when the |
| + // method is called. |
| + EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[2]->timestamp()); |
| + |
| + // Advance the fake clock and the method is expected to return the |
| + // contributing source object with same |source| and updated |timestamp|. |
| + fake_clock.AdvanceTimeMilliseconds(1); |
| + EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4, |
| + payload_specific, in_order)); |
| + sources = rtp_receiver1_->GetContributingSources(); |
| + ASSERT_EQ(3u, sources.size()); |
| + EXPECT_EQ(222u, sources[0]->source()); |
| + EXPECT_EQ(timestamp + 1, sources[0]->timestamp()); |
| + EXPECT_EQ(111u, sources[1]->source()); |
| + EXPECT_EQ(timestamp + 1, sources[1]->timestamp()); |
| + EXPECT_EQ(1u, sources[2]->source()); |
| + EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[2]->timestamp()); |
| + |
| + // Simulate the time out. |
| + fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeout + 1); |
| + sources = rtp_receiver1_->GetContributingSources(); |
| + // The sources using the CSRCs should be out of date. |
| + ASSERT_EQ(1u, sources.size()); |
| + EXPECT_EQ(1u, sources[0]->source()); |
| + EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[0]->timestamp()); |
| +} |
| + |
| } // namespace webrtc |