| 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..bc3f7c92c8a93bbd58b80457b3fc08346a311435 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 kContributingSourcesTimeoutMs = 10000;
|
|
|
| struct CngCodecSpec {
|
| int payload_type;
|
| @@ -284,4 +285,105 @@ 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);
|
| + EXPECT_EQ(timestamp, 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(timestamp + 1, sources[2].timestamp);
|
| +
|
| + // Simulate the time out.
|
| + fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs + 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(timestamp + 1, sources[0].timestamp);
|
| +}
|
| +
|
| +// Test that when the SSRC is changed, it returns an object for the old SSRC for
|
| +// 10 seconds after it switches.
|
| +TEST_F(RtpRtcpAudioTest, GetContributingSourcesChangeSSRC) {
|
| + int64_t timestamp = fake_clock.TimeInMilliseconds();
|
| + RTPHeader header;
|
| + header.payloadType = kPcmuPayloadType;
|
| + header.ssrc = 1;
|
| + header.timestamp = timestamp;
|
| +
|
| + 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();
|
| + ASSERT_EQ(1u, sources.size());
|
| + EXPECT_EQ(1u, sources[0].source);
|
| + EXPECT_EQ(timestamp, sources[0].timestamp);
|
| +
|
| + header.ssrc = 2;
|
| + fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs);
|
| + EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + sources = rtp_receiver1_->GetContributingSources();
|
| + // Return the old SSRC since it is not out of date.
|
| + ASSERT_EQ(1u, sources.size());
|
| + EXPECT_EQ(1u, sources[0].source);
|
| + EXPECT_EQ(timestamp, sources[0].timestamp);
|
| +
|
| + fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs + 1);
|
| + EXPECT_TRUE(rtp_receiver1_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + sources = rtp_receiver1_->GetContributingSources();
|
| + // Return new SSRC and new timestamp.
|
| + ASSERT_EQ(1u, sources.size());
|
| + EXPECT_EQ(2u, sources[0].source);
|
| + EXPECT_EQ(fake_clock.TimeInMilliseconds(), sources[0].timestamp);
|
| +}
|
| +
|
| } // namespace webrtc
|
|
|