diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /third_party/libwebrtc/webrtc/common_video/include | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/libwebrtc/webrtc/common_video/include')
7 files changed, 488 insertions, 0 deletions
diff --git a/third_party/libwebrtc/webrtc/common_video/include/bitrate_adjuster.h b/third_party/libwebrtc/webrtc/common_video/include/bitrate_adjuster.h new file mode 100644 index 0000000000..fd83555469 --- /dev/null +++ b/third_party/libwebrtc/webrtc/common_video/include/bitrate_adjuster.h @@ -0,0 +1,90 @@ +/* + * 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 <functional> + +#include "rtc_base/criticalsection.h" +#include "rtc_base/rate_statistics.h" + +namespace webrtc { + +class Clock; + +// 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: + // 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(Clock* clock, + 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. + rtc::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(crit_); + // Returns largest possible adjusted value. + uint32_t GetMaxAdjustedBitrateBps() const RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); + + void Reset(); + void UpdateBitrate(uint32_t current_time_ms) + RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_); + + rtc::CriticalSection crit_; + Clock* const clock_; + 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(crit_); + // The bitrate we use to get what we want. + volatile uint32_t adjusted_bitrate_bps_ RTC_GUARDED_BY(crit_); + // The target bitrate that the adjusted bitrate was computed from. + volatile uint32_t last_adjusted_target_bitrate_bps_ RTC_GUARDED_BY(crit_); + // Used to estimate bitrate. + RateStatistics bitrate_tracker_ RTC_GUARDED_BY(crit_); + // The last time we tried to adjust the bitrate. + uint32_t last_bitrate_update_time_ms_ RTC_GUARDED_BY(crit_); + // The number of frames since the last time we tried to adjust the bitrate. + uint32_t frames_since_last_update_ RTC_GUARDED_BY(crit_); +}; + +} // namespace webrtc + +#endif // COMMON_VIDEO_INCLUDE_BITRATE_ADJUSTER_H_ diff --git a/third_party/libwebrtc/webrtc/common_video/include/frame_callback.h b/third_party/libwebrtc/webrtc/common_video/include/frame_callback.h new file mode 100644 index 0000000000..2101965287 --- /dev/null +++ b/third_party/libwebrtc/webrtc/common_video/include/frame_callback.h @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2013 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_FRAME_CALLBACK_H_ +#define COMMON_VIDEO_INCLUDE_FRAME_CALLBACK_H_ + +#include <stddef.h> +#include <stdint.h> + +#include "common_types.h" // NOLINT(build/include) + +namespace webrtc { + +class VideoFrame; + +struct EncodedFrame { + public: + EncodedFrame() + : data_(nullptr), + length_(0), + frame_type_(kEmptyFrame), + stream_id_(0), + timestamp_(0) {} + EncodedFrame(const uint8_t* data, + size_t length, + FrameType frame_type, + size_t stream_id, + uint32_t timestamp) + : data_(data), + length_(length), + frame_type_(frame_type), + stream_id_(stream_id), + timestamp_(timestamp) {} + + const uint8_t* data_; + const size_t length_; + const FrameType frame_type_; + const size_t stream_id_; + const uint32_t timestamp_; +}; + +class EncodedFrameObserver { + public: + virtual void EncodedFrameCallback(const EncodedFrame& encoded_frame) = 0; + virtual void OnEncodeTiming(int64_t capture_ntp_ms, int encode_duration_ms) {} + + protected: + virtual ~EncodedFrameObserver() {} +}; + +} // namespace webrtc + +#endif // COMMON_VIDEO_INCLUDE_FRAME_CALLBACK_H_ diff --git a/third_party/libwebrtc/webrtc/common_video/include/i420_buffer_pool.h b/third_party/libwebrtc/webrtc/common_video/include/i420_buffer_pool.h new file mode 100644 index 0000000000..863eb10180 --- /dev/null +++ b/third_party/libwebrtc/webrtc/common_video/include/i420_buffer_pool.h @@ -0,0 +1,65 @@ +/* + * 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_I420_BUFFER_POOL_H_ +#define COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ + +#include <list> +#include <limits> + +#include "api/video/i420_buffer.h" +#include "rtc_base/race_checker.h" +#include "rtc_base/refcountedobject.h" + +namespace webrtc { + +// Simple buffer pool to avoid unnecessary allocations of I420Buffer objects. +// The pool manages the memory of the I420Buffer returned from CreateBuffer. +// When the I420Buffer is destructed, the memory is returned to the pool for use +// by subsequent calls to CreateBuffer. If the resolution passed to CreateBuffer +// changes, old buffers will be purged from the pool. +// Note that CreateBuffer will crash if more than kMaxNumberOfFramesBeforeCrash +// are created. This is to prevent memory leaks where frames are not returned. +class I420BufferPool { + public: + I420BufferPool() + : I420BufferPool(false) {} + explicit I420BufferPool(bool zero_initialize) + : I420BufferPool(zero_initialize, std::numeric_limits<size_t>::max()) {} + I420BufferPool(bool zero_initialze, size_t max_number_of_buffers); + + // 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> CreateBuffer(int width, int height); + // Clears buffers_ and detaches the thread checker so that it can be reused + // later from another thread. + void Release(); + + private: + // Explicitly use a RefCountedObject to get access to HasOneRef, + // needed by the pool to check exclusive access. + using PooledI420Buffer = rtc::RefCountedObject<I420Buffer>; + + rtc::RaceChecker race_checker_; + std::list<rtc::scoped_refptr<PooledI420Buffer>> 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. + const size_t max_number_of_buffers_; +}; + +} // namespace webrtc + +#endif // COMMON_VIDEO_INCLUDE_I420_BUFFER_POOL_H_ diff --git a/third_party/libwebrtc/webrtc/common_video/include/incoming_video_stream.h b/third_party/libwebrtc/webrtc/common_video/include/incoming_video_stream.h new file mode 100644 index 0000000000..7ae27a96a8 --- /dev/null +++ b/third_party/libwebrtc/webrtc/common_video/include/incoming_video_stream.h @@ -0,0 +1,44 @@ +/* + * 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 "common_video/video_render_frames.h" +#include "media/base/videosinkinterface.h" +#include "rtc_base/race_checker.h" +#include "rtc_base/task_queue.h" + +namespace webrtc { + +class IncomingVideoStream : public rtc::VideoSinkInterface<VideoFrame> { + public: + IncomingVideoStream(int32_t delay_ms, + rtc::VideoSinkInterface<VideoFrame>* callback); + ~IncomingVideoStream() override; + + private: + void OnFrame(const VideoFrame& video_frame) override; + void Dequeue(); + + // Fwd decl of a QueuedTask implementation for carrying frames over to the TQ. + class NewFrameTask; + + rtc::ThreadChecker main_thread_checker_; + rtc::RaceChecker decoder_race_checker_; + + VideoRenderFrames render_buffers_; // Only touched on the TaskQueue. + 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/webrtc/common_video/include/video_bitrate_allocator.h b/third_party/libwebrtc/webrtc/common_video/include/video_bitrate_allocator.h new file mode 100644 index 0000000000..597b6259a4 --- /dev/null +++ b/third_party/libwebrtc/webrtc/common_video/include/video_bitrate_allocator.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 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_VIDEO_BITRATE_ALLOCATOR_H_ +#define COMMON_VIDEO_INCLUDE_VIDEO_BITRATE_ALLOCATOR_H_ + +#include "common_types.h" // NOLINT(build/include) + +namespace webrtc { + +class VideoBitrateAllocator { + public: + VideoBitrateAllocator() {} + virtual ~VideoBitrateAllocator() {} + + virtual BitrateAllocation GetAllocation(uint32_t total_bitrate, + uint32_t framerate) = 0; + virtual uint32_t GetPreferredBitrateBps(uint32_t framerate) = 0; +}; + +class VideoBitrateAllocationObserver { + public: + VideoBitrateAllocationObserver() {} + virtual ~VideoBitrateAllocationObserver() {} + + virtual void OnBitrateAllocationUpdated( + const BitrateAllocation& allocation) = 0; +}; + +} // namespace webrtc + +#endif // COMMON_VIDEO_INCLUDE_VIDEO_BITRATE_ALLOCATOR_H_ diff --git a/third_party/libwebrtc/webrtc/common_video/include/video_frame.h b/third_party/libwebrtc/webrtc/common_video/include/video_frame.h new file mode 100644 index 0000000000..188d5e5260 --- /dev/null +++ b/third_party/libwebrtc/webrtc/common_video/include/video_frame.h @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2014 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_H_ +#define COMMON_VIDEO_INCLUDE_VIDEO_FRAME_H_ + +// TODO(nisse): This header file should eventually be deleted. The +// EncodedImage class stays in this file until we have figured out how +// to refactor and clean up related interfaces, at which point it +// should be moved to somewhere under api/. + +#include "common_types.h" // NOLINT(build/include) +#include "typedefs.h" // NOLINT(build/include) + +namespace webrtc { + +// TODO(pbos): Rename EncodedFrame and reformat this class' members. +class EncodedImage { + public: + static const size_t kBufferPaddingBytesH264; + + // Some decoders require encoded image buffers to be padded with a small + // number of additional bytes (due to over-reading byte readers). + static size_t GetBufferPaddingBytes(VideoCodecType codec_type); + + EncodedImage(); + EncodedImage(uint8_t* buffer, size_t length, size_t size); + + void SetEncodeTime(int64_t encode_start_ms, int64_t encode_finish_ms); + + // TODO(kthelgason): get rid of this struct as it only has a single member + // remaining. + struct AdaptReason { + AdaptReason() : bw_resolutions_disabled(-1) {} + int bw_resolutions_disabled; // Number of resolutions that are not sent + // due to bandwidth for this frame. + // Or -1 if information is not provided. + }; + uint32_t _encodedWidth = 0; + uint32_t _encodedHeight = 0; + uint32_t _timeStamp = 0; + // NTP time of the capture time in local timebase in milliseconds. + int64_t ntp_time_ms_ = 0; + int64_t capture_time_ms_ = 0; + FrameType _frameType = kVideoFrameDelta; + uint8_t* _buffer; + size_t _length; + size_t _size; + VideoRotation rotation_ = kVideoRotation_0; + VideoContentType content_type_ = VideoContentType::UNSPECIFIED; + bool _completeFrame = false; + AdaptReason adapt_reason_; + int qp_ = -1; // Quantizer value. + + // When an application indicates non-zero values here, it is taken as an + // indication that all future frames will be constrained with those limits + // until the application indicates a change again. + PlayoutDelay playout_delay_ = {-1, -1}; + + struct Timing { + uint8_t flags = TimingFrameFlags::kInvalid; + int64_t encode_start_ms = 0; + int64_t encode_finish_ms = 0; + int64_t packetization_finish_ms = 0; + int64_t pacer_exit_ms = 0; + int64_t network_timestamp_ms = 0; + int64_t network2_timestamp_ms = 0; + int64_t receive_start_ms = 0; + int64_t receive_finish_ms = 0; + } timing_; +}; + +} // namespace webrtc + +#endif // COMMON_VIDEO_INCLUDE_VIDEO_FRAME_H_ diff --git a/third_party/libwebrtc/webrtc/common_video/include/video_frame_buffer.h b/third_party/libwebrtc/webrtc/common_video/include/video_frame_buffer.h new file mode 100644 index 0000000000..312979b05d --- /dev/null +++ b/third_party/libwebrtc/webrtc/common_video/include/video_frame_buffer.h @@ -0,0 +1,108 @@ +/* + * 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 <memory> + +#include "api/video/video_frame_buffer.h" +#include "rtc_base/callback.h" +#include "rtc_base/scoped_ref_ptr.h" + +namespace webrtc { + +// Deprecated. Please use WrapI420Buffer(...) instead. +class WrappedI420Buffer : public I420BufferInterface { + public: + WrappedI420Buffer(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 rtc::Callback0<void>& no_longer_used); + int width() const override; + int height() const override; + + const uint8_t* DataY() const override; + const uint8_t* DataU() const override; + const uint8_t* DataV() const override; + int StrideY() const override; + int StrideU() const override; + int StrideV() const override; + + private: + friend class rtc::RefCountedObject<WrappedI420Buffer>; + ~WrappedI420Buffer() override; + + const int width_; + const int height_; + const uint8_t* const y_plane_; + const uint8_t* const u_plane_; + const uint8_t* const v_plane_; + const int y_stride_; + const int u_stride_; + const int v_stride_; + rtc::Callback0<void> no_longer_used_cb_; +}; + +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, + const rtc::Callback0<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, + const rtc::Callback0<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, + const rtc::Callback0<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, + const rtc::Callback0<void>& no_longer_used); + +} // namespace webrtc + +#endif // COMMON_VIDEO_INCLUDE_VIDEO_FRAME_BUFFER_H_ |