From 4f4da649aa3b966aa8233be26f17008d429116e9 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Tue, 30 Aug 2022 22:17:49 +0200 Subject: [PATCH] sm7125-common: Rebase custom audio impl Change-Id: I22e67b1245d8c890b5f72340d456b5f89045b8b6 --- audio/Android.bp | 23 ++++- audio/Device.cpp | 108 ++++++++++++++------ audio/DevicesFactory.cpp | 38 ++++++- audio/ParametersUtil.cpp | 4 +- audio/PrimaryDevice.cpp | 8 +- audio/Stream.cpp | 6 +- audio/StreamIn.cpp | 8 +- audio/StreamOut.cpp | 75 +++++++++++++- audio/include/core/default/Conversions.h | 48 --------- audio/include/core/default/Device.h | 37 ++++++- audio/include/core/default/DevicesFactory.h | 8 +- audio/include/core/default/ParametersUtil.h | 13 ++- audio/include/core/default/PrimaryDevice.h | 9 +- audio/include/core/default/Stream.h | 11 +- audio/include/core/default/StreamIn.h | 7 +- audio/include/core/default/StreamOut.h | 15 ++- audio/include/core/default/Util.h | 16 +-- 17 files changed, 319 insertions(+), 115 deletions(-) delete mode 100644 audio/include/core/default/Conversions.h diff --git a/audio/Android.bp b/audio/Android.bp index e361b15..297c747 100644 --- a/audio/Android.bp +++ b/audio/Android.bp @@ -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", + ], +} diff --git a/audio/Device.cpp b/audio/Device.cpp index 440d0ef..6e55e7b 100644 --- a/audio/Device.cpp +++ b/audio/Device.cpp @@ -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 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 Device::getInputBufferSize(const AudioConfig& config, getInputBuffe return Void(); } -std::tuple> Device::openOutputStreamImpl(int32_t ioHandle, +std::tuple> Device::openOutputStreamCore(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, const AudioOutputFlags& flags, @@ -187,7 +190,7 @@ std::tuple> Device::openOutputStreamImpl(int32_t ioHandle return {analyzeStatus("open_output_stream", status, {EINVAL} /*ignore*/), streamOut}; } -std::tuple> Device::openInputStreamImpl( +std::tuple> 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 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 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 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, 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 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 Device::openInputStream(int32_t ioHandle, const DeviceAddress& device, - const AudioConfig& config, +std::tuple, 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 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 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 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 Device::supportsAudioPatches() { return version() >= AUDIO_DEVICE_API_VERSION_3_0; } @@ -575,6 +610,21 @@ Return Device::updateAudioPatch(int32_t previousPatch, #endif +#if MAJOR_VERSION == 7 && MINOR_VERSION == 1 +Return 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 diff --git a/audio/DevicesFactory.cpp b/audio/DevicesFactory.cpp index 729f18c..f44daf0 100644 --- a/audio/DevicesFactory.cpp +++ b/audio/DevicesFactory.cpp @@ -47,21 +47,53 @@ Return DevicesFactory::openDevice(IDevicesFactory::Device device, openDevi _hidl_cb(Result::INVALID_ARGUMENTS, nullptr); return Void(); } + +Return DevicesFactory::openDevice(const char* moduleName, openDevice_cb _hidl_cb) { + return openDevice(moduleName, _hidl_cb); +} #elif MAJOR_VERSION >= 4 Return DevicesFactory::openDevice(const hidl_string& moduleName, openDevice_cb _hidl_cb) { if (moduleName == AUDIO_HARDWARE_MODULE_ID_PRIMARY) { return openDevice(moduleName.c_str(), _hidl_cb); } - return openDevice(moduleName.c_str(), _hidl_cb); + return openDevice(moduleName.c_str(), _hidl_cb); } Return DevicesFactory::openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) { return openDevice(AUDIO_HARDWARE_MODULE_ID_PRIMARY, _hidl_cb); } #endif -Return DevicesFactory::openDevice(const char* moduleName, openDevice_cb _hidl_cb) { - return openDevice(moduleName, _hidl_cb); +#if MAJOR_VERSION == 7 && MINOR_VERSION == 1 +Return DevicesFactory::openDevice_7_1(const hidl_string& moduleName, + openDevice_7_1_cb _hidl_cb) { + if (moduleName == AUDIO_HARDWARE_MODULE_ID_PRIMARY) { + Result result; + sp primary; + auto ret = openDevice( + AUDIO_HARDWARE_MODULE_ID_PRIMARY, + [&result, &primary](Result r, const sp& 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(moduleName.c_str(), _hidl_cb); +} + +Return DevicesFactory::openPrimaryDevice_7_1(openPrimaryDevice_7_1_cb _hidl_cb) { + return openDevice(AUDIO_HARDWARE_MODULE_ID_PRIMARY, _hidl_cb); } +#endif // V7.1 template Return DevicesFactory::openDevice(const char* moduleName, Callback _hidl_cb) { diff --git a/audio/ParametersUtil.cpp b/audio/ParametersUtil.cpp index 27a610e..2844d03 100644 --- a/audio/ParametersUtil.cpp +++ b/audio/ParametersUtil.cpp @@ -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 diff --git a/audio/PrimaryDevice.cpp b/audio/PrimaryDevice.cpp index 9daf671..80a494b 100644 --- a/audio/PrimaryDevice.cpp +++ b/audio/PrimaryDevice.cpp @@ -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 PrimaryDevice::updateAudioPatch(int32_t previousPatch, // Methods from ::android::hardware::audio::CPP_VERSION::IPrimaryDevice follow. Return 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 PrimaryDevice::setBtHfpSampleRate(uint32_t sampleRateHz) { return mDevice->setParam(AUDIO_PARAMETER_KEY_HFP_SET_SAMPLING_RATE, int(sampleRateHz)); } Return 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; } diff --git a/audio/Stream.cpp b/audio/Stream.cpp index 7e32573..8e85a8b 100644 --- a/audio/Stream.cpp +++ b/audio/Stream.cpp @@ -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. diff --git a/audio/StreamIn.cpp b/audio/StreamIn.cpp index 2aeee43..2bea425 100644 --- a/audio/StreamIn.cpp +++ b/audio/StreamIn.cpp @@ -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 StreamIn::getAudioSource(getAudioSource_cb _hidl_cb) { } Return 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; } diff --git a/audio/StreamOut.cpp b/audio/StreamOut.cpp index d027231..09df4ed 100644 --- a/audio/StreamOut.cpp +++ b/audio/StreamOut.cpp @@ -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 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 StreamOut::setLatencyMode(LatencyMode mode) { + return mStream->set_latency_mode != nullptr + ? Stream::analyzeStatus( + "set_latency_mode", + mStream->set_latency_mode(mStream, + static_cast(mode))) + : Result::NOT_SUPPORTED; +}; + +Return StreamOut::getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) { + Result retval = Result::NOT_SUPPORTED; + hidl_vec 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(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(cookie); + sp 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 hidlModes(num_modes); + for (size_t i = 0; i < num_modes; ++i) { + hidlModes[i] = static_cast(modes[i]); + } + Return result = callback->onRecommendedLatencyModeChanged(hidlModes); + ALOGW_IF(!result.isOk(), "Client callback failed: %s", result.description().c_str()); +} + +Return StreamOut::setLatencyModeCallback( + const sp& 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 diff --git a/audio/include/core/default/Conversions.h b/audio/include/core/default/Conversions.h deleted file mode 100644 index cb7914f..0000000 --- a/audio/include/core/default/Conversions.h +++ /dev/null @@ -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 - -#include - -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_ diff --git a/audio/include/core/default/Device.h b/audio/include/core/default/Device.h index 4c51609..f0e7afd 100644 --- a/audio/include/core/default/Device.h +++ b/audio/include/core/default/Device.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 getInputBufferSize(const AudioConfig& config, getInputBufferSize_cb _hidl_cb) override; - std::tuple> openOutputStreamImpl(int32_t ioHandle, + std::tuple> openOutputStreamCore(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, const AudioOutputFlags& flags, AudioConfig* suggestedConfig); - std::tuple> openInputStreamImpl( + std::tuple> openInputStreamCore( int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, const AudioInputFlags& flags, AudioSource source, AudioConfig* suggestedConfig); +#if MAJOR_VERSION >= 4 + std::tuple, 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, 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 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 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 supportsAudioPatches() override; Return createAudioPatch(const hidl_vec& sources, const hidl_vec& sinks, @@ -130,6 +158,9 @@ struct Device : public IDevice, public ParametersUtil { Return updateAudioPatch(int32_t previousPatch, const hidl_vec& sources, const hidl_vec& sinks, createAudioPatch_cb _hidl_cb) override; +#endif +#if MAJOR_VERSION == 7 && MINOR_VERSION == 1 + Return setConnectedState_7_1(const AudioPort& devicePort, bool connected) override; #endif Return debug(const hidl_handle& fd, const hidl_vec& options) override; diff --git a/audio/include/core/default/DevicesFactory.h b/audio/include/core/default/DevicesFactory.h index 9f93a38..566bc8a 100644 --- a/audio/include/core/default/DevicesFactory.h +++ b/audio/include/core/default/DevicesFactory.h @@ -44,11 +44,17 @@ struct DevicesFactory : public IDevicesFactory { Return openDevice(const hidl_string& device, openDevice_cb _hidl_cb) override; Return openPrimaryDevice(openPrimaryDevice_cb _hidl_cb) override; #endif +#if MAJOR_VERSION == 7 && MINOR_VERSION == 1 + Return openDevice_7_1(const hidl_string& device, openDevice_7_1_cb _hidl_cb) override; + Return openPrimaryDevice_7_1(openPrimaryDevice_7_1_cb _hidl_cb) override; +#endif - private: + private: template Return openDevice(const char* moduleName, Callback _hidl_cb); +#if MAJOR_VERSION == 2 Return openDevice(const char* moduleName, openDevice_cb _hidl_cb); +#endif static int loadAudioInterface(const char* if_name, audio_hw_device_t** dev); }; diff --git a/audio/include/core/default/ParametersUtil.h b/audio/include/core/default/ParametersUtil.h index 45d9b21..25c193a 100644 --- a/audio/include/core/default/ParametersUtil.h +++ b/audio/include/core/default/ParametersUtil.h @@ -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 #include @@ -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 diff --git a/audio/include/core/default/PrimaryDevice.h b/audio/include/core/default/PrimaryDevice.h index 5f65acf..8b37e01 100644 --- a/audio/include/core/default/PrimaryDevice.h +++ b/audio/include/core/default/PrimaryDevice.h @@ -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 setBtHfpVolume(float volume) override; Return updateRotation(IPrimaryDevice::Rotation rotation) override; #endif - - private: +#if MAJOR_VERSION == 7 && MINOR_VERSION == 1 + Return> getDevice() override { return mDevice; } +#endif + private: sp mDevice; virtual ~PrimaryDevice(); diff --git a/audio/include/core/default/Stream.h b/audio/include/core/default/Stream.h index 66d60e3..4e79884 100644 --- a/audio/include/core/default/Stream.h +++ b/audio/include/core/default/Stream.h @@ -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 { diff --git a/audio/include/core/default/StreamIn.h b/audio/include/core/default/StreamIn.h index a980f3f..4627eec 100644 --- a/audio/include/core/default/StreamIn.h +++ b/audio/include/core/default/StreamIn.h @@ -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 { diff --git a/audio/include/core/default/StreamOut.h b/audio/include/core/default/StreamOut.h index 0b07972..ce5253f 100644 --- a/audio/include/core/default/StreamOut.h +++ b/audio/include/core/default/StreamOut.h @@ -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 setLatencyMode(LatencyMode mode) override; + Return getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) override; + Return setLatencyModeCallback( + const sp& callback) override; +#endif #endif #endif // MAJOR_VERSION >= 4 @@ -162,6 +169,9 @@ struct StreamOut : public IStreamOut { mediautils::atomic_sp mCallback; // for non-blocking write and drain #if MAJOR_VERSION >= 6 mediautils::atomic_sp mEventCallback; +#if MAJOR_VERSION == 7 && MINOR_VERSION == 1 + mediautils::atomic_sp mLatencyModeCallback; +#endif #endif std::unique_ptr mCommandMQ; std::unique_ptr 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 }; diff --git a/audio/include/core/default/Util.h b/audio/include/core/default/Util.h index 78ae03e..abf5317 100644 --- a/audio/include/core/default/Util.h +++ b/audio/include/core/default/Util.h @@ -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 #include @@ -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 inline bool element_in(T e, const std::vector& 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