AudioFlinger: Move standby time property load to Threads
Test: atest AudioRecordTest AudioTrackTest
Test: Camera YouTube
Bug: 182392769
Bug: 292018229
Merged-In: Ib381b58ac2d23759a5ad4fa8eac048ab32247f85
Change-Id: Ib381b58ac2d23759a5ad4fa8eac048ab32247f85
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 523b074..53c4f9f 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -126,8 +126,6 @@
static constexpr char kAudioServiceName[] = "audio";
-nsecs_t AudioFlinger::mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs;
-
// In order to avoid invalidating offloaded tracks each time a Visualizer is turned on and off
// we define a minimum time during which a global effect is considered enabled.
static const nsecs_t kMinGlobalEffectEnabletimeNs = seconds(7200);
@@ -343,20 +341,6 @@
{
Mutex::Autolock _l(mLock);
- /* TODO: move all this work into an Init() function */
- char val_str[PROPERTY_VALUE_MAX] = { 0 };
- if (property_get("ro.audio.flinger_standbytime_ms", val_str, NULL) >= 0) {
- uint32_t int_val;
- if (1 == sscanf(val_str, "%u", &int_val)) {
- mStandbyTimeInNsecs = milliseconds(int_val);
- ALOGI("Using %u mSec as standby time.", int_val);
- } else {
- mStandbyTimeInNsecs = kDefaultStandbyTimeInNsecs;
- ALOGI("Using default %u mSec as standby time.",
- (uint32_t)(mStandbyTimeInNsecs / 1000000));
- }
- }
-
mMode = AUDIO_MODE_NORMAL;
gAudioFlinger = this; // we are already refcounted, store into atomic pointer.
@@ -760,10 +744,7 @@
String8 result;
hardware_call_state hardwareStatus = mHardwareStatus;
- snprintf(buffer, SIZE, "Hardware status: %d\n"
- "Standby Time mSec: %u\n",
- hardwareStatus,
- (uint32_t)(mStandbyTimeInNsecs / 1000000));
+ snprintf(buffer, SIZE, "Hardware status: %d\n", hardwareStatus);
result.append(buffer);
write(fd, result.c_str(), result.size());
diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h
index 5427434..c96b584 100644
--- a/services/audioflinger/AudioFlinger.h
+++ b/services/audioflinger/AudioFlinger.h
@@ -149,8 +149,6 @@
// ----------------------------------------------------------------------------
-static const nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);
-
using android::content::AttributionSourceState;
struct stream_type_t {
@@ -559,10 +557,6 @@
}
}
- // standby delay for MIXER and DUPLICATING playback threads is read from property
- // ro.audio.flinger_standbytime_ms or defaults to kDefaultStandbyTimeInNsecs
- static nsecs_t mStandbyTimeInNsecs;
-
private:
// incremented by 2 when screen state changes, bit 0 == 1 means "off"
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index f6b8e19..c8338b2 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -245,6 +245,18 @@
// and that all "fast" AudioRecord clients read from. In either case, the size can be small.
static const size_t kRecordThreadReadOnlyHeapSize = 0xD000;
+static constexpr nsecs_t kDefaultStandbyTimeInNsecs = seconds(3);
+
+static nsecs_t getStandbyTimeInNanos() {
+ static nsecs_t standbyTimeInNanos = []() {
+ const int ms = property_get_int32("ro.audio.flinger_standbytime_ms",
+ kDefaultStandbyTimeInNsecs / NANOS_PER_MILLISECOND);
+ ALOGI("%s: Using %d ms as standby time", __func__, ms);
+ return milliseconds(ms);
+ }();
+ return standbyTimeInNanos;
+}
+
// ----------------------------------------------------------------------------
// TODO: move all toString helpers to audio.h
@@ -2085,7 +2097,7 @@
mNumWrites(0), mNumDelayedWrites(0), mInWrite(false),
mMixerStatus(MIXER_IDLE),
mMixerStatusIgnoringFastTracks(MIXER_IDLE),
- mStandbyDelayNs(AudioFlinger::mStandbyTimeInNsecs),
+ mStandbyDelayNs(getStandbyTimeInNanos()),
mBytesRemaining(0),
mCurrentWriteLength(0),
mUseAsyncWrite(false),
@@ -3558,7 +3570,7 @@
mActiveSleepTimeUs = activeSleepTimeUs();
mIdleSleepTimeUs = idleSleepTimeUs();
- mStandbyDelayNs = AudioFlinger::mStandbyTimeInNsecs;
+ mStandbyDelayNs = getStandbyTimeInNanos();
// make sure standby delay is not too short when connected to an A2DP sink to avoid
// truncating audio when going to standby.