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

Side by Side Diff: webrtc/modules/video_coding/include/bitrate_adjuster.h

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 #ifndef WEBRTC_MODULES_VIDEO_CODING_INCLUDE_BITRATE_ADJUSTER_H_
12 #define WEBRTC_MODULES_VIDEO_CODING_INCLUDE_BITRATE_ADJUSTER_H_
13
14 #include <functional>
15
16 #include "webrtc/base/criticalsection.h"
17 #include "webrtc/base/rate_statistics.h"
18
19 namespace webrtc {
20
21 class Clock;
22
23 // Certain hardware encoders tend to consistently overshoot the bitrate that
24 // they are configured to encode at. This class estimates an adjusted bitrate
25 // that when set on the encoder will produce the desired bitrate.
26 class BitrateAdjuster {
27 public:
28 explicit BitrateAdjuster(Clock* clock);
29 virtual ~BitrateAdjuster() {}
30
31 static const uint32_t kBitrateUpdateIntervalMs;
32 static const uint32_t kBitrateUpdateFrameInterval;
33 static const uint32_t kBitrateTolerancePct;
34
35 // Sets the desired bitrate in kbps. Should be called at least once before
36 // Update.
37 void SetTargetBitrate(uint32_t bitrate_kbit);
38 uint32_t GetTargetBitrate() const;
39
40 // Returns the adjusted bitrate in kbps.
41 uint32_t GetAdjustedBitrate() const;
42
43 // Returns what we think the current bitrate is.
44 uint32_t GetEstimatedBitrate();
45
46 // Returns smallest possible adjusted value.
47 uint32_t GetMinAdjustedBitrate() const;
48
49 // Returns largest possible adjusted value.
50 uint32_t GetMaxAdjustedBitrate() const;
51
52 // This should be called after each frame is encoded. The timestamp at which
53 // it is called is used to estimate the output bitrate of the encoder.
54 // Should be called from only one thread.
55 void Update(size_t frame_size);
56
57 private:
58 void Reset();
59 void UpdateBitrate(uint32_t current_time_ms);
60
61 rtc::CriticalSection crit_;
62 Clock* const clock_;
63 // The bitrate we want.
64 volatile uint32_t target_bitrate_kbit_ GUARDED_BY(crit_);
65 // The bitrate we use to get what we want.
66 volatile uint32_t adjusted_bitrate_kbit_ GUARDED_BY(crit_);
67 // Used to estimate bitrate.
68 RateStatistics bitrate_tracker_ GUARDED_BY(crit_);
69 // The last time we tried to adjust the bitrate.
70 uint32_t last_bitrate_update_time_ms_ GUARDED_BY(crit_);
71 // The number of frames since the last time we tried to adjust the bitrate.
72 uint32_t frames_since_last_update_ GUARDED_BY(crit_);
73 };
74
75 } // namespace webrtc
76
77 #endif // WEBRTC_MODULES_VIDEO_CODING_INCLUDE_BITRATE_ADJUSTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698