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

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: . 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 "webrtc/base/fakeclock.h"
14 #include "webrtc/base/ptr_util.h"
15 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
16 #include "webrtc/test/gmock.h"
17 #include "webrtc/test/gtest.h"
18
19 using testing::_;
20 using testing::NiceMock;
21 using testing::InSequence;
22 using testing::Return;
23
24 namespace webrtc {
25
26 namespace {
27
28 constexpr int64_t first_arrival_time_ms = 10;
29 constexpr int64_t first_send_time_ms = 10;
30 constexpr uint16_t sequence_number = 1;
31 constexpr size_t payload_size = 10;
32
33 class MockBitrateEstimator : public BitrateEstimator {
34 public:
35 ~MockBitrateEstimator() { Die(); }
36
37 MOCK_METHOD0(Die, void());
38 MOCK_METHOD2(Update, void(int64_t now_ms, int bytes));
39 MOCK_CONST_METHOD0(bitrate_bps, rtc::Optional<uint32_t>());
40 };
41
42 struct AcknowledgedBitrateEstimatorTestStates {
43 std::unique_ptr<AcknowledgedBitrateEstimator> acknowledged_bitrate_estimator;
44 MockBitrateEstimator* bitrate_estimator;
45 };
46
47 class MockBitrateEstimatorCreator : public BitrateEstimatorCreator {
48 public:
49 explicit MockBitrateEstimatorCreator(
50 AcknowledgedBitrateEstimatorTestStates* states)
51 : states_(states) {
52 RTC_CHECK(states_);
53 }
54 std::unique_ptr<BitrateEstimator> Create() const override {
55 auto bitrate_estimator = rtc::MakeUnique<NiceMock<MockBitrateEstimator>>();
56 states_->bitrate_estimator = bitrate_estimator.get();
57 return bitrate_estimator;
58 }
59 AcknowledgedBitrateEstimatorTestStates* states_;
60 };
61
62 AcknowledgedBitrateEstimatorTestStates CreateTestStates() {
63 AcknowledgedBitrateEstimatorTestStates states;
64 states.acknowledged_bitrate_estimator =
65 rtc::MakeUnique<AcknowledgedBitrateEstimator>(
66 rtc::MakeUnique<MockBitrateEstimatorCreator>(&states));
67 EXPECT_CALL(*states.bitrate_estimator, Die()).Times(1);
68 return states;
69 }
70
71 std::vector<PacketFeedback> CreateFeedbackVector() {
72 std::vector<PacketFeedback> packet_feedback_vector;
73 const PacedPacketInfo pacing_info;
74 packet_feedback_vector.push_back(
75 PacketFeedback(first_arrival_time_ms, first_send_time_ms, sequence_number,
76 payload_size, pacing_info));
77 packet_feedback_vector.push_back(
78 PacketFeedback(first_arrival_time_ms + 10, first_send_time_ms + 10,
79 sequence_number, payload_size + 10, pacing_info));
80 return packet_feedback_vector;
81 }
82
83 } // anonymous namespace
84
85 TEST(TestAcknowledgedBitrateEstimator, DontAddPacketsWhichAreNotInSendHistory) {
86 auto states = CreateTestStates();
87 std::vector<PacketFeedback> packet_feedback_vector;
88 packet_feedback_vector.push_back(
89 PacketFeedback(first_arrival_time_ms, sequence_number));
90 EXPECT_CALL(*states.bitrate_estimator, Update(_, _)).Times(0);
91 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
92 packet_feedback_vector, false);
93 }
94
95 TEST(TestAcknowledgedBitrateEstimator, UpdateBandwith) {
96 auto states = CreateTestStates();
97 auto packet_feedback_vector = CreateFeedbackVector();
98 {
99 InSequence dummy;
100 EXPECT_CALL(*states.bitrate_estimator,
101 Update(packet_feedback_vector[0].arrival_time_ms,
102 packet_feedback_vector[0].payload_size))
103 .Times(1);
104 EXPECT_CALL(*states.bitrate_estimator,
105 Update(packet_feedback_vector[1].arrival_time_ms,
106 packet_feedback_vector[1].payload_size))
107 .Times(1);
108 }
109 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
110 packet_feedback_vector, false);
111 }
112
113 TEST(TestAcknowledgedBitrateEstimator,
114 ResetAfterLeafAlrStateAndDontAddOldPackets) {
115 auto states = CreateTestStates();
116 auto packet_feedback_vector = CreateFeedbackVector();
117 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
118 packet_feedback_vector, true);
119
120 rtc::ScopedFakeClock fake_clock;
121
122 fake_clock.AdvanceTime(
123 rtc::TimeDelta::FromMilliseconds(first_arrival_time_ms + 1));
124 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
125 std::vector<PacketFeedback>(), false);
126 EXPECT_CALL(*states.bitrate_estimator, Die()).Times(1);
127
128 {
129 InSequence dummy;
130 EXPECT_CALL(*states.bitrate_estimator,
131 Update(packet_feedback_vector[0].arrival_time_ms,
132 packet_feedback_vector[0].payload_size))
133 .Times(0);
134 EXPECT_CALL(*states.bitrate_estimator,
135 Update(packet_feedback_vector[1].arrival_time_ms,
136 packet_feedback_vector[1].payload_size))
137 .Times(1);
138 }
139 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
140 packet_feedback_vector, false);
141 }
142
143 TEST(TestAcknowledgedBitrateEstimator, ReturnBitrate) {
144 auto states = CreateTestStates();
145 rtc::Optional<uint32_t> return_value(42);
146 EXPECT_CALL(*states.bitrate_estimator, bitrate_bps())
147 .Times(1)
148 .WillOnce(Return(return_value));
149 EXPECT_EQ(return_value, states.acknowledged_bitrate_estimator->bitrate_bps());
150 }
151
152 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698