From 37d825e72a6c606553a745da1212590a425996d3 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Fri, 24 Feb 2012 07:21:48 -0800 Subject: Pull out duplicated copies of silent mode check Also fix the error handling for the property_get. This is part of preparation for the threadLoop() merge. Change-Id: I6405190ea18146d1271575e1dfe9f279e8f36b17 --- services/audioflinger/AudioFlinger.cpp | 45 +++++++++++++++------------------- services/audioflinger/AudioFlinger.h | 3 +++ 2 files changed, 23 insertions(+), 25 deletions(-) (limited to 'services') diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 2c3329e..d522091 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -1973,6 +1973,23 @@ void CpuStats::sample() { #endif }; +void AudioFlinger::PlaybackThread::checkSilentMode_l() +{ + if (!mMasterMute) { + char value[PROPERTY_VALUE_MAX]; + if (property_get("ro.audio.silent", value, "0") > 0) { + char *endptr; + unsigned long ul = strtoul(value, &endptr, 0); + if (*endptr == '\0' && ul != 0) { + ALOGD("Silence is golden"); + // The setprop command will not allow a property to be changed after + // the first time it is set, so we don't have to worry about un-muting. + setMasterMute_l(true); + } + } + } +} + bool AudioFlinger::MixerThread::threadLoop() { Vector< sp > tracksToRemove; @@ -2042,14 +2059,7 @@ bool AudioFlinger::MixerThread::threadLoop() acquireWakeLock_l(); mPrevMixerStatus = MIXER_IDLE; - if (!mMasterMute) { - char value[PROPERTY_VALUE_MAX]; - property_get("ro.audio.silent", value, "0"); - if (atoi(value)) { - ALOGD("Silence is golden"); - setMasterMute_l(true); - } - } + checkSilentMode_l(); standbyTime = systemTime() + mStandbyTimeInNsecs; sleepTime = idleSleepTime; @@ -2751,14 +2761,7 @@ bool AudioFlinger::DirectOutputThread::threadLoop() ALOGV("DirectOutputThread %p TID %d waking up in active mode", this, gettid()); acquireWakeLock_l(); - if (!mMasterMute) { - char value[PROPERTY_VALUE_MAX]; - property_get("ro.audio.silent", value, "0"); - if (atoi(value)) { - ALOGD("Silence is golden"); - setMasterMute_l(true); - } - } + checkSilentMode_l(); standbyTime = systemTime() + standbyDelay; sleepTime = idleSleepTime; @@ -3147,15 +3150,7 @@ bool AudioFlinger::DuplicatingThread::threadLoop() ALOGV("DuplicatingThread %p TID %d waking up", this, gettid()); acquireWakeLock_l(); - mPrevMixerStatus = MIXER_IDLE; - if (!mMasterMute) { - char value[PROPERTY_VALUE_MAX]; - property_get("ro.audio.silent", value, "0"); - if (atoi(value)) { - ALOGD("Silence is golden"); - setMasterMute_l(true); - } - } + checkSilentMode_l(); standbyTime = systemTime() + mStandbyTimeInNsecs; sleepTime = idleSleepTime; diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index a2ab680..2a5d805 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -859,6 +859,9 @@ private: virtual uint32_t idleSleepTimeUs() = 0; virtual uint32_t suspendSleepTimeUs() = 0; + // Code snippets that are temporarily lifted up out of threadLoop() until the merge + void checkSilentMode_l(); + private: friend class AudioFlinger; -- cgit v1.1