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

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

Powered by Google App Engine
This is Rietveld 408576698