summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcodeworkx <daniel.hillenbrand@codeworkx.de>2011-03-01 07:59:04 -0800
committercodeworkx <daniel.hillenbrand@codeworkx.de>2011-03-01 07:59:04 -0800
commitc8c2110d6bcac25eb151acb7543fe53154d29c17 (patch)
treef79d9ddcb99d3180fb92714166d55b23365111cb
parent17bc56198afddda0f18b0d2bc0f270264a90fbcd (diff)
downloaddevice_samsung_aries-common-c8c2110d6bcac25eb151acb7543fe53154d29c17.zip
device_samsung_aries-common-c8c2110d6bcac25eb151acb7543fe53154d29c17.tar.gz
device_samsung_aries-common-c8c2110d6bcac25eb151acb7543fe53154d29c17.tar.bz2
kanged 2.3.3 libaudio changes from crespo
-rw-r--r--aries/libaudio/AudioHardware.cpp195
-rw-r--r--aries/libaudio/AudioHardware.h33
-rw-r--r--aries/libaudio/AudioPolicyManager.cpp28
-rw-r--r--aries/libaudio/AudioPolicyManager.h1
4 files changed, 180 insertions, 77 deletions
diff --git a/aries/libaudio/AudioHardware.cpp b/aries/libaudio/AudioHardware.cpp
index 10409a1..45f0a2d 100644
--- a/aries/libaudio/AudioHardware.cpp
+++ b/aries/libaudio/AudioHardware.cpp
@@ -73,6 +73,11 @@ enum {
// ----------------------------------------------------------------------------
+const char *AudioHardware::inputPathNameDefault = "Default";
+const char *AudioHardware::inputPathNameCamcorder = "Camcorder";
+const char *AudioHardware::inputPathNameVoiceRecognition = "Voice Recognition";
+const char *AudioHardware::inputPathNameVoiceCommunication = "Voice Communication";
+
AudioHardware::AudioHardware() :
mInit(false),
mMicMute(false),
@@ -81,8 +86,9 @@ AudioHardware::AudioHardware() :
mPcmOpenCnt(0),
mMixerOpenCnt(0),
mInCallAudioMode(false),
- mInputSource("Default"),
+ mInputSource(AUDIO_SOURCE_DEFAULT),
mBluetoothNrec(true),
+ mTTYMode(TTY_MODE_OFF),
mSecRilLibHandle(NULL),
mRilClient(0),
mActivatedCP(false),
@@ -312,17 +318,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();
@@ -341,7 +343,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();
@@ -355,8 +357,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);
@@ -383,7 +383,7 @@ status_t AudioHardware::setMode(int mode)
LOGV("setMode() openPcmOut_l()");
openPcmOut_l();
openMixer_l();
- setInputSource_l(String8("Default"));
+ setInputSource_l(AUDIO_SOURCE_DEFAULT);
mInCallAudioMode = true;
}
if (mMode == AudioSystem::MODE_NORMAL && mInCallAudioMode) {
@@ -466,6 +466,11 @@ status_t AudioHardware::setParameters(const String8& keyValuePairs)
String8 key;
const char BT_NREC_KEY[] = "bt_headset_nrec";
const char BT_NREC_VALUE_ON[] = "on";
+ const char TTY_MODE_KEY[] = "tty_mode";
+ const char TTY_MODE_VALUE_OFF[] = "tty_off";
+ const char TTY_MODE_VALUE_VCO[] = "tty_vco";
+ const char TTY_MODE_VALUE_HCO[] = "tty_hco";
+ const char TTY_MODE_VALUE_FULL[] = "tty_full";
key = String8(BT_NREC_KEY);
if (param.get(key, value) == NO_ERROR) {
@@ -476,8 +481,34 @@ status_t AudioHardware::setParameters(const String8& keyValuePairs)
LOGD("Turning noise reduction and echo cancellation off for BT "
"headset");
}
+ param.remove(String8(BT_NREC_KEY));
}
+ key = String8(TTY_MODE_KEY);
+ if (param.get(key, value) == NO_ERROR) {
+ int ttyMode;
+ if (value == TTY_MODE_VALUE_OFF) {
+ ttyMode = TTY_MODE_OFF;
+ } else if (value == TTY_MODE_VALUE_VCO) {
+ ttyMode = TTY_MODE_VCO;
+ } else if (value == TTY_MODE_VALUE_HCO) {
+ ttyMode = TTY_MODE_HCO;
+ } else if (value == TTY_MODE_VALUE_FULL) {
+ ttyMode = TTY_MODE_FULL;
+ } else {
+ return BAD_VALUE;
+ }
+
+ if (ttyMode != mTTYMode) {
+ LOGV("new tty mode %d", ttyMode);
+ mTTYMode = ttyMode;
+ if (mOutput != 0 && mMode == AudioSystem::MODE_IN_CALL) {
+ setIncallPath_l(mOutput->device());
+ }
+ }
+ param.remove(String8(TTY_MODE_KEY));
+ }
+
return NO_ERROR;
}
@@ -615,7 +646,7 @@ status_t AudioHardware::dump(int fd, const Vector<String16>& args)
snprintf(buffer, SIZE, "\tIn Call Audio Mode %s\n",
(mInCallAudioMode) ? "ON" : "OFF");
result.append(buffer);
- snprintf(buffer, SIZE, "\tInput source %s\n", mInputSource.string());
+ snprintf(buffer, SIZE, "\tInput source %d\n", mInputSource);
result.append(buffer);
snprintf(buffer, SIZE, "\tmSecRilLibHandle: %p\n", mSecRilLibHandle);
result.append(buffer);
@@ -682,12 +713,10 @@ status_t AudioHardware::setIncallPath_l(uint32_t device)
LOGD("### incall mode headphone route");
path = SOUND_AUDIO_PATH_HEADPHONE;
break;
-
case AudioSystem::DEVICE_OUT_WIRED_HEADSET :
LOGD("### incall mode headset route");
path = SOUND_AUDIO_PATH_HEADSET;
break;
-
default:
LOGW("### incall mode Error!! route = [%d]", device);
path = SOUND_AUDIO_PATH_HANDSET;
@@ -830,9 +859,22 @@ const char *AudioHardware::getVoiceRouteFromDevice(uint32_t device)
case AudioSystem::DEVICE_OUT_SPEAKER:
return "SPK";
case AudioSystem::DEVICE_OUT_WIRED_HEADPHONE:
- return "HP_NO_MIC";
case AudioSystem::DEVICE_OUT_WIRED_HEADSET:
- return "HP";
+ switch (mTTYMode) {
+ case TTY_MODE_VCO:
+ return "TTY_VCO";
+ case TTY_MODE_HCO:
+ return "TTY_HCO";
+ case TTY_MODE_FULL:
+ return "TTY_FULL";
+ case TTY_MODE_OFF:
+ default:
+ if (device == AudioSystem::DEVICE_OUT_WIRED_HEADPHONE) {
+ return "HP_NO_MIC";
+ } else {
+ return "HP";
+ }
+ }
case AudioSystem::DEVICE_OUT_BLUETOOTH_SCO:
case AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_HEADSET:
case AudioSystem::DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
@@ -891,11 +933,11 @@ sp <AudioHardware::AudioStreamInALSA> AudioHardware::getActiveInput_l()
return spIn;
}
-status_t AudioHardware::setInputSource_l(String8 source)
+status_t AudioHardware::setInputSource_l(audio_source source)
{
- LOGV("setInputSource_l(%s)", source.string());
+ LOGV("setInputSource_l(%d)", source);
if (source != mInputSource) {
- if ((source == "Default") || (mMode != AudioSystem::MODE_IN_CALL)) {
+ if ((source == AUDIO_SOURCE_DEFAULT) || (mMode != AudioSystem::MODE_IN_CALL)) {
if (mMixer) {
TRACE_DRIVER_IN(DRV_MIXER_GET)
struct mixer_ctl *ctl= mixer_get_control(mMixer, "Input Source", 0);
@@ -903,9 +945,30 @@ status_t AudioHardware::setInputSource_l(String8 source)
if (ctl == NULL) {
return NO_INIT;
}
- LOGV("mixer_ctl_select, Input Source, (%s)", source.string());
+ const char* sourceName;
+ switch (source) {
+ case AUDIO_SOURCE_DEFAULT: // intended fall-through
+ case AUDIO_SOURCE_MIC:
+ sourceName = inputPathNameDefault;
+ break;
+ case AUDIO_SOURCE_VOICE_COMMUNICATION:
+ sourceName = inputPathNameVoiceCommunication;
+ break;
+ case AUDIO_SOURCE_CAMCORDER:
+ sourceName = inputPathNameCamcorder;
+ break;
+ case AUDIO_SOURCE_VOICE_RECOGNITION:
+ sourceName = inputPathNameVoiceRecognition;
+ break;
+ case AUDIO_SOURCE_VOICE_UPLINK: // intended fall-through
+ case AUDIO_SOURCE_VOICE_DOWNLINK: // intended fall-through
+ case AUDIO_SOURCE_VOICE_CALL: // intended fall-through
+ default:
+ return NO_INIT;
+ }
+ LOGV("mixer_ctl_select, Input Source, (%s)", sourceName);
TRACE_DRIVER_IN(DRV_MIXER_SEL)
- mixer_ctl_select(ctl, source.string());
+ mixer_ctl_select(ctl, sourceName);
TRACE_DRIVER_OUT
}
}
@@ -924,7 +987,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)
{
}
@@ -979,6 +1042,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);
@@ -991,7 +1060,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();
@@ -1172,16 +1241,18 @@ status_t AudioHardware::AudioStreamOutALSA::setParameters(const String8& keyValu
if (param.getInt(String8(AudioParameter::keyRouting), device) == NO_ERROR)
{
- AutoMutex hwLock(mHardware->lock());
+ if (device != 0) {
+ AutoMutex hwLock(mHardware->lock());
- if (mDevices != (uint32_t)device) {
- mDevices = (uint32_t)device;
- if (mHardware->mode() != AudioSystem::MODE_IN_CALL) {
- doStandby_l();
+ if (mDevices != (uint32_t)device) {
+ mDevices = (uint32_t)device;
+ if (mHardware->mode() != AudioSystem::MODE_IN_CALL) {
+ doStandby_l();
+ }
+ }
+ if (mHardware->mode() == AudioSystem::MODE_IN_CALL) {
+ mHardware->setIncallPath_l(device);
}
- }
- if (mHardware->mode() == AudioSystem::MODE_IN_CALL) {
- mHardware->setIncallPath_l(device);
}
param.remove(String8(AudioParameter::keyRouting));
}
@@ -1216,6 +1287,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
//------------------------------------------------------------------------------
@@ -1225,7 +1314,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)
{
}
@@ -1297,6 +1386,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);
@@ -1309,7 +1404,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
@@ -1523,7 +1618,6 @@ status_t AudioHardware::AudioStreamInALSA::setParameters(const String8& keyValue
AudioParameter param = AudioParameter(keyValuePairs);
status_t status = NO_ERROR;
int value;
- String8 source;
LOGD("AudioStreamInALSA::setParameters() %s", keyValuePairs.string());
@@ -1532,14 +1626,14 @@ status_t AudioHardware::AudioStreamInALSA::setParameters(const String8& keyValue
{
AutoMutex lock(mLock);
- if (param.get(String8(INPUT_SOURCE_KEY), source) == NO_ERROR) {
+ if (param.getInt(String8(AudioParameter::keyInputSource), value) == NO_ERROR) {
AutoMutex hwLock(mHardware->lock());
mHardware->openMixer_l();
- mHardware->setInputSource_l(source);
+ mHardware->setInputSource_l((audio_source)value);
mHardware->closeMixer_l();
- param.remove(String8(INPUT_SOURCE_KEY));
+ param.remove(String8(AudioParameter::keyInputSource));
}
if (param.getInt(String8(AudioParameter::keyRouting), value) == NO_ERROR)
@@ -1635,6 +1729,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
//------------------------------------------------------------------------------
@@ -1771,16 +1883,17 @@ void resample_441_320(int16_t* input, int16_t* output, int* num_samples_in, int*
}
const float step_float = (float)RESAMPLE_16KHZ_SAMPLES_IN / (float)RESAMPLE_16KHZ_SAMPLES_OUT;
+ const uint32_t step = (uint32_t)(step_float * 32768.0f + 0.5f); // 17.15 fixed point
- uint32_t in_sample_num = 0; // 16.16 fixed point
- const uint32_t step = (uint32_t)(step_float * 65536.0f + 0.5f); // 16.16 fixed point
+ uint32_t in_sample_num = 0; // 17.15 fixed point
for (int j = 0; j < RESAMPLE_16KHZ_SAMPLES_OUT; ++j, in_sample_num += step) {
- const uint32_t whole = in_sample_num >> 16;
- const uint32_t frac = (in_sample_num & 0xffff); // 0.16 fixed point
+ const uint32_t whole = in_sample_num >> 15;
+ const uint32_t frac = (in_sample_num & 0x7fff); // 0.15 fixed point
const int32_t s1 = tmp[whole];
const int32_t s2 = tmp[whole + 1];
- *output++ = clip(s1 + (((s2 - s1) * (int32_t)frac) >> 16));
+ *output++ = clip(s1 + (((s2 - s1) * (int32_t)frac) >> 15));
}
+
}
const int samples_consumed = num_blocks * RESAMPLE_16KHZ_SAMPLES_IN;
diff --git a/aries/libaudio/AudioHardware.h b/aries/libaudio/AudioHardware.h
index 1379495..a23e6c9 100644
--- a/aries/libaudio/AudioHardware.h
+++ b/aries/libaudio/AudioHardware.h
@@ -24,6 +24,7 @@
#include <utils/SortedVector.h>
#include <hardware_legacy/AudioHardwareBase.h>
+#include <media/mediarecorder.h>
#include "secril-client.h"
@@ -66,7 +67,6 @@ namespace android {
// Default audio input buffer size in bytes (8kHz mono)
#define AUDIO_HW_IN_PERIOD_BYTES ((AUDIO_HW_IN_PERIOD_SZ*sizeof(int16_t))/8)
-#define INPUT_SOURCE_KEY "Input Source"
class AudioHardware : public AudioHardwareBase
{
@@ -74,6 +74,12 @@ class AudioHardware : public AudioHardwareBase
class AudioStreamInALSA;
public:
+ // input path names used to translate from input sources to driver paths
+ static const char *inputPathNameDefault;
+ static const char *inputPathNameCamcorder;
+ static const char *inputPathNameVoiceRecognition;
+ static const char *inputPathNameVoiceCommunication;
+
AudioHardware();
virtual ~AudioHardware();
virtual status_t initCheck();
@@ -111,7 +117,7 @@ public:
status_t setIncallPath_l(uint32_t device);
- status_t setInputSource_l(String8 source);
+ status_t setInputSource_l(audio_source source);
static uint32_t getInputSampleRate(uint32_t sampleRate);
sp <AudioStreamInALSA> getActiveInput_l();
@@ -131,6 +137,13 @@ protected:
private:
+ enum tty_modes {
+ TTY_MODE_OFF,
+ TTY_MODE_VCO,
+ TTY_MODE_HCO,
+ TTY_MODE_FULL
+ };
+
bool mInit;
bool mMicMute;
sp <AudioStreamOutALSA> mOutput;
@@ -142,8 +155,10 @@ private:
uint32_t mMixerOpenCnt;
bool mInCallAudioMode;
- String8 mInputSource;
+ audio_source mInputSource;
bool mBluetoothNrec;
+ int mTTYMode;
+
void* mSecRilLibHandle;
HRilClient mRilClient;
bool mActivatedCP;
@@ -203,8 +218,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:
@@ -222,6 +238,7 @@ private:
// trace driver operations for dump
int mDriverOp;
int mStandbyCnt;
+ bool mSleepReq;
};
class DownSampler;
@@ -316,8 +333,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;
@@ -339,6 +357,7 @@ private:
// trace driver operations for dump
int mDriverOp;
int mStandbyCnt;
+ bool mSleepReq;
};
};
diff --git a/aries/libaudio/AudioPolicyManager.cpp b/aries/libaudio/AudioPolicyManager.cpp
index 93d70d8..c53d1e9 100644
--- a/aries/libaudio/AudioPolicyManager.cpp
+++ b/aries/libaudio/AudioPolicyManager.cpp
@@ -43,32 +43,4 @@ extern "C" void destroyAudioPolicyManager(AudioPolicyInterface *interface)
}
-status_t AudioPolicyManager::startInput(audio_io_handle_t input)
-{
- status_t status = AudioPolicyManagerBase::startInput(input);
-
- if (status == NO_ERROR) {
- AudioInputDescriptor *inputDesc = mInputs.valueFor(input);
- String8 key = String8("Input Source");
- String8 value;
- switch(inputDesc->mInputSource) {
- case AUDIO_SOURCE_VOICE_RECOGNITION:
- value = String8("Voice Recognition");
- break;
- case AUDIO_SOURCE_CAMCORDER:
- value = String8("Camcorder");
- break;
- case AUDIO_SOURCE_DEFAULT:
- case AUDIO_SOURCE_MIC:
- value = String8("Default");
- default:
- break;
- }
- AudioParameter param = AudioParameter();
- param.add(key, value);
- mpClientInterface->setParameters(input, param.toString());
- }
- return status;
-}
-
}; // namespace android
diff --git a/aries/libaudio/AudioPolicyManager.h b/aries/libaudio/AudioPolicyManager.h
index ae283db..03141e5 100644
--- a/aries/libaudio/AudioPolicyManager.h
+++ b/aries/libaudio/AudioPolicyManager.h
@@ -34,7 +34,6 @@ public:
virtual ~AudioPolicyManager() {}
- virtual status_t startInput(audio_io_handle_t input);
protected:
// true is current platform implements a back microphone
virtual bool hasBackMicrophone() const { return false; }