Reland of "Create rtc::AtomicInt POD struct."
Relands https://codereview.webrtc.org/1420043008/ with brace initializers instead of constructors hoping that they won't introduce static initializers. BUG= R=tommi@webrtc.org Review URL: https://codereview.webrtc.org/1498953002 . Cr-Commit-Position: refs/heads/master@{#10920}
This commit is contained in:
@ -13,6 +13,7 @@
|
||||
|
||||
#include <AudioUnit/AudioUnit.h>
|
||||
|
||||
#include "webrtc/base/atomicops.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/base/thread_checker.h"
|
||||
#include "webrtc/modules/audio_device/audio_device_generic.h"
|
||||
@ -53,11 +54,15 @@ class AudioDeviceIOS : public AudioDeviceGeneric {
|
||||
|
||||
int32_t StartPlayout() override;
|
||||
int32_t StopPlayout() override;
|
||||
bool Playing() const override { return playing_; }
|
||||
bool Playing() const override {
|
||||
return rtc::AtomicInt::AcquireLoad(&playing_) != 0;
|
||||
}
|
||||
|
||||
int32_t StartRecording() override;
|
||||
int32_t StopRecording() override;
|
||||
bool Recording() const override { return recording_; }
|
||||
bool Recording() const override {
|
||||
return rtc::AtomicInt::AcquireLoad(&recording_) != 0;
|
||||
}
|
||||
|
||||
int32_t SetLoudspeakerStatus(bool enable) override;
|
||||
int32_t GetLoudspeakerStatus(bool& enabled) const override;
|
||||
@ -271,10 +276,10 @@ class AudioDeviceIOS : public AudioDeviceGeneric {
|
||||
rtc::scoped_ptr<SInt8[]> record_audio_buffer_;
|
||||
|
||||
// Set to 1 when recording is active and 0 otherwise.
|
||||
volatile int recording_;
|
||||
rtc::AtomicInt recording_;
|
||||
|
||||
// Set to 1 when playout is active and 0 otherwise.
|
||||
volatile int playing_;
|
||||
rtc::AtomicInt playing_;
|
||||
|
||||
// Set to true after successful call to Init(), false otherwise.
|
||||
bool initialized_;
|
||||
|
||||
@ -28,7 +28,7 @@
|
||||
namespace webrtc {
|
||||
|
||||
// Protects |g_audio_session_users|.
|
||||
static rtc::GlobalLockPod g_lock;
|
||||
static rtc::GlobalLockPod g_lock = {{0}};
|
||||
|
||||
// Counts number of users (=instances of this object) who needs an active
|
||||
// audio session. This variable is used to ensure that we only activate an audio
|
||||
@ -288,8 +288,8 @@ static void LogDeviceInfo() {
|
||||
AudioDeviceIOS::AudioDeviceIOS()
|
||||
: audio_device_buffer_(nullptr),
|
||||
vpio_unit_(nullptr),
|
||||
recording_(0),
|
||||
playing_(0),
|
||||
recording_({0}),
|
||||
playing_({0}),
|
||||
initialized_(false),
|
||||
rec_is_initialized_(false),
|
||||
play_is_initialized_(false),
|
||||
@ -359,7 +359,7 @@ int32_t AudioDeviceIOS::InitPlayout() {
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(!play_is_initialized_);
|
||||
RTC_DCHECK(!playing_);
|
||||
RTC_DCHECK(!Playing());
|
||||
if (!rec_is_initialized_) {
|
||||
if (!InitPlayOrRecord()) {
|
||||
LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitPlayout!";
|
||||
@ -375,7 +375,7 @@ int32_t AudioDeviceIOS::InitRecording() {
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(initialized_);
|
||||
RTC_DCHECK(!rec_is_initialized_);
|
||||
RTC_DCHECK(!recording_);
|
||||
RTC_DCHECK(!Recording());
|
||||
if (!play_is_initialized_) {
|
||||
if (!InitPlayOrRecord()) {
|
||||
LOG_F(LS_ERROR) << "InitPlayOrRecord failed for InitRecording!";
|
||||
@ -390,9 +390,9 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
||||
LOGI() << "StartPlayout";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(play_is_initialized_);
|
||||
RTC_DCHECK(!playing_);
|
||||
RTC_DCHECK(!Playing());
|
||||
fine_audio_buffer_->ResetPlayout();
|
||||
if (!recording_) {
|
||||
if (!Recording()) {
|
||||
OSStatus result = AudioOutputUnitStart(vpio_unit_);
|
||||
if (result != noErr) {
|
||||
LOG_F(LS_ERROR) << "AudioOutputUnitStart failed for StartPlayout: "
|
||||
@ -401,21 +401,21 @@ int32_t AudioDeviceIOS::StartPlayout() {
|
||||
}
|
||||
LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
||||
}
|
||||
rtc::AtomicOps::ReleaseStore(&playing_, 1);
|
||||
rtc::AtomicInt::ReleaseStore(&playing_, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::StopPlayout() {
|
||||
LOGI() << "StopPlayout";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
if (!play_is_initialized_ || !playing_) {
|
||||
if (!play_is_initialized_ || !Playing()) {
|
||||
return 0;
|
||||
}
|
||||
if (!recording_) {
|
||||
if (!Recording()) {
|
||||
ShutdownPlayOrRecord();
|
||||
}
|
||||
play_is_initialized_ = false;
|
||||
rtc::AtomicOps::ReleaseStore(&playing_, 0);
|
||||
rtc::AtomicInt::ReleaseStore(&playing_, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -423,9 +423,9 @@ int32_t AudioDeviceIOS::StartRecording() {
|
||||
LOGI() << "StartRecording";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
RTC_DCHECK(rec_is_initialized_);
|
||||
RTC_DCHECK(!recording_);
|
||||
RTC_DCHECK(!Recording());
|
||||
fine_audio_buffer_->ResetRecord();
|
||||
if (!playing_) {
|
||||
if (!Playing()) {
|
||||
OSStatus result = AudioOutputUnitStart(vpio_unit_);
|
||||
if (result != noErr) {
|
||||
LOG_F(LS_ERROR) << "AudioOutputUnitStart failed for StartRecording: "
|
||||
@ -434,21 +434,21 @@ int32_t AudioDeviceIOS::StartRecording() {
|
||||
}
|
||||
LOG(LS_INFO) << "Voice-Processing I/O audio unit is now started";
|
||||
}
|
||||
rtc::AtomicOps::ReleaseStore(&recording_, 1);
|
||||
rtc::AtomicInt::ReleaseStore(&recording_, 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t AudioDeviceIOS::StopRecording() {
|
||||
LOGI() << "StopRecording";
|
||||
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
||||
if (!rec_is_initialized_ || !recording_) {
|
||||
if (!rec_is_initialized_ || !Recording()) {
|
||||
return 0;
|
||||
}
|
||||
if (!playing_) {
|
||||
if (!Playing()) {
|
||||
ShutdownPlayOrRecord();
|
||||
}
|
||||
rec_is_initialized_ = false;
|
||||
rtc::AtomicOps::ReleaseStore(&recording_, 0);
|
||||
rtc::AtomicInt::ReleaseStore(&recording_, 0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1028,7 +1028,7 @@ OSStatus AudioDeviceIOS::OnRecordedDataIsAvailable(
|
||||
UInt32 in_number_frames) {
|
||||
OSStatus result = noErr;
|
||||
// Simply return if recording is not enabled.
|
||||
if (!rtc::AtomicOps::AcquireLoad(&recording_))
|
||||
if (!Recording())
|
||||
return result;
|
||||
if (in_number_frames != record_parameters_.frames_per_buffer()) {
|
||||
// We have seen short bursts (1-2 frames) where |in_number_frames| changes.
|
||||
@ -1087,7 +1087,7 @@ OSStatus AudioDeviceIOS::OnGetPlayoutData(
|
||||
SInt8* destination = static_cast<SInt8*>(io_data->mBuffers[0].mData);
|
||||
// Produce silence and give audio unit a hint about it if playout is not
|
||||
// activated.
|
||||
if (!rtc::AtomicOps::AcquireLoad(&playing_)) {
|
||||
if (!Playing()) {
|
||||
*io_action_flags |= kAudioUnitRenderAction_OutputIsSilence;
|
||||
memset(destination, 0, dataSizeInBytes);
|
||||
return noErr;
|
||||
|
||||
Reference in New Issue
Block a user