1+ /*
2+ * Copyright (C) 2022 The Android Open Source Project
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+
17+ #pragma once
18+ #include < string>
19+
20+ #include < aidl/android/hardware/audio/effect/BnEffect.h>
21+ #include < aidl/android/hardware/audio/effect/Range.h>
22+ #include < android-base/logging.h>
23+ // #include <system/audio_effects/aidl_effects_utils.h>
24+
25+ typedef binder_exception_t (*EffectCreateFunctor)(
26+ const ::aidl::android::media::audio::common::AudioUuid*,
27+ std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>*);
28+ typedef binder_exception_t (*EffectDestroyFunctor)(
29+ const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>&);
30+ typedef binder_exception_t (*EffectQueryFunctor)(
31+ const ::aidl::android::media::audio::common::AudioUuid*,
32+ ::aidl::android::hardware::audio::effect::Descriptor*);
33+
34+ struct effect_dl_interface_s {
35+ EffectCreateFunctor createEffectFunc;
36+ EffectDestroyFunctor destroyEffectFunc;
37+ EffectQueryFunctor queryEffectFunc;
38+ };
39+
40+ namespace aidl ::android::hardware::audio::effect {
41+
42+ enum class RetCode {
43+ SUCCESS,
44+ ERROR_ILLEGAL_PARAMETER, /* Illegal parameter */
45+ ERROR_THREAD, /* Effect thread error */
46+ ERROR_NULL_POINTER, /* NULL pointer */
47+ ERROR_ALIGNMENT_ERROR, /* Memory alignment error */
48+ ERROR_BLOCK_SIZE_EXCEED, /* Maximum block size exceeded */
49+ ERROR_EFFECT_LIB_ERROR, /* Effect implementation library error */
50+ ERROR_EVENT_FLAG_ERROR /* Error with effect event flags */
51+ };
52+
53+ static const int INVALID_AUDIO_SESSION_ID = -1 ;
54+
55+ inline std::ostream& operator <<(std::ostream& out, const RetCode& code) {
56+ switch (code) {
57+ case RetCode::SUCCESS:
58+ return out << " SUCCESS" ;
59+ case RetCode::ERROR_ILLEGAL_PARAMETER:
60+ return out << " ERROR_ILLEGAL_PARAMETER" ;
61+ case RetCode::ERROR_THREAD:
62+ return out << " ERROR_THREAD" ;
63+ case RetCode::ERROR_NULL_POINTER:
64+ return out << " ERROR_NULL_POINTER" ;
65+ case RetCode::ERROR_ALIGNMENT_ERROR:
66+ return out << " ERROR_ALIGNMENT_ERROR" ;
67+ case RetCode::ERROR_BLOCK_SIZE_EXCEED:
68+ return out << " ERROR_BLOCK_SIZE_EXCEED" ;
69+ case RetCode::ERROR_EFFECT_LIB_ERROR:
70+ return out << " ERROR_EFFECT_LIB_ERROR" ;
71+ case RetCode::ERROR_EVENT_FLAG_ERROR:
72+ return out << " ERROR_EVENT_FLAG_ERROR" ;
73+ }
74+
75+ return out << " EnumError: " << code;
76+ }
77+
78+ #define RETURN_IF_ASTATUS_NOT_OK (status, message ) \
79+ do { \
80+ const ::ndk::ScopedAStatus curr_status = (status); \
81+ if (!curr_status.isOk ()) { \
82+ LOG (ERROR) << __func__ << " : line" << __LINE__ \
83+ << " return with status: " << curr_status.getDescription () << (message); \
84+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage ( \
85+ curr_status.getExceptionCode (), (message)); \
86+ } \
87+ } while (0 )
88+
89+ #define RETURN_IF (expr, exception, message ) \
90+ do { \
91+ if (expr) { \
92+ LOG (ERROR) << __func__ << " : line" << __LINE__ << " return with expr " << #expr; \
93+ return ndk::ScopedAStatus::fromExceptionCodeWithMessage ((exception), (message)); \
94+ } \
95+ } while (0 )
96+
97+ #define RETURN_OK_IF (expr ) \
98+ do { \
99+ if (expr) { \
100+ LOG (INFO) << __func__ << " : line" << __LINE__ << " return with expr " << #expr; \
101+ return ndk::ScopedAStatus::ok (); \
102+ } \
103+ } while (0 )
104+
105+ #define RETURN_VALUE_IF (expr, ret, log ) \
106+ do { \
107+ if (expr) { \
108+ LOG (ERROR) << __func__ << " : line" << __LINE__ << " return with expr \" " << #expr \
109+ << " \" :" << (log); \
110+ return ret; \
111+ } \
112+ } while (0 )
113+
114+ #define RETURN_IF_BINDER_EXCEPTION (functor ) \
115+ { \
116+ binder_exception_t exception = functor; \
117+ if (EX_NONE != exception) { \
118+ LOG (ERROR) << #functor << " : failed with error " << exception; \
119+ return ndk::ScopedAStatus::fromExceptionCode (exception); \
120+ } \
121+ }
122+
123+ /* *
124+ * Make a Range::$EffectType$Range.
125+ * T: The $EffectType$, Visualizer for example.
126+ * Tag: The union tag name in $EffectType$ definition, latencyMs for example.
127+ * l: The value of Range::$EffectType$Range.min.
128+ * r: The value of Range::$EffectType$Range.max.
129+ */
130+ #define MAKE_RANGE (T, Tag, l, r ) \
131+ { .min = T::make<T::Tag>(l), .max = T::make<T::Tag>(r) }
132+
133+ } // namespace aidl::android::hardware::audio::effect
0 commit comments