From f26235fde01ec013846db8ebefa301d8523cb2c8 Mon Sep 17 00:00:00 2001 From: Kevin Rocard Date: Thu, 19 Apr 2018 03:29:55 +0000 Subject: [PATCH] Revert "Audio: setParam improve status_t to Result consistency" This commit broke sailfish build in V4 due to https://cs.corp.google.com/android/hardware/interfaces/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h?q=hardware/interfaces/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h:251 not being updated. This is really strange as 1) sailfish should not build the V4 code in the first place 2) walleye is not broken although it should be the broken code 3) neither treehugger nor my local builds found this issue Revert to give the time to investigate. This reverts commit 2c6755a00cbeb3ddb1e60b7ea42ae5eca7cbae8e. Reason for revert: Change-Id: Ibf5270c15d52212a41b3b4eb4c0fcfe82a08fd6b --- audio/core/2.0/default/Device.cpp | 2 +- audio/core/2.0/default/ParametersUtil.cpp | 1 - audio/core/2.0/default/PrimaryDevice.cpp | 2 +- audio/core/2.0/default/Stream.cpp | 1 - audio/core/2.0/default/StreamIn.cpp | 2 +- audio/core/2.0/default/StreamOut.cpp | 2 +- .../default/include/core/2.0/default/Util.h | 26 ---------- audio/core/4.0/default/Device.cpp | 2 +- audio/core/4.0/default/ParametersUtil.cpp | 1 - audio/core/4.0/default/PrimaryDevice.cpp | 2 +- audio/core/4.0/default/Stream.cpp | 1 - audio/core/4.0/default/StreamIn.cpp | 2 +- audio/core/4.0/default/StreamOut.cpp | 2 +- .../default/include/core/4.0/default/Util.h | 26 ---------- .../core/all-versions/default/Device.impl.h | 1 + .../default/ParametersUtil.impl.h | 21 +++++++- .../all-versions/default/PrimaryDevice.impl.h | 2 +- .../core/all-versions/default/Stream.impl.h | 25 +++++++++- .../core/all-versions/default/StreamIn.impl.h | 2 + .../all-versions/default/StreamOut.impl.h | 1 + .../include/core/all-versions/default/Util.h | 49 +++---------------- 21 files changed, 62 insertions(+), 111 deletions(-) delete mode 100644 audio/core/2.0/default/include/core/2.0/default/Util.h delete mode 100644 audio/core/4.0/default/include/core/4.0/default/Util.h diff --git a/audio/core/2.0/default/Device.cpp b/audio/core/2.0/default/Device.cpp index b67203d50e..221ea5c0eb 100644 --- a/audio/core/2.0/default/Device.cpp +++ b/audio/core/2.0/default/Device.cpp @@ -21,7 +21,7 @@ #include "core/2.0/default/Conversions.h" #include "core/2.0/default/StreamIn.h" #include "core/2.0/default/StreamOut.h" -#include "core/2.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V2_0 #include diff --git a/audio/core/2.0/default/ParametersUtil.cpp b/audio/core/2.0/default/ParametersUtil.cpp index 963e291de0..33a3ad9b7b 100644 --- a/audio/core/2.0/default/ParametersUtil.cpp +++ b/audio/core/2.0/default/ParametersUtil.cpp @@ -15,7 +15,6 @@ */ #include "core/2.0/default/ParametersUtil.h" -#include "core/2.0/default/Util.h" #define AUDIO_HAL_VERSION V2_0 #include diff --git a/audio/core/2.0/default/PrimaryDevice.cpp b/audio/core/2.0/default/PrimaryDevice.cpp index decaa14658..ce57403864 100644 --- a/audio/core/2.0/default/PrimaryDevice.cpp +++ b/audio/core/2.0/default/PrimaryDevice.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "PrimaryDeviceHAL" #include "core/2.0/default/PrimaryDevice.h" -#include "core/2.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V2_0 #include diff --git a/audio/core/2.0/default/Stream.cpp b/audio/core/2.0/default/Stream.cpp index 0863a7c399..69ee659811 100644 --- a/audio/core/2.0/default/Stream.cpp +++ b/audio/core/2.0/default/Stream.cpp @@ -19,7 +19,6 @@ #include "core/2.0/default/Stream.h" #include "common/all-versions/default/EffectMap.h" #include "core/2.0/default/Conversions.h" -#include "core/2.0/default/Util.h" #define AUDIO_HAL_VERSION V2_0 #include diff --git a/audio/core/2.0/default/StreamIn.cpp b/audio/core/2.0/default/StreamIn.cpp index 2021df1c49..6b8776ebe5 100644 --- a/audio/core/2.0/default/StreamIn.cpp +++ b/audio/core/2.0/default/StreamIn.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "StreamInHAL" #include "core/2.0/default/StreamIn.h" -#include "core/2.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V2_0 #include diff --git a/audio/core/2.0/default/StreamOut.cpp b/audio/core/2.0/default/StreamOut.cpp index 940a251272..7f1461ac7d 100644 --- a/audio/core/2.0/default/StreamOut.cpp +++ b/audio/core/2.0/default/StreamOut.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "StreamOutHAL" #include "core/2.0/default/StreamOut.h" -#include "core/2.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V2_0 #include diff --git a/audio/core/2.0/default/include/core/2.0/default/Util.h b/audio/core/2.0/default/include/core/2.0/default/Util.h deleted file mode 100644 index 858cd3bb3d..0000000000 --- a/audio/core/2.0/default/include/core/2.0/default/Util.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2017 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_V2_0_UTIL_H -#define ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H - -#include - -#define AUDIO_HAL_VERSION V2_0 -#include -#undef AUDIO_HAL_VERSION - -#endif // ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H diff --git a/audio/core/4.0/default/Device.cpp b/audio/core/4.0/default/Device.cpp index b33434ecfb..26f9ab4a70 100644 --- a/audio/core/4.0/default/Device.cpp +++ b/audio/core/4.0/default/Device.cpp @@ -21,7 +21,7 @@ #include "core/4.0/default/Conversions.h" #include "core/4.0/default/StreamIn.h" #include "core/4.0/default/StreamOut.h" -#include "core/4.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V4_0 #include diff --git a/audio/core/4.0/default/ParametersUtil.cpp b/audio/core/4.0/default/ParametersUtil.cpp index 2cc9fb56a3..5c1b1c4b18 100644 --- a/audio/core/4.0/default/ParametersUtil.cpp +++ b/audio/core/4.0/default/ParametersUtil.cpp @@ -15,7 +15,6 @@ */ #include "core/4.0/default/ParametersUtil.h" -#include "core/4.0/default/Util.h" #define AUDIO_HAL_VERSION V4_0 #include diff --git a/audio/core/4.0/default/PrimaryDevice.cpp b/audio/core/4.0/default/PrimaryDevice.cpp index e3e49768d5..0294b4d0d4 100644 --- a/audio/core/4.0/default/PrimaryDevice.cpp +++ b/audio/core/4.0/default/PrimaryDevice.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "PrimaryDeviceHAL" #include "core/4.0/default/PrimaryDevice.h" -#include "core/4.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V4_0 #include diff --git a/audio/core/4.0/default/Stream.cpp b/audio/core/4.0/default/Stream.cpp index b8c71de7b7..30b34544d6 100644 --- a/audio/core/4.0/default/Stream.cpp +++ b/audio/core/4.0/default/Stream.cpp @@ -19,7 +19,6 @@ #include "core/4.0/default/Stream.h" #include "common/all-versions/default/EffectMap.h" #include "core/4.0/default/Conversions.h" -#include "core/4.0/default/Util.h" #define AUDIO_HAL_VERSION V4_0 #include diff --git a/audio/core/4.0/default/StreamIn.cpp b/audio/core/4.0/default/StreamIn.cpp index 718bd25a63..18719b5da2 100644 --- a/audio/core/4.0/default/StreamIn.cpp +++ b/audio/core/4.0/default/StreamIn.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "StreamInHAL" #include "core/4.0/default/StreamIn.h" -#include "core/4.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V4_0 #include diff --git a/audio/core/4.0/default/StreamOut.cpp b/audio/core/4.0/default/StreamOut.cpp index db88e401d2..11c8fde663 100644 --- a/audio/core/4.0/default/StreamOut.cpp +++ b/audio/core/4.0/default/StreamOut.cpp @@ -17,7 +17,7 @@ #define LOG_TAG "StreamOutHAL" #include "core/4.0/default/StreamOut.h" -#include "core/4.0/default/Util.h" +#include "core/all-versions/default/Util.h" #define AUDIO_HAL_VERSION V4_0 #include diff --git a/audio/core/4.0/default/include/core/4.0/default/Util.h b/audio/core/4.0/default/include/core/4.0/default/Util.h deleted file mode 100644 index dcdc7ee7a1..0000000000 --- a/audio/core/4.0/default/include/core/4.0/default/Util.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2017 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_V4_0_UTIL_H -#define ANDROID_HARDWARE_AUDIO_V4_0_UTIL_H - -#include - -#define AUDIO_HAL_VERSION V4_0 -#include -#undef AUDIO_HAL_VERSION - -#endif // ANDROID_HARDWARE_AUDIO_V4_0_UTIL_H diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h index 37b7124a26..581e1dcce3 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/Device.impl.h @@ -25,6 +25,7 @@ #include using ::android::hardware::audio::common::AUDIO_HAL_VERSION::HidlUtils; +using ::android::hardware::audio::all_versions::implementation::isGainNormalized; namespace android { namespace hardware { diff --git a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h index afff2b6d2a..3907284048 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/ParametersUtil.impl.h @@ -149,7 +149,26 @@ Result ParametersUtil::setParam(const char* name, const DeviceAddress& address) Result ParametersUtil::setParams(const AudioParameter& param) { int halStatus = halSetParameters(param.toString().string()); - return util::analyzeStatus(halStatus); + switch (halStatus) { + case OK: + return Result::OK; + case -EINVAL: + return Result::INVALID_ARGUMENTS; + case -ENODATA: + return Result::INVALID_STATE; + case -ENODEV: + return Result::NOT_INITIALIZED; + // The rest of the API (*::analyseStatus) returns NOT_SUPPORTED + // when the legacy API returns -ENOSYS + // However the legacy API explicitly state that for get_paramers, + // -ENOSYS should be returned if + // "the implementation does not accept a parameter change while the + // output is active but the parameter is acceptable otherwise" + case -ENOSYS: + return Result::INVALID_STATE; + default: + return Result::INVALID_ARGUMENTS; + } } } // namespace implementation diff --git a/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h index 801feb05bf..f00cac4ee1 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/PrimaryDevice.impl.h @@ -156,7 +156,7 @@ Return PrimaryDevice::setConnectedState(const DeviceAddress& address, bo // Methods from ::android::hardware::audio::AUDIO_HAL_VERSION::IPrimaryDevice follow. Return PrimaryDevice::setVoiceVolume(float volume) { - if (!isGainNormalized(volume)) { + if (!all_versions::implementation::isGainNormalized(volume)) { ALOGW("Can not set a voice volume (%f) outside [0,1]", volume); return Result::INVALID_ARGUMENTS; } diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h index 7415112545..fa0ef45bec 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/Stream.impl.h @@ -39,14 +39,35 @@ Stream::~Stream() { // static Result Stream::analyzeStatus(const char* funcName, int status) { - return util::analyzeStatus("stream", funcName, status); + static const std::vector empty; + return analyzeStatus(funcName, status, empty); } +template +inline bool element_in(T e, const std::vector& v) { + return std::find(v.begin(), v.end(), e) != v.end(); +} // static Result Stream::analyzeStatus(const char* funcName, int status, const std::vector& ignoreErrors) { - return util::analyzeStatus("stream", funcName, status, ignoreErrors); + if (status != 0 && (ignoreErrors.empty() || !element_in(-status, ignoreErrors))) { + ALOGW("Error from HAL stream in function %s: %s", funcName, strerror(-status)); + } + switch (status) { + case 0: + return Result::OK; + case -EINVAL: + return Result::INVALID_ARGUMENTS; + case -ENODATA: + return Result::INVALID_STATE; + case -ENODEV: + return Result::NOT_INITIALIZED; + case -ENOSYS: + return Result::NOT_SUPPORTED; + default: + return Result::INVALID_STATE; + } } char* Stream::halGetParameters(const char* keys) { diff --git a/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h index 64c85ab5fc..8774be904f 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/StreamIn.impl.h @@ -25,7 +25,9 @@ #include using ::android::hardware::audio::AUDIO_HAL_VERSION::MessageQueueFlagBits; +using ::android::hardware::audio::all_versions::implementation::isGainNormalized; #include "Conversions.h" +#include "Util.h" namespace android { namespace hardware { diff --git a/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h b/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h index 6fb157f7de..77098a8168 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/StreamOut.impl.h @@ -32,6 +32,7 @@ namespace AUDIO_HAL_VERSION { namespace implementation { using ::android::hardware::audio::common::AUDIO_HAL_VERSION::ThreadInfo; +using ::android::hardware::audio::all_versions::implementation::isGainNormalized; namespace { diff --git a/audio/core/all-versions/default/include/core/all-versions/default/Util.h b/audio/core/all-versions/default/include/core/all-versions/default/Util.h index 350fd867e6..39d9dbde00 100644 --- a/audio/core/all-versions/default/include/core/all-versions/default/Util.h +++ b/audio/core/all-versions/default/include/core/all-versions/default/Util.h @@ -14,61 +14,24 @@ * limitations under the License. */ -#include - -#include -#include - -#include +#ifndef ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H +#define ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H namespace android { namespace hardware { namespace audio { -namespace AUDIO_HAL_VERSION { +namespace all_versions { namespace implementation { -using ::android::hardware::audio::AUDIO_HAL_VERSION::Result; - /** @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(); -} - -static inline Result analyzeStatus(status_t status) { - switch (status) { - case 0: - return Result::OK; - case -EINVAL: - return Result::INVALID_ARGUMENTS; - case -ENODATA: - return Result::INVALID_STATE; - case -ENODEV: - return Result::NOT_INITIALIZED; - case -ENOSYS: - return Result::NOT_SUPPORTED; - default: - return Result::INVALID_STATE; - } -} - -static inline Result analyzeStatus(const char* className, const char* funcName, status_t status, - const std::vector& ignoreErrors = {}) { - if (status != 0 && !element_in(-status, ignoreErrors)) { - ALOGW("Error from HAL %s in function %s: %s", className, funcName, strerror(-status)); - } - return analyzeStatus(status); -} - -} // namespace util } // namespace implementation -} // namespace AUDIO_HAL_VERSION +} // namespace all_versions } // namespace audio } // namespace hardware } // namespace android + +#endif // ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H