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

Side by Side Diff: webrtc/modules/bitrate_controller/bitrate_controller_unittest.cc

Issue 1748403002: Move RtcEventLog object from inside VoiceEngine to Call. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Another rebase and accompanying changes. Created 4 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
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <algorithm> 11 #include <algorithm>
12 #include <vector> 12 #include <vector>
13 13
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 #include "webrtc/call/mock/mock_rtc_event_log.h"
16 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 17 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
17 #include "webrtc/modules/pacing/mock/mock_paced_sender.h" 18 #include "webrtc/modules/pacing/mock/mock_paced_sender.h"
18 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h" 19 #include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
19 20
20 using ::testing::Exactly; 21 using ::testing::Exactly;
21 using ::testing::Return; 22 using ::testing::Return;
22 23
23 using webrtc::BitrateController; 24 using webrtc::BitrateController;
24 using webrtc::BitrateObserver; 25 using webrtc::BitrateObserver;
25 using webrtc::PacedSender; 26 using webrtc::PacedSender;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 uint8_t last_fraction_loss_; 60 uint8_t last_fraction_loss_;
60 int64_t last_rtt_; 61 int64_t last_rtt_;
61 }; 62 };
62 63
63 class BitrateControllerTest : public ::testing::Test { 64 class BitrateControllerTest : public ::testing::Test {
64 protected: 65 protected:
65 BitrateControllerTest() : clock_(0) {} 66 BitrateControllerTest() : clock_(0) {}
66 ~BitrateControllerTest() {} 67 ~BitrateControllerTest() {}
67 68
68 virtual void SetUp() { 69 virtual void SetUp() {
69 controller_ = 70 controller_ = BitrateController::CreateBitrateController(
70 BitrateController::CreateBitrateController(&clock_, &bitrate_observer_); 71 &clock_, &bitrate_observer_, &event_log_);
71 controller_->SetStartBitrate(kStartBitrateBps); 72 controller_->SetStartBitrate(kStartBitrateBps);
72 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); 73 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_);
73 controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps); 74 controller_->SetMinMaxBitrate(kMinBitrateBps, kMaxBitrateBps);
74 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); 75 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_);
75 bandwidth_observer_ = controller_->CreateRtcpBandwidthObserver(); 76 bandwidth_observer_ = controller_->CreateRtcpBandwidthObserver();
76 } 77 }
77 78
78 virtual void TearDown() { 79 virtual void TearDown() {
79 delete bandwidth_observer_; 80 delete bandwidth_observer_;
80 delete controller_; 81 delete controller_;
81 } 82 }
82 83
83 const int kMinBitrateBps = 100000; 84 const int kMinBitrateBps = 100000;
84 const int kStartBitrateBps = 200000; 85 const int kStartBitrateBps = 200000;
85 const int kMaxBitrateBps = 300000; 86 const int kMaxBitrateBps = 300000;
86 87
87 const int kDefaultMinBitrateBps = 10000; 88 const int kDefaultMinBitrateBps = 10000;
88 const int kDefaultMaxBitrateBps = 1000000000; 89 const int kDefaultMaxBitrateBps = 1000000000;
89 90
90 webrtc::SimulatedClock clock_; 91 webrtc::SimulatedClock clock_;
91 TestBitrateObserver bitrate_observer_; 92 TestBitrateObserver bitrate_observer_;
92 BitrateController* controller_; 93 BitrateController* controller_;
93 RtcpBandwidthObserver* bandwidth_observer_; 94 RtcpBandwidthObserver* bandwidth_observer_;
95 webrtc::MockRtcEventLog event_log_;
94 }; 96 };
95 97
96 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) { 98 TEST_F(BitrateControllerTest, DefaultMinMaxBitrate) {
97 // Receive successively lower REMBs, verify the reserved bitrate is deducted. 99 // Receive successively lower REMBs, verify the reserved bitrate is deducted.
98 controller_->SetMinMaxBitrate(0, 0); 100 controller_->SetMinMaxBitrate(0, 0);
99 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_); 101 EXPECT_EQ(kStartBitrateBps, bitrate_observer_.last_bitrate_);
100 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2); 102 bandwidth_observer_->OnReceivedEstimatedBitrate(kDefaultMinBitrateBps / 2);
101 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_); 103 EXPECT_EQ(kDefaultMinBitrateBps, bitrate_observer_.last_bitrate_);
102 bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps); 104 bandwidth_observer_->OnReceivedEstimatedBitrate(2 * kDefaultMaxBitrateBps);
103 clock_.AdvanceTimeMilliseconds(1000); 105 clock_.AdvanceTimeMilliseconds(1000);
104 controller_->Process(); 106 controller_->Process();
105 EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_); 107 EXPECT_EQ(kDefaultMaxBitrateBps, bitrate_observer_.last_bitrate_);
106 } 108 }
107 109
108 TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) { 110 TEST_F(BitrateControllerTest, OneBitrateObserverOneRtcpObserver) {
109 // First REMB applies immediately. 111 // First REMB applies immediately.
112 EXPECT_CALL(event_log_, LogBwePacketLossEvent(testing::Gt(0), 0, 0)).Times(8);
110 int64_t time_ms = 1001; 113 int64_t time_ms = 1001;
111 webrtc::ReportBlockList report_blocks; 114 webrtc::ReportBlockList report_blocks;
112 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); 115 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1));
113 bandwidth_observer_->OnReceivedEstimatedBitrate(200000); 116 bandwidth_observer_->OnReceivedEstimatedBitrate(200000);
114 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_); 117 EXPECT_EQ(200000, bitrate_observer_.last_bitrate_);
115 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); 118 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_);
116 EXPECT_EQ(0, bitrate_observer_.last_rtt_); 119 EXPECT_EQ(0, bitrate_observer_.last_rtt_);
117 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); 120 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
118 report_blocks.clear(); 121 report_blocks.clear();
119 time_ms += 2000; 122 time_ms += 2000;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 EXPECT_EQ(250000, bitrate_observer_.last_bitrate_); 179 EXPECT_EQ(250000, bitrate_observer_.last_bitrate_);
177 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); 180 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_);
178 EXPECT_EQ(50, bitrate_observer_.last_rtt_); 181 EXPECT_EQ(50, bitrate_observer_.last_rtt_);
179 182
180 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); 183 bandwidth_observer_->OnReceivedEstimatedBitrate(1000);
181 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); 184 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_);
182 } 185 }
183 186
184 TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) { 187 TEST_F(BitrateControllerTest, OneBitrateObserverTwoRtcpObservers) {
185 // REMBs during the first 2 seconds apply immediately. 188 // REMBs during the first 2 seconds apply immediately.
189 EXPECT_CALL(event_log_, LogBwePacketLossEvent(testing::Gt(0), 0, 0)).Times(9);
186 int64_t time_ms = 1; 190 int64_t time_ms = 1;
187 webrtc::ReportBlockList report_blocks; 191 webrtc::ReportBlockList report_blocks;
188 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1)); 192 report_blocks.push_back(CreateReportBlock(1, 2, 0, 1));
189 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms); 193 bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, 50, time_ms);
190 report_blocks.clear(); 194 report_blocks.clear();
191 time_ms += 500; 195 time_ms += 500;
192 196
193 RtcpBandwidthObserver* second_bandwidth_observer = 197 RtcpBandwidthObserver* second_bandwidth_observer =
194 controller_->CreateRtcpBandwidthObserver(); 198 controller_->CreateRtcpBandwidthObserver();
195 199
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_); 275 EXPECT_EQ(0, bitrate_observer_.last_fraction_loss_);
272 EXPECT_EQ(50, bitrate_observer_.last_rtt_); 276 EXPECT_EQ(50, bitrate_observer_.last_rtt_);
273 277
274 // Min cap. 278 // Min cap.
275 bandwidth_observer_->OnReceivedEstimatedBitrate(1000); 279 bandwidth_observer_->OnReceivedEstimatedBitrate(1000);
276 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); 280 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_);
277 delete second_bandwidth_observer; 281 delete second_bandwidth_observer;
278 } 282 }
279 283
280 TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) { 284 TEST_F(BitrateControllerTest, OneBitrateObserverMultipleReportBlocks) {
285 testing::Expectation first_calls =
286 EXPECT_CALL(event_log_, LogBwePacketLossEvent(testing::Gt(0), 0, 0))
287 .Times(7);
288 EXPECT_CALL(event_log_,
289 LogBwePacketLossEvent(testing::Gt(0), testing::Gt(0), 0))
290 .Times(2)
291 .After(first_calls);
281 uint32_t sequence_number[2] = {0, 0xFF00}; 292 uint32_t sequence_number[2] = {0, 0xFF00};
282 const int kStartBitrate = 200000; 293 const int kStartBitrate = 200000;
283 const int kMinBitrate = 100000; 294 const int kMinBitrate = 100000;
284 const int kMaxBitrate = 300000; 295 const int kMaxBitrate = 300000;
285 controller_->SetStartBitrate(kStartBitrate); 296 controller_->SetStartBitrate(kStartBitrate);
286 controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate); 297 controller_->SetMinMaxBitrate(kMinBitrate, kMaxBitrate);
287 298
288 // REMBs during the first 2 seconds apply immediately. 299 // REMBs during the first 2 seconds apply immediately.
289 int64_t time_ms = 1001; 300 int64_t time_ms = 1001;
290 webrtc::ReportBlockList report_blocks; 301 webrtc::ReportBlockList report_blocks;
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 EXPECT_EQ(120000, bitrate_observer_.last_bitrate_); 408 EXPECT_EQ(120000, bitrate_observer_.last_bitrate_);
398 controller_->SetReservedBitrate(50000); 409 controller_->SetReservedBitrate(50000);
399 bandwidth_observer_->OnReceivedEstimatedBitrate(120000); 410 bandwidth_observer_->OnReceivedEstimatedBitrate(120000);
400 // Limited by min bitrate. 411 // Limited by min bitrate.
401 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); 412 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_);
402 413
403 controller_->SetReservedBitrate(10000); 414 controller_->SetReservedBitrate(10000);
404 bandwidth_observer_->OnReceivedEstimatedBitrate(1); 415 bandwidth_observer_->OnReceivedEstimatedBitrate(1);
405 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_); 416 EXPECT_EQ(100000, bitrate_observer_.last_bitrate_);
406 } 417 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698