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

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: CR comments 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:
20 BitrateAdjusterTest()
21 : clock_(0), adjuster_(&clock_) {}
22
23 // Simulate an output bitrate for one update cycle of BitrateAdjuster.
24 void SimulateBitrate(uint32_t bitrate_in_kbit) {
25 const uint32_t update_interval_ms =
26 BitrateAdjuster::kBitrateUpdateIntervalMs;
27 const uint32_t update_frame_interval =
28 BitrateAdjuster::kBitrateUpdateFrameInterval;
29 // Round up frame interval so we get one cycle passes.
30 const uint32_t frame_interval_ms =
31 (update_interval_ms + update_frame_interval - 1) /
32 update_frame_interval;
33 const size_t frame_size_bytes = (bitrate_in_kbit * frame_interval_ms) / 8;
34 for (size_t i = 0; i < update_frame_interval; ++i) {
35 clock_.AdvanceTimeMilliseconds(frame_interval_ms);
36 adjuster_.Update(frame_size_bytes);
37 }
38 }
39
40 void VerifyAdjustment() {
41 // The adjusted bitrate should be between the estimated bitrate and the
42 // target bitrate within clamp.
43 uint32_t target_bitrate = adjuster_.GetTargetBitrate();
44 uint32_t adjusted_bitrate = adjuster_.GetAdjustedBitrate();
45 uint32_t estimated_bitrate = adjuster_.GetEstimatedBitrate();
46 uint32_t adjusted_lower_bound = adjuster_.GetMinAdjustedBitrate();
47 uint32_t adjusted_upper_bound = adjuster_.GetMaxAdjustedBitrate();
48 EXPECT_LE(adjusted_bitrate, adjusted_upper_bound);
49 EXPECT_GE(adjusted_bitrate, adjusted_lower_bound);
50 if (estimated_bitrate > target_bitrate) {
51 EXPECT_LT(adjusted_bitrate, target_bitrate);
52 }
53 }
54
55 protected:
56 SimulatedClock clock_;
57 BitrateAdjuster adjuster_;
58 };
59
60 TEST_F(BitrateAdjusterTest, VaryingBitrates) {
61 const uint32_t target_bitrate = 640;
62 adjuster_.SetTargetBitrate(target_bitrate);
63
64 // Grossly overshoot for a little while. Adjusted bitrate should decrease.
65 uint32_t actual_bitrate = 2 * target_bitrate;
66 uint32_t last_adjusted_bitrate = 0;
67 uint32_t adjusted_bitrate = 0;
68
69 SimulateBitrate(actual_bitrate);
70 VerifyAdjustment();
71 last_adjusted_bitrate = adjuster_.GetAdjustedBitrate();
72
73 SimulateBitrate(actual_bitrate);
74 VerifyAdjustment();
75 adjusted_bitrate = adjuster_.GetAdjustedBitrate();
76 EXPECT_LT(adjusted_bitrate, last_adjusted_bitrate);
77 last_adjusted_bitrate = adjusted_bitrate;
78 // After two cycles we should've stabilized and hit the lower bound.
79 EXPECT_EQ(adjuster_.GetMinAdjustedBitrate(), adjusted_bitrate);
80
81 // Simulate encoder settling down. Adjusted bitrate should increase.
82 SimulateBitrate(target_bitrate);
83 adjusted_bitrate = adjuster_.GetAdjustedBitrate();
84 VerifyAdjustment();
85 EXPECT_GT(adjusted_bitrate, last_adjusted_bitrate);
86 last_adjusted_bitrate = adjusted_bitrate;
87
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 // After two cycles we should've stabilized and hit the upper bound.
94 EXPECT_EQ(adjuster_.GetMaxAdjustedBitrate(), adjusted_bitrate);
95 }
96
97 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698