2015-01-08 07:50:56 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "video/report_block_stats.h"
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/gtest.h"
|
2015-01-08 07:50:56 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2021-05-18 12:48:12 +02:00
|
|
|
namespace {
|
2015-01-08 07:50:56 +00:00
|
|
|
|
2021-05-18 12:48:12 +02:00
|
|
|
constexpr uint32_t kSsrc1 = 123;
|
|
|
|
|
constexpr uint32_t kSsrc2 = 234;
|
2015-01-08 07:50:56 +00:00
|
|
|
|
2021-05-18 12:48:12 +02:00
|
|
|
TEST(ReportBlockStatsTest, StoreAndGetFractionLost) {
|
2015-01-08 07:50:56 +00:00
|
|
|
ReportBlockStats stats;
|
2015-01-21 09:00:19 +00:00
|
|
|
EXPECT_EQ(-1, stats.FractionLostInPercent());
|
2015-01-08 07:50:56 +00:00
|
|
|
|
2019-08-01 17:38:01 +02:00
|
|
|
// First report.
|
2021-05-18 12:48:12 +02:00
|
|
|
stats.Store(kSsrc1, /*packets_lost=*/10,
|
|
|
|
|
/*extended_highest_sequence_number=*/24'000);
|
2015-01-21 09:00:19 +00:00
|
|
|
EXPECT_EQ(-1, stats.FractionLostInPercent());
|
2015-01-08 07:50:56 +00:00
|
|
|
// fl: 100 * (15-10) / (24100-24000) = 5%
|
2021-05-18 12:48:12 +02:00
|
|
|
stats.Store(kSsrc1, /*packets_lost=*/15,
|
|
|
|
|
/*extended_highest_sequence_number=*/24'100);
|
2015-01-08 07:50:56 +00:00
|
|
|
EXPECT_EQ(5, stats.FractionLostInPercent());
|
|
|
|
|
// fl: 100 * (50-10) / (24200-24000) = 20%
|
2021-05-18 12:48:12 +02:00
|
|
|
stats.Store(kSsrc1, /*packets_lost=*/50,
|
|
|
|
|
/*extended_highest_sequence_number=*/24'200);
|
2015-01-08 07:50:56 +00:00
|
|
|
EXPECT_EQ(20, stats.FractionLostInPercent());
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-18 12:48:12 +02:00
|
|
|
TEST(ReportBlockStatsTest, StoreAndGetFractionLost_TwoSsrcs) {
|
2019-08-01 17:38:01 +02:00
|
|
|
ReportBlockStats stats;
|
|
|
|
|
EXPECT_EQ(-1, stats.FractionLostInPercent());
|
|
|
|
|
|
|
|
|
|
// First report.
|
2021-05-18 12:48:12 +02:00
|
|
|
stats.Store(kSsrc1, /*packets_lost=*/10,
|
|
|
|
|
/*extended_highest_sequence_number=*/24'000);
|
2019-08-01 17:38:01 +02:00
|
|
|
EXPECT_EQ(-1, stats.FractionLostInPercent());
|
|
|
|
|
// fl: 100 * (15-10) / (24100-24000) = 5%
|
2021-05-18 12:48:12 +02:00
|
|
|
stats.Store(kSsrc1, /*packets_lost=*/15,
|
|
|
|
|
/*extended_highest_sequence_number=*/24'100);
|
2019-08-01 17:38:01 +02:00
|
|
|
EXPECT_EQ(5, stats.FractionLostInPercent());
|
|
|
|
|
|
|
|
|
|
// First report, kSsrc2.
|
2021-05-18 12:48:12 +02:00
|
|
|
stats.Store(kSsrc2, /*packets_lost=*/111,
|
|
|
|
|
/*extended_highest_sequence_number=*/8'500);
|
2019-08-01 17:38:01 +02:00
|
|
|
EXPECT_EQ(5, stats.FractionLostInPercent());
|
|
|
|
|
// fl: 100 * ((15-10) + (136-111)) / ((24100-24000) + (8800-8500)) = 7%
|
2021-05-18 12:48:12 +02:00
|
|
|
stats.Store(kSsrc2, /*packets_lost=*/136,
|
|
|
|
|
/*extended_highest_sequence_number=*/8'800);
|
2019-08-01 17:38:01 +02:00
|
|
|
EXPECT_EQ(7, stats.FractionLostInPercent());
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-18 12:48:12 +02:00
|
|
|
} // namespace
|
2015-01-08 07:50:56 +00:00
|
|
|
} // namespace webrtc
|