Migrate modules/audio_device to webrtc::Mutex.

Bug: webrtc:11567
Change-Id: I6d1a7145aaaae2e4cd0c8658fa31a673f857dbd6
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178814
Commit-Queue: Markus Handell <handellm@webrtc.org>
Reviewed-by: Magnus Flodman <mflodman@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31664}
This commit is contained in:
Markus Handell 2020-07-08 10:13:20 +02:00 committed by Commit Bot
parent adbfd1d985
commit 5f61282687
20 changed files with 223 additions and 227 deletions

View File

@ -73,6 +73,7 @@ rtc_library("audio_device_buffer") {
"../../rtc_base:checks",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_task_queue",
"../../rtc_base/synchronization:mutex",
"../../system_wrappers",
"../../system_wrappers:metrics",
]
@ -169,6 +170,7 @@ rtc_library("audio_device_impl") {
"../../rtc_base:deprecation",
"../../rtc_base:rtc_base_approved",
"../../rtc_base:rtc_task_queue",
"../../rtc_base/synchronization:mutex",
"../../rtc_base/system:arch",
"../../rtc_base/system:file_wrapper",
"../../rtc_base/task_utils:repeating_task",
@ -381,6 +383,7 @@ if (rtc_include_tests) {
"../../rtc_base:checks",
"../../rtc_base:ignore_wundef",
"../../rtc_base:rtc_base_approved",
"../../rtc_base/synchronization:mutex",
"../../system_wrappers",
"../../test:fileutils",
"../../test:test_support",

View File

@ -28,9 +28,9 @@
#include "modules/audio_device/audio_device_impl.h"
#include "modules/audio_device/include/mock_audio_transport.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/format_macros.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/time_utils.h"
#include "test/gmock.h"
#include "test/gtest.h"
@ -182,7 +182,7 @@ class FifoAudioStream : public AudioStreamInterface {
}
int16_t* memory = new int16_t[frames_per_buffer_];
memcpy(static_cast<int16_t*>(&memory[0]), source, bytes_per_buffer_);
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
fifo_->push_back(memory);
const size_t size = fifo_->size();
if (size > largest_size_) {
@ -198,7 +198,7 @@ class FifoAudioStream : public AudioStreamInterface {
void Read(void* destination, size_t num_frames) override {
ASSERT_EQ(num_frames, frames_per_buffer_);
PRINTD("-");
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
if (fifo_->empty()) {
memset(destination, 0, bytes_per_buffer_);
} else {
@ -229,7 +229,7 @@ class FifoAudioStream : public AudioStreamInterface {
}
using AudioBufferList = std::list<int16_t*>;
rtc::CriticalSection lock_;
Mutex lock_;
const size_t frames_per_buffer_;
const size_t bytes_per_buffer_;
std::unique_ptr<AudioBufferList> fifo_;

View File

@ -386,7 +386,7 @@ void AudioDeviceBuffer::LogStats(LogState state) {
Stats stats;
{
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
stats = stats_;
stats_.max_rec_level = 0;
stats_.max_play_level = 0;
@ -468,20 +468,20 @@ void AudioDeviceBuffer::LogStats(LogState state) {
void AudioDeviceBuffer::ResetRecStats() {
RTC_DCHECK_RUN_ON(&task_queue_);
last_stats_.ResetRecStats();
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
stats_.ResetRecStats();
}
void AudioDeviceBuffer::ResetPlayStats() {
RTC_DCHECK_RUN_ON(&task_queue_);
last_stats_.ResetPlayStats();
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
stats_.ResetPlayStats();
}
void AudioDeviceBuffer::UpdateRecStats(int16_t max_abs,
size_t samples_per_channel) {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
++stats_.rec_callbacks;
stats_.rec_samples += samples_per_channel;
if (max_abs > stats_.max_rec_level) {
@ -491,7 +491,7 @@ void AudioDeviceBuffer::UpdateRecStats(int16_t max_abs,
void AudioDeviceBuffer::UpdatePlayStats(int16_t max_abs,
size_t samples_per_channel) {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
++stats_.play_callbacks;
stats_.play_samples += samples_per_channel;
if (max_abs > stats_.max_play_level) {

View File

@ -19,7 +19,7 @@
#include "api/task_queue/task_queue_factory.h"
#include "modules/audio_device/include/audio_device_defines.h"
#include "rtc_base/buffer.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
@ -142,7 +142,7 @@ class AudioDeviceBuffer {
// Main thread on which this object is created.
rtc::ThreadChecker main_thread_checker_;
rtc::CriticalSection lock_;
Mutex lock_;
// Task queue used to invoke LogStats() periodically. Tasks are executed on a
// worker thread but it does not necessarily have to be the same thread for

View File

@ -25,11 +25,11 @@
#include "modules/audio_device/include/mock_audio_transport.h"
#include "rtc_base/arraysize.h"
#include "rtc_base/buffer.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/race_checker.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
#include "rtc_base/time_utils.h"
@ -39,6 +39,7 @@
#ifdef WEBRTC_WIN
#include "modules/audio_device/include/audio_device_factory.h"
#include "modules/audio_device/win/core_audio_utility_win.h"
#endif
using ::testing::_;
@ -137,7 +138,7 @@ class FifoAudioStream : public AudioStream {
void Write(rtc::ArrayView<const int16_t> source) override {
RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
const size_t size = [&] {
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
fifo_.push_back(Buffer16(source.data(), source.size()));
return fifo_.size();
}();
@ -152,7 +153,7 @@ class FifoAudioStream : public AudioStream {
}
void Read(rtc::ArrayView<int16_t> destination) override {
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
if (fifo_.empty()) {
std::fill(destination.begin(), destination.end(), 0);
} else {
@ -183,7 +184,7 @@ class FifoAudioStream : public AudioStream {
}
size_t size() const {
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
return fifo_.size();
}
@ -199,7 +200,7 @@ class FifoAudioStream : public AudioStream {
using Buffer16 = rtc::BufferT<int16_t>;
rtc::CriticalSection lock_;
mutable Mutex lock_;
rtc::RaceChecker race_checker_;
std::list<Buffer16> fifo_ RTC_GUARDED_BY(lock_);
@ -230,7 +231,7 @@ class LatencyAudioStream : public AudioStream {
if (read_count_ % (kNumCallbacksPerSecond / kImpulseFrequencyInHz) == 0) {
PRINT(".");
{
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
if (!pulse_time_) {
pulse_time_ = rtc::TimeMillis();
}
@ -245,7 +246,7 @@ class LatencyAudioStream : public AudioStream {
void Write(rtc::ArrayView<const int16_t> source) override {
RTC_DCHECK_RUN_ON(&write_thread_checker_);
RTC_DCHECK_RUNS_SERIALIZED(&race_checker_);
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
write_count_++;
if (!pulse_time_) {
// Avoid detection of new impulse response until a new impulse has
@ -315,7 +316,7 @@ class LatencyAudioStream : public AudioStream {
max_latency(), average_latency());
}
rtc::CriticalSection lock_;
Mutex lock_;
rtc::RaceChecker race_checker_;
rtc::ThreadChecker read_thread_checker_;
rtc::ThreadChecker write_thread_checker_;
@ -390,7 +391,7 @@ class MockAudioTransport : public test::MockAudioTransport {
record_parameters_.frames_per_10ms_buffer());
}
{
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
rec_count_++;
}
// Write audio data to audio stream object if one has been injected.
@ -430,7 +431,7 @@ class MockAudioTransport : public test::MockAudioTransport {
playout_parameters_.frames_per_10ms_buffer());
}
{
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
play_count_++;
}
samples_out = samples_per_channel * channels;
@ -453,14 +454,14 @@ class MockAudioTransport : public test::MockAudioTransport {
bool ReceivedEnoughCallbacks() {
bool recording_done = false;
if (rec_mode()) {
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
recording_done = rec_count_ >= num_callbacks_;
} else {
recording_done = true;
}
bool playout_done = false;
if (play_mode()) {
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
playout_done = play_count_ >= num_callbacks_;
} else {
playout_done = true;
@ -479,7 +480,7 @@ class MockAudioTransport : public test::MockAudioTransport {
}
void ResetCallbackCounters() {
rtc::CritScope lock(&lock_);
MutexLock lock(&lock_);
if (play_mode()) {
play_count_ = 0;
}
@ -489,7 +490,7 @@ class MockAudioTransport : public test::MockAudioTransport {
}
private:
rtc::CriticalSection lock_;
Mutex lock_;
TransportType type_ = TransportType::kInvalid;
rtc::Event* event_ = nullptr;
AudioStream* audio_stream_ = nullptr;

View File

@ -139,7 +139,7 @@ int32_t FileAudioDevice::PlayoutIsAvailable(bool& available) {
}
int32_t FileAudioDevice::InitPlayout() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playing) {
return -1;
@ -169,7 +169,7 @@ int32_t FileAudioDevice::RecordingIsAvailable(bool& available) {
}
int32_t FileAudioDevice::InitRecording() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_recording) {
return -1;
@ -228,7 +228,7 @@ int32_t FileAudioDevice::StartPlayout() {
int32_t FileAudioDevice::StopPlayout() {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_playing = false;
}
@ -238,7 +238,7 @@ int32_t FileAudioDevice::StopPlayout() {
_ptrThreadPlay.reset();
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_playoutFramesLeft = 0;
delete[] _playoutBuffer;
@ -289,7 +289,7 @@ int32_t FileAudioDevice::StartRecording() {
int32_t FileAudioDevice::StopRecording() {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_recording = false;
}
@ -298,7 +298,7 @@ int32_t FileAudioDevice::StopRecording() {
_ptrThreadRec.reset();
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_recordingFramesLeft = 0;
if (_recordingBuffer) {
delete[] _recordingBuffer;
@ -426,7 +426,7 @@ int32_t FileAudioDevice::PlayoutDelay(uint16_t& delayMS) const {
}
void FileAudioDevice::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_ptrAudioBuffer = audioBuffer;
@ -456,13 +456,13 @@ bool FileAudioDevice::PlayThreadProcess() {
return false;
}
int64_t currentTime = rtc::TimeMillis();
_critSect.Enter();
mutex_.Lock();
if (_lastCallPlayoutMillis == 0 ||
currentTime - _lastCallPlayoutMillis >= 10) {
_critSect.Leave();
mutex_.Unlock();
_ptrAudioBuffer->RequestPlayoutData(_playoutFramesIn10MS);
_critSect.Enter();
mutex_.Lock();
_playoutFramesLeft = _ptrAudioBuffer->GetPlayoutData(_playoutBuffer);
RTC_DCHECK_EQ(_playoutFramesIn10MS, _playoutFramesLeft);
@ -472,7 +472,7 @@ bool FileAudioDevice::PlayThreadProcess() {
_lastCallPlayoutMillis = currentTime;
}
_playoutFramesLeft = 0;
_critSect.Leave();
mutex_.Unlock();
int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime;
if (deltaTimeMillis < 10) {
@ -488,7 +488,7 @@ bool FileAudioDevice::RecThreadProcess() {
}
int64_t currentTime = rtc::TimeMillis();
_critSect.Enter();
mutex_.Lock();
if (_lastCallRecordMillis == 0 || currentTime - _lastCallRecordMillis >= 10) {
if (_inputFile.is_open()) {
@ -499,13 +499,13 @@ bool FileAudioDevice::RecThreadProcess() {
_inputFile.Rewind();
}
_lastCallRecordMillis = currentTime;
_critSect.Leave();
mutex_.Unlock();
_ptrAudioBuffer->DeliverRecordedData();
_critSect.Enter();
mutex_.Lock();
}
}
_critSect.Leave();
mutex_.Unlock();
int64_t deltaTimeMillis = rtc::TimeMillis() - currentTime;
if (deltaTimeMillis < 10) {

View File

@ -17,7 +17,7 @@
#include <string>
#include "modules/audio_device/audio_device_generic.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/system/file_wrapper.h"
#include "rtc_base/time_utils.h"
@ -139,7 +139,7 @@ class FileAudioDevice : public AudioDeviceGeneric {
int8_t* _playoutBuffer; // In bytes.
uint32_t _recordingFramesLeft;
uint32_t _playoutFramesLeft;
rtc::CriticalSection _critSect;
Mutex mutex_;
size_t _recordingBufferSizeIn10MS;
size_t _recordingFramesIn10MS;

View File

@ -23,13 +23,13 @@
#include "modules/audio_device/include/audio_device_default.h"
#include "rtc_base/buffer.h"
#include "rtc_base/checks.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/logging.h"
#include "rtc_base/numerics/safe_conversions.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/random.h"
#include "rtc_base/ref_counted_object.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/task_queue.h"
#include "rtc_base/task_utils/repeating_task.h"
#include "rtc_base/thread_annotations.h"
@ -99,45 +99,45 @@ class TestAudioDeviceModuleImpl
}
int32_t RegisterAudioCallback(AudioTransport* callback) override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
RTC_DCHECK(callback || audio_callback_);
audio_callback_ = callback;
return 0;
}
int32_t StartPlayout() override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
RTC_CHECK(renderer_);
rendering_ = true;
return 0;
}
int32_t StopPlayout() override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
rendering_ = false;
return 0;
}
int32_t StartRecording() override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
RTC_CHECK(capturer_);
capturing_ = true;
return 0;
}
int32_t StopRecording() override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
capturing_ = false;
return 0;
}
bool Playing() const override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
return rendering_;
}
bool Recording() const override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
return capturing_;
}
@ -155,7 +155,7 @@ class TestAudioDeviceModuleImpl
private:
void ProcessAudio() {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
if (capturing_) {
// Capture 10ms of audio. 2 bytes per sample.
const bool keep_capturing = capturer_->Capture(&recording_buffer_);
@ -194,7 +194,7 @@ class TestAudioDeviceModuleImpl
const std::unique_ptr<Renderer> renderer_ RTC_GUARDED_BY(lock_);
const int64_t process_interval_us_;
rtc::CriticalSection lock_;
mutable Mutex lock_;
AudioTransport* audio_callback_ RTC_GUARDED_BY(lock_);
bool rendering_ RTC_GUARDED_BY(lock_);
bool capturing_ RTC_GUARDED_BY(lock_);
@ -231,7 +231,7 @@ class PulsedNoiseCapturerImpl final
fill_with_zero_ = !fill_with_zero_;
int16_t max_amplitude;
{
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
max_amplitude = max_amplitude_;
}
buffer->SetData(
@ -251,7 +251,7 @@ class PulsedNoiseCapturerImpl final
}
void SetMaxAmplitude(int16_t amplitude) override {
rtc::CritScope cs(&lock_);
MutexLock lock(&lock_);
max_amplitude_ = amplitude;
}
@ -259,7 +259,7 @@ class PulsedNoiseCapturerImpl final
int sampling_frequency_in_hz_;
bool fill_with_zero_;
Random random_generator_;
rtc::CriticalSection lock_;
Mutex lock_;
int16_t max_amplitude_ RTC_GUARDED_BY(lock_);
const int num_channels_;
};

View File

@ -122,7 +122,7 @@ AudioDeviceLinuxALSA::~AudioDeviceLinuxALSA() {
}
void AudioDeviceLinuxALSA::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_ptrAudioBuffer = audioBuffer;
@ -142,7 +142,7 @@ int32_t AudioDeviceLinuxALSA::ActiveAudioLayer(
}
AudioDeviceGeneric::InitStatus AudioDeviceLinuxALSA::Init() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
// Load libasound
if (!GetAlsaSymbolTable()->Load()) {
@ -173,30 +173,30 @@ int32_t AudioDeviceLinuxALSA::Terminate() {
return 0;
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_mixerManager.Close();
// RECORDING
if (_ptrThreadRec) {
rtc::PlatformThread* tmpThread = _ptrThreadRec.release();
_critSect.Leave();
mutex_.Unlock();
tmpThread->Stop();
delete tmpThread;
_critSect.Enter();
mutex_.Lock();
}
// PLAYOUT
if (_ptrThreadPlay) {
rtc::PlatformThread* tmpThread = _ptrThreadPlay.release();
_critSect.Leave();
mutex_.Unlock();
tmpThread->Stop();
delete tmpThread;
_critSect.Enter();
mutex_.Lock();
}
#if defined(WEBRTC_USE_X11)
if (_XDisplay) {
@ -216,7 +216,7 @@ bool AudioDeviceLinuxALSA::Initialized() const {
}
int32_t AudioDeviceLinuxALSA::InitSpeaker() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playing) {
return -1;
@ -228,7 +228,7 @@ int32_t AudioDeviceLinuxALSA::InitSpeaker() {
}
int32_t AudioDeviceLinuxALSA::InitMicrophone() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_recording) {
return -1;
@ -404,7 +404,7 @@ int32_t AudioDeviceLinuxALSA::MicrophoneMute(bool& enabled) const {
}
int32_t AudioDeviceLinuxALSA::StereoRecordingIsAvailable(bool& available) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
// If we already have initialized in stereo it's obviously available
if (_recIsInitialized && (2 == _recChannels)) {
@ -464,7 +464,7 @@ int32_t AudioDeviceLinuxALSA::StereoRecording(bool& enabled) const {
}
int32_t AudioDeviceLinuxALSA::StereoPlayoutIsAvailable(bool& available) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
// If we already have initialized in stereo it's obviously available
if (_playIsInitialized && (2 == _playChannels)) {
@ -747,7 +747,7 @@ int32_t AudioDeviceLinuxALSA::RecordingIsAvailable(bool& available) {
int32_t AudioDeviceLinuxALSA::InitPlayout() {
int errVal = 0;
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playing) {
return -1;
}
@ -866,7 +866,7 @@ int32_t AudioDeviceLinuxALSA::InitPlayout() {
int32_t AudioDeviceLinuxALSA::InitRecording() {
int errVal = 0;
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_recording) {
return -1;
@ -1059,7 +1059,7 @@ int32_t AudioDeviceLinuxALSA::StartRecording() {
int32_t AudioDeviceLinuxALSA::StopRecording() {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_recIsInitialized) {
return 0;
@ -1079,7 +1079,7 @@ int32_t AudioDeviceLinuxALSA::StopRecording() {
_ptrThreadRec.reset();
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_recordingFramesLeft = 0;
if (_recordingBuffer) {
delete[] _recordingBuffer;
@ -1163,7 +1163,7 @@ int32_t AudioDeviceLinuxALSA::StartPlayout() {
int32_t AudioDeviceLinuxALSA::StopPlayout() {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_playIsInitialized) {
return 0;
@ -1182,7 +1182,7 @@ int32_t AudioDeviceLinuxALSA::StopPlayout() {
_ptrThreadPlay.reset();
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_playoutFramesLeft = 0;
delete[] _playoutBuffer;

View File

@ -15,8 +15,8 @@
#include "modules/audio_device/audio_device_generic.h"
#include "modules/audio_device/linux/audio_mixer_manager_alsa_linux.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/synchronization/mutex.h"
#if defined(WEBRTC_USE_X11)
#include <X11/Xlib.h>
@ -131,8 +131,8 @@ class AudioDeviceLinuxALSA : public AudioDeviceGeneric {
bool KeyPressed() const;
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION(_critSect) { _critSect.Enter(); }
void UnLock() RTC_UNLOCK_FUNCTION(_critSect) { _critSect.Leave(); }
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION(mutex_) { mutex_.Lock(); }
void UnLock() RTC_UNLOCK_FUNCTION(mutex_) { mutex_.Unlock(); }
inline int32_t InputSanityCheckAfterUnlockedPeriod() const;
inline int32_t OutputSanityCheckAfterUnlockedPeriod() const;
@ -144,7 +144,7 @@ class AudioDeviceLinuxALSA : public AudioDeviceGeneric {
AudioDeviceBuffer* _ptrAudioBuffer;
rtc::CriticalSection _critSect;
Mutex mutex_;
// TODO(pbos): Make plain members and start/stop instead of resetting these
// pointers. A thread can be reused.

View File

@ -181,7 +181,7 @@ int32_t AudioDeviceLinuxPulse::Terminate() {
return 0;
}
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
quit_ = true;
}
_mixerManager.Close();
@ -872,7 +872,7 @@ int32_t AudioDeviceLinuxPulse::InitPlayout() {
// Create a new play stream
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_playStream =
LATE(pa_stream_new)(_paContext, "playStream", &playSampleSpec, NULL);
}
@ -945,7 +945,7 @@ int32_t AudioDeviceLinuxPulse::InitPlayout() {
// Mark playout side as initialized
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_playIsInitialized = true;
_sndCardPlayDelay = 0;
}
@ -1066,7 +1066,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() {
_timeEventRec.Set();
if (!_recStartEvent.Wait(10000)) {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_startRec = false;
}
StopRecording();
@ -1075,7 +1075,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() {
}
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_recording) {
// The recording state is set by the audio thread after recording
// has started.
@ -1090,7 +1090,7 @@ int32_t AudioDeviceLinuxPulse::StartRecording() {
int32_t AudioDeviceLinuxPulse::StopRecording() {
RTC_DCHECK(thread_checker_.IsCurrent());
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_recIsInitialized) {
return 0;
@ -1170,7 +1170,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() {
// Set state to ensure that playout starts from the audio thread.
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_startPlay = true;
}
@ -1181,7 +1181,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() {
_timeEventPlay.Set();
if (!_playStartEvent.Wait(10000)) {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_startPlay = false;
}
StopPlayout();
@ -1190,7 +1190,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() {
}
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playing) {
// The playing state is set by the audio thread after playout
// has started.
@ -1205,7 +1205,7 @@ int32_t AudioDeviceLinuxPulse::StartPlayout() {
int32_t AudioDeviceLinuxPulse::StopPlayout() {
RTC_DCHECK(thread_checker_.IsCurrent());
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_playIsInitialized) {
return 0;
@ -1259,7 +1259,7 @@ int32_t AudioDeviceLinuxPulse::StopPlayout() {
}
int32_t AudioDeviceLinuxPulse::PlayoutDelay(uint16_t& delayMS) const {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
delayMS = (uint16_t)_sndCardPlayDelay;
return 0;
}
@ -1885,7 +1885,7 @@ int32_t AudioDeviceLinuxPulse::LatencyUsecs(pa_stream* stream) {
int32_t AudioDeviceLinuxPulse::ReadRecordedData(const void* bufferData,
size_t bufferSize)
RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect) {
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
size_t size = bufferSize;
uint32_t numRecSamples = _recordBufferSize / (2 * _recChannels);
@ -1953,7 +1953,7 @@ int32_t AudioDeviceLinuxPulse::ReadRecordedData(const void* bufferData,
int32_t AudioDeviceLinuxPulse::ProcessRecordedData(int8_t* bufferData,
uint32_t bufferSizeInSamples,
uint32_t recDelay)
RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect) {
RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_) {
_ptrAudioBuffer->SetRecordedBuffer(bufferData, bufferSizeInSamples);
// TODO(andrew): this is a temporary hack, to avoid non-causal far- and
@ -1998,7 +1998,7 @@ bool AudioDeviceLinuxPulse::PlayThreadProcess() {
return true;
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (quit_) {
return false;
@ -2170,7 +2170,7 @@ bool AudioDeviceLinuxPulse::RecThreadProcess() {
return true;
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (quit_) {
return false;
}

View File

@ -19,9 +19,9 @@
#include "modules/audio_device/include/audio_device_defines.h"
#include "modules/audio_device/linux/audio_mixer_manager_pulse_linux.h"
#include "modules/audio_device/linux/pulseaudiosymboltable_linux.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/platform_thread.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
#include "rtc_base/thread_checker.h"
@ -197,8 +197,8 @@ class AudioDeviceLinuxPulse : public AudioDeviceGeneric {
void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) override;
private:
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION(_critSect) { _critSect.Enter(); }
void UnLock() RTC_UNLOCK_FUNCTION(_critSect) { _critSect.Leave(); }
void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION(mutex_) { mutex_.Lock(); }
void UnLock() RTC_UNLOCK_FUNCTION(mutex_) { mutex_.Unlock(); }
void WaitForOperationCompletion(pa_operation* paOperation) const;
void WaitForSuccess(pa_operation* paOperation) const;
@ -261,7 +261,7 @@ class AudioDeviceLinuxPulse : public AudioDeviceGeneric {
AudioDeviceBuffer* _ptrAudioBuffer;
rtc::CriticalSection _critSect;
mutable Mutex mutex_;
rtc::Event _timeEventRec;
rtc::Event _timeEventPlay;
rtc::Event _recStartEvent;
@ -296,9 +296,9 @@ class AudioDeviceLinuxPulse : public AudioDeviceGeneric {
bool _startRec;
bool _startPlay;
bool update_speaker_volume_at_startup_;
bool quit_ RTC_GUARDED_BY(&_critSect);
bool quit_ RTC_GUARDED_BY(&mutex_);
uint32_t _sndCardPlayDelay RTC_GUARDED_BY(&_critSect);
uint32_t _sndCardPlayDelay RTC_GUARDED_BY(&mutex_);
int32_t _writeErrors;

View File

@ -45,7 +45,7 @@ AudioMixerManagerLinuxALSA::~AudioMixerManagerLinuxALSA() {
int32_t AudioMixerManagerLinuxALSA::Close() {
RTC_LOG(LS_VERBOSE) << __FUNCTION__;
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
CloseSpeaker();
CloseMicrophone();
@ -56,7 +56,7 @@ int32_t AudioMixerManagerLinuxALSA::Close() {
int32_t AudioMixerManagerLinuxALSA::CloseSpeaker() {
RTC_LOG(LS_VERBOSE) << __FUNCTION__;
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
int errVal = 0;
@ -88,7 +88,7 @@ int32_t AudioMixerManagerLinuxALSA::CloseSpeaker() {
int32_t AudioMixerManagerLinuxALSA::CloseMicrophone() {
RTC_LOG(LS_VERBOSE) << __FUNCTION__;
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
int errVal = 0;
@ -128,7 +128,7 @@ int32_t AudioMixerManagerLinuxALSA::OpenSpeaker(char* deviceName) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerLinuxALSA::OpenSpeaker(name="
<< deviceName << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
int errVal = 0;
@ -204,7 +204,7 @@ int32_t AudioMixerManagerLinuxALSA::OpenMicrophone(char* deviceName) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerLinuxALSA::OpenMicrophone(name="
<< deviceName << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
int errVal = 0;
@ -298,7 +298,7 @@ int32_t AudioMixerManagerLinuxALSA::SetSpeakerVolume(uint32_t volume) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerLinuxALSA::SetSpeakerVolume(volume="
<< volume << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_outputMixerElement == NULL) {
RTC_LOG(LS_WARNING) << "no avaliable output mixer element exists";
@ -501,7 +501,7 @@ int32_t AudioMixerManagerLinuxALSA::SetSpeakerMute(bool enable) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerLinuxALSA::SetSpeakerMute(enable="
<< enable << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_outputMixerElement == NULL) {
RTC_LOG(LS_WARNING) << "no avaliable output mixer element exists";
@ -574,7 +574,7 @@ int32_t AudioMixerManagerLinuxALSA::SetMicrophoneMute(bool enable) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerLinuxALSA::SetMicrophoneMute(enable="
<< enable << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_inputMixerElement == NULL) {
RTC_LOG(LS_WARNING) << "no avaliable input mixer element exists";
@ -649,7 +649,7 @@ int32_t AudioMixerManagerLinuxALSA::SetMicrophoneVolume(uint32_t volume) {
<< "AudioMixerManagerLinuxALSA::SetMicrophoneVolume(volume=" << volume
<< ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_inputMixerElement == NULL) {
RTC_LOG(LS_WARNING) << "no avaliable input mixer element exists";

View File

@ -15,7 +15,7 @@
#include "modules/audio_device/include/audio_device.h"
#include "modules/audio_device/linux/alsasymboltable_linux.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
@ -55,7 +55,7 @@ class AudioMixerManagerLinuxALSA {
void GetControlName(char* controlName, char* deviceName) const;
private:
rtc::CriticalSection _critSect;
Mutex mutex_;
mutable snd_mixer_t* _outputMixerHandle;
char _outputMixerStr[kAdmMaxDeviceNameSize];
mutable snd_mixer_t* _inputMixerHandle;

View File

@ -206,7 +206,7 @@ AudioDeviceMac::~AudioDeviceMac() {
// ============================================================================
void AudioDeviceMac::AttachAudioBuffer(AudioDeviceBuffer* audioBuffer) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
_ptrAudioBuffer = audioBuffer;
@ -224,7 +224,7 @@ int32_t AudioDeviceMac::ActiveAudioLayer(
}
AudioDeviceGeneric::InitStatus AudioDeviceMac::Init() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_initialized) {
return InitStatus::OK;
@ -350,8 +350,7 @@ int32_t AudioDeviceMac::Terminate() {
return -1;
}
_critSect.Enter();
MutexLock lock(&mutex_);
_mixerManager.Close();
OSStatus err = noErr;
@ -375,8 +374,6 @@ int32_t AudioDeviceMac::Terminate() {
_outputDeviceIsSpecified = false;
_inputDeviceIsSpecified = false;
_critSect.Leave();
return retVal;
}
@ -409,7 +406,7 @@ int32_t AudioDeviceMac::SpeakerIsAvailable(bool& available) {
}
int32_t AudioDeviceMac::InitSpeaker() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
return InitSpeakerLocked();
}
@ -460,7 +457,7 @@ int32_t AudioDeviceMac::MicrophoneIsAvailable(bool& available) {
}
int32_t AudioDeviceMac::InitMicrophone() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
return InitMicrophoneLocked();
}
@ -802,7 +799,7 @@ int16_t AudioDeviceMac::PlayoutDevices() {
}
int32_t AudioDeviceMac::SetPlayoutDevice(uint16_t index) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playIsInitialized) {
return -1;
@ -951,7 +948,7 @@ int32_t AudioDeviceMac::RecordingIsAvailable(bool& available) {
int32_t AudioDeviceMac::InitPlayout() {
RTC_LOG(LS_INFO) << "InitPlayout";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playing) {
return -1;
@ -1089,7 +1086,7 @@ int32_t AudioDeviceMac::InitPlayout() {
int32_t AudioDeviceMac::InitRecording() {
RTC_LOG(LS_INFO) << "InitRecording";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_recording) {
return -1;
@ -1286,7 +1283,7 @@ int32_t AudioDeviceMac::InitRecording() {
int32_t AudioDeviceMac::StartRecording() {
RTC_LOG(LS_INFO) << "StartRecording";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_recIsInitialized) {
return -1;
@ -1322,7 +1319,7 @@ int32_t AudioDeviceMac::StartRecording() {
int32_t AudioDeviceMac::StopRecording() {
RTC_LOG(LS_INFO) << "StopRecording";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_recIsInitialized) {
return 0;
@ -1335,16 +1332,16 @@ int32_t AudioDeviceMac::StopRecording() {
if (_recording) {
_recording = false;
_doStopRec = true; // Signal to io proc to stop audio device
_critSect.Leave(); // Cannot be under lock, risk of deadlock
mutex_.Unlock(); // Cannot be under lock, risk of deadlock
if (!_stopEventRec.Wait(2000)) {
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
RTC_LOG(LS_WARNING) << "Timed out stopping the capture IOProc."
"We may have failed to detect a device removal.";
WEBRTC_CA_LOG_WARN(AudioDeviceStop(_inputDeviceID, _inDeviceIOProcID));
WEBRTC_CA_LOG_WARN(
AudioDeviceDestroyIOProcID(_inputDeviceID, _inDeviceIOProcID));
}
_critSect.Enter();
mutex_.Lock();
_doStopRec = false;
RTC_LOG(LS_INFO) << "Recording stopped (input device)";
} else if (_recIsInitialized) {
@ -1363,9 +1360,9 @@ int32_t AudioDeviceMac::StopRecording() {
if (_recording && captureDeviceIsAlive == 1) {
_recording = false;
_doStop = true; // Signal to io proc to stop audio device
_critSect.Leave(); // Cannot be under lock, risk of deadlock
mutex_.Unlock(); // Cannot be under lock, risk of deadlock
if (!_stopEvent.Wait(2000)) {
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
RTC_LOG(LS_WARNING) << "Timed out stopping the shared IOProc."
"We may have failed to detect a device removal.";
// We assume rendering on a shared device has stopped as well if
@ -1374,7 +1371,7 @@ int32_t AudioDeviceMac::StopRecording() {
WEBRTC_CA_LOG_WARN(
AudioDeviceDestroyIOProcID(_outputDeviceID, _deviceIOProcID));
}
_critSect.Enter();
mutex_.Lock();
_doStop = false;
RTC_LOG(LS_INFO) << "Recording stopped (shared device)";
} else if (_recIsInitialized && !_playing && !_playIsInitialized) {
@ -1388,10 +1385,10 @@ int32_t AudioDeviceMac::StopRecording() {
AtomicSet32(&_captureDeviceIsAlive, 0);
if (capture_worker_thread_.get()) {
_critSect.Leave();
mutex_.Unlock();
capture_worker_thread_->Stop();
capture_worker_thread_.reset();
_critSect.Enter();
mutex_.Lock();
}
WEBRTC_CA_LOG_WARN(AudioConverterDispose(_captureConverter));
@ -1426,7 +1423,7 @@ bool AudioDeviceMac::PlayoutIsInitialized() const {
int32_t AudioDeviceMac::StartPlayout() {
RTC_LOG(LS_INFO) << "StartPlayout";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_playIsInitialized) {
return -1;
@ -1452,7 +1449,7 @@ int32_t AudioDeviceMac::StartPlayout() {
int32_t AudioDeviceMac::StopPlayout() {
RTC_LOG(LS_INFO) << "StopPlayout";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_playIsInitialized) {
return 0;
@ -1470,9 +1467,9 @@ int32_t AudioDeviceMac::StopPlayout() {
// has ended before stopping itself.
_playing = false;
_doStop = true; // Signal to io proc to stop audio device
_critSect.Leave(); // Cannot be under lock, risk of deadlock
mutex_.Unlock(); // Cannot be under lock, risk of deadlock
if (!_stopEvent.Wait(2000)) {
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
RTC_LOG(LS_WARNING) << "Timed out stopping the render IOProc."
"We may have failed to detect a device removal.";
@ -1482,7 +1479,7 @@ int32_t AudioDeviceMac::StopPlayout() {
WEBRTC_CA_LOG_WARN(
AudioDeviceDestroyIOProcID(_outputDeviceID, _deviceIOProcID));
}
_critSect.Enter();
mutex_.Lock();
_doStop = false;
RTC_LOG(LS_INFO) << "Playout stopped";
} else if (_twoDevices && _playIsInitialized) {
@ -1498,10 +1495,10 @@ int32_t AudioDeviceMac::StopPlayout() {
// Setting this signal will allow the worker thread to be stopped.
AtomicSet32(&_renderDeviceIsAlive, 0);
if (render_worker_thread_.get()) {
_critSect.Leave();
mutex_.Unlock();
render_worker_thread_->Stop();
render_worker_thread_.reset();
_critSect.Enter();
mutex_.Lock();
}
WEBRTC_CA_LOG_WARN(AudioConverterDispose(_renderConverter));
@ -2181,7 +2178,7 @@ OSStatus AudioDeviceMac::implDeviceIOProc(const AudioBufferList* inputData,
// Check if we should close down audio device
// Double-checked locking optimization to remove locking overhead
if (_doStop) {
_critSect.Enter();
MutexLock lock(&mutex_);
if (_doStop) {
if (_twoDevices || (!_recording && !_playing)) {
// In the case of a shared device, the single driving ioProc
@ -2196,10 +2193,8 @@ OSStatus AudioDeviceMac::implDeviceIOProc(const AudioBufferList* inputData,
_doStop = false;
_stopEvent.Set();
_critSect.Leave();
return 0;
}
_critSect.Leave();
}
if (!_playing) {
@ -2276,7 +2271,7 @@ OSStatus AudioDeviceMac::implInDeviceIOProc(const AudioBufferList* inputData,
// Check if we should close down audio device
// Double-checked locking optimization to remove locking overhead
if (_doStopRec) {
_critSect.Enter();
MutexLock lock(&mutex_);
if (_doStopRec) {
// This will be signalled only when a shared device is not in use.
WEBRTC_CA_LOG_ERR(AudioDeviceStop(_inputDeviceID, _inDeviceIOProcID));
@ -2288,10 +2283,8 @@ OSStatus AudioDeviceMac::implInDeviceIOProc(const AudioBufferList* inputData,
_doStopRec = false;
_stopEventRec.Set();
_critSect.Leave();
return 0;
}
_critSect.Leave();
}
if (!_recording) {

View File

@ -19,9 +19,9 @@
#include "modules/audio_device/audio_device_generic.h"
#include "modules/audio_device/mac/audio_mixer_manager_mac.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/event.h"
#include "rtc_base/logging.h"
#include "rtc_base/synchronization/mutex.h"
#include "rtc_base/thread_annotations.h"
struct PaUtilRingBuffer;
@ -69,8 +69,8 @@ class AudioDeviceMac : public AudioDeviceGeneric {
AudioDeviceModule::AudioLayer& audioLayer) const;
// Main initializaton and termination
virtual InitStatus Init() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t Terminate() RTC_LOCKS_EXCLUDED(_critSect);
virtual InitStatus Init() RTC_LOCKS_EXCLUDED(mutex_);
virtual int32_t Terminate() RTC_LOCKS_EXCLUDED(mutex_);
virtual bool Initialized() const;
// Device enumeration
@ -84,8 +84,7 @@ class AudioDeviceMac : public AudioDeviceGeneric {
char guid[kAdmMaxGuidSize]);
// Device selection
virtual int32_t SetPlayoutDevice(uint16_t index)
RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t SetPlayoutDevice(uint16_t index) RTC_LOCKS_EXCLUDED(mutex_);
virtual int32_t SetPlayoutDevice(AudioDeviceModule::WindowsDeviceType device);
virtual int32_t SetRecordingDevice(uint16_t index);
virtual int32_t SetRecordingDevice(
@ -93,24 +92,24 @@ class AudioDeviceMac : public AudioDeviceGeneric {
// Audio transport initialization
virtual int32_t PlayoutIsAvailable(bool& available);
virtual int32_t InitPlayout() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t InitPlayout() RTC_LOCKS_EXCLUDED(mutex_);
virtual bool PlayoutIsInitialized() const;
virtual int32_t RecordingIsAvailable(bool& available);
virtual int32_t InitRecording() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t InitRecording() RTC_LOCKS_EXCLUDED(mutex_);
virtual bool RecordingIsInitialized() const;
// Audio transport control
virtual int32_t StartPlayout() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t StopPlayout() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t StartPlayout() RTC_LOCKS_EXCLUDED(mutex_);
virtual int32_t StopPlayout() RTC_LOCKS_EXCLUDED(mutex_);
virtual bool Playing() const;
virtual int32_t StartRecording() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t StopRecording() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t StartRecording() RTC_LOCKS_EXCLUDED(mutex_);
virtual int32_t StopRecording() RTC_LOCKS_EXCLUDED(mutex_);
virtual bool Recording() const;
// Audio mixer initialization
virtual int32_t InitSpeaker() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t InitSpeaker() RTC_LOCKS_EXCLUDED(mutex_);
virtual bool SpeakerIsInitialized() const;
virtual int32_t InitMicrophone() RTC_LOCKS_EXCLUDED(_critSect);
virtual int32_t InitMicrophone() RTC_LOCKS_EXCLUDED(mutex_);
virtual bool MicrophoneIsInitialized() const;
// Speaker volume controls
@ -149,11 +148,11 @@ class AudioDeviceMac : public AudioDeviceGeneric {
virtual int32_t PlayoutDelay(uint16_t& delayMS) const;
virtual void AttachAudioBuffer(AudioDeviceBuffer* audioBuffer)
RTC_LOCKS_EXCLUDED(_critSect);
RTC_LOCKS_EXCLUDED(mutex_);
private:
int32_t InitSpeakerLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect);
int32_t InitMicrophoneLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect);
int32_t InitSpeakerLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
int32_t InitMicrophoneLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
virtual int32_t MicrophoneIsAvailable(bool& available);
virtual int32_t SpeakerIsAvailable(bool& available);
@ -235,14 +234,14 @@ class AudioDeviceMac : public AudioDeviceGeneric {
const AudioTimeStamp* inputTime,
AudioBufferList* outputData,
const AudioTimeStamp* outputTime)
RTC_LOCKS_EXCLUDED(_critSect);
RTC_LOCKS_EXCLUDED(mutex_);
OSStatus implOutConverterProc(UInt32* numberDataPackets,
AudioBufferList* data);
OSStatus implInDeviceIOProc(const AudioBufferList* inputData,
const AudioTimeStamp* inputTime)
RTC_LOCKS_EXCLUDED(_critSect);
RTC_LOCKS_EXCLUDED(mutex_);
OSStatus implInConverterProc(UInt32* numberDataPackets,
AudioBufferList* data);
@ -256,7 +255,7 @@ class AudioDeviceMac : public AudioDeviceGeneric {
AudioDeviceBuffer* _ptrAudioBuffer;
rtc::CriticalSection _critSect;
Mutex mutex_;
rtc::Event _stopEventRec;
rtc::Event _stopEvent;

View File

@ -61,7 +61,7 @@ AudioMixerManagerMac::~AudioMixerManagerMac() {
int32_t AudioMixerManagerMac::Close() {
RTC_LOG(LS_VERBOSE) << __FUNCTION__;
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
CloseSpeakerLocked();
CloseMicrophoneLocked();
@ -70,7 +70,7 @@ int32_t AudioMixerManagerMac::Close() {
}
int32_t AudioMixerManagerMac::CloseSpeaker() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
return CloseSpeakerLocked();
}
@ -84,7 +84,7 @@ int32_t AudioMixerManagerMac::CloseSpeakerLocked() {
}
int32_t AudioMixerManagerMac::CloseMicrophone() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
return CloseMicrophoneLocked();
}
@ -101,7 +101,7 @@ int32_t AudioMixerManagerMac::OpenSpeaker(AudioDeviceID deviceID) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerMac::OpenSpeaker(id=" << deviceID
<< ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
OSStatus err = noErr;
UInt32 size = 0;
@ -153,7 +153,7 @@ int32_t AudioMixerManagerMac::OpenMicrophone(AudioDeviceID deviceID) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerMac::OpenMicrophone(id=" << deviceID
<< ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
OSStatus err = noErr;
UInt32 size = 0;
@ -211,7 +211,7 @@ int32_t AudioMixerManagerMac::SetSpeakerVolume(uint32_t volume) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerMac::SetSpeakerVolume(volume="
<< volume << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_outputDeviceID == kAudioObjectUnknown) {
RTC_LOG(LS_WARNING) << "device ID has not been set";
@ -427,7 +427,7 @@ int32_t AudioMixerManagerMac::SetSpeakerMute(bool enable) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerMac::SetSpeakerMute(enable="
<< enable << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_outputDeviceID == kAudioObjectUnknown) {
RTC_LOG(LS_WARNING) << "device ID has not been set";
@ -595,7 +595,7 @@ int32_t AudioMixerManagerMac::SetMicrophoneMute(bool enable) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerMac::SetMicrophoneMute(enable="
<< enable << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_inputDeviceID == kAudioObjectUnknown) {
RTC_LOG(LS_WARNING) << "device ID has not been set";
@ -743,7 +743,7 @@ int32_t AudioMixerManagerMac::SetMicrophoneVolume(uint32_t volume) {
RTC_LOG(LS_VERBOSE) << "AudioMixerManagerMac::SetMicrophoneVolume(volume="
<< volume << ")";
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_inputDeviceID == kAudioObjectUnknown) {
RTC_LOG(LS_WARNING) << "device ID has not been set";

View File

@ -14,36 +14,36 @@
#include <CoreAudio/CoreAudio.h>
#include "modules/audio_device/include/audio_device.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/logging.h"
#include "rtc_base/synchronization/mutex.h"
namespace webrtc {
class AudioMixerManagerMac {
public:
int32_t OpenSpeaker(AudioDeviceID deviceID) RTC_LOCKS_EXCLUDED(_critSect);
int32_t OpenMicrophone(AudioDeviceID deviceID) RTC_LOCKS_EXCLUDED(_critSect);
int32_t SetSpeakerVolume(uint32_t volume) RTC_LOCKS_EXCLUDED(_critSect);
int32_t OpenSpeaker(AudioDeviceID deviceID) RTC_LOCKS_EXCLUDED(mutex_);
int32_t OpenMicrophone(AudioDeviceID deviceID) RTC_LOCKS_EXCLUDED(mutex_);
int32_t SetSpeakerVolume(uint32_t volume) RTC_LOCKS_EXCLUDED(mutex_);
int32_t SpeakerVolume(uint32_t& volume) const;
int32_t MaxSpeakerVolume(uint32_t& maxVolume) const;
int32_t MinSpeakerVolume(uint32_t& minVolume) const;
int32_t SpeakerVolumeIsAvailable(bool& available);
int32_t SpeakerMuteIsAvailable(bool& available);
int32_t SetSpeakerMute(bool enable) RTC_LOCKS_EXCLUDED(_critSect);
int32_t SetSpeakerMute(bool enable) RTC_LOCKS_EXCLUDED(mutex_);
int32_t SpeakerMute(bool& enabled) const;
int32_t StereoPlayoutIsAvailable(bool& available);
int32_t StereoRecordingIsAvailable(bool& available);
int32_t MicrophoneMuteIsAvailable(bool& available);
int32_t SetMicrophoneMute(bool enable) RTC_LOCKS_EXCLUDED(_critSect);
int32_t SetMicrophoneMute(bool enable) RTC_LOCKS_EXCLUDED(mutex_);
int32_t MicrophoneMute(bool& enabled) const;
int32_t MicrophoneVolumeIsAvailable(bool& available);
int32_t SetMicrophoneVolume(uint32_t volume) RTC_LOCKS_EXCLUDED(_critSect);
int32_t SetMicrophoneVolume(uint32_t volume) RTC_LOCKS_EXCLUDED(mutex_);
int32_t MicrophoneVolume(uint32_t& volume) const;
int32_t MaxMicrophoneVolume(uint32_t& maxVolume) const;
int32_t MinMicrophoneVolume(uint32_t& minVolume) const;
int32_t Close() RTC_LOCKS_EXCLUDED(_critSect);
int32_t CloseSpeaker() RTC_LOCKS_EXCLUDED(_critSect);
int32_t CloseMicrophone() RTC_LOCKS_EXCLUDED(_critSect);
int32_t Close() RTC_LOCKS_EXCLUDED(mutex_);
int32_t CloseSpeaker() RTC_LOCKS_EXCLUDED(mutex_);
int32_t CloseMicrophone() RTC_LOCKS_EXCLUDED(mutex_);
bool SpeakerIsInitialized() const;
bool MicrophoneIsInitialized() const;
@ -52,14 +52,14 @@ class AudioMixerManagerMac {
~AudioMixerManagerMac();
private:
int32_t CloseSpeakerLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect);
int32_t CloseMicrophoneLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(_critSect);
int32_t CloseSpeakerLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
int32_t CloseMicrophoneLocked() RTC_EXCLUSIVE_LOCKS_REQUIRED(mutex_);
static void logCAMsg(const rtc::LoggingSeverity sev,
const char* msg,
const char* err);
private:
rtc::CriticalSection _critSect;
Mutex mutex_;
AudioDeviceID _inputDeviceID;
AudioDeviceID _outputDeviceID;

View File

@ -579,7 +579,7 @@ int32_t AudioDeviceWindowsCore::ActiveAudioLayer(
// ----------------------------------------------------------------------------
AudioDeviceGeneric::InitStatus AudioDeviceWindowsCore::Init() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_initialized) {
return InitStatus::OK;
@ -601,7 +601,7 @@ AudioDeviceGeneric::InitStatus AudioDeviceWindowsCore::Init() {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::Terminate() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_initialized) {
return 0;
@ -640,7 +640,7 @@ bool AudioDeviceWindowsCore::Initialized() const {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::InitSpeaker() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playing) {
return -1;
@ -709,7 +709,7 @@ int32_t AudioDeviceWindowsCore::InitSpeaker() {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::InitMicrophone() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_recording) {
return -1;
@ -784,7 +784,7 @@ bool AudioDeviceWindowsCore::MicrophoneIsInitialized() const {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::SpeakerVolumeIsAvailable(bool& available) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_ptrDeviceOut == NULL) {
return -1;
@ -826,7 +826,7 @@ Exit:
int32_t AudioDeviceWindowsCore::SetSpeakerVolume(uint32_t volume) {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_speakerIsInitialized) {
return -1;
@ -846,9 +846,9 @@ int32_t AudioDeviceWindowsCore::SetSpeakerVolume(uint32_t volume) {
// scale input volume to valid range (0.0 to 1.0)
const float fLevel = (float)volume / MAX_CORE_SPEAKER_VOLUME;
_volumeMutex.Enter();
volume_mutex_.Lock();
hr = _ptrRenderSimpleVolume->SetMasterVolume(fLevel, NULL);
_volumeMutex.Leave();
volume_mutex_.Unlock();
EXIT_ON_ERROR(hr);
return 0;
@ -864,7 +864,7 @@ Exit:
int32_t AudioDeviceWindowsCore::SpeakerVolume(uint32_t& volume) const {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_speakerIsInitialized) {
return -1;
@ -878,9 +878,9 @@ int32_t AudioDeviceWindowsCore::SpeakerVolume(uint32_t& volume) const {
HRESULT hr = S_OK;
float fLevel(0.0f);
_volumeMutex.Enter();
volume_mutex_.Lock();
hr = _ptrRenderSimpleVolume->GetMasterVolume(&fLevel);
_volumeMutex.Leave();
volume_mutex_.Unlock();
EXIT_ON_ERROR(hr);
// scale input volume range [0.0,1.0] to valid output range
@ -931,7 +931,7 @@ int32_t AudioDeviceWindowsCore::MinSpeakerVolume(uint32_t& minVolume) const {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::SpeakerMuteIsAvailable(bool& available) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_ptrDeviceOut == NULL) {
return -1;
@ -967,7 +967,7 @@ Exit:
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::SetSpeakerMute(bool enable) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_speakerIsInitialized) {
return -1;
@ -1041,7 +1041,7 @@ Exit:
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::MicrophoneMuteIsAvailable(bool& available) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_ptrDeviceIn == NULL) {
return -1;
@ -1151,7 +1151,7 @@ int32_t AudioDeviceWindowsCore::StereoRecordingIsAvailable(bool& available) {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::SetStereoRecording(bool enable) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (enable) {
_recChannelsPrioList[0] = 2; // try stereo first
@ -1193,7 +1193,7 @@ int32_t AudioDeviceWindowsCore::StereoPlayoutIsAvailable(bool& available) {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::SetStereoPlayout(bool enable) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (enable) {
_playChannelsPrioList[0] = 2; // try stereo first
@ -1226,7 +1226,7 @@ int32_t AudioDeviceWindowsCore::StereoPlayout(bool& enabled) const {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::MicrophoneVolumeIsAvailable(bool& available) {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_ptrDeviceIn == NULL) {
return -1;
@ -1264,7 +1264,7 @@ int32_t AudioDeviceWindowsCore::SetMicrophoneVolume(uint32_t volume) {
<< volume << ")";
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_microphoneIsInitialized) {
return -1;
@ -1283,9 +1283,9 @@ int32_t AudioDeviceWindowsCore::SetMicrophoneVolume(uint32_t volume) {
HRESULT hr = S_OK;
// scale input volume to valid range (0.0 to 1.0)
const float fLevel = static_cast<float>(volume) / MAX_CORE_MICROPHONE_VOLUME;
_volumeMutex.Enter();
volume_mutex_.Lock();
_ptrCaptureVolume->SetMasterVolumeLevelScalar(fLevel, NULL);
_volumeMutex.Leave();
volume_mutex_.Unlock();
EXIT_ON_ERROR(hr);
return 0;
@ -1301,7 +1301,7 @@ Exit:
int32_t AudioDeviceWindowsCore::MicrophoneVolume(uint32_t& volume) const {
{
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (!_microphoneIsInitialized) {
return -1;
@ -1315,9 +1315,9 @@ int32_t AudioDeviceWindowsCore::MicrophoneVolume(uint32_t& volume) const {
HRESULT hr = S_OK;
float fLevel(0.0f);
volume = 0;
_volumeMutex.Enter();
volume_mutex_.Lock();
hr = _ptrCaptureVolume->GetMasterVolumeLevelScalar(&fLevel);
_volumeMutex.Leave();
volume_mutex_.Unlock();
EXIT_ON_ERROR(hr);
// scale input volume range [0.0,1.0] to valid output range
@ -1370,7 +1370,7 @@ int32_t AudioDeviceWindowsCore::MinMicrophoneVolume(uint32_t& minVolume) const {
// ----------------------------------------------------------------------------
int16_t AudioDeviceWindowsCore::PlayoutDevices() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_RefreshDeviceList(eRender) != -1) {
return (_DeviceListCount(eRender));
@ -1398,7 +1398,7 @@ int32_t AudioDeviceWindowsCore::SetPlayoutDevice(uint16_t index) {
return -1;
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
HRESULT hr(S_OK);
@ -1445,7 +1445,7 @@ int32_t AudioDeviceWindowsCore::SetPlayoutDevice(
role = eCommunications;
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
// Refresh the list of rendering endpoint devices
_RefreshDeviceList(eRender);
@ -1506,7 +1506,7 @@ int32_t AudioDeviceWindowsCore::PlayoutDeviceName(
memset(guid, 0, kAdmMaxGuidSize);
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
int32_t ret(-1);
WCHAR szDeviceName[MAX_PATH];
@ -1582,7 +1582,7 @@ int32_t AudioDeviceWindowsCore::RecordingDeviceName(
memset(guid, 0, kAdmMaxGuidSize);
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
int32_t ret(-1);
WCHAR szDeviceName[MAX_PATH];
@ -1633,7 +1633,7 @@ int32_t AudioDeviceWindowsCore::RecordingDeviceName(
// ----------------------------------------------------------------------------
int16_t AudioDeviceWindowsCore::RecordingDevices() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_RefreshDeviceList(eCapture) != -1) {
return (_DeviceListCount(eCapture));
@ -1661,7 +1661,7 @@ int32_t AudioDeviceWindowsCore::SetRecordingDevice(uint16_t index) {
return -1;
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
HRESULT hr(S_OK);
@ -1708,7 +1708,7 @@ int32_t AudioDeviceWindowsCore::SetRecordingDevice(
role = eCommunications;
}
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
// Refresh the list of capture endpoint devices
_RefreshDeviceList(eCapture);
@ -1785,7 +1785,7 @@ int32_t AudioDeviceWindowsCore::RecordingIsAvailable(bool& available) {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::InitPlayout() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_playing) {
return -1;
@ -2099,7 +2099,7 @@ int32_t AudioDeviceWindowsCore::InitRecordingDMO() {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::InitRecording() {
rtc::CritScope lock(&_critSect);
MutexLock lock(&mutex_);
if (_recording) {
return -1;
@ -2326,7 +2326,7 @@ int32_t AudioDeviceWindowsCore::StartRecording() {
}
{
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
// Create thread which will drive the capturing
LPTHREAD_START_ROUTINE lpStartAddress = WSAPICaptureThread;
@ -2479,7 +2479,7 @@ int32_t AudioDeviceWindowsCore::StartPlayout() {
}
{
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
// Create thread which will drive the rendering.
assert(_hPlayThread == NULL);
@ -2515,7 +2515,7 @@ int32_t AudioDeviceWindowsCore::StopPlayout() {
}
{
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
if (_hPlayThread == NULL) {
RTC_LOG(LS_VERBOSE)
@ -2545,7 +2545,7 @@ int32_t AudioDeviceWindowsCore::StopPlayout() {
}
{
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
RTC_LOG(LS_VERBOSE) << "webrtc_core_audio_render_thread is now closed";
// to reset this event manually at each time we finish with it,
@ -2587,7 +2587,7 @@ int32_t AudioDeviceWindowsCore::StopPlayout() {
// ----------------------------------------------------------------------------
int32_t AudioDeviceWindowsCore::PlayoutDelay(uint16_t& delayMS) const {
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
delayMS = static_cast<uint16_t>(_sndCardPlayDelay);
return 0;
}
@ -2981,7 +2981,7 @@ DWORD AudioDeviceWindowsCore::DoCaptureThreadPollDMO() {
}
while (keepRecording) {
rtc::CritScope critScoped(&_critSect);
MutexLock lockScoped(&mutex_);
DWORD dwStatus = 0;
{
@ -3357,11 +3357,11 @@ int32_t AudioDeviceWindowsCore::EnableBuiltInAEC(bool enable) {
}
void AudioDeviceWindowsCore::_Lock() RTC_NO_THREAD_SAFETY_ANALYSIS {
_critSect.Enter();
mutex_.Lock();
}
void AudioDeviceWindowsCore::_UnLock() RTC_NO_THREAD_SAFETY_ANALYSIS {
_critSect.Leave();
mutex_.Unlock();
}
int AudioDeviceWindowsCore::SetDMOProperties() {

View File

@ -27,7 +27,7 @@
#include <mmdeviceapi.h> // MMDevice
#include "api/scoped_refptr.h"
#include "rtc_base/critical_section.h"
#include "rtc_base/synchronization/mutex.h"
// Use Multimedia Class Scheduler Service (MMCSS) to boost the thread priority
#pragma comment(lib, "avrt.lib")
@ -237,8 +237,8 @@ class AudioDeviceWindowsCore : public AudioDeviceGeneric {
ScopedCOMInitializer _comInit;
AudioDeviceBuffer* _ptrAudioBuffer;
rtc::CriticalSection _critSect;
rtc::CriticalSection _volumeMutex;
mutable Mutex mutex_;
mutable Mutex volume_mutex_;
IMMDeviceEnumerator* _ptrEnumerator;
IMMDeviceCollection* _ptrRenderCollection;