diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/libwebrtc/common_video/include | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/common_video/include')
5 files changed, 352 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/incoming_video_stream.h b/third_party/libwebrtc/common_video/include/incoming_video_stream.h new file mode 100644 index 0000000000..d616c5a2ec --- /dev/null +++ b/third_party/libwebrtc/common_video/include/incoming_video_stream.h @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2012 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_INCOMING_VIDEO_STREAM_H_ +#define COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_H_ + +#include <stdint.h> + +#include "api/sequence_checker.h" +#include "api/task_queue/task_queue_factory.h" +#include "api/video/video_frame.h" +#include "api/video/video_sink_interface.h" +#include "common_video/video_render_frames.h" +#include "rtc_base/race_checker.h" +#include "rtc_base/task_queue.h" +#include "rtc_base/thread_annotations.h" + +namespace webrtc { + +class IncomingVideoStream : public rtc::VideoSinkInterface<VideoFrame> { + public: + IncomingVideoStream(TaskQueueFactory* task_queue_factory, + int32_t delay_ms, + rtc::VideoSinkInterface<VideoFrame>* callback); + ~IncomingVideoStream() override; + + private: + void OnFrame(const VideoFrame& video_frame) override; + void Dequeue(); + + SequenceChecker main_thread_checker_; + rtc::RaceChecker decoder_race_checker_; + + VideoRenderFrames render_buffers_ RTC_GUARDED_BY(&incoming_render_queue_); + rtc::VideoSinkInterface<VideoFrame>* const callback_; + rtc::TaskQueue incoming_render_queue_; +}; + +} // namespace webrtc + +#endif // COMMON_VIDEO_INCLUDE_INCOMING_VIDEO_STREAM_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..34a9bb5a37 --- /dev/null +++ b/third_party/libwebrtc/common_video/include/video_frame_buffer.h @@ -0,0 +1,104 @@ +/* + * 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); +} // 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..fd1bd164ec --- /dev/null +++ b/third_party/libwebrtc/common_video/include/video_frame_buffer_pool.h @@ -0,0 +1,82 @@ +/* + * 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/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<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_ |