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

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

Issue 2970653004: Reimplemeted "Test and fix for huge bwe drop after alr state" (Closed)
Patch Set: Respond to comments Created 3 years, 5 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/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
16 #include "webrtc/rtc_base/fakeclock.h"
17 #include "webrtc/rtc_base/ptr_util.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 kFirstArrivalTimeMs = 10;
31 constexpr int64_t kFirstSendTimeMs = 10;
32 constexpr uint16_t kSequenceNumber = 1;
33 constexpr size_t kPayloadSize = 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 MOCK_METHOD0(ExpectFastRateChange, void());
40 };
41
42 struct AcknowledgedBitrateEstimatorTestStates {
43 std::unique_ptr<AcknowledgedBitrateEstimator> acknowledged_bitrate_estimator;
44 MockBitrateEstimator* mock_bitrate_estimator;
45 };
46
47 AcknowledgedBitrateEstimatorTestStates CreateTestStates() {
48 AcknowledgedBitrateEstimatorTestStates states;
49 auto mock_bitrate_estimator = rtc::MakeUnique<MockBitrateEstimator>();
50 states.mock_bitrate_estimator = mock_bitrate_estimator.get();
51 states.acknowledged_bitrate_estimator =
52 rtc::MakeUnique<AcknowledgedBitrateEstimator>(
53 std::move(mock_bitrate_estimator));
54 return states;
55 }
56
57 std::vector<PacketFeedback> CreateFeedbackVector() {
58 std::vector<PacketFeedback> packet_feedback_vector;
59 const PacedPacketInfo pacing_info;
60 packet_feedback_vector.push_back(
61 PacketFeedback(kFirstArrivalTimeMs, kFirstSendTimeMs, kSequenceNumber,
62 kPayloadSize, pacing_info));
63 packet_feedback_vector.push_back(
64 PacketFeedback(kFirstArrivalTimeMs + 10, kFirstSendTimeMs + 10,
65 kSequenceNumber, kPayloadSize + 10, pacing_info));
66 return packet_feedback_vector;
67 }
68
69 } // anonymous namespace
70
71 TEST(TestAcknowledgedBitrateEstimator, DontAddPacketsWhichAreNotInSendHistory) {
72 auto states = CreateTestStates();
73 std::vector<PacketFeedback> packet_feedback_vector;
74 packet_feedback_vector.push_back(
75 PacketFeedback(kFirstArrivalTimeMs, kSequenceNumber));
76 EXPECT_CALL(*states.mock_bitrate_estimator, Update(_, _)).Times(0);
77 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
78 packet_feedback_vector);
79 }
80
81 TEST(TestAcknowledgedBitrateEstimator, UpdateBandwith) {
82 auto states = CreateTestStates();
83 auto packet_feedback_vector = CreateFeedbackVector();
84 {
85 InSequence dummy;
86 EXPECT_CALL(
87 *states.mock_bitrate_estimator,
88 Update(packet_feedback_vector[0].arrival_time_ms,
89 static_cast<int>(packet_feedback_vector[0].payload_size)))
90 .Times(1);
91 EXPECT_CALL(
92 *states.mock_bitrate_estimator,
93 Update(packet_feedback_vector[1].arrival_time_ms,
94 static_cast<int>(packet_feedback_vector[1].payload_size)))
95 .Times(1);
96 }
97 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
98 packet_feedback_vector);
99 }
100
101 TEST(TestAcknowledgedBitrateEstimator, ExpectFastRateChangeWhenLeftAlr) {
102 auto states = CreateTestStates();
103 auto packet_feedback_vector = CreateFeedbackVector();
104 {
105 InSequence dummy;
106 EXPECT_CALL(
107 *states.mock_bitrate_estimator,
108 Update(packet_feedback_vector[0].arrival_time_ms,
109 static_cast<int>(packet_feedback_vector[0].payload_size)))
110 .Times(1);
111 EXPECT_CALL(*states.mock_bitrate_estimator, ExpectFastRateChange())
112 .Times(1);
113 EXPECT_CALL(
114 *states.mock_bitrate_estimator,
115 Update(packet_feedback_vector[1].arrival_time_ms,
116 static_cast<int>(packet_feedback_vector[1].payload_size)))
117 .Times(1);
118 }
119 states.acknowledged_bitrate_estimator->SetAlrEndedTimeMs(kFirstArrivalTimeMs +
120 1);
121 states.acknowledged_bitrate_estimator->IncomingPacketFeedbackVector(
122 packet_feedback_vector);
123 }
124
125 TEST(TestAcknowledgedBitrateEstimator, ReturnBitrate) {
126 auto states = CreateTestStates();
127 rtc::Optional<uint32_t> return_value(42);
128 EXPECT_CALL(*states.mock_bitrate_estimator, bitrate_bps())
129 .Times(1)
130 .WillOnce(Return(return_value));
131 EXPECT_EQ(return_value, states.acknowledged_bitrate_estimator->bitrate_bps());
132 }
133
134 } // namespace webrtc*/
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698