AudioFlinger: clean up ctor initialization
Test: atest AudioTrackTest AudioRecordTest
Test: atest AAudioTests AudioTrackOffloadTest
Test: atest AudioPlaybackCaptureTest
Test: Camera YouTube
Bug: 298529417
Change-Id: Idd3be2e20eb90dff7f794aad096b286b2cd7d938
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 9aefb6b..6516756 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -20,6 +20,7 @@
// Classes and interfaces directly used.
#include "Client.h"
#include "DeviceEffectManager.h"
+#include "EffectConfiguration.h"
#include "IAfEffect.h"
#include "IAfPatchPanel.h"
#include "IAfThread.h"
@@ -459,7 +460,7 @@
static const int kPostTriggerSleepPeriod = 1000000;
};
- const sp<MediaLogNotifier> mMediaLogNotifier;
+ const sp<MediaLogNotifier> mMediaLogNotifier = sp<MediaLogNotifier>::make();
// Find io handle by session id.
// Preference is given to an io handle with a matching effect chain to session id.
@@ -571,13 +572,12 @@
// NOTE: If both mLock and mHardwareLock mutexes must be held,
// always take mLock before mHardwareLock
- // guarded by mHardwareLock
- AudioHwDevice* mPrimaryHardwareDev;
- DefaultKeyedVector<audio_module_handle_t, AudioHwDevice*> mAudioHwDevs;
+ std::atomic<AudioHwDevice*> mPrimaryHardwareDev = nullptr;
+ DefaultKeyedVector<audio_module_handle_t, AudioHwDevice*> mAudioHwDevs{nullptr /* defValue */};
- // These two fields are immutable after onFirstRef(), so no lock needed to access
- sp<DevicesFactoryHalInterface> mDevicesFactoryHal;
- sp<DevicesFactoryHalCallback> mDevicesFactoryHalCallback;
+ const sp<DevicesFactoryHalInterface> mDevicesFactoryHal =
+ DevicesFactoryHalInterface::create();
+ /* const */ sp<DevicesFactoryHalCallback> mDevicesFactoryHalCallback; // set onFirstRef().
// for dump, indicates which hardware operation is currently in progress (but not stream ops)
enum hardware_call_state {
@@ -607,16 +607,15 @@
AUDIO_HW_SET_SIMULATE_CONNECTIONS, // setSimulateDeviceConnections
};
- mutable hardware_call_state mHardwareStatus; // for dump only
-
+ mutable hardware_call_state mHardwareStatus = AUDIO_HW_IDLE; // for dump only
DefaultKeyedVector<audio_io_handle_t, sp<IAfPlaybackThread>> mPlaybackThreads;
stream_type_t mStreamTypes[AUDIO_STREAM_CNT];
// member variables below are protected by mLock
- float mMasterVolume;
- bool mMasterMute;
- float mMasterBalance = 0.f;
+ float mMasterVolume = 1.f;
+ bool mMasterMute = false;
+ float mMasterBalance = 0.f;
// end of variables protected by mLock
DefaultKeyedVector<audio_io_handle_t, sp<IAfRecordThread>> mRecordThreads;
@@ -625,10 +624,10 @@
DefaultKeyedVector< pid_t, sp<NotificationClient> > mNotificationClients;
// updated by atomic_fetch_add_explicit
- volatile atomic_uint_fast32_t mNextUniqueIds[AUDIO_UNIQUE_ID_USE_MAX];
+ volatile atomic_uint_fast32_t mNextUniqueIds[AUDIO_UNIQUE_ID_USE_MAX]; // ctor init
- audio_mode_t mMode;
- std::atomic_bool mBtNrecIsOff;
+ std::atomic<audio_mode_t> mMode = AUDIO_MODE_INVALID;
+ std::atomic<bool> mBtNrecIsOff = false;
// protected by mLock
Vector<AudioSessionRef*> mAudioSessionRefs;
@@ -667,24 +666,25 @@
// though the variables are updated with mLock.
size_t getClientSharedHeapSize() const;
- std::atomic<bool> mIsLowRamDevice;
- bool mIsDeviceTypeKnown;
- int64_t mTotalMemory;
- std::atomic<size_t> mClientSharedHeapSize;
+ std::atomic<bool> mIsLowRamDevice = true;
+ bool mIsDeviceTypeKnown = false;
+ int64_t mTotalMemory = 0;
+ std::atomic<size_t> mClientSharedHeapSize = kMinimumClientSharedHeapSizeBytes;
static constexpr size_t kMinimumClientSharedHeapSizeBytes = 1024 * 1024; // 1MB
- nsecs_t mGlobalEffectEnableTime; // when a global effect was last enabled
+ nsecs_t mGlobalEffectEnableTime = 0; // when a global effect was last enabled
/* const */ sp<IAfPatchPanel> mPatchPanel;
- sp<EffectsFactoryHalInterface> mEffectsFactoryHal;
+ const sp<EffectsFactoryHalInterface> mEffectsFactoryHal =
+ audioflinger::EffectConfiguration::getEffectsFactoryHal();
- const sp<PatchCommandThread> mPatchCommandThread;
+ const sp<PatchCommandThread> mPatchCommandThread = sp<PatchCommandThread>::make();
/* const */ sp<DeviceEffectManager> mDeviceEffectManager; // set onFirstRef
/* const */ sp<MelReporter> mMelReporter; // set onFirstRef
- bool mSystemReady;
- std::atomic_bool mAudioPolicyReady{};
+ bool mSystemReady = false;
+ std::atomic<bool> mAudioPolicyReady = false;
mediautils::UidInfo mUidInfo;
@@ -705,7 +705,7 @@
mediautils::atomic_sp<IAudioManager> mAudioManager;
// Bluetooth Variable latency control logic is enabled or disabled
- std::atomic_bool mBluetoothLatencyModesEnabled;
+ std::atomic<bool> mBluetoothLatencyModesEnabled = true;
};
// ----------------------------------------------------------------------------