summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
Diffstat (limited to 'audio')
-rw-r--r--audio/A2dpAudioInterface.cpp36
-rw-r--r--audio/Android.mk16
-rw-r--r--audio/AudioDumpInterface.cpp42
-rw-r--r--audio/AudioHardwareGeneric.cpp14
-rw-r--r--audio/AudioHardwareInterface.cpp11
-rw-r--r--audio/AudioPolicyCompatClient.cpp6
-rw-r--r--audio/AudioPolicyCompatClient.h2
-rw-r--r--audio/AudioPolicyManagerBase.cpp1178
-rw-r--r--audio/AudioPolicyManagerDefault.h4
-rw-r--r--audio/audio_hw_hal.cpp39
-rw-r--r--audio/audio_policy_hal.cpp56
11 files changed, 783 insertions, 621 deletions
diff --git a/audio/A2dpAudioInterface.cpp b/audio/A2dpAudioInterface.cpp
index 2d78858..cc435bd 100644
--- a/audio/A2dpAudioInterface.cpp
+++ b/audio/A2dpAudioInterface.cpp
@@ -38,7 +38,7 @@ static const char *sA2dpWakeLock = "A2dpOutputStream";
// AudioHardwareInterface* hw = 0;
//
// hw = AudioHardwareInterface::create();
-// LOGD("new A2dpAudioInterface(hw: %p)", hw);
+// ALOGD("new A2dpAudioInterface(hw: %p)", hw);
// hw = new A2dpAudioInterface(hw);
// return hw;
//}
@@ -64,7 +64,7 @@ AudioStreamOut* A2dpAudioInterface::openOutputStream(
uint32_t devices, int *format, uint32_t *channels, uint32_t *sampleRate, status_t *status)
{
if (!AudioSystem::isA2dpDevice((AudioSystem::audio_devices)devices)) {
- LOGV("A2dpAudioInterface::openOutputStream() open HW device: %x", devices);
+ ALOGV("A2dpAudioInterface::openOutputStream() open HW device: %x", devices);
return mHardwareInterface->openOutputStream(devices, format, channels, sampleRate, status);
}
@@ -137,7 +137,7 @@ status_t A2dpAudioInterface::setParameters(const String8& keyValuePairs)
String8 key;
status_t status = NO_ERROR;
- LOGV("setParameters() %s", keyValuePairs.string());
+ ALOGV("setParameters() %s", keyValuePairs.string());
key = "bluetooth_enabled";
if (param.get(key, value) == NO_ERROR) {
@@ -195,7 +195,7 @@ String8 A2dpAudioInterface::getParameters(const String8& keys)
keyValuePairs += mHardwareInterface->getParameters(param.toString());
}
- LOGV("getParameters() %s", keyValuePairs.string());
+ ALOGV("getParameters() %s", keyValuePairs.string());
return keyValuePairs;
}
@@ -239,7 +239,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::set(
uint32_t lChannels = pChannels ? *pChannels : 0;
uint32_t lRate = pRate ? *pRate : 0;
- LOGD("A2dpAudioStreamOut::set %x, %d, %d, %d\n", device, lFormat, lChannels, lRate);
+ ALOGD("A2dpAudioStreamOut::set %x, %d, %d, %d\n", device, lFormat, lChannels, lRate);
// fix up defaults
if (lFormat == 0) lFormat = format();
@@ -267,9 +267,9 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::set(
A2dpAudioInterface::A2dpAudioStreamOut::~A2dpAudioStreamOut()
{
- LOGV("A2dpAudioStreamOut destructor");
+ ALOGV("A2dpAudioStreamOut destructor");
close();
- LOGV("A2dpAudioStreamOut destructor returning from close()");
+ ALOGV("A2dpAudioStreamOut destructor returning from close()");
}
ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t bytes)
@@ -281,7 +281,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t
size_t remaining = bytes;
if (!mBluetoothEnabled || mClosing || mSuspended) {
- LOGV("A2dpAudioStreamOut::write(), but bluetooth disabled \
+ ALOGV("A2dpAudioStreamOut::write(), but bluetooth disabled \
mBluetoothEnabled %d, mClosing %d, mSuspended %d",
mBluetoothEnabled, mClosing, mSuspended);
goto Error;
@@ -301,7 +301,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t
while (remaining > 0 && retries) {
status = a2dp_write(mData, buffer, remaining);
if (status < 0) {
- LOGE("a2dp_write failed err: %d\n", status);
+ ALOGE("a2dp_write failed err: %d\n", status);
goto Error;
}
if (status == 0) {
@@ -316,7 +316,7 @@ ssize_t A2dpAudioInterface::A2dpAudioStreamOut::write(const void* buffer, size_t
// NOTE: It is likely that the A2DP headset is being disconnected
nsecs_t now = systemTime();
if ((uint32_t)ns2us(now - mLastWriteTime) < (mBufferDurationUs >> 2)) {
- LOGV("A2DP sink runs too fast");
+ ALOGV("A2DP sink runs too fast");
usleep(mBufferDurationUs - (uint32_t)ns2us(now - mLastWriteTime));
}
mLastWriteTime = now;
@@ -338,7 +338,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::init()
if (!mData) {
status_t status = a2dp_init(44100, 2, &mData);
if (status < 0) {
- LOGE("a2dp_init failed err: %d\n", status);
+ ALOGE("a2dp_init failed err: %d\n", status);
mData = NULL;
return status;
}
@@ -359,7 +359,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::standby_l()
int result = NO_ERROR;
if (!mStandby) {
- LOGV_IF(mClosing || !mBluetoothEnabled, "Standby skip stop: closing %d enabled %d",
+ ALOGV_IF(mClosing || !mBluetoothEnabled, "Standby skip stop: closing %d enabled %d",
mClosing, mBluetoothEnabled);
if (!mClosing && mBluetoothEnabled) {
result = a2dp_stop(mData);
@@ -378,7 +378,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setParameters(const String8& ke
String8 key = String8("a2dp_sink_address");
status_t status = NO_ERROR;
int device;
- LOGV("A2dpAudioStreamOut::setParameters() %s", keyValuePairs.string());
+ ALOGV("A2dpAudioStreamOut::setParameters() %s", keyValuePairs.string());
if (param.get(key, value) == NO_ERROR) {
if (value.length() != strlen("00:00:00:00:00:00")) {
@@ -428,7 +428,7 @@ String8 A2dpAudioInterface::A2dpAudioStreamOut::getParameters(const String8& key
param.addInt(key, (int)mDevice);
}
- LOGV("A2dpAudioStreamOut::getParameters() %s", param.toString().string());
+ ALOGV("A2dpAudioStreamOut::getParameters() %s", param.toString().string());
return param.toString();
}
@@ -448,7 +448,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setAddress(const char* address)
status_t A2dpAudioInterface::A2dpAudioStreamOut::setBluetoothEnabled(bool enabled)
{
- LOGD("setBluetoothEnabled %d", enabled);
+ ALOGD("setBluetoothEnabled %d", enabled);
Mutex::Autolock lock(mLock);
@@ -461,7 +461,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setBluetoothEnabled(bool enable
status_t A2dpAudioInterface::A2dpAudioStreamOut::setSuspended(bool onOff)
{
- LOGV("setSuspended %d", onOff);
+ ALOGV("setSuspended %d", onOff);
mSuspended = onOff;
standby();
return NO_ERROR;
@@ -470,7 +470,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::setSuspended(bool onOff)
status_t A2dpAudioInterface::A2dpAudioStreamOut::close()
{
Mutex::Autolock lock(mLock);
- LOGV("A2dpAudioStreamOut::close() calling close_l()");
+ ALOGV("A2dpAudioStreamOut::close() calling close_l()");
return close_l();
}
@@ -478,7 +478,7 @@ status_t A2dpAudioInterface::A2dpAudioStreamOut::close_l()
{
standby_l();
if (mData) {
- LOGV("A2dpAudioStreamOut::close_l() calling a2dp_cleanup(mData)");
+ ALOGV("A2dpAudioStreamOut::close_l() calling a2dp_cleanup(mData)");
a2dp_cleanup(mData);
mData = NULL;
}
diff --git a/audio/Android.mk b/audio/Android.mk
index ef41374..a69b9cd 100644
--- a/audio/Android.mk
+++ b/audio/Android.mk
@@ -10,10 +10,6 @@ LOCAL_SRC_FILES := \
AudioHardwareInterface.cpp \
audio_hw_hal.cpp
-ifeq ($(BOARD_HAVE_BLUETOOTH),true)
- LOCAL_CFLAGS += -DWITH_A2DP
-endif
-
LOCAL_MODULE := libaudiohw_legacy
LOCAL_MODULE_TAGS := optional
LOCAL_STATIC_LIBRARIES := libmedia_helper
@@ -31,10 +27,6 @@ ifeq ($(AUDIO_POLICY_TEST),true)
LOCAL_CFLAGS += -DAUDIO_POLICY_TEST
endif
-ifeq ($(BOARD_HAVE_BLUETOOTH),true)
- LOCAL_CFLAGS += -DWITH_A2DP
-endif
-
LOCAL_STATIC_LIBRARIES := libmedia_helper
LOCAL_MODULE := libaudiopolicy_legacy
LOCAL_MODULE_TAGS := optional
@@ -50,8 +42,7 @@ LOCAL_SRC_FILES := \
LOCAL_SHARED_LIBRARIES := \
libcutils \
- libutils \
- libmedia
+ libutils
LOCAL_STATIC_LIBRARIES := \
libmedia_helper
@@ -63,10 +54,6 @@ LOCAL_MODULE := audio_policy.default
LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
LOCAL_MODULE_TAGS := optional
-ifeq ($(BOARD_HAVE_BLUETOOTH),true)
- LOCAL_CFLAGS += -DWITH_A2DP
-endif
-
include $(BUILD_SHARED_LIBRARY)
#ifeq ($(ENABLE_AUDIO_DUMP),true)
@@ -85,7 +72,6 @@ include $(BUILD_SHARED_LIBRARY)
#
# LOCAL_CFLAGS += \
# -DWITH_BLUETOOTH \
-# -DWITH_A2DP
#endif
#
#include $(BUILD_SHARED_LIBRARY)
diff --git a/audio/AudioDumpInterface.cpp b/audio/AudioDumpInterface.cpp
index 6c11114..62fdbd6 100644
--- a/audio/AudioDumpInterface.cpp
+++ b/audio/AudioDumpInterface.cpp
@@ -35,10 +35,10 @@ AudioDumpInterface::AudioDumpInterface(AudioHardwareInterface* hw)
: mPolicyCommands(String8("")), mFileName(String8(""))
{
if(hw == 0) {
- LOGE("Dump construct hw = 0");
+ ALOGE("Dump construct hw = 0");
}
mFinalInterface = hw;
- LOGV("Constructor %p, mFinalInterface %p", this, mFinalInterface);
+ ALOGV("Constructor %p, mFinalInterface %p", this, mFinalInterface);
}
@@ -94,7 +94,7 @@ AudioStreamOut* AudioDumpInterface::openOutputStream(
}
if (status) *status = NO_ERROR;
}
- LOGV("openOutputStream(), outFinal %p", outFinal);
+ ALOGV("openOutputStream(), outFinal %p", outFinal);
AudioStreamOutDump *dumOutput = new AudioStreamOutDump(this, mOutputs.size(), outFinal,
devices, lFormat, lChannels, lRate);
@@ -108,11 +108,11 @@ void AudioDumpInterface::closeOutputStream(AudioStreamOut* out)
AudioStreamOutDump *dumpOut = (AudioStreamOutDump *)out;
if (mOutputs.indexOf(dumpOut) < 0) {
- LOGW("Attempt to close invalid output stream");
+ ALOGW("Attempt to close invalid output stream");
return;
}
- LOGV("closeOutputStream() output %p", out);
+ ALOGV("closeOutputStream() output %p", out);
dumpOut->standby();
if (dumpOut->finalStream() != NULL) {
@@ -160,7 +160,7 @@ AudioStreamIn* AudioDumpInterface::openInputStream(uint32_t devices, int *format
}
if (status) *status = NO_ERROR;
}
- LOGV("openInputStream(), inFinal %p", inFinal);
+ ALOGV("openInputStream(), inFinal %p", inFinal);
AudioStreamInDump *dumInput = new AudioStreamInDump(this, mInputs.size(), inFinal,
devices, lFormat, lChannels, lRate);
@@ -173,7 +173,7 @@ void AudioDumpInterface::closeInputStream(AudioStreamIn* in)
AudioStreamInDump *dumpIn = (AudioStreamInDump *)in;
if (mInputs.indexOf(dumpIn) < 0) {
- LOGW("Attempt to close invalid input stream");
+ ALOGW("Attempt to close invalid input stream");
return;
}
dumpIn->standby();
@@ -191,7 +191,7 @@ status_t AudioDumpInterface::setParameters(const String8& keyValuePairs)
AudioParameter param = AudioParameter(keyValuePairs);
String8 value;
int valueInt;
- LOGV("setParameters %s", keyValuePairs.string());
+ ALOGV("setParameters %s", keyValuePairs.string());
if (param.get(String8("test_cmd_file_name"), value) == NO_ERROR) {
mFileName = value;
@@ -201,7 +201,7 @@ status_t AudioDumpInterface::setParameters(const String8& keyValuePairs)
Mutex::Autolock _l(mLock);
param.remove(String8("test_cmd_policy"));
mPolicyCommands = param.toString();
- LOGV("test_cmd_policy command %s written", mPolicyCommands.string());
+ ALOGV("test_cmd_policy command %s written", mPolicyCommands.string());
return NO_ERROR;
}
@@ -215,7 +215,7 @@ String8 AudioDumpInterface::getParameters(const String8& keys)
AudioParameter response;
String8 value;
-// LOGV("getParameters %s", keys.string());
+// ALOGV("getParameters %s", keys.string());
if (param.get(String8("test_cmd_policy"), value) == NO_ERROR) {
Mutex::Autolock _l(mLock);
if (mPolicyCommands.length() != 0) {
@@ -225,7 +225,7 @@ String8 AudioDumpInterface::getParameters(const String8& keys)
response.addInt(String8("test_cmd_policy"), 0);
}
param.remove(String8("test_cmd_policy"));
-// LOGV("test_cmd_policy command %s read", mPolicyCommands.string());
+// ALOGV("test_cmd_policy command %s read", mPolicyCommands.string());
}
if (param.get(String8("test_cmd_file_name"), value) == NO_ERROR) {
@@ -266,13 +266,13 @@ AudioStreamOutDump::AudioStreamOutDump(AudioDumpInterface *interface,
mSampleRate(sampleRate), mFormat(format), mChannels(channels), mLatency(0), mDevice(devices),
mBufferSize(1024), mFinalStream(finalStream), mFile(0), mFileCount(0)
{
- LOGV("AudioStreamOutDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
+ ALOGV("AudioStreamOutDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
}
AudioStreamOutDump::~AudioStreamOutDump()
{
- LOGV("AudioStreamOutDump destructor");
+ ALOGV("AudioStreamOutDump destructor");
Close();
}
@@ -291,7 +291,7 @@ ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes)
char name[255];
sprintf(name, "%s_out_%d_%d.pcm", mInterface->fileName().string(), mId, ++mFileCount);
mFile = fopen(name, "wb");
- LOGV("Opening dump file %s, fh %p", name, mFile);
+ ALOGV("Opening dump file %s, fh %p", name, mFile);
}
}
if (mFile) {
@@ -302,7 +302,7 @@ ssize_t AudioStreamOutDump::write(const void* buffer, size_t bytes)
status_t AudioStreamOutDump::standby()
{
- LOGV("AudioStreamOutDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
+ ALOGV("AudioStreamOutDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
Close();
if (mFinalStream != 0 ) return mFinalStream->standby();
@@ -343,7 +343,7 @@ status_t AudioStreamOutDump::setVolume(float left, float right)
}
status_t AudioStreamOutDump::setParameters(const String8& keyValuePairs)
{
- LOGV("AudioStreamOutDump::setParameters %s", keyValuePairs.string());
+ ALOGV("AudioStreamOutDump::setParameters %s", keyValuePairs.string());
if (mFinalStream != 0 ) {
return mFinalStream->setParameters(keyValuePairs);
@@ -427,7 +427,7 @@ AudioStreamInDump::AudioStreamInDump(AudioDumpInterface *interface,
mSampleRate(sampleRate), mFormat(format), mChannels(channels), mDevice(devices),
mBufferSize(1024), mFinalStream(finalStream), mFile(0), mFileCount(0)
{
- LOGV("AudioStreamInDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
+ ALOGV("AudioStreamInDump Constructor %p, mInterface %p, mFinalStream %p", this, mInterface, mFinalStream);
}
@@ -447,7 +447,7 @@ ssize_t AudioStreamInDump::read(void* buffer, ssize_t bytes)
char name[255];
sprintf(name, "%s_in_%d_%d.pcm", mInterface->fileName().string(), mId, ++mFileCount);
mFile = fopen(name, "wb");
- LOGV("Opening input dump file %s, fh %p", name, mFile);
+ ALOGV("Opening input dump file %s, fh %p", name, mFile);
}
}
if (mFile) {
@@ -480,7 +480,7 @@ ssize_t AudioStreamInDump::read(void* buffer, ssize_t bytes)
}
strcat(name, ".wav");
mFile = fopen(name, "rb");
- LOGV("Opening input read file %s, fh %p", name, mFile);
+ ALOGV("Opening input read file %s, fh %p", name, mFile);
if (mFile) {
fseek(mFile, AUDIO_DUMP_WAVE_HDR_SIZE, SEEK_SET);
}
@@ -499,7 +499,7 @@ ssize_t AudioStreamInDump::read(void* buffer, ssize_t bytes)
status_t AudioStreamInDump::standby()
{
- LOGV("AudioStreamInDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
+ ALOGV("AudioStreamInDump standby(), mFile %p, mFinalStream %p", mFile, mFinalStream);
Close();
if (mFinalStream != 0 ) return mFinalStream->standby();
@@ -538,7 +538,7 @@ int AudioStreamInDump::format() const
status_t AudioStreamInDump::setParameters(const String8& keyValuePairs)
{
- LOGV("AudioStreamInDump::setParameters()");
+ ALOGV("AudioStreamInDump::setParameters()");
if (mFinalStream != 0 ) return mFinalStream->setParameters(keyValuePairs);
return NO_ERROR;
}
diff --git a/audio/AudioHardwareGeneric.cpp b/audio/AudioHardwareGeneric.cpp
index 61286e4..a2b00f8 100644
--- a/audio/AudioHardwareGeneric.cpp
+++ b/audio/AudioHardwareGeneric.cpp
@@ -273,7 +273,7 @@ status_t AudioStreamOutGeneric::setParameters(const String8& keyValuePairs)
String8 key = String8(AudioParameter::keyRouting);
status_t status = NO_ERROR;
int device;
- LOGV("setParameters() %s", keyValuePairs.string());
+ ALOGV("setParameters() %s", keyValuePairs.string());
if (param.getInt(key, device) == NO_ERROR) {
mDevice = device;
@@ -296,7 +296,7 @@ String8 AudioStreamOutGeneric::getParameters(const String8& keys)
param.addInt(key, (int)mDevice);
}
- LOGV("getParameters() %s", param.toString().string());
+ ALOGV("getParameters() %s", param.toString().string());
return param.toString();
}
@@ -318,12 +318,12 @@ status_t AudioStreamInGeneric::set(
AudioSystem::audio_in_acoustics acoustics)
{
if (pFormat == 0 || pChannels == 0 || pRate == 0) return BAD_VALUE;
- LOGV("AudioStreamInGeneric::set(%p, %d, %d, %d, %u)", hw, fd, *pFormat, *pChannels, *pRate);
+ ALOGV("AudioStreamInGeneric::set(%p, %d, %d, %d, %u)", hw, fd, *pFormat, *pChannels, *pRate);
// check values
if ((*pFormat != format()) ||
(*pChannels != channels()) ||
(*pRate != sampleRate())) {
- LOGE("Error opening input channel");
+ ALOGE("Error opening input channel");
*pFormat = format();
*pChannels = channels();
*pRate = sampleRate();
@@ -344,7 +344,7 @@ ssize_t AudioStreamInGeneric::read(void* buffer, ssize_t bytes)
{
AutoMutex lock(mLock);
if (mFd < 0) {
- LOGE("Attempt to read from unopened device");
+ ALOGE("Attempt to read from unopened device");
return NO_INIT;
}
return ::read(mFd, buffer, bytes);
@@ -381,7 +381,7 @@ status_t AudioStreamInGeneric::setParameters(const String8& keyValuePairs)
String8 key = String8(AudioParameter::keyRouting);
status_t status = NO_ERROR;
int device;
- LOGV("setParameters() %s", keyValuePairs.string());
+ ALOGV("setParameters() %s", keyValuePairs.string());
if (param.getInt(key, device) == NO_ERROR) {
mDevice = device;
@@ -404,7 +404,7 @@ String8 AudioStreamInGeneric::getParameters(const String8& keys)
param.addInt(key, (int)mDevice);
}
- LOGV("getParameters() %s", param.toString().string());
+ ALOGV("getParameters() %s", param.toString().string());
return param.toString();
}
diff --git a/audio/AudioHardwareInterface.cpp b/audio/AudioHardwareInterface.cpp
index 4997a6a..53c64b5 100644
--- a/audio/AudioHardwareInterface.cpp
+++ b/audio/AudioHardwareInterface.cpp
@@ -26,9 +26,6 @@
#include "AudioHardwareStub.h"
#include "AudioHardwareGeneric.h"
-#ifdef WITH_A2DP
-#include "A2dpAudioInterface.h"
-#endif
#ifdef ENABLE_AUDIO_DUMP
#include "AudioDumpInterface.h"
@@ -83,7 +80,7 @@ AudioHardwareBase::AudioHardwareBase()
status_t AudioHardwareBase::setMode(int mode)
{
#if LOG_ROUTING_CALLS
- LOGD("setMode(%s)", displayMode(mode));
+ ALOGD("setMode(%s)", displayMode(mode));
#endif
if ((mode < 0) || (mode >= AudioSystem::NUM_MODES))
return BAD_VALUE;
@@ -110,15 +107,15 @@ String8 AudioHardwareBase::getParameters(const String8& keys)
size_t AudioHardwareBase::getInputBufferSize(uint32_t sampleRate, int format, int channelCount)
{
if (sampleRate != 8000) {
- LOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
+ ALOGW("getInputBufferSize bad sampling rate: %d", sampleRate);
return 0;
}
if (format != AudioSystem::PCM_16_BIT) {
- LOGW("getInputBufferSize bad format: %d", format);
+ ALOGW("getInputBufferSize bad format: %d", format);
return 0;
}
if (channelCount != 1) {
- LOGW("getInputBufferSize bad channel count: %d", channelCount);
+ ALOGW("getInputBufferSize bad channel count: %d", channelCount);
return 0;
}
diff --git a/audio/AudioPolicyCompatClient.cpp b/audio/AudioPolicyCompatClient.cpp
index 08c31c5..5231b41 100644
--- a/audio/AudioPolicyCompatClient.cpp
+++ b/audio/AudioPolicyCompatClient.cpp
@@ -37,7 +37,7 @@ audio_io_handle_t AudioPolicyCompatClient::openOutput(uint32_t *pDevices,
uint32_t *pLatencyMs,
AudioSystem::output_flags flags)
{
- return mServiceOps->open_output(mService, pDevices, pSamplingRate, pFormat,
+ return mServiceOps->open_output(mService, pDevices, pSamplingRate, (audio_format_t *) pFormat,
pChannels, pLatencyMs,
(audio_policy_output_flags_t)flags);
}
@@ -67,9 +67,9 @@ audio_io_handle_t AudioPolicyCompatClient::openInput(uint32_t *pDevices,
uint32_t *pSamplingRate,
uint32_t *pFormat,
uint32_t *pChannels,
- uint32_t acoustics)
+ audio_in_acoustics_t acoustics)
{
- return mServiceOps->open_input(mService, pDevices, pSamplingRate, pFormat,
+ return mServiceOps->open_input(mService, pDevices, pSamplingRate, (audio_format_t *) pFormat,
pChannels, acoustics);
}
diff --git a/audio/AudioPolicyCompatClient.h b/audio/AudioPolicyCompatClient.h
index 4feee37..99dd639 100644
--- a/audio/AudioPolicyCompatClient.h
+++ b/audio/AudioPolicyCompatClient.h
@@ -50,7 +50,7 @@ public:
uint32_t *pSamplingRate,
uint32_t *pFormat,
uint32_t *pChannels,
- uint32_t acoustics);
+ audio_in_acoustics_t acoustics);
virtual status_t closeInput(audio_io_handle_t input);
virtual status_t setStreamOutput(AudioSystem::stream_type stream, audio_io_handle_t output);
virtual status_t moveEffects(int session,
diff --git a/audio/AudioPolicyManagerBase.cpp b/audio/AudioPolicyManagerBase.cpp
index e299db8..0e6a1cb 100644
--- a/audio/AudioPolicyManagerBase.cpp
+++ b/audio/AudioPolicyManagerBase.cpp
@@ -19,6 +19,7 @@
#include <utils/Log.h>
#include <hardware_legacy/AudioPolicyManagerBase.h>
#include <hardware/audio_effect.h>
+#include <hardware/audio.h>
#include <math.h>
namespace android_audio_legacy {
@@ -27,109 +28,152 @@ namespace android_audio_legacy {
// AudioPolicyInterface implementation
// ----------------------------------------------------------------------------
+////////////////////
+// TODO: the following static configuration will be read from a configuration file
+
+
+// sHasA2dp is true on platforms with support for bluetooth A2DP
+bool sHasA2dp = true;
+
+// devices that are always available on the platform
+audio_devices_t sAttachedOutputDevices =
+ (audio_devices_t)(AUDIO_DEVICE_OUT_EARPIECE | AUDIO_DEVICE_OUT_SPEAKER);
+
+// device selected by default at boot time must be in sAttachedOutputDevices
+audio_devices_t sDefaultOutputDevice = AUDIO_DEVICE_OUT_SPEAKER;
+
+uint32_t sSamplingRates[] = {44100, 0};
+audio_channel_mask_t sChannels[] = {AUDIO_CHANNEL_OUT_STEREO, (audio_channel_mask_t)0};
+audio_format_t sFormats[] = {AUDIO_FORMAT_PCM_16_BIT, (audio_format_t)0};
+
+// the primary output (identified by AUDIO_POLICY_OUTPUT_FLAG_PRIMARY in its profile) must exist and
+// is unique on a platform. It is the output receiving the routing and volume commands for telephony
+// use cases. It is normally exposed by the primary audio hw module and opened at boot time by
+// the audio policy manager.
+const output_profile_t sPrimaryOutput = {
+ sSamplingRates,
+ sChannels,
+ sFormats,
+ (audio_devices_t)(AUDIO_DEVICE_OUT_EARPIECE |
+ AUDIO_DEVICE_OUT_SPEAKER |
+ AUDIO_DEVICE_OUT_WIRED_HEADSET |
+ AUDIO_DEVICE_OUT_WIRED_HEADPHONE |
+ AUDIO_DEVICE_OUT_ALL_SCO |
+ AUDIO_DEVICE_OUT_AUX_DIGITAL |
+ AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET),
+ AUDIO_POLICY_OUTPUT_FLAG_PRIMARY
+};
+
+const output_profile_t sA2dpOutput = {
+ sSamplingRates,
+ sChannels,
+ sFormats,
+ AUDIO_DEVICE_OUT_ALL_A2DP,
+ (audio_policy_output_flags_t)0
+};
+
+const output_profile_t *sAvailableOutputs[] = {
+ &sPrimaryOutput,
+ &sA2dpOutput,
+ NULL
+};
+
+///////////// end of temporary static configuration data
+
status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_devices device,
AudioSystem::device_connection_state state,
const char *device_address)
{
+ audio_io_handle_t output = 0;
- LOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
+ ALOGV("setDeviceConnectionState() device: %x, state %d, address %s", device, state, device_address);
// connect/disconnect only 1 device at a time
if (AudioSystem::popCount(device) != 1) return BAD_VALUE;
if (strlen(device_address) >= MAX_DEVICE_ADDRESS_LEN) {
- LOGE("setDeviceConnectionState() invalid address: %s", device_address);
+ ALOGE("setDeviceConnectionState() invalid address: %s", device_address);
return BAD_VALUE;
}
// handle output devices
if (AudioSystem::isOutputDevice(device)) {
-#ifndef WITH_A2DP
- if (AudioSystem::isA2dpDevice(device)) {
- LOGE("setDeviceConnectionState() invalid device: %x", device);
+ if (!sHasA2dp && AudioSystem::isA2dpDevice(device)) {
+ ALOGE("setDeviceConnectionState() invalid device: %x", device);
return BAD_VALUE;
}
-#endif
switch (state)
{
// handle output device connection
case AudioSystem::DEVICE_STATE_AVAILABLE:
if (mAvailableOutputDevices & device) {
- LOGW("setDeviceConnectionState() device already connected: %x", device);
+ ALOGW("setDeviceConnectionState() device already connected: %x", device);
return INVALID_OPERATION;
}
- LOGV("setDeviceConnectionState() connecting device %x", device);
+ ALOGV("setDeviceConnectionState() connecting device %x", device);
// register new device as available
- mAvailableOutputDevices |= device;
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | device);
-#ifdef WITH_A2DP
+ output = checkOutputForDevice((audio_devices_t)device, state);
+ if (output == 0) {
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device);
+ return INVALID_OPERATION;
+ }
// handle A2DP device connection
- if (AudioSystem::isA2dpDevice(device)) {
- status_t status = handleA2dpConnection(device, device_address);
- if (status != NO_ERROR) {
- mAvailableOutputDevices &= ~device;
- return status;
- }
- } else
-#endif
- {
- if (AudioSystem::isBluetoothScoDevice(device)) {
- LOGV("setDeviceConnectionState() BT SCO device, address %s", device_address);
- // keep track of SCO device address
- mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
- }
+ if (sHasA2dp && AudioSystem::isA2dpDevice(device)) {
+ AudioParameter param;
+ param.add(String8(AUDIO_PARAMETER_A2DP_SINK_ADDRESS), String8(device_address));
+ mpClientInterface->setParameters(output, param.toString());
+ mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
+ mA2dpSuspended = false;
+ } else if (AudioSystem::isBluetoothScoDevice(device)) {
+ ALOGV("setDeviceConnectionState() BT SCO device, address %s", device_address);
+ // keep track of SCO device address
+ mScoDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
}
break;
// handle output device disconnection
case AudioSystem::DEVICE_STATE_UNAVAILABLE: {
if (!(mAvailableOutputDevices & device)) {
- LOGW("setDeviceConnectionState() device not connected: %x", device);
+ ALOGW("setDeviceConnectionState() device not connected: %x", device);
return INVALID_OPERATION;
}
- LOGV("setDeviceConnectionState() disconnecting device %x", device);
+ ALOGV("setDeviceConnectionState() disconnecting device %x", device);
// remove device from available output devices
- mAvailableOutputDevices &= ~device;
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices & ~device);
-#ifdef WITH_A2DP
+ output = checkOutputForDevice((audio_devices_t)device, state);
// handle A2DP device disconnection
- if (AudioSystem::isA2dpDevice(device)) {
- status_t status = handleA2dpDisconnection(device, device_address);
- if (status != NO_ERROR) {
- mAvailableOutputDevices |= device;
- return status;
- }
- } else
-#endif
- {
- if (AudioSystem::isBluetoothScoDevice(device)) {
- mScoDeviceAddress = "";
- }
+ if (sHasA2dp && AudioSystem::isA2dpDevice(device)) {
+ mA2dpDeviceAddress = "";
+ mA2dpSuspended = false;
+ } else if (AudioSystem::isBluetoothScoDevice(device)) {
+ mScoDeviceAddress = "";
}
} break;
default:
- LOGE("setDeviceConnectionState() invalid state: %x", state);
+ ALOGE("setDeviceConnectionState() invalid state: %x", state);
return BAD_VALUE;
}
// request routing change if necessary
- uint32_t newDevice = getNewDevice(mHardwareOutput, false);
-#ifdef WITH_A2DP
+ audio_devices_t newDevice = getNewDevice(mPrimaryOutput, false);
+
checkA2dpSuspend();
checkOutputForAllStrategies();
- // A2DP outputs must be closed after checkOutputForAllStrategies() is executed
- if (state == AudioSystem::DEVICE_STATE_UNAVAILABLE && AudioSystem::isA2dpDevice(device)) {
- closeA2dpOutputs();
+ // outputs must be closed after checkOutputForAllStrategies() is executed
+ if (state == AudioSystem::DEVICE_STATE_UNAVAILABLE && output != 0) {
+ closeOutput(output);
}
-#endif
updateDeviceForStrategy();
- setOutputDevice(mHardwareOutput, newDevice);
+ setOutputDevice(mPrimaryOutput, newDevice);
if (device == AudioSystem::DEVICE_OUT_WIRED_HEADSET) {
device = AudioSystem::DEVICE_IN_WIRED_HEADSET;
@@ -149,7 +193,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev
// handle input device connection
case AudioSystem::DEVICE_STATE_AVAILABLE: {
if (mAvailableInputDevices & device) {
- LOGW("setDeviceConnectionState() device already connected: %d", device);
+ ALOGW("setDeviceConnectionState() device already connected: %d", device);
return INVALID_OPERATION;
}
mAvailableInputDevices |= device;
@@ -159,23 +203,23 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev
// handle input device disconnection
case AudioSystem::DEVICE_STATE_UNAVAILABLE: {
if (!(mAvailableInputDevices & device)) {
- LOGW("setDeviceConnectionState() device not connected: %d", device);
+ ALOGW("setDeviceConnectionState() device not connected: %d", device);
return INVALID_OPERATION;
}
mAvailableInputDevices &= ~device;
} break;
default:
- LOGE("setDeviceConnectionState() invalid state: %x", state);
+ ALOGE("setDeviceConnectionState() invalid state: %x", state);
return BAD_VALUE;
}
audio_io_handle_t activeInput = getActiveInput();
if (activeInput != 0) {
AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput);
- uint32_t newDevice = getDeviceForInputSource(inputDesc->mInputSource);
+ audio_devices_t newDevice = getDeviceForInputSource(inputDesc->mInputSource);
if (newDevice != inputDesc->mDevice) {
- LOGV("setDeviceConnectionState() changing device from %x to %x for input %d",
+ ALOGV("setDeviceConnectionState() changing device from %x to %x for input %d",
inputDesc->mDevice, newDevice, activeInput);
inputDesc->mDevice = newDevice;
AudioParameter param = AudioParameter();
@@ -187,7 +231,7 @@ status_t AudioPolicyManagerBase::setDeviceConnectionState(AudioSystem::audio_dev
return NO_ERROR;
}
- LOGW("setDeviceConnectionState() invalid device: %x", device);
+ ALOGW("setDeviceConnectionState() invalid device: %x", device);
return BAD_VALUE;
}
@@ -198,12 +242,10 @@ AudioSystem::device_connection_state AudioPolicyManagerBase::getDeviceConnection
String8 address = String8(device_address);
if (AudioSystem::isOutputDevice(device)) {
if (device & mAvailableOutputDevices) {
-#ifdef WITH_A2DP
if (AudioSystem::isA2dpDevice(device) &&
- address != "" && mA2dpDeviceAddress != address) {
+ (!sHasA2dp || (address != "" && mA2dpDeviceAddress != address))) {
return state;
}
-#endif
if (AudioSystem::isBluetoothScoDevice(device) &&
address != "" && mScoDeviceAddress != address) {
return state;
@@ -221,22 +263,22 @@ AudioSystem::device_connection_state AudioPolicyManagerBase::getDeviceConnection
void AudioPolicyManagerBase::setPhoneState(int state)
{
- LOGV("setPhoneState() state %d", state);
- uint32_t newDevice = 0;
+ ALOGV("setPhoneState() state %d", state);
+ audio_devices_t newDevice = (audio_devices_t)0;
if (state < 0 || state >= AudioSystem::NUM_MODES) {
- LOGW("setPhoneState() invalid state %d", state);
+ ALOGW("setPhoneState() invalid state %d", state);
return;
}
if (state == mPhoneState ) {
- LOGW("setPhoneState() setting same state %d", state);
+ ALOGW("setPhoneState() setting same state %d", state);
return;
}
// if leaving call state, handle special case of active streams
// pertaining to sonification strategy see handleIncallSonification()
if (isInCall()) {
- LOGV("setPhoneState() in call state management: new state is %d", state);
+ ALOGV("setPhoneState() in call state management: new state is %d", state);
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
handleIncallSonification(stream, false, true);
}
@@ -249,31 +291,29 @@ void AudioPolicyManagerBase::setPhoneState(int state)
// are we entering or starting a call
if (!isStateInCall(oldState) && isStateInCall(state)) {
- LOGV(" Entering call in setPhoneState()");
+ ALOGV(" Entering call in setPhoneState()");
// force routing command to audio hardware when starting a call
// even if no device change is needed
force = true;
} else if (isStateInCall(oldState) && !isStateInCall(state)) {
- LOGV(" Exiting call in setPhoneState()");
+ ALOGV(" Exiting call in setPhoneState()");
// force routing command to audio hardware when exiting a call
// even if no device change is needed
force = true;
} else if (isStateInCall(state) && (state != oldState)) {
- LOGV(" Switching between telephony and VoIP in setPhoneState()");
+ ALOGV(" Switching between telephony and VoIP in setPhoneState()");
// force routing command to audio hardware when switching between telephony and VoIP
// even if no device change is needed
force = true;
}
// check for device and output changes triggered by new phone state
- newDevice = getNewDevice(mHardwareOutput, false);
-#ifdef WITH_A2DP
+ newDevice = getNewDevice(mPrimaryOutput, false);
checkA2dpSuspend();
checkOutputForAllStrategies();
-#endif
updateDeviceForStrategy();
- AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mHardwareOutput);
+ AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mPrimaryOutput);
// force routing command to audio hardware when ending call
// even if no device change is needed
@@ -290,20 +330,20 @@ void AudioPolicyManagerBase::setPhoneState(int state)
// and be sure that audio buffers not yet affected by the mute are out when
// we actually apply the route change
delayMs = hwOutputDesc->mLatency*2;
- setStreamMute(AudioSystem::RING, true, mHardwareOutput);
+ setStreamMute(AudioSystem::RING, true, mPrimaryOutput);
}
// change routing is necessary
- setOutputDevice(mHardwareOutput, newDevice, force, delayMs);
+ setOutputDevice(mPrimaryOutput, newDevice, force, delayMs);
// if entering in call state, handle special case of active streams
// pertaining to sonification strategy see handleIncallSonification()
if (isStateInCall(state)) {
- LOGV("setPhoneState() in call state management: new state is %d", state);
+ ALOGV("setPhoneState() in call state management: new state is %d", state);
// unmute the ringing tone after a sufficient delay if it was muted before
// setting output device above
if (oldState == AudioSystem::MODE_RINGTONE) {
- setStreamMute(AudioSystem::RING, false, mHardwareOutput, MUTE_TIME_MS);
+ setStreamMute(AudioSystem::RING, false, mPrimaryOutput, MUTE_TIME_MS);
}
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
handleIncallSonification(stream, true, true);
@@ -319,23 +359,16 @@ void AudioPolicyManagerBase::setPhoneState(int state)
}
}
-void AudioPolicyManagerBase::setRingerMode(uint32_t mode, uint32_t mask)
-{
- LOGV("setRingerMode() mode %x, mask %x", mode, mask);
-
- mRingerMode = mode;
-}
-
void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSystem::forced_config config)
{
- LOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mPhoneState);
+ ALOGV("setForceUse() usage %d, config %d, mPhoneState %d", usage, config, mPhoneState);
bool forceVolumeReeval = false;
switch(usage) {
case AudioSystem::FOR_COMMUNICATION:
if (config != AudioSystem::FORCE_SPEAKER && config != AudioSystem::FORCE_BT_SCO &&
config != AudioSystem::FORCE_NONE) {
- LOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config);
+ ALOGW("setForceUse() invalid config %d for FOR_COMMUNICATION", config);
return;
}
forceVolumeReeval = true;
@@ -346,7 +379,7 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
config != AudioSystem::FORCE_WIRED_ACCESSORY &&
config != AudioSystem::FORCE_ANALOG_DOCK &&
config != AudioSystem::FORCE_DIGITAL_DOCK && config != AudioSystem::FORCE_NONE) {
- LOGW("setForceUse() invalid config %d for FOR_MEDIA", config);
+ ALOGW("setForceUse() invalid config %d for FOR_MEDIA", config);
return;
}
mForceUse[usage] = config;
@@ -354,7 +387,7 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
case AudioSystem::FOR_RECORD:
if (config != AudioSystem::FORCE_BT_SCO && config != AudioSystem::FORCE_WIRED_ACCESSORY &&
config != AudioSystem::FORCE_NONE) {
- LOGW("setForceUse() invalid config %d for FOR_RECORD", config);
+ ALOGW("setForceUse() invalid config %d for FOR_RECORD", config);
return;
}
mForceUse[usage] = config;
@@ -365,26 +398,24 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
config != AudioSystem::FORCE_WIRED_ACCESSORY &&
config != AudioSystem::FORCE_ANALOG_DOCK &&
config != AudioSystem::FORCE_DIGITAL_DOCK) {
- LOGW("setForceUse() invalid config %d for FOR_DOCK", config);
+ ALOGW("setForceUse() invalid config %d for FOR_DOCK", config);
}
forceVolumeReeval = true;
mForceUse[usage] = config;
break;
default:
- LOGW("setForceUse() invalid usage %d", usage);
+ ALOGW("setForceUse() invalid usage %d", usage);
break;
}
// check for device and output changes triggered by new phone state
- uint32_t newDevice = getNewDevice(mHardwareOutput, false);
-#ifdef WITH_A2DP
+ audio_devices_t newDevice = getNewDevice(mPrimaryOutput, false);
checkA2dpSuspend();
checkOutputForAllStrategies();
-#endif
updateDeviceForStrategy();
- setOutputDevice(mHardwareOutput, newDevice);
+ setOutputDevice(mPrimaryOutput, newDevice);
if (forceVolumeReeval) {
- applyStreamVolumes(mHardwareOutput, newDevice, 0, true);
+ applyStreamVolumes(mPrimaryOutput, newDevice, 0, true);
}
audio_io_handle_t activeInput = getActiveInput();
@@ -392,7 +423,7 @@ void AudioPolicyManagerBase::setForceUse(AudioSystem::force_use usage, AudioSyst
AudioInputDescriptor *inputDesc = mInputs.valueFor(activeInput);
newDevice = getDeviceForInputSource(inputDesc->mInputSource);
if (newDevice != inputDesc->mDevice) {
- LOGV("setForceUse() changing device from %x to %x for input %d",
+ ALOGV("setForceUse() changing device from %x to %x for input %d",
inputDesc->mDevice, newDevice, activeInput);
inputDesc->mDevice = newDevice;
AudioParameter param = AudioParameter();
@@ -410,13 +441,13 @@ AudioSystem::forced_config AudioPolicyManagerBase::getForceUse(AudioSystem::forc
void AudioPolicyManagerBase::setSystemProperty(const char* property, const char* value)
{
- LOGV("setSystemProperty() property %s, value %s", property, value);
+ ALOGV("setSystemProperty() property %s, value %s", property, value);
if (strcmp(property, "ro.camera.sound.forced") == 0) {
if (atoi(value)) {
- LOGV("ENFORCED_AUDIBLE cannot be muted");
+ ALOGV("ENFORCED_AUDIBLE cannot be muted");
mStreams[AudioSystem::ENFORCED_AUDIBLE].mCanBeMuted = false;
} else {
- LOGV("ENFORCED_AUDIBLE can be muted");
+ ALOGV("ENFORCED_AUDIBLE can be muted");
mStreams[AudioSystem::ENFORCED_AUDIBLE].mCanBeMuted = true;
}
}
@@ -431,16 +462,16 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
audio_io_handle_t output = 0;
uint32_t latency = 0;
routing_strategy strategy = getStrategy((AudioSystem::stream_type)stream);
- uint32_t device = getDeviceForStrategy(strategy);
- LOGV("getOutput() stream %d, samplingRate %d, format %d, channels %x, flags %x", stream, samplingRate, format, channels, flags);
+ audio_devices_t device = getDeviceForStrategy(strategy);
+ ALOGV("getOutput() stream %d, samplingRate %d, format %d, channels %x, flags %x", stream, samplingRate, format, channels, flags);
#ifdef AUDIO_POLICY_TEST
if (mCurOutput != 0) {
- LOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channels %x, mDirectOutput %d",
+ ALOGV("getOutput() test output mCurOutput %d, samplingRate %d, format %d, channels %x, mDirectOutput %d",
mCurOutput, mTestSamplingRate, mTestFormat, mTestChannels, mDirectOutput);
if (mTestOutputs[mCurOutput] == 0) {
- LOGV("getOutput() opening test output");
+ ALOGV("getOutput() opening test output");
AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
outputDesc->mDevice = mTestDevice;
outputDesc->mSamplingRate = mTestSamplingRate;
@@ -469,8 +500,8 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
// open a direct output if required by specified parameters
if (needsDirectOuput(stream, samplingRate, format, channels, flags, device)) {
- LOGV("getOutput() opening direct output device %x", device);
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
+ ALOGV("getOutput() opening direct output device %x", device);
+ AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(NULL);
outputDesc->mDevice = device;
outputDesc->mSamplingRate = samplingRate;
outputDesc->mFormat = format;
@@ -479,7 +510,7 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
outputDesc->mFlags = (AudioSystem::output_flags)(flags | AudioSystem::OUTPUT_FLAG_DIRECT);
outputDesc->mRefCount[stream] = 0;
outputDesc->mStopTime[stream] = 0;
- output = mpClientInterface->openOutput(&outputDesc->mDevice,
+ output = mpClientInterface->openOutput((uint32_t *)&outputDesc->mDevice,
&outputDesc->mSamplingRate,
&outputDesc->mFormat,
&outputDesc->mChannels,
@@ -491,7 +522,7 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
(samplingRate != 0 && samplingRate != outputDesc->mSamplingRate) ||
(format != 0 && format != outputDesc->mFormat) ||
(channels != 0 && channels != outputDesc->mChannels)) {
- LOGV("getOutput() failed opening direct output: samplingRate %d, format %d, channels %d",
+ ALOGV("getOutput() failed opening direct output: samplingRate %d, format %d, channels %d",
samplingRate, format, channels);
if (output != 0) {
mpClientInterface->closeOutput(output);
@@ -511,37 +542,15 @@ audio_io_handle_t AudioPolicyManagerBase::getOutput(AudioSystem::stream_type str
// get which output is suitable for the specified stream. The actual routing change will happen
// when startOutput() will be called
- uint32_t a2dpDevice = device & AudioSystem::DEVICE_OUT_ALL_A2DP;
- if (AudioSystem::popCount((AudioSystem::audio_devices)device) == 2) {
-#ifdef WITH_A2DP
- if (a2dpUsedForSonification() && a2dpDevice != 0) {
- // if playing on 2 devices among which one is A2DP, use duplicated output
- LOGV("getOutput() using duplicated output");
- LOGW_IF((mA2dpOutput == 0), "getOutput() A2DP device in multiple %x selected but A2DP output not opened", device);
- output = mDuplicatedOutput;
- } else
-#endif
- {
- // if playing on 2 devices among which none is A2DP, use hardware output
- output = mHardwareOutput;
- }
- LOGV("getOutput() using output %d for 2 devices %x", output, device);
- } else {
-#ifdef WITH_A2DP
- if (a2dpDevice != 0) {
- // if playing on A2DP device, use a2dp output
- LOGW_IF((mA2dpOutput == 0), "getOutput() A2DP device %x selected but A2DP output not opened", device);
- output = mA2dpOutput;
- } else
-#endif
- {
- // if playing on not A2DP device, use hardware output
- output = mHardwareOutput;
- }
- }
+ SortedVector<audio_io_handle_t> outputs = getOutputsForDevice(device);
+ // TODO: current implementation assumes that at most one output corresponds to a device.
+ // this will change when supporting low power, low latency or tunneled output streams
+ ALOG_ASSERT(outputs.size() < 2, "getOutput(): getOutputsForDevice() "
+ "returned %d outputs for device %04x", outputs.size(), device);
+ output = outputs[0];
- LOGW_IF((output ==0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
+ ALOGW_IF((output ==0), "getOutput() could not find output for stream %d, samplingRate %d, format %d, channels %x, flags %x",
stream, samplingRate, format, channels, flags);
return output;
@@ -551,28 +560,24 @@ status_t AudioPolicyManagerBase::startOutput(audio_io_handle_t output,
AudioSystem::stream_type stream,
int session)
{
- LOGV("startOutput() output %d, stream %d, session %d", output, stream, session);
+ ALOGV("startOutput() output %d, stream %d, session %d", output, stream, session);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- LOGW("startOutput() unknow output %d", output);
+ ALOGW("startOutput() unknow output %d", output);
return BAD_VALUE;
}
AudioOutputDescriptor *outputDesc = mOutputs.valueAt(index);
routing_strategy strategy = getStrategy((AudioSystem::stream_type)stream);
-#ifdef WITH_A2DP
- if (mA2dpOutput != 0 && !a2dpUsedForSonification() && strategy == STRATEGY_SONIFICATION) {
- setStrategyMute(STRATEGY_MEDIA, true, mA2dpOutput);
- }
-#endif
-
// incremenent usage count for this stream on the requested output:
// NOTE that the usage count is the same for duplicated output and hardware output which is
// necassary for a correct control of hardware output routing by startOutput() and stopOutput()
outputDesc->changeRefCount(stream, 1);
+ audio_devices_t prevDevice = outputDesc->device();
setOutputDevice(output, getNewDevice(output));
+ audio_devices_t newDevice = outputDesc->device();
// handle special case for sonification while in call
if (isInCall()) {
@@ -580,7 +585,17 @@ status_t AudioPolicyManagerBase::startOutput(audio_io_handle_t output,
}
// apply volume rules for current stream and device if necessary
- checkAndSetVolume(stream, mStreams[stream].mIndexCur, output, outputDesc->device());
+ checkAndSetVolume(stream,
+ mStreams[stream].getVolumeIndex((audio_devices_t)newDevice),
+ output,
+ newDevice);
+
+ // FIXME: need a delay to make sure that audio path switches to speaker before sound
+ // starts. Should be platform specific?
+ if (stream == AudioSystem::ENFORCED_AUDIBLE &&
+ prevDevice != newDevice) {
+ usleep(outputDesc->mLatency*4*1000);
+ }
return NO_ERROR;
}
@@ -589,10 +604,10 @@ status_t AudioPolicyManagerBase::stopOutput(audio_io_handle_t output,
AudioSystem::stream_type stream,
int session)
{
- LOGV("stopOutput() output %d, stream %d, session %d", output, stream, session);
+ ALOGV("stopOutput() output %d, stream %d, session %d", output, stream, session);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- LOGW("stopOutput() unknow output %d", output);
+ ALOGW("stopOutput() unknow output %d", output);
return BAD_VALUE;
}
@@ -612,31 +627,22 @@ status_t AudioPolicyManagerBase::stopOutput(audio_io_handle_t output,
setOutputDevice(output, getNewDevice(output), false, outputDesc->mLatency*2);
-#ifdef WITH_A2DP
- if (mA2dpOutput != 0 && !a2dpUsedForSonification() &&
- strategy == STRATEGY_SONIFICATION) {
- setStrategyMute(STRATEGY_MEDIA,
- false,
- mA2dpOutput,
- mOutputs.valueFor(mHardwareOutput)->mLatency*2);
- }
-#endif
- if (output != mHardwareOutput) {
- setOutputDevice(mHardwareOutput, getNewDevice(mHardwareOutput), true);
+ if (output != mPrimaryOutput) {
+ setOutputDevice(mPrimaryOutput, getNewDevice(mPrimaryOutput), true);
}
return NO_ERROR;
} else {
- LOGW("stopOutput() refcount is already 0 for output %d", output);
+ ALOGW("stopOutput() refcount is already 0 for output %d", output);
return INVALID_OPERATION;
}
}
void AudioPolicyManagerBase::releaseOutput(audio_io_handle_t output)
{
- LOGV("releaseOutput() %d", output);
+ ALOGV("releaseOutput() %d", output);
ssize_t index = mOutputs.indexOfKey(output);
if (index < 0) {
- LOGW("releaseOutput() releasing unknown output %d", output);
+ ALOGW("releaseOutput() releasing unknown output %d", output);
return;
}
@@ -668,9 +674,9 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,
AudioSystem::audio_in_acoustics acoustics)
{
audio_io_handle_t input = 0;
- uint32_t device = getDeviceForInputSource(inputSource);
+ audio_devices_t device = getDeviceForInputSource(inputSource);
- LOGV("getInput() inputSource %d, samplingRate %d, format %d, channels %x, acoustics %x", inputSource, samplingRate, format, channels, acoustics);
+ ALOGV("getInput() inputSource %d, samplingRate %d, format %d, channels %x, acoustics %x", inputSource, samplingRate, format, channels, acoustics);
if (device == 0) {
return 0;
@@ -700,18 +706,18 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,
inputDesc->mChannels = channels;
inputDesc->mAcoustics = acoustics;
inputDesc->mRefCount = 0;
- input = mpClientInterface->openInput(&inputDesc->mDevice,
+ input = mpClientInterface->openInput((uint32_t *)&inputDesc->mDevice,
&inputDesc->mSamplingRate,
&inputDesc->mFormat,
&inputDesc->mChannels,
- inputDesc->mAcoustics);
+ (audio_in_acoustics_t) inputDesc->mAcoustics);
// only accept input with the exact requested set of parameters
if (input == 0 ||
(samplingRate != inputDesc->mSamplingRate) ||
(format != inputDesc->mFormat) ||
(channels != inputDesc->mChannels)) {
- LOGV("getInput() failed opening input: samplingRate %d, format %d, channels %d",
+ ALOGV("getInput() failed opening input: samplingRate %d, format %d, channels %d",
samplingRate, format, channels);
if (input != 0) {
mpClientInterface->closeInput(input);
@@ -725,10 +731,10 @@ audio_io_handle_t AudioPolicyManagerBase::getInput(int inputSource,
status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
{
- LOGV("startInput() input %d", input);
+ ALOGV("startInput() input %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- LOGW("startInput() unknow input %d", input);
+ ALOGW("startInput() unknow input %d", input);
return BAD_VALUE;
}
AudioInputDescriptor *inputDesc = mInputs.valueAt(index);
@@ -739,7 +745,7 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
{
// refuse 2 active AudioRecord clients at the same time
if (getActiveInput() != 0) {
- LOGW("startInput() input %d failed: other input already started", input);
+ ALOGW("startInput() input %d failed: other input already started", input);
return INVALID_OPERATION;
}
}
@@ -748,7 +754,7 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
param.addInt(String8(AudioParameter::keyRouting), (int)inputDesc->mDevice);
param.addInt(String8(AudioParameter::keyInputSource), (int)inputDesc->mInputSource);
- LOGV("AudioPolicyManager::startInput() input source = %d", inputDesc->mInputSource);
+ ALOGV("AudioPolicyManager::startInput() input source = %d", inputDesc->mInputSource);
mpClientInterface->setParameters(input, param.toString());
@@ -758,16 +764,16 @@ status_t AudioPolicyManagerBase::startInput(audio_io_handle_t input)
status_t AudioPolicyManagerBase::stopInput(audio_io_handle_t input)
{
- LOGV("stopInput() input %d", input);
+ ALOGV("stopInput() input %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- LOGW("stopInput() unknow input %d", input);
+ ALOGW("stopInput() unknow input %d", input);
return BAD_VALUE;
}
AudioInputDescriptor *inputDesc = mInputs.valueAt(index);
if (inputDesc->mRefCount == 0) {
- LOGW("stopInput() input %d already stopped", input);
+ ALOGW("stopInput() input %d already stopped", input);
return INVALID_OPERATION;
} else {
AudioParameter param = AudioParameter();
@@ -780,68 +786,96 @@ status_t AudioPolicyManagerBase::stopInput(audio_io_handle_t input)
void AudioPolicyManagerBase::releaseInput(audio_io_handle_t input)
{
- LOGV("releaseInput() %d", input);
+ ALOGV("releaseInput() %d", input);
ssize_t index = mInputs.indexOfKey(input);
if (index < 0) {
- LOGW("releaseInput() releasing unknown input %d", input);
+ ALOGW("releaseInput() releasing unknown input %d", input);
return;
}
mpClientInterface->closeInput(input);
delete mInputs.valueAt(index);
mInputs.removeItem(input);
- LOGV("releaseInput() exit");
+ ALOGV("releaseInput() exit");
}
void AudioPolicyManagerBase::initStreamVolume(AudioSystem::stream_type stream,
int indexMin,
int indexMax)
{
- LOGV("initStreamVolume() stream %d, min %d, max %d", stream , indexMin, indexMax);
+ ALOGV("initStreamVolume() stream %d, min %d, max %d", stream , indexMin, indexMax);
if (indexMin < 0 || indexMin >= indexMax) {
- LOGW("initStreamVolume() invalid index limits for stream %d, min %d, max %d", stream , indexMin, indexMax);
+ ALOGW("initStreamVolume() invalid index limits for stream %d, min %d, max %d", stream , indexMin, indexMax);
return;
}
mStreams[stream].mIndexMin = indexMin;
mStreams[stream].mIndexMax = indexMax;
}
-status_t AudioPolicyManagerBase::setStreamVolumeIndex(AudioSystem::stream_type stream, int index)
+status_t AudioPolicyManagerBase::setStreamVolumeIndex(AudioSystem::stream_type stream,
+ int index,
+ audio_devices_t device)
{
if ((index < mStreams[stream].mIndexMin) || (index > mStreams[stream].mIndexMax)) {
return BAD_VALUE;
}
+ if (!audio_is_output_device(device)) {
+ return BAD_VALUE;
+ }
// Force max volume if stream cannot be muted
if (!mStreams[stream].mCanBeMuted) index = mStreams[stream].mIndexMax;
- LOGV("setStreamVolumeIndex() stream %d, index %d", stream, index);
- mStreams[stream].mIndexCur = index;
+ ALOGV("setStreamVolumeIndex() stream %d, device %04x, index %d",
+ stream, device, index);
+
+ // if device is AUDIO_DEVICE_OUT_DEFAULT set default value and
+ // clear all device specific values
+ if (device == AUDIO_DEVICE_OUT_DEFAULT) {
+ mStreams[stream].mIndexCur.clear();
+ }
+ mStreams[stream].mIndexCur.add(device, index);
// compute and apply stream volume on all outputs according to connected device
status_t status = NO_ERROR;
for (size_t i = 0; i < mOutputs.size(); i++) {
- status_t volStatus = checkAndSetVolume(stream, index, mOutputs.keyAt(i), mOutputs.valueAt(i)->device());
- if (volStatus != NO_ERROR) {
- status = volStatus;
+ audio_devices_t curDevice =
+ getDeviceForVolume((audio_devices_t)mOutputs.valueAt(i)->device());
+ if (device == curDevice) {
+ status_t volStatus = checkAndSetVolume(stream, index, mOutputs.keyAt(i), curDevice);
+ if (volStatus != NO_ERROR) {
+ status = volStatus;
+ }
}
}
return status;
}
-status_t AudioPolicyManagerBase::getStreamVolumeIndex(AudioSystem::stream_type stream, int *index)
+status_t AudioPolicyManagerBase::getStreamVolumeIndex(AudioSystem::stream_type stream,
+ int *index,
+ audio_devices_t device)
{
- if (index == 0) {
+ if (index == NULL) {
return BAD_VALUE;
}
- LOGV("getStreamVolumeIndex() stream %d", stream);
- *index = mStreams[stream].mIndexCur;
+ if (!audio_is_output_device(device)) {
+ return BAD_VALUE;
+ }
+ // if device is AUDIO_DEVICE_OUT_DEFAULT, return volume for device corresponding to
+ // the strategy the stream belongs to.
+ if (device == AUDIO_DEVICE_OUT_DEFAULT) {
+ device = (audio_devices_t)getDeviceForStrategy(getStrategy(stream), true);
+ }
+ device = getDeviceForVolume(device);
+
+ *index = mStreams[stream].getVolumeIndex(device);
+ ALOGV("getStreamVolumeIndex() stream %d device %08x index %d", stream, device, *index);
return NO_ERROR;
}
audio_io_handle_t AudioPolicyManagerBase::getOutputForEffect(effect_descriptor_t *desc)
{
- LOGV("getOutputForEffect()");
+ ALOGV("getOutputForEffect()");
// apply simple rule where global effects are attached to the same output as MUSIC streams
return getOutput(AudioSystem::MUSIC);
}
@@ -856,20 +890,20 @@ status_t AudioPolicyManagerBase::registerEffect(effect_descriptor_t *desc,
if (index < 0) {
index = mInputs.indexOfKey(io);
if (index < 0) {
- LOGW("registerEffect() unknown io %d", io);
+ ALOGW("registerEffect() unknown io %d", io);
return INVALID_OPERATION;
}
}
if (mTotalEffectsMemory + desc->memoryUsage > getMaxEffectsMemory()) {
- LOGW("registerEffect() memory limit exceeded for Fx %s, Memory %d KB",
+ ALOGW("registerEffect() memory limit exceeded for Fx %s, Memory %d KB",
desc->name, desc->memoryUsage);
return INVALID_OPERATION;
}
mTotalEffectsMemory += desc->memoryUsage;
- LOGV("registerEffect() effect %s, io %d, strategy %d session %d id %d",
+ ALOGV("registerEffect() effect %s, io %d, strategy %d session %d id %d",
desc->name, io, strategy, session, id);
- LOGV("registerEffect() memory %d, total memory %d", desc->memoryUsage, mTotalEffectsMemory);
+ ALOGV("registerEffect() memory %d, total memory %d", desc->memoryUsage, mTotalEffectsMemory);
EffectDescriptor *pDesc = new EffectDescriptor();
memcpy (&pDesc->mDesc, desc, sizeof(effect_descriptor_t));
@@ -887,7 +921,7 @@ status_t AudioPolicyManagerBase::unregisterEffect(int id)
{
ssize_t index = mEffects.indexOfKey(id);
if (index < 0) {
- LOGW("unregisterEffect() unknown effect ID %d", id);
+ ALOGW("unregisterEffect() unknown effect ID %d", id);
return INVALID_OPERATION;
}
@@ -896,12 +930,12 @@ status_t AudioPolicyManagerBase::unregisterEffect(int id)
setEffectEnabled(pDesc, false);
if (mTotalEffectsMemory < pDesc->mDesc.memoryUsage) {
- LOGW("unregisterEffect() memory %d too big for total %d",
+ ALOGW("unregisterEffect() memory %d too big for total %d",
pDesc->mDesc.memoryUsage, mTotalEffectsMemory);
pDesc->mDesc.memoryUsage = mTotalEffectsMemory;
}
mTotalEffectsMemory -= pDesc->mDesc.memoryUsage;
- LOGV("unregisterEffect() effect %s, ID %d, memory %d total memory %d",
+ ALOGV("unregisterEffect() effect %s, ID %d, memory %d total memory %d",
pDesc->mDesc.name, id, pDesc->mDesc.memoryUsage, mTotalEffectsMemory);
mEffects.removeItem(id);
@@ -914,7 +948,7 @@ status_t AudioPolicyManagerBase::setEffectEnabled(int id, bool enabled)
{
ssize_t index = mEffects.indexOfKey(id);
if (index < 0) {
- LOGW("unregisterEffect() unknown effect ID %d", id);
+ ALOGW("unregisterEffect() unknown effect ID %d", id);
return INVALID_OPERATION;
}
@@ -924,27 +958,27 @@ status_t AudioPolicyManagerBase::setEffectEnabled(int id, bool enabled)
status_t AudioPolicyManagerBase::setEffectEnabled(EffectDescriptor *pDesc, bool enabled)
{
if (enabled == pDesc->mEnabled) {
- LOGV("setEffectEnabled(%s) effect already %s",
+ ALOGV("setEffectEnabled(%s) effect already %s",
enabled?"true":"false", enabled?"enabled":"disabled");
return INVALID_OPERATION;
}
if (enabled) {
if (mTotalEffectsCpuLoad + pDesc->mDesc.cpuLoad > getMaxEffectsCpuLoad()) {
- LOGW("setEffectEnabled(true) CPU Load limit exceeded for Fx %s, CPU %f MIPS",
+ ALOGW("setEffectEnabled(true) CPU Load limit exceeded for Fx %s, CPU %f MIPS",
pDesc->mDesc.name, (float)pDesc->mDesc.cpuLoad/10);
return INVALID_OPERATION;
}
mTotalEffectsCpuLoad += pDesc->mDesc.cpuLoad;
- LOGV("setEffectEnabled(true) total CPU %d", mTotalEffectsCpuLoad);
+ ALOGV("setEffectEnabled(true) total CPU %d", mTotalEffectsCpuLoad);
} else {
if (mTotalEffectsCpuLoad < pDesc->mDesc.cpuLoad) {
- LOGW("setEffectEnabled(false) CPU load %d too high for total %d",
+ ALOGW("setEffectEnabled(false) CPU load %d too high for total %d",
pDesc->mDesc.cpuLoad, mTotalEffectsCpuLoad);
pDesc->mDesc.cpuLoad = mTotalEffectsCpuLoad;
}
mTotalEffectsCpuLoad -= pDesc->mDesc.cpuLoad;
- LOGV("setEffectEnabled(false) total CPU %d", mTotalEffectsCpuLoad);
+ ALOGV("setEffectEnabled(false) total CPU %d", mTotalEffectsCpuLoad);
}
pDesc->mEnabled = enabled;
return NO_ERROR;
@@ -971,16 +1005,11 @@ status_t AudioPolicyManagerBase::dump(int fd)
snprintf(buffer, SIZE, "\nAudioPolicyManager Dump: %p\n", this);
result.append(buffer);
- snprintf(buffer, SIZE, " Hardware Output: %d\n", mHardwareOutput);
- result.append(buffer);
-#ifdef WITH_A2DP
- snprintf(buffer, SIZE, " A2DP Output: %d\n", mA2dpOutput);
- result.append(buffer);
- snprintf(buffer, SIZE, " Duplicated Output: %d\n", mDuplicatedOutput);
+
+ snprintf(buffer, SIZE, " Hardware Output: %d\n", mPrimaryOutput);
result.append(buffer);
snprintf(buffer, SIZE, " A2DP device address: %s\n", mA2dpDeviceAddress.string());
result.append(buffer);
-#endif
snprintf(buffer, SIZE, " SCO device address: %s\n", mScoDeviceAddress.string());
result.append(buffer);
snprintf(buffer, SIZE, " Output devices: %08x\n", mAvailableOutputDevices);
@@ -989,8 +1018,6 @@ status_t AudioPolicyManagerBase::dump(int fd)
result.append(buffer);
snprintf(buffer, SIZE, " Phone state: %d\n", mPhoneState);
result.append(buffer);
- snprintf(buffer, SIZE, " Ringer mode: %d\n", mRingerMode);
- result.append(buffer);
snprintf(buffer, SIZE, " Force use for communications %d\n", mForceUse[AudioSystem::FOR_COMMUNICATION]);
result.append(buffer);
snprintf(buffer, SIZE, " Force use for media %d\n", mForceUse[AudioSystem::FOR_MEDIA]);
@@ -1019,12 +1046,13 @@ status_t AudioPolicyManagerBase::dump(int fd)
snprintf(buffer, SIZE, "\nStreams dump:\n");
write(fd, buffer, strlen(buffer));
- snprintf(buffer, SIZE, " Stream Index Min Index Max Index Cur Can be muted\n");
+ snprintf(buffer, SIZE,
+ " Stream Can be muted Index Min Index Max Index Cur [device : index]...\n");
write(fd, buffer, strlen(buffer));
for (size_t i = 0; i < AudioSystem::NUM_STREAM_TYPES; i++) {
- snprintf(buffer, SIZE, " %02d", i);
- mStreams[i].dump(buffer + 3, SIZE);
+ snprintf(buffer, SIZE, " %02d ", i);
write(fd, buffer, strlen(buffer));
+ mStreams[i].dump(fd);
}
snprintf(buffer, SIZE, "\nTotal Effects CPU: %f MIPS, Total Effects memory: %d KB\n",
@@ -1052,7 +1080,8 @@ AudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clien
#ifdef AUDIO_POLICY_TEST
Thread(false),
#endif //AUDIO_POLICY_TEST
- mPhoneState(AudioSystem::MODE_NORMAL), mRingerMode(0),
+ mAvailableOutputDevices((audio_devices_t)0),
+ mPhoneState(AudioSystem::MODE_NORMAL),
mLimitRingtoneVolume(false), mLastVoiceVolume(-1.0f),
mTotalEffectsCpuLoad(0), mTotalEffectsMemory(0),
mA2dpSuspended(false)
@@ -1065,43 +1094,59 @@ AudioPolicyManagerBase::AudioPolicyManagerBase(AudioPolicyClientInterface *clien
initializeVolumeCurves();
- // devices available by default are speaker, ear piece and microphone
- mAvailableOutputDevices = AudioSystem::DEVICE_OUT_EARPIECE |
- AudioSystem::DEVICE_OUT_SPEAKER;
- mAvailableInputDevices = AudioSystem::DEVICE_IN_BUILTIN_MIC;
-
-#ifdef WITH_A2DP
- mA2dpOutput = 0;
- mDuplicatedOutput = 0;
mA2dpDeviceAddress = String8("");
-#endif
mScoDeviceAddress = String8("");
- // open hardware output
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
- outputDesc->mDevice = (uint32_t)AudioSystem::DEVICE_OUT_SPEAKER;
- mHardwareOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
- &outputDesc->mSamplingRate,
- &outputDesc->mFormat,
- &outputDesc->mChannels,
- &outputDesc->mLatency,
- outputDesc->mFlags);
-
- if (mHardwareOutput == 0) {
- LOGE("Failed to initialize hardware output stream, samplingRate: %d, format %d, channels %d",
- outputDesc->mSamplingRate, outputDesc->mFormat, outputDesc->mChannels);
- } else {
- addOutput(mHardwareOutput, outputDesc);
- setOutputDevice(mHardwareOutput, (uint32_t)AudioSystem::DEVICE_OUT_SPEAKER, true);
- //TODO: configure audio effect output stage here
+ // TODO read this from configuration file
+ sHasA2dp = true;
+ const output_profile_t **outProfile = sAvailableOutputs;
+ // open all output streams needed to access attached devices
+ while (*outProfile)
+ {
+ if ((*outProfile)->mSupportedDevices & sAttachedOutputDevices) {
+ AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(*outProfile);
+
+ outputDesc->mDevice = (audio_devices_t)(sDefaultOutputDevice & (*outProfile)->mSupportedDevices);
+ outputDesc->mSamplingRate = (*outProfile)->mSamplingRates[0];
+ outputDesc->mFormat = (*outProfile)->mFormats[0];
+ outputDesc->mChannels = (*outProfile)->mChannelMasks[0];
+ outputDesc->mFlags = (AudioSystem::output_flags)(*outProfile)->mFlags;
+ audio_io_handle_t output = mpClientInterface->openOutput((uint32_t *)&outputDesc->mDevice,
+ &outputDesc->mSamplingRate,
+ &outputDesc->mFormat,
+ &outputDesc->mChannels,
+ &outputDesc->mLatency,
+ outputDesc->mFlags);
+ if (output == 0) {
+ delete outputDesc;
+ } else {
+ mAvailableOutputDevices = (audio_devices_t)(mAvailableOutputDevices | ((*outProfile)->mSupportedDevices & sAttachedOutputDevices));
+ if ((*outProfile)->mFlags & AUDIO_POLICY_OUTPUT_FLAG_PRIMARY) {
+ mPrimaryOutput = output;
+ }
+ addOutput(output, outputDesc);
+ setOutputDevice(output,
+ (audio_devices_t)(sDefaultOutputDevice & (*outProfile)->mSupportedDevices),
+ true);
+ }
+ }
+ outProfile++;
}
+ ALOGE_IF((sAttachedOutputDevices & ~mAvailableOutputDevices),
+ "Not output found for attached devices %08x",
+ (sAttachedOutputDevices & ~mAvailableOutputDevices));
+
+ ALOGE_IF((mPrimaryOutput == 0), "Failed to open primary output");
+
+ mAvailableInputDevices = AudioSystem::DEVICE_IN_BUILTIN_MIC;
+
updateDeviceForStrategy();
#ifdef AUDIO_POLICY_TEST
- if (mHardwareOutput != 0) {
+ if (mPrimaryOutput != 0) {
AudioParameter outputCmd = AudioParameter();
outputCmd.addInt(String8("set_id"), 0);
- mpClientInterface->setParameters(mHardwareOutput, outputCmd.toString());
+ mpClientInterface->setParameters(mPrimaryOutput, outputCmd.toString());
mTestDevice = AudioSystem::DEVICE_OUT_SPEAKER;
mTestSamplingRate = 44100;
@@ -1141,13 +1186,13 @@ AudioPolicyManagerBase::~AudioPolicyManagerBase()
status_t AudioPolicyManagerBase::initCheck()
{
- return (mHardwareOutput == 0) ? NO_INIT : NO_ERROR;
+ return (mPrimaryOutput == 0) ? NO_INIT : NO_ERROR;
}
#ifdef AUDIO_POLICY_TEST
bool AudioPolicyManagerBase::threadLoop()
{
- LOGV("entering threadLoop()");
+ ALOGV("entering threadLoop()");
while (!exitPending())
{
String8 command;
@@ -1162,7 +1207,7 @@ bool AudioPolicyManagerBase::threadLoop()
if (param.getInt(String8("test_cmd_policy"), valueInt) == NO_ERROR &&
valueInt != 0) {
- LOGV("Test command %s received", command.string());
+ ALOGV("Test command %s received", command.string());
String8 target;
if (param.get(String8("target"), target) != NO_ERROR) {
target = "Manager";
@@ -1240,26 +1285,26 @@ bool AudioPolicyManagerBase::threadLoop()
if (param.get(String8("test_cmd_policy_reopen"), value) == NO_ERROR) {
param.remove(String8("test_cmd_policy_reopen"));
- mpClientInterface->closeOutput(mHardwareOutput);
- delete mOutputs.valueFor(mHardwareOutput);
- mOutputs.removeItem(mHardwareOutput);
+ mpClientInterface->closeOutput(mPrimaryOutput);
+ delete mOutputs.valueFor(mPrimaryOutput);
+ mOutputs.removeItem(mPrimaryOutput);
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
+ AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor(NULL);
outputDesc->mDevice = (uint32_t)AudioSystem::DEVICE_OUT_SPEAKER;
- mHardwareOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
+ mPrimaryOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
&outputDesc->mSamplingRate,
&outputDesc->mFormat,
&outputDesc->mChannels,
&outputDesc->mLatency,
outputDesc->mFlags);
- if (mHardwareOutput == 0) {
- LOGE("Failed to reopen hardware output stream, samplingRate: %d, format %d, channels %d",
+ if (mPrimaryOutput == 0) {
+ ALOGE("Failed to reopen hardware output stream, samplingRate: %d, format %d, channels %d",
outputDesc->mSamplingRate, outputDesc->mFormat, outputDesc->mChannels);
} else {
AudioParameter outputCmd = AudioParameter();
outputCmd.addInt(String8("set_id"), 0);
- mpClientInterface->setParameters(mHardwareOutput, outputCmd.toString());
- addOutput(mHardwareOutput, outputDesc);
+ mpClientInterface->setParameters(mPrimaryOutput, outputCmd.toString());
+ addOutput(mPrimaryOutput, outputDesc);
}
}
@@ -1298,193 +1343,211 @@ void AudioPolicyManagerBase::addOutput(audio_io_handle_t id, AudioOutputDescript
}
-#ifdef WITH_A2DP
-status_t AudioPolicyManagerBase::handleA2dpConnection(AudioSystem::audio_devices device,
- const char *device_address)
+audio_io_handle_t AudioPolicyManagerBase::checkOutputForDevice(
+ audio_devices_t device,
+ AudioSystem::device_connection_state state)
{
- // when an A2DP device is connected, open an A2DP and a duplicated output
- LOGV("opening A2DP output for device %s", device_address);
- AudioOutputDescriptor *outputDesc = new AudioOutputDescriptor();
- outputDesc->mDevice = device;
- mA2dpOutput = mpClientInterface->openOutput(&outputDesc->mDevice,
- &outputDesc->mSamplingRate,
- &outputDesc->mFormat,
- &outputDesc->mChannels,
- &outputDesc->mLatency,
- outputDesc->mFlags);
- if (mA2dpOutput) {
- // add A2DP output descriptor
- addOutput(mA2dpOutput, outputDesc);
-
- //TODO: configure audio effect output stage here
-
- // set initial stream volume for A2DP device
- applyStreamVolumes(mA2dpOutput, device);
- if (a2dpUsedForSonification()) {
- mDuplicatedOutput = mpClientInterface->openDuplicateOutput(mA2dpOutput, mHardwareOutput);
- }
- if (mDuplicatedOutput != 0 ||
- !a2dpUsedForSonification()) {
- // If both A2DP and duplicated outputs are open, send device address to A2DP hardware
- // interface
- AudioParameter param;
- param.add(String8("a2dp_sink_address"), String8(device_address));
- mpClientInterface->setParameters(mA2dpOutput, param.toString());
- mA2dpDeviceAddress = String8(device_address, MAX_DEVICE_ADDRESS_LEN);
-
- if (a2dpUsedForSonification()) {
+ audio_io_handle_t output = 0;
+ AudioOutputDescriptor *outputDesc;
+
+ // TODO handle multiple outputs supporting overlapping sets of devices.
+
+ if (state == AudioSystem::DEVICE_STATE_AVAILABLE) {
+ // first check if one output already open can be routed to this device
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ AudioOutputDescriptor *outputDesc = mOutputs.valueAt(i);
+ if (outputDesc->mProfile && outputDesc->mProfile->mSupportedDevices & device) {
+ return mOutputs.keyAt(i);
+ }
+ }
+ // then look for one available output that can be routed to this device
+ const output_profile_t **outProfile = sAvailableOutputs;
+ while (*outProfile)
+ {
+ if ((*outProfile)->mSupportedDevices & device) {
+ break;
+ }
+ outProfile++;
+ }
+ if (*outProfile == NULL) {
+ ALOGW("No output available for device %04x", device);
+ return output;
+ }
+
+ ALOGV("opening output for device %08x", device);
+ outputDesc = new AudioOutputDescriptor(*outProfile);
+ outputDesc->mDevice = device;
+ output = mpClientInterface->openOutput((uint32_t *)&outputDesc->mDevice,
+ &outputDesc->mSamplingRate,
+ &outputDesc->mFormat,
+ &outputDesc->mChannels,
+ &outputDesc->mLatency,
+ outputDesc->mFlags);
+
+ if (output != 0) {
+ audio_io_handle_t duplicatedOutput = 0;
+ // add output descriptor
+ addOutput(output, outputDesc);
+ // set initial stream volume for device
+ applyStreamVolumes(output, device);
+
+ //TODO: configure audio effect output stage here
+
+ // open a duplicating output thread for the new output and the primary output
+ duplicatedOutput = mpClientInterface->openDuplicateOutput(output, mPrimaryOutput);
+ if (duplicatedOutput != 0) {
// add duplicated output descriptor
- AudioOutputDescriptor *dupOutputDesc = new AudioOutputDescriptor();
- dupOutputDesc->mOutput1 = mOutputs.valueFor(mHardwareOutput);
- dupOutputDesc->mOutput2 = mOutputs.valueFor(mA2dpOutput);
+ AudioOutputDescriptor *dupOutputDesc = new AudioOutputDescriptor(NULL);
+ dupOutputDesc->mOutput1 = mOutputs.valueFor(mPrimaryOutput);
+ dupOutputDesc->mOutput2 = mOutputs.valueFor(output);
dupOutputDesc->mSamplingRate = outputDesc->mSamplingRate;
dupOutputDesc->mFormat = outputDesc->mFormat;
dupOutputDesc->mChannels = outputDesc->mChannels;
dupOutputDesc->mLatency = outputDesc->mLatency;
- addOutput(mDuplicatedOutput, dupOutputDesc);
- applyStreamVolumes(mDuplicatedOutput, device);
+ addOutput(duplicatedOutput, dupOutputDesc);
+ applyStreamVolumes(duplicatedOutput, device);
+ } else {
+ ALOGW("getOutput() could not open duplicated output for %d and %d",
+ mPrimaryOutput, output);
+ mpClientInterface->closeOutput(output);
+ mOutputs.removeItem(output);
+ delete outputDesc;
+ return 0;
}
} else {
- LOGW("getOutput() could not open duplicated output for %d and %d",
- mHardwareOutput, mA2dpOutput);
- mpClientInterface->closeOutput(mA2dpOutput);
- mOutputs.removeItem(mA2dpOutput);
- mA2dpOutput = 0;
+ ALOGW("setDeviceConnectionState() could not open A2DP output for device %x", device);
delete outputDesc;
- return NO_INIT;
+ return 0;
}
} else {
- LOGW("setDeviceConnectionState() could not open A2DP output for device %x", device);
- delete outputDesc;
- return NO_INIT;
- }
- AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mHardwareOutput);
-
- if (!a2dpUsedForSonification()) {
- // mute music on A2DP output if a notification or ringtone is playing
- uint32_t refCount = hwOutputDesc->strategyRefCount(STRATEGY_SONIFICATION);
- for (uint32_t i = 0; i < refCount; i++) {
- setStrategyMute(STRATEGY_MEDIA, true, mA2dpOutput);
+ // we assume that one given device is supported by zero or one output
+ // check if one opened output is not needed any more after disconnecting one device
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ outputDesc = mOutputs.valueAt(i);
+ if (outputDesc->mProfile &&
+ !(outputDesc->mProfile->mSupportedDevices & mAvailableOutputDevices)) {
+ output = mOutputs.keyAt(i);
+ break;
+ }
}
}
- mA2dpSuspended = false;
-
- return NO_ERROR;
+ return output;
}
-status_t AudioPolicyManagerBase::handleA2dpDisconnection(AudioSystem::audio_devices device,
- const char *device_address)
+void AudioPolicyManagerBase::closeOutput(audio_io_handle_t output)
{
- if (mA2dpOutput == 0) {
- LOGW("setDeviceConnectionState() disconnecting A2DP and no A2DP output!");
- return INVALID_OPERATION;
- }
+ ALOGV("closeOutput(%d)", output);
- if (mA2dpDeviceAddress != device_address) {
- LOGW("setDeviceConnectionState() disconnecting unknow A2DP sink address %s", device_address);
- return INVALID_OPERATION;
+ AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
+ if (outputDesc == NULL) {
+ ALOGW("closeOutput() unknown output %d", output);
+ return;
}
- // mute media strategy to avoid outputting sound on hardware output while music stream
- // is switched from A2DP output and before music is paused by music application
- setStrategyMute(STRATEGY_MEDIA, true, mHardwareOutput);
- setStrategyMute(STRATEGY_MEDIA, false, mHardwareOutput, MUTE_TIME_MS);
+ // look for duplicated outputs connected to the output being removed.
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ AudioOutputDescriptor *dupOutputDesc = mOutputs.valueAt(i);
+ if (dupOutputDesc->isDuplicated() &&
+ (dupOutputDesc->mOutput1 == outputDesc ||
+ dupOutputDesc->mOutput2 == outputDesc)) {
+ AudioOutputDescriptor *outputDesc2;
+ if (dupOutputDesc->mOutput1 == outputDesc) {
+ outputDesc2 = dupOutputDesc->mOutput2;
+ } else {
+ outputDesc2 = dupOutputDesc->mOutput1;
+ }
+ // As all active tracks on duplicated output will be deleted,
+ // and as they were also referenced on the other output, the reference
+ // count for their stream type must be adjusted accordingly on
+ // the other output.
+ for (int j = 0; j < (int)AudioSystem::NUM_STREAM_TYPES; j++) {
+ int refCount = dupOutputDesc->mRefCount[j];
+ outputDesc2->changeRefCount((AudioSystem::stream_type)j,-refCount);
+ }
+ audio_io_handle_t duplicatedOutput = mOutputs.keyAt(i);
+ ALOGV("closeOutput() closing also duplicated output %d", duplicatedOutput);
- if (!a2dpUsedForSonification()) {
- // unmute music on A2DP output if a notification or ringtone is playing
- uint32_t refCount = mOutputs.valueFor(mHardwareOutput)->strategyRefCount(STRATEGY_SONIFICATION);
- for (uint32_t i = 0; i < refCount; i++) {
- setStrategyMute(STRATEGY_MEDIA, false, mA2dpOutput);
+ mpClientInterface->closeOutput(duplicatedOutput);
+ delete mOutputs.valueFor(duplicatedOutput);
+ mOutputs.removeItem(duplicatedOutput);
}
}
- mA2dpDeviceAddress = "";
- mA2dpSuspended = false;
- return NO_ERROR;
+
+ AudioParameter param;
+ param.add(String8("closing"), String8("true"));
+ mpClientInterface->setParameters(output, param.toString());
+
+ mpClientInterface->closeOutput(output);
+ delete mOutputs.valueFor(output);
+ mOutputs.removeItem(output);
}
-void AudioPolicyManagerBase::closeA2dpOutputs()
+SortedVector<audio_io_handle_t> AudioPolicyManagerBase::getOutputsForDevice(audio_devices_t device)
{
+ SortedVector<audio_io_handle_t> outputs;
- LOGV("setDeviceConnectionState() closing A2DP and duplicated output!");
-
- if (mDuplicatedOutput != 0) {
- AudioOutputDescriptor *dupOutputDesc = mOutputs.valueFor(mDuplicatedOutput);
- AudioOutputDescriptor *hwOutputDesc = mOutputs.valueFor(mHardwareOutput);
- // As all active tracks on duplicated output will be deleted,
- // and as they were also referenced on hardware output, the reference
- // count for their stream type must be adjusted accordingly on
- // hardware output.
- for (int i = 0; i < (int)AudioSystem::NUM_STREAM_TYPES; i++) {
- int refCount = dupOutputDesc->mRefCount[i];
- hwOutputDesc->changeRefCount((AudioSystem::stream_type)i,-refCount);
+ ALOGV("getOutputsForDevice() device %04x", device);
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ if ((device & mOutputs.valueAt(i)->supportedDevices()) == device) {
+ ALOGV("getOutputsForDevice() found output %d", mOutputs.keyAt(i));
+ outputs.add(mOutputs.keyAt(i));
}
-
- mpClientInterface->closeOutput(mDuplicatedOutput);
- delete mOutputs.valueFor(mDuplicatedOutput);
- mOutputs.removeItem(mDuplicatedOutput);
- mDuplicatedOutput = 0;
- }
- if (mA2dpOutput != 0) {
- AudioParameter param;
- param.add(String8("closing"), String8("true"));
- mpClientInterface->setParameters(mA2dpOutput, param.toString());
-
- mpClientInterface->closeOutput(mA2dpOutput);
- delete mOutputs.valueFor(mA2dpOutput);
- mOutputs.removeItem(mA2dpOutput);
- mA2dpOutput = 0;
}
+ return outputs;
}
-void AudioPolicyManagerBase::checkOutputForStrategy(routing_strategy strategy)
+bool AudioPolicyManagerBase::vectorsEqual(SortedVector<audio_io_handle_t>& outputs1,
+ SortedVector<audio_io_handle_t>& outputs2)
{
- uint32_t prevDevice = getDeviceForStrategy(strategy);
- uint32_t curDevice = getDeviceForStrategy(strategy, false);
- bool a2dpWasUsed = AudioSystem::isA2dpDevice((AudioSystem::audio_devices)(prevDevice & ~AudioSystem::DEVICE_OUT_SPEAKER));
- bool a2dpIsUsed = AudioSystem::isA2dpDevice((AudioSystem::audio_devices)(curDevice & ~AudioSystem::DEVICE_OUT_SPEAKER));
- audio_io_handle_t srcOutput = 0;
- audio_io_handle_t dstOutput = 0;
-
- if (a2dpWasUsed && !a2dpIsUsed) {
- bool dupUsed = a2dpUsedForSonification() && a2dpWasUsed && (AudioSystem::popCount(prevDevice) == 2);
- dstOutput = mHardwareOutput;
- if (dupUsed) {
- LOGV("checkOutputForStrategy() moving strategy %d from duplicated", strategy);
- srcOutput = mDuplicatedOutput;
- } else {
- LOGV("checkOutputForStrategy() moving strategy %d from a2dp", strategy);
- srcOutput = mA2dpOutput;
- }
+ if (outputs1.size() != outputs2.size()) {
+ return false;
}
- if (a2dpIsUsed && !a2dpWasUsed) {
- bool dupUsed = a2dpUsedForSonification() && a2dpIsUsed && (AudioSystem::popCount(curDevice) == 2);
- srcOutput = mHardwareOutput;
- if (dupUsed) {
- LOGV("checkOutputForStrategy() moving strategy %d to duplicated", strategy);
- dstOutput = mDuplicatedOutput;
- } else {
- LOGV("checkOutputForStrategy() moving strategy %d to a2dp", strategy);
- dstOutput = mA2dpOutput;
+ for (size_t i = 0; i < outputs1.size(); i++) {
+ if (outputs1[i] != outputs2[i]) {
+ return false;
}
}
+ return true;
+}
+
+void AudioPolicyManagerBase::checkOutputForStrategy(routing_strategy strategy)
+{
+ SortedVector<audio_io_handle_t> srcOutputs =
+ getOutputsForDevice(getDeviceForStrategy(strategy));
+ SortedVector<audio_io_handle_t> dstOutputs =
+ getOutputsForDevice(getDeviceForStrategy(strategy, false));
+
+ // TODO: current implementation assumes that at most one output corresponds to a device.
+ // this will change when supporting low power, low latency or tunneled output streams
+ ALOG_ASSERT(srcOutputs.size() < 2, "checkOutputForStrategy(): "
+ "more than one (%d) source output for strategy %d", srcOutputs.size(), strategy);
+ ALOG_ASSERT(dstOutputs.size() < 2, "checkOutputForStrategy(): "
+ "more than one (%d) destination output for strategy %d", dstOutputs.size(), strategy);
+
+ if (!vectorsEqual(srcOutputs,dstOutputs)) {
+ ALOGV("checkOutputForStrategy() strategy %d, moving from output %d to output %d",
+ strategy, srcOutputs[0], dstOutputs[0]);
+ // mute media strategy while moving tracks from one output to another
+ setStrategyMute(strategy, true, srcOutputs[0]);
+ setStrategyMute(strategy, false, srcOutputs[0], MUTE_TIME_MS);
- if (srcOutput != 0 && dstOutput != 0) {
// Move effects associated to this strategy from previous output to new output
for (size_t i = 0; i < mEffects.size(); i++) {
EffectDescriptor *desc = mEffects.valueAt(i);
if (desc->mSession != AudioSystem::SESSION_OUTPUT_STAGE &&
desc->mStrategy == strategy &&
- desc->mIo == srcOutput) {
- LOGV("checkOutputForStrategy() moving effect %d to output %d", mEffects.keyAt(i), dstOutput);
- mpClientInterface->moveEffects(desc->mSession, srcOutput, dstOutput);
- desc->mIo = dstOutput;
+ desc->mIo == srcOutputs[0]) {
+ ALOGV("checkOutputForStrategy() moving effect %d to output %d",
+ mEffects.keyAt(i), dstOutputs[0]);
+ mpClientInterface->moveEffects(desc->mSession, srcOutputs[0], dstOutputs[0]);
+ desc->mIo = dstOutputs[0];
}
}
// Move tracks associated to this strategy from previous output to new output
for (int i = 0; i < (int)AudioSystem::NUM_STREAM_TYPES; i++) {
if (getStrategy((AudioSystem::stream_type)i) == strategy) {
- mpClientInterface->setStreamOutput((AudioSystem::stream_type)i, dstOutput);
+ mpClientInterface->setStreamOutput((AudioSystem::stream_type)i, dstOutputs[0]);
}
}
}
@@ -1492,14 +1555,39 @@ void AudioPolicyManagerBase::checkOutputForStrategy(routing_strategy strategy)
void AudioPolicyManagerBase::checkOutputForAllStrategies()
{
+ checkOutputForStrategy(STRATEGY_ENFORCED_AUDIBLE);
checkOutputForStrategy(STRATEGY_PHONE);
checkOutputForStrategy(STRATEGY_SONIFICATION);
checkOutputForStrategy(STRATEGY_MEDIA);
checkOutputForStrategy(STRATEGY_DTMF);
}
+audio_io_handle_t AudioPolicyManagerBase::getA2dpOutput()
+{
+ if (!sHasA2dp) {
+ return 0;
+ }
+
+ for (size_t i = 0; i < mOutputs.size(); i++) {
+ AudioOutputDescriptor *outputDesc = mOutputs.valueAt(i);
+ if (!outputDesc->isDuplicated() && outputDesc->device() & AUDIO_DEVICE_OUT_ALL_A2DP) {
+ return mOutputs.keyAt(i);
+ }
+ }
+
+ return 0;
+}
+
void AudioPolicyManagerBase::checkA2dpSuspend()
{
+ if (!sHasA2dp) {
+ return;
+ }
+ audio_io_handle_t a2dpOutput = getA2dpOutput();
+ if (a2dpOutput == 0) {
+ return;
+ }
+
// suspend A2DP output if:
// (NOT already suspended) &&
// ((SCO device is connected &&
@@ -1512,10 +1600,6 @@ void AudioPolicyManagerBase::checkA2dpSuspend()
// (forced usage NOT for communication && NOT for record is SCO))) &&
// (phone state is NOT ringing && NOT in call)
//
- if (mA2dpOutput == 0) {
- return;
- }
-
if (mA2dpSuspended) {
if (((mScoDeviceAddress == "") ||
((mForceUse[AudioSystem::FOR_COMMUNICATION] != AudioSystem::FORCE_BT_SCO) &&
@@ -1523,7 +1607,7 @@ void AudioPolicyManagerBase::checkA2dpSuspend()
((mPhoneState != AudioSystem::MODE_IN_CALL) &&
(mPhoneState != AudioSystem::MODE_RINGTONE))) {
- mpClientInterface->restoreOutput(mA2dpOutput);
+ mpClientInterface->restoreOutput(a2dpOutput);
mA2dpSuspended = false;
}
} else {
@@ -1533,31 +1617,32 @@ void AudioPolicyManagerBase::checkA2dpSuspend()
((mPhoneState == AudioSystem::MODE_IN_CALL) ||
(mPhoneState == AudioSystem::MODE_RINGTONE))) {
- mpClientInterface->suspendOutput(mA2dpOutput);
+ mpClientInterface->suspendOutput(a2dpOutput);
mA2dpSuspended = true;
}
}
}
-
-#endif
-
-uint32_t AudioPolicyManagerBase::getNewDevice(audio_io_handle_t output, bool fromCache)
+audio_devices_t AudioPolicyManagerBase::getNewDevice(audio_io_handle_t output, bool fromCache)
{
- uint32_t device = 0;
+ audio_devices_t device = (audio_devices_t)0;
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
// check the following by order of priority to request a routing change if necessary:
- // 1: we are in call or the strategy phone is active on the hardware output:
+ // 1: the strategy enforced audible is active on the output:
+ // use device for strategy enforced audible
+ // 2: we are in call or the strategy phone is active on the output:
// use device for strategy phone
- // 2: the strategy sonification is active on the hardware output:
+ // 3: the strategy sonification is active on the output:
// use device for strategy sonification
- // 3: the strategy media is active on the hardware output:
+ // 4: the strategy media is active on the output:
// use device for strategy media
- // 4: the strategy DTMF is active on the hardware output:
+ // 5: the strategy DTMF is active on the output:
// use device for strategy DTMF
- if (isInCall() ||
- outputDesc->isUsedByStrategy(STRATEGY_PHONE)) {
+ if (outputDesc->isUsedByStrategy(STRATEGY_ENFORCED_AUDIBLE)) {
+ device = getDeviceForStrategy(STRATEGY_ENFORCED_AUDIBLE, fromCache);
+ } else if (isInCall() ||
+ outputDesc->isUsedByStrategy(STRATEGY_PHONE)) {
device = getDeviceForStrategy(STRATEGY_PHONE, fromCache);
} else if (outputDesc->isUsedByStrategy(STRATEGY_SONIFICATION)) {
device = getDeviceForStrategy(STRATEGY_SONIFICATION, fromCache);
@@ -1567,7 +1652,7 @@ uint32_t AudioPolicyManagerBase::getNewDevice(audio_io_handle_t output, bool fro
device = getDeviceForStrategy(STRATEGY_DTMF, fromCache);
}
- LOGV("getNewDevice() selected device %x", device);
+ ALOGV("getNewDevice() selected device %x", device);
return device;
}
@@ -1575,13 +1660,13 @@ uint32_t AudioPolicyManagerBase::getStrategyForStream(AudioSystem::stream_type s
return (uint32_t)getStrategy(stream);
}
-uint32_t AudioPolicyManagerBase::getDevicesForStream(AudioSystem::stream_type stream) {
- uint32_t devices;
+audio_devices_t AudioPolicyManagerBase::getDevicesForStream(AudioSystem::stream_type stream) {
+ audio_devices_t devices;
// By checking the range of stream before calling getStrategy, we avoid
- // getStrategy's behavior for invalid streams. getStrategy would do a LOGE
+ // getStrategy's behavior for invalid streams. getStrategy would do a ALOGE
// and then return STRATEGY_MEDIA, but we want to return the empty set.
if (stream < (AudioSystem::stream_type) 0 || stream >= AudioSystem::NUM_STREAM_TYPES) {
- devices = 0;
+ devices = (audio_devices_t)0;
} else {
AudioPolicyManagerBase::routing_strategy strategy = getStrategy(stream);
devices = getDeviceForStrategy(strategy, true);
@@ -1599,27 +1684,28 @@ AudioPolicyManagerBase::routing_strategy AudioPolicyManagerBase::getStrategy(
case AudioSystem::RING:
case AudioSystem::NOTIFICATION:
case AudioSystem::ALARM:
- case AudioSystem::ENFORCED_AUDIBLE:
return STRATEGY_SONIFICATION;
case AudioSystem::DTMF:
return STRATEGY_DTMF;
default:
- LOGE("unknown stream type");
+ ALOGE("unknown stream type");
case AudioSystem::SYSTEM:
// NOTE: SYSTEM stream uses MEDIA strategy because muting music and switching outputs
// while key clicks are played produces a poor result
case AudioSystem::TTS:
case AudioSystem::MUSIC:
return STRATEGY_MEDIA;
+ case AudioSystem::ENFORCED_AUDIBLE:
+ return STRATEGY_ENFORCED_AUDIBLE;
}
}
-uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy, bool fromCache)
+audio_devices_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy, bool fromCache)
{
uint32_t device = 0;
if (fromCache) {
- LOGV("getDeviceForStrategy() from cache strategy %d, device %x", strategy, mDeviceForStrategy[strategy]);
+ ALOGV("getDeviceForStrategy() from cache strategy %d, device %x", strategy, mDeviceForStrategy[strategy]);
return mDeviceForStrategy[strategy];
}
@@ -1654,15 +1740,13 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
if (device) break;
-#ifdef WITH_A2DP
// when not in a phone call, phone strategy should route STREAM_VOICE_CALL to A2DP
- if (!isInCall() && !mA2dpSuspended) {
+ if (sHasA2dp && !isInCall() && !mA2dpSuspended) {
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP;
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES;
if (device) break;
}
-#endif
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_AUX_DIGITAL;
@@ -1671,19 +1755,17 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_EARPIECE;
if (device == 0) {
- LOGE("getDeviceForStrategy() earpiece device not found");
+ ALOGE("getDeviceForStrategy() earpiece device not found");
}
break;
case AudioSystem::FORCE_SPEAKER:
-#ifdef WITH_A2DP
// when not in a phone call, phone strategy should route STREAM_VOICE_CALL to
// A2DP speaker when forcing to speaker output
- if (!isInCall() && !mA2dpSuspended) {
+ if (sHasA2dp && !isInCall() && !mA2dpSuspended) {
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
if (device) break;
}
-#endif
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_AUX_DIGITAL;
@@ -1692,7 +1774,7 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device) break;
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
if (device == 0) {
- LOGE("getDeviceForStrategy() speaker device not found");
+ ALOGE("getDeviceForStrategy() speaker device not found");
}
break;
}
@@ -1706,9 +1788,15 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
device = getDeviceForStrategy(STRATEGY_PHONE, false);
break;
}
+ // FALL THROUGH
+
+ case STRATEGY_ENFORCED_AUDIBLE:
+ // strategy STRATEGY_ENFORCED_AUDIBLE uses same routing policy as STRATEGY_SONIFICATION
+ // except when in call where it doesn't default to STRATEGY_PHONE behavior
+
device = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
if (device == 0) {
- LOGE("getDeviceForStrategy() speaker device not found");
+ ALOGE("getDeviceForStrategy() speaker device not found");
}
// The second device used for sonification is the same as the device used by media strategy
// FALL THROUGH
@@ -1718,9 +1806,7 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
if (device2 == 0) {
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_WIRED_HEADSET;
}
-#ifdef WITH_A2DP
- if ((mA2dpOutput != 0) && !mA2dpSuspended &&
- (strategy != STRATEGY_SONIFICATION || a2dpUsedForSonification())) {
+ if (sHasA2dp && (getA2dpOutput() != 0) && !mA2dpSuspended) {
if (device2 == 0) {
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP;
}
@@ -1731,7 +1817,6 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER;
}
}
-#endif
if (device2 == 0) {
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET;
}
@@ -1745,20 +1830,21 @@ uint32_t AudioPolicyManagerBase::getDeviceForStrategy(routing_strategy strategy,
device2 = mAvailableOutputDevices & AudioSystem::DEVICE_OUT_SPEAKER;
}
- // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION, 0 otherwise
+ // device is DEVICE_OUT_SPEAKER if we come from case STRATEGY_SONIFICATION or
+ // STRATEGY_ENFORCED_AUDIBLE, 0 otherwise
device |= device2;
if (device == 0) {
- LOGE("getDeviceForStrategy() speaker device not found");
+ ALOGE("getDeviceForStrategy() speaker device not found");
}
} break;
default:
- LOGW("getDeviceForStrategy() unknown strategy: %d", strategy);
+ ALOGW("getDeviceForStrategy() unknown strategy: %d", strategy);
break;
}
- LOGV("getDeviceForStrategy() strategy %d, device %x", strategy, device);
- return device;
+ ALOGV("getDeviceForStrategy() strategy %d, device %x", strategy, device);
+ return (audio_devices_t)device;
}
void AudioPolicyManagerBase::updateDeviceForStrategy()
@@ -1768,9 +1854,12 @@ void AudioPolicyManagerBase::updateDeviceForStrategy()
}
}
-void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t device, bool force, int delayMs)
+void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output,
+ audio_devices_t device,
+ bool force,
+ int delayMs)
{
- LOGV("setOutputDevice() output %d device %x delayMs %d", output, device, delayMs);
+ ALOGV("setOutputDevice() output %d device %x delayMs %d", output, device, delayMs);
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
@@ -1779,28 +1868,22 @@ void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t
setOutputDevice(outputDesc->mOutput2->mId, device, force, delayMs);
return;
}
-#ifdef WITH_A2DP
// filter devices according to output selected
- if (output == mA2dpOutput) {
- device &= AudioSystem::DEVICE_OUT_ALL_A2DP;
- } else {
- device &= ~AudioSystem::DEVICE_OUT_ALL_A2DP;
- }
-#endif
+ device = (audio_devices_t)(device & outputDesc->mProfile->mSupportedDevices);
- uint32_t prevDevice = (uint32_t)outputDesc->device();
+ audio_devices_t prevDevice = outputDesc->device();
// Do not change the routing if:
// - the requestede device is 0
// - the requested device is the same as current device and force is not specified.
// Doing this check here allows the caller to call setOutputDevice() without conditions
if ((device == 0 || device == prevDevice) && !force) {
- LOGV("setOutputDevice() setting same device %x or null device for output %d", device, output);
+ ALOGV("setOutputDevice() setting same device %x or null device for output %d", device, output);
return;
}
outputDesc->mDevice = device;
// mute media streams if both speaker and headset are selected
- if (output == mHardwareOutput && AudioSystem::popCount(device) == 2) {
+ if (output == mPrimaryOutput && AudioSystem::popCount(device) == 2) {
setStrategyMute(STRATEGY_MEDIA, true, output);
// wait for the PCM output buffers to empty before proceeding with the rest of the command
// FIXME: increased delay due to larger buffers used for low power audio mode.
@@ -1811,17 +1894,17 @@ void AudioPolicyManagerBase::setOutputDevice(audio_io_handle_t output, uint32_t
// do the routing
AudioParameter param = AudioParameter();
param.addInt(String8(AudioParameter::keyRouting), (int)device);
- mpClientInterface->setParameters(mHardwareOutput, param.toString(), delayMs);
+ mpClientInterface->setParameters(mPrimaryOutput, param.toString(), delayMs);
// update stream volumes according to new device
applyStreamVolumes(output, device, delayMs);
// if changing from a combined headset + speaker route, unmute media streams
- if (output == mHardwareOutput && AudioSystem::popCount(prevDevice) == 2) {
+ if (output == mPrimaryOutput && AudioSystem::popCount((uint32_t)prevDevice) == 2) {
setStrategyMute(STRATEGY_MEDIA, false, output, delayMs);
}
}
-uint32_t AudioPolicyManagerBase::getDeviceForInputSource(int inputSource)
+audio_devices_t AudioPolicyManagerBase::getDeviceForInputSource(int inputSource)
{
uint32_t device;
@@ -1852,12 +1935,12 @@ uint32_t AudioPolicyManagerBase::getDeviceForInputSource(int inputSource)
device = AudioSystem::DEVICE_IN_VOICE_CALL;
break;
default:
- LOGW("getDeviceForInputSource() invalid input source %d", inputSource);
+ ALOGW("getDeviceForInputSource() invalid input source %d", inputSource);
device = 0;
break;
}
- LOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device);
- return device;
+ ALOGV("getDeviceForInputSource()input source %d, device %08x", inputSource, device);
+ return (audio_devices_t)device;
}
audio_io_handle_t AudioPolicyManagerBase::getActiveInput()
@@ -1871,31 +1954,35 @@ audio_io_handle_t AudioPolicyManagerBase::getActiveInput()
}
-AudioPolicyManagerBase::device_category AudioPolicyManagerBase::getDeviceCategory(uint32_t device)
+audio_devices_t AudioPolicyManagerBase::getDeviceForVolume(audio_devices_t device)
{
if (device == 0) {
// this happens when forcing a route update and no track is active on an output.
// In this case the returned category is not important.
- return DEVICE_CATEGORY_SPEAKER;
- }
-
- if (AudioSystem::popCount(device) > 1) {
+ device = AUDIO_DEVICE_OUT_SPEAKER;
+ } else if (AudioSystem::popCount(device) > 1) {
// Multiple device selection is either:
// - speaker + one other device: give priority to speaker in this case.
// - one A2DP device + another device: happens with duplicated output. In this case
// retain the device on the A2DP output as the other must not correspond to an active
// selection if not the speaker.
- if (device & AUDIO_DEVICE_OUT_SPEAKER)
- return DEVICE_CATEGORY_SPEAKER;
-
- device &= AUDIO_DEVICE_OUT_ALL_A2DP;
+ if (device & AUDIO_DEVICE_OUT_SPEAKER) {
+ device = AUDIO_DEVICE_OUT_SPEAKER;
+ } else {
+ device = (audio_devices_t)(device & AUDIO_DEVICE_OUT_ALL_A2DP);
+ }
}
- LOGW_IF(AudioSystem::popCount(device) != 1,
- "getDeviceCategory() invalid device combination: %08x",
+ ALOGW_IF(AudioSystem::popCount(device) != 1,
+ "getDeviceForVolume() invalid device combination: %08x",
device);
- switch(device) {
+ return device;
+}
+
+AudioPolicyManagerBase::device_category AudioPolicyManagerBase::getDeviceCategory(audio_devices_t device)
+{
+ switch(getDeviceForVolume(device)) {
case AUDIO_DEVICE_OUT_EARPIECE:
return DEVICE_CATEGORY_EARPIECE;
case AUDIO_DEVICE_OUT_WIRED_HEADSET:
@@ -1908,12 +1995,13 @@ AudioPolicyManagerBase::device_category AudioPolicyManagerBase::getDeviceCategor
case AUDIO_DEVICE_OUT_SPEAKER:
case AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT:
case AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER:
+ case AUDIO_DEVICE_OUT_AUX_DIGITAL:
default:
return DEVICE_CATEGORY_SPEAKER;
}
}
-float AudioPolicyManagerBase::volIndexToAmpl(uint32_t device, const StreamDescriptor& streamDesc,
+float AudioPolicyManagerBase::volIndexToAmpl(audio_devices_t device, const StreamDescriptor& streamDesc,
int indexInUi)
{
device_category deviceCategory = getDeviceCategory(device);
@@ -1949,7 +2037,7 @@ float AudioPolicyManagerBase::volIndexToAmpl(uint32_t device, const StreamDescri
float amplification = exp( decibels * 0.115129f); // exp( dB * ln(10) / 20 )
- LOGV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f",
+ ALOGV("VOLUME vol index=[%d %d %d], dB=[%.1f %.1f %.1f] ampl=%.5f",
curve[segment].mIndex, volIdx,
curve[segment+1].mIndex,
curve[segment].mDBAttenuation,
@@ -2003,7 +2091,12 @@ const AudioPolicyManagerBase::VolumeCurvePoint
sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
sDefaultVolumeCurve, // DEVICE_CATEGORY_SPEAKER
sDefaultVolumeCurve // DEVICE_CATEGORY_EARPIECE
- }
+ },
+ { // STRATEGY_ENFORCED_AUDIBLE
+ sDefaultVolumeCurve, // DEVICE_CATEGORY_HEADSET
+ sSpeakerSonificationVolumeCurve, // DEVICE_CATEGORY_SPEAKER
+ sDefaultVolumeCurve // DEVICE_CATEGORY_EARPIECE
+ },
};
void AudioPolicyManagerBase::initializeVolumeCurves()
@@ -2016,7 +2109,10 @@ void AudioPolicyManagerBase::initializeVolumeCurves()
}
}
-float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_handle_t output, uint32_t device)
+float AudioPolicyManagerBase::computeVolume(int stream,
+ int index,
+ audio_io_handle_t output,
+ audio_devices_t device)
{
float volume = 1.0;
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
@@ -2029,8 +2125,8 @@ float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_hand
// if volume is not 0 (not muted), force media volume to max on digital output
if (stream == AudioSystem::MUSIC &&
index != mStreams[stream].mIndexMin &&
- (device == AudioSystem::DEVICE_OUT_AUX_DIGITAL ||
- device == AudioSystem::DEVICE_OUT_DGTL_DOCK_HEADSET)) {
+ (device == AUDIO_DEVICE_OUT_AUX_DIGITAL ||
+ device == AUDIO_DEVICE_OUT_DGTL_DOCK_HEADSET)) {
return 1.0;
}
@@ -2054,11 +2150,15 @@ float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_hand
// by the music application and behave as if music was active if the last music track was
// just stopped
if (outputDesc->mRefCount[AudioSystem::MUSIC] || mLimitRingtoneVolume) {
- float musicVol = computeVolume(AudioSystem::MUSIC, mStreams[AudioSystem::MUSIC].mIndexCur, output, device);
- float minVol = (musicVol > SONIFICATION_HEADSET_VOLUME_MIN) ? musicVol : SONIFICATION_HEADSET_VOLUME_MIN;
+ float musicVol = computeVolume(AudioSystem::MUSIC,
+ mStreams[AudioSystem::MUSIC].getVolumeIndex(device),
+ output,
+ device);
+ float minVol = (musicVol > SONIFICATION_HEADSET_VOLUME_MIN) ?
+ musicVol : SONIFICATION_HEADSET_VOLUME_MIN;
if (volume > minVol) {
volume = minVol;
- LOGV("computeVolume limiting volume to %f musicVol %f", minVol, musicVol);
+ ALOGV("computeVolume limiting volume to %f musicVol %f", minVol, musicVol);
}
}
}
@@ -2066,19 +2166,24 @@ float AudioPolicyManagerBase::computeVolume(int stream, int index, audio_io_hand
return volume;
}
-status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_io_handle_t output, uint32_t device, int delayMs, bool force)
+status_t AudioPolicyManagerBase::checkAndSetVolume(int stream,
+ int index,
+ audio_io_handle_t output,
+ audio_devices_t device,
+ int delayMs,
+ bool force)
{
// do not change actual stream volume if the stream is muted
if (mOutputs.valueFor(output)->mMuteCount[stream] != 0) {
- LOGV("checkAndSetVolume() stream %d muted count %d", stream, mOutputs.valueFor(output)->mMuteCount[stream]);
+ ALOGV("checkAndSetVolume() stream %d muted count %d", stream, mOutputs.valueFor(output)->mMuteCount[stream]);
return NO_ERROR;
}
// do not change in call volume if bluetooth is connected and vice versa
if ((stream == AudioSystem::VOICE_CALL && mForceUse[AudioSystem::FOR_COMMUNICATION] == AudioSystem::FORCE_BT_SCO) ||
(stream == AudioSystem::BLUETOOTH_SCO && mForceUse[AudioSystem::FOR_COMMUNICATION] != AudioSystem::FORCE_BT_SCO)) {
- LOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
+ ALOGV("checkAndSetVolume() cannot set stream %d volume with force use = %d for comm",
stream, mForceUse[AudioSystem::FOR_COMMUNICATION]);
return INVALID_OPERATION;
}
@@ -2090,7 +2195,7 @@ status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_
if (volume != mOutputs.valueFor(output)->mCurVolume[stream] ||
force) {
mOutputs.valueFor(output)->mCurVolume[stream] = volume;
- LOGV("setStreamVolume() for output %d stream %d, volume %f, delay %d", output, stream, volume, delayMs);
+ ALOGV("setStreamVolume() for output %d stream %d, volume %f, delay %d", output, stream, volume, delayMs);
if (stream == AudioSystem::VOICE_CALL ||
stream == AudioSystem::DTMF ||
stream == AudioSystem::BLUETOOTH_SCO) {
@@ -2117,7 +2222,7 @@ status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_
voiceVolume = 1.0;
}
- if (voiceVolume != mLastVoiceVolume && output == mHardwareOutput) {
+ if (voiceVolume != mLastVoiceVolume && output == mPrimaryOutput) {
mpClientInterface->setVoiceVolume(voiceVolume, delayMs);
mLastVoiceVolume = voiceVolume;
}
@@ -2126,18 +2231,26 @@ status_t AudioPolicyManagerBase::checkAndSetVolume(int stream, int index, audio_
return NO_ERROR;
}
-void AudioPolicyManagerBase::applyStreamVolumes(audio_io_handle_t output, uint32_t device, int delayMs, bool force)
+void AudioPolicyManagerBase::applyStreamVolumes(audio_io_handle_t output,
+ audio_devices_t device,
+ int delayMs,
+ bool force)
{
- LOGV("applyStreamVolumes() for output %d and device %x", output, device);
+ ALOGV("applyStreamVolumes() for output %d and device %x", output, device);
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
- checkAndSetVolume(stream, mStreams[stream].mIndexCur, output, device, delayMs, force);
+ checkAndSetVolume(stream,
+ mStreams[stream].getVolumeIndex(device),
+ output,
+ device,
+ delayMs,
+ force);
}
}
void AudioPolicyManagerBase::setStrategyMute(routing_strategy strategy, bool on, audio_io_handle_t output, int delayMs)
{
- LOGV("setStrategyMute() strategy %d, mute %d, output %d", strategy, on, output);
+ ALOGV("setStrategyMute() strategy %d, mute %d, output %d", strategy, on, output);
for (int stream = 0; stream < AudioSystem::NUM_STREAM_TYPES; stream++) {
if (getStrategy((AudioSystem::stream_type)stream) == strategy) {
setStreamMute(stream, on, output, delayMs);
@@ -2149,24 +2262,29 @@ void AudioPolicyManagerBase::setStreamMute(int stream, bool on, audio_io_handle_
{
StreamDescriptor &streamDesc = mStreams[stream];
AudioOutputDescriptor *outputDesc = mOutputs.valueFor(output);
+ audio_devices_t device = outputDesc->device();
- LOGV("setStreamMute() stream %d, mute %d, output %d, mMuteCount %d", stream, on, output, outputDesc->mMuteCount[stream]);
+ ALOGV("setStreamMute() stream %d, mute %d, output %d, mMuteCount %d", stream, on, output, outputDesc->mMuteCount[stream]);
if (on) {
if (outputDesc->mMuteCount[stream] == 0) {
if (streamDesc.mCanBeMuted) {
- checkAndSetVolume(stream, 0, output, outputDesc->device(), delayMs);
+ checkAndSetVolume(stream, 0, output, device, delayMs);
}
}
// increment mMuteCount after calling checkAndSetVolume() so that volume change is not ignored
outputDesc->mMuteCount[stream]++;
} else {
if (outputDesc->mMuteCount[stream] == 0) {
- LOGW("setStreamMute() unmuting non muted stream!");
+ ALOGW("setStreamMute() unmuting non muted stream!");
return;
}
if (--outputDesc->mMuteCount[stream] == 0) {
- checkAndSetVolume(stream, streamDesc.mIndexCur, output, outputDesc->device(), delayMs);
+ checkAndSetVolume(stream,
+ streamDesc.getVolumeIndex((audio_devices_t)device),
+ output,
+ device,
+ delayMs);
}
}
}
@@ -2181,8 +2299,8 @@ void AudioPolicyManagerBase::handleIncallSonification(int stream, bool starting,
// many times as there are active tracks on the output
if (getStrategy((AudioSystem::stream_type)stream) == STRATEGY_SONIFICATION) {
- AudioOutputDescriptor *outputDesc = mOutputs.valueFor(mHardwareOutput);
- LOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
+ AudioOutputDescriptor *outputDesc = mOutputs.valueFor(mPrimaryOutput);
+ ALOGV("handleIncallSonification() stream %d starting %d device %x stateChange %d",
stream, starting, outputDesc->mDevice, stateChange);
if (outputDesc->mRefCount[stream]) {
int muteCount = 1;
@@ -2190,16 +2308,16 @@ void AudioPolicyManagerBase::handleIncallSonification(int stream, bool starting,
muteCount = outputDesc->mRefCount[stream];
}
if (AudioSystem::isLowVisibility((AudioSystem::stream_type)stream)) {
- LOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
+ ALOGV("handleIncallSonification() low visibility, muteCount %d", muteCount);
for (int i = 0; i < muteCount; i++) {
- setStreamMute(stream, starting, mHardwareOutput);
+ setStreamMute(stream, starting, mPrimaryOutput);
}
} else {
- LOGV("handleIncallSonification() high visibility");
+ ALOGV("handleIncallSonification() high visibility");
if (outputDesc->device() & getDeviceForStrategy(STRATEGY_PHONE)) {
- LOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
+ ALOGV("handleIncallSonification() high visibility muted, muteCount %d", muteCount);
for (int i = 0; i < muteCount; i++) {
- setStreamMute(stream, starting, mHardwareOutput);
+ setStreamMute(stream, starting, mPrimaryOutput);
}
}
if (starting) {
@@ -2230,7 +2348,7 @@ bool AudioPolicyManagerBase::needsDirectOuput(AudioSystem::stream_type stream,
uint32_t device)
{
return ((flags & AudioSystem::OUTPUT_FLAG_DIRECT) ||
- (format !=0 && !AudioSystem::isLinearPCM(format)));
+ (format != 0 && !AudioSystem::isLinearPCM(format)));
}
uint32_t AudioPolicyManagerBase::getMaxEffectsCpuLoad()
@@ -2245,9 +2363,11 @@ uint32_t AudioPolicyManagerBase::getMaxEffectsMemory()
// --- AudioOutputDescriptor class implementation
-AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor()
+AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor(
+ const output_profile_t *profile)
: mId(0), mSamplingRate(0), mFormat(0), mChannels(0), mLatency(0),
- mFlags((AudioSystem::output_flags)0), mDevice(0), mOutput1(0), mOutput2(0)
+ mFlags((AudioSystem::output_flags)0), mDevice((audio_devices_t)0),
+ mOutput1(0), mOutput2(0), mProfile(profile)
{
// clear usage count for all stream types
for (int i = 0; i < AudioSystem::NUM_STREAM_TYPES; i++) {
@@ -2258,15 +2378,13 @@ AudioPolicyManagerBase::AudioOutputDescriptor::AudioOutputDescriptor()
}
}
-uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::device()
+audio_devices_t AudioPolicyManagerBase::AudioOutputDescriptor::device()
{
- uint32_t device = 0;
if (isDuplicated()) {
- device = mOutput1->mDevice | mOutput2->mDevice;
+ return (audio_devices_t)(mOutput1->mDevice | mOutput2->mDevice);
} else {
- device = mDevice;
+ return mDevice;
}
- return device;
}
void AudioPolicyManagerBase::AudioOutputDescriptor::changeRefCount(AudioSystem::stream_type stream, int delta)
@@ -2277,12 +2395,12 @@ void AudioPolicyManagerBase::AudioOutputDescriptor::changeRefCount(AudioSystem::
mOutput2->changeRefCount(stream, delta);
}
if ((delta + (int)mRefCount[stream]) < 0) {
- LOGW("changeRefCount() invalid delta %d for stream %d, refCount %d", delta, stream, mRefCount[stream]);
+ ALOGW("changeRefCount() invalid delta %d for stream %d, refCount %d", delta, stream, mRefCount[stream]);
mRefCount[stream] = 0;
return;
}
mRefCount[stream] += delta;
- LOGV("changeRefCount() stream %d, count %d", stream, mRefCount[stream]);
+ ALOGV("changeRefCount() stream %d, count %d", stream, mRefCount[stream]);
}
uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::refCount()
@@ -2305,6 +2423,15 @@ uint32_t AudioPolicyManagerBase::AudioOutputDescriptor::strategyRefCount(routing
return refCount;
}
+audio_devices_t AudioPolicyManagerBase::AudioOutputDescriptor::supportedDevices()
+{
+ if (isDuplicated()) {
+ return (audio_devices_t)(mOutput1->supportedDevices() | mOutput2->supportedDevices());
+ } else {
+ return mProfile->mSupportedDevices ;
+ }
+}
+
status_t AudioPolicyManagerBase::AudioOutputDescriptor::dump(int fd)
{
const size_t SIZE = 256;
@@ -2338,7 +2465,7 @@ status_t AudioPolicyManagerBase::AudioOutputDescriptor::dump(int fd)
AudioPolicyManagerBase::AudioInputDescriptor::AudioInputDescriptor()
: mSamplingRate(0), mFormat(0), mChannels(0),
- mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice(0), mRefCount(0),
+ mAcoustics((AudioSystem::audio_in_acoustics)0), mDevice((audio_devices_t)0), mRefCount(0),
mInputSource(0)
{
}
@@ -2368,13 +2495,40 @@ status_t AudioPolicyManagerBase::AudioInputDescriptor::dump(int fd)
// --- StreamDescriptor class implementation
-void AudioPolicyManagerBase::StreamDescriptor::dump(char* buffer, size_t size)
+AudioPolicyManagerBase::StreamDescriptor::StreamDescriptor()
+ : mIndexMin(0), mIndexMax(1), mCanBeMuted(true)
+{
+ mIndexCur.add(AUDIO_DEVICE_OUT_DEFAULT, 0);
+}
+
+int AudioPolicyManagerBase::StreamDescriptor::getVolumeIndex(audio_devices_t device)
+{
+ device = AudioPolicyManagerBase::getDeviceForVolume(device);
+ // there is always a valid entry for AUDIO_DEVICE_OUT_DEFAULT
+ if (mIndexCur.indexOfKey(device) < 0) {
+ device = AUDIO_DEVICE_OUT_DEFAULT;
+ }
+ return mIndexCur.valueFor(device);
+}
+
+void AudioPolicyManagerBase::StreamDescriptor::dump(int fd)
{
- snprintf(buffer, size, " %02d %02d %02d %d\n",
- mIndexMin,
- mIndexMax,
- mIndexCur,
- mCanBeMuted);
+ const size_t SIZE = 256;
+ char buffer[SIZE];
+ String8 result;
+
+ snprintf(buffer, SIZE, "%s %02d %02d ",
+ mCanBeMuted ? "true " : "false", mIndexMin, mIndexMax);
+ result.append(buffer);
+ for (size_t i = 0; i < mIndexCur.size(); i++) {
+ snprintf(buffer, SIZE, "%04x : %02d, ",
+ mIndexCur.keyAt(i),
+ mIndexCur.valueAt(i));
+ result.append(buffer);
+ }
+ result.append("\n");
+
+ write(fd, result.string(), result.size());
}
// --- EffectDescriptor class implementation
diff --git a/audio/AudioPolicyManagerDefault.h b/audio/AudioPolicyManagerDefault.h
index b2b2576..96dfee1 100644
--- a/audio/AudioPolicyManagerDefault.h
+++ b/audio/AudioPolicyManagerDefault.h
@@ -34,10 +34,6 @@ public:
protected:
// true is current platform implements a back microphone
virtual bool hasBackMicrophone() const { return false; }
-#ifdef WITH_A2DP
- // true is current platform supports suplication of notifications and ringtones over A2DP output
- virtual bool a2dpUsedForSonification() const { return true; }
-#endif
};
};
diff --git a/audio/audio_hw_hal.cpp b/audio/audio_hw_hal.cpp
index f249f88..dd66f76 100644
--- a/audio/audio_hw_hal.cpp
+++ b/audio/audio_hw_hal.cpp
@@ -65,7 +65,7 @@ static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
struct legacy_stream_out *out =
reinterpret_cast<struct legacy_stream_out *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement this */
return 0;
}
@@ -84,18 +84,19 @@ static uint32_t out_get_channels(const struct audio_stream *stream)
return out->legacy_out->channels();
}
-static int out_get_format(const struct audio_stream *stream)
+static audio_format_t out_get_format(const struct audio_stream *stream)
{
const struct legacy_stream_out *out =
reinterpret_cast<const struct legacy_stream_out *>(stream);
- return out->legacy_out->format();
+ // legacy API, don't change return type
+ return (audio_format_t) out->legacy_out->format();
}
-static int out_set_format(struct audio_stream *stream, int format)
+static int out_set_format(struct audio_stream *stream, audio_format_t format)
{
struct legacy_stream_out *out =
reinterpret_cast<struct legacy_stream_out *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement me */
return 0;
}
@@ -185,7 +186,7 @@ static int in_set_sample_rate(struct audio_stream *stream, uint32_t rate)
struct legacy_stream_in *in =
reinterpret_cast<struct legacy_stream_in *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement this */
return 0;
}
@@ -204,18 +205,19 @@ static uint32_t in_get_channels(const struct audio_stream *stream)
return in->legacy_in->channels();
}
-static int in_get_format(const struct audio_stream *stream)
+static audio_format_t in_get_format(const struct audio_stream *stream)
{
const struct legacy_stream_in *in =
reinterpret_cast<const struct legacy_stream_in *>(stream);
- return in->legacy_in->format();
+ // legacy API, don't change return type
+ return (audio_format_t) in->legacy_in->format();
}
-static int in_set_format(struct audio_stream *stream, int format)
+static int in_set_format(struct audio_stream *stream, audio_format_t format)
{
struct legacy_stream_in *in =
reinterpret_cast<struct legacy_stream_in *>(stream);
- LOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
+ ALOGE("(%s:%d) %s: Implement me!", __FILE__, __LINE__, __func__);
/* TODO: implement me */
return 0;
}
@@ -352,10 +354,11 @@ static int adev_get_master_volume(struct audio_hw_device *dev, float* volume)
return ladev->hwif->getMasterVolume(volume);
}
-static int adev_set_mode(struct audio_hw_device *dev, int mode)
+static int adev_set_mode(struct audio_hw_device *dev, audio_mode_t mode)
{
struct legacy_audio_device *ladev = to_ladev(dev);
- return ladev->hwif->setMode(mode);
+ // as this is the legacy API, don't change it to use audio_mode_t instead of int
+ return ladev->hwif->setMode((int) mode);
}
static int adev_set_mic_mute(struct audio_hw_device *dev, bool state)
@@ -387,16 +390,16 @@ static char * adev_get_parameters(const struct audio_hw_device *dev,
}
static size_t adev_get_input_buffer_size(const struct audio_hw_device *dev,
- uint32_t sample_rate, int format,
+ uint32_t sample_rate, audio_format_t format,
int channel_count)
{
const struct legacy_audio_device *ladev = to_cladev(dev);
- return ladev->hwif->getInputBufferSize(sample_rate, format, channel_count);
+ return ladev->hwif->getInputBufferSize(sample_rate, (int) format, channel_count);
}
static int adev_open_output_stream(struct audio_hw_device *dev,
uint32_t devices,
- int *format,
+ audio_format_t *format,
uint32_t *channels,
uint32_t *sample_rate,
struct audio_stream_out **stream_out)
@@ -410,7 +413,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
if (!out)
return -ENOMEM;
- out->legacy_out = ladev->hwif->openOutputStream(devices, format, channels,
+ out->legacy_out = ladev->hwif->openOutputStream(devices, (int *) format, channels,
sample_rate, &status);
if (!out->legacy_out) {
ret = status;
@@ -455,7 +458,7 @@ static void adev_close_output_stream(struct audio_hw_device *dev,
/** This method creates and opens the audio hardware input stream */
static int adev_open_input_stream(struct audio_hw_device *dev,
- uint32_t devices, int *format,
+ uint32_t devices, audio_format_t *format,
uint32_t *channels, uint32_t *sample_rate,
audio_in_acoustics_t acoustics,
struct audio_stream_in **stream_in)
@@ -469,7 +472,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
if (!in)
return -ENOMEM;
- in->legacy_in = ladev->hwif->openInputStream(devices, format, channels,
+ in->legacy_in = ladev->hwif->openInputStream(devices, (int *) format, channels,
sample_rate, &status,
(AudioSystem::audio_in_acoustics)acoustics);
if (!in->legacy_in) {
diff --git a/audio/audio_policy_hal.cpp b/audio/audio_policy_hal.cpp
index d5f2816..9a71d2f 100644
--- a/audio/audio_policy_hal.cpp
+++ b/audio/audio_policy_hal.cpp
@@ -84,18 +84,18 @@ static audio_policy_dev_state_t ap_get_device_connection_state(
device_address);
}
-static void ap_set_phone_state(struct audio_policy *pol, int state)
+static void ap_set_phone_state(struct audio_policy *pol, audio_mode_t state)
{
struct legacy_audio_policy *lap = to_lap(pol);
- lap->apm->setPhoneState(state);
+ // as this is the legacy API, don't change it to use audio_mode_t instead of int
+ lap->apm->setPhoneState((int) state);
}
/* indicate a change in ringer mode */
static void ap_set_ringer_mode(struct audio_policy *pol, uint32_t mode,
uint32_t mask)
{
- struct legacy_audio_policy *lap = to_lap(pol);
- lap->apm->setRingerMode(mode, mask);
+ // deprecated, never called
}
/* force using a specific device category for the specified usage */
@@ -136,15 +136,15 @@ static int ap_init_check(const struct audio_policy *pol)
static audio_io_handle_t ap_get_output(struct audio_policy *pol,
audio_stream_type_t stream,
uint32_t sampling_rate,
- uint32_t format,
+ audio_format_t format,
uint32_t channels,
audio_policy_output_flags_t flags)
{
struct legacy_audio_policy *lap = to_lap(pol);
- LOGV("%s: tid %d", __func__, gettid());
+ ALOGV("%s: tid %d", __func__, gettid());
return lap->apm->getOutput((AudioSystem::stream_type)stream,
- sampling_rate, format, channels,
+ sampling_rate, (int) format, channels,
(AudioSystem::output_flags)flags);
}
@@ -171,14 +171,14 @@ static void ap_release_output(struct audio_policy *pol,
lap->apm->releaseOutput(output);
}
-static audio_io_handle_t ap_get_input(struct audio_policy *pol, int inputSource,
+static audio_io_handle_t ap_get_input(struct audio_policy *pol, audio_source_t inputSource,
uint32_t sampling_rate,
- uint32_t format,
+ audio_format_t format,
uint32_t channels,
audio_in_acoustics_t acoustics)
{
struct legacy_audio_policy *lap = to_lap(pol);
- return lap->apm->getInput(inputSource, sampling_rate, format, channels,
+ return lap->apm->getInput((int) inputSource, sampling_rate, (int) format, channels,
(AudioSystem::audio_in_acoustics)acoustics);
}
@@ -215,7 +215,8 @@ static int ap_set_stream_volume_index(struct audio_policy *pol,
{
struct legacy_audio_policy *lap = to_lap(pol);
return lap->apm->setStreamVolumeIndex((AudioSystem::stream_type)stream,
- index);
+ index,
+ AUDIO_DEVICE_OUT_DEFAULT);
}
static int ap_get_stream_volume_index(const struct audio_policy *pol,
@@ -224,7 +225,30 @@ static int ap_get_stream_volume_index(const struct audio_policy *pol,
{
const struct legacy_audio_policy *lap = to_clap(pol);
return lap->apm->getStreamVolumeIndex((AudioSystem::stream_type)stream,
- index);
+ index,
+ AUDIO_DEVICE_OUT_DEFAULT);
+}
+
+static int ap_set_stream_volume_index_for_device(struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int index,
+ audio_devices_t device)
+{
+ struct legacy_audio_policy *lap = to_lap(pol);
+ return lap->apm->setStreamVolumeIndex((AudioSystem::stream_type)stream,
+ index,
+ device);
+}
+
+static int ap_get_stream_volume_index_for_device(const struct audio_policy *pol,
+ audio_stream_type_t stream,
+ int *index,
+ audio_devices_t device)
+{
+ const struct legacy_audio_policy *lap = to_clap(pol);
+ return lap->apm->getStreamVolumeIndex((AudioSystem::stream_type)stream,
+ index,
+ device);
}
static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
@@ -234,7 +258,7 @@ static uint32_t ap_get_strategy_for_stream(const struct audio_policy *pol,
return lap->apm->getStrategyForStream((AudioSystem::stream_type)stream);
}
-static uint32_t ap_get_devices_for_stream(const struct audio_policy *pol,
+static audio_devices_t ap_get_devices_for_stream(const struct audio_policy *pol,
audio_stream_type_t stream)
{
const struct legacy_audio_policy *lap = to_clap(pol);
@@ -271,11 +295,11 @@ static int ap_set_effect_enabled(struct audio_policy *pol, int id, bool enabled)
return lap->apm->setEffectEnabled(id, enabled);
}
-static bool ap_is_stream_active(const struct audio_policy *pol, int stream,
+static bool ap_is_stream_active(const struct audio_policy *pol, audio_stream_type_t stream,
uint32_t in_past_ms)
{
const struct legacy_audio_policy *lap = to_clap(pol);
- return lap->apm->isStreamActive(stream, in_past_ms);
+ return lap->apm->isStreamActive((int) stream, in_past_ms);
}
static int ap_dump(const struct audio_policy *pol, int fd)
@@ -319,6 +343,8 @@ static int create_legacy_ap(const struct audio_policy_device *device,
lap->policy.init_stream_volume = ap_init_stream_volume;
lap->policy.set_stream_volume_index = ap_set_stream_volume_index;
lap->policy.get_stream_volume_index = ap_get_stream_volume_index;
+ lap->policy.set_stream_volume_index_for_device = ap_set_stream_volume_index_for_device;
+ lap->policy.get_stream_volume_index_for_device = ap_get_stream_volume_index_for_device;
lap->policy.get_strategy_for_stream = ap_get_strategy_for_stream;
lap->policy.get_devices_for_stream = ap_get_devices_for_stream;
lap->policy.get_output_for_effect = ap_get_output_for_effect;