summaryrefslogtreecommitdiffstats
path: root/libaudio
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2011-01-21 15:50:31 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2011-01-21 15:50:31 -0800
commit87bbe23ebffab7f5fdea3f8f673f14f6414ee0ce (patch)
tree482c20a6948d285834b0ffbe2c9a0857a051dc98 /libaudio
parent927003b34fbcbaabc19825eccf35bd8807dfcc8f (diff)
parent92786a1ce7e7dd078d1a5c05411715d4a617dc57 (diff)
downloaddevice_samsung_crespo-87bbe23ebffab7f5fdea3f8f673f14f6414ee0ce.zip
device_samsung_crespo-87bbe23ebffab7f5fdea3f8f673f14f6414ee0ce.tar.gz
device_samsung_crespo-87bbe23ebffab7f5fdea3f8f673f14f6414ee0ce.tar.bz2
am 92786a1c: am 27cc0c78: Merge "Fix issue 3305305." into gingerbread
* commit '92786a1ce7e7dd078d1a5c05411715d4a617dc57': Fix issue 3305305.
Diffstat (limited to 'libaudio')
-rw-r--r--libaudio/AudioHardware.cpp66
-rw-r--r--libaudio/AudioHardware.h12
2 files changed, 62 insertions, 16 deletions
diff --git a/libaudio/AudioHardware.cpp b/libaudio/AudioHardware.cpp
index 7a39d93..b21cef2 100644
--- a/libaudio/AudioHardware.cpp
+++ b/libaudio/AudioHardware.cpp
@@ -316,17 +316,13 @@ status_t AudioHardware::setMode(int mode)
sp<AudioStreamInALSA> spIn;
status_t status;
- // bump thread priority to speed up mutex acquisition
- int priority = getpriority(PRIO_PROCESS, 0);
- setpriority(PRIO_PROCESS, 0, ANDROID_PRIORITY_URGENT_AUDIO);
-
// Mutex acquisition order is always out -> in -> hw
AutoMutex lock(mLock);
spOut = mOutput;
while (spOut != 0) {
if (!spOut->checkStandby()) {
- int cnt = spOut->standbyCnt();
+ int cnt = spOut->prepareLock();
mLock.unlock();
spOut->lock();
mLock.lock();
@@ -345,7 +341,7 @@ status_t AudioHardware::setMode(int mode)
spIn = getActiveInput_l();
while (spIn != 0) {
- int cnt = spIn->standbyCnt();
+ int cnt = spIn->prepareLock();
mLock.unlock();
spIn->lock();
mLock.lock();
@@ -359,8 +355,6 @@ status_t AudioHardware::setMode(int mode)
}
// spIn is not 0 here only if the input is active
- setpriority(PRIO_PROCESS, 0, priority);
-
int prevMode = mMode;
status = AudioHardwareBase::setMode(mode);
LOGV("setMode() : new %d, old %d", mMode, prevMode);
@@ -947,7 +941,7 @@ AudioHardware::AudioStreamOutALSA::AudioStreamOutALSA() :
mHardware(0), mPcm(0), mMixer(0), mRouteCtl(0),
mStandby(true), mDevices(0), mChannels(AUDIO_HW_OUT_CHANNELS),
mSampleRate(AUDIO_HW_OUT_SAMPLERATE), mBufferSize(AUDIO_HW_OUT_PERIOD_BYTES),
- mDriverOp(DRV_NONE), mStandbyCnt(0)
+ mDriverOp(DRV_NONE), mStandbyCnt(0), mSleepReq(false)
{
}
@@ -1002,6 +996,12 @@ ssize_t AudioHardware::AudioStreamOutALSA::write(const void* buffer, size_t byte
if (mHardware == NULL) return NO_INIT;
+ if (mSleepReq) {
+ // 10ms are always shorter than the time to reconfigure the audio path
+ // which is the only condition when mSleepReq would be true.
+ usleep(10000);
+ }
+
{ // scope for the lock
AutoMutex lock(mLock);
@@ -1014,7 +1014,7 @@ ssize_t AudioHardware::AudioStreamOutALSA::write(const void* buffer, size_t byte
sp<AudioStreamInALSA> spIn = mHardware->getActiveInput_l();
while (spIn != 0) {
- int cnt = spIn->standbyCnt();
+ int cnt = spIn->prepareLock();
mHardware->lock().unlock();
// Mutex acquisition order is always out -> in -> hw
spIn->lock();
@@ -1239,6 +1239,24 @@ status_t AudioHardware::AudioStreamOutALSA::getRenderPosition(uint32_t *dspFrame
return INVALID_OPERATION;
}
+int AudioHardware::AudioStreamOutALSA::prepareLock()
+{
+ // request sleep next time write() is called so that caller can acquire
+ // mLock
+ mSleepReq = true;
+ return mStandbyCnt;
+}
+
+void AudioHardware::AudioStreamOutALSA::lock()
+{
+ mLock.lock();
+ mSleepReq = false;
+}
+
+void AudioHardware::AudioStreamOutALSA::unlock() {
+ mLock.unlock();
+}
+
//------------------------------------------------------------------------------
// AudioStreamInALSA
//------------------------------------------------------------------------------
@@ -1248,7 +1266,7 @@ AudioHardware::AudioStreamInALSA::AudioStreamInALSA() :
mStandby(true), mDevices(0), mChannels(AUDIO_HW_IN_CHANNELS), mChannelCount(1),
mSampleRate(AUDIO_HW_IN_SAMPLERATE), mBufferSize(AUDIO_HW_IN_PERIOD_BYTES),
mDownSampler(NULL), mReadStatus(NO_ERROR), mDriverOp(DRV_NONE),
- mStandbyCnt(0)
+ mStandbyCnt(0), mSleepReq(false)
{
}
@@ -1320,6 +1338,12 @@ ssize_t AudioHardware::AudioStreamInALSA::read(void* buffer, ssize_t bytes)
if (mHardware == NULL) return NO_INIT;
+ if (mSleepReq) {
+ // 10ms are always shorter than the time to reconfigure the audio path
+ // which is the only condition when mSleepReq would be true.
+ usleep(10000);
+ }
+
{ // scope for the lock
AutoMutex lock(mLock);
@@ -1332,7 +1356,7 @@ ssize_t AudioHardware::AudioStreamInALSA::read(void* buffer, ssize_t bytes)
sp<AudioStreamOutALSA> spOut = mHardware->output();
while (spOut != 0) {
if (!spOut->checkStandby()) {
- int cnt = spOut->standbyCnt();
+ int cnt = spOut->prepareLock();
mHardware->lock().unlock();
mLock.unlock();
// Mutex acquisition order is always out -> in -> hw
@@ -1657,6 +1681,24 @@ size_t AudioHardware::AudioStreamInALSA::getBufferSize(uint32_t sampleRate, int
return (AUDIO_HW_IN_PERIOD_SZ*channelCount*sizeof(int16_t)) / ratio ;
}
+int AudioHardware::AudioStreamInALSA::prepareLock()
+{
+ // request sleep next time read() is called so that caller can acquire
+ // mLock
+ mSleepReq = true;
+ return mStandbyCnt;
+}
+
+void AudioHardware::AudioStreamInALSA::lock()
+{
+ mLock.lock();
+ mSleepReq = false;
+}
+
+void AudioHardware::AudioStreamInALSA::unlock() {
+ mLock.unlock();
+}
+
//------------------------------------------------------------------------------
// DownSampler
//------------------------------------------------------------------------------
diff --git a/libaudio/AudioHardware.h b/libaudio/AudioHardware.h
index 0a09f18..428cf12 100644
--- a/libaudio/AudioHardware.h
+++ b/libaudio/AudioHardware.h
@@ -208,8 +208,9 @@ private:
status_t open_l();
int standbyCnt() { return mStandbyCnt; }
- void lock() { mLock.lock(); }
- void unlock() { mLock.unlock(); }
+ int prepareLock();
+ void lock();
+ void unlock();
private:
@@ -227,6 +228,7 @@ private:
// trace driver operations for dump
int mDriverOp;
int mStandbyCnt;
+ bool mSleepReq;
};
class DownSampler;
@@ -321,8 +323,9 @@ private:
virtual status_t getNextBuffer(BufferProvider::Buffer* buffer);
virtual void releaseBuffer(BufferProvider::Buffer* buffer);
- void lock() { mLock.lock(); }
- void unlock() { mLock.unlock(); }
+ int prepareLock();
+ void lock();
+ void unlock();
private:
Mutex mLock;
@@ -344,6 +347,7 @@ private:
// trace driver operations for dump
int mDriverOp;
int mStandbyCnt;
+ bool mSleepReq;
};
};