Merge "Audio: setParam improve status_t to Result consistency" into pi-dev am: f21217f173
am: 614ce638d5
Change-Id: I8e270bf53392110d6b296664eb3957c980d87361
This commit is contained in:
commit
d8efe30bbe
21 changed files with 111 additions and 62 deletions
|
@ -21,7 +21,7 @@
|
||||||
#include "core/2.0/default/Conversions.h"
|
#include "core/2.0/default/Conversions.h"
|
||||||
#include "core/2.0/default/StreamIn.h"
|
#include "core/2.0/default/StreamIn.h"
|
||||||
#include "core/2.0/default/StreamOut.h"
|
#include "core/2.0/default/StreamOut.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/2.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V2_0
|
#define AUDIO_HAL_VERSION V2_0
|
||||||
#include <core/all-versions/default/Device.impl.h>
|
#include <core/all-versions/default/Device.impl.h>
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "core/2.0/default/ParametersUtil.h"
|
#include "core/2.0/default/ParametersUtil.h"
|
||||||
|
#include "core/2.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V2_0
|
#define AUDIO_HAL_VERSION V2_0
|
||||||
#include <core/all-versions/default/ParametersUtil.impl.h>
|
#include <core/all-versions/default/ParametersUtil.impl.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#define LOG_TAG "PrimaryDeviceHAL"
|
#define LOG_TAG "PrimaryDeviceHAL"
|
||||||
|
|
||||||
#include "core/2.0/default/PrimaryDevice.h"
|
#include "core/2.0/default/PrimaryDevice.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/2.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V2_0
|
#define AUDIO_HAL_VERSION V2_0
|
||||||
#include <core/all-versions/default/PrimaryDevice.impl.h>
|
#include <core/all-versions/default/PrimaryDevice.impl.h>
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "core/2.0/default/Stream.h"
|
#include "core/2.0/default/Stream.h"
|
||||||
#include "common/all-versions/default/EffectMap.h"
|
#include "common/all-versions/default/EffectMap.h"
|
||||||
#include "core/2.0/default/Conversions.h"
|
#include "core/2.0/default/Conversions.h"
|
||||||
|
#include "core/2.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V2_0
|
#define AUDIO_HAL_VERSION V2_0
|
||||||
#include <core/all-versions/default/Stream.impl.h>
|
#include <core/all-versions/default/Stream.impl.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#define LOG_TAG "StreamInHAL"
|
#define LOG_TAG "StreamInHAL"
|
||||||
|
|
||||||
#include "core/2.0/default/StreamIn.h"
|
#include "core/2.0/default/StreamIn.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/2.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V2_0
|
#define AUDIO_HAL_VERSION V2_0
|
||||||
#include <core/all-versions/default/StreamIn.impl.h>
|
#include <core/all-versions/default/StreamIn.impl.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#define LOG_TAG "StreamOutHAL"
|
#define LOG_TAG "StreamOutHAL"
|
||||||
|
|
||||||
#include "core/2.0/default/StreamOut.h"
|
#include "core/2.0/default/StreamOut.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/2.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V2_0
|
#define AUDIO_HAL_VERSION V2_0
|
||||||
#include <core/all-versions/default/StreamOut.impl.h>
|
#include <core/all-versions/default/StreamOut.impl.h>
|
||||||
|
|
26
audio/core/2.0/default/include/core/2.0/default/Util.h
Normal file
26
audio/core/2.0/default/include/core/2.0/default/Util.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* 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 <android/hardware/audio/2.0/types.h>
|
||||||
|
|
||||||
|
#define AUDIO_HAL_VERSION V2_0
|
||||||
|
#include <core/all-versions/default/Util.h>
|
||||||
|
#undef AUDIO_HAL_VERSION
|
||||||
|
|
||||||
|
#endif // ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H
|
|
@ -21,7 +21,7 @@
|
||||||
#include "core/4.0/default/Conversions.h"
|
#include "core/4.0/default/Conversions.h"
|
||||||
#include "core/4.0/default/StreamIn.h"
|
#include "core/4.0/default/StreamIn.h"
|
||||||
#include "core/4.0/default/StreamOut.h"
|
#include "core/4.0/default/StreamOut.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/4.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V4_0
|
#define AUDIO_HAL_VERSION V4_0
|
||||||
#include <core/all-versions/default/Device.impl.h>
|
#include <core/all-versions/default/Device.impl.h>
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "core/4.0/default/ParametersUtil.h"
|
#include "core/4.0/default/ParametersUtil.h"
|
||||||
|
#include "core/4.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V4_0
|
#define AUDIO_HAL_VERSION V4_0
|
||||||
#include <core/all-versions/default/ParametersUtil.impl.h>
|
#include <core/all-versions/default/ParametersUtil.impl.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#define LOG_TAG "PrimaryDeviceHAL"
|
#define LOG_TAG "PrimaryDeviceHAL"
|
||||||
|
|
||||||
#include "core/4.0/default/PrimaryDevice.h"
|
#include "core/4.0/default/PrimaryDevice.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/4.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V4_0
|
#define AUDIO_HAL_VERSION V4_0
|
||||||
#include <core/all-versions/default/PrimaryDevice.impl.h>
|
#include <core/all-versions/default/PrimaryDevice.impl.h>
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "core/4.0/default/Stream.h"
|
#include "core/4.0/default/Stream.h"
|
||||||
#include "common/all-versions/default/EffectMap.h"
|
#include "common/all-versions/default/EffectMap.h"
|
||||||
#include "core/4.0/default/Conversions.h"
|
#include "core/4.0/default/Conversions.h"
|
||||||
|
#include "core/4.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V4_0
|
#define AUDIO_HAL_VERSION V4_0
|
||||||
#include <core/all-versions/default/Stream.impl.h>
|
#include <core/all-versions/default/Stream.impl.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#define LOG_TAG "StreamInHAL"
|
#define LOG_TAG "StreamInHAL"
|
||||||
|
|
||||||
#include "core/4.0/default/StreamIn.h"
|
#include "core/4.0/default/StreamIn.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/4.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V4_0
|
#define AUDIO_HAL_VERSION V4_0
|
||||||
#include <core/all-versions/default/StreamIn.impl.h>
|
#include <core/all-versions/default/StreamIn.impl.h>
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#define LOG_TAG "StreamOutHAL"
|
#define LOG_TAG "StreamOutHAL"
|
||||||
|
|
||||||
#include "core/4.0/default/StreamOut.h"
|
#include "core/4.0/default/StreamOut.h"
|
||||||
#include "core/all-versions/default/Util.h"
|
#include "core/4.0/default/Util.h"
|
||||||
|
|
||||||
#define AUDIO_HAL_VERSION V4_0
|
#define AUDIO_HAL_VERSION V4_0
|
||||||
#include <core/all-versions/default/StreamOut.impl.h>
|
#include <core/all-versions/default/StreamOut.impl.h>
|
||||||
|
|
26
audio/core/4.0/default/include/core/4.0/default/Util.h
Normal file
26
audio/core/4.0/default/include/core/4.0/default/Util.h
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
* 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 <android/hardware/audio/4.0/types.h>
|
||||||
|
|
||||||
|
#define AUDIO_HAL_VERSION V4_0
|
||||||
|
#include <core/all-versions/default/Util.h>
|
||||||
|
#undef AUDIO_HAL_VERSION
|
||||||
|
|
||||||
|
#endif // ANDROID_HARDWARE_AUDIO_V4_0_UTIL_H
|
|
@ -25,7 +25,6 @@
|
||||||
#include <android/log.h>
|
#include <android/log.h>
|
||||||
|
|
||||||
using ::android::hardware::audio::common::AUDIO_HAL_VERSION::HidlUtils;
|
using ::android::hardware::audio::common::AUDIO_HAL_VERSION::HidlUtils;
|
||||||
using ::android::hardware::audio::all_versions::implementation::isGainNormalized;
|
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
|
|
|
@ -149,26 +149,7 @@ Result ParametersUtil::setParam(const char* name, const DeviceAddress& address)
|
||||||
|
|
||||||
Result ParametersUtil::setParams(const AudioParameter& param) {
|
Result ParametersUtil::setParams(const AudioParameter& param) {
|
||||||
int halStatus = halSetParameters(param.toString().string());
|
int halStatus = halSetParameters(param.toString().string());
|
||||||
switch (halStatus) {
|
return util::analyzeStatus(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
|
} // namespace implementation
|
||||||
|
|
|
@ -160,7 +160,7 @@ Return<Result> PrimaryDevice::setConnectedState(const DeviceAddress& address, bo
|
||||||
|
|
||||||
// Methods from ::android::hardware::audio::AUDIO_HAL_VERSION::IPrimaryDevice follow.
|
// Methods from ::android::hardware::audio::AUDIO_HAL_VERSION::IPrimaryDevice follow.
|
||||||
Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
|
Return<Result> PrimaryDevice::setVoiceVolume(float volume) {
|
||||||
if (!all_versions::implementation::isGainNormalized(volume)) {
|
if (!isGainNormalized(volume)) {
|
||||||
ALOGW("Can not set a voice volume (%f) outside [0,1]", volume);
|
ALOGW("Can not set a voice volume (%f) outside [0,1]", volume);
|
||||||
return Result::INVALID_ARGUMENTS;
|
return Result::INVALID_ARGUMENTS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,35 +39,14 @@ Stream::~Stream() {
|
||||||
|
|
||||||
// static
|
// static
|
||||||
Result Stream::analyzeStatus(const char* funcName, int status) {
|
Result Stream::analyzeStatus(const char* funcName, int status) {
|
||||||
static const std::vector<int> empty;
|
return util::analyzeStatus("stream", funcName, status);
|
||||||
return analyzeStatus(funcName, status, empty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
inline bool element_in(T e, const std::vector<T>& v) {
|
|
||||||
return std::find(v.begin(), v.end(), e) != v.end();
|
|
||||||
}
|
|
||||||
|
|
||||||
// static
|
// static
|
||||||
Result Stream::analyzeStatus(const char* funcName, int status,
|
Result Stream::analyzeStatus(const char* funcName, int status,
|
||||||
const std::vector<int>& ignoreErrors) {
|
const std::vector<int>& ignoreErrors) {
|
||||||
if (status != 0 && (ignoreErrors.empty() || !element_in(-status, ignoreErrors))) {
|
return util::analyzeStatus("stream", funcName, 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) {
|
char* Stream::halGetParameters(const char* keys) {
|
||||||
|
|
|
@ -25,9 +25,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
using ::android::hardware::audio::AUDIO_HAL_VERSION::MessageQueueFlagBits;
|
using ::android::hardware::audio::AUDIO_HAL_VERSION::MessageQueueFlagBits;
|
||||||
using ::android::hardware::audio::all_versions::implementation::isGainNormalized;
|
|
||||||
#include "Conversions.h"
|
#include "Conversions.h"
|
||||||
#include "Util.h"
|
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
|
|
|
@ -32,7 +32,6 @@ namespace AUDIO_HAL_VERSION {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
using ::android::hardware::audio::common::AUDIO_HAL_VERSION::ThreadInfo;
|
using ::android::hardware::audio::common::AUDIO_HAL_VERSION::ThreadInfo;
|
||||||
using ::android::hardware::audio::all_versions::implementation::isGainNormalized;
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
|
@ -14,24 +14,61 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H
|
#include <common/all-versions/IncludeGuard.h>
|
||||||
#define ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <system/audio.h>
|
||||||
|
|
||||||
namespace android {
|
namespace android {
|
||||||
namespace hardware {
|
namespace hardware {
|
||||||
namespace audio {
|
namespace audio {
|
||||||
namespace all_versions {
|
namespace AUDIO_HAL_VERSION {
|
||||||
namespace implementation {
|
namespace implementation {
|
||||||
|
|
||||||
|
using ::android::hardware::audio::AUDIO_HAL_VERSION::Result;
|
||||||
|
|
||||||
/** @return true if gain is between 0 and 1 included. */
|
/** @return true if gain is between 0 and 1 included. */
|
||||||
constexpr bool isGainNormalized(float gain) {
|
constexpr bool isGainNormalized(float gain) {
|
||||||
return gain >= 0.0 && gain <= 1.0;
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
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<int>& 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 implementation
|
||||||
} // namespace all_versions
|
} // namespace AUDIO_HAL_VERSION
|
||||||
} // namespace audio
|
} // namespace audio
|
||||||
} // namespace hardware
|
} // namespace hardware
|
||||||
} // namespace android
|
} // namespace android
|
||||||
|
|
||||||
#endif // ANDROID_HARDWARE_AUDIO_DEVICE_ALL_VERSIONS_UTIL_H
|
|
||||||
|
|
Loading…
Reference in a new issue