Introduces rtc_base/synchronization/mutex.h.
This change introduces a new non-reentrant mutex to WebRTC. It enables eventual migration to Abseil's mutex. The mutex types supportable by webrtc::Mutex are - absl::Mutex - CriticalSection (Windows only) - pthread_mutex (POSIX only) In addition to introducing the mutexes, the CL also changes PacketBuffer to use the new mutex instead of rtc::CriticalSection. The method of yielding from critical_section.cc was given a mini-cleanup and YieldCurrentThread() was added to rtc_base/synchronization/yield.h/cc. Additionally, google_benchmark benchmarks for the mutexes were added (test courtesy of danilchap@), and some results from a pthread/Abseil shootout were added showing Abseil has the advantage in higher contention. Bug: webrtc:11567, webrtc:11634 Change-Id: Iaec324ccb32ec3851bf6db3fd290f5ea5dee4c81 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176230 Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Tommi <tommi@webrtc.org> Reviewed-by: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#31443}
This commit is contained in:

committed by
Commit Bot

parent
e917379c5b
commit
f70fbc8411
@ -22,8 +22,8 @@
|
||||
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
|
||||
#include "modules/rtp_rtcp/source/rtp_video_header.h"
|
||||
#include "rtc_base/copy_on_write_buffer.h"
|
||||
#include "rtc_base/critical_section.h"
|
||||
#include "rtc_base/numerics/sequence_number_util.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "rtc_base/thread_annotations.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
|
||||
@ -83,67 +83,67 @@ class PacketBuffer {
|
||||
~PacketBuffer();
|
||||
|
||||
InsertResult InsertPacket(std::unique_ptr<Packet> packet) ABSL_MUST_USE_RESULT
|
||||
RTC_LOCKS_EXCLUDED(crit_);
|
||||
RTC_LOCKS_EXCLUDED(mutex_);
|
||||
InsertResult InsertPadding(uint16_t seq_num) ABSL_MUST_USE_RESULT
|
||||
RTC_LOCKS_EXCLUDED(crit_);
|
||||
void ClearTo(uint16_t seq_num) RTC_LOCKS_EXCLUDED(crit_);
|
||||
void Clear() RTC_LOCKS_EXCLUDED(crit_);
|
||||
RTC_LOCKS_EXCLUDED(mutex_);
|
||||
void ClearTo(uint16_t seq_num) RTC_LOCKS_EXCLUDED(mutex_);
|
||||
void Clear() RTC_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
// Timestamp (not RTP timestamp) of the last received packet/keyframe packet.
|
||||
absl::optional<int64_t> LastReceivedPacketMs() const
|
||||
RTC_LOCKS_EXCLUDED(crit_);
|
||||
RTC_LOCKS_EXCLUDED(mutex_);
|
||||
absl::optional<int64_t> LastReceivedKeyframePacketMs() const
|
||||
RTC_LOCKS_EXCLUDED(crit_);
|
||||
RTC_LOCKS_EXCLUDED(mutex_);
|
||||
|
||||
private:
|
||||
Clock* const clock_;
|
||||
|
||||
// Clears with |crit_| taken.
|
||||
void ClearInternal() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
// Clears with |mutex_| taken.
|
||||
void ClearInternal() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// Tries to expand the buffer.
|
||||
bool ExpandBufferSize() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
bool ExpandBufferSize() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// Test if all previous packets has arrived for the given sequence number.
|
||||
bool PotentialNewFrame(uint16_t seq_num) const
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
// Test if all packets of a frame has arrived, and if so, returns packets to
|
||||
// create frames.
|
||||
std::vector<std::unique_ptr<Packet>> FindFrames(uint16_t seq_num)
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
void UpdateMissingPackets(uint16_t seq_num)
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_);
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
|
||||
|
||||
rtc::CriticalSection crit_;
|
||||
mutable Mutex mutex_;
|
||||
|
||||
// buffer_.size() and max_size_ must always be a power of two.
|
||||
const size_t max_size_;
|
||||
|
||||
// The fist sequence number currently in the buffer.
|
||||
uint16_t first_seq_num_ RTC_GUARDED_BY(crit_);
|
||||
uint16_t first_seq_num_ RTC_GUARDED_BY(mutex_);
|
||||
|
||||
// If the packet buffer has received its first packet.
|
||||
bool first_packet_received_ RTC_GUARDED_BY(crit_);
|
||||
bool first_packet_received_ RTC_GUARDED_BY(mutex_);
|
||||
|
||||
// If the buffer is cleared to |first_seq_num_|.
|
||||
bool is_cleared_to_first_seq_num_ RTC_GUARDED_BY(crit_);
|
||||
bool is_cleared_to_first_seq_num_ RTC_GUARDED_BY(mutex_);
|
||||
|
||||
// Buffer that holds the the inserted packets and information needed to
|
||||
// determine continuity between them.
|
||||
std::vector<std::unique_ptr<Packet>> buffer_ RTC_GUARDED_BY(crit_);
|
||||
std::vector<std::unique_ptr<Packet>> buffer_ RTC_GUARDED_BY(mutex_);
|
||||
|
||||
// Timestamp of the last received packet/keyframe packet.
|
||||
absl::optional<int64_t> last_received_packet_ms_ RTC_GUARDED_BY(crit_);
|
||||
absl::optional<int64_t> last_received_packet_ms_ RTC_GUARDED_BY(mutex_);
|
||||
absl::optional<int64_t> last_received_keyframe_packet_ms_
|
||||
RTC_GUARDED_BY(crit_);
|
||||
RTC_GUARDED_BY(mutex_);
|
||||
absl::optional<uint32_t> last_received_keyframe_rtp_timestamp_
|
||||
RTC_GUARDED_BY(crit_);
|
||||
RTC_GUARDED_BY(mutex_);
|
||||
|
||||
absl::optional<uint16_t> newest_inserted_seq_num_ RTC_GUARDED_BY(crit_);
|
||||
absl::optional<uint16_t> newest_inserted_seq_num_ RTC_GUARDED_BY(mutex_);
|
||||
std::set<uint16_t, DescendingSeqNumComp<uint16_t>> missing_packets_
|
||||
RTC_GUARDED_BY(crit_);
|
||||
RTC_GUARDED_BY(mutex_);
|
||||
|
||||
// Indicates if we should require SPS, PPS, and IDR for a particular
|
||||
// RTP timestamp to treat the corresponding frame as a keyframe.
|
||||
|
Reference in New Issue
Block a user