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

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 UT 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 SimulateBitrateBps(uint32_t bitrate_bps) {
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 =
34 (bitrate_bps * frame_interval_ms) / (8 * 1000);
35 for (size_t i = 0; i < update_frame_interval; ++i) {
36 clock_.AdvanceTimeMilliseconds(frame_interval_ms);
37 adjuster_.Update(frame_size_bytes);
38 }
39 }
40
41 void VerifyAdjustment() {
42 // The adjusted bitrate should be between the estimated bitrate and the
43 // target bitrate within clamp.
44 uint32_t target_bitrate_bps = adjuster_.GetTargetBitrateBps();
45 uint32_t adjusted_bitrate_bps = adjuster_.GetAdjustedBitrateBps();
46 uint32_t estimated_bitrate_bps = adjuster_.GetEstimatedBitrateBps();
47 uint32_t adjusted_lower_bound_bps = adjuster_.GetMinAdjustedBitrateBps();
48 uint32_t adjusted_upper_bound_bps = adjuster_.GetMaxAdjustedBitrateBps();
49 EXPECT_LE(adjusted_bitrate_bps, adjusted_upper_bound_bps);
50 EXPECT_GE(adjusted_bitrate_bps, adjusted_lower_bound_bps);
51 if (estimated_bitrate_bps > target_bitrate_bps) {
52 EXPECT_LT(adjusted_bitrate_bps, target_bitrate_bps);
53 }
54 }
55
56 protected:
57 SimulatedClock clock_;
58 BitrateAdjuster adjuster_;
59 };
60
61 TEST_F(BitrateAdjusterTest, VaryingBitrates) {
62 const uint32_t target_bitrate_bps = 640000;
63 adjuster_.SetTargetBitrateBps(target_bitrate_bps);
64
65 // Grossly overshoot for a little while. Adjusted bitrate should decrease.
66 uint32_t actual_bitrate_bps = 2 * target_bitrate_bps;
67 uint32_t last_adjusted_bitrate_bps = 0;
68 uint32_t adjusted_bitrate_bps = 0;
69
70 SimulateBitrateBps(actual_bitrate_bps);
71 VerifyAdjustment();
72 last_adjusted_bitrate_bps = adjuster_.GetAdjustedBitrateBps();
73
74 SimulateBitrateBps(actual_bitrate_bps);
75 VerifyAdjustment();
76 adjusted_bitrate_bps = adjuster_.GetAdjustedBitrateBps();
77 EXPECT_LT(adjusted_bitrate_bps, last_adjusted_bitrate_bps);
78 last_adjusted_bitrate_bps = adjusted_bitrate_bps;
79 // After two cycles we should've stabilized and hit the lower bound.
80 EXPECT_EQ(adjuster_.GetMinAdjustedBitrateBps(), adjusted_bitrate_bps);
81
82 // Simulate encoder settling down. Adjusted bitrate should increase.
83 SimulateBitrateBps(target_bitrate_bps);
84 adjusted_bitrate_bps = adjuster_.GetAdjustedBitrateBps();
85 VerifyAdjustment();
86 EXPECT_GT(adjusted_bitrate_bps, last_adjusted_bitrate_bps);
87 last_adjusted_bitrate_bps = adjusted_bitrate_bps;
88
89 SimulateBitrateBps(target_bitrate_bps);
90 adjusted_bitrate_bps = adjuster_.GetAdjustedBitrateBps();
91 VerifyAdjustment();
92 EXPECT_GT(adjusted_bitrate_bps, last_adjusted_bitrate_bps);
93 last_adjusted_bitrate_bps = adjusted_bitrate_bps;
94 // After two cycles we should've stabilized and hit the upper bound.
95 EXPECT_EQ(adjuster_.GetMaxAdjustedBitrateBps(), adjusted_bitrate_bps);
96 }
97
98 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698