hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <memory> |
| 12 | |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame] | 13 | #include "common_types.h" // NOLINT(build/include) |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 14 | #include "modules/rtp_rtcp/include/rtp_header_parser.h" |
| 15 | #include "modules/rtp_rtcp/include/rtp_payload_registry.h" |
| 16 | #include "modules/rtp_rtcp/include/rtp_receiver.h" |
| 17 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 18 | #include "modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
| 19 | #include "modules/rtp_rtcp/source/rtp_receiver_impl.h" |
| 20 | #include "test/gmock.h" |
| 21 | #include "test/gtest.h" |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 24 | namespace { |
| 25 | |
nisse | 7fcdb6d | 2017-06-01 00:30:55 -0700 | [diff] [blame] | 26 | using ::testing::NiceMock; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 27 | using ::testing::UnorderedElementsAre; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 28 | |
| 29 | const uint32_t kTestRate = 64000u; |
| 30 | const uint8_t kTestPayload[] = {'t', 'e', 's', 't'}; |
| 31 | const uint8_t kPcmuPayloadType = 96; |
| 32 | const int64_t kGetSourcesTimeoutMs = 10000; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 33 | const uint32_t kSsrc1 = 123; |
| 34 | const uint32_t kSsrc2 = 124; |
| 35 | const uint32_t kCsrc1 = 111; |
| 36 | const uint32_t kCsrc2 = 222; |
| 37 | const bool kInOrder = true; |
| 38 | |
| 39 | static uint32_t rtp_timestamp(int64_t time_ms) { |
| 40 | return static_cast<uint32_t>(time_ms * kTestRate / 1000); |
| 41 | } |
| 42 | |
| 43 | } // namespace |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 44 | |
| 45 | class RtpReceiverTest : public ::testing::Test { |
| 46 | protected: |
| 47 | RtpReceiverTest() |
| 48 | : fake_clock_(123456), |
| 49 | rtp_receiver_( |
| 50 | RtpReceiver::CreateAudioReceiver(&fake_clock_, |
nisse | 7fcdb6d | 2017-06-01 00:30:55 -0700 | [diff] [blame] | 51 | &mock_rtp_data_, |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 52 | nullptr, |
| 53 | &rtp_payload_registry_)) { |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 54 | rtp_receiver_->RegisterReceivePayload(kPcmuPayloadType, |
| 55 | SdpAudioFormat("PCMU", 8000, 1)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 56 | } |
| 57 | ~RtpReceiverTest() {} |
| 58 | |
| 59 | bool FindSourceByIdAndType(const std::vector<RtpSource>& sources, |
| 60 | uint32_t source_id, |
| 61 | RtpSourceType type, |
| 62 | RtpSource* source) { |
| 63 | for (size_t i = 0; i < sources.size(); ++i) { |
| 64 | if (sources[i].source_id() == source_id && |
| 65 | sources[i].source_type() == type) { |
| 66 | (*source) = sources[i]; |
| 67 | return true; |
| 68 | } |
| 69 | } |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | SimulatedClock fake_clock_; |
nisse | 7fcdb6d | 2017-06-01 00:30:55 -0700 | [diff] [blame] | 74 | NiceMock<MockRtpData> mock_rtp_data_; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 75 | RTPPayloadRegistry rtp_payload_registry_; |
| 76 | std::unique_ptr<RtpReceiver> rtp_receiver_; |
| 77 | }; |
| 78 | |
| 79 | TEST_F(RtpReceiverTest, GetSources) { |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 80 | int64_t now_ms = fake_clock_.TimeInMilliseconds(); |
| 81 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 82 | RTPHeader header; |
| 83 | header.payloadType = kPcmuPayloadType; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 84 | header.ssrc = kSsrc1; |
| 85 | header.timestamp = rtp_timestamp(now_ms); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 86 | header.numCSRCs = 2; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 87 | header.arrOfCSRCs[0] = kCsrc1; |
| 88 | header.arrOfCSRCs[1] = kCsrc2; |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 89 | const PayloadUnion payload_specific{ |
| 90 | AudioPayload{SdpAudioFormat("foo", 8000, 1), 0}}; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 91 | |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 92 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 93 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 94 | auto sources = rtp_receiver_->GetSources(); |
| 95 | // One SSRC source and two CSRC sources. |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 96 | EXPECT_THAT(sources, UnorderedElementsAre( |
| 97 | RtpSource(now_ms, kSsrc1, RtpSourceType::SSRC), |
| 98 | RtpSource(now_ms, kCsrc1, RtpSourceType::CSRC), |
| 99 | RtpSource(now_ms, kCsrc2, RtpSourceType::CSRC))); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 100 | |
| 101 | // Advance the fake clock and the method is expected to return the |
| 102 | // contributing source object with same source id and updated timestamp. |
| 103 | fake_clock_.AdvanceTimeMilliseconds(1); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 104 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 105 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 106 | sources = rtp_receiver_->GetSources(); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 107 | now_ms = fake_clock_.TimeInMilliseconds(); |
| 108 | EXPECT_THAT(sources, UnorderedElementsAre( |
| 109 | RtpSource(now_ms, kSsrc1, RtpSourceType::SSRC), |
| 110 | RtpSource(now_ms, kCsrc1, RtpSourceType::CSRC), |
| 111 | RtpSource(now_ms, kCsrc2, RtpSourceType::CSRC))); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 112 | |
| 113 | // Test the edge case that the sources are still there just before the |
| 114 | // timeout. |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 115 | int64_t prev_time_ms = fake_clock_.TimeInMilliseconds(); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 116 | fake_clock_.AdvanceTimeMilliseconds(kGetSourcesTimeoutMs); |
| 117 | sources = rtp_receiver_->GetSources(); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 118 | EXPECT_THAT(sources, |
| 119 | UnorderedElementsAre( |
| 120 | RtpSource(prev_time_ms, kSsrc1, RtpSourceType::SSRC), |
| 121 | RtpSource(prev_time_ms, kCsrc1, RtpSourceType::CSRC), |
| 122 | RtpSource(prev_time_ms, kCsrc2, RtpSourceType::CSRC))); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 123 | |
| 124 | // Time out. |
| 125 | fake_clock_.AdvanceTimeMilliseconds(1); |
| 126 | sources = rtp_receiver_->GetSources(); |
| 127 | // All the sources should be out of date. |
| 128 | ASSERT_EQ(0u, sources.size()); |
| 129 | } |
| 130 | |
| 131 | // Test the case that the SSRC is changed. |
| 132 | TEST_F(RtpReceiverTest, GetSourcesChangeSSRC) { |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 133 | int64_t prev_time_ms = -1; |
| 134 | int64_t now_ms = fake_clock_.TimeInMilliseconds(); |
| 135 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 136 | RTPHeader header; |
| 137 | header.payloadType = kPcmuPayloadType; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 138 | header.ssrc = kSsrc1; |
| 139 | header.timestamp = rtp_timestamp(now_ms); |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 140 | const PayloadUnion payload_specific{ |
| 141 | AudioPayload{SdpAudioFormat("foo", 8000, 1), 0}}; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 142 | |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 143 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 144 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 145 | auto sources = rtp_receiver_->GetSources(); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 146 | EXPECT_THAT(sources, UnorderedElementsAre( |
| 147 | RtpSource(now_ms, kSsrc1, RtpSourceType::SSRC))); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 148 | |
| 149 | // The SSRC is changed and the old SSRC is expected to be returned. |
| 150 | fake_clock_.AdvanceTimeMilliseconds(100); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 151 | prev_time_ms = now_ms; |
| 152 | now_ms = fake_clock_.TimeInMilliseconds(); |
| 153 | header.ssrc = kSsrc2; |
| 154 | header.timestamp = rtp_timestamp(now_ms); |
| 155 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 156 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 157 | sources = rtp_receiver_->GetSources(); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 158 | EXPECT_THAT(sources, UnorderedElementsAre( |
| 159 | RtpSource(prev_time_ms, kSsrc1, RtpSourceType::SSRC), |
| 160 | RtpSource(now_ms, kSsrc2, RtpSourceType::SSRC))); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 161 | |
| 162 | // The SSRC is changed again and happen to be changed back to 1. No |
| 163 | // duplication is expected. |
| 164 | fake_clock_.AdvanceTimeMilliseconds(100); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 165 | header.ssrc = kSsrc1; |
| 166 | header.timestamp = rtp_timestamp(now_ms); |
| 167 | prev_time_ms = now_ms; |
| 168 | now_ms = fake_clock_.TimeInMilliseconds(); |
| 169 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 170 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 171 | sources = rtp_receiver_->GetSources(); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 172 | EXPECT_THAT(sources, UnorderedElementsAre( |
| 173 | RtpSource(prev_time_ms, kSsrc2, RtpSourceType::SSRC), |
| 174 | RtpSource(now_ms, kSsrc1, RtpSourceType::SSRC))); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 175 | |
| 176 | // Old SSRC source timeout. |
| 177 | fake_clock_.AdvanceTimeMilliseconds(kGetSourcesTimeoutMs); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 178 | now_ms = fake_clock_.TimeInMilliseconds(); |
| 179 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 180 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 181 | sources = rtp_receiver_->GetSources(); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 182 | EXPECT_THAT(sources, UnorderedElementsAre( |
| 183 | RtpSource(now_ms, kSsrc1, RtpSourceType::SSRC))); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | TEST_F(RtpReceiverTest, GetSourcesRemoveOutdatedSource) { |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 187 | int64_t now_ms = fake_clock_.TimeInMilliseconds(); |
| 188 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 189 | RTPHeader header; |
| 190 | header.payloadType = kPcmuPayloadType; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 191 | header.timestamp = rtp_timestamp(now_ms); |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 192 | const PayloadUnion payload_specific{ |
| 193 | AudioPayload{SdpAudioFormat("foo", 8000, 1), 0}}; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 194 | header.numCSRCs = 1; |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 195 | size_t kSourceListSize = 20; |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 196 | |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 197 | for (size_t i = 0; i < kSourceListSize; ++i) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 198 | header.ssrc = i; |
| 199 | header.arrOfCSRCs[0] = (i + 1); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 200 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket(header, kTestPayload, |
| 201 | sizeof(kTestPayload), |
| 202 | payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 203 | } |
| 204 | |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 205 | RtpSource source(0, 0, RtpSourceType::SSRC); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 206 | auto sources = rtp_receiver_->GetSources(); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 207 | // Expect |kSourceListSize| SSRC sources and |kSourceListSize| CSRC sources. |
| 208 | ASSERT_EQ(2 * kSourceListSize, sources.size()); |
| 209 | for (size_t i = 0; i < kSourceListSize; ++i) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 210 | // The SSRC source IDs are expected to be 19, 18, 17 ... 0 |
| 211 | ASSERT_TRUE( |
| 212 | FindSourceByIdAndType(sources, i, RtpSourceType::SSRC, &source)); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 213 | EXPECT_EQ(now_ms, source.timestamp_ms()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 214 | |
| 215 | // The CSRC source IDs are expected to be 20, 19, 18 ... 1 |
| 216 | ASSERT_TRUE( |
| 217 | FindSourceByIdAndType(sources, (i + 1), RtpSourceType::CSRC, &source)); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 218 | EXPECT_EQ(now_ms, source.timestamp_ms()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | fake_clock_.AdvanceTimeMilliseconds(kGetSourcesTimeoutMs); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 222 | for (size_t i = 0; i < kSourceListSize; ++i) { |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 223 | // The SSRC source IDs are expected to be 19, 18, 17 ... 0 |
| 224 | ASSERT_TRUE( |
| 225 | FindSourceByIdAndType(sources, i, RtpSourceType::SSRC, &source)); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 226 | EXPECT_EQ(now_ms, source.timestamp_ms()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 227 | |
| 228 | // The CSRC source IDs are expected to be 20, 19, 18 ... 1 |
| 229 | ASSERT_TRUE( |
| 230 | FindSourceByIdAndType(sources, (i + 1), RtpSourceType::CSRC, &source)); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 231 | EXPECT_EQ(now_ms, source.timestamp_ms()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | // Timeout. All the existing objects are out of date and are expected to be |
| 235 | // removed. |
| 236 | fake_clock_.AdvanceTimeMilliseconds(1); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 237 | header.ssrc = kSsrc1; |
| 238 | header.arrOfCSRCs[0] = kCsrc1; |
| 239 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 240 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 241 | auto rtp_receiver_impl = static_cast<RtpReceiverImpl*>(rtp_receiver_.get()); |
| 242 | auto ssrc_sources = rtp_receiver_impl->ssrc_sources_for_testing(); |
| 243 | ASSERT_EQ(1u, ssrc_sources.size()); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 244 | EXPECT_EQ(kSsrc1, ssrc_sources.begin()->source_id()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 245 | EXPECT_EQ(RtpSourceType::SSRC, ssrc_sources.begin()->source_type()); |
| 246 | EXPECT_EQ(fake_clock_.TimeInMilliseconds(), |
| 247 | ssrc_sources.begin()->timestamp_ms()); |
| 248 | |
| 249 | auto csrc_sources = rtp_receiver_impl->csrc_sources_for_testing(); |
| 250 | ASSERT_EQ(1u, csrc_sources.size()); |
zhihuang | 0426222 | 2017-04-11 11:28:10 -0700 | [diff] [blame] | 251 | EXPECT_EQ(kCsrc1, csrc_sources.begin()->source_id()); |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 252 | EXPECT_EQ(RtpSourceType::CSRC, csrc_sources.begin()->source_type()); |
| 253 | EXPECT_EQ(fake_clock_.TimeInMilliseconds(), |
| 254 | csrc_sources.begin()->timestamp_ms()); |
| 255 | } |
| 256 | |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 257 | // The audio level from the RTPHeader extension should be stored in the |
| 258 | // RtpSource with the matching SSRC. |
| 259 | TEST_F(RtpReceiverTest, GetSourcesContainsAudioLevelExtension) { |
| 260 | RTPHeader header; |
| 261 | int64_t time1_ms = fake_clock_.TimeInMilliseconds(); |
| 262 | header.payloadType = kPcmuPayloadType; |
| 263 | header.ssrc = kSsrc1; |
| 264 | header.timestamp = rtp_timestamp(time1_ms); |
| 265 | header.extension.hasAudioLevel = true; |
| 266 | header.extension.audioLevel = 10; |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 267 | const PayloadUnion payload_specific{ |
| 268 | AudioPayload{SdpAudioFormat("foo", 8000, 1), 0}}; |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 269 | |
| 270 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 271 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
| 272 | auto sources = rtp_receiver_->GetSources(); |
| 273 | EXPECT_THAT(sources, UnorderedElementsAre(RtpSource( |
| 274 | time1_ms, kSsrc1, RtpSourceType::SSRC, 10))); |
| 275 | |
| 276 | // Receive a packet from a different SSRC with a different level and check |
| 277 | // that they are both remembered. |
| 278 | fake_clock_.AdvanceTimeMilliseconds(1); |
| 279 | int64_t time2_ms = fake_clock_.TimeInMilliseconds(); |
| 280 | header.ssrc = kSsrc2; |
| 281 | header.timestamp = rtp_timestamp(time2_ms); |
| 282 | header.extension.hasAudioLevel = true; |
| 283 | header.extension.audioLevel = 20; |
| 284 | |
| 285 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 286 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
| 287 | sources = rtp_receiver_->GetSources(); |
| 288 | EXPECT_THAT(sources, |
| 289 | UnorderedElementsAre( |
| 290 | RtpSource(time1_ms, kSsrc1, RtpSourceType::SSRC, 10), |
| 291 | RtpSource(time2_ms, kSsrc2, RtpSourceType::SSRC, 20))); |
| 292 | |
| 293 | // Receive a packet from the first SSRC again and check that the level is |
| 294 | // updated. |
| 295 | fake_clock_.AdvanceTimeMilliseconds(1); |
| 296 | int64_t time3_ms = fake_clock_.TimeInMilliseconds(); |
| 297 | header.ssrc = kSsrc1; |
| 298 | header.timestamp = rtp_timestamp(time3_ms); |
| 299 | header.extension.hasAudioLevel = true; |
| 300 | header.extension.audioLevel = 30; |
| 301 | |
| 302 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 303 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
| 304 | sources = rtp_receiver_->GetSources(); |
| 305 | EXPECT_THAT(sources, |
| 306 | UnorderedElementsAre( |
| 307 | RtpSource(time3_ms, kSsrc1, RtpSourceType::SSRC, 30), |
| 308 | RtpSource(time2_ms, kSsrc2, RtpSourceType::SSRC, 20))); |
| 309 | } |
| 310 | |
| 311 | TEST_F(RtpReceiverTest, |
| 312 | MissingAudioLevelHeaderExtensionClearsRtpSourceAudioLevel) { |
| 313 | RTPHeader header; |
| 314 | int64_t time1_ms = fake_clock_.TimeInMilliseconds(); |
| 315 | header.payloadType = kPcmuPayloadType; |
| 316 | header.ssrc = kSsrc1; |
| 317 | header.timestamp = rtp_timestamp(time1_ms); |
| 318 | header.extension.hasAudioLevel = true; |
| 319 | header.extension.audioLevel = 10; |
Karl Wiberg | c62f6c7 | 2017-10-04 12:38:53 +0200 | [diff] [blame] | 320 | const PayloadUnion payload_specific{ |
| 321 | AudioPayload{SdpAudioFormat("foo", 8000, 1), 0}}; |
zstein | 2b70634 | 2017-08-24 14:52:17 -0700 | [diff] [blame] | 322 | |
| 323 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 324 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
| 325 | auto sources = rtp_receiver_->GetSources(); |
| 326 | EXPECT_THAT(sources, UnorderedElementsAre(RtpSource( |
| 327 | time1_ms, kSsrc1, RtpSourceType::SSRC, 10))); |
| 328 | |
| 329 | // Receive a second packet without the audio level header extension and check |
| 330 | // that the audio level is cleared. |
| 331 | fake_clock_.AdvanceTimeMilliseconds(1); |
| 332 | int64_t time2_ms = fake_clock_.TimeInMilliseconds(); |
| 333 | header.timestamp = rtp_timestamp(time2_ms); |
| 334 | header.extension.hasAudioLevel = false; |
| 335 | |
| 336 | EXPECT_TRUE(rtp_receiver_->IncomingRtpPacket( |
| 337 | header, kTestPayload, sizeof(kTestPayload), payload_specific, !kInOrder)); |
| 338 | sources = rtp_receiver_->GetSources(); |
| 339 | EXPECT_THAT(sources, UnorderedElementsAre( |
| 340 | RtpSource(time2_ms, kSsrc1, RtpSourceType::SSRC))); |
| 341 | } |
| 342 | |
hbos | 8d609f6 | 2017-04-10 07:39:05 -0700 | [diff] [blame] | 343 | } // namespace webrtc |