Migrate audio/ to use webrtc::Mutex

Bug: webrtc:11567
Change-Id: Ic6a753f09aafb508690f4b8dadd4c99433fcfeb6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176741
Reviewed-by: Sam Zackrisson <saza@webrtc.org>
Commit-Queue: Markus Handell <handellm@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31635}
This commit is contained in:
Markus Handell
2020-07-06 15:15:07 +02:00
committed by Commit Bot
parent afd1dcbde0
commit 6287280d64
17 changed files with 103 additions and 98 deletions

View File

@ -90,6 +90,7 @@ rtc_library("audio") {
"../rtc_base:rtc_task_queue", "../rtc_base:rtc_task_queue",
"../rtc_base:safe_minmax", "../rtc_base:safe_minmax",
"../rtc_base/experiments:field_trial_parser", "../rtc_base/experiments:field_trial_parser",
"../rtc_base/synchronization:mutex",
"../rtc_base/synchronization:sequence_checker", "../rtc_base/synchronization:sequence_checker",
"../rtc_base/task_utils:to_queued_task", "../rtc_base/task_utils:to_queued_task",
"../system_wrappers", "../system_wrappers",

View File

@ -22,7 +22,7 @@ AudioLevel::AudioLevel()
AudioLevel::~AudioLevel() {} AudioLevel::~AudioLevel() {}
void AudioLevel::Reset() { void AudioLevel::Reset() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
abs_max_ = 0; abs_max_ = 0;
count_ = 0; count_ = 0;
current_level_full_range_ = 0; current_level_full_range_ = 0;
@ -31,24 +31,24 @@ void AudioLevel::Reset() {
} }
int16_t AudioLevel::LevelFullRange() const { int16_t AudioLevel::LevelFullRange() const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return current_level_full_range_; return current_level_full_range_;
} }
void AudioLevel::ResetLevelFullRange() { void AudioLevel::ResetLevelFullRange() {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
abs_max_ = 0; abs_max_ = 0;
count_ = 0; count_ = 0;
current_level_full_range_ = 0; current_level_full_range_ = 0;
} }
double AudioLevel::TotalEnergy() const { double AudioLevel::TotalEnergy() const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return total_energy_; return total_energy_;
} }
double AudioLevel::TotalDuration() const { double AudioLevel::TotalDuration() const {
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
return total_duration_; return total_duration_;
} }
@ -63,7 +63,7 @@ void AudioLevel::ComputeLevel(const AudioFrame& audioFrame, double duration) {
// Protect member access using a lock since this method is called on a // Protect member access using a lock since this method is called on a
// dedicated audio thread in the RecordedDataIsAvailable() callback. // dedicated audio thread in the RecordedDataIsAvailable() callback.
rtc::CritScope cs(&crit_sect_); MutexLock lock(&mutex_);
if (abs_value > abs_max_) if (abs_value > abs_max_)
abs_max_ = abs_value; abs_max_ = abs_value;

View File

@ -11,7 +11,7 @@
#ifndef AUDIO_AUDIO_LEVEL_H_ #ifndef AUDIO_AUDIO_LEVEL_H_
#define AUDIO_AUDIO_LEVEL_H_ #define AUDIO_AUDIO_LEVEL_H_
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
namespace webrtc { namespace webrtc {
@ -59,14 +59,14 @@ class AudioLevel {
private: private:
enum { kUpdateFrequency = 10 }; enum { kUpdateFrequency = 10 };
rtc::CriticalSection crit_sect_; mutable Mutex mutex_;
int16_t abs_max_ RTC_GUARDED_BY(crit_sect_); int16_t abs_max_ RTC_GUARDED_BY(mutex_);
int16_t count_ RTC_GUARDED_BY(crit_sect_); int16_t count_ RTC_GUARDED_BY(mutex_);
int16_t current_level_full_range_ RTC_GUARDED_BY(crit_sect_); int16_t current_level_full_range_ RTC_GUARDED_BY(mutex_);
double total_energy_ RTC_GUARDED_BY(crit_sect_) = 0.0; double total_energy_ RTC_GUARDED_BY(mutex_) = 0.0;
double total_duration_ RTC_GUARDED_BY(crit_sect_) = 0.0; double total_duration_ RTC_GUARDED_BY(mutex_) = 0.0;
}; };
} // namespace voe } // namespace voe

View File

@ -347,7 +347,7 @@ void AudioSendStream::ConfigureStream(
// Set currently known overhead (used in ANA, opus only). // Set currently known overhead (used in ANA, opus only).
{ {
rtc::CritScope cs(&overhead_per_packet_lock_); MutexLock lock(&overhead_per_packet_lock_);
UpdateOverheadForEncoder(); UpdateOverheadForEncoder();
} }
@ -422,7 +422,7 @@ void AudioSendStream::SendAudioData(std::unique_ptr<AudioFrame> audio_frame) {
// TODO(https://crbug.com/webrtc/10771): All "media-source" related stats // TODO(https://crbug.com/webrtc/10771): All "media-source" related stats
// should move from send-streams to the local audio sources or tracks; a // should move from send-streams to the local audio sources or tracks; a
// send-stream should not be required to read the microphone audio levels. // send-stream should not be required to read the microphone audio levels.
rtc::CritScope cs(&audio_level_lock_); MutexLock lock(&audio_level_lock_);
audio_level_.ComputeLevel(*audio_frame, duration); audio_level_.ComputeLevel(*audio_frame, duration);
} }
channel_send_->ProcessAndEncodeAudio(std::move(audio_frame)); channel_send_->ProcessAndEncodeAudio(std::move(audio_frame));
@ -488,7 +488,7 @@ webrtc::AudioSendStream::Stats AudioSendStream::GetStats(
} }
{ {
rtc::CritScope cs(&audio_level_lock_); MutexLock lock(&audio_level_lock_);
stats.audio_level = audio_level_.LevelFullRange(); stats.audio_level = audio_level_.LevelFullRange();
stats.total_input_energy = audio_level_.TotalEnergy(); stats.total_input_energy = audio_level_.TotalEnergy();
stats.total_input_duration = audio_level_.TotalDuration(); stats.total_input_duration = audio_level_.TotalDuration();
@ -513,7 +513,7 @@ void AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
worker_queue_->PostTask([&]() { worker_queue_->PostTask([&]() {
// Poll if overhead has changed, which it can do if ack triggers us to stop // Poll if overhead has changed, which it can do if ack triggers us to stop
// sending mid/rid. // sending mid/rid.
rtc::CritScope cs(&overhead_per_packet_lock_); MutexLock lock(&overhead_per_packet_lock_);
UpdateOverheadForEncoder(); UpdateOverheadForEncoder();
}); });
} }
@ -538,7 +538,7 @@ uint32_t AudioSendStream::OnBitrateUpdated(BitrateAllocationUpdate update) {
void AudioSendStream::SetTransportOverhead( void AudioSendStream::SetTransportOverhead(
int transport_overhead_per_packet_bytes) { int transport_overhead_per_packet_bytes) {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
rtc::CritScope cs(&overhead_per_packet_lock_); MutexLock lock(&overhead_per_packet_lock_);
transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes; transport_overhead_per_packet_bytes_ = transport_overhead_per_packet_bytes;
UpdateOverheadForEncoder(); UpdateOverheadForEncoder();
} }
@ -570,7 +570,7 @@ void AudioSendStream::UpdateOverheadForEncoder() {
} }
size_t AudioSendStream::TestOnlyGetPerPacketOverheadBytes() const { size_t AudioSendStream::TestOnlyGetPerPacketOverheadBytes() const {
rtc::CritScope cs(&overhead_per_packet_lock_); MutexLock lock(&overhead_per_packet_lock_);
return GetPerPacketOverheadBytes(); return GetPerPacketOverheadBytes();
} }
@ -670,7 +670,7 @@ bool AudioSendStream::SetupSendCodec(const Config& new_config) {
// Set currently known overhead (used in ANA, opus only). // Set currently known overhead (used in ANA, opus only).
// If overhead changes later, it will be updated in UpdateOverheadForEncoder. // If overhead changes later, it will be updated in UpdateOverheadForEncoder.
{ {
rtc::CritScope cs(&overhead_per_packet_lock_); MutexLock lock(&overhead_per_packet_lock_);
size_t overhead = GetPerPacketOverheadBytes(); size_t overhead = GetPerPacketOverheadBytes();
if (overhead > 0) { if (overhead > 0) {
encoder->OnReceivedOverhead(overhead); encoder->OnReceivedOverhead(overhead);

View File

@ -24,6 +24,7 @@
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/experiments/struct_parameters_parser.h" #include "rtc_base/experiments/struct_parameters_parser.h"
#include "rtc_base/race_checker.h" #include "rtc_base/race_checker.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
@ -166,7 +167,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
int encoder_sample_rate_hz_ = 0; int encoder_sample_rate_hz_ = 0;
size_t encoder_num_channels_ = 0; size_t encoder_num_channels_ = 0;
bool sending_ = false; bool sending_ = false;
rtc::CriticalSection audio_level_lock_; mutable Mutex audio_level_lock_;
// Keeps track of audio level, total audio energy and total samples duration. // Keeps track of audio level, total audio energy and total samples duration.
// https://w3c.github.io/webrtc-stats/#dom-rtcaudiohandlerstats-totalaudioenergy // https://w3c.github.io/webrtc-stats/#dom-rtcaudiohandlerstats-totalaudioenergy
webrtc::voe::AudioLevel audio_level_; webrtc::voe::AudioLevel audio_level_;
@ -194,7 +195,7 @@ class AudioSendStream final : public webrtc::AudioSendStream,
const std::vector<RtpExtension>& extensions); const std::vector<RtpExtension>& extensions);
static int TransportSeqNumId(const Config& config); static int TransportSeqNumId(const Config& config);
rtc::CriticalSection overhead_per_packet_lock_; mutable Mutex overhead_per_packet_lock_;
size_t overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_) = 0; size_t overhead_per_packet_ RTC_GUARDED_BY(overhead_per_packet_lock_) = 0;
// Current transport overhead (ICE, TURN, etc.) // Current transport overhead (ICE, TURN, etc.)

View File

@ -118,7 +118,7 @@ int32_t AudioTransportImpl::RecordedDataIsAvailable(
size_t send_num_channels = 0; size_t send_num_channels = 0;
bool swap_stereo_channels = false; bool swap_stereo_channels = false;
{ {
rtc::CritScope lock(&capture_lock_); MutexLock lock(&capture_lock_);
send_sample_rate_hz = send_sample_rate_hz_; send_sample_rate_hz = send_sample_rate_hz_;
send_num_channels = send_num_channels_; send_num_channels = send_num_channels_;
swap_stereo_channels = swap_stereo_channels_; swap_stereo_channels = swap_stereo_channels_;
@ -149,7 +149,7 @@ int32_t AudioTransportImpl::RecordedDataIsAvailable(
// Copy frame and push to each sending stream. The copy is required since an // Copy frame and push to each sending stream. The copy is required since an
// encoding task will be posted internally to each stream. // encoding task will be posted internally to each stream.
{ {
rtc::CritScope lock(&capture_lock_); MutexLock lock(&capture_lock_);
typing_noise_detected_ = typing_detected; typing_noise_detected_ = typing_detected;
RTC_DCHECK_GT(audio_frame->samples_per_channel_, 0); RTC_DCHECK_GT(audio_frame->samples_per_channel_, 0);
@ -237,19 +237,19 @@ void AudioTransportImpl::PullRenderData(int bits_per_sample,
void AudioTransportImpl::UpdateAudioSenders(std::vector<AudioSender*> senders, void AudioTransportImpl::UpdateAudioSenders(std::vector<AudioSender*> senders,
int send_sample_rate_hz, int send_sample_rate_hz,
size_t send_num_channels) { size_t send_num_channels) {
rtc::CritScope lock(&capture_lock_); MutexLock lock(&capture_lock_);
audio_senders_ = std::move(senders); audio_senders_ = std::move(senders);
send_sample_rate_hz_ = send_sample_rate_hz; send_sample_rate_hz_ = send_sample_rate_hz;
send_num_channels_ = send_num_channels; send_num_channels_ = send_num_channels;
} }
void AudioTransportImpl::SetStereoChannelSwapping(bool enable) { void AudioTransportImpl::SetStereoChannelSwapping(bool enable) {
rtc::CritScope lock(&capture_lock_); MutexLock lock(&capture_lock_);
swap_stereo_channels_ = enable; swap_stereo_channels_ = enable;
} }
bool AudioTransportImpl::typing_noise_detected() const { bool AudioTransportImpl::typing_noise_detected() const {
rtc::CritScope lock(&capture_lock_); MutexLock lock(&capture_lock_);
return typing_noise_detected_; return typing_noise_detected_;
} }
} // namespace webrtc } // namespace webrtc

View File

@ -20,7 +20,7 @@
#include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/include/audio_processing.h"
#include "modules/audio_processing/typing_detection.h" #include "modules/audio_processing/typing_detection.h"
#include "rtc_base/constructor_magic.h" #include "rtc_base/constructor_magic.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h" #include "rtc_base/thread_annotations.h"
namespace webrtc { namespace webrtc {
@ -71,7 +71,7 @@ class AudioTransportImpl : public AudioTransport {
AudioProcessing* audio_processing_ = nullptr; AudioProcessing* audio_processing_ = nullptr;
// Capture side. // Capture side.
rtc::CriticalSection capture_lock_; mutable Mutex capture_lock_;
std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_); std::vector<AudioSender*> audio_senders_ RTC_GUARDED_BY(capture_lock_);
int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000; int send_sample_rate_hz_ RTC_GUARDED_BY(capture_lock_) = 8000;
size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1; size_t send_num_channels_ RTC_GUARDED_BY(capture_lock_) = 1;

View File

@ -40,12 +40,12 @@
#include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h" #include "modules/rtp_rtcp/source/rtp_rtcp_impl2.h"
#include "modules/utility/include/process_thread.h" #include "modules/utility/include/process_thread.h"
#include "rtc_base/checks.h" #include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/format_macros.h" #include "rtc_base/format_macros.h"
#include "rtc_base/location.h" #include "rtc_base/location.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h" #include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/race_checker.h" #include "rtc_base/race_checker.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
#include "system_wrappers/include/metrics.h" #include "system_wrappers/include/metrics.h"
@ -188,7 +188,7 @@ class ChannelReceive : public ChannelReceiveInterface {
rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer); rtc::scoped_refptr<webrtc::FrameTransformerInterface> frame_transformer);
bool Playing() const { bool Playing() const {
rtc::CritScope lock(&playing_lock_); MutexLock lock(&playing_lock_);
return playing_; return playing_;
} }
@ -204,10 +204,10 @@ class ChannelReceive : public ChannelReceiveInterface {
// audio thread to another, but access is still sequential. // audio thread to another, but access is still sequential.
rtc::RaceChecker audio_thread_race_checker_; rtc::RaceChecker audio_thread_race_checker_;
rtc::RaceChecker video_capture_thread_race_checker_; rtc::RaceChecker video_capture_thread_race_checker_;
rtc::CriticalSection _callbackCritSect; Mutex callback_mutex_;
rtc::CriticalSection volume_settings_critsect_; Mutex volume_settings_mutex_;
rtc::CriticalSection playing_lock_; mutable Mutex playing_lock_;
bool playing_ RTC_GUARDED_BY(&playing_lock_) = false; bool playing_ RTC_GUARDED_BY(&playing_lock_) = false;
RtcEventLog* const event_log_; RtcEventLog* const event_log_;
@ -221,7 +221,7 @@ class ChannelReceive : public ChannelReceiveInterface {
// Info for GetSyncInfo is updated on network or worker thread, and queried on // Info for GetSyncInfo is updated on network or worker thread, and queried on
// the worker thread. // the worker thread.
rtc::CriticalSection sync_info_lock_; mutable Mutex sync_info_lock_;
absl::optional<uint32_t> last_received_rtp_timestamp_ absl::optional<uint32_t> last_received_rtp_timestamp_
RTC_GUARDED_BY(&sync_info_lock_); RTC_GUARDED_BY(&sync_info_lock_);
absl::optional<int64_t> last_received_rtp_system_time_ms_ absl::optional<int64_t> last_received_rtp_system_time_ms_
@ -237,7 +237,7 @@ class ChannelReceive : public ChannelReceiveInterface {
// Timestamp of the audio pulled from NetEq. // Timestamp of the audio pulled from NetEq.
absl::optional<uint32_t> jitter_buffer_playout_timestamp_; absl::optional<uint32_t> jitter_buffer_playout_timestamp_;
rtc::CriticalSection video_sync_lock_; mutable Mutex video_sync_lock_;
uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_); uint32_t playout_timestamp_rtp_ RTC_GUARDED_BY(video_sync_lock_);
absl::optional<int64_t> playout_timestamp_rtp_time_ms_ absl::optional<int64_t> playout_timestamp_rtp_time_ms_
RTC_GUARDED_BY(video_sync_lock_); RTC_GUARDED_BY(video_sync_lock_);
@ -247,7 +247,7 @@ class ChannelReceive : public ChannelReceiveInterface {
absl::optional<int64_t> playout_timestamp_ntp_time_ms_ absl::optional<int64_t> playout_timestamp_ntp_time_ms_
RTC_GUARDED_BY(video_sync_lock_); RTC_GUARDED_BY(video_sync_lock_);
rtc::CriticalSection ts_stats_lock_; mutable Mutex ts_stats_lock_;
std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_; std::unique_ptr<rtc::TimestampWrapAroundHandler> rtp_ts_wraparound_handler_;
// The rtp timestamp of the first played out audio frame. // The rtp timestamp of the first played out audio frame.
@ -259,10 +259,10 @@ class ChannelReceive : public ChannelReceiveInterface {
// uses // uses
ProcessThread* _moduleProcessThreadPtr; ProcessThread* _moduleProcessThreadPtr;
AudioDeviceModule* _audioDeviceModulePtr; AudioDeviceModule* _audioDeviceModulePtr;
float _outputGain RTC_GUARDED_BY(volume_settings_critsect_); float _outputGain RTC_GUARDED_BY(volume_settings_mutex_);
// An associated send channel. // An associated send channel.
rtc::CriticalSection assoc_send_channel_lock_; mutable Mutex assoc_send_channel_lock_;
const ChannelSendInterface* associated_send_channel_ const ChannelSendInterface* associated_send_channel_
RTC_GUARDED_BY(assoc_send_channel_lock_); RTC_GUARDED_BY(assoc_send_channel_lock_);
@ -359,7 +359,7 @@ AudioMixer::Source::AudioFrameInfo ChannelReceive::GetAudioFrameWithInfo(
// scaling/panning, as that applies to the mix operation. // scaling/panning, as that applies to the mix operation.
// External recipients of the audio (e.g. via AudioTrack), will do their // External recipients of the audio (e.g. via AudioTrack), will do their
// own mixing/dynamic processing. // own mixing/dynamic processing.
rtc::CritScope cs(&_callbackCritSect); MutexLock lock(&callback_mutex_);
if (audio_sink_) { if (audio_sink_) {
AudioSinkInterface::Data data( AudioSinkInterface::Data data(
audio_frame->data(), audio_frame->samples_per_channel_, audio_frame->data(), audio_frame->samples_per_channel_,
@ -371,7 +371,7 @@ AudioMixer::Source::AudioFrameInfo ChannelReceive::GetAudioFrameWithInfo(
float output_gain = 1.0f; float output_gain = 1.0f;
{ {
rtc::CritScope cs(&volume_settings_critsect_); MutexLock lock(&volume_settings_mutex_);
output_gain = _outputGain; output_gain = _outputGain;
} }
@ -403,7 +403,7 @@ AudioMixer::Source::AudioFrameInfo ChannelReceive::GetAudioFrameWithInfo(
(GetRtpTimestampRateHz() / 1000); (GetRtpTimestampRateHz() / 1000);
{ {
rtc::CritScope lock(&ts_stats_lock_); MutexLock lock(&ts_stats_lock_);
// Compute ntp time. // Compute ntp time.
audio_frame->ntp_time_ms_ = audio_frame->ntp_time_ms_ =
ntp_estimator_.Estimate(audio_frame->timestamp_); ntp_estimator_.Estimate(audio_frame->timestamp_);
@ -421,7 +421,7 @@ AudioMixer::Source::AudioFrameInfo ChannelReceive::GetAudioFrameWithInfo(
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.TargetJitterBufferDelayMs", RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.TargetJitterBufferDelayMs",
acm_receiver_.TargetDelayMs()); acm_receiver_.TargetDelayMs());
const int jitter_buffer_delay = acm_receiver_.FilteredCurrentDelayMs(); const int jitter_buffer_delay = acm_receiver_.FilteredCurrentDelayMs();
rtc::CritScope lock(&video_sync_lock_); MutexLock lock(&video_sync_lock_);
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverDelayEstimateMs", RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverDelayEstimateMs",
jitter_buffer_delay + playout_delay_ms_); jitter_buffer_delay + playout_delay_ms_);
RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverJitterBufferDelayMs", RTC_HISTOGRAM_COUNTS_1000("WebRTC.Audio.ReceiverJitterBufferDelayMs",
@ -532,19 +532,19 @@ ChannelReceive::~ChannelReceive() {
void ChannelReceive::SetSink(AudioSinkInterface* sink) { void ChannelReceive::SetSink(AudioSinkInterface* sink) {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
rtc::CritScope cs(&_callbackCritSect); MutexLock lock(&callback_mutex_);
audio_sink_ = sink; audio_sink_ = sink;
} }
void ChannelReceive::StartPlayout() { void ChannelReceive::StartPlayout() {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
rtc::CritScope lock(&playing_lock_); MutexLock lock(&playing_lock_);
playing_ = true; playing_ = true;
} }
void ChannelReceive::StopPlayout() { void ChannelReceive::StopPlayout() {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
rtc::CritScope lock(&playing_lock_); MutexLock lock(&playing_lock_);
playing_ = false; playing_ = false;
_outputAudioLevel.ResetLevelFullRange(); _outputAudioLevel.ResetLevelFullRange();
} }
@ -570,7 +570,7 @@ void ChannelReceive::OnRtpPacket(const RtpPacketReceived& packet) {
int64_t now_ms = rtc::TimeMillis(); int64_t now_ms = rtc::TimeMillis();
{ {
rtc::CritScope cs(&sync_info_lock_); MutexLock lock(&sync_info_lock_);
last_received_rtp_timestamp_ = packet.Timestamp(); last_received_rtp_timestamp_ = packet.Timestamp();
last_received_rtp_system_time_ms_ = now_ms; last_received_rtp_system_time_ms_ = now_ms;
} }
@ -677,7 +677,7 @@ void ChannelReceive::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
} }
{ {
rtc::CritScope lock(&ts_stats_lock_); MutexLock lock(&ts_stats_lock_);
ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
} }
} }
@ -699,7 +699,7 @@ double ChannelReceive::GetTotalOutputDuration() const {
void ChannelReceive::SetChannelOutputVolumeScaling(float scaling) { void ChannelReceive::SetChannelOutputVolumeScaling(float scaling) {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
rtc::CritScope cs(&volume_settings_critsect_); MutexLock lock(&volume_settings_mutex_);
_outputGain = scaling; _outputGain = scaling;
} }
@ -759,7 +759,7 @@ CallReceiveStatistics ChannelReceive::GetRTCPStatistics() const {
// --- Timestamps // --- Timestamps
{ {
rtc::CritScope lock(&ts_stats_lock_); MutexLock lock(&ts_stats_lock_);
stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_; stats.capture_start_ntp_time_ms_ = capture_start_ntp_time_ms_;
} }
return stats; return stats;
@ -787,7 +787,7 @@ int ChannelReceive::ResendPackets(const uint16_t* sequence_numbers,
void ChannelReceive::SetAssociatedSendChannel( void ChannelReceive::SetAssociatedSendChannel(
const ChannelSendInterface* channel) { const ChannelSendInterface* channel) {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
rtc::CritScope lock(&assoc_send_channel_lock_); MutexLock lock(&assoc_send_channel_lock_);
associated_send_channel_ = channel; associated_send_channel_ = channel;
} }
@ -818,7 +818,7 @@ AudioDecodingCallStats ChannelReceive::GetDecodingCallStatistics() const {
uint32_t ChannelReceive::GetDelayEstimate() const { uint32_t ChannelReceive::GetDelayEstimate() const {
RTC_DCHECK(worker_thread_checker_.IsCurrent() || RTC_DCHECK(worker_thread_checker_.IsCurrent() ||
module_process_thread_checker_.IsCurrent()); module_process_thread_checker_.IsCurrent());
rtc::CritScope lock(&video_sync_lock_); MutexLock lock(&video_sync_lock_);
return acm_receiver_.FilteredCurrentDelayMs() + playout_delay_ms_; return acm_receiver_.FilteredCurrentDelayMs() + playout_delay_ms_;
} }
@ -838,7 +838,7 @@ bool ChannelReceive::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
int64_t* time_ms) const { int64_t* time_ms) const {
RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_); RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
{ {
rtc::CritScope lock(&video_sync_lock_); MutexLock lock(&video_sync_lock_);
if (!playout_timestamp_rtp_time_ms_) if (!playout_timestamp_rtp_time_ms_)
return false; return false;
*rtp_timestamp = playout_timestamp_rtp_; *rtp_timestamp = playout_timestamp_rtp_;
@ -850,7 +850,7 @@ bool ChannelReceive::GetPlayoutRtpTimestamp(uint32_t* rtp_timestamp,
void ChannelReceive::SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms, void ChannelReceive::SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
int64_t time_ms) { int64_t time_ms) {
RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_); RTC_DCHECK_RUNS_SERIALIZED(&video_capture_thread_race_checker_);
rtc::CritScope lock(&video_sync_lock_); MutexLock lock(&video_sync_lock_);
playout_timestamp_ntp_ = ntp_timestamp_ms; playout_timestamp_ntp_ = ntp_timestamp_ms;
playout_timestamp_ntp_time_ms_ = time_ms; playout_timestamp_ntp_time_ms_ = time_ms;
} }
@ -858,7 +858,7 @@ void ChannelReceive::SetEstimatedPlayoutNtpTimestampMs(int64_t ntp_timestamp_ms,
absl::optional<int64_t> absl::optional<int64_t>
ChannelReceive::GetCurrentEstimatedPlayoutNtpTimestampMs(int64_t now_ms) const { ChannelReceive::GetCurrentEstimatedPlayoutNtpTimestampMs(int64_t now_ms) const {
RTC_DCHECK(worker_thread_checker_.IsCurrent()); RTC_DCHECK(worker_thread_checker_.IsCurrent());
rtc::CritScope lock(&video_sync_lock_); MutexLock lock(&video_sync_lock_);
if (!playout_timestamp_ntp_ || !playout_timestamp_ntp_time_ms_) if (!playout_timestamp_ntp_ || !playout_timestamp_ntp_time_ms_)
return absl::nullopt; return absl::nullopt;
@ -883,7 +883,7 @@ absl::optional<Syncable::Info> ChannelReceive::GetSyncInfo() const {
return absl::nullopt; return absl::nullopt;
} }
{ {
rtc::CritScope cs(&sync_info_lock_); MutexLock lock(&sync_info_lock_);
if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) { if (!last_received_rtp_timestamp_ || !last_received_rtp_system_time_ms_) {
return absl::nullopt; return absl::nullopt;
} }
@ -917,7 +917,7 @@ void ChannelReceive::UpdatePlayoutTimestamp(bool rtcp, int64_t now_ms) {
playout_timestamp -= (delay_ms * (GetRtpTimestampRateHz() / 1000)); playout_timestamp -= (delay_ms * (GetRtpTimestampRateHz() / 1000));
{ {
rtc::CritScope lock(&video_sync_lock_); MutexLock lock(&video_sync_lock_);
if (!rtcp && playout_timestamp != playout_timestamp_rtp_) { if (!rtcp && playout_timestamp != playout_timestamp_rtp_) {
playout_timestamp_rtp_ = playout_timestamp; playout_timestamp_rtp_ = playout_timestamp;
playout_timestamp_rtp_time_ms_ = now_ms; playout_timestamp_rtp_time_ms_ = now_ms;
@ -947,7 +947,7 @@ int64_t ChannelReceive::GetRTT() const {
// TODO(nisse): Could we check the return value from the ->RTT() call below, // TODO(nisse): Could we check the return value from the ->RTT() call below,
// instead of checking if we have any report blocks? // instead of checking if we have any report blocks?
if (report_blocks.empty()) { if (report_blocks.empty()) {
rtc::CritScope lock(&assoc_send_channel_lock_); MutexLock lock(&assoc_send_channel_lock_);
// Tries to get RTT from an associated channel. // Tries to get RTT from an associated channel.
if (!associated_send_channel_) { if (!associated_send_channel_) {
return 0; return 0;

View File

@ -39,6 +39,7 @@
#include "rtc_base/numerics/safe_conversions.h" #include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/race_checker.h" #include "rtc_base/race_checker.h"
#include "rtc_base/rate_limiter.h" #include "rtc_base/rate_limiter.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
@ -186,7 +187,7 @@ class ChannelSend : public ChannelSendInterface,
// audio thread to another, but access is still sequential. // audio thread to another, but access is still sequential.
rtc::RaceChecker audio_thread_race_checker_; rtc::RaceChecker audio_thread_race_checker_;
rtc::CriticalSection volume_settings_critsect_; mutable Mutex volume_settings_mutex_;
bool sending_ RTC_GUARDED_BY(&worker_thread_checker_) = false; bool sending_ RTC_GUARDED_BY(&worker_thread_checker_) = false;
@ -201,7 +202,7 @@ class ChannelSend : public ChannelSendInterface,
// uses // uses
ProcessThread* const _moduleProcessThreadPtr; ProcessThread* const _moduleProcessThreadPtr;
RmsLevel rms_level_ RTC_GUARDED_BY(encoder_queue_); RmsLevel rms_level_ RTC_GUARDED_BY(encoder_queue_);
bool input_mute_ RTC_GUARDED_BY(volume_settings_critsect_); bool input_mute_ RTC_GUARDED_BY(volume_settings_mutex_);
bool previous_frame_muted_ RTC_GUARDED_BY(encoder_queue_); bool previous_frame_muted_ RTC_GUARDED_BY(encoder_queue_);
// VoeRTP_RTCP // VoeRTP_RTCP
// TODO(henrika): can today be accessed on the main thread and on the // TODO(henrika): can today be accessed on the main thread and on the
@ -234,8 +235,8 @@ class ChannelSend : public ChannelSendInterface,
rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> rtc::scoped_refptr<ChannelSendFrameTransformerDelegate>
frame_transformer_delegate_ RTC_GUARDED_BY(encoder_queue_); frame_transformer_delegate_ RTC_GUARDED_BY(encoder_queue_);
rtc::CriticalSection bitrate_crit_section_; mutable Mutex bitrate_mutex_;
int configured_bitrate_bps_ RTC_GUARDED_BY(bitrate_crit_section_) = 0; int configured_bitrate_bps_ RTC_GUARDED_BY(bitrate_mutex_) = 0;
// Defined last to ensure that there are no running tasks when the other // Defined last to ensure that there are no running tasks when the other
// members are destroyed. // members are destroyed.
@ -250,20 +251,20 @@ class RtpPacketSenderProxy : public RtpPacketSender {
void SetPacketPacer(RtpPacketSender* rtp_packet_pacer) { void SetPacketPacer(RtpPacketSender* rtp_packet_pacer) {
RTC_DCHECK(thread_checker_.IsCurrent()); RTC_DCHECK(thread_checker_.IsCurrent());
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
rtp_packet_pacer_ = rtp_packet_pacer; rtp_packet_pacer_ = rtp_packet_pacer;
} }
void EnqueuePackets( void EnqueuePackets(
std::vector<std::unique_ptr<RtpPacketToSend>> packets) override { std::vector<std::unique_ptr<RtpPacketToSend>> packets) override {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
rtp_packet_pacer_->EnqueuePackets(std::move(packets)); rtp_packet_pacer_->EnqueuePackets(std::move(packets));
} }
private: private:
rtc::ThreadChecker thread_checker_; rtc::ThreadChecker thread_checker_;
rtc::CriticalSection crit_; Mutex mutex_;
RtpPacketSender* rtp_packet_pacer_ RTC_GUARDED_BY(&crit_); RtpPacketSender* rtp_packet_pacer_ RTC_GUARDED_BY(&mutex_);
}; };
class VoERtcpObserver : public RtcpBandwidthObserver { class VoERtcpObserver : public RtcpBandwidthObserver {
@ -273,12 +274,12 @@ class VoERtcpObserver : public RtcpBandwidthObserver {
~VoERtcpObserver() override {} ~VoERtcpObserver() override {}
void SetBandwidthObserver(RtcpBandwidthObserver* bandwidth_observer) { void SetBandwidthObserver(RtcpBandwidthObserver* bandwidth_observer) {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
bandwidth_observer_ = bandwidth_observer; bandwidth_observer_ = bandwidth_observer;
} }
void OnReceivedEstimatedBitrate(uint32_t bitrate) override { void OnReceivedEstimatedBitrate(uint32_t bitrate) override {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
if (bandwidth_observer_) { if (bandwidth_observer_) {
bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate); bandwidth_observer_->OnReceivedEstimatedBitrate(bitrate);
} }
@ -288,7 +289,7 @@ class VoERtcpObserver : public RtcpBandwidthObserver {
int64_t rtt, int64_t rtt,
int64_t now_ms) override { int64_t now_ms) override {
{ {
rtc::CritScope lock(&crit_); MutexLock lock(&mutex_);
if (bandwidth_observer_) { if (bandwidth_observer_) {
bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, rtt, bandwidth_observer_->OnReceivedRtcpReceiverReport(report_blocks, rtt,
now_ms); now_ms);
@ -336,8 +337,8 @@ class VoERtcpObserver : public RtcpBandwidthObserver {
ChannelSend* owner_; ChannelSend* owner_;
// Maps remote side ssrc to extended highest sequence number received. // Maps remote side ssrc to extended highest sequence number received.
std::map<uint32_t, uint32_t> extended_max_sequence_number_; std::map<uint32_t, uint32_t> extended_max_sequence_number_;
rtc::CriticalSection crit_; Mutex mutex_;
RtcpBandwidthObserver* bandwidth_observer_ RTC_GUARDED_BY(crit_); RtcpBandwidthObserver* bandwidth_observer_ RTC_GUARDED_BY(mutex_);
}; };
int32_t ChannelSend::SendData(AudioFrameType frameType, int32_t ChannelSend::SendData(AudioFrameType frameType,
@ -606,7 +607,7 @@ void ChannelSend::OnBitrateAllocation(BitrateAllocationUpdate update) {
// rules. // rules.
// RTC_DCHECK(worker_thread_checker_.IsCurrent() || // RTC_DCHECK(worker_thread_checker_.IsCurrent() ||
// module_process_thread_checker_.IsCurrent()); // module_process_thread_checker_.IsCurrent());
rtc::CritScope lock(&bitrate_crit_section_); MutexLock lock(&bitrate_mutex_);
CallEncoder([&](AudioEncoder* encoder) { CallEncoder([&](AudioEncoder* encoder) {
encoder->OnReceivedUplinkAllocation(update); encoder->OnReceivedUplinkAllocation(update);
@ -616,7 +617,7 @@ void ChannelSend::OnBitrateAllocation(BitrateAllocationUpdate update) {
} }
int ChannelSend::GetBitrate() const { int ChannelSend::GetBitrate() const {
rtc::CritScope lock(&bitrate_crit_section_); MutexLock lock(&bitrate_mutex_);
return configured_bitrate_bps_; return configured_bitrate_bps_;
} }
@ -651,12 +652,12 @@ void ChannelSend::ReceivedRTCPPacket(const uint8_t* data, size_t length) {
void ChannelSend::SetInputMute(bool enable) { void ChannelSend::SetInputMute(bool enable) {
RTC_DCHECK_RUN_ON(&worker_thread_checker_); RTC_DCHECK_RUN_ON(&worker_thread_checker_);
rtc::CritScope cs(&volume_settings_critsect_); MutexLock lock(&volume_settings_mutex_);
input_mute_ = enable; input_mute_ = enable;
} }
bool ChannelSend::InputMute() const { bool ChannelSend::InputMute() const {
rtc::CritScope cs(&volume_settings_critsect_); MutexLock lock(&volume_settings_mutex_);
return input_mute_; return input_mute_;
} }

View File

@ -77,7 +77,7 @@ void ChannelSendFrameTransformerDelegate::Reset() {
frame_transformer_->UnregisterTransformedFrameCallback(); frame_transformer_->UnregisterTransformedFrameCallback();
frame_transformer_ = nullptr; frame_transformer_ = nullptr;
rtc::CritScope lock(&send_lock_); MutexLock lock(&send_lock_);
send_frame_callback_ = SendFrameCallback(); send_frame_callback_ = SendFrameCallback();
} }
@ -97,7 +97,7 @@ void ChannelSendFrameTransformerDelegate::Transform(
void ChannelSendFrameTransformerDelegate::OnTransformedFrame( void ChannelSendFrameTransformerDelegate::OnTransformedFrame(
std::unique_ptr<TransformableFrameInterface> frame) { std::unique_ptr<TransformableFrameInterface> frame) {
rtc::CritScope lock(&send_lock_); MutexLock lock(&send_lock_);
if (!send_frame_callback_) if (!send_frame_callback_)
return; return;
rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = this; rtc::scoped_refptr<ChannelSendFrameTransformerDelegate> delegate = this;
@ -109,7 +109,7 @@ void ChannelSendFrameTransformerDelegate::OnTransformedFrame(
void ChannelSendFrameTransformerDelegate::SendFrame( void ChannelSendFrameTransformerDelegate::SendFrame(
std::unique_ptr<TransformableFrameInterface> frame) const { std::unique_ptr<TransformableFrameInterface> frame) const {
rtc::CritScope lock(&send_lock_); MutexLock lock(&send_lock_);
RTC_DCHECK_RUN_ON(encoder_queue_); RTC_DCHECK_RUN_ON(encoder_queue_);
if (!send_frame_callback_) if (!send_frame_callback_)
return; return;

View File

@ -16,7 +16,7 @@
#include "api/frame_transformer_interface.h" #include "api/frame_transformer_interface.h"
#include "modules/audio_coding/include/audio_coding_module_typedefs.h" #include "modules/audio_coding/include/audio_coding_module_typedefs.h"
#include "rtc_base/buffer.h" #include "rtc_base/buffer.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/synchronization/sequence_checker.h" #include "rtc_base/synchronization/sequence_checker.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
@ -72,7 +72,7 @@ class ChannelSendFrameTransformerDelegate : public TransformedFrameCallback {
~ChannelSendFrameTransformerDelegate() override = default; ~ChannelSendFrameTransformerDelegate() override = default;
private: private:
rtc::CriticalSection send_lock_; mutable Mutex send_lock_;
SendFrameCallback send_frame_callback_ RTC_GUARDED_BY(send_lock_); SendFrameCallback send_frame_callback_ RTC_GUARDED_BY(send_lock_);
rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_; rtc::scoped_refptr<FrameTransformerInterface> frame_transformer_;
rtc::TaskQueue* encoder_queue_ RTC_GUARDED_BY(send_lock_); rtc::TaskQueue* encoder_queue_ RTC_GUARDED_BY(send_lock_);

View File

@ -26,6 +26,7 @@ rtc_library("voip_core") {
"../../modules/utility:utility", "../../modules/utility:utility",
"../../rtc_base:criticalsection", "../../rtc_base:criticalsection",
"../../rtc_base:logging", "../../rtc_base:logging",
"../../rtc_base/synchronization:mutex",
] ]
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ] absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
} }
@ -74,6 +75,7 @@ rtc_library("audio_ingress") {
"../../rtc_base:logging", "../../rtc_base:logging",
"../../rtc_base:safe_minmax", "../../rtc_base:safe_minmax",
"../../rtc_base:timeutils", "../../rtc_base:timeutils",
"../../rtc_base/synchronization:mutex",
"../utility:audio_frame_operations", "../utility:audio_frame_operations",
] ]
} }
@ -95,6 +97,7 @@ rtc_library("audio_egress") {
"../../rtc_base:rtc_task_queue", "../../rtc_base:rtc_task_queue",
"../../rtc_base:thread_checker", "../../rtc_base:thread_checker",
"../../rtc_base:timeutils", "../../rtc_base:timeutils",
"../../rtc_base/synchronization:mutex",
"../utility:audio_frame_operations", "../utility:audio_frame_operations",
] ]
} }

View File

@ -22,6 +22,7 @@
#include "modules/rtp_rtcp/include/report_block_data.h" #include "modules/rtp_rtcp/include/report_block_data.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
#include "modules/rtp_rtcp/source/rtp_sender_audio.h" #include "modules/rtp_rtcp/source/rtp_sender_audio.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue.h" #include "rtc_base/task_queue.h"
#include "rtc_base/thread_checker.h" #include "rtc_base/thread_checker.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
@ -72,7 +73,7 @@ class AudioEgress : public AudioSender, public AudioPacketizationCallback {
// Retrieve current encoder format info. This returns encoder format set // Retrieve current encoder format info. This returns encoder format set
// by SetEncoder() and if encoder is not set, this will return nullopt. // by SetEncoder() and if encoder is not set, this will return nullopt.
absl::optional<SdpAudioFormat> GetEncoderFormat() const { absl::optional<SdpAudioFormat> GetEncoderFormat() const {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
return encoder_format_; return encoder_format_;
} }
@ -99,11 +100,11 @@ class AudioEgress : public AudioSender, public AudioPacketizationCallback {
private: private:
void SetEncoderFormat(const SdpAudioFormat& encoder_format) { void SetEncoderFormat(const SdpAudioFormat& encoder_format) {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
encoder_format_ = encoder_format; encoder_format_ = encoder_format;
} }
rtc::CriticalSection lock_; mutable Mutex lock_;
// Current encoder format selected by caller. // Current encoder format selected by caller.
absl::optional<SdpAudioFormat> encoder_format_ RTC_GUARDED_BY(lock_); absl::optional<SdpAudioFormat> encoder_format_ RTC_GUARDED_BY(lock_);

View File

@ -17,7 +17,6 @@
#include "api/audio_codecs/audio_format.h" #include "api/audio_codecs/audio_format.h"
#include "audio/utility/audio_frame_operations.h" #include "audio/utility/audio_frame_operations.h"
#include "modules/audio_coding/include/audio_coding_module.h" #include "modules/audio_coding/include/audio_coding_module.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_minmax.h" #include "rtc_base/numerics/safe_minmax.h"
@ -83,7 +82,7 @@ AudioMixer::Source::AudioFrameInfo AudioIngress::GetAudioFrameWithInfo(
// Compute elapsed and NTP times. // Compute elapsed and NTP times.
int64_t unwrap_timestamp; int64_t unwrap_timestamp;
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
unwrap_timestamp = unwrap_timestamp =
timestamp_wrap_handler_.Unwrap(audio_frame->timestamp_); timestamp_wrap_handler_.Unwrap(audio_frame->timestamp_);
audio_frame->ntp_time_ms_ = audio_frame->ntp_time_ms_ =
@ -107,7 +106,7 @@ AudioMixer::Source::AudioFrameInfo AudioIngress::GetAudioFrameWithInfo(
void AudioIngress::SetReceiveCodecs( void AudioIngress::SetReceiveCodecs(
const std::map<int, SdpAudioFormat>& codecs) { const std::map<int, SdpAudioFormat>& codecs) {
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
for (const auto& kv : codecs) { for (const auto& kv : codecs) {
receive_codec_info_[kv.first] = kv.second.clockrate_hz; receive_codec_info_[kv.first] = kv.second.clockrate_hz;
} }
@ -125,7 +124,7 @@ void AudioIngress::ReceivedRTPPacket(rtc::ArrayView<const uint8_t> rtp_packet) {
// Set payload type's sampling rate before we feed it into ReceiveStatistics. // Set payload type's sampling rate before we feed it into ReceiveStatistics.
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
const auto& it = const auto& it =
receive_codec_info_.find(rtp_packet_received.PayloadType()); receive_codec_info_.find(rtp_packet_received.PayloadType());
// If sampling rate info is not available in our received codec set, it // If sampling rate info is not available in our received codec set, it
@ -185,7 +184,7 @@ void AudioIngress::ReceivedRTCPPacket(
} }
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp); ntp_estimator_.UpdateRtcpTimestamp(rtt, ntp_secs, ntp_frac, rtp_timestamp);
} }
} }

View File

@ -28,7 +28,7 @@
#include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h" #include "modules/rtp_rtcp/include/remote_ntp_time_estimator.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h" #include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h" #include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h" #include "rtc_base/time_utils.h"
namespace webrtc { namespace webrtc {
@ -131,7 +131,7 @@ class AudioIngress : public AudioMixer::Source {
// Synchronizaton is handled internally by voe::AudioLevel. // Synchronizaton is handled internally by voe::AudioLevel.
voe::AudioLevel output_audio_level_; voe::AudioLevel output_audio_level_;
rtc::CriticalSection lock_; Mutex lock_;
RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(lock_); RemoteNtpTimeEstimator ntp_estimator_ RTC_GUARDED_BY(lock_);

View File

@ -15,7 +15,6 @@
#include <utility> #include <utility>
#include "api/audio_codecs/audio_format.h" #include "api/audio_codecs/audio_format.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h" #include "rtc_base/logging.h"
namespace webrtc { namespace webrtc {
@ -134,7 +133,7 @@ absl::optional<ChannelId> VoipCore::CreateChannel(
process_thread_.get(), audio_mixer_.get(), decoder_factory_); process_thread_.get(), audio_mixer_.get(), decoder_factory_);
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
channel = static_cast<ChannelId>(next_channel_id_); channel = static_cast<ChannelId>(next_channel_id_);
channels_[*channel] = audio_channel; channels_[*channel] = audio_channel;
@ -154,7 +153,7 @@ void VoipCore::ReleaseChannel(ChannelId channel) {
// Destroy channel outside of the lock. // Destroy channel outside of the lock.
rtc::scoped_refptr<AudioChannel> audio_channel; rtc::scoped_refptr<AudioChannel> audio_channel;
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
auto iter = channels_.find(channel); auto iter = channels_.find(channel);
if (iter != channels_.end()) { if (iter != channels_.end()) {
@ -170,7 +169,7 @@ void VoipCore::ReleaseChannel(ChannelId channel) {
rtc::scoped_refptr<AudioChannel> VoipCore::GetChannel(ChannelId channel) { rtc::scoped_refptr<AudioChannel> VoipCore::GetChannel(ChannelId channel) {
rtc::scoped_refptr<AudioChannel> audio_channel; rtc::scoped_refptr<AudioChannel> audio_channel;
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
auto iter = channels_.find(channel); auto iter = channels_.find(channel);
if (iter != channels_.end()) { if (iter != channels_.end()) {
audio_channel = iter->second; audio_channel = iter->second;
@ -191,7 +190,7 @@ bool VoipCore::UpdateAudioTransportWithSenders() {
int max_sampling_rate = 8000; int max_sampling_rate = 8000;
size_t max_num_channels = 1; size_t max_num_channels = 1;
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
// Reserve to prevent run time vector re-allocation. // Reserve to prevent run time vector re-allocation.
audio_senders.reserve(channels_.size()); audio_senders.reserve(channels_.size());
for (auto kv : channels_) { for (auto kv : channels_) {
@ -290,7 +289,7 @@ bool VoipCore::StopPlayout(ChannelId channel) {
bool stop_device = true; bool stop_device = true;
{ {
rtc::CritScope lock(&lock_); MutexLock lock(&lock_);
for (auto kv : channels_) { for (auto kv : channels_) {
rtc::scoped_refptr<AudioChannel>& channel = kv.second; rtc::scoped_refptr<AudioChannel>& channel = kv.second;
if (channel->IsPlaying()) { if (channel->IsPlaying()) {

View File

@ -31,7 +31,7 @@
#include "modules/audio_mixer/audio_mixer_impl.h" #include "modules/audio_mixer/audio_mixer_impl.h"
#include "modules/audio_processing/include/audio_processing.h" #include "modules/audio_processing/include/audio_processing.h"
#include "modules/utility/include/process_thread.h" #include "modules/utility/include/process_thread.h"
#include "rtc_base/critical_section.h" #include "rtc_base/synchronization/mutex.h"
namespace webrtc { namespace webrtc {
@ -123,7 +123,7 @@ class VoipCore : public VoipEngine,
// Must be placed before |channels_| for proper destruction. // Must be placed before |channels_| for proper destruction.
std::unique_ptr<ProcessThread> process_thread_; std::unique_ptr<ProcessThread> process_thread_;
rtc::CriticalSection lock_; Mutex lock_;
// Member to track a next ChannelId for new AudioChannel. // Member to track a next ChannelId for new AudioChannel.
int next_channel_id_ RTC_GUARDED_BY(lock_) = 0; int next_channel_id_ RTC_GUARDED_BY(lock_) = 0;