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

@ -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_;
};