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
@ -277,7 +277,6 @@ if (is_ios || is_mac) {
|
||||
"../modules/audio_device:audio_device_buffer",
|
||||
"../modules/audio_device:audio_device_generic",
|
||||
"../rtc_base",
|
||||
"../rtc_base:atomicops",
|
||||
"../rtc_base:buffer",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base:logging",
|
||||
@ -348,7 +347,6 @@ if (is_ios || is_mac) {
|
||||
":base_objc",
|
||||
":helpers_objc",
|
||||
"../rtc_base",
|
||||
"../rtc_base:atomicops",
|
||||
"../rtc_base:checks",
|
||||
"../rtc_base/synchronization:mutex",
|
||||
]
|
||||
|
||||
@ -951,7 +951,6 @@ if (current_os == "linux" || is_android) {
|
||||
":generated_native_api_jni",
|
||||
":internal_jni",
|
||||
"../../api:sequence_checker",
|
||||
"../../rtc_base:atomicops",
|
||||
"//api:array_view",
|
||||
"//rtc_base:checks",
|
||||
]
|
||||
|
||||
@ -10,7 +10,6 @@
|
||||
|
||||
#include "sdk/android/src/jni/jni_generator_helper.h"
|
||||
|
||||
#include "rtc_base/atomic_ops.h"
|
||||
#include "sdk/android/native_api/jni/class_loader.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
@ -12,10 +12,10 @@
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <vector>
|
||||
|
||||
#include "absl/base/attributes.h"
|
||||
#include "rtc_base/atomic_ops.h"
|
||||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
|
||||
@ -48,8 +48,8 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
||||
@implementation RTC_OBJC_TYPE (RTCAudioSession) {
|
||||
webrtc::Mutex _mutex;
|
||||
AVAudioSession *_session;
|
||||
volatile int _activationCount;
|
||||
volatile int _webRTCSessionCount;
|
||||
std::atomic<int> _activationCount;
|
||||
std::atomic<int> _webRTCSessionCount;
|
||||
BOOL _isActive;
|
||||
BOOL _useManualAudio;
|
||||
BOOL _isAudioEnabled;
|
||||
@ -351,7 +351,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
||||
if (![self checkLock:outError]) {
|
||||
return NO;
|
||||
}
|
||||
int activationCount = _activationCount;
|
||||
int activationCount = _activationCount.load();
|
||||
if (!active && activationCount == 0) {
|
||||
RTCLogWarning(@"Attempting to deactivate without prior activation.");
|
||||
}
|
||||
@ -403,7 +403,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
||||
[self notifyDidSetActive:active];
|
||||
[self decrementActivationCount];
|
||||
}
|
||||
RTCLog(@"Number of current activations: %d", _activationCount);
|
||||
RTCLog(@"Number of current activations: %d", _activationCount.load());
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -643,21 +643,21 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
||||
}
|
||||
|
||||
- (int)activationCount {
|
||||
return _activationCount;
|
||||
return _activationCount.load();
|
||||
}
|
||||
|
||||
- (int)incrementActivationCount {
|
||||
RTCLog(@"Incrementing activation count.");
|
||||
return rtc::AtomicOps::Increment(&_activationCount);
|
||||
return _activationCount.fetch_add(1) + 1;
|
||||
}
|
||||
|
||||
- (NSInteger)decrementActivationCount {
|
||||
RTCLog(@"Decrementing activation count.");
|
||||
return rtc::AtomicOps::Decrement(&_activationCount);
|
||||
return _activationCount.fetch_sub(1) - 1;
|
||||
}
|
||||
|
||||
- (int)webRTCSessionCount {
|
||||
return _webRTCSessionCount;
|
||||
return _webRTCSessionCount.load();
|
||||
}
|
||||
|
||||
- (BOOL)canPlayOrRecord {
|
||||
@ -693,7 +693,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
||||
if (outError) {
|
||||
*outError = nil;
|
||||
}
|
||||
rtc::AtomicOps::Increment(&_webRTCSessionCount);
|
||||
_webRTCSessionCount.fetch_add(1);
|
||||
[self notifyDidStartPlayOrRecord];
|
||||
return YES;
|
||||
}
|
||||
@ -702,7 +702,7 @@ ABSL_CONST_INIT thread_local bool mutex_locked = false;
|
||||
if (outError) {
|
||||
*outError = nil;
|
||||
}
|
||||
rtc::AtomicOps::Decrement(&_webRTCSessionCount);
|
||||
_webRTCSessionCount.fetch_sub(1);
|
||||
[self notifyDidStopPlayOrRecord];
|
||||
return YES;
|
||||
}
|
||||
|
||||
@ -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