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

Side by Side Diff: webrtc/modules/video_coding/bitrate_adjuster_unittest.cc

Issue 1660963002: Bitrate controller for VideoToolbox encoder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix GN build. Created 4 years, 10 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 2016 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 "testing/gtest/include/gtest/gtest.h"
12
13 #include "webrtc/modules/video_coding/include/bitrate_adjuster.h"
14 #include "webrtc/system_wrappers/include/clock.h"
15
16 namespace webrtc {
17
18 class BitrateAdjusterTest : public ::testing::Test,
19 public BitrateAdjusterObserver {
20 public:
21 BitrateAdjusterTest()
22 : clock_(0), adjuster_(&clock_, this), adjusted_bitrate_kbit_(0) {}
23
24 virtual void OnBitrateAdjusted(uint32_t adjusted_bitrate) {
25 adjusted_bitrate_kbit_ = adjusted_bitrate;
26 }
27
28 // Simulate an output bitrate for one update cycle of BitrateAdjuster.
29 void SimulateBitrate(uint32_t bitrate_in_kbit) {
30 const uint32_t update_interval_ms =
31 BitrateAdjuster::kBitrateUpdateIntervalMs;
32 const uint32_t update_frame_interval =
33 BitrateAdjuster::kBitrateUpdateFrameInterval;
34 // Round up frame interval so we get one cycle passes.
35 const uint32_t frame_interval_ms =
36 (update_interval_ms + update_frame_interval - 1) /
37 update_frame_interval;
38 const size_t frame_size_bytes = (bitrate_in_kbit * frame_interval_ms) / 8;
39 for (size_t i = 0; i < update_frame_interval; ++i) {
40 clock_.AdvanceTimeMilliseconds(frame_interval_ms);
41 adjuster_.Update(frame_size_bytes);
42 }
43 }
44
45 void VerifyAdjustment() {
46 // The adjusted bitrate should be between the estimated bitrate and the
47 // target bitrate within clamp.
48 uint32_t target_bitrate = adjuster_.GetTargetBitrate();
49 uint32_t adjusted_bitrate = adjuster_.GetAdjustedBitrate();
50 uint32_t estimated_bitrate = adjuster_.GetEstimatedBitrate();
51 uint32_t adjusted_lower_bound = adjuster_.GetMinAdjustedBitrate();
52 uint32_t adjusted_upper_bound = adjuster_.GetMaxAdjustedBitrate();
53 EXPECT_LE(adjusted_bitrate, adjusted_upper_bound);
54 EXPECT_GE(adjusted_bitrate, adjusted_lower_bound);
55 if (estimated_bitrate > target_bitrate) {
56 EXPECT_LT(adjusted_bitrate, target_bitrate);
57 }
58 }
59
60 protected:
61 SimulatedClock clock_;
62 BitrateAdjuster adjuster_;
63 uint32_t adjusted_bitrate_kbit_;
64 };
65
66 TEST_F(BitrateAdjusterTest, VaryingBitrates) {
67 const uint32_t target_bitrate = 640;
68 adjuster_.SetTargetBitrate(target_bitrate);
69
70 // Grossly overshoot for a little while. Adjusted bitrate should decrease.
71 uint32_t actual_bitrate = 2 * target_bitrate;
72 uint32_t last_adjusted_bitrate = 0;
73 uint32_t adjusted_bitrate = 0;
74
75 SimulateBitrate(actual_bitrate);
76 VerifyAdjustment();
77 last_adjusted_bitrate = adjuster_.GetAdjustedBitrate();
78
79 SimulateBitrate(actual_bitrate);
80 VerifyAdjustment();
81 adjusted_bitrate = adjuster_.GetAdjustedBitrate();
82 EXPECT_LT(adjusted_bitrate, last_adjusted_bitrate);
83 last_adjusted_bitrate = adjusted_bitrate;
84 // After two cycles we should've stabilized and hit the lower bound.
85 EXPECT_EQ(adjuster_.GetMinAdjustedBitrate(), adjusted_bitrate);
86
87 // Simulate encoder settling down. Adjusted bitrate should increase.
88 SimulateBitrate(target_bitrate);
89 adjusted_bitrate = adjuster_.GetAdjustedBitrate();
90 VerifyAdjustment();
91 EXPECT_GT(adjusted_bitrate, last_adjusted_bitrate);
92 last_adjusted_bitrate = adjusted_bitrate;
93
94 SimulateBitrate(target_bitrate);
95 adjusted_bitrate = adjuster_.GetAdjustedBitrate();
96 VerifyAdjustment();
97 EXPECT_GT(adjusted_bitrate, last_adjusted_bitrate);
98 last_adjusted_bitrate = adjusted_bitrate;
99 // After two cycles we should've stabilized and hit the upper bound.
100 EXPECT_EQ(adjuster_.GetMaxAdjustedBitrate(), adjusted_bitrate);
101 }
102
103 TEST_F(BitrateAdjusterTest, AdjustentObserver) {
104 const uint32_t target_bitrate = 640;
105 adjuster_.SetTargetBitrate(target_bitrate);
106 SimulateBitrate(1440);
107 uint32_t adjusted_bitrate_kbit = adjuster_.GetAdjustedBitrate();
108 EXPECT_EQ(adjusted_bitrate_kbit, adjusted_bitrate_kbit_);
109 }
110
111 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698