stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
Henrik Kjellander | ff761fb | 2015-11-04 08:31:52 +0100 | [diff] [blame] | 13 | #include "webrtc/modules/rtp_rtcp/include/receive_statistics.h" |
Henrik Kjellander | 98f5351 | 2015-10-28 18:17:40 +0100 | [diff] [blame] | 14 | #include "webrtc/system_wrappers/include/clock.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 15 | #include "webrtc/test/gmock.h" |
| 16 | #include "webrtc/test/gtest.h" |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 17 | |
| 18 | namespace webrtc { |
| 19 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 20 | const size_t kPacketSize1 = 100; |
| 21 | const size_t kPacketSize2 = 300; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 22 | const uint32_t kSsrc1 = 1; |
| 23 | const uint32_t kSsrc2 = 2; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 24 | |
| 25 | class ReceiveStatisticsTest : public ::testing::Test { |
| 26 | public: |
| 27 | ReceiveStatisticsTest() : |
| 28 | clock_(0), |
| 29 | receive_statistics_(ReceiveStatistics::Create(&clock_)) { |
| 30 | memset(&header1_, 0, sizeof(header1_)); |
| 31 | header1_.ssrc = kSsrc1; |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 32 | header1_.sequenceNumber = 100; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 33 | memset(&header2_, 0, sizeof(header2_)); |
| 34 | header2_.ssrc = kSsrc2; |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 35 | header2_.sequenceNumber = 100; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | protected: |
| 39 | SimulatedClock clock_; |
kwiberg | 84be511 | 2016-04-27 01:19:58 -0700 | [diff] [blame] | 40 | std::unique_ptr<ReceiveStatistics> receive_statistics_; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 41 | RTPHeader header1_; |
| 42 | RTPHeader header2_; |
| 43 | }; |
| 44 | |
| 45 | TEST_F(ReceiveStatisticsTest, TwoIncomingSsrcs) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 46 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 47 | ++header1_.sequenceNumber; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 48 | receive_statistics_->IncomingPacket(header2_, kPacketSize2, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 49 | ++header2_.sequenceNumber; |
| 50 | clock_.AdvanceTimeMilliseconds(100); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 51 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 52 | ++header1_.sequenceNumber; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 53 | receive_statistics_->IncomingPacket(header2_, kPacketSize2, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 54 | ++header2_.sequenceNumber; |
| 55 | |
| 56 | StreamStatistician* statistician = |
| 57 | receive_statistics_->GetStatistician(kSsrc1); |
| 58 | ASSERT_TRUE(statistician != NULL); |
| 59 | EXPECT_GT(statistician->BitrateReceived(), 0u); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 60 | size_t bytes_received = 0; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 61 | uint32_t packets_received = 0; |
| 62 | statistician->GetDataCounters(&bytes_received, &packets_received); |
| 63 | EXPECT_EQ(200u, bytes_received); |
| 64 | EXPECT_EQ(2u, packets_received); |
| 65 | |
| 66 | statistician = |
| 67 | receive_statistics_->GetStatistician(kSsrc2); |
| 68 | ASSERT_TRUE(statistician != NULL); |
| 69 | EXPECT_GT(statistician->BitrateReceived(), 0u); |
| 70 | statistician->GetDataCounters(&bytes_received, &packets_received); |
| 71 | EXPECT_EQ(600u, bytes_received); |
| 72 | EXPECT_EQ(2u, packets_received); |
| 73 | |
| 74 | StatisticianMap statisticians = receive_statistics_->GetActiveStatisticians(); |
| 75 | EXPECT_EQ(2u, statisticians.size()); |
| 76 | // Add more incoming packets and verify that they are registered in both |
| 77 | // access methods. |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 78 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 79 | ++header1_.sequenceNumber; |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 80 | receive_statistics_->IncomingPacket(header2_, kPacketSize2, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 81 | ++header2_.sequenceNumber; |
| 82 | |
| 83 | statisticians[kSsrc1]->GetDataCounters(&bytes_received, &packets_received); |
| 84 | EXPECT_EQ(300u, bytes_received); |
| 85 | EXPECT_EQ(3u, packets_received); |
| 86 | statisticians[kSsrc2]->GetDataCounters(&bytes_received, &packets_received); |
| 87 | EXPECT_EQ(900u, bytes_received); |
| 88 | EXPECT_EQ(3u, packets_received); |
| 89 | |
| 90 | receive_statistics_->GetStatistician(kSsrc1)->GetDataCounters( |
| 91 | &bytes_received, &packets_received); |
| 92 | EXPECT_EQ(300u, bytes_received); |
| 93 | EXPECT_EQ(3u, packets_received); |
| 94 | receive_statistics_->GetStatistician(kSsrc2)->GetDataCounters( |
| 95 | &bytes_received, &packets_received); |
| 96 | EXPECT_EQ(900u, bytes_received); |
| 97 | EXPECT_EQ(3u, packets_received); |
| 98 | } |
| 99 | |
| 100 | TEST_F(ReceiveStatisticsTest, ActiveStatisticians) { |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 101 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 102 | ++header1_.sequenceNumber; |
| 103 | clock_.AdvanceTimeMilliseconds(1000); |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 104 | receive_statistics_->IncomingPacket(header2_, kPacketSize2, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 105 | ++header2_.sequenceNumber; |
| 106 | StatisticianMap statisticians = receive_statistics_->GetActiveStatisticians(); |
| 107 | // Nothing should time out since only 1000 ms has passed since the first |
| 108 | // packet came in. |
| 109 | EXPECT_EQ(2u, statisticians.size()); |
| 110 | |
| 111 | clock_.AdvanceTimeMilliseconds(7000); |
| 112 | // kSsrc1 should have timed out. |
| 113 | statisticians = receive_statistics_->GetActiveStatisticians(); |
| 114 | EXPECT_EQ(1u, statisticians.size()); |
| 115 | |
| 116 | clock_.AdvanceTimeMilliseconds(1000); |
| 117 | // kSsrc2 should have timed out. |
| 118 | statisticians = receive_statistics_->GetActiveStatisticians(); |
| 119 | EXPECT_EQ(0u, statisticians.size()); |
| 120 | |
stefan@webrtc.org | 7bb8f02 | 2013-09-06 13:40:11 +0000 | [diff] [blame] | 121 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 122 | ++header1_.sequenceNumber; |
| 123 | // kSsrc1 should be active again and the data counters should have survived. |
| 124 | statisticians = receive_statistics_->GetActiveStatisticians(); |
| 125 | EXPECT_EQ(1u, statisticians.size()); |
| 126 | StreamStatistician* statistician = |
| 127 | receive_statistics_->GetStatistician(kSsrc1); |
| 128 | ASSERT_TRUE(statistician != NULL); |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 129 | size_t bytes_received = 0; |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 130 | uint32_t packets_received = 0; |
| 131 | statistician->GetDataCounters(&bytes_received, &packets_received); |
| 132 | EXPECT_EQ(200u, bytes_received); |
| 133 | EXPECT_EQ(2u, packets_received); |
| 134 | } |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 135 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 136 | TEST_F(ReceiveStatisticsTest, GetReceiveStreamDataCounters) { |
| 137 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 138 | StreamStatistician* statistician = |
| 139 | receive_statistics_->GetStatistician(kSsrc1); |
| 140 | ASSERT_TRUE(statistician != NULL); |
| 141 | |
| 142 | StreamDataCounters counters; |
| 143 | statistician->GetReceiveStreamDataCounters(&counters); |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 144 | EXPECT_GT(counters.first_packet_time_ms, -1); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 145 | EXPECT_EQ(1u, counters.transmitted.packets); |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 146 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 147 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 148 | statistician->GetReceiveStreamDataCounters(&counters); |
asapersson@webrtc.org | d08d389 | 2014-12-16 12:03:11 +0000 | [diff] [blame] | 149 | EXPECT_GT(counters.first_packet_time_ms, -1); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 150 | EXPECT_EQ(2u, counters.transmitted.packets); |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 151 | } |
| 152 | |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 153 | TEST_F(ReceiveStatisticsTest, RtcpCallbacks) { |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 154 | class TestCallback : public RtcpStatisticsCallback { |
| 155 | public: |
| 156 | TestCallback() |
| 157 | : RtcpStatisticsCallback(), num_calls_(0), ssrc_(0), stats_() {} |
| 158 | virtual ~TestCallback() {} |
| 159 | |
nisse | ef8b61e | 2016-04-29 06:09:15 -0700 | [diff] [blame] | 160 | void StatisticsUpdated(const RtcpStatistics& statistics, |
| 161 | uint32_t ssrc) override { |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 162 | ssrc_ = ssrc; |
| 163 | stats_ = statistics; |
| 164 | ++num_calls_; |
| 165 | } |
| 166 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 167 | void CNameChanged(const char* cname, uint32_t ssrc) override {} |
pbos@webrtc.org | ce4e9a3 | 2014-12-18 13:50:16 +0000 | [diff] [blame] | 168 | |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 169 | uint32_t num_calls_; |
| 170 | uint32_t ssrc_; |
| 171 | RtcpStatistics stats_; |
| 172 | } callback; |
| 173 | |
| 174 | receive_statistics_->RegisterRtcpStatisticsCallback(&callback); |
| 175 | |
| 176 | // Add some arbitrary data, with loss and jitter. |
| 177 | header1_.sequenceNumber = 1; |
| 178 | clock_.AdvanceTimeMilliseconds(7); |
| 179 | header1_.timestamp += 3; |
| 180 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 181 | header1_.sequenceNumber += 2; |
| 182 | clock_.AdvanceTimeMilliseconds(9); |
| 183 | header1_.timestamp += 9; |
| 184 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 185 | --header1_.sequenceNumber; |
| 186 | clock_.AdvanceTimeMilliseconds(13); |
| 187 | header1_.timestamp += 47; |
| 188 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, true); |
| 189 | header1_.sequenceNumber += 3; |
| 190 | clock_.AdvanceTimeMilliseconds(11); |
| 191 | header1_.timestamp += 17; |
| 192 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 193 | ++header1_.sequenceNumber; |
| 194 | |
| 195 | EXPECT_EQ(0u, callback.num_calls_); |
| 196 | |
| 197 | // Call GetStatistics, simulating a timed rtcp sender thread. |
| 198 | RtcpStatistics statistics; |
| 199 | receive_statistics_->GetStatistician(kSsrc1) |
| 200 | ->GetStatistics(&statistics, true); |
| 201 | |
| 202 | EXPECT_EQ(1u, callback.num_calls_); |
| 203 | EXPECT_EQ(callback.ssrc_, kSsrc1); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 204 | EXPECT_EQ(statistics.packets_lost, callback.stats_.packets_lost); |
| 205 | EXPECT_EQ(statistics.extended_highest_sequence_number, |
| 206 | callback.stats_.extended_highest_sequence_number); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 207 | EXPECT_EQ(statistics.fraction_lost, callback.stats_.fraction_lost); |
| 208 | EXPECT_EQ(statistics.jitter, callback.stats_.jitter); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 209 | EXPECT_EQ(51, statistics.fraction_lost); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 210 | EXPECT_EQ(1u, statistics.packets_lost); |
| 211 | EXPECT_EQ(5u, statistics.extended_highest_sequence_number); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 212 | EXPECT_EQ(4u, statistics.jitter); |
sprang@webrtc.org | 54ae4ff | 2013-12-19 13:26:02 +0000 | [diff] [blame] | 213 | |
| 214 | receive_statistics_->RegisterRtcpStatisticsCallback(NULL); |
| 215 | |
| 216 | // Add some more data. |
| 217 | header1_.sequenceNumber = 1; |
| 218 | clock_.AdvanceTimeMilliseconds(7); |
| 219 | header1_.timestamp += 3; |
| 220 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 221 | header1_.sequenceNumber += 2; |
| 222 | clock_.AdvanceTimeMilliseconds(9); |
| 223 | header1_.timestamp += 9; |
| 224 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 225 | --header1_.sequenceNumber; |
| 226 | clock_.AdvanceTimeMilliseconds(13); |
| 227 | header1_.timestamp += 47; |
| 228 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, true); |
| 229 | header1_.sequenceNumber += 3; |
| 230 | clock_.AdvanceTimeMilliseconds(11); |
| 231 | header1_.timestamp += 17; |
| 232 | receive_statistics_->IncomingPacket(header1_, kPacketSize1, false); |
| 233 | ++header1_.sequenceNumber; |
| 234 | |
| 235 | receive_statistics_->GetStatistician(kSsrc1) |
| 236 | ->GetStatistics(&statistics, true); |
| 237 | |
| 238 | // Should not have been called after deregister. |
| 239 | EXPECT_EQ(1u, callback.num_calls_); |
| 240 | } |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 241 | |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 242 | class RtpTestCallback : public StreamDataCountersCallback { |
| 243 | public: |
| 244 | RtpTestCallback() |
| 245 | : StreamDataCountersCallback(), num_calls_(0), ssrc_(0), stats_() {} |
| 246 | virtual ~RtpTestCallback() {} |
| 247 | |
| 248 | virtual void DataCountersUpdated(const StreamDataCounters& counters, |
| 249 | uint32_t ssrc) { |
| 250 | ssrc_ = ssrc; |
| 251 | stats_ = counters; |
| 252 | ++num_calls_; |
| 253 | } |
| 254 | |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 +0000 | [diff] [blame] | 255 | void MatchPacketCounter(const RtpPacketCounter& expected, |
| 256 | const RtpPacketCounter& actual) { |
| 257 | EXPECT_EQ(expected.payload_bytes, actual.payload_bytes); |
| 258 | EXPECT_EQ(expected.header_bytes, actual.header_bytes); |
| 259 | EXPECT_EQ(expected.padding_bytes, actual.padding_bytes); |
| 260 | EXPECT_EQ(expected.packets, actual.packets); |
| 261 | } |
| 262 | |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 263 | void Matches(uint32_t num_calls, |
| 264 | uint32_t ssrc, |
| 265 | const StreamDataCounters& expected) { |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 266 | EXPECT_EQ(num_calls, num_calls_); |
| 267 | EXPECT_EQ(ssrc, ssrc_); |
asapersson@webrtc.org | 4414939 | 2015-02-04 08:34:47 +0000 | [diff] [blame] | 268 | MatchPacketCounter(expected.transmitted, stats_.transmitted); |
| 269 | MatchPacketCounter(expected.retransmitted, stats_.retransmitted); |
| 270 | MatchPacketCounter(expected.fec, stats_.fec); |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | uint32_t num_calls_; |
| 274 | uint32_t ssrc_; |
| 275 | StreamDataCounters stats_; |
| 276 | }; |
| 277 | |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 278 | TEST_F(ReceiveStatisticsTest, RtpCallbacks) { |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 279 | RtpTestCallback callback; |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 280 | receive_statistics_->RegisterRtpStatisticsCallback(&callback); |
| 281 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 282 | const size_t kHeaderLength = 20; |
| 283 | const size_t kPaddingLength = 9; |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 284 | |
| 285 | // One packet of size kPacketSize1. |
| 286 | header1_.headerLength = kHeaderLength; |
| 287 | receive_statistics_->IncomingPacket( |
| 288 | header1_, kPacketSize1 + kHeaderLength, false); |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 289 | StreamDataCounters expected; |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 290 | expected.transmitted.payload_bytes = kPacketSize1; |
| 291 | expected.transmitted.header_bytes = kHeaderLength; |
| 292 | expected.transmitted.padding_bytes = 0; |
| 293 | expected.transmitted.packets = 1; |
| 294 | expected.retransmitted.payload_bytes = 0; |
| 295 | expected.retransmitted.header_bytes = 0; |
| 296 | expected.retransmitted.padding_bytes = 0; |
| 297 | expected.retransmitted.packets = 0; |
| 298 | expected.fec.packets = 0; |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 299 | callback.Matches(1, kSsrc1, expected); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 300 | |
| 301 | ++header1_.sequenceNumber; |
| 302 | clock_.AdvanceTimeMilliseconds(5); |
| 303 | header1_.paddingLength = 9; |
| 304 | // Another packet of size kPacketSize1 with 9 bytes padding. |
| 305 | receive_statistics_->IncomingPacket( |
| 306 | header1_, kPacketSize1 + kHeaderLength + kPaddingLength, false); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 307 | expected.transmitted.payload_bytes = kPacketSize1 * 2; |
| 308 | expected.transmitted.header_bytes = kHeaderLength * 2; |
| 309 | expected.transmitted.padding_bytes = kPaddingLength; |
| 310 | expected.transmitted.packets = 2; |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 311 | callback.Matches(2, kSsrc1, expected); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 312 | |
| 313 | clock_.AdvanceTimeMilliseconds(5); |
| 314 | // Retransmit last packet. |
| 315 | receive_statistics_->IncomingPacket( |
| 316 | header1_, kPacketSize1 + kHeaderLength + kPaddingLength, true); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 317 | expected.transmitted.payload_bytes = kPacketSize1 * 3; |
| 318 | expected.transmitted.header_bytes = kHeaderLength * 3; |
| 319 | expected.transmitted.padding_bytes = kPaddingLength * 2; |
| 320 | expected.transmitted.packets = 3; |
| 321 | expected.retransmitted.payload_bytes = kPacketSize1; |
| 322 | expected.retransmitted.header_bytes = kHeaderLength; |
| 323 | expected.retransmitted.padding_bytes = kPaddingLength; |
| 324 | expected.retransmitted.packets = 1; |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 325 | callback.Matches(3, kSsrc1, expected); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 326 | |
| 327 | header1_.paddingLength = 0; |
| 328 | ++header1_.sequenceNumber; |
| 329 | clock_.AdvanceTimeMilliseconds(5); |
asapersson@webrtc.org | 273fbbb | 2015-01-27 12:17:29 +0000 | [diff] [blame] | 330 | // One FEC packet. |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 331 | receive_statistics_->IncomingPacket( |
| 332 | header1_, kPacketSize1 + kHeaderLength, false); |
asapersson@webrtc.org | 273fbbb | 2015-01-27 12:17:29 +0000 | [diff] [blame] | 333 | receive_statistics_->FecPacketReceived(header1_, |
| 334 | kPacketSize1 + kHeaderLength); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 335 | expected.transmitted.payload_bytes = kPacketSize1 * 4; |
| 336 | expected.transmitted.header_bytes = kHeaderLength * 4; |
| 337 | expected.transmitted.packets = 4; |
asapersson@webrtc.org | 273fbbb | 2015-01-27 12:17:29 +0000 | [diff] [blame] | 338 | expected.fec.payload_bytes = kPacketSize1; |
| 339 | expected.fec.header_bytes = kHeaderLength; |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 340 | expected.fec.packets = 1; |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 341 | callback.Matches(5, kSsrc1, expected); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 342 | |
| 343 | receive_statistics_->RegisterRtpStatisticsCallback(NULL); |
| 344 | |
| 345 | // New stats, but callback should not be called. |
| 346 | ++header1_.sequenceNumber; |
| 347 | clock_.AdvanceTimeMilliseconds(5); |
| 348 | receive_statistics_->IncomingPacket( |
| 349 | header1_, kPacketSize1 + kHeaderLength, true); |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 350 | callback.Matches(5, kSsrc1, expected); |
sprang@webrtc.org | 0e93257 | 2014-01-23 10:00:39 +0000 | [diff] [blame] | 351 | } |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 352 | |
| 353 | TEST_F(ReceiveStatisticsTest, RtpCallbacksFecFirst) { |
| 354 | RtpTestCallback callback; |
| 355 | receive_statistics_->RegisterRtpStatisticsCallback(&callback); |
| 356 | |
| 357 | const uint32_t kHeaderLength = 20; |
asapersson@webrtc.org | 273fbbb | 2015-01-27 12:17:29 +0000 | [diff] [blame] | 358 | header1_.headerLength = kHeaderLength; |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 359 | |
| 360 | // If first packet is FEC, ignore it. |
asapersson@webrtc.org | 273fbbb | 2015-01-27 12:17:29 +0000 | [diff] [blame] | 361 | receive_statistics_->FecPacketReceived(header1_, |
| 362 | kPacketSize1 + kHeaderLength); |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 363 | EXPECT_EQ(0u, callback.num_calls_); |
| 364 | |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 365 | receive_statistics_->IncomingPacket( |
| 366 | header1_, kPacketSize1 + kHeaderLength, false); |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 367 | StreamDataCounters expected; |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 368 | expected.transmitted.payload_bytes = kPacketSize1; |
| 369 | expected.transmitted.header_bytes = kHeaderLength; |
| 370 | expected.transmitted.padding_bytes = 0; |
| 371 | expected.transmitted.packets = 1; |
| 372 | expected.fec.packets = 0; |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 373 | callback.Matches(1, kSsrc1, expected); |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 374 | |
asapersson@webrtc.org | 273fbbb | 2015-01-27 12:17:29 +0000 | [diff] [blame] | 375 | receive_statistics_->FecPacketReceived(header1_, |
| 376 | kPacketSize1 + kHeaderLength); |
| 377 | expected.fec.payload_bytes = kPacketSize1; |
| 378 | expected.fec.header_bytes = kHeaderLength; |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 379 | expected.fec.packets = 1; |
asapersson@webrtc.org | 97d0489 | 2014-12-09 09:47:53 +0000 | [diff] [blame] | 380 | callback.Matches(2, kSsrc1, expected); |
sprang@webrtc.org | c30e9e2 | 2014-09-08 08:20:18 +0000 | [diff] [blame] | 381 | } |
stefan@webrtc.org | 286fe0b | 2013-08-21 20:58:21 +0000 | [diff] [blame] | 382 | } // namespace webrtc |