sm7125-common: Rebase custom audio impl

Change-Id: I22e67b1245d8c890b5f72340d456b5f89045b8b6
tirimbino
LuK1337 2 years ago committed by Ruchit Marathe
parent 89fa89330f
commit 8d6e01b8ba
  1. 23
      audio/Android.bp
  2. 108
      audio/Device.cpp
  3. 38
      audio/DevicesFactory.cpp
  4. 4
      audio/ParametersUtil.cpp
  5. 8
      audio/PrimaryDevice.cpp
  6. 6
      audio/Stream.cpp
  7. 8
      audio/StreamIn.cpp
  8. 75
      audio/StreamOut.cpp
  9. 48
      audio/include/core/default/Conversions.h
  10. 37
      audio/include/core/default/Device.h
  11. 8
      audio/include/core/default/DevicesFactory.h
  12. 13
      audio/include/core/default/ParametersUtil.h
  13. 9
      audio/include/core/default/PrimaryDevice.h
  14. 11
      audio/include/core/default/Stream.h
  15. 7
      audio/include/core/default/StreamIn.h
  16. 15
      audio/include/core/default/StreamOut.h
  17. 16
      audio/include/core/default/Util.h

@ -48,7 +48,6 @@ cc_defaults {
header_libs: [
"android.hardware.audio-impl_sm7125_headers",
"android.hardware.audio.common.util@all-versions",
"libaudioclient_headers",
"libaudioutils_headers",
"libaudio_system_headers",
"libhardware_headers",
@ -148,3 +147,25 @@ cc_library_shared {
"-include common/all-versions/VersionMacro.h",
],
}
cc_library_shared {
name: "android.hardware.audio@7.1-impl.sm7125",
defaults: ["android.hardware.audio-impl_sm7125"],
shared_libs: [
"android.hardware.audio@7.0",
"android.hardware.audio@7.1",
"android.hardware.audio@7.1-util",
"android.hardware.audio.common@7.0",
"android.hardware.audio.common@7.1-enums",
"android.hardware.audio.common@7.1-util",
"libbase",
"libcutils",
],
cflags: [
"-DMAJOR_VERSION=7",
"-DMINOR_VERSION=1",
"-DCOMMON_TYPES_MINOR_VERSION=0",
"-DCORE_TYPES_MINOR_VERSION=0",
"-include common/all-versions/VersionMacro.h",
],
}

@ -41,7 +41,10 @@ namespace audio {
namespace CPP_VERSION {
namespace implementation {
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
namespace util {
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::util;
}
Device::Device(audio_hw_device_t* device) : mIsClosed(false), mDevice(device) {}
@ -84,7 +87,7 @@ Return<Result> Device::setMasterVolume(float volume) {
if (mDevice->set_master_volume == NULL) {
return Result::NOT_SUPPORTED;
}
if (!isGainNormalized(volume)) {
if (!util::isGainNormalized(volume)) {
ALOGW("Can not set a master volume (%f) outside [0,1]", volume);
return Result::INVALID_ARGUMENTS;
}
@ -150,7 +153,7 @@ Return<void> Device::getInputBufferSize(const AudioConfig& config, getInputBuffe
return Void();
}
std::tuple<Result, sp<IStreamOut>> Device::openOutputStreamImpl(int32_t ioHandle,
std::tuple<Result, sp<IStreamOut>> Device::openOutputStreamCore(int32_t ioHandle,
const DeviceAddress& device,
const AudioConfig& config,
const AudioOutputFlags& flags,
@ -187,7 +190,7 @@ std::tuple<Result, sp<IStreamOut>> Device::openOutputStreamImpl(int32_t ioHandle
return {analyzeStatus("open_output_stream", status, {EINVAL} /*ignore*/), streamOut};
}
std::tuple<Result, sp<IStreamIn>> Device::openInputStreamImpl(
std::tuple<Result, sp<IStreamIn>> Device::openInputStreamCore(
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig) {
audio_config_t halConfig;
@ -230,7 +233,7 @@ Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& dev
openOutputStream_cb _hidl_cb) {
AudioConfig suggestedConfig;
auto [result, streamOut] =
openOutputStreamImpl(ioHandle, device, config, flags, &suggestedConfig);
openOutputStreamCore(ioHandle, device, config, flags, &suggestedConfig);
_hidl_cb(result, streamOut, suggestedConfig);
return Void();
}
@ -240,57 +243,64 @@ Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& devi
AudioSource source, openInputStream_cb _hidl_cb) {
AudioConfig suggestedConfig;
auto [result, streamIn] =
openInputStreamImpl(ioHandle, device, config, flags, source, &suggestedConfig);
openInputStreamCore(ioHandle, device, config, flags, source, &suggestedConfig);
_hidl_cb(result, streamIn, suggestedConfig);
return Void();
}
#elif MAJOR_VERSION >= 4
Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config,
#if MAJOR_VERSION <= 6
AudioOutputFlags flags,
#else
const AudioOutputFlags& flags,
#endif
const SourceMetadata& sourceMetadata,
openOutputStream_cb _hidl_cb) {
std::tuple<Result, sp<IStreamOut>, AudioConfig> Device::openOutputStreamImpl(
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
const SourceMetadata& sourceMetadata,
#if MAJOR_VERSION <= 6
AudioOutputFlags flags) {
if (status_t status = CoreUtils::sourceMetadataToHal(sourceMetadata, nullptr);
status != NO_ERROR) {
#else
const AudioOutputFlags& flags) {
if (status_t status = CoreUtils::sourceMetadataToHalV7(sourceMetadata,
false /*ignoreNonVendorTags*/, nullptr);
status != NO_ERROR) {
#endif
_hidl_cb(analyzeStatus("sourceMetadataToHal", status), nullptr, AudioConfig{});
return Void();
return {analyzeStatus("sourceMetadataToHal", status), nullptr, {}};
}
AudioConfig suggestedConfig;
auto [result, streamOut] =
openOutputStreamImpl(ioHandle, device, config, flags, &suggestedConfig);
openOutputStreamCore(ioHandle, device, config, flags, &suggestedConfig);
if (streamOut) {
streamOut->updateSourceMetadata(sourceMetadata);
}
return {result, streamOut, suggestedConfig};
}
Return<void> Device::openOutputStream(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config,
#if MAJOR_VERSION <= 6
AudioOutputFlags flags,
#else
const AudioOutputFlags& flags,
#endif
const SourceMetadata& sourceMetadata,
openOutputStream_cb _hidl_cb) {
auto [result, streamOut, suggestedConfig] =
openOutputStreamImpl(ioHandle, device, config, sourceMetadata, flags);
_hidl_cb(result, streamOut, suggestedConfig);
return Void();
}
Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config,
std::tuple<Result, sp<IStreamIn>, AudioConfig> Device::openInputStreamImpl(
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
#if MAJOR_VERSION <= 6
AudioInputFlags flags,
AudioInputFlags flags,
#else
const AudioInputFlags& flags,
const AudioInputFlags& flags,
#endif
const SinkMetadata& sinkMetadata,
openInputStream_cb _hidl_cb) {
const SinkMetadata& sinkMetadata) {
if (sinkMetadata.tracks.size() == 0) {
// This should never happen, the framework must not create as stream
// if there is no client
ALOGE("openInputStream called without tracks connected");
_hidl_cb(Result::INVALID_ARGUMENTS, nullptr, AudioConfig{});
return Void();
return {Result::INVALID_ARGUMENTS, nullptr, AudioConfig{}};
}
#if MAJOR_VERSION <= 6
if (status_t status = CoreUtils::sinkMetadataToHal(sinkMetadata, nullptr); status != NO_ERROR) {
@ -299,22 +309,47 @@ Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& devi
false /*ignoreNonVendorTags*/, nullptr);
status != NO_ERROR) {
#endif
_hidl_cb(analyzeStatus("sinkMetadataToHal", status), nullptr, AudioConfig{});
return Void();
return {analyzeStatus("sinkMetadataToHal", status), nullptr, AudioConfig{}};
}
// Pick the first one as the main.
AudioSource source = sinkMetadata.tracks[0].source;
AudioConfig suggestedConfig;
auto [result, streamIn] =
openInputStreamImpl(ioHandle, device, config, flags, source, &suggestedConfig);
openInputStreamCore(ioHandle, device, config, flags, source, &suggestedConfig);
if (streamIn) {
streamIn->updateSinkMetadata(sinkMetadata);
}
return {result, streamIn, suggestedConfig};
}
Return<void> Device::openInputStream(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config,
#if MAJOR_VERSION <= 6
AudioInputFlags flags,
#else
const AudioInputFlags& flags,
#endif
const SinkMetadata& sinkMetadata,
openInputStream_cb _hidl_cb) {
auto [result, streamIn, suggestedConfig] =
openInputStreamImpl(ioHandle, device, config, flags, sinkMetadata);
_hidl_cb(result, streamIn, suggestedConfig);
return Void();
}
#endif /* MAJOR_VERSION */
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<void> Device::openOutputStream_7_1(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config, const AudioOutputFlags& flags,
const SourceMetadata& sourceMetadata,
openOutputStream_7_1_cb _hidl_cb) {
auto [result, streamOut, suggestedConfig] =
openOutputStreamImpl(ioHandle, device, config, sourceMetadata, flags);
_hidl_cb(result, streamOut, suggestedConfig);
return Void();
}
#endif // V7.1
Return<bool> Device::supportsAudioPatches() {
return version() >= AUDIO_DEVICE_API_VERSION_3_0;
}
@ -575,6 +610,21 @@ Return<void> Device::updateAudioPatch(int32_t previousPatch,
#endif
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<Result> Device::setConnectedState_7_1(const AudioPort& devicePort, bool connected) {
if (version() >= AUDIO_DEVICE_API_VERSION_3_2 &&
mDevice->set_device_connected_state_v7 != nullptr) {
audio_port_v7 halPort;
if (status_t status = HidlUtils::audioPortToHal(devicePort, &halPort); status != NO_ERROR) {
return analyzeStatus("audioPortToHal", status);
}
return analyzeStatus("set_device_connected_state_v7",
mDevice->set_device_connected_state_v7(mDevice, &halPort, connected));
}
return Result::NOT_SUPPORTED;
}
#endif
} // namespace implementation
} // namespace CPP_VERSION
} // namespace audio

@ -47,21 +47,53 @@ Return<void> DevicesFactory::openDevice(IDevicesFactory::Device device, openDevi
_hidl_cb(Result::INVALID_ARGUMENTS, nullptr);
return Void();
}
Return<void> DevicesFactory::openDevice(const char* moduleName, openDevice_cb _hidl_cb) {
return openDevice<implementation::Device>(moduleName, _hidl_cb);
}
#elif MAJOR_VERSION >= 4
Return<void> DevicesFactory::openDevice(const hidl_string& moduleName, openDevice_cb _hidl_cb) {
if (moduleName == AUDIO_HARDWARE_MODULE_ID_PRIMARY) {
return openDevice<PrimaryDevice>(moduleName.c_str(), _hidl_cb);
}
return openDevice(moduleName.c_str(), _hidl_cb);
return openDevice<implementation::Device>(moduleName.c_str(), _hidl_cb);
}
Return<void> DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) {
return openDevice<PrimaryDevice>(AUDIO_HARDWARE_MODULE_ID_PRIMARY, _hidl_cb);
}
#endif
Return<void> DevicesFactory::openDevice(const char* moduleName, openDevice_cb _hidl_cb) {
return openDevice<implementation::Device>(moduleName, _hidl_cb);
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<void> DevicesFactory::openDevice_7_1(const hidl_string& moduleName,
openDevice_7_1_cb _hidl_cb) {
if (moduleName == AUDIO_HARDWARE_MODULE_ID_PRIMARY) {
Result result;
sp<IPrimaryDevice> primary;
auto ret = openDevice<PrimaryDevice>(
AUDIO_HARDWARE_MODULE_ID_PRIMARY,
[&result, &primary](Result r, const sp<IPrimaryDevice>& p) {
result = r;
primary = p;
});
if (ret.isOk() && result == Result::OK && primary != nullptr) {
auto getDeviceRet = primary->getDevice();
if (getDeviceRet.isOk()) {
_hidl_cb(result, getDeviceRet);
} else {
_hidl_cb(Result::NOT_INITIALIZED, nullptr);
}
} else {
_hidl_cb(result, nullptr);
}
return Void();
}
return openDevice<implementation::Device>(moduleName.c_str(), _hidl_cb);
}
Return<void> DevicesFactory::openPrimaryDevice_7_1(openPrimaryDevice_7_1_cb _hidl_cb) {
return openDevice<PrimaryDevice>(AUDIO_HARDWARE_MODULE_ID_PRIMARY, _hidl_cb);
}
#endif // V7.1
template <class DeviceShim, class Callback>
Return<void> DevicesFactory::openDevice(const char* moduleName, Callback _hidl_cb) {

@ -24,7 +24,7 @@
namespace android {
namespace hardware {
namespace audio {
namespace CPP_VERSION {
namespace CORE_TYPES_CPP_VERSION {
namespace implementation {
/** Converts a status_t in Result according to the rules of AudioParameter::get*
@ -172,7 +172,7 @@ Result ParametersUtil::setParams(const AudioParameter& param) {
}
} // namespace implementation
} // namespace CPP_VERSION
} // namespace CORE_TYPES_CPP_VERSION
} // namespace audio
} // namespace hardware
} // namespace android

@ -34,6 +34,10 @@ namespace audio {
namespace CPP_VERSION {
namespace implementation {
namespace util {
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::util;
}
PrimaryDevice::PrimaryDevice(audio_hw_device_t* device) : mDevice(new Device(device)) {}
PrimaryDevice::~PrimaryDevice() {
@ -200,7 +204,7 @@ Return<void> PrimaryDevice::updateAudioPatch(int32_t previousPatch,
// Methods from ::android::hardware::audio::CPP_VERSION::IPrimaryDevice follow.
Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
if (!isGainNormalized(volume)) {
if (!util::isGainNormalized(volume)) {
ALOGW("Can not set a voice volume (%f) outside [0,1]", volume);
return Result::INVALID_ARGUMENTS;
}
@ -364,7 +368,7 @@ Return<Result> PrimaryDevice::setBtHfpSampleRate(uint32_t sampleRateHz) {
return mDevice->setParam(AUDIO_PARAMETER_KEY_HFP_SET_SAMPLING_RATE, int(sampleRateHz));
}
Return<Result> PrimaryDevice::setBtHfpVolume(float volume) {
if (!isGainNormalized(volume)) {
if (!util::isGainNormalized(volume)) {
ALOGW("Can not set BT HFP volume (%f) outside [0,1]", volume);
return Result::INVALID_ARGUMENTS;
}

@ -37,8 +37,12 @@ namespace audio {
namespace CPP_VERSION {
namespace implementation {
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::common::utils::splitString;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
namespace util {
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::util;
}
Stream::Stream(bool isInput, audio_stream_t* stream) : mIsInput(isInput), mStream(stream) {
(void)mIsInput; // prevent 'unused field' warnings in pre-V7 versions.

@ -37,7 +37,11 @@ namespace audio {
namespace CPP_VERSION {
namespace implementation {
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
namespace util {
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::util;
}
namespace {
@ -348,7 +352,7 @@ Return<void> StreamIn::getAudioSource(getAudioSource_cb _hidl_cb) {
}
Return<Result> StreamIn::setGain(float gain) {
if (!isGainNormalized(gain)) {
if (!util::isGainNormalized(gain)) {
ALOGW("Can not set a stream input gain (%f) outside [0,1]", gain);
return Result::INVALID_ARGUMENTS;
}

@ -39,7 +39,11 @@ namespace audio {
namespace CPP_VERSION {
namespace implementation {
using ::android::hardware::audio::common::CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::HidlUtils;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
namespace util {
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::util;
}
namespace {
@ -334,7 +338,7 @@ Return<Result> StreamOut::setVolume(float left, float right) {
if (mStream->set_volume == NULL) {
return Result::NOT_SUPPORTED;
}
if (!isGainNormalized(left)) {
if (!util::isGainNormalized(left)) {
ALOGW("Can not set a stream output volume {%f, %f} outside [0,1]", left, right);
return Result::INVALID_ARGUMENTS;
}
@ -757,6 +761,73 @@ int StreamOut::asyncEventCallback(stream_event_callback_type_t event, void* para
ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str());
return 0;
}
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<Result> StreamOut::setLatencyMode(LatencyMode mode) {
return mStream->set_latency_mode != nullptr
? Stream::analyzeStatus(
"set_latency_mode",
mStream->set_latency_mode(mStream,
static_cast<audio_latency_mode_t>(mode)))
: Result::NOT_SUPPORTED;
};
Return<void> StreamOut::getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) {
Result retval = Result::NOT_SUPPORTED;
hidl_vec<LatencyMode> hidlModes;
size_t num_modes = AUDIO_LATENCY_MODE_CNT;
audio_latency_mode_t modes[AUDIO_LATENCY_MODE_CNT];
if (mStream->get_recommended_latency_modes != nullptr &&
mStream->get_recommended_latency_modes(mStream, &modes[0], &num_modes) == 0) {
if (num_modes == 0 || num_modes > AUDIO_LATENCY_MODE_CNT) {
ALOGW("%s invalid number of modes returned: %zu", __func__, num_modes);
retval = Result::INVALID_STATE;
} else {
hidlModes.resize(num_modes);
for (size_t i = 0; i < num_modes; ++i) {
hidlModes[i] = static_cast<LatencyMode>(modes[i]);
}
retval = Result::OK;
}
}
_hidl_cb(retval, hidlModes);
return Void();
};
// static
void StreamOut::latencyModeCallback(audio_latency_mode_t* modes, size_t num_modes, void* cookie) {
StreamOut* self = reinterpret_cast<StreamOut*>(cookie);
sp<IStreamOutLatencyModeCallback> callback = self->mLatencyModeCallback.load();
if (callback.get() == nullptr) return;
ALOGV("%s", __func__);
if (num_modes == 0 || num_modes > AUDIO_LATENCY_MODE_CNT) {
ALOGW("%s invalid number of modes returned: %zu", __func__, num_modes);
return;
}
hidl_vec<LatencyMode> hidlModes(num_modes);
for (size_t i = 0; i < num_modes; ++i) {
hidlModes[i] = static_cast<LatencyMode>(modes[i]);
}
Return<void> result = callback->onRecommendedLatencyModeChanged(hidlModes);
ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str());
}
Return<Result> StreamOut::setLatencyModeCallback(
const sp<IStreamOutLatencyModeCallback>& callback) {
if (mStream->set_latency_mode_callback == nullptr) return Result::NOT_SUPPORTED;
int result = mStream->set_latency_mode_callback(mStream, StreamOut::latencyModeCallback, this);
if (result == 0) {
mLatencyModeCallback = callback;
}
return Stream::analyzeStatus("set_latency_mode_callback", result, {ENOSYS} /*ignore*/);
};
#endif
#endif
} // namespace implementation

@ -1,48 +0,0 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef ANDROID_HARDWARE_AUDIO_CONVERSIONS_H_
#define ANDROID_HARDWARE_AUDIO_CONVERSIONS_H_
#include PATH(android/hardware/audio/FILE_VERSION/types.h)
#include <string>
#include <system/audio.h>
namespace android {
namespace hardware {
namespace audio {
namespace CPP_VERSION {
namespace implementation {
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
std::string deviceAddressToHal(const DeviceAddress& address);
#if MAJOR_VERSION >= 4
bool halToMicrophoneCharacteristics(MicrophoneInfo* pDst,
const struct audio_microphone_characteristic_t& src);
#endif
} // namespace implementation
} // namespace CPP_VERSION
} // namespace audio
} // namespace hardware
} // namespace android
#endif // ANDROID_HARDWARE_AUDIO_CONVERSIONS_H_

@ -44,7 +44,10 @@ using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::CoreUtils;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::ParametersUtil;
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
using AudioInputFlags = CoreUtils::AudioInputFlags;
using AudioOutputFlags = CoreUtils::AudioOutputFlags;
@ -63,14 +66,32 @@ struct Device : public IDevice, public ParametersUtil {
Return<void> getInputBufferSize(const AudioConfig& config,
getInputBufferSize_cb _hidl_cb) override;
std::tuple<Result, sp<IStreamOut>> openOutputStreamImpl(int32_t ioHandle,
std::tuple<Result, sp<IStreamOut>> openOutputStreamCore(int32_t ioHandle,
const DeviceAddress& device,
const AudioConfig& config,
const AudioOutputFlags& flags,
AudioConfig* suggestedConfig);
std::tuple<Result, sp<IStreamIn>> openInputStreamImpl(
std::tuple<Result, sp<IStreamIn>> openInputStreamCore(
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig);
#if MAJOR_VERSION >= 4
std::tuple<Result, sp<IStreamOut>, AudioConfig> openOutputStreamImpl(
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
const SourceMetadata& sourceMetadata,
#if MAJOR_VERSION <= 6
AudioOutputFlags flags);
#else
const AudioOutputFlags& flags);
#endif
std::tuple<Result, sp<IStreamIn>, AudioConfig> openInputStreamImpl(
int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config,
#if MAJOR_VERSION <= 6
AudioInputFlags flags,
#else
const AudioInputFlags& flags,
#endif
const SinkMetadata& sinkMetadata);
#endif // MAJOR_VERSION >= 4
Return<void> openOutputStream(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config,
@ -97,6 +118,13 @@ struct Device : public IDevice, public ParametersUtil {
#endif
openInputStream_cb _hidl_cb) override;
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<void> openOutputStream_7_1(int32_t ioHandle, const DeviceAddress& device,
const AudioConfig& config, const AudioOutputFlags& flags,
const SourceMetadata& sourceMetadata,
openOutputStream_7_1_cb _hidl_cb) override;
#endif
Return<bool> supportsAudioPatches() override;
Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources,
const hidl_vec<AudioPortConfig>& sinks,
@ -130,6 +158,9 @@ struct Device : public IDevice, public ParametersUtil {
Return<void> updateAudioPatch(int32_t previousPatch, const hidl_vec<AudioPortConfig>& sources,
const hidl_vec<AudioPortConfig>& sinks,
createAudioPatch_cb _hidl_cb) override;
#endif
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<Result> setConnectedState_7_1(const AudioPort& devicePort, bool connected) override;
#endif
Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;

@ -44,11 +44,17 @@ struct DevicesFactory : public IDevicesFactory {
Return<void> openDevice(const hidl_string& device, openDevice_cb _hidl_cb) override;
Return<void> openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) override;
#endif
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<void> openDevice_7_1(const hidl_string& device, openDevice_7_1_cb _hidl_cb) override;
Return<void> openPrimaryDevice_7_1(openPrimaryDevice_7_1_cb _hidl_cb) override;
#endif
private:
private:
template <class DeviceShim, class Callback>
Return<void> openDevice(const char* moduleName, Callback _hidl_cb);
#if MAJOR_VERSION == 2
Return<void> openDevice(const char* moduleName, openDevice_cb _hidl_cb);
#endif
static int loadAudioInterface(const char* if_name, audio_hw_device_t** dev);
};

@ -17,7 +17,10 @@
#ifndef ANDROID_HARDWARE_AUDIO_PARAMETERS_UTIL_H_
#define ANDROID_HARDWARE_AUDIO_PARAMETERS_UTIL_H_
#include PATH(android/hardware/audio/FILE_VERSION/types.h)
// clang-format off
#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h)
#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h)
// clang-format on
#include <functional>
#include <memory>
@ -28,13 +31,13 @@
namespace android {
namespace hardware {
namespace audio {
namespace CPP_VERSION {
namespace CORE_TYPES_CPP_VERSION {
namespace implementation {
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
class ParametersUtil {
public:
@ -62,7 +65,7 @@ class ParametersUtil {
};
} // namespace implementation
} // namespace CPP_VERSION
} // namespace CORE_TYPES_CPP_VERSION
} // namespace audio
} // namespace hardware
} // namespace android

@ -36,7 +36,8 @@ using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
struct PrimaryDevice : public IPrimaryDevice {
@ -135,8 +136,10 @@ struct PrimaryDevice : public IPrimaryDevice {
Return<Result> setBtHfpVolume(float volume) override;
Return<Result> updateRotation(IPrimaryDevice::Rotation rotation) override;
#endif
private:
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<sp<::android::hardware::audio::V7_1::IDevice>> getDevice() override { return mDevice; }
#endif
private:
sp<Device> mDevice;
virtual ~PrimaryDevice();

@ -17,7 +17,9 @@
#ifndef ANDROID_HARDWARE_AUDIO_STREAM_H
#define ANDROID_HARDWARE_AUDIO_STREAM_H
#include PATH(android/hardware/audio/FILE_VERSION/IStream.h)
// clang-format off
#include PATH(android/hardware/audio/COMMON_TYPES_FILE_VERSION/IStream.h)
// clang-format on
#include "ParametersUtil.h"
@ -41,10 +43,13 @@ using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::implementation::ParametersUtil;
#if MAJOR_VERSION <= 6
using ::android::hardware::audio::common::CPP_VERSION::implementation::AudioChannelBitfield;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::
AudioChannelBitfield;
#endif
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
struct Stream : public IStream, public ParametersUtil {

@ -17,7 +17,9 @@
#ifndef ANDROID_HARDWARE_AUDIO_STREAMIN_H
#define ANDROID_HARDWARE_AUDIO_STREAMIN_H
#include PATH(android/hardware/audio/FILE_VERSION/IStreamIn.h)
// clang-format off
#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/IStreamIn.h)
// clang-format on
#include "Device.h"
#include "Stream.h"
@ -42,7 +44,8 @@ using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
struct StreamIn : public IStreamIn {

@ -43,7 +43,8 @@ using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::Return;
using ::android::hardware::Void;
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
struct StreamOut : public IStreamOut {
@ -152,6 +153,12 @@ struct StreamOut : public IStreamOut {
Result doUpdateSourceMetadata(const SourceMetadata& sourceMetadata);
#if MAJOR_VERSION >= 7
Result doUpdateSourceMetadataV7(const SourceMetadata& sourceMetadata);
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
Return<Result> setLatencyMode(LatencyMode mode) override;
Return<void> getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) override;
Return<Result> setLatencyModeCallback(
const sp<IStreamOutLatencyModeCallback>& callback) override;
#endif
#endif
#endif // MAJOR_VERSION >= 4
@ -162,6 +169,9 @@ struct StreamOut : public IStreamOut {
mediautils::atomic_sp<IStreamOutCallback> mCallback; // for non-blocking write and drain
#if MAJOR_VERSION >= 6
mediautils::atomic_sp<IStreamOutEventCallback> mEventCallback;
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
mediautils::atomic_sp<IStreamOutLatencyModeCallback> mLatencyModeCallback;
#endif
#endif
std::unique_ptr<CommandMQ> mCommandMQ;
std::unique_ptr<DataMQ> mDataMQ;
@ -176,6 +186,9 @@ struct StreamOut : public IStreamOut {
#if MAJOR_VERSION >= 6
static int asyncEventCallback(stream_event_callback_type_t event, void* param, void* cookie);
#if MAJOR_VERSION == 7 && MINOR_VERSION == 1
static void latencyModeCallback(audio_latency_mode_t* modes, size_t num_modes, void* cookie);
#endif
#endif
};

@ -17,7 +17,9 @@
#ifndef ANDROID_HARDWARE_AUDIO_UTIL_H
#define ANDROID_HARDWARE_AUDIO_UTIL_H
#include PATH(android/hardware/audio/FILE_VERSION/types.h)
// clang-format off
#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h)
// clang-format on
#include <algorithm>
#include <vector>
@ -27,19 +29,19 @@
namespace android {
namespace hardware {
namespace audio {
namespace CPP_VERSION {
namespace CORE_TYPES_CPP_VERSION {
namespace implementation {
using namespace ::android::hardware::audio::common::CPP_VERSION;
using namespace ::android::hardware::audio::CPP_VERSION;
using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION;
namespace util {
/** @return true if gain is between 0 and 1 included. */
constexpr bool isGainNormalized(float gain) {
return gain >= 0.0 && gain <= 1.0;
}
namespace util {
template <typename T>
inline bool element_in(T e, const std::vector<T>& v) {
return std::find(v.begin(), v.end(), e) != v.end();
@ -72,7 +74,7 @@ static inline Result analyzeStatus(const char* className, const char* funcName,
} // namespace util
} // namespace implementation
} // namespace CPP_VERSION
} // namespace CORE_TYPES_CPP_VERSION
} // namespace audio
} // namespace hardware
} // namespace android

Loading…
Cancel
Save