Remove last references to hardware/audio.h
DeviceHalInterface transitioned to "capabilities" model
(similar to the one already used by streams, e.g. 'supportsDrain').
No direct checking of the HAL version is needed.
AudioPolicy uses its own version read from the configuration,
and these values never checked against the actual HAL version,
thus it does not need versions and macroses from hardware/*.
Test: make & run on N6P
Change-Id: Ic4a56bfa19a9a61edac2b9f9a163fd8f63a0ff87
diff --git a/include/media/audiohal/DeviceHalInterface.h b/include/media/audiohal/DeviceHalInterface.h
index 2f7ed3a..caf01be 100644
--- a/include/media/audiohal/DeviceHalInterface.h
+++ b/include/media/audiohal/DeviceHalInterface.h
@@ -33,9 +33,6 @@
// Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
virtual status_t getSupportedDevices(uint32_t *devices) = 0;
- // Get the hardware module version.
- virtual status_t getVersion(uint32_t *version) = 0;
-
// Check to see if the audio hardware interface has been initialized.
virtual status_t initCheck() = 0;
@@ -88,6 +85,9 @@
audio_source_t source,
sp<StreamInHalInterface> *inStream) = 0;
+ // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
+ virtual status_t supportsAudioPatches(bool *supportsPatches) = 0;
+
// Creates an audio patch between several source and sink ports.
virtual status_t createAudioPatch(
unsigned int num_sources,
diff --git a/media/libaudiohal/DeviceHalLocal.cpp b/media/libaudiohal/DeviceHalLocal.cpp
index c5df8c8..78adfef 100644
--- a/media/libaudiohal/DeviceHalLocal.cpp
+++ b/media/libaudiohal/DeviceHalLocal.cpp
@@ -40,11 +40,6 @@
return OK;
}
-status_t DeviceHalLocal::getVersion(uint32_t *version) {
- *version = mDev->common.version;
- return OK;
-}
-
status_t DeviceHalLocal::initCheck() {
return mDev->init_check(mDev);
}
@@ -139,17 +134,31 @@
return openResult;
}
+status_t DeviceHalLocal::supportsAudioPatches(bool *supportsPatches) {
+ *supportsPatches = version() >= AUDIO_DEVICE_API_VERSION_3_0;
+ return OK;
+}
+
status_t DeviceHalLocal::createAudioPatch(
unsigned int num_sources,
const struct audio_port_config *sources,
unsigned int num_sinks,
const struct audio_port_config *sinks,
audio_patch_handle_t *patch) {
- return mDev->create_audio_patch(mDev, num_sources, sources, num_sinks, sinks, patch);
+ if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
+ return mDev->create_audio_patch(
+ mDev, num_sources, sources, num_sinks, sinks, patch);
+ } else {
+ return INVALID_OPERATION;
+ }
}
status_t DeviceHalLocal::releaseAudioPatch(audio_patch_handle_t patch) {
- return mDev->release_audio_patch(mDev, patch);
+ if (version() >= AUDIO_DEVICE_API_VERSION_3_0) {
+ return mDev->release_audio_patch(mDev, patch);
+ } else {
+ return INVALID_OPERATION;
+ }
}
status_t DeviceHalLocal::getAudioPort(struct audio_port *port) {
@@ -157,7 +166,10 @@
}
status_t DeviceHalLocal::setAudioPortConfig(const struct audio_port_config *config) {
- return mDev->set_audio_port_config(mDev, config);
+ if (version() >= AUDIO_DEVICE_API_VERSION_3_0)
+ return mDev->set_audio_port_config(mDev, config);
+ else
+ return INVALID_OPERATION;
}
status_t DeviceHalLocal::dump(int fd) {
diff --git a/media/libaudiohal/DeviceHalLocal.h b/media/libaudiohal/DeviceHalLocal.h
index eba360c..865f296 100644
--- a/media/libaudiohal/DeviceHalLocal.h
+++ b/media/libaudiohal/DeviceHalLocal.h
@@ -28,9 +28,6 @@
// Sets the value of 'devices' to a bitmask of 1 or more values of audio_devices_t.
virtual status_t getSupportedDevices(uint32_t *devices);
- // Get the hardware module version.
- virtual status_t getVersion(uint32_t *version);
-
// Check to see if the audio hardware interface has been initialized.
virtual status_t initCheck();
@@ -83,6 +80,9 @@
audio_source_t source,
sp<StreamInHalInterface> *inStream);
+ // Returns whether createAudioPatch and releaseAudioPatch operations are supported.
+ virtual status_t supportsAudioPatches(bool *supportsPatches);
+
// Creates an audio patch between several source and sink ports.
virtual status_t createAudioPatch(
unsigned int num_sources,
@@ -115,6 +115,8 @@
// The destructor automatically closes the device.
virtual ~DeviceHalLocal();
+
+ uint32_t version() const { return mDev->common.version; }
};
} // namespace android
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index 6c71f60..04fb8ba 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -67,8 +67,6 @@
#include <mediautils/BatteryNotifier.h>
#include <private/android_filesystem_config.h>
-#include <hardware/audio.h> // for AUDIO_HARDWARE_MODULE_...
-
// ----------------------------------------------------------------------------
// Note: the following macro is used for extremely verbose logging message. In
diff --git a/services/audioflinger/AudioHwDevice.cpp b/services/audioflinger/AudioHwDevice.cpp
index 28110a2..b109d06 100644
--- a/services/audioflinger/AudioHwDevice.cpp
+++ b/services/audioflinger/AudioHwDevice.cpp
@@ -93,10 +93,10 @@
return status;
}
-uint32_t AudioHwDevice::version() const
-{
- uint32_t result;
- return mHwDevice->getVersion(&result) == OK ? result : 0;
+bool AudioHwDevice::supportsAudioPatches() const {
+ bool result;
+ return mHwDevice->supportsAudioPatches(&result) == OK ? result : false;
}
+
}; // namespace android
diff --git a/services/audioflinger/AudioHwDevice.h b/services/audioflinger/AudioHwDevice.h
index ebb8911..eb826c6 100644
--- a/services/audioflinger/AudioHwDevice.h
+++ b/services/audioflinger/AudioHwDevice.h
@@ -58,7 +58,6 @@
audio_module_handle_t handle() const { return mHandle; }
const char *moduleName() const { return mModuleName; }
sp<DeviceHalInterface> hwDevice() const { return mHwDevice; }
- uint32_t version() const;
/** This method creates and opens the audio hardware output stream.
* The "address" parameter qualifies the "devices" audio device type if needed.
@@ -75,6 +74,8 @@
struct audio_config *config,
const char *address);
+ bool supportsAudioPatches() const;
+
private:
const audio_module_handle_t mHandle;
const char * const mModuleName;
diff --git a/services/audioflinger/PatchPanel.cpp b/services/audioflinger/PatchPanel.cpp
index 93f634a..591a49e 100644
--- a/services/audioflinger/PatchPanel.cpp
+++ b/services/audioflinger/PatchPanel.cpp
@@ -27,8 +27,6 @@
#include "ServiceUtilities.h"
#include <media/AudioParameter.h>
-#include <hardware/audio.h> // for AUDIO_DEVICE_API_VERSION_...
-
// ----------------------------------------------------------------------------
// Note: the following macro is used for extremely verbose logging message. In
@@ -249,11 +247,11 @@
// - special patch request with 2 sources (reuse one existing output mix) OR
// - Device to device AND
// - source HW module != destination HW module OR
- // - audio HAL version < 3.0
+ // - audio HAL does not support audio patches creation
if ((patch->num_sources == 2) ||
((patch->sinks[0].type == AUDIO_PORT_TYPE_DEVICE) &&
((patch->sinks[0].ext.device.hw_module != srcModule) ||
- (audioHwDevice->version() < AUDIO_DEVICE_API_VERSION_3_0)))) {
+ !audioHwDevice->supportsAudioPatches()))) {
if (patch->num_sources == 2) {
if (patch->sources[1].type != AUDIO_PORT_TYPE_MIX ||
(patch->num_sinks != 0 && patch->sinks[0].ext.device.hw_module !=
@@ -341,17 +339,13 @@
}
status = thread->sendCreateAudioPatchConfigEvent(patch, &halHandle);
} else {
- if (audioHwDevice->version() < AUDIO_DEVICE_API_VERSION_3_0) {
- status = INVALID_OPERATION;
- goto exit;
- }
-
sp<DeviceHalInterface> hwDevice = audioHwDevice->hwDevice();
status = hwDevice->createAudioPatch(patch->num_sources,
patch->sources,
patch->num_sinks,
patch->sinks,
&halHandle);
+ if (status == INVALID_OPERATION) goto exit;
}
}
} break;
@@ -620,10 +614,6 @@
status = thread->sendReleaseAudioPatchConfigEvent(removedPatch->mHalHandle);
} else {
AudioHwDevice *audioHwDevice = audioflinger->mAudioHwDevs.valueAt(index);
- if (audioHwDevice->version() < AUDIO_DEVICE_API_VERSION_3_0) {
- status = INVALID_OPERATION;
- break;
- }
sp<DeviceHalInterface> hwDevice = audioHwDevice->hwDevice();
status = hwDevice->releaseAudioPatch(removedPatch->mHalHandle);
}
@@ -688,13 +678,7 @@
}
AudioHwDevice *audioHwDevice = audioflinger->mAudioHwDevs.valueAt(index);
- if (audioHwDevice->version() >= AUDIO_DEVICE_API_VERSION_3_0) {
- sp<DeviceHalInterface> hwDevice = audioHwDevice->hwDevice();
- return hwDevice->setAudioPortConfig(config);
- } else {
- return INVALID_OPERATION;
- }
- return NO_ERROR;
+ return audioHwDevice->hwDevice()->setAudioPortConfig(config);
}
} // namespace android
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index e661a3b..6b23e56 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -53,8 +53,6 @@
#include <powermanager/PowerManager.h>
-#include <hardware/audio.h> // for AUDIO_DEVICE_API_VERSION_...
-
#include "AudioFlinger.h"
#include "AudioMixer.h"
#include "BufferProviders.h"
@@ -3492,7 +3490,7 @@
mOutDevice = type;
mPatch = *patch;
- if (mOutput->audioHwDev->version() >= AUDIO_DEVICE_API_VERSION_3_0) {
+ if (mOutput->audioHwDev->supportsAudioPatches()) {
sp<DeviceHalInterface> hwDevice = mOutput->audioHwDev->hwDevice();
status = hwDevice->createAudioPatch(patch->num_sources,
patch->sources,
@@ -3542,7 +3540,7 @@
mOutDevice = AUDIO_DEVICE_NONE;
- if (mOutput->audioHwDev->version() >= AUDIO_DEVICE_API_VERSION_3_0) {
+ if (mOutput->audioHwDev->supportsAudioPatches()) {
sp<DeviceHalInterface> hwDevice = mOutput->audioHwDev->hwDevice();
status = hwDevice->releaseAudioPatch(handle);
} else {
@@ -7612,7 +7610,7 @@
}
}
- if (mInput->audioHwDev->version() >= AUDIO_DEVICE_API_VERSION_3_0) {
+ if (mInput->audioHwDev->supportsAudioPatches()) {
sp<DeviceHalInterface> hwDevice = mInput->audioHwDev->hwDevice();
status = hwDevice->createAudioPatch(patch->num_sources,
patch->sources,
@@ -7652,7 +7650,7 @@
mInDevice = AUDIO_DEVICE_NONE;
- if (mInput->audioHwDev->version() >= AUDIO_DEVICE_API_VERSION_3_0) {
+ if (mInput->audioHwDev->supportsAudioPatches()) {
sp<DeviceHalInterface> hwDevice = mInput->audioHwDev->hwDevice();
status = hwDevice->releaseAudioPatch(handle);
} else {
diff --git a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
index 99c0cd2..ded2285 100644
--- a/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
+++ b/services/audiopolicy/common/managerdefinitions/include/AudioPort.h
@@ -118,7 +118,7 @@
audio_format_t targetFormat);
audio_module_handle_t getModuleHandle() const;
- uint32_t getModuleVersion() const;
+ uint32_t getModuleVersionMajor() const;
const char *getModuleName() const;
bool useInputChannelMask() const
diff --git a/services/audiopolicy/common/managerdefinitions/include/HwModule.h b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
index 3a31672..29b6b9c 100644
--- a/services/audiopolicy/common/managerdefinitions/include/HwModule.h
+++ b/services/audiopolicy/common/managerdefinitions/include/HwModule.h
@@ -18,7 +18,6 @@
#include "DeviceDescriptor.h"
#include "AudioRoute.h"
-#include <hardware/audio.h>
#include <utils/RefBase.h>
#include <utils/String8.h>
#include <utils/Errors.h>
@@ -40,7 +39,7 @@
class HwModule : public RefBase
{
public:
- explicit HwModule(const char *name, uint32_t halVersion = AUDIO_DEVICE_API_VERSION_MIN);
+ explicit HwModule(const char *name, uint32_t halVersionMajor = 0, uint32_t halVersionMinor = 0);
~HwModule();
const char *getName() const { return mName.string(); }
@@ -55,8 +54,11 @@
void setProfiles(const IOProfileCollection &profiles);
- void setHalVersion(uint32_t halVersion) { mHalVersion = halVersion; }
- uint32_t getHalVersion() const { return mHalVersion; }
+ void setHalVersion(uint32_t major, uint32_t minor) {
+ mHalVersion = (major << 8) | (minor & 0xff);
+ }
+ uint32_t getHalVersionMajor() const { return mHalVersion >> 8; }
+ uint32_t getHalVersionMinor() const { return mHalVersion & 0xff; }
sp<DeviceDescriptor> getRouteSinkDevice(const sp<AudioRoute> &route) const;
DeviceVector getRouteSourceDevices(const sp<AudioRoute> &route) const;
diff --git a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
index 31bf95c..aac23b4 100644
--- a/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/AudioPort.cpp
@@ -50,12 +50,12 @@
return mModule->mHandle;
}
-uint32_t AudioPort::getModuleVersion() const
+uint32_t AudioPort::getModuleVersionMajor() const
{
if (mModule == 0) {
return 0;
}
- return mModule->getHalVersion();
+ return mModule->getHalVersionMajor();
}
const char *AudioPort::getModuleName() const
diff --git a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp b/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
index 643ac1e..d751f07 100644
--- a/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/ConfigParsingUtils.cpp
@@ -357,9 +357,8 @@
} else if (strcmp(AUDIO_HAL_VERSION_TAG, node->name) == 0) {
uint32_t major, minor;
sscanf((char *)node->value, "%u.%u", &major, &minor);
- module->setHalVersion(HARDWARE_DEVICE_API_VERSION(major, minor));
- ALOGV("loadGlobalConfig() mHalVersion = %04x major %u minor %u",
- module->getHalVersion(), major, minor);
+ module->setHalVersion(major, minor);
+ ALOGV("loadGlobalConfig() mHalVersion = major %u minor %u", major, minor);
}
node = node->next;
}
diff --git a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
index 356aef1..cc56fb8 100644
--- a/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/HwModule.cpp
@@ -25,11 +25,11 @@
namespace android {
-HwModule::HwModule(const char *name, uint32_t halVersion)
+HwModule::HwModule(const char *name, uint32_t halVersionMajor, uint32_t halVersionMinor)
: mName(String8(name)),
- mHandle(AUDIO_MODULE_HANDLE_NONE),
- mHalVersion(halVersion)
+ mHandle(AUDIO_MODULE_HANDLE_NONE)
{
+ setHalVersion(halVersionMajor, halVersionMinor);
}
HwModule::~HwModule()
@@ -227,7 +227,7 @@
result.append(buffer);
snprintf(buffer, SIZE, " - handle: %d\n", mHandle);
result.append(buffer);
- snprintf(buffer, SIZE, " - version: %u.%u\n", mHalVersion >> 8, mHalVersion & 0xFF);
+ snprintf(buffer, SIZE, " - version: %u.%u\n", getHalVersionMajor(), getHalVersionMinor());
result.append(buffer);
write(fd, result.string(), result.size());
if (mOutputProfiles.size()) {
diff --git a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
index 3e5bb7d..44f382b 100644
--- a/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
+++ b/services/audiopolicy/common/managerdefinitions/src/Serializer.cpp
@@ -418,19 +418,17 @@
ALOGE("%s: No %s found", __FUNCTION__, Attributes::name);
return BAD_VALUE;
}
- uint32_t version = AUDIO_DEVICE_API_VERSION_MIN;
+ uint32_t versionMajor = 0, versionMinor = 0;
string versionLiteral = getXmlAttribute(root, Attributes::version);
if (!versionLiteral.empty()) {
- uint32_t major, minor;
- sscanf(versionLiteral.c_str(), "%u.%u", &major, &minor);
- version = HARDWARE_DEVICE_API_VERSION(major, minor);
- ALOGV("%s: mHalVersion = %04x major %u minor %u", __FUNCTION__,
- version, major, minor);
+ sscanf(versionLiteral.c_str(), "%u.%u", &versionMajor, &versionMinor);
+ ALOGV("%s: mHalVersion = major %u minor %u", __FUNCTION__,
+ versionMajor, versionMajor);
}
ALOGV("%s: %s %s=%s", __FUNCTION__, tag, Attributes::name, name.c_str());
- module = new Element(name.c_str(), version);
+ module = new Element(name.c_str(), versionMajor, versionMinor);
// Deserialize childrens: Audio Mix Port, Audio Device Ports (Source/Sink), Audio Routes
MixPortTraits::Collection mixPorts;
diff --git a/services/audiopolicy/enginedefault/src/Engine.cpp b/services/audiopolicy/enginedefault/src/Engine.cpp
index d31429c..5f0557c 100644
--- a/services/audiopolicy/enginedefault/src/Engine.cpp
+++ b/services/audiopolicy/enginedefault/src/Engine.cpp
@@ -320,8 +320,7 @@
if (((availableInputDevices.types() &
AUDIO_DEVICE_IN_TELEPHONY_RX & ~AUDIO_DEVICE_BIT_IN) == 0) ||
(((txDevice & availPrimaryInputDevices & ~AUDIO_DEVICE_BIT_IN) != 0) &&
- (primaryOutput->getAudioPort()->getModuleVersion() <
- AUDIO_DEVICE_API_VERSION_3_0))) {
+ (primaryOutput->getAudioPort()->getModuleVersionMajor() < 3))) {
availableOutputDevicesType = availPrimaryOutputDevices;
}
}
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 125d422..7c955e5 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -37,6 +37,7 @@
#include <media/AudioPolicyHelper.h>
#include <soundtrigger/SoundTrigger.h>
#include <system/audio.h>
+#include <audio_policy_conf.h>
#include "AudioPolicyManager.h"
#ifndef USE_XML_AUDIO_POLICY_CONF
#include <ConfigParsingUtils.h>
@@ -2721,7 +2722,7 @@
// - source and sink devices are on differnt HW modules OR
// - audio HAL version is < 3.0
if (!srcDeviceDesc->hasSameHwModuleAs(sinkDeviceDesc) ||
- (srcDeviceDesc->mModule->getHalVersion() < AUDIO_DEVICE_API_VERSION_3_0)) {
+ (srcDeviceDesc->mModule->getHalVersionMajor() < 3)) {
// support only one sink device for now to simplify output selection logic
if (patch->num_sinks > 1) {
return INVALID_OPERATION;
@@ -3083,7 +3084,7 @@
if (srcDeviceDesc->getAudioPort()->mModule->getHandle() ==
sinkDeviceDesc->getAudioPort()->mModule->getHandle() &&
- srcDeviceDesc->getAudioPort()->mModule->getHalVersion() >= AUDIO_DEVICE_API_VERSION_3_0 &&
+ srcDeviceDesc->getAudioPort()->mModule->getHalVersionMajor() >= 3 &&
srcDeviceDesc->getAudioPort()->mGains.size() > 0) {
ALOGV("%s AUDIO_DEVICE_API_VERSION_3_0", __FUNCTION__);
// create patch between src device and output device