Migrate modules/audio_coding, audio_mixer/ and audio_processing/ to webrtc::Mutex.
Bug: webrtc:11567
Change-Id: I03b78bd2e411e9bcca199f85e4457511826cd17e
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176745
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Magnus Flodman <mflodman@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31649}
diff --git a/modules/audio_coding/neteq/neteq_impl.h b/modules/audio_coding/neteq/neteq_impl.h
index 623968a..0ade6b5 100644
--- a/modules/audio_coding/neteq/neteq_impl.h
+++ b/modules/audio_coding/neteq/neteq_impl.h
@@ -30,7 +30,7 @@
#include "modules/audio_coding/neteq/random_vector.h"
#include "modules/audio_coding/neteq/statistics_calculator.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"
namespace webrtc {
@@ -210,14 +210,14 @@
// TODO(hlundin): Merge this with InsertPacket above?
int InsertPacketInternal(const RTPHeader& rtp_header,
rtc::ArrayView<const uint8_t> payload)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Delivers 10 ms of audio data. The data is written to |audio_frame|.
// Returns 0 on success, otherwise an error code.
int GetAudioInternal(AudioFrame* audio_frame,
bool* muted,
absl::optional<Operation> action_override)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Provides a decision to the GetAudioInternal method. The decision what to
// do is written to |operation|. Packets to decode are written to
@@ -229,7 +229,7 @@
DtmfEvent* dtmf_event,
bool* play_dtmf,
absl::optional<Operation> action_override)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Decodes the speech packets in |packet_list|, and writes the results to
// |decoded_buffer|, which is allocated to hold |decoded_buffer_length|
@@ -241,13 +241,13 @@
Operation* operation,
int* decoded_length,
AudioDecoder::SpeechType* speech_type)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method to Decode(). Performs codec internal CNG.
int DecodeCng(AudioDecoder* decoder,
int* decoded_length,
AudioDecoder::SpeechType* speech_type)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method to Decode(). Performs the actual decoding.
int DecodeLoop(PacketList* packet_list,
@@ -255,24 +255,24 @@
AudioDecoder* decoder,
int* decoded_length,
AudioDecoder::SpeechType* speech_type)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Normal class to perform the normal operation.
void DoNormal(const int16_t* decoded_buffer,
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
- bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Merge class to perform the merge operation.
void DoMerge(int16_t* decoded_buffer,
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
- bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
- bool DoCodecPlc() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool DoCodecPlc() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Expand class to perform the expand operation.
- int DoExpand(bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ int DoExpand(bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the Accelerate class to perform the accelerate
// operation.
@@ -280,144 +280,136 @@
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
bool play_dtmf,
- bool fast_accelerate)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool fast_accelerate) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the PreemptiveExpand class to perform the
// preemtive expand operation.
int DoPreemptiveExpand(int16_t* decoded_buffer,
size_t decoded_length,
AudioDecoder::SpeechType speech_type,
- bool play_dtmf)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ bool play_dtmf) RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Sub-method which calls the ComfortNoise class to generate RFC 3389 comfort
// noise. |packet_list| can either contain one SID frame to update the
// noise parameters, or no payload at all, in which case the previously
// received parameters are used.
int DoRfc3389Cng(PacketList* packet_list, bool play_dtmf)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Calls the audio decoder to generate codec-internal comfort noise when
// no packet was received.
void DoCodecInternalCng(const int16_t* decoded_buffer, size_t decoded_length)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Calls the DtmfToneGenerator class to generate DTMF tones.
int DoDtmf(const DtmfEvent& dtmf_event, bool* play_dtmf)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Overdub DTMF on top of |output|.
int DtmfOverdub(const DtmfEvent& dtmf_event,
size_t num_channels,
- int16_t* output) const
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ int16_t* output) const RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Extracts packets from |packet_buffer_| to produce at least
// |required_samples| samples. The packets are inserted into |packet_list|.
// Returns the number of samples that the packets in the list will produce, or
// -1 in case of an error.
int ExtractPackets(size_t required_samples, PacketList* packet_list)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Resets various variables and objects to new values based on the sample rate
// |fs_hz| and |channels| number audio channels.
void SetSampleRateAndChannels(int fs_hz, size_t channels)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Returns the output type for the audio produced by the latest call to
// GetAudio().
- OutputType LastOutputType() RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ OutputType LastOutputType() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
// Updates Expand and Merge.
virtual void UpdatePlcComponents(int fs_hz, size_t channels)
- RTC_EXCLUSIVE_LOCKS_REQUIRED(crit_sect_);
+ RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
Clock* const clock_;
- rtc::CriticalSection crit_sect_;
- const std::unique_ptr<TickTimer> tick_timer_ RTC_GUARDED_BY(crit_sect_);
+ mutable Mutex mutex_;
+ const std::unique_ptr<TickTimer> tick_timer_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<DecoderDatabase> decoder_database_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<DtmfBuffer> dtmf_buffer_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<DtmfBuffer> dtmf_buffer_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<DtmfToneGenerator> dtmf_tone_generator_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<PacketBuffer> packet_buffer_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<PacketBuffer> packet_buffer_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<RedPayloadSplitter> red_payload_splitter_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<TimestampScaler> timestamp_scaler_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<PostDecodeVad> vad_ RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<ExpandFactory> expand_factory_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<PostDecodeVad> vad_ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<ExpandFactory> expand_factory_ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<AccelerateFactory> accelerate_factory_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
const std::unique_ptr<PreemptiveExpandFactory> preemptive_expand_factory_
- RTC_GUARDED_BY(crit_sect_);
- const std::unique_ptr<StatisticsCalculator> stats_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ const std::unique_ptr<StatisticsCalculator> stats_ RTC_GUARDED_BY(mutex_);
- std::unique_ptr<BackgroundNoise> background_noise_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<NetEqController> controller_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<AudioMultiVector> algorithm_buffer_
- RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<SyncBuffer> sync_buffer_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Expand> expand_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Normal> normal_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Merge> merge_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<Accelerate> accelerate_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<PreemptiveExpand> preemptive_expand_
- RTC_GUARDED_BY(crit_sect_);
- RandomVector random_vector_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<ComfortNoise> comfort_noise_ RTC_GUARDED_BY(crit_sect_);
- int fs_hz_ RTC_GUARDED_BY(crit_sect_);
- int fs_mult_ RTC_GUARDED_BY(crit_sect_);
- int last_output_sample_rate_hz_ RTC_GUARDED_BY(crit_sect_);
- size_t output_size_samples_ RTC_GUARDED_BY(crit_sect_);
- size_t decoder_frame_length_ RTC_GUARDED_BY(crit_sect_);
- Mode last_mode_ RTC_GUARDED_BY(crit_sect_);
- Operation last_operation_ RTC_GUARDED_BY(crit_sect_);
- size_t decoded_buffer_length_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<int16_t[]> decoded_buffer_ RTC_GUARDED_BY(crit_sect_);
- uint32_t playout_timestamp_ RTC_GUARDED_BY(crit_sect_);
- bool new_codec_ RTC_GUARDED_BY(crit_sect_);
- uint32_t timestamp_ RTC_GUARDED_BY(crit_sect_);
- bool reset_decoder_ RTC_GUARDED_BY(crit_sect_);
- absl::optional<uint8_t> current_rtp_payload_type_ RTC_GUARDED_BY(crit_sect_);
- absl::optional<uint8_t> current_cng_rtp_payload_type_
- RTC_GUARDED_BY(crit_sect_);
- bool first_packet_ RTC_GUARDED_BY(crit_sect_);
- bool enable_fast_accelerate_ RTC_GUARDED_BY(crit_sect_);
- std::unique_ptr<NackTracker> nack_ RTC_GUARDED_BY(crit_sect_);
- bool nack_enabled_ RTC_GUARDED_BY(crit_sect_);
- const bool enable_muted_state_ RTC_GUARDED_BY(crit_sect_);
- AudioFrame::VADActivity last_vad_activity_ RTC_GUARDED_BY(crit_sect_) =
+ std::unique_ptr<BackgroundNoise> background_noise_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<NetEqController> controller_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<AudioMultiVector> algorithm_buffer_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<SyncBuffer> sync_buffer_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Expand> expand_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Normal> normal_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Merge> merge_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<Accelerate> accelerate_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<PreemptiveExpand> preemptive_expand_ RTC_GUARDED_BY(mutex_);
+ RandomVector random_vector_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<ComfortNoise> comfort_noise_ RTC_GUARDED_BY(mutex_);
+ int fs_hz_ RTC_GUARDED_BY(mutex_);
+ int fs_mult_ RTC_GUARDED_BY(mutex_);
+ int last_output_sample_rate_hz_ RTC_GUARDED_BY(mutex_);
+ size_t output_size_samples_ RTC_GUARDED_BY(mutex_);
+ size_t decoder_frame_length_ RTC_GUARDED_BY(mutex_);
+ Mode last_mode_ RTC_GUARDED_BY(mutex_);
+ Operation last_operation_ RTC_GUARDED_BY(mutex_);
+ size_t decoded_buffer_length_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<int16_t[]> decoded_buffer_ RTC_GUARDED_BY(mutex_);
+ uint32_t playout_timestamp_ RTC_GUARDED_BY(mutex_);
+ bool new_codec_ RTC_GUARDED_BY(mutex_);
+ uint32_t timestamp_ RTC_GUARDED_BY(mutex_);
+ bool reset_decoder_ RTC_GUARDED_BY(mutex_);
+ absl::optional<uint8_t> current_rtp_payload_type_ RTC_GUARDED_BY(mutex_);
+ absl::optional<uint8_t> current_cng_rtp_payload_type_ RTC_GUARDED_BY(mutex_);
+ bool first_packet_ RTC_GUARDED_BY(mutex_);
+ bool enable_fast_accelerate_ RTC_GUARDED_BY(mutex_);
+ std::unique_ptr<NackTracker> nack_ RTC_GUARDED_BY(mutex_);
+ bool nack_enabled_ RTC_GUARDED_BY(mutex_);
+ const bool enable_muted_state_ RTC_GUARDED_BY(mutex_);
+ AudioFrame::VADActivity last_vad_activity_ RTC_GUARDED_BY(mutex_) =
AudioFrame::kVadPassive;
std::unique_ptr<TickTimer::Stopwatch> generated_noise_stopwatch_
- RTC_GUARDED_BY(crit_sect_);
- std::vector<uint32_t> last_decoded_timestamps_ RTC_GUARDED_BY(crit_sect_);
- std::vector<RtpPacketInfo> last_decoded_packet_infos_
- RTC_GUARDED_BY(crit_sect_);
- ExpandUmaLogger expand_uma_logger_ RTC_GUARDED_BY(crit_sect_);
- ExpandUmaLogger speech_expand_uma_logger_ RTC_GUARDED_BY(crit_sect_);
- bool no_time_stretching_ RTC_GUARDED_BY(crit_sect_); // Only used for test.
- rtc::BufferT<int16_t> concealment_audio_ RTC_GUARDED_BY(crit_sect_);
- const bool enable_rtx_handling_ RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
+ std::vector<uint32_t> last_decoded_timestamps_ RTC_GUARDED_BY(mutex_);
+ std::vector<RtpPacketInfo> last_decoded_packet_infos_ RTC_GUARDED_BY(mutex_);
+ ExpandUmaLogger expand_uma_logger_ RTC_GUARDED_BY(mutex_);
+ ExpandUmaLogger speech_expand_uma_logger_ RTC_GUARDED_BY(mutex_);
+ bool no_time_stretching_ RTC_GUARDED_BY(mutex_); // Only used for test.
+ rtc::BufferT<int16_t> concealment_audio_ RTC_GUARDED_BY(mutex_);
+ const bool enable_rtx_handling_ RTC_GUARDED_BY(mutex_);
// Data members used for adding extra delay to the output of NetEq.
// The delay in ms (which is 10 times the number of elements in
// output_delay_chain_).
- const int output_delay_chain_ms_ RTC_GUARDED_BY(crit_sect_);
+ const int output_delay_chain_ms_ RTC_GUARDED_BY(mutex_);
// Vector of AudioFrames which contains the delayed audio. Accessed as a
// circular buffer.
- std::vector<AudioFrame> output_delay_chain_ RTC_GUARDED_BY(crit_sect_);
+ std::vector<AudioFrame> output_delay_chain_ RTC_GUARDED_BY(mutex_);
// Index into output_delay_chain_.
- size_t output_delay_chain_ix_ RTC_GUARDED_BY(crit_sect_) = 0;
+ size_t output_delay_chain_ix_ RTC_GUARDED_BY(mutex_) = 0;
// Did output_delay_chain_ get populated yet?
- bool output_delay_chain_empty_ RTC_GUARDED_BY(crit_sect_) = true;
+ bool output_delay_chain_empty_ RTC_GUARDED_BY(mutex_) = true;
// Contains the sample rate of the AudioFrame last emitted from the delay
// chain. If the extra output delay chain is not used, or if no audio has been
// emitted yet, the variable is empty.
absl::optional<int> delayed_last_output_sample_rate_hz_
- RTC_GUARDED_BY(crit_sect_);
+ RTC_GUARDED_BY(mutex_);
private:
RTC_DISALLOW_COPY_AND_ASSIGN(NetEqImpl);