mirror of
https://github.com/Evolution-X/hardware_interfaces
synced 2026-02-01 11:36:00 +00:00
audio: Update default wrapper to support V7 am: e1a9c8f8b8 am: 5efd34043e
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/1530604 MUST ONLY BE SUBMITTED BY AUTOMERGER Change-Id: Ib47395cdeec54c56d98921010c6a560c33c67342
This commit is contained in:
@@ -66,9 +66,10 @@ interface IStream {
|
||||
* Retrieves basic stream configuration: sample rate, audio format,
|
||||
* channel mask.
|
||||
*
|
||||
* @return retval operation completion status.
|
||||
* @return config basic stream configuration.
|
||||
*/
|
||||
getAudioProperties() generates (AudioConfigBase config);
|
||||
getAudioProperties() generates (Result retval, AudioConfigBase config);
|
||||
|
||||
/**
|
||||
* Sets stream parameters. Only sets parameters that are specified.
|
||||
|
||||
@@ -125,13 +125,15 @@ cc_library_shared {
|
||||
}
|
||||
|
||||
cc_library_shared {
|
||||
enabled: false,
|
||||
name: "android.hardware.audio@7.0-impl",
|
||||
defaults: ["android.hardware.audio-impl_default"],
|
||||
shared_libs: [
|
||||
"android.hardware.audio@7.0",
|
||||
"android.hardware.audio.common@7.0",
|
||||
"android.hardware.audio.common@7.0-enums",
|
||||
"android.hardware.audio.common@7.0-util",
|
||||
"libbase",
|
||||
"libxml2",
|
||||
],
|
||||
cflags: [
|
||||
"-DMAJOR_VERSION=7",
|
||||
|
||||
@@ -18,8 +18,11 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if MAJOR_VERSION >= 7
|
||||
#include <android_audio_policy_configuration_V7_0-enums.h>
|
||||
#endif
|
||||
#include <HidlUtils.h>
|
||||
#include <log/log.h>
|
||||
#include <media/AudioContainers.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
@@ -27,73 +30,36 @@ namespace audio {
|
||||
namespace CPP_VERSION {
|
||||
namespace implementation {
|
||||
|
||||
// TODO(mnaganov): Use method from HidlUtils for V7
|
||||
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
|
||||
|
||||
#if MAJOR_VERSION <= 6
|
||||
std::string deviceAddressToHal(const DeviceAddress& address) {
|
||||
// HAL assumes that the address is NUL-terminated.
|
||||
audio_devices_t halDevice;
|
||||
char halAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
|
||||
memset(halAddress, 0, sizeof(halAddress));
|
||||
audio_devices_t halDevice = static_cast<audio_devices_t>(address.device);
|
||||
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 (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 (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 (halDevice == AUDIO_DEVICE_OUT_BUS || halDevice == AUDIO_DEVICE_IN_BUS) {
|
||||
snprintf(halAddress, sizeof(halAddress), "%s", address.busAddress.c_str());
|
||||
} else if (halDevice == AUDIO_DEVICE_OUT_REMOTE_SUBMIX ||
|
||||
halDevice == AUDIO_DEVICE_IN_REMOTE_SUBMIX) {
|
||||
snprintf(halAddress, sizeof(halAddress), "%s", address.rSubmixAddress.c_str());
|
||||
}
|
||||
(void)deviceAddressToHal(address, &halDevice, halAddress);
|
||||
return halAddress;
|
||||
}
|
||||
#endif
|
||||
|
||||
status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
|
||||
char* halDeviceAddress) {
|
||||
#if MAJOR_VERSION >= 5
|
||||
return HidlUtils::deviceAddressToHal(device, halDeviceType, halDeviceAddress);
|
||||
#else
|
||||
return HidlUtils::deviceAddressToHalImpl(device, halDeviceType, halDeviceAddress);
|
||||
#endif
|
||||
}
|
||||
|
||||
status_t deviceAddressFromHal(audio_devices_t halDeviceType, const char* halDeviceAddress,
|
||||
DeviceAddress* device) {
|
||||
#if MAJOR_VERSION >= 5
|
||||
return HidlUtils::deviceAddressFromHal(halDeviceType, halDeviceAddress, device);
|
||||
#else
|
||||
return HidlUtils::deviceAddressFromHalImpl(halDeviceType, halDeviceAddress, device);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if MAJOR_VERSION >= 4
|
||||
status_t deviceAddressFromHal(audio_devices_t device, const char* halAddress,
|
||||
DeviceAddress* address) {
|
||||
if (address == nullptr) {
|
||||
return BAD_VALUE;
|
||||
}
|
||||
address->device = AudioDevice(device);
|
||||
if (halAddress == nullptr || strnlen(halAddress, AUDIO_DEVICE_MAX_ADDRESS_LEN) == 0) {
|
||||
return OK;
|
||||
}
|
||||
|
||||
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 (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 (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 (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;
|
||||
}
|
||||
address->busAddress = halAddress;
|
||||
return OK;
|
||||
}
|
||||
|
||||
bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
|
||||
const struct audio_microphone_characteristic_t& src) {
|
||||
bool status = false;
|
||||
@@ -131,6 +97,44 @@ bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
|
||||
}
|
||||
return status;
|
||||
}
|
||||
#endif // MAJOR_VERSION >= 4
|
||||
|
||||
#if MAJOR_VERSION >= 7
|
||||
namespace xsd {
|
||||
using namespace ::android::audio::policy::configuration::V7_0;
|
||||
}
|
||||
|
||||
bool audioInputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_input_flags_t* halFlags) {
|
||||
bool success = true;
|
||||
*halFlags = {};
|
||||
for (const auto& flag : flags) {
|
||||
audio_input_flags_t halFlag;
|
||||
if (!xsd::isUnknownAudioInOutFlag(flag) &&
|
||||
audio_input_flag_from_string(flag.c_str(), &halFlag)) {
|
||||
*halFlags = static_cast<audio_input_flags_t>(*halFlags | halFlag);
|
||||
} else {
|
||||
ALOGE("Unknown audio input flag \"%s\"", flag.c_str());
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool audioOutputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_output_flags_t* halFlags) {
|
||||
bool success = true;
|
||||
*halFlags = {};
|
||||
for (const auto& flag : flags) {
|
||||
audio_output_flags_t halFlag;
|
||||
if (!xsd::isUnknownAudioInOutFlag(flag) &&
|
||||
audio_output_flag_from_string(flag.c_str(), &halFlag)) {
|
||||
*halFlags = static_cast<audio_output_flags_t>(*halFlags | halFlag);
|
||||
} else {
|
||||
ALOGE("Unknown audio output flag \"%s\"", flag.c_str());
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace implementation
|
||||
|
||||
@@ -150,63 +150,76 @@ Return<void> Device::getInputBufferSize(const AudioConfig& config, getInputBuffe
|
||||
std::tuple<Result, sp<IStreamOut>> Device::openOutputStreamImpl(int32_t ioHandle,
|
||||
const DeviceAddress& device,
|
||||
const AudioConfig& config,
|
||||
AudioOutputFlagBitfield flags,
|
||||
const AudioOutputFlags& flags,
|
||||
AudioConfig* suggestedConfig) {
|
||||
audio_config_t halConfig;
|
||||
HidlUtils::audioConfigToHal(config, &halConfig);
|
||||
audio_stream_out_t* halStream;
|
||||
ALOGV(
|
||||
"open_output_stream handle: %d devices: %x flags: %#x "
|
||||
"srate: %d format %#x channels %x address %s",
|
||||
ioHandle, static_cast<audio_devices_t>(device.device),
|
||||
static_cast<audio_output_flags_t>(flags), halConfig.sample_rate, halConfig.format,
|
||||
halConfig.channel_mask, deviceAddressToHal(device).c_str());
|
||||
int status =
|
||||
mDevice->open_output_stream(mDevice, ioHandle, static_cast<audio_devices_t>(device.device),
|
||||
static_cast<audio_output_flags_t>(flags), &halConfig,
|
||||
&halStream, deviceAddressToHal(device).c_str());
|
||||
audio_devices_t halDevice;
|
||||
char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
|
||||
if (deviceAddressToHal(device, &halDevice, halDeviceAddress) != NO_ERROR) {
|
||||
return {Result::INVALID_ARGUMENTS, nullptr};
|
||||
}
|
||||
audio_output_flags_t halFlags;
|
||||
if (!audioOutputFlagsToHal(flags, &halFlags)) {
|
||||
return {Result::INVALID_ARGUMENTS, nullptr};
|
||||
}
|
||||
ALOGV("open_output_stream handle: %d devices: %x flags: %#x "
|
||||
"srate: %d format %#x channels %x address %s",
|
||||
ioHandle, halDevice, halFlags, halConfig.sample_rate, halConfig.format,
|
||||
halConfig.channel_mask, halDeviceAddress);
|
||||
int status = mDevice->open_output_stream(mDevice, ioHandle, halDevice, halFlags, &halConfig,
|
||||
&halStream, halDeviceAddress);
|
||||
ALOGV("open_output_stream status %d stream %p", status, halStream);
|
||||
sp<IStreamOut> streamOut;
|
||||
if (status == OK) {
|
||||
streamOut = new StreamOut(this, halStream);
|
||||
++mOpenedStreamsCount;
|
||||
}
|
||||
status_t convertStatus = HidlUtils::audioConfigFromHal(halConfig, suggestedConfig);
|
||||
status_t convertStatus =
|
||||
HidlUtils::audioConfigFromHal(halConfig, false /*isInput*/, suggestedConfig);
|
||||
ALOGW_IF(convertStatus != OK, "%s: suggested config with incompatible fields", __func__);
|
||||
return {analyzeStatus("open_output_stream", status, {EINVAL} /*ignore*/), streamOut};
|
||||
}
|
||||
|
||||
std::tuple<Result, sp<IStreamIn>> Device::openInputStreamImpl(
|
||||
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
|
||||
AudioInputFlagBitfield flags, AudioSource source, AudioConfig* suggestedConfig) {
|
||||
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
|
||||
const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig) {
|
||||
audio_config_t halConfig;
|
||||
HidlUtils::audioConfigToHal(config, &halConfig);
|
||||
audio_stream_in_t* halStream;
|
||||
ALOGV(
|
||||
"open_input_stream handle: %d devices: %x flags: %#x "
|
||||
"srate: %d format %#x channels %x address %s source %d",
|
||||
ioHandle, static_cast<audio_devices_t>(device.device),
|
||||
static_cast<audio_input_flags_t>(flags), halConfig.sample_rate, halConfig.format,
|
||||
halConfig.channel_mask, deviceAddressToHal(device).c_str(),
|
||||
static_cast<audio_source_t>(source));
|
||||
int status = mDevice->open_input_stream(
|
||||
mDevice, ioHandle, static_cast<audio_devices_t>(device.device), &halConfig, &halStream,
|
||||
static_cast<audio_input_flags_t>(flags), deviceAddressToHal(device).c_str(),
|
||||
static_cast<audio_source_t>(source));
|
||||
audio_devices_t halDevice;
|
||||
char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
|
||||
if (deviceAddressToHal(device, &halDevice, halDeviceAddress) != NO_ERROR) {
|
||||
return {Result::INVALID_ARGUMENTS, nullptr};
|
||||
}
|
||||
audio_input_flags_t halFlags;
|
||||
audio_source_t halSource;
|
||||
if (!audioInputFlagsToHal(flags, &halFlags) ||
|
||||
HidlUtils::audioSourceToHal(source, &halSource) != NO_ERROR) {
|
||||
return {Result::INVALID_ARGUMENTS, nullptr};
|
||||
}
|
||||
ALOGV("open_input_stream handle: %d devices: %x flags: %#x "
|
||||
"srate: %d format %#x channels %x address %s source %d",
|
||||
ioHandle, halDevice, halFlags, halConfig.sample_rate, halConfig.format,
|
||||
halConfig.channel_mask, halDeviceAddress, halSource);
|
||||
int status = mDevice->open_input_stream(mDevice, ioHandle, halDevice, &halConfig, &halStream,
|
||||
halFlags, halDeviceAddress, halSource);
|
||||
ALOGV("open_input_stream status %d stream %p", status, halStream);
|
||||
sp<IStreamIn> streamIn;
|
||||
if (status == OK) {
|
||||
streamIn = new StreamIn(this, halStream);
|
||||
++mOpenedStreamsCount;
|
||||
}
|
||||
status_t convertStatus = HidlUtils::audioConfigFromHal(halConfig, suggestedConfig);
|
||||
status_t convertStatus =
|
||||
HidlUtils::audioConfigFromHal(halConfig, true /*isInput*/, suggestedConfig);
|
||||
ALOGW_IF(convertStatus != OK, "%s: suggested config with incompatible fields", __func__);
|
||||
return {analyzeStatus("open_input_stream", status, {EINVAL} /*ignore*/), streamIn};
|
||||
}
|
||||
|
||||
#if MAJOR_VERSION == 2
|
||||
Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioOutputFlagBitfield flags,
|
||||
const AudioConfig& config, AudioOutputFlags flags,
|
||||
openOutputStream_cb _hidl_cb) {
|
||||
AudioConfig suggestedConfig;
|
||||
auto [result, streamOut] =
|
||||
@@ -216,7 +229,7 @@ Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& dev
|
||||
}
|
||||
|
||||
Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
const AudioConfig& config, AudioInputFlags flags,
|
||||
AudioSource source, openInputStream_cb _hidl_cb) {
|
||||
AudioConfig suggestedConfig;
|
||||
auto [result, streamIn] =
|
||||
@@ -227,7 +240,12 @@ Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& devi
|
||||
|
||||
#elif MAJOR_VERSION >= 4
|
||||
Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioOutputFlagBitfield flags,
|
||||
const AudioConfig& config,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioOutputFlags flags,
|
||||
#else
|
||||
const AudioOutputFlags& flags,
|
||||
#endif
|
||||
const SourceMetadata& sourceMetadata,
|
||||
openOutputStream_cb _hidl_cb) {
|
||||
AudioConfig suggestedConfig;
|
||||
@@ -241,7 +259,12 @@ Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& dev
|
||||
}
|
||||
|
||||
Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
const AudioConfig& config,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioInputFlags flags,
|
||||
#else
|
||||
const AudioInputFlags& flags,
|
||||
#endif
|
||||
const SinkMetadata& sinkMetadata,
|
||||
openInputStream_cb _hidl_cb) {
|
||||
if (sinkMetadata.tracks.size() == 0) {
|
||||
@@ -271,9 +294,7 @@ Return<bool> Device::supportsAudioPatches() {
|
||||
Return<void> Device::createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks,
|
||||
createAudioPatch_cb _hidl_cb) {
|
||||
auto [retval, patch] = createOrUpdateAudioPatch(
|
||||
static_cast<AudioPatchHandle>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE), sources,
|
||||
sinks);
|
||||
auto [retval, patch] = createOrUpdateAudioPatch(AudioPatchHandle{}, sources, sinks);
|
||||
_hidl_cb(retval, patch);
|
||||
return Void();
|
||||
}
|
||||
@@ -454,7 +475,7 @@ Return<void> Device::updateAudioPatch(int32_t previousPatch,
|
||||
const hidl_vec<AudioPortConfig>& sources,
|
||||
const hidl_vec<AudioPortConfig>& sinks,
|
||||
createAudioPatch_cb _hidl_cb) {
|
||||
if (previousPatch != static_cast<int32_t>(AudioHandleConsts::AUDIO_PATCH_HANDLE_NONE)) {
|
||||
if (previousPatch != static_cast<int32_t>(AudioPatchHandle{})) {
|
||||
auto [retval, patch] = createOrUpdateAudioPatch(previousPatch, sources, sinks);
|
||||
_hidl_cb(retval, patch);
|
||||
} else {
|
||||
|
||||
@@ -149,9 +149,15 @@ Result ParametersUtil::setParametersImpl(const hidl_vec<ParameterValue>& context
|
||||
}
|
||||
return setParams(params);
|
||||
}
|
||||
|
||||
Result ParametersUtil::setParam(const char* name, const DeviceAddress& address) {
|
||||
AudioParameter params(String8(deviceAddressToHal(address).c_str()));
|
||||
params.addInt(String8(name), int(address.device));
|
||||
audio_devices_t halDeviceType;
|
||||
char halDeviceAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
|
||||
if (deviceAddressToHal(address, &halDeviceType, halDeviceAddress) != NO_ERROR) {
|
||||
return Result::INVALID_ARGUMENTS;
|
||||
}
|
||||
AudioParameter params{String8(halDeviceAddress)};
|
||||
params.addInt(String8(name), halDeviceType);
|
||||
return setParams(params);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,28 +73,36 @@ Return<void> PrimaryDevice::getInputBufferSize(const AudioConfig& config,
|
||||
|
||||
#if MAJOR_VERSION == 2
|
||||
Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config,
|
||||
AudioOutputFlagBitfield flags,
|
||||
const AudioConfig& config, AudioOutputFlags flags,
|
||||
openOutputStream_cb _hidl_cb) {
|
||||
return mDevice->openOutputStream(ioHandle, device, config, flags, _hidl_cb);
|
||||
}
|
||||
|
||||
Return<void> PrimaryDevice::openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
const AudioConfig& config, AudioInputFlags flags,
|
||||
AudioSource source, openInputStream_cb _hidl_cb) {
|
||||
return mDevice->openInputStream(ioHandle, device, config, flags, source, _hidl_cb);
|
||||
}
|
||||
#elif MAJOR_VERSION >= 4
|
||||
Return<void> PrimaryDevice::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config,
|
||||
AudioOutputFlagBitfield flags,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioOutputFlags flags,
|
||||
#else
|
||||
const AudioOutputFlags& flags,
|
||||
#endif
|
||||
const SourceMetadata& sourceMetadata,
|
||||
openOutputStream_cb _hidl_cb) {
|
||||
return mDevice->openOutputStream(ioHandle, device, config, flags, sourceMetadata, _hidl_cb);
|
||||
}
|
||||
|
||||
Return<void> PrimaryDevice::openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
const AudioConfig& config,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioInputFlags flags,
|
||||
#else
|
||||
const AudioInputFlags& flags,
|
||||
#endif
|
||||
const SinkMetadata& sinkMetadata,
|
||||
openInputStream_cb _hidl_cb) {
|
||||
return mDevice->openInputStream(ioHandle, device, config, flags, sinkMetadata, _hidl_cb);
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <HidlUtils.h>
|
||||
#include <android/log.h>
|
||||
#include <hardware/audio.h>
|
||||
#include <hardware/audio_effect.h>
|
||||
@@ -35,7 +36,11 @@ namespace audio {
|
||||
namespace CPP_VERSION {
|
||||
namespace implementation {
|
||||
|
||||
Stream::Stream(audio_stream_t* stream) : mStream(stream) {}
|
||||
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
|
||||
|
||||
Stream::Stream(bool isInput, audio_stream_t* stream) : mIsInput(isInput), mStream(stream) {
|
||||
(void)mIsInput; // prevent 'unused field' warnings in pre-V7 versions.
|
||||
}
|
||||
|
||||
Stream::~Stream() {
|
||||
mStream = nullptr;
|
||||
@@ -78,6 +83,7 @@ Return<uint64_t> Stream::getBufferSize() {
|
||||
return mStream->get_buffer_size(mStream);
|
||||
}
|
||||
|
||||
#if MAJOR_VERSION <= 6
|
||||
Return<uint32_t> Stream::getSampleRate() {
|
||||
return mStream->get_sample_rate(mStream);
|
||||
}
|
||||
@@ -201,6 +207,96 @@ Return<void> Stream::getAudioProperties(getAudioProperties_cb _hidl_cb) {
|
||||
return Void();
|
||||
}
|
||||
|
||||
#else // MAJOR_VERSION <= 6
|
||||
|
||||
Return<void> Stream::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
|
||||
String8 halListValue;
|
||||
Result result = getParam(AudioParameter::keyStreamSupportedFormats, &halListValue);
|
||||
hidl_vec<AudioProfile> profiles;
|
||||
if (result != Result::OK) {
|
||||
_hidl_cb(result, profiles);
|
||||
return Void();
|
||||
}
|
||||
// Ensure that the separator is one character, despite that it's defined as a C string.
|
||||
static_assert(sizeof(AUDIO_PARAMETER_VALUE_LIST_SEPARATOR) == 2);
|
||||
std::vector<std::string> halFormats =
|
||||
util::splitString(halListValue.string(), AUDIO_PARAMETER_VALUE_LIST_SEPARATOR[0]);
|
||||
hidl_vec<AudioFormat> formats;
|
||||
(void)HidlUtils::audioFormatsFromHal(halFormats, &formats);
|
||||
std::vector<AudioProfile> tempProfiles;
|
||||
for (const auto& format : formats) {
|
||||
audio_format_t halFormat;
|
||||
if (status_t status = HidlUtils::audioFormatToHal(format, &halFormat); status != NO_ERROR) {
|
||||
continue;
|
||||
}
|
||||
AudioParameter context;
|
||||
context.addInt(String8(AUDIO_PARAMETER_STREAM_FORMAT), int(halFormat));
|
||||
// Query supported sample rates for the format.
|
||||
result = getParam(AudioParameter::keyStreamSupportedSamplingRates, &halListValue, context);
|
||||
if (result != Result::OK) break;
|
||||
std::vector<std::string> halSampleRates =
|
||||
util::splitString(halListValue.string(), AUDIO_PARAMETER_VALUE_LIST_SEPARATOR[0]);
|
||||
hidl_vec<uint32_t> sampleRates;
|
||||
sampleRates.resize(halSampleRates.size());
|
||||
for (size_t i = 0; i < sampleRates.size(); ++i) {
|
||||
sampleRates[i] = std::stoi(halSampleRates[i]);
|
||||
}
|
||||
// Query supported channel masks for the format.
|
||||
result = getParam(AudioParameter::keyStreamSupportedChannels, &halListValue, context);
|
||||
if (result != Result::OK) break;
|
||||
std::vector<std::string> halChannelMasks =
|
||||
util::splitString(halListValue.string(), AUDIO_PARAMETER_VALUE_LIST_SEPARATOR[0]);
|
||||
hidl_vec<AudioChannelMask> channelMasks;
|
||||
(void)HidlUtils::audioChannelMasksFromHal(halChannelMasks, &channelMasks);
|
||||
// Create a profile.
|
||||
if (channelMasks.size() != 0 && sampleRates.size() != 0) {
|
||||
tempProfiles.push_back({.format = format,
|
||||
.sampleRates = std::move(sampleRates),
|
||||
.channelMasks = std::move(channelMasks)});
|
||||
}
|
||||
}
|
||||
// Legacy get_parameter does not return a status_t, thus can not advertise of failure.
|
||||
// Note that the method must not return an empty list if this capability is supported.
|
||||
if (!tempProfiles.empty()) {
|
||||
profiles = tempProfiles;
|
||||
} else {
|
||||
result = Result::NOT_SUPPORTED;
|
||||
}
|
||||
_hidl_cb(result, profiles);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<void> Stream::getAudioProperties(getAudioProperties_cb _hidl_cb) {
|
||||
audio_config_base_t halConfigBase = {mStream->get_sample_rate(mStream),
|
||||
mStream->get_channels(mStream),
|
||||
mStream->get_format(mStream)};
|
||||
AudioConfigBase configBase = {};
|
||||
status_t status = HidlUtils::audioConfigBaseFromHal(halConfigBase, mIsInput, &configBase);
|
||||
_hidl_cb(Stream::analyzeStatus("get_audio_properties", status), configBase);
|
||||
return Void();
|
||||
}
|
||||
|
||||
Return<Result> Stream::setAudioProperties(const AudioConfigBase& config) {
|
||||
audio_config_base_t halConfigBase = {};
|
||||
status_t status = HidlUtils::audioConfigBaseToHal(config, &halConfigBase);
|
||||
if (status != NO_ERROR) {
|
||||
return Stream::analyzeStatus("set_audio_properties", status);
|
||||
}
|
||||
if (Result result = setParam(AudioParameter::keySamplingRate,
|
||||
static_cast<int>(halConfigBase.sample_rate));
|
||||
result != Result::OK) {
|
||||
return result;
|
||||
}
|
||||
if (Result result =
|
||||
setParam(AudioParameter::keyChannels, static_cast<int>(halConfigBase.channel_mask));
|
||||
result != Result::OK) {
|
||||
return result;
|
||||
}
|
||||
return setParam(AudioParameter::keyFormat, static_cast<int>(halConfigBase.format));
|
||||
}
|
||||
|
||||
#endif // MAJOR_VERSION <= 6
|
||||
|
||||
Return<Result> Stream::addEffect(uint64_t effectId) {
|
||||
effect_handle_t halEffect = EffectMap::getInstance().get(effectId);
|
||||
if (halEffect != NULL) {
|
||||
@@ -257,12 +353,14 @@ Return<Result> Stream::setConnectedState(const DeviceAddress& address, bool conn
|
||||
}
|
||||
#elif MAJOR_VERSION >= 4
|
||||
Return<void> Stream::getDevices(getDevices_cb _hidl_cb) {
|
||||
int device = 0;
|
||||
Result retval = getParam(AudioParameter::keyRouting, &device);
|
||||
int halDevice = 0;
|
||||
Result retval = getParam(AudioParameter::keyRouting, &halDevice);
|
||||
hidl_vec<DeviceAddress> devices;
|
||||
if (retval == Result::OK) {
|
||||
devices.resize(1);
|
||||
devices[0].device = static_cast<AudioDevice>(device);
|
||||
retval = Stream::analyzeStatus("get_devices",
|
||||
deviceAddressFromHal(static_cast<audio_devices_t>(halDevice),
|
||||
nullptr, &devices[0]));
|
||||
}
|
||||
_hidl_cb(retval, devices);
|
||||
return Void();
|
||||
@@ -273,14 +371,13 @@ Return<Result> Stream::setDevices(const hidl_vec<DeviceAddress>& devices) {
|
||||
if (devices.size() > 1) {
|
||||
return Result::NOT_SUPPORTED;
|
||||
}
|
||||
DeviceAddress address;
|
||||
DeviceAddress address{};
|
||||
if (devices.size() == 1) {
|
||||
address = devices[0];
|
||||
} else {
|
||||
address.device = AudioDevice::NONE;
|
||||
}
|
||||
return setParam(AudioParameter::keyRouting, address);
|
||||
}
|
||||
|
||||
Return<void> Stream::getParameters(const hidl_vec<ParameterValue>& context,
|
||||
const hidl_vec<hidl_string>& keys, getParameters_cb _hidl_cb) {
|
||||
getParametersImpl(context, keys, _hidl_cb);
|
||||
|
||||
@@ -24,11 +24,12 @@
|
||||
//#define LOG_NDEBUG 0
|
||||
#define ATRACE_TAG ATRACE_TAG_AUDIO
|
||||
|
||||
#include <HidlUtils.h>
|
||||
#include <android/log.h>
|
||||
#include <hardware/audio.h>
|
||||
#include <utils/Trace.h>
|
||||
#include <memory>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
@@ -36,6 +37,8 @@ namespace audio {
|
||||
namespace CPP_VERSION {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
|
||||
|
||||
namespace {
|
||||
|
||||
class ReadThread : public Thread {
|
||||
@@ -141,7 +144,7 @@ bool ReadThread::threadLoop() {
|
||||
StreamIn::StreamIn(const sp<Device>& device, audio_stream_in_t* stream)
|
||||
: mDevice(device),
|
||||
mStream(stream),
|
||||
mStreamCommon(new Stream(&stream->common)),
|
||||
mStreamCommon(new Stream(true /*isInput*/, &stream->common)),
|
||||
mStreamMmap(new StreamMmap<audio_stream_in_t>(stream)),
|
||||
mEfGroup(nullptr),
|
||||
mStopReadThread(false) {}
|
||||
@@ -177,6 +180,7 @@ Return<uint64_t> StreamIn::getBufferSize() {
|
||||
return mStreamCommon->getBufferSize();
|
||||
}
|
||||
|
||||
#if MAJOR_VERSION <= 6
|
||||
Return<uint32_t> StreamIn::getSampleRate() {
|
||||
return mStreamCommon->getSampleRate();
|
||||
}
|
||||
@@ -223,6 +227,18 @@ Return<Result> StreamIn::setFormat(AudioFormat format) {
|
||||
return mStreamCommon->setFormat(format);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Return<void> StreamIn::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
|
||||
return mStreamCommon->getSupportedProfiles(_hidl_cb);
|
||||
}
|
||||
|
||||
Return<Result> StreamIn::setAudioProperties(const AudioConfigBase& config) {
|
||||
return mStreamCommon->setAudioProperties(config);
|
||||
}
|
||||
|
||||
#endif // MAJOR_VERSION <= 6
|
||||
|
||||
Return<void> StreamIn::getAudioProperties(getAudioProperties_cb _hidl_cb) {
|
||||
return mStreamCommon->getAudioProperties(_hidl_cb);
|
||||
}
|
||||
@@ -321,9 +337,11 @@ Return<Result> StreamIn::close() {
|
||||
Return<void> StreamIn::getAudioSource(getAudioSource_cb _hidl_cb) {
|
||||
int halSource;
|
||||
Result retval = mStreamCommon->getParam(AudioParameter::keyInputSource, &halSource);
|
||||
AudioSource source(AudioSource::DEFAULT);
|
||||
AudioSource source = {};
|
||||
if (retval == Result::OK) {
|
||||
source = AudioSource(halSource);
|
||||
retval = Stream::analyzeStatus(
|
||||
"get_audio_source",
|
||||
HidlUtils::audioSourceFromHal(static_cast<audio_source_t>(halSource), &source));
|
||||
}
|
||||
_hidl_cb(retval, source);
|
||||
return Void();
|
||||
@@ -340,7 +358,11 @@ Return<Result> StreamIn::setGain(float gain) {
|
||||
Return<void> StreamIn::prepareForReading(uint32_t frameSize, uint32_t framesCount,
|
||||
prepareForReading_cb _hidl_cb) {
|
||||
status_t status;
|
||||
#if MAJOR_VERSION <= 6
|
||||
ThreadInfo threadInfo = {0, 0};
|
||||
#else
|
||||
int32_t threadInfo = 0;
|
||||
#endif
|
||||
|
||||
// Wrap the _hidl_cb to return an error
|
||||
auto sendError = [&threadInfo, &_hidl_cb](Result result) {
|
||||
@@ -410,8 +432,12 @@ Return<void> StreamIn::prepareForReading(uint32_t frameSize, uint32_t framesCoun
|
||||
mStatusMQ = std::move(tempStatusMQ);
|
||||
mReadThread = tempReadThread.release();
|
||||
mEfGroup = tempElfGroup.release();
|
||||
#if MAJOR_VERSION <= 6
|
||||
threadInfo.pid = getpid();
|
||||
threadInfo.tid = mReadThread->getTid();
|
||||
#else
|
||||
threadInfo = mReadThread->getTid();
|
||||
#endif
|
||||
_hidl_cb(Result::OK, *mCommandMQ->getDesc(), *mDataMQ->getDesc(), *mStatusMQ->getDesc(),
|
||||
threadInfo);
|
||||
return Void();
|
||||
@@ -459,16 +485,13 @@ Return<void> StreamIn::updateSinkMetadata(const SinkMetadata& sinkMetadata) {
|
||||
std::vector<record_track_metadata> halTracks;
|
||||
halTracks.reserve(sinkMetadata.tracks.size());
|
||||
for (auto& metadata : sinkMetadata.tracks) {
|
||||
record_track_metadata halTrackMetadata = {
|
||||
.source = static_cast<audio_source_t>(metadata.source), .gain = metadata.gain};
|
||||
record_track_metadata halTrackMetadata = {.gain = metadata.gain};
|
||||
(void)HidlUtils::audioSourceToHal(metadata.source, &halTrackMetadata.source);
|
||||
#if MAJOR_VERSION >= 5
|
||||
if (metadata.destination.getDiscriminator() ==
|
||||
RecordTrackMetadata::Destination::hidl_discriminator::device) {
|
||||
halTrackMetadata.dest_device =
|
||||
static_cast<audio_devices_t>(metadata.destination.device().device);
|
||||
strncpy(halTrackMetadata.dest_device_address,
|
||||
deviceAddressToHal(metadata.destination.device()).c_str(),
|
||||
AUDIO_DEVICE_MAX_ADDRESS_LEN);
|
||||
(void)deviceAddressToHal(metadata.destination.device(), &halTrackMetadata.dest_device,
|
||||
halTrackMetadata.dest_device_address);
|
||||
}
|
||||
#endif
|
||||
halTracks.push_back(halTrackMetadata);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <HidlUtils.h>
|
||||
#include <android/log.h>
|
||||
#include <hardware/audio.h>
|
||||
#include <utils/Trace.h>
|
||||
@@ -36,6 +37,8 @@ namespace audio {
|
||||
namespace CPP_VERSION {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
|
||||
|
||||
namespace {
|
||||
|
||||
class WriteThread : public Thread {
|
||||
@@ -142,7 +145,7 @@ bool WriteThread::threadLoop() {
|
||||
StreamOut::StreamOut(const sp<Device>& device, audio_stream_out_t* stream)
|
||||
: mDevice(device),
|
||||
mStream(stream),
|
||||
mStreamCommon(new Stream(&stream->common)),
|
||||
mStreamCommon(new Stream(false /*isInput*/, &stream->common)),
|
||||
mStreamMmap(new StreamMmap<audio_stream_out_t>(stream)),
|
||||
mEfGroup(nullptr),
|
||||
mStopWriteThread(false) {}
|
||||
@@ -182,6 +185,7 @@ Return<uint64_t> StreamOut::getBufferSize() {
|
||||
return mStreamCommon->getBufferSize();
|
||||
}
|
||||
|
||||
#if MAJOR_VERSION <= 6
|
||||
Return<uint32_t> StreamOut::getSampleRate() {
|
||||
return mStreamCommon->getSampleRate();
|
||||
}
|
||||
@@ -228,6 +232,18 @@ Return<Result> StreamOut::setFormat(AudioFormat format) {
|
||||
return mStreamCommon->setFormat(format);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
Return<void> StreamOut::getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) {
|
||||
return mStreamCommon->getSupportedProfiles(_hidl_cb);
|
||||
}
|
||||
|
||||
Return<Result> StreamOut::setAudioProperties(const AudioConfigBase& config) {
|
||||
return mStreamCommon->setAudioProperties(config);
|
||||
}
|
||||
|
||||
#endif // MAJOR_VERSION <= 6
|
||||
|
||||
Return<void> StreamOut::getAudioProperties(getAudioProperties_cb _hidl_cb) {
|
||||
return mStreamCommon->getAudioProperties(_hidl_cb);
|
||||
}
|
||||
@@ -327,7 +343,11 @@ Return<Result> StreamOut::setVolume(float left, float right) {
|
||||
Return<void> StreamOut::prepareForWriting(uint32_t frameSize, uint32_t framesCount,
|
||||
prepareForWriting_cb _hidl_cb) {
|
||||
status_t status;
|
||||
#if MAJOR_VERSION <= 6
|
||||
ThreadInfo threadInfo = {0, 0};
|
||||
#else
|
||||
int32_t threadInfo = 0;
|
||||
#endif
|
||||
|
||||
// Wrap the _hidl_cb to return an error
|
||||
auto sendError = [&threadInfo, &_hidl_cb](Result result) {
|
||||
@@ -396,8 +416,12 @@ Return<void> StreamOut::prepareForWriting(uint32_t frameSize, uint32_t framesCou
|
||||
mStatusMQ = std::move(tempStatusMQ);
|
||||
mWriteThread = tempWriteThread.release();
|
||||
mEfGroup = tempElfGroup.release();
|
||||
#if MAJOR_VERSION <= 6
|
||||
threadInfo.pid = getpid();
|
||||
threadInfo.tid = mWriteThread->getTid();
|
||||
#else
|
||||
threadInfo = mWriteThread->getTid();
|
||||
#endif
|
||||
_hidl_cb(Result::OK, *mCommandMQ->getDesc(), *mDataMQ->getDesc(), *mStatusMQ->getDesc(),
|
||||
threadInfo);
|
||||
return Void();
|
||||
@@ -565,14 +589,14 @@ Return<void> StreamOut::updateSourceMetadata(const SourceMetadata& sourceMetadat
|
||||
if (mStream->update_source_metadata == nullptr) {
|
||||
return Void(); // not supported by the HAL
|
||||
}
|
||||
std::vector<playback_track_metadata> halTracks;
|
||||
std::vector<playback_track_metadata_t> halTracks;
|
||||
halTracks.reserve(sourceMetadata.tracks.size());
|
||||
for (auto& metadata : sourceMetadata.tracks) {
|
||||
halTracks.push_back({
|
||||
.usage = static_cast<audio_usage_t>(metadata.usage),
|
||||
.content_type = static_cast<audio_content_type_t>(metadata.contentType),
|
||||
.gain = metadata.gain,
|
||||
});
|
||||
playback_track_metadata_t halTrackMetadata = {.gain = metadata.gain};
|
||||
(void)HidlUtils::audioUsageToHal(metadata.usage, &halTrackMetadata.usage);
|
||||
(void)HidlUtils::audioContentTypeToHal(metadata.contentType,
|
||||
&halTrackMetadata.content_type);
|
||||
halTracks.push_back(std::move(halTrackMetadata));
|
||||
}
|
||||
const source_metadata_t halMetadata = {
|
||||
.track_count = halTracks.size(),
|
||||
|
||||
@@ -23,22 +23,54 @@
|
||||
|
||||
#include <system/audio.h>
|
||||
|
||||
#include <VersionUtils.h>
|
||||
|
||||
namespace android {
|
||||
namespace hardware {
|
||||
namespace audio {
|
||||
namespace CPP_VERSION {
|
||||
namespace implementation {
|
||||
|
||||
using ::android::hardware::hidl_vec;
|
||||
using namespace ::android::hardware::audio::common::CPP_VERSION;
|
||||
using namespace ::android::hardware::audio::CPP_VERSION;
|
||||
|
||||
#if MAJOR_VERSION <= 6
|
||||
// Temporary version for compatibility with forks of the default implementation.
|
||||
// Will be removed, do not use!
|
||||
std::string deviceAddressToHal(const DeviceAddress& address);
|
||||
#endif
|
||||
|
||||
status_t deviceAddressToHal(const DeviceAddress& device, audio_devices_t* halDeviceType,
|
||||
char* halDeviceAddress);
|
||||
status_t deviceAddressFromHal(audio_devices_t halDeviceType, const char* halDeviceAddress,
|
||||
DeviceAddress* device);
|
||||
|
||||
#if MAJOR_VERSION >= 4
|
||||
bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
|
||||
const struct audio_microphone_characteristic_t& src);
|
||||
#endif
|
||||
|
||||
#if MAJOR_VERSION <= 6
|
||||
using AudioInputFlags =
|
||||
::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield;
|
||||
using AudioOutputFlags =
|
||||
::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield;
|
||||
|
||||
inline bool audioInputFlagsToHal(AudioInputFlags flags, audio_input_flags_t* halFlags) {
|
||||
*halFlags = static_cast<audio_input_flags_t>(flags);
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool audioOutputFlagsToHal(AudioOutputFlags flags, audio_output_flags_t* halFlags) {
|
||||
*halFlags = static_cast<audio_output_flags_t>(flags);
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
bool audioInputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_input_flags_t* halFlags);
|
||||
bool audioOutputFlagsToHal(const hidl_vec<AudioInOutFlag>& flags, audio_output_flags_t* halFlags);
|
||||
#endif
|
||||
|
||||
} // namespace implementation
|
||||
} // namespace CPP_VERSION
|
||||
} // namespace audio
|
||||
|
||||
@@ -44,8 +44,13 @@ using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
#if MAJOR_VERSION <= 6
|
||||
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield;
|
||||
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield;
|
||||
using AudioInputFlags =
|
||||
::android::hardware::audio::common::CPP_VERSION::implementation::AudioInputFlagBitfield;
|
||||
using AudioOutputFlags =
|
||||
::android::hardware::audio::common::CPP_VERSION::implementation::AudioOutputFlagBitfield;
|
||||
#else
|
||||
using AudioInputFlags = hidl_vec<::android::hardware::audio::CPP_VERSION::AudioInOutFlag>;
|
||||
using AudioOutputFlags = hidl_vec<::android::hardware::audio::CPP_VERSION::AudioInOutFlag>;
|
||||
#endif
|
||||
using namespace ::android::hardware::audio::common::CPP_VERSION;
|
||||
using namespace ::android::hardware::audio::CPP_VERSION;
|
||||
@@ -67,28 +72,36 @@ struct Device : public IDevice, public ParametersUtil {
|
||||
std::tuple<Result, sp<IStreamOut>> openOutputStreamImpl(int32_t ioHandle,
|
||||
const DeviceAddress& device,
|
||||
const AudioConfig& config,
|
||||
AudioOutputFlagBitfield flags,
|
||||
const AudioOutputFlags& flags,
|
||||
AudioConfig* suggestedConfig);
|
||||
std::tuple<Result, sp<IStreamIn>> openInputStreamImpl(
|
||||
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
|
||||
AudioInputFlagBitfield flags, AudioSource source, AudioConfig* suggestedConfig);
|
||||
#if MAJOR_VERSION == 2
|
||||
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
|
||||
const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig);
|
||||
|
||||
Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioOutputFlagBitfield flags,
|
||||
openOutputStream_cb _hidl_cb) override;
|
||||
Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
AudioSource source, openInputStream_cb _hidl_cb) override;
|
||||
#elif MAJOR_VERSION >= 4
|
||||
Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioOutputFlagBitfield flags,
|
||||
const SourceMetadata& sourceMetadata,
|
||||
openOutputStream_cb _hidl_cb) override;
|
||||
Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
const SinkMetadata& sinkMetadata,
|
||||
openInputStream_cb _hidl_cb) override;
|
||||
const AudioConfig& config,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioOutputFlags flags,
|
||||
#else
|
||||
const AudioOutputFlags& flags,
|
||||
#endif
|
||||
#if MAJOR_VERSION >= 4
|
||||
const SourceMetadata& sourceMetadata,
|
||||
#endif
|
||||
openOutputStream_cb _hidl_cb) override;
|
||||
Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioInputFlags flags,
|
||||
#else
|
||||
const AudioInputFlags& flags,
|
||||
#endif
|
||||
#if MAJOR_VERSION == 2
|
||||
AudioSource source,
|
||||
#elif MAJOR_VERSION >= 4
|
||||
const SinkMetadata& sinkMetadata,
|
||||
#endif
|
||||
openInputStream_cb _hidl_cb) override;
|
||||
|
||||
Return<bool> supportsAudioPatches() override;
|
||||
Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
|
||||
|
||||
@@ -54,21 +54,29 @@ struct PrimaryDevice : public IPrimaryDevice {
|
||||
getInputBufferSize_cb _hidl_cb) override;
|
||||
|
||||
Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioOutputFlagBitfield flags,
|
||||
const AudioConfig& config,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioOutputFlags flags,
|
||||
#else
|
||||
const AudioOutputFlags& flags,
|
||||
#endif
|
||||
#if MAJOR_VERSION >= 4
|
||||
const SourceMetadata& sourceMetadata,
|
||||
#endif
|
||||
openOutputStream_cb _hidl_cb) override;
|
||||
|
||||
Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
AudioSource source, openInputStream_cb _hidl_cb);
|
||||
#if MAJOR_VERSION >= 4
|
||||
Return<void> openInputStream(int32_t ioHandle, const DeviceAddress& device,
|
||||
const AudioConfig& config, AudioInputFlagBitfield flags,
|
||||
const SinkMetadata& sinkMetadata,
|
||||
openInputStream_cb _hidl_cb) override;
|
||||
const AudioConfig& config,
|
||||
#if MAJOR_VERSION <= 6
|
||||
AudioInputFlags flags,
|
||||
#else
|
||||
const AudioInputFlags& flags,
|
||||
#endif
|
||||
#if MAJOR_VERSION == 2
|
||||
AudioSource source,
|
||||
#elif MAJOR_VERSION >= 4
|
||||
const SinkMetadata& sinkMetadata,
|
||||
#endif
|
||||
openInputStream_cb _hidl_cb) override;
|
||||
|
||||
Return<bool> supportsAudioPatches() override;
|
||||
Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
|
||||
|
||||
@@ -41,12 +41,14 @@ using ::android::hardware::hidl_string;
|
||||
using ::android::hardware::hidl_vec;
|
||||
using ::android::hardware::Return;
|
||||
using ::android::hardware::Void;
|
||||
#if MAJOR_VERSION <= 6
|
||||
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioChannelBitfield;
|
||||
#endif
|
||||
using namespace ::android::hardware::audio::common::CPP_VERSION;
|
||||
using namespace ::android::hardware::audio::CPP_VERSION;
|
||||
|
||||
struct Stream : public IStream, public ParametersUtil {
|
||||
explicit Stream(audio_stream_t* stream);
|
||||
Stream(bool isInput, audio_stream_t* stream);
|
||||
|
||||
/** 1GiB is the maximum buffer size the HAL client is allowed to request.
|
||||
* This value has been chosen to be under SIZE_MAX and still big enough
|
||||
@@ -59,6 +61,7 @@ struct Stream : public IStream, public ParametersUtil {
|
||||
Return<uint64_t> getFrameSize() override;
|
||||
Return<uint64_t> getFrameCount() override;
|
||||
Return<uint64_t> getBufferSize() override;
|
||||
#if MAJOR_VERSION <= 6
|
||||
Return<uint32_t> getSampleRate() override;
|
||||
#if MAJOR_VERSION == 2
|
||||
Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
|
||||
@@ -72,6 +75,10 @@ struct Stream : public IStream, public ParametersUtil {
|
||||
Return<AudioFormat> getFormat() override;
|
||||
Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
|
||||
Return<Result> setFormat(AudioFormat format) override;
|
||||
#else
|
||||
Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override;
|
||||
Return<Result> setAudioProperties(const AudioConfigBase& config) override;
|
||||
#endif // MAJOR_VERSION <= 6
|
||||
Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
|
||||
Return<Result> addEffect(uint64_t effectId) override;
|
||||
Return<Result> removeEffect(uint64_t effectId) override;
|
||||
@@ -110,13 +117,14 @@ struct Stream : public IStream, public ParametersUtil {
|
||||
const std::vector<int>& ignoreErrors);
|
||||
|
||||
private:
|
||||
audio_stream_t* mStream;
|
||||
const bool mIsInput;
|
||||
audio_stream_t* mStream;
|
||||
|
||||
virtual ~Stream();
|
||||
virtual ~Stream();
|
||||
|
||||
// Methods from ParametersUtil.
|
||||
char* halGetParameters(const char* keys) override;
|
||||
int halSetParameters(const char* keysAndValues) override;
|
||||
// Methods from ParametersUtil.
|
||||
char* halGetParameters(const char* keys) override;
|
||||
int halSetParameters(const char* keysAndValues) override;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
||||
@@ -56,6 +56,7 @@ struct StreamIn : public IStreamIn {
|
||||
Return<uint64_t> getFrameSize() override;
|
||||
Return<uint64_t> getFrameCount() override;
|
||||
Return<uint64_t> getBufferSize() override;
|
||||
#if MAJOR_VERSION <= 6
|
||||
Return<uint32_t> getSampleRate() override;
|
||||
#if MAJOR_VERSION == 2
|
||||
Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
|
||||
@@ -69,6 +70,10 @@ struct StreamIn : public IStreamIn {
|
||||
Return<AudioFormat> getFormat() override;
|
||||
Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
|
||||
Return<Result> setFormat(AudioFormat format) override;
|
||||
#else
|
||||
Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override;
|
||||
Return<Result> setAudioProperties(const AudioConfigBase& config) override;
|
||||
#endif // MAJOR_VERSION <= 6
|
||||
Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
|
||||
Return<Result> addEffect(uint64_t effectId) override;
|
||||
Return<Result> removeEffect(uint64_t effectId) override;
|
||||
|
||||
@@ -56,6 +56,7 @@ struct StreamOut : public IStreamOut {
|
||||
Return<uint64_t> getFrameSize() override;
|
||||
Return<uint64_t> getFrameCount() override;
|
||||
Return<uint64_t> getBufferSize() override;
|
||||
#if MAJOR_VERSION <= 6
|
||||
Return<uint32_t> getSampleRate() override;
|
||||
#if MAJOR_VERSION == 2
|
||||
Return<void> getSupportedSampleRates(getSupportedSampleRates_cb _hidl_cb) override;
|
||||
@@ -69,6 +70,10 @@ struct StreamOut : public IStreamOut {
|
||||
Return<AudioFormat> getFormat() override;
|
||||
Return<void> getSupportedFormats(getSupportedFormats_cb _hidl_cb) override;
|
||||
Return<Result> setFormat(AudioFormat format) override;
|
||||
#else
|
||||
Return<void> getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override;
|
||||
Return<Result> setAudioProperties(const AudioConfigBase& config) override;
|
||||
#endif // MAJOR_VERSION <= 6
|
||||
Return<void> getAudioProperties(getAudioProperties_cb _hidl_cb) override;
|
||||
Return<Result> addEffect(uint64_t effectId) override;
|
||||
Return<Result> removeEffect(uint64_t effectId) override;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#include PATH(android/hardware/audio/FILE_VERSION/types.h)
|
||||
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <system/audio.h>
|
||||
@@ -70,6 +72,16 @@ static inline Result analyzeStatus(const char* className, const char* funcName,
|
||||
return analyzeStatus(status);
|
||||
}
|
||||
|
||||
static inline std::vector<std::string> splitString(const std::string& s, char separator) {
|
||||
std::istringstream iss(s);
|
||||
std::string t;
|
||||
std::vector<std::string> result;
|
||||
while (std::getline(iss, t, separator)) {
|
||||
result.push_back(std::move(t));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace util
|
||||
} // namespace implementation
|
||||
} // namespace CPP_VERSION
|
||||
|
||||
@@ -1179,9 +1179,11 @@ static void testGetAudioProperties(IStream* stream, AudioConfig expectedConfig)
|
||||
EXPECT_EQ(expectedConfig.channelMask, mask);
|
||||
EXPECT_EQ(expectedConfig.format, format);
|
||||
#elif MAJOR_VERSION >= 7
|
||||
Result res;
|
||||
AudioConfigBase actualConfig{};
|
||||
auto ret = stream->getAudioProperties(returnIn(actualConfig));
|
||||
auto ret = stream->getAudioProperties(returnIn(res, actualConfig));
|
||||
EXPECT_TRUE(ret.isOk());
|
||||
EXPECT_EQ(Result::OK, res);
|
||||
EXPECT_EQ(expectedConfig.base.sampleRateHz, actualConfig.sampleRateHz);
|
||||
EXPECT_EQ(expectedConfig.base.channelMask, actualConfig.channelMask);
|
||||
EXPECT_EQ(expectedConfig.base.format, actualConfig.format);
|
||||
|
||||
Reference in New Issue
Block a user