Delete rtc_base/atomic_ops.h
Bug: webrtc:9305 Change-Id: I3e8b0db03b84b5361d63db31ee23e6db3deabfe4 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/266497 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Niels Moller <nisse@webrtc.org> Reviewed-by: Harald Alvestrand <hta@webrtc.org> Cr-Commit-Position: refs/heads/main@{#37348}
This commit is contained in:
committed by
WebRTC LUCI CQ
parent
3e8a797b2e
commit
7a66900683
@ -11,6 +11,7 @@
|
||||
#ifndef SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_IOS_H_
|
||||
#define SDK_OBJC_NATIVE_SRC_AUDIO_AUDIO_DEVICE_IOS_H_
|
||||
|
||||
#include <atomic>
|
||||
#include <memory>
|
||||
|
||||
#include "api/sequence_checker.h"
|
||||
@ -266,10 +267,10 @@ class AudioDeviceIOS : public AudioDeviceGeneric,
|
||||
rtc::BufferT<int16_t> record_audio_buffer_;
|
||||
|
||||
// Set to 1 when recording is active and 0 otherwise.
|
||||
volatile int recording_;
|
||||
std::atomic<int> recording_;
|
||||
|
||||
// Set to 1 when playout is active and 0 otherwise.
|
||||
volatile int playing_;
|
||||
std::atomic<int> playing_;
|
||||
|
||||
// Set to true after successful call to Init(), false otherwise.
|
||||
bool initialized_ RTC_GUARDED_BY(thread_checker_);
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
#include "api/array_view.h"
|
||||
#include "helpers.h"
|
||||
#include "modules/audio_device/fine_audio_buffer.h"
|
||||
#include "rtc_base/atomic_ops.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/thread.h"
|
||||
@ -188,7 +187,7 @@ int32_t AudioDeviceIOS::InitPlayout() {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(!audio_is_initialized_);
|
||||
RTC_DCHECK(!playing_);
|
||||
RTC_DCHECK(!playing_.load());
|
||||
if (!audio_is_initialized_) {
|
||||
if (!InitPlayOrRecord()) {
|
||||
RTC_LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitPlayout!";
|
||||
@ -214,7 +213,7 @@ int32_t AudioDeviceIOS::InitRecording() {
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(!audio_is_initialized_);
|
||||
RTC_DCHECK(!recording_);
|
||||
RTC_DCHECK(!recording_.load());
|
||||
if (!audio_is_initialized_) {
|
||||
if (!InitPlayOrRecord()) {
|
||||
RTC_LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitRecording!";
|
||||
@ -229,12 +228,12 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
||||
LOGI() << "StartPlayout";
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_DCHECK(audio_is_initialized_);
|
||||
RTC_DCHECK(!playing_);
|
||||
RTC_DCHECK(!playing_.load());
|
||||
RTC_DCHECK(audio_unit_);
|
||||
if (fine_audio_buffer_) {
|
||||
fine_audio_buffer_->ResetPlayout();
|
||||
}
|
||||
if (!recording_ && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
||||
if (!recording_.load() && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
||||
OSStatus result = audio_unit_->Start();
|
||||
if (result != noErr) {
|
||||
RTC_OBJC_TYPE(RTCAudioSession)* session = [RTC_OBJC_TYPE(RTCAudioSession) sharedInstance];
|
||||
@ -244,7 +243,7 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
||||
}
|
||||
RTC_LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
||||
}
|
||||
rtc::AtomicOps::ReleaseStore(&playing_, 1);
|
||||
playing_.store(1, std::memory_order_release);
|
||||
num_playout_callbacks_ = 0;
|
||||
num_detected_playout_glitches_ = 0;
|
||||
return 0;
|
||||
@ -253,14 +252,14 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
||||
int32_t AudioDeviceIOS::StopPlayout() {
|
||||
LOGI() << "StopPlayout";
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
if (!audio_is_initialized_ || !playing_) {
|
||||
if (!audio_is_initialized_ || !playing_.load()) {
|
||||
return 0;
|
||||
}
|
||||
if (!recording_) {
|
||||
if (!recording_.load()) {
|
||||
ShutdownPlayOrRecord();
|
||||
audio_is_initialized_ = false;
|
||||
}
|
||||
rtc::AtomicOps::ReleaseStore(&playing_, 0);
|
||||
playing_.store(0, std::memory_order_release);
|
||||
|
||||
// Derive average number of calls to OnGetPlayoutData() between detected
|
||||
// audio glitches and add the result to a histogram.
|
||||
@ -278,19 +277,19 @@ int32_t AudioDeviceIOS::StopPlayout() {
|
||||
}
|
||||
|
||||
bool AudioDeviceIOS::Playing() const {
|
||||
return playing_;
|
||||
return playing_.load();
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::StartRecording() {
|
||||
LOGI() << "StartRecording";
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
RTC_DCHECK(audio_is_initialized_);
|
||||
RTC_DCHECK(!recording_);
|
||||
RTC_DCHECK(!recording_.load());
|
||||
RTC_DCHECK(audio_unit_);
|
||||
if (fine_audio_buffer_) {
|
||||
fine_audio_buffer_->ResetRecord();
|
||||
}
|
||||
if (!playing_ && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
||||
if (!playing_.load() && audio_unit_->GetState() == VoiceProcessingAudioUnit::kInitialized) {
|
||||
OSStatus result = audio_unit_->Start();
|
||||
if (result != noErr) {
|
||||
RTC_OBJC_TYPE(RTCAudioSession)* session = [RTC_OBJC_TYPE(RTCAudioSession) sharedInstance];
|
||||
@ -300,26 +299,26 @@ int32_t AudioDeviceIOS::StartRecording() {
|
||||
}
|
||||
RTC_LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
||||
}
|
||||
rtc::AtomicOps::ReleaseStore(&recording_, 1);
|
||||
recording_.store(1, std::memory_order_release);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::StopRecording() {
|
||||
LOGI() << "StopRecording";
|
||||
RTC_DCHECK_RUN_ON(&thread_checker_);
|
||||
if (!audio_is_initialized_ || !recording_) {
|
||||
if (!audio_is_initialized_ || !recording_.load()) {
|
||||
return 0;
|
||||
}
|
||||
if (!playing_) {
|
||||
if (!playing_.load()) {
|
||||
ShutdownPlayOrRecord();
|
||||
audio_is_initialized_ = false;
|
||||
}
|
||||
rtc::AtomicOps::ReleaseStore(&recording_, 0);
|
||||
recording_.store(0, std::memory_order_release);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool AudioDeviceIOS::Recording() const {
|
||||
return recording_;
|
||||
return recording_.load();
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::PlayoutDelay(uint16_t& delayMS) const {
|
||||
@ -381,7 +380,7 @@ OSStatus AudioDeviceIOS::OnDeliverRecordedData(AudioUnitRenderActionFlags* flags
|
||||
RTC_DCHECK_RUN_ON(&io_thread_checker_);
|
||||
OSStatus result = noErr;
|
||||
// Simply return if recording is not enabled.
|
||||
if (!rtc::AtomicOps::AcquireLoad(&recording_)) return result;
|
||||
if (!recording_.load(std::memory_order_acquire)) return result;
|
||||
|
||||
// Set the size of our own audio buffer and clear it first to avoid copying
|
||||
// in combination with potential reallocations.
|
||||
@ -434,7 +433,7 @@ OSStatus AudioDeviceIOS::OnGetPlayoutData(AudioUnitRenderActionFlags* flags,
|
||||
|
||||
// Produce silence and give audio unit a hint about it if playout is not
|
||||
// activated.
|
||||
if (!rtc::AtomicOps::AcquireLoad(&playing_)) {
|
||||
if (!playing_.load(std::memory_order_acquire)) {
|
||||
const size_t size_in_bytes = audio_buffer->mDataByteSize;
|
||||
RTC_CHECK_EQ(size_in_bytes / VoiceProcessingAudioUnit::kBytesPerSample, num_frames);
|
||||
*flags |= kAudioUnitRenderAction_OutputIsSilence;
|
||||
@ -783,16 +782,17 @@ void AudioDeviceIOS::UpdateAudioUnit(bool can_play_or_record) {
|
||||
case VoiceProcessingAudioUnit::kUninitialized:
|
||||
RTCLog(@"VPAU state: Uninitialized");
|
||||
should_initialize_audio_unit = can_play_or_record;
|
||||
should_start_audio_unit = should_initialize_audio_unit && (playing_ || recording_);
|
||||
should_start_audio_unit =
|
||||
should_initialize_audio_unit && (playing_.load() || recording_.load());
|
||||
break;
|
||||
case VoiceProcessingAudioUnit::kInitialized:
|
||||
RTCLog(@"VPAU state: Initialized");
|
||||
should_start_audio_unit = can_play_or_record && (playing_ || recording_);
|
||||
should_start_audio_unit = can_play_or_record && (playing_.load() || recording_.load());
|
||||
should_uninitialize_audio_unit = !can_play_or_record;
|
||||
break;
|
||||
case VoiceProcessingAudioUnit::kStarted:
|
||||
RTCLog(@"VPAU state: Started");
|
||||
RTC_DCHECK(playing_ || recording_);
|
||||
RTC_DCHECK(playing_.load() || recording_.load());
|
||||
should_stop_audio_unit = !can_play_or_record;
|
||||
should_uninitialize_audio_unit = should_stop_audio_unit;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user