Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: webrtc/modules/congestion_controller/acknowledged_bitrate_estimator_unittest.cc

Issue 2931873002: Test and fix for huge bwe drop after alr state. (Closed)
Patch Set: fix_for_unittest Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "webrtc/modules/congestion_controller/acknowledged_bitrate_estimator.h"
12
13 #include <utility>
14
15 #include "webrtc/base/fakeclock.h"
16 #include "webrtc/base/ptr_util.h"
17 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
18 #include "webrtc/test/gmock.h"
19 #include "webrtc/test/gtest.h"
20
21 using testing::_;
22 using testing::NiceMock;
23 using testing::InSequence;
24 using testing::Return;
25
26 namespace webrtc {
27
28 namespace {
29
30 constexpr int64_t first_arrival_time_ms = 10;
31 constexpr int64_t first_send_time_ms = 10;
32 constexpr uint16_t sequence_number = 1;
33 constexpr size_t payload_size = 10;
34
35 class MockBitrateEstimator : public BitrateEstimator {
36 public:
37 MOCK_METHOD2(Update, void(int64_t now_ms, int bytes));
38 MOCK_CONST_METHOD0(bitrate_bps, rtc::Optional<uint32_t>());
39 };
40
41 class MockBitrateEstimatorCreator : public BitrateEstimatorCreator {
42 public:
43 MockBitrateEstimatorCreator()
44 : mock_bitrate_estimator_(nullptr), num_created_bitrate_estimators_(0) {}
45 std::unique_ptr<BitrateEstimator> Create() override {
46 auto bitrate_estimator = rtc::MakeUnique<NiceMock<MockBitrateEstimator>>();
47 mock_bitrate_estimator_ = bitrate_estimator.get();
48 num_created_bitrate_estimators_++;
49 return bitrate_estimator;
50 }
51 int num_created_bitrate_estimators() {
52 return num_created_bitrate_estimators_;
53 }
54
55 MockBitrateEstimator* get_mock_bitrate_estimator() {
56 RTC_CHECK(mock_bitrate_estimator_);
57 return mock_bitrate_estimator_;
58 }
59
60 private:
61 MockBitrateEstimator* mock_bitrate_estimator_;
62 int num_created_bitrate_estimators_;
63 };
64
65 struct AcknowledgedBitrateEstimatorTestStates {
66 std::unique_ptr<AcknowledgedBitrateEstimator> acknowledged_bitrate_estimator;
67 MockBitrateEstimatorCreator* mock_bitrate_estimator_creator;
68 };
69
70 AcknowledgedBitrateEstimatorTestStates CreateTestStates() {
71 AcknowledgedBitrateEstimatorTestStates states;
72 auto mock_bitrate_estimator_creator =
73 rtc::MakeUnique<MockBitrateEstimatorCreator>();
74 states.mock_bitrate_estimator_creator = mock_bitrate_estimator_creator.get();
75 states.acknowledged_bitrate_estimator =
76 rtc::MakeUnique<AcknowledgedBitrateEstimator>(
77 std::move(mock_bitrate_estimator_creator));
78 return states;
79 }
80
81 std::vector<PacketFeedback> CreateFeedbackVector() {
82 std::vector<PacketFeedback> packet_feedback_vector;
83 const PacedPacketInfo pacing_info;
84 packet_feedback_vector.push_back(
85 PacketFeedback(first_arrival_time_ms, first_send_time_ms, sequence_number,
86 payload_size, pacing_info));
87 packet_feedback_vector.push_back(
88 PacketFeedback(first_arrival_time_ms + 10, first_send_time_ms + 10,
89 sequence_number, payload_size + 10, pacing_info));
90 return packet_feedback_vector;
91 }
92
93 } // anonymous namespace
94
95 TEST(TestAcknowledgedBitrateEstimator, DontAddPacketsWhichAreNotInSendHistory) {
96 auto states = CreateTestStates();
97 std::vector<PacketFeedback> packet_feedback_vector;
98 packet_feedback_vector.push_back(
99 PacketFeedback(first_arrival_time_ms, sequence_number));
100 EXPECT_CALL(
101 *states.mock_bitrate_estimator_creator->get_mock_bitrate_estimator(),
102 Update(_, _))
103 .Times(0);
104 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
105 packet_feedback_vector, false);
106 }
107
108 TEST(TestAcknowledgedBitrateEstimator, UpdateBandwith) {
109 auto states = CreateTestStates();
110 auto packet_feedback_vector = CreateFeedbackVector();
111 {
112 InSequence dummy;
113 EXPECT_CALL(
114 *states.mock_bitrate_estimator_creator->get_mock_bitrate_estimator(),
115 Update(packet_feedback_vector[0].arrival_time_ms,
116 static_cast<int>(packet_feedback_vector[0].payload_size)))
117 .Times(1);
118 EXPECT_CALL(
119 *states.mock_bitrate_estimator_creator->get_mock_bitrate_estimator(),
120 Update(packet_feedback_vector[1].arrival_time_ms,
121 static_cast<int>(packet_feedback_vector[1].payload_size)))
122 .Times(1);
123 }
124 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
125 packet_feedback_vector, false);
126 }
127
128 TEST(TestAcknowledgedBitrateEstimator,
129 ResetAfterLeafAlrStateAndDontAddOldPackets) {
130 auto states = CreateTestStates();
131 auto packet_feedback_vector = CreateFeedbackVector();
132 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
133 packet_feedback_vector, true);
134
135 rtc::ScopedFakeClock fake_clock;
136
137 fake_clock.AdvanceTime(
138 rtc::TimeDelta::FromMilliseconds(first_arrival_time_ms + 1));
139
140 EXPECT_EQ(
141 1,
142 states.mock_bitrate_estimator_creator->num_created_bitrate_estimators());
143 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
144 std::vector<PacketFeedback>(), false);
145 EXPECT_EQ(
146 2,
147 states.mock_bitrate_estimator_creator->num_created_bitrate_estimators());
148
149 {
150 InSequence dummy;
151 EXPECT_CALL(
152 *states.mock_bitrate_estimator_creator->get_mock_bitrate_estimator(),
153 Update(packet_feedback_vector[0].arrival_time_ms,
154 static_cast<int>(packet_feedback_vector[0].payload_size)))
155 .Times(0);
156 EXPECT_CALL(
157 *states.mock_bitrate_estimator_creator->get_mock_bitrate_estimator(),
158 Update(packet_feedback_vector[1].arrival_time_ms,
159 static_cast<int>(packet_feedback_vector[1].payload_size)))
160 .Times(1);
161 }
162 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
163 packet_feedback_vector, false);
164 }
165
166 TEST(TestAcknowledgedBitrateEstimator, ReturnBitrate) {
167 auto states = CreateTestStates();
168 rtc::Optional<uint32_t> return_value(42);
169 EXPECT_CALL(
170 *states.mock_bitrate_estimator_creator->get_mock_bitrate_estimator(),
171 bitrate_bps())
172 .Times(1)
173 .WillOnce(Return(return_value));
174 EXPECT_EQ(return_value, states.acknowledged_bitrate_estimator->bitrate_bps());
175 }
176
177 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698