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

Unified 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: Remove unneeded call 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/video_coding/include/bitrate_adjuster.h
diff --git a/webrtc/modules/video_coding/include/bitrate_adjuster.h b/webrtc/modules/video_coding/include/bitrate_adjuster.h
new file mode 100644
index 0000000000000000000000000000000000000000..2105b02d9881677f0f2a85462d0248c3cfe6845e
--- /dev/null
+++ b/webrtc/modules/video_coding/include/bitrate_adjuster.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef WEBRTC_MODULES_VIDEO_CODING_INCLUDE_BITRATE_ADJUSTER_H_
+#define WEBRTC_MODULES_VIDEO_CODING_INCLUDE_BITRATE_ADJUSTER_H_
+
+#include <functional>
+
+#include "webrtc/base/criticalsection.h"
+#include "webrtc/base/rollingaccumulator.h"
+
+namespace webrtc {
+
+class BitrateAdjusterObserver {
+ public:
+ virtual ~BitrateAdjusterObserver() {}
+
+ // Called when a new bitrate adjustment is computed.
+ virtual void OnBitrateAdjusted(uint32_t adjusted_bitrate_kbit) = 0;
+};
+
+// Certain hardware encoders tend to consistently overshoot the bitrate that
+// they are configured to encode at. This class estimates an adjusted bitrate
+// that when set on the encoder will produce the desired bitrate.
+class BitrateAdjuster {
+ public:
+ // The observer is called each time a new bitrate adjustment is computed.
+ explicit BitrateAdjuster(BitrateAdjusterObserver* observer);
+ virtual ~BitrateAdjuster() {}
+
+ // Sets the desired bitrate in kbps. Should be called at least once before
+ // Update.
+ void SetTargetBitrate(uint32_t bitrate_kbit);
+ uint32_t GetTargetBitrate() const;
+
+ // Returns the adjusted bitrate in kbps.
+ uint32_t GetAdjustedBitrate() const;
+
+ // This should be called after each frame is encoded. The timestamp at which
+ // it is called is used to estimate the output bitrate of the encoder.
+ // Should be called from only one thread.
+ void Update(size_t frame_size);
+
+ private:
+ static const uint32_t kBitrateUpdateIntervalMs;
+ static const uint32_t kBitrateTolerancePct;
+
+ void Reset();
+ void UpdateBitrate(uint32_t current_time_ms);
+ void UpdateBitrateTracker(size_t frame_size, uint32_t current_time_ms);
+
+ rtc::CriticalSection crit_;
+ BitrateAdjusterObserver* observer_;
+ // The bitrate we want.
+ volatile uint32_t target_bitrate_kbit_ GUARDED_BY(crit_);
+ // The bitrate we use to get what we want.
+ volatile uint32_t adjusted_bitrate_kbit_ GUARDED_BY(crit_);
+ // Used to estimate bitrate.
+ rtc::RollingAccumulator<float> bitrate_tracker_ GUARDED_BY(crit_);
+ // The last time we tried to adjust the bitrate.
+ uint32_t last_bitrate_update_time_ms_ GUARDED_BY(crit_);
+ // The timestamp of the last time Update was called.
+ uint32_t last_update_time_ms_ GUARDED_BY(crit_);
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_VIDEO_CODING_INCLUDE_BITRATE_ADJUSTER_H_

Powered by Google App Engine
This is Rietveld 408576698