Merge changes from topic "adtConversion"

* changes:
  Refactor for audio device type in conversion.
  Use AudioDeviceTypeAddr when setting device for effects.
  Add constructor with type and address for DeviceDescriptor.
gugelfrei
Treehugger Robot 5 years ago committed by Gerrit Code Review
commit 9410d2ed17

@ -42,6 +42,13 @@ const DeviceTypeSet& getAudioDeviceOutAllScoSet() {
return audioDeviceOutAllScoSet;
}
const DeviceTypeSet& getAudioDeviceOutAllUsbSet() {
static const DeviceTypeSet audioDeviceOutAllUsbSet = DeviceTypeSet(
std::begin(AUDIO_DEVICE_OUT_ALL_USB_ARRAY),
std::end(AUDIO_DEVICE_OUT_ALL_USB_ARRAY));
return audioDeviceOutAllUsbSet;
}
const DeviceTypeSet& getAudioDeviceInAllSet() {
static const DeviceTypeSet audioDeviceInAllSet = DeviceTypeSet(
std::begin(AUDIO_DEVICE_IN_ALL_ARRAY),
@ -49,6 +56,13 @@ const DeviceTypeSet& getAudioDeviceInAllSet() {
return audioDeviceInAllSet;
}
const DeviceTypeSet& getAudioDeviceInAllUsbSet() {
static const DeviceTypeSet audioDeviceInAllUsbSet = DeviceTypeSet(
std::begin(AUDIO_DEVICE_IN_ALL_USB_ARRAY),
std::end(AUDIO_DEVICE_IN_ALL_USB_ARRAY));
return audioDeviceInAllUsbSet;
}
bool deviceTypesToString(const DeviceTypeSet &deviceTypes, std::string &str) {
if (deviceTypes.empty()) {
str = "Empty device types";

@ -25,12 +25,22 @@
namespace android {
DeviceDescriptorBase::DeviceDescriptorBase(audio_devices_t type) :
AudioPort("", AUDIO_PORT_TYPE_DEVICE,
audio_is_output_device(type) ? AUDIO_PORT_ROLE_SINK :
AUDIO_PORT_ROLE_SOURCE)
DeviceDescriptorBase(type, "")
{
mDeviceTypeAddr.mType = type;
if (audio_is_remote_submix_device(type)) {
}
DeviceDescriptorBase::DeviceDescriptorBase(audio_devices_t type, const std::string& address) :
DeviceDescriptorBase(AudioDeviceTypeAddr(type, address))
{
}
DeviceDescriptorBase::DeviceDescriptorBase(const AudioDeviceTypeAddr &deviceTypeAddr) :
AudioPort("", AUDIO_PORT_TYPE_DEVICE,
audio_is_output_device(deviceTypeAddr.mType) ? AUDIO_PORT_ROLE_SINK :
AUDIO_PORT_ROLE_SOURCE),
mDeviceTypeAddr(deviceTypeAddr)
{
if (mDeviceTypeAddr.mAddress.empty() && audio_is_remote_submix_device(mDeviceTypeAddr.mType)) {
mDeviceTypeAddr.mAddress = "0";
}
}

@ -37,7 +37,9 @@ using FormatVector = std::vector<audio_format_t>;
const DeviceTypeSet& getAudioDeviceOutAllSet();
const DeviceTypeSet& getAudioDeviceOutAllA2dpSet();
const DeviceTypeSet& getAudioDeviceOutAllScoSet();
const DeviceTypeSet& getAudioDeviceOutAllUsbSet();
const DeviceTypeSet& getAudioDeviceInAllSet();
const DeviceTypeSet& getAudioDeviceInAllUsbSet();
template<typename T>
static std::vector<T> Intersection(const std::set<T>& a, const std::set<T>& b) {

@ -35,6 +35,8 @@ class DeviceDescriptorBase : public AudioPort, public AudioPortConfig
public:
// Note that empty name refers by convention to a generic device.
explicit DeviceDescriptorBase(audio_devices_t type);
DeviceDescriptorBase(audio_devices_t type, const std::string& address);
explicit DeviceDescriptorBase(const AudioDeviceTypeAddr& deviceTypeAddr);
virtual ~DeviceDescriptorBase() {}

@ -27,6 +27,7 @@ cc_defaults {
"android.hardware.audio.common-util",
"android.hidl.allocator@1.0",
"android.hidl.memory@1.0",
"libaudiofoundation",
"libaudiohal_deathhandler",
"libaudioutils",
"libbase",

@ -17,6 +17,7 @@
#include <string.h>
#define LOG_TAG "HalHidl"
#include <media/AudioContainers.h>
#include <media/AudioParameter.h>
#include <utils/Log.h>
@ -109,26 +110,22 @@ static std::string deviceAddressToHal(const DeviceAddress& address) {
char halAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
memset(halAddress, 0, sizeof(halAddress));
audio_devices_t halDevice = static_cast<audio_devices_t>(address.device);
const bool isInput = (halDevice & AUDIO_DEVICE_BIT_IN) != 0;
if (isInput) halDevice &= ~AUDIO_DEVICE_BIT_IN;
if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_A2DP) != 0) ||
(isInput && (halDevice & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) {
if (getAudioDeviceOutAllA2dpSet().count(halDevice) > 0 ||
halDevice == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
snprintf(halAddress, sizeof(halAddress), "%02X:%02X:%02X:%02X:%02X:%02X",
address.address.mac[0], address.address.mac[1], address.address.mac[2],
address.address.mac[3], address.address.mac[4], address.address.mac[5]);
} else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_IP) != 0) ||
(isInput && (halDevice & AUDIO_DEVICE_IN_IP) != 0)) {
} else if (halDevice == AUDIO_DEVICE_OUT_IP || halDevice == AUDIO_DEVICE_IN_IP) {
snprintf(halAddress, sizeof(halAddress), "%d.%d.%d.%d", address.address.ipv4[0],
address.address.ipv4[1], address.address.ipv4[2], address.address.ipv4[3]);
} else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0) ||
(isInput && (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0)) {
} else if (getAudioDeviceOutAllUsbSet().count(halDevice) > 0 ||
getAudioDeviceInAllUsbSet().count(halDevice) > 0) {
snprintf(halAddress, sizeof(halAddress), "card=%d;device=%d", address.address.alsa.card,
address.address.alsa.device);
} else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_BUS) != 0) ||
(isInput && (halDevice & AUDIO_DEVICE_IN_BUS) != 0)) {
} else if (halDevice == AUDIO_DEVICE_OUT_BUS || halDevice == AUDIO_DEVICE_IN_BUS) {
snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str());
} else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0 ||
(isInput && (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) {
} else if (halDevice == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
halDevice == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
snprintf(halAddress, sizeof(halAddress), "%s", address.rSubmixAddress.c_str());
} else {
snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str());

@ -22,6 +22,7 @@
#include PATH(android/hardware/audio/FILE_VERSION/IPrimaryDevice.h)
#include <cutils/native_handle.h>
#include <hwbinder/IPCThreadState.h>
#include <media/AudioContainers.h>
#include <utils/Log.h>
#include <common/all-versions/VersionUtils.h>
@ -51,42 +52,32 @@ status_t deviceAddressFromHal(
if (halAddress == nullptr || strnlen(halAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) {
return OK;
}
const bool isInput = (device & AUDIO_DEVICE_BIT_IN) != 0;
if (isInput) device &= ~AUDIO_DEVICE_BIT_IN;
if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_A2DP) != 0)
|| (isInput && (device & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) {
if (getAudioDeviceOutAllA2dpSet().count(device) > 0
|| device == AUDIO_DEVICE_IN_BLUETOOTH_A2DP) {
int status = sscanf(halAddress,
"%hhX:%hhX:%hhX:%hhX:%hhX:%hhX",
&address->address.mac[0], &address->address.mac[1], &address->address.mac[2],
&address->address.mac[3], &address->address.mac[4], &address->address.mac[5]);
return status == 6 ? OK : BAD_VALUE;
} else if ((!isInput && (device & AUDIO_DEVICE_OUT_IP) != 0)
|| (isInput && (device & AUDIO_DEVICE_IN_IP) != 0)) {
} else if (device == AUDIO_DEVICE_OUT_IP || device == AUDIO_DEVICE_IN_IP) {
int status = sscanf(halAddress,
"%hhu.%hhu.%hhu.%hhu",
&address->address.ipv4[0], &address->address.ipv4[1],
&address->address.ipv4[2], &address->address.ipv4[3]);
return status == 4 ? OK : BAD_VALUE;
} else if ((!isInput && (device & AUDIO_DEVICE_OUT_ALL_USB)) != 0
|| (isInput && (device & AUDIO_DEVICE_IN_ALL_USB)) != 0) {
} else if (getAudioDeviceOutAllUsbSet().count(device) > 0
|| getAudioDeviceInAllUsbSet().count(device) > 0) {
int status = sscanf(halAddress,
"card=%d;device=%d",
&address->address.alsa.card, &address->address.alsa.device);
return status == 2 ? OK : BAD_VALUE;
} else if ((!isInput && (device & AUDIO_DEVICE_OUT_BUS) != 0)
|| (isInput && (device & AUDIO_DEVICE_IN_BUS) != 0)) {
if (halAddress != NULL) {
address->busAddress = halAddress;
return OK;
}
return BAD_VALUE;
} else if ((!isInput && (device & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0
|| (isInput && (device & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) {
if (halAddress != NULL) {
address->rSubmixAddress = halAddress;
return OK;
}
return BAD_VALUE;
} else if (device == AUDIO_DEVICE_OUT_BUS || device == AUDIO_DEVICE_IN_BUS) {
address->busAddress = halAddress;
return OK;
} else if (device == AUDIO_DEVICE_OUT_REMOTE_SUBMIX
|| device == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
address->rSubmixAddress = halAddress;
return OK;
}
return OK;
}

@ -29,7 +29,9 @@
#include <system/audio_effects/effect_visualizer.h>
#include <audio_utils/channels.h>
#include <audio_utils/primitives.h>
#include <media/AudioContainers.h>
#include <media/AudioEffect.h>
#include <media/AudioDeviceTypeAddr.h>
#include <media/audiohal/EffectHalInterface.h>
#include <media/audiohal/EffectsFactoryHalInterface.h>
#include <mediautils/ServiceUtilities.h>
@ -1229,9 +1231,11 @@ void AudioFlinger::EffectChain::setVolumeForOutput_l(uint32_t left, uint32_t rig
}
}
status_t AudioFlinger::EffectModule::setDevice(audio_devices_t device)
status_t AudioFlinger::EffectModule::sendSetAudioDevicesCommand(
const AudioDeviceTypeAddrVector &devices, uint32_t cmdCode)
{
if (device == AUDIO_DEVICE_NONE) {
audio_devices_t deviceType = deviceTypesToBitMask(getAudioDeviceTypes(devices));
if (deviceType == AUDIO_DEVICE_NONE) {
return NO_ERROR;
}
@ -1243,17 +1247,26 @@ status_t AudioFlinger::EffectModule::setDevice(audio_devices_t device)
if ((mDescriptor.flags & EFFECT_FLAG_DEVICE_MASK) == EFFECT_FLAG_DEVICE_IND) {
status_t cmdStatus;
uint32_t size = sizeof(status_t);
uint32_t cmd = audio_is_output_devices(device) ? EFFECT_CMD_SET_DEVICE :
EFFECT_CMD_SET_INPUT_DEVICE;
status = mEffectInterface->command(cmd,
// FIXME: use audio device types and addresses when the hal interface is ready.
status = mEffectInterface->command(cmdCode,
sizeof(uint32_t),
&device,
&deviceType,
&size,
&cmdStatus);
}
return status;
}
status_t AudioFlinger::EffectModule::setDevices(const AudioDeviceTypeAddrVector &devices)
{
return sendSetAudioDevicesCommand(devices, EFFECT_CMD_SET_DEVICE);
}
status_t AudioFlinger::EffectModule::setInputDevice(const AudioDeviceTypeAddr &device)
{
return sendSetAudioDevicesCommand({device}, EFFECT_CMD_SET_INPUT_DEVICE);
}
status_t AudioFlinger::EffectModule::setMode(audio_mode_t mode)
{
Mutex::Autolock _l(mLock);
@ -2288,12 +2301,21 @@ size_t AudioFlinger::EffectChain::removeEffect_l(const sp<EffectModule>& effect,
return mEffects.size();
}
// setDevice_l() must be called with ThreadBase::mLock held
void AudioFlinger::EffectChain::setDevice_l(audio_devices_t device)
// setDevices_l() must be called with ThreadBase::mLock held
void AudioFlinger::EffectChain::setDevices_l(const AudioDeviceTypeAddrVector &devices)
{
size_t size = mEffects.size();
for (size_t i = 0; i < size; i++) {
mEffects[i]->setDevices(devices);
}
}
// setInputDevice_l() must be called with ThreadBase::mLock held
void AudioFlinger::EffectChain::setInputDevice_l(const AudioDeviceTypeAddr &device)
{
size_t size = mEffects.size();
for (size_t i = 0; i < size; i++) {
mEffects[i]->setDevice(device);
mEffects[i]->setInputDevice(device);
}
}

@ -109,7 +109,8 @@ public:
const effect_descriptor_t& desc() const { return mDescriptor; }
wp<EffectChain>& chain() { return mChain; }
status_t setDevice(audio_devices_t device);
status_t setDevices(const AudioDeviceTypeAddrVector &devices);
status_t setInputDevice(const AudioDeviceTypeAddr &device);
status_t setVolume(uint32_t *left, uint32_t *right, bool controller);
status_t setMode(audio_mode_t mode);
status_t setAudioSource(audio_source_t source);
@ -158,6 +159,7 @@ private:
status_t start_l();
status_t stop_l();
status_t remove_effect_from_hal_l();
status_t sendSetAudioDevicesCommand(const AudioDeviceTypeAddrVector &devices, uint32_t cmdCode);
mutable Mutex mLock; // mutex for process, commands and handles list protection
wp<ThreadBase> mThread; // parent thread
@ -350,7 +352,8 @@ public:
// FIXME use float to improve the dynamic range
bool setVolume_l(uint32_t *left, uint32_t *right, bool force = false);
void resetVolume_l();
void setDevice_l(audio_devices_t device);
void setDevices_l(const AudioDeviceTypeAddrVector &devices);
void setInputDevice_l(const AudioDeviceTypeAddr &device);
void setMode_l(audio_mode_t mode);
void setAudioSource_l(audio_source_t source);

@ -1378,8 +1378,8 @@ sp<AudioFlinger::EffectHandle> AudioFlinger::ThreadBase::createEffect_l(
effectCreated = true;
// FIXME: use vector of device and address when effect interface is ready.
effect->setDevice(deviceTypesToBitMask(outDeviceTypes()));
effect->setDevice(inDeviceType());
effect->setDevices(outDeviceTypeAddrs());
effect->setInputDevice(inDeviceTypeAddr());
effect->setMode(mAudioFlinger->getMode());
effect->setAudioSource(mAudioSource);
}
@ -1495,8 +1495,8 @@ status_t AudioFlinger::ThreadBase::addEffect_l(const sp<EffectModule>& effect)
return status;
}
effect->setDevice(deviceTypesToBitMask(outDeviceTypes()));
effect->setDevice(inDeviceType());
effect->setDevices(outDeviceTypeAddrs());
effect->setInputDevice(inDeviceTypeAddr());
effect->setMode(mAudioFlinger->getMode());
effect->setAudioSource(mAudioSource);
@ -4070,7 +4070,7 @@ status_t AudioFlinger::PlaybackThread::createAudioPatch_l(const struct audio_pat
#endif
for (size_t i = 0; i < mEffectChains.size(); i++) {
mEffectChains[i]->setDevice_l(type);
mEffectChains[i]->setDevices_l(deviceTypeAddrs);
}
// mPatch.num_sinks is not set when the thread is created so that
@ -8321,7 +8321,7 @@ status_t AudioFlinger::RecordThread::createAudioPatch_l(const struct audio_patch
mInDeviceTypeAddr.mAddress = patch->sources[0].ext.device.address;
audio_port_handle_t deviceId = patch->sources[0].id;
for (size_t i = 0; i < mEffectChains.size(); i++) {
mEffectChains[i]->setDevice_l(mInDeviceTypeAddr.mType);
mEffectChains[i]->setInputDevice_l(inDeviceTypeAddr());
}
checkBtNrec_l();
@ -8391,7 +8391,7 @@ void AudioFlinger::RecordThread::updateOutDevices(const DeviceDescriptorBaseVect
mOutDevices = outDevices;
mOutDeviceTypeAddrs = deviceTypeAddrsFromDescriptors(mOutDevices);
for (size_t i = 0; i < mEffectChains.size(); i++) {
mEffectChains[i]->setDevice_l(deviceTypesToBitMask(outDeviceTypes()));
mEffectChains[i]->setDevices_l(outDeviceTypeAddrs());
}
}
@ -8922,7 +8922,11 @@ status_t AudioFlinger::MmapThread::createAudioPatch_l(const struct audio_patch *
}
for (size_t i = 0; i < mEffectChains.size(); i++) {
mEffectChains[i]->setDevice_l(type);
if (isOutput()) {
mEffectChains[i]->setDevices_l(sinkDeviceTypeAddrs);
} else {
mEffectChains[i]->setInputDevice_l(sourceDeviceTypeAddr);
}
}
if (!isOutput()) {

@ -321,6 +321,13 @@ public:
return isOutput() ? outDeviceTypes() : DeviceTypeSet({inDeviceType()});
}
const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const {
return mOutDeviceTypeAddrs;
}
const AudioDeviceTypeAddr& inDeviceTypeAddr() const {
return mInDeviceTypeAddr;
}
virtual bool isOutput() const = 0;
virtual sp<StreamHalInterface> stream() const = 0;

@ -33,9 +33,13 @@ class DeviceDescriptor : public DeviceDescriptorBase,
{
public:
// Note that empty name refers by convention to a generic device.
explicit DeviceDescriptor(audio_devices_t type, const std::string &tagName = "");
DeviceDescriptor(audio_devices_t type, const FormatVector &encodedFormats,
const std::string &tagName = "");
explicit DeviceDescriptor(audio_devices_t type);
DeviceDescriptor(audio_devices_t type, const std::string &tagName,
const FormatVector &encodedFormats = FormatVector{});
DeviceDescriptor(audio_devices_t type, const std::string &tagName,
const std::string &address, const FormatVector &encodedFormats = FormatVector{});
DeviceDescriptor(const AudioDeviceTypeAddr &deviceTypeAddr, const std::string &tagName = "",
const FormatVector &encodedFormats = FormatVector{});
virtual ~DeviceDescriptor() {}

@ -26,14 +26,30 @@
namespace android {
DeviceDescriptor::DeviceDescriptor(audio_devices_t type, const std::string &tagName) :
DeviceDescriptor(type, FormatVector{}, tagName)
DeviceDescriptor::DeviceDescriptor(audio_devices_t type) :
DeviceDescriptor(type, "" /*tagName*/)
{
}
DeviceDescriptor::DeviceDescriptor(audio_devices_t type, const FormatVector &encodedFormats,
const std::string &tagName) :
DeviceDescriptorBase(type), mTagName(tagName), mEncodedFormats(encodedFormats)
DeviceDescriptor::DeviceDescriptor(audio_devices_t type,
const std::string &tagName,
const FormatVector &encodedFormats) :
DeviceDescriptor(type, tagName, "" /*address*/, encodedFormats)
{
}
DeviceDescriptor::DeviceDescriptor(audio_devices_t type,
const std::string &tagName,
const std::string &address,
const FormatVector &encodedFormats) :
DeviceDescriptor(AudioDeviceTypeAddr(type, address), tagName, encodedFormats)
{
}
DeviceDescriptor::DeviceDescriptor(const AudioDeviceTypeAddr &deviceTypeAddr,
const std::string &tagName,
const FormatVector &encodedFormats) :
DeviceDescriptorBase(deviceTypeAddr), mTagName(tagName), mEncodedFormats(encodedFormats)
{
mCurrentEncodedFormat = AUDIO_FORMAT_DEFAULT;
/* If framework runs against a pre 5.0 Audio HAL, encoded formats are absent from the config.
@ -41,7 +57,7 @@ DeviceDescriptor::DeviceDescriptor(audio_devices_t type, const FormatVector &enc
* For now, the workaround to remove AC3 and IEC61937 support on HDMI is to declare
* something like 'encodedFormats="AUDIO_FORMAT_PCM_16_BIT"' on the HDMI devicePort.
*/
if (type == AUDIO_DEVICE_OUT_HDMI && mEncodedFormats.empty()) {
if (mDeviceTypeAddr.mType == AUDIO_DEVICE_OUT_HDMI && mEncodedFormats.empty()) {
mEncodedFormats.push_back(AUDIO_FORMAT_AC3);
mEncodedFormats.push_back(AUDIO_FORMAT_IEC61937);
}

@ -49,8 +49,7 @@ status_t HwModule::addOutputProfile(const std::string& name, const audio_config_
profile->addAudioProfile(new AudioProfile(config->format, config->channel_mask,
config->sample_rate));
sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device);
devDesc->setAddress(address.string());
sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device, "" /*tagName*/, address.string());
addDynamicDevice(devDesc);
// Reciprocally attach the device to the module
devDesc->attach(this);
@ -117,8 +116,7 @@ status_t HwModule::addInputProfile(const std::string& name, const audio_config_t
profile->addAudioProfile(new AudioProfile(config->format, config->channel_mask,
config->sample_rate));
sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device);
devDesc->setAddress(address.string());
sp<DeviceDescriptor> devDesc = new DeviceDescriptor(device, "" /*tagName*/, address.string());
addDynamicDevice(devDesc);
// Reciprocally attach the device to the module
devDesc->attach(this);
@ -360,9 +358,9 @@ sp<DeviceDescriptor> HwModuleCollection::createDevice(const audio_devices_t type
address);
return nullptr;
}
sp<DeviceDescriptor> device = new DeviceDescriptor(type, name);
sp<DeviceDescriptor> device = new DeviceDescriptor(type, name, address);
device->setName(name);
device->setAddress(address);
device->setEncodedFormat(encodedFormat);
// Add the device to the list of dynamic devices

@ -511,13 +511,8 @@ Return<DevicePortTraits::Element> DevicePortTraits::deserialize(const xmlNode *c
if (!encodedFormatsLiteral.empty()) {
encodedFormats = formatsFromString(encodedFormatsLiteral, " ");
}
Element deviceDesc = new DeviceDescriptor(type, encodedFormats, name);
std::string address = getXmlAttribute(cur, Attributes::address);
if (!address.empty()) {
ALOGV("%s: address=%s for %s", __func__, address.c_str(), name.c_str());
deviceDesc->setAddress(address);
}
Element deviceDesc = new DeviceDescriptor(type, name, address, encodedFormats);
AudioProfileTraits::Collection profiles;
status_t status = deserializeCollection<AudioProfileTraits>(cur, &profiles, NULL);

Loading…
Cancel
Save