diff options
author | Kevin Rocard | 2018-04-23 16:41:14 -0500 |
---|---|---|
committer | Gerrit Code Review | 2018-04-23 16:41:14 -0500 |
commit | 74e1cbb09486b18e150e1cc8c1e99bc33fa0518f (patch) | |
tree | f2db4a5e8d8457cbd0b25e091a3c38f10b660aa9 | |
parent | a7b9291b825755adb5249bd53e4aac2ee801e7f8 (diff) | |
parent | 574cc909d4d7659f641de10e2f571e44521d3979 (diff) | |
download | platform-hardware-interfaces-74e1cbb09486b18e150e1cc8c1e99bc33fa0518f.tar.gz platform-hardware-interfaces-74e1cbb09486b18e150e1cc8c1e99bc33fa0518f.tar.xz platform-hardware-interfaces-74e1cbb09486b18e150e1cc8c1e99bc33fa0518f.zip |
Merge "Audio: setParam improve status_t to Result consistency"
-rw-r--r-- | audio/2.0/default/Device.cpp | 18 | ||||
-rw-r--r-- | audio/2.0/default/ParametersUtil.cpp | 8 | ||||
-rw-r--r-- | audio/2.0/default/Stream.cpp | 20 | ||||
-rw-r--r-- | audio/2.0/default/Util.h | 38 |
4 files changed, 44 insertions, 40 deletions
diff --git a/audio/2.0/default/Device.cpp b/audio/2.0/default/Device.cpp index 37279662..8b83e464 100644 --- a/audio/2.0/default/Device.cpp +++ b/audio/2.0/default/Device.cpp | |||
@@ -48,23 +48,7 @@ Device::~Device() { | |||
48 | } | 48 | } |
49 | 49 | ||
50 | Result Device::analyzeStatus(const char* funcName, int status) { | 50 | Result Device::analyzeStatus(const char* funcName, int status) { |
51 | if (status != 0) { | 51 | return util::analyzeStatus("Device", funcName, status); |
52 | ALOGW("Device %p %s: %s", mDevice, funcName, strerror(-status)); | ||
53 | } | ||
54 | switch (status) { | ||
55 | case 0: | ||
56 | return Result::OK; | ||
57 | case -EINVAL: | ||
58 | return Result::INVALID_ARGUMENTS; | ||
59 | case -ENODATA: | ||
60 | return Result::INVALID_STATE; | ||
61 | case -ENODEV: | ||
62 | return Result::NOT_INITIALIZED; | ||
63 | case -ENOSYS: | ||
64 | return Result::NOT_SUPPORTED; | ||
65 | default: | ||
66 | return Result::INVALID_STATE; | ||
67 | } | ||
68 | } | 52 | } |
69 | 53 | ||
70 | void Device::closeInputStream(audio_stream_in_t* stream) { | 54 | void Device::closeInputStream(audio_stream_in_t* stream) { |
diff --git a/audio/2.0/default/ParametersUtil.cpp b/audio/2.0/default/ParametersUtil.cpp index 2140885f..257c8e5f 100644 --- a/audio/2.0/default/ParametersUtil.cpp +++ b/audio/2.0/default/ParametersUtil.cpp | |||
@@ -15,6 +15,7 @@ | |||
15 | */ | 15 | */ |
16 | 16 | ||
17 | #include "ParametersUtil.h" | 17 | #include "ParametersUtil.h" |
18 | #include "Util.h" | ||
18 | 19 | ||
19 | namespace android { | 20 | namespace android { |
20 | namespace hardware { | 21 | namespace hardware { |
@@ -141,12 +142,7 @@ Result ParametersUtil::setParametersImpl( | |||
141 | 142 | ||
142 | Result ParametersUtil::setParams(const AudioParameter& param) { | 143 | Result ParametersUtil::setParams(const AudioParameter& param) { |
143 | int halStatus = halSetParameters(param.toString().string()); | 144 | int halStatus = halSetParameters(param.toString().string()); |
144 | if (halStatus == OK) | 145 | return util::analyzeStatus(halStatus); |
145 | return Result::OK; | ||
146 | else if (halStatus == -ENOSYS) | ||
147 | return Result::INVALID_STATE; | ||
148 | else | ||
149 | return Result::INVALID_ARGUMENTS; | ||
150 | } | 146 | } |
151 | 147 | ||
152 | } // namespace implementation | 148 | } // namespace implementation |
diff --git a/audio/2.0/default/Stream.cpp b/audio/2.0/default/Stream.cpp index effdd285..55ae6dbd 100644 --- a/audio/2.0/default/Stream.cpp +++ b/audio/2.0/default/Stream.cpp | |||
@@ -28,6 +28,7 @@ | |||
28 | #include "Conversions.h" | 28 | #include "Conversions.h" |
29 | #include "EffectMap.h" | 29 | #include "EffectMap.h" |
30 | #include "Stream.h" | 30 | #include "Stream.h" |
31 | #include "Util.h" | ||
31 | 32 | ||
32 | namespace android { | 33 | namespace android { |
33 | namespace hardware { | 34 | namespace hardware { |
@@ -45,29 +46,14 @@ Stream::~Stream() { | |||
45 | 46 | ||
46 | // static | 47 | // static |
47 | Result Stream::analyzeStatus(const char* funcName, int status) { | 48 | Result Stream::analyzeStatus(const char* funcName, int status) { |
48 | static const std::vector<int> empty; | 49 | return util::analyzeStatus("stream", funcName, status); |
49 | return analyzeStatus(funcName, status, empty); | ||
50 | } | 50 | } |
51 | 51 | ||
52 | template <typename T> | ||
53 | inline bool element_in(T e, const std::vector<T>& v) { | ||
54 | return std::find(v.begin(), v.end(), e) != v.end(); | ||
55 | } | ||
56 | 52 | ||
57 | // static | 53 | // static |
58 | Result Stream::analyzeStatus(const char* funcName, int status, | 54 | Result Stream::analyzeStatus(const char* funcName, int status, |
59 | const std::vector<int>& ignoreErrors) { | 55 | const std::vector<int>& ignoreErrors) { |
60 | if (status != 0 && (ignoreErrors.empty() || !element_in(-status, ignoreErrors))) { | 56 | return util::analyzeStatus("stream", funcName, status, ignoreErrors); |
61 | ALOGW("Error from HAL stream in function %s: %s", funcName, strerror(-status)); | ||
62 | } | ||
63 | switch (status) { | ||
64 | case 0: return Result::OK; | ||
65 | case -EINVAL: return Result::INVALID_ARGUMENTS; | ||
66 | case -ENODATA: return Result::INVALID_STATE; | ||
67 | case -ENODEV: return Result::NOT_INITIALIZED; | ||
68 | case -ENOSYS: return Result::NOT_SUPPORTED; | ||
69 | default: return Result::INVALID_STATE; | ||
70 | } | ||
71 | } | 57 | } |
72 | 58 | ||
73 | char* Stream::halGetParameters(const char* keys) { | 59 | char* Stream::halGetParameters(const char* keys) { |
diff --git a/audio/2.0/default/Util.h b/audio/2.0/default/Util.h index 72eea503..55019b87 100644 --- a/audio/2.0/default/Util.h +++ b/audio/2.0/default/Util.h | |||
@@ -17,6 +17,11 @@ | |||
17 | #ifndef ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H | 17 | #ifndef ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H |
18 | #define ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H | 18 | #define ANDROID_HARDWARE_AUDIO_V2_0_UTIL_H |
19 | 19 | ||
20 | #include <algorithm> | ||
21 | #include <vector> | ||
22 | |||
23 | #include <system/audio.h> | ||
24 | |||
20 | namespace android { | 25 | namespace android { |
21 | namespace hardware { | 26 | namespace hardware { |
22 | namespace audio { | 27 | namespace audio { |
@@ -28,6 +33,39 @@ constexpr bool isGainNormalized(float gain) { | |||
28 | return gain >= 0.0 && gain <= 1.0; | 33 | return gain >= 0.0 && gain <= 1.0; |
29 | } | 34 | } |
30 | 35 | ||
36 | namespace util { | ||
37 | |||
38 | template <typename T> | ||
39 | inline bool element_in(T e, const std::vector<T>& v) { | ||
40 | return std::find(v.begin(), v.end(), e) != v.end(); | ||
41 | } | ||
42 | |||
43 | static inline Result analyzeStatus(status_t status) { | ||
44 | switch (status) { | ||
45 | case 0: | ||
46 | return Result::OK; | ||
47 | case -EINVAL: | ||
48 | return Result::INVALID_ARGUMENTS; | ||
49 | case -ENODATA: | ||
50 | return Result::INVALID_STATE; | ||
51 | case -ENODEV: | ||
52 | return Result::NOT_INITIALIZED; | ||
53 | case -ENOSYS: | ||
54 | return Result::NOT_SUPPORTED; | ||
55 | default: | ||
56 | return Result::INVALID_STATE; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | static inline Result analyzeStatus(const char* className, const char* funcName, status_t status, | ||
61 | const std::vector<int>& ignoreErrors = {}) { | ||
62 | if (status != 0 && !element_in(-status, ignoreErrors)) { | ||
63 | ALOGW("Error from HAL %s in function %s: %s", className, funcName, strerror(-status)); | ||
64 | } | ||
65 | return analyzeStatus(status); | ||
66 | } | ||
67 | |||
68 | } // namespace util | ||
31 | } // namespace implementation | 69 | } // namespace implementation |
32 | } // namespace V2_0 | 70 | } // namespace V2_0 |
33 | } // namespace audio | 71 | } // namespace audio |