| Index: webrtc/modules/rtp_rtcp/source/rtp_receiver_unittest.cc
|
| diff --git a/webrtc/modules/rtp_rtcp/source/rtp_receiver_unittest.cc b/webrtc/modules/rtp_rtcp/source/rtp_receiver_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..1a7bd4697bc7607435be74f88abe1adcc1b51341
|
| --- /dev/null
|
| +++ b/webrtc/modules/rtp_rtcp/source/rtp_receiver_unittest.cc
|
| @@ -0,0 +1,158 @@
|
| +/*
|
| + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
|
| + *
|
| + * Use of this source code is governed by a BSD-style license
|
| + * that can be found in the LICENSE file in the root of the source
|
| + * tree. An additional intellectual property rights grant can be found
|
| + * in the file PATENTS. All contributing project authors may
|
| + * be found in the AUTHORS file in the root of the source tree.
|
| + */
|
| +
|
| +#include <memory>
|
| +
|
| +#include "webrtc/common_types.h"
|
| +#include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h"
|
| +#include "webrtc/modules/rtp_rtcp/include/rtp_payload_registry.h"
|
| +#include "webrtc/modules/rtp_rtcp/include/rtp_receiver.h"
|
| +#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
| +#include "webrtc/test/gtest.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +const int64_t kContributingSourcesTimeoutMs = 10000;
|
| +const uint32_t kTestRate = 64000u;
|
| +const uint8_t kTestPayload[] = {'t', 'e', 's', 't'};
|
| +const uint8_t kPcmuPayloadType = 96;
|
| +
|
| +class RtpReceiverTest : public ::testing::Test {
|
| + protected:
|
| + RtpReceiverTest() : fake_clock(123456) {}
|
| + ~RtpReceiverTest() {}
|
| +
|
| + void SetUp() override {
|
| + rtp_payload_registry_.reset(new RTPPayloadRegistry());
|
| +
|
| + rtp_receiver_.reset(RtpReceiver::CreateAudioReceiver(
|
| + &fake_clock, nullptr, nullptr, rtp_payload_registry_.get()));
|
| +
|
| + CodecInst voice_codec = {};
|
| + voice_codec.pltype = kPcmuPayloadType;
|
| + voice_codec.plfreq = 8000;
|
| + voice_codec.rate = kTestRate;
|
| + memcpy(voice_codec.plname, "PCMU", 5);
|
| + rtp_receiver_->RegisterReceivePayload(voice_codec);
|
| + }
|
| +
|
| + std::unique_ptr<RTPPayloadRegistry> rtp_payload_registry_;
|
| + std::unique_ptr<RtpReceiver> rtp_receiver_;
|
| + SimulatedClock fake_clock;
|
| +};
|
| +
|
| +TEST_F(RtpReceiverTest, 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;
|
| + PayloadUnion payload_specific;
|
| + bool in_order = false;
|
| +
|
| + EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + auto sources = rtp_receiver_->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].ssrc());
|
| + 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_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + sources = rtp_receiver_->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].ssrc());
|
| + EXPECT_EQ(1u, sources[2].source());
|
| + EXPECT_EQ(timestamp + 1, sources[2].timestamp());
|
| +
|
| + // Simulate the time out.
|
| + fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs + 1);
|
| + sources = rtp_receiver_->GetContributingSources();
|
| + // All the sources should be out of date.
|
| + ASSERT_EQ(0u, sources.size());
|
| +}
|
| +
|
| +// Test the cases that the SSRC is changed.
|
| +TEST_F(RtpReceiverTest, GetContributingSourcesChangeSSRC) {
|
| + int64_t prev_time = -1;
|
| + int64_t cur_time = fake_clock.TimeInMilliseconds();
|
| + RTPHeader header;
|
| + header.payloadType = kPcmuPayloadType;
|
| + header.ssrc = 1;
|
| + header.timestamp = cur_time;
|
| + PayloadUnion payload_specific;
|
| + bool in_order = false;
|
| +
|
| + EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + auto sources = rtp_receiver_->GetContributingSources();
|
| + ASSERT_EQ(1u, sources.size());
|
| + EXPECT_EQ(1u, sources[0].source());
|
| + EXPECT_EQ(cur_time, sources[0].timestamp());
|
| +
|
| + // The SSRC is changed and the old SSRC is expected to be returned.
|
| + fake_clock.AdvanceTimeMilliseconds(100);
|
| + prev_time = cur_time;
|
| + cur_time = fake_clock.TimeInMilliseconds();
|
| + header.ssrc = 2;
|
| + header.timestamp = cur_time;
|
| + EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + sources = rtp_receiver_->GetContributingSources();
|
| + ASSERT_EQ(2u, sources.size());
|
| + EXPECT_EQ(2u, sources[0].source());
|
| + EXPECT_EQ(cur_time, sources[0].timestamp());
|
| + EXPECT_EQ(1u, sources[1].source());
|
| + EXPECT_EQ(prev_time, sources[1].timestamp());
|
| +
|
| + // The SSRC is changed again and happen to be changed back to 1. No
|
| + // duplication is expected.
|
| + fake_clock.AdvanceTimeMilliseconds(100);
|
| + header.ssrc = 1;
|
| + header.timestamp = cur_time;
|
| + prev_time = cur_time;
|
| + cur_time = fake_clock.TimeInMilliseconds();
|
| + EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + sources = rtp_receiver_->GetContributingSources();
|
| + ASSERT_EQ(2u, sources.size());
|
| + EXPECT_EQ(1u, sources[0].source());
|
| + EXPECT_EQ(cur_time, sources[0].timestamp());
|
| + EXPECT_EQ(2u, sources[1].source());
|
| + EXPECT_EQ(prev_time, sources[1].timestamp());
|
| +
|
| + // Old SSRC source timeout.
|
| + fake_clock.AdvanceTimeMilliseconds(kContributingSourcesTimeoutMs);
|
| + cur_time = fake_clock.TimeInMilliseconds();
|
| + EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, 4,
|
| + payload_specific, in_order));
|
| + sources = rtp_receiver_->GetContributingSources();
|
| + ASSERT_EQ(1u, sources.size());
|
| + EXPECT_EQ(1u, sources[0].source());
|
| + EXPECT_EQ(cur_time, sources[0].timestamp());
|
| +}
|
| +
|
| +} // namespace webrtc
|
|
|