summaryrefslogtreecommitdiffstats
path: root/third_party/libwebrtc/common_video/include
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/libwebrtc/common_video/include
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/common_video/include')
-rw-r--r--third_party/libwebrtc/common_video/include/bitrate_adjuster.h92
-rw-r--r--third_party/libwebrtc/common_video/include/quality_limitation_reason.h26
-rw-r--r--third_party/libwebrtc/common_video/include/video_frame_buffer.h115
-rw-r--r--third_party/libwebrtc/common_video/include/video_frame_buffer_pool.h84
4 files changed, 317 insertions, 0 deletions
diff --git a/third_party/libwebrtc/common_video/include/bitrate_adjuster.h b/third_party/libwebrtc/common_video/include/bitrate_adjuster.h
new file mode 100644
index 0000000000..4b208307a1
--- /dev/null
+++ b/third_party/libwebrtc/common_video/include/bitrate_adjuster.h
@@ -0,0 +1,92 @@
+/*
+ * 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 COMMON_VIDEO_INCLUDE_BITRATE_ADJUSTER_H_
+#define COMMON_VIDEO_INCLUDE_BITRATE_ADJUSTER_H_
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "absl/types/optional.h"
+#include "rtc_base/rate_statistics.h"
+#include "rtc_base/synchronization/mutex.h"
+#include "rtc_base/system/rtc_export.h"
+#include "rtc_base/thread_annotations.h"
+
+namespace webrtc {
+
+// 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 RTC_EXPORT BitrateAdjuster {
+ public:
+ // min_adjusted_bitrate_pct and max_adjusted_bitrate_pct are the lower and
+ // upper bound outputted adjusted bitrates as a percentage of the target
+ // bitrate.
+ BitrateAdjuster(float min_adjusted_bitrate_pct,
+ float max_adjusted_bitrate_pct);
+ virtual ~BitrateAdjuster() {}
+
+ static const uint32_t kBitrateUpdateIntervalMs;
+ static const uint32_t kBitrateUpdateFrameInterval;
+ static const float kBitrateTolerancePct;
+ static const float kBytesPerMsToBitsPerSecond;
+
+ // Sets the desired bitrate in bps (bits per second).
+ // Should be called at least once before Update.
+ void SetTargetBitrateBps(uint32_t bitrate_bps);
+ uint32_t GetTargetBitrateBps() const;
+
+ // Returns the adjusted bitrate in bps.
+ uint32_t GetAdjustedBitrateBps() const;
+
+ // Returns what we think the current bitrate is.
+ absl::optional<uint32_t> GetEstimatedBitrateBps();
+
+ // 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:
+ // Returns true if the bitrate is within kBitrateTolerancePct of bitrate_bps.
+ bool IsWithinTolerance(uint32_t bitrate_bps, uint32_t target_bitrate_bps);
+
+ // Returns smallest possible adjusted value.
+ uint32_t GetMinAdjustedBitrateBps() const
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+ // Returns largest possible adjusted value.
+ uint32_t GetMaxAdjustedBitrateBps() const
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+
+ void Reset();
+ void UpdateBitrate(uint32_t current_time_ms)
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
+
+ mutable Mutex mutex_;
+ const float min_adjusted_bitrate_pct_;
+ const float max_adjusted_bitrate_pct_;
+ // The bitrate we want.
+ volatile uint32_t target_bitrate_bps_ RTC_GUARDED_BY(mutex_);
+ // The bitrate we use to get what we want.
+ volatile uint32_t adjusted_bitrate_bps_ RTC_GUARDED_BY(mutex_);
+ // The target bitrate that the adjusted bitrate was computed from.
+ volatile uint32_t last_adjusted_target_bitrate_bps_ RTC_GUARDED_BY(mutex_);
+ // Used to estimate bitrate.
+ RateStatistics bitrate_tracker_ RTC_GUARDED_BY(mutex_);
+ // The last time we tried to adjust the bitrate.
+ uint32_t last_bitrate_update_time_ms_ RTC_GUARDED_BY(mutex_);
+ // The number of frames since the last time we tried to adjust the bitrate.
+ uint32_t frames_since_last_update_ RTC_GUARDED_BY(mutex_);
+};
+
+} // namespace webrtc
+
+#endif // COMMON_VIDEO_INCLUDE_BITRATE_ADJUSTER_H_
diff --git a/third_party/libwebrtc/common_video/include/quality_limitation_reason.h b/third_party/libwebrtc/common_video/include/quality_limitation_reason.h
new file mode 100644
index 0000000000..068136a4b2
--- /dev/null
+++ b/third_party/libwebrtc/common_video/include/quality_limitation_reason.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2019 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 COMMON_VIDEO_INCLUDE_QUALITY_LIMITATION_REASON_H_
+#define COMMON_VIDEO_INCLUDE_QUALITY_LIMITATION_REASON_H_
+
+namespace webrtc {
+
+// https://w3c.github.io/webrtc-stats/#rtcqualitylimitationreason-enum
+enum class QualityLimitationReason {
+ kNone,
+ kCpu,
+ kBandwidth,
+ kOther,
+};
+
+} // namespace webrtc
+
+#endif // COMMON_VIDEO_INCLUDE_QUALITY_LIMITATION_REASON_H_
diff --git a/third_party/libwebrtc/common_video/include/video_frame_buffer.h b/third_party/libwebrtc/common_video/include/video_frame_buffer.h
new file mode 100644
index 0000000000..1f6331b94d
--- /dev/null
+++ b/third_party/libwebrtc/common_video/include/video_frame_buffer.h
@@ -0,0 +1,115 @@
+/*
+ * Copyright (c) 2015 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 COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_
+#define COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_
+
+#include <stdint.h>
+
+#include <functional>
+
+#include "api/scoped_refptr.h"
+#include "api/video/video_frame_buffer.h"
+
+namespace webrtc {
+
+rtc::scoped_refptr<I420BufferInterface> WrapI420Buffer(
+ int width,
+ int height,
+ const uint8_t* y_plane,
+ int y_stride,
+ const uint8_t* u_plane,
+ int u_stride,
+ const uint8_t* v_plane,
+ int v_stride,
+ std::function<void()> no_longer_used);
+
+rtc::scoped_refptr<I422BufferInterface> WrapI422Buffer(
+ int width,
+ int height,
+ const uint8_t* y_plane,
+ int y_stride,
+ const uint8_t* u_plane,
+ int u_stride,
+ const uint8_t* v_plane,
+ int v_stride,
+ std::function<void()> no_longer_used);
+
+rtc::scoped_refptr<I444BufferInterface> WrapI444Buffer(
+ int width,
+ int height,
+ const uint8_t* y_plane,
+ int y_stride,
+ const uint8_t* u_plane,
+ int u_stride,
+ const uint8_t* v_plane,
+ int v_stride,
+ std::function<void()> no_longer_used);
+
+rtc::scoped_refptr<I420ABufferInterface> WrapI420ABuffer(
+ int width,
+ int height,
+ const uint8_t* y_plane,
+ int y_stride,
+ const uint8_t* u_plane,
+ int u_stride,
+ const uint8_t* v_plane,
+ int v_stride,
+ const uint8_t* a_plane,
+ int a_stride,
+ std::function<void()> no_longer_used);
+
+rtc::scoped_refptr<PlanarYuvBuffer> WrapYuvBuffer(
+ VideoFrameBuffer::Type type,
+ int width,
+ int height,
+ const uint8_t* y_plane,
+ int y_stride,
+ const uint8_t* u_plane,
+ int u_stride,
+ const uint8_t* v_plane,
+ int v_stride,
+ std::function<void()> no_longer_used);
+
+rtc::scoped_refptr<I010BufferInterface> WrapI010Buffer(
+ int width,
+ int height,
+ const uint16_t* y_plane,
+ int y_stride,
+ const uint16_t* u_plane,
+ int u_stride,
+ const uint16_t* v_plane,
+ int v_stride,
+ std::function<void()> no_longer_used);
+
+rtc::scoped_refptr<I210BufferInterface> WrapI210Buffer(
+ int width,
+ int height,
+ const uint16_t* y_plane,
+ int y_stride,
+ const uint16_t* u_plane,
+ int u_stride,
+ const uint16_t* v_plane,
+ int v_stride,
+ std::function<void()> no_longer_used);
+
+rtc::scoped_refptr<I410BufferInterface> WrapI410Buffer(
+ int width,
+ int height,
+ const uint16_t* y_plane,
+ int y_stride,
+ const uint16_t* u_plane,
+ int u_stride,
+ const uint16_t* v_plane,
+ int v_stride,
+ std::function<void()> no_longer_used);
+} // namespace webrtc
+
+#endif // COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_
diff --git a/third_party/libwebrtc/common_video/include/video_frame_buffer_pool.h b/third_party/libwebrtc/common_video/include/video_frame_buffer_pool.h
new file mode 100644
index 0000000000..3d94bc5669
--- /dev/null
+++ b/third_party/libwebrtc/common_video/include/video_frame_buffer_pool.h
@@ -0,0 +1,84 @@
+/*
+ * Copyright (c) 2015 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 COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_POOL_H_
+#define COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_POOL_H_
+
+#include <stddef.h>
+
+#include <list>
+
+#include "api/scoped_refptr.h"
+#include "api/video/i010_buffer.h"
+#include "api/video/i210_buffer.h"
+#include "api/video/i410_buffer.h"
+#include "api/video/i420_buffer.h"
+#include "api/video/i422_buffer.h"
+#include "api/video/i444_buffer.h"
+#include "api/video/nv12_buffer.h"
+#include "rtc_base/race_checker.h"
+
+namespace webrtc {
+
+// Simple buffer pool to avoid unnecessary allocations of video frame buffers.
+// The pool manages the memory of the I420Buffer/NV12Buffer returned from
+// Create(I420|NV12)Buffer. When the buffer is destructed, the memory is
+// returned to the pool for use by subsequent calls to Create(I420|NV12)Buffer.
+// If the resolution passed to Create(I420|NV12)Buffer changes or requested
+// pixel format changes, old buffers will be purged from the pool.
+// Note that Create(I420|NV12)Buffer will crash if more than
+// kMaxNumberOfFramesBeforeCrash are created. This is to prevent memory leaks
+// where frames are not returned.
+class VideoFrameBufferPool {
+ public:
+ VideoFrameBufferPool();
+ explicit VideoFrameBufferPool(bool zero_initialize);
+ VideoFrameBufferPool(bool zero_initialize, size_t max_number_of_buffers);
+ ~VideoFrameBufferPool();
+
+ // Returns a buffer from the pool. If no suitable buffer exist in the pool
+ // and there are less than `max_number_of_buffers` pending, a buffer is
+ // created. Returns null otherwise.
+ rtc::scoped_refptr<I420Buffer> CreateI420Buffer(int width, int height);
+ rtc::scoped_refptr<I422Buffer> CreateI422Buffer(int width, int height);
+ rtc::scoped_refptr<I444Buffer> CreateI444Buffer(int width, int height);
+ rtc::scoped_refptr<I010Buffer> CreateI010Buffer(int width, int height);
+ rtc::scoped_refptr<I210Buffer> CreateI210Buffer(int width, int height);
+ rtc::scoped_refptr<I410Buffer> CreateI410Buffer(int width, int height);
+ rtc::scoped_refptr<NV12Buffer> CreateNV12Buffer(int width, int height);
+
+ // Changes the max amount of buffers in the pool to the new value.
+ // Returns true if change was successful and false if the amount of already
+ // allocated buffers is bigger than new value.
+ bool Resize(size_t max_number_of_buffers);
+
+ // Clears buffers_ and detaches the thread checker so that it can be reused
+ // later from another thread.
+ void Release();
+
+ private:
+ rtc::scoped_refptr<VideoFrameBuffer>
+ GetExistingBuffer(int width, int height, VideoFrameBuffer::Type type);
+
+ rtc::RaceChecker race_checker_;
+ std::list<rtc::scoped_refptr<VideoFrameBuffer>> buffers_;
+ // If true, newly allocated buffers are zero-initialized. Note that recycled
+ // buffers are not zero'd before reuse. This is required of buffers used by
+ // FFmpeg according to http://crbug.com/390941, which only requires it for the
+ // initial allocation (as shown by FFmpeg's own buffer allocation code). It
+ // has to do with "Use-of-uninitialized-value" on "Linux_msan_chrome".
+ const bool zero_initialize_;
+ // Max number of buffers this pool can have pending.
+ size_t max_number_of_buffers_;
+};
+
+} // namespace webrtc
+
+#endif // COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_POOL_H_