asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "video/report_block_stats.h" |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 12 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 13 | #include "test/gtest.h" |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | class ReportBlockStatsTest : public ::testing::Test { |
| 18 | protected: |
Åsa Persson | 5e155a6 | 2019-08-01 17:38:01 +0200 | [diff] [blame] | 19 | ReportBlockStatsTest() { |
| 20 | // kSsrc1: report 1-3. |
| 21 | stats1_1_.packets_lost = 10; |
| 22 | stats1_1_.extended_highest_sequence_number = 24000; |
| 23 | stats1_2_.packets_lost = 15; |
| 24 | stats1_2_.extended_highest_sequence_number = 24100; |
| 25 | stats1_3_.packets_lost = 50; |
| 26 | stats1_3_.extended_highest_sequence_number = 24200; |
| 27 | // kSsrc2: report 1,2. |
| 28 | stats2_1_.packets_lost = 111; |
| 29 | stats2_1_.extended_highest_sequence_number = 8500; |
| 30 | stats2_2_.packets_lost = 136; |
| 31 | stats2_2_.extended_highest_sequence_number = 8800; |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Åsa Persson | 5e155a6 | 2019-08-01 17:38:01 +0200 | [diff] [blame] | 34 | const uint32_t kSsrc1 = 123; |
| 35 | const uint32_t kSsrc2 = 234; |
| 36 | RtcpStatistics stats1_1_; |
| 37 | RtcpStatistics stats1_2_; |
| 38 | RtcpStatistics stats1_3_; |
| 39 | RtcpStatistics stats2_1_; |
| 40 | RtcpStatistics stats2_2_; |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 41 | }; |
| 42 | |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 43 | TEST_F(ReportBlockStatsTest, StoreAndGetFractionLost) { |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 44 | ReportBlockStats stats; |
asapersson@webrtc.org | e7358ea | 2015-01-21 09:00:19 +0000 | [diff] [blame] | 45 | EXPECT_EQ(-1, stats.FractionLostInPercent()); |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 46 | |
Åsa Persson | 5e155a6 | 2019-08-01 17:38:01 +0200 | [diff] [blame] | 47 | // First report. |
| 48 | stats.Store(kSsrc1, stats1_1_); |
asapersson@webrtc.org | e7358ea | 2015-01-21 09:00:19 +0000 | [diff] [blame] | 49 | EXPECT_EQ(-1, stats.FractionLostInPercent()); |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 50 | // fl: 100 * (15-10) / (24100-24000) = 5% |
Åsa Persson | 5e155a6 | 2019-08-01 17:38:01 +0200 | [diff] [blame] | 51 | stats.Store(kSsrc1, stats1_2_); |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 52 | EXPECT_EQ(5, stats.FractionLostInPercent()); |
| 53 | // fl: 100 * (50-10) / (24200-24000) = 20% |
Åsa Persson | 5e155a6 | 2019-08-01 17:38:01 +0200 | [diff] [blame] | 54 | stats.Store(kSsrc1, stats1_3_); |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 55 | EXPECT_EQ(20, stats.FractionLostInPercent()); |
| 56 | } |
| 57 | |
Åsa Persson | 5e155a6 | 2019-08-01 17:38:01 +0200 | [diff] [blame] | 58 | TEST_F(ReportBlockStatsTest, StoreAndGetFractionLost_TwoSsrcs) { |
| 59 | ReportBlockStats stats; |
| 60 | EXPECT_EQ(-1, stats.FractionLostInPercent()); |
| 61 | |
| 62 | // First report. |
| 63 | stats.Store(kSsrc1, stats1_1_); |
| 64 | EXPECT_EQ(-1, stats.FractionLostInPercent()); |
| 65 | // fl: 100 * (15-10) / (24100-24000) = 5% |
| 66 | stats.Store(kSsrc1, stats1_2_); |
| 67 | EXPECT_EQ(5, stats.FractionLostInPercent()); |
| 68 | |
| 69 | // First report, kSsrc2. |
| 70 | stats.Store(kSsrc2, stats2_1_); |
| 71 | EXPECT_EQ(5, stats.FractionLostInPercent()); |
| 72 | // fl: 100 * ((15-10) + (136-111)) / ((24100-24000) + (8800-8500)) = 7% |
| 73 | stats.Store(kSsrc2, stats2_2_); |
| 74 | EXPECT_EQ(7, stats.FractionLostInPercent()); |
| 75 | } |
| 76 | |
asapersson@webrtc.org | 823c9b8 | 2015-01-08 07:50:56 +0000 | [diff] [blame] | 77 | } // namespace webrtc |