1 /*
2  * Copyright (C) 2018 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 #ifndef ANDROID_HARDWARE_AUDIO_EFFECT_VIRTUALIZEREFFECT_H
18 #define ANDROID_HARDWARE_AUDIO_EFFECT_VIRTUALIZEREFFECT_H
19 
20 #include PATH(android/hardware/audio/effect/FILE_VERSION/IVirtualizerEffect.h)
21 
22 #include "Effect.h"
23 
24 #include <hidl/Status.h>
25 
26 #include <hidl/MQDescriptor.h>
27 
28 #include "VersionUtils.h"
29 
30 namespace android {
31 namespace hardware {
32 namespace audio {
33 namespace effect {
34 namespace CPP_VERSION {
35 namespace implementation {
36 
37 using ::android::sp;
38 using ::android::hardware::hidl_string;
39 using ::android::hardware::hidl_vec;
40 using ::android::hardware::Return;
41 using ::android::hardware::Void;
42 #if MAJOR_VERSION <= 6
43 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::implementation::
44         AudioChannelBitfield;
45 #endif
46 using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION;
47 using namespace ::android::hardware::audio::effect::CPP_VERSION;
48 
49 struct VirtualizerEffect : public IVirtualizerEffect {
50     explicit VirtualizerEffect(effect_handle_t handle);
51 
52     // Methods from ::android::hardware::audio::effect::CPP_VERSION::IEffect follow.
53     Return<Result> init() override;
54     Return<Result> setConfig(
55         const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
56         const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
57     Return<Result> reset() override;
58     Return<Result> enable() override;
59     Return<Result> disable() override;
60 #if MAJOR_VERSION <= 6
61     Return<Result> setAudioSource(AudioSource source) override;
62     Return<Result> setDevice(AudioDeviceBitfield device) override;
63     Return<Result> setInputDevice(AudioDeviceBitfield device) override;
64 #else
65     Return<Result> setAudioSource(const AudioSource& source) override;
66     Return<Result> setDevice(const DeviceAddress& device) override;
67     Return<Result> setInputDevice(const DeviceAddress& device) override;
68 #endif
69     Return<void> setAndGetVolume(const hidl_vec<uint32_t>& volumes,
70                                  setAndGetVolume_cb _hidl_cb) override;
71     Return<Result> volumeChangeNotification(const hidl_vec<uint32_t>& volumes) override;
72     Return<Result> setAudioMode(AudioMode mode) override;
73     Return<Result> setConfigReverse(
74         const EffectConfig& config, const sp<IEffectBufferProviderCallback>& inputBufferProvider,
75         const sp<IEffectBufferProviderCallback>& outputBufferProvider) override;
76     Return<void> getConfig(getConfig_cb _hidl_cb) override;
77     Return<void> getConfigReverse(getConfigReverse_cb _hidl_cb) override;
78     Return<void> getSupportedAuxChannelsConfigs(
79         uint32_t maxConfigs, getSupportedAuxChannelsConfigs_cb _hidl_cb) override;
80     Return<void> getAuxChannelsConfig(getAuxChannelsConfig_cb _hidl_cb) override;
81     Return<Result> setAuxChannelsConfig(const EffectAuxChannelsConfig& config) override;
82     Return<Result> offload(const EffectOffloadParameter& param) override;
83     Return<void> getDescriptor(getDescriptor_cb _hidl_cb) override;
84     Return<void> prepareForProcessing(prepareForProcessing_cb _hidl_cb) override;
85     Return<Result> setProcessBuffers(const AudioBuffer& inBuffer,
86                                      const AudioBuffer& outBuffer) override;
87     Return<void> command(uint32_t commandId, const hidl_vec<uint8_t>& data, uint32_t resultMaxSize,
88                          command_cb _hidl_cb) override;
89     Return<Result> setParameter(const hidl_vec<uint8_t>& parameter,
90                                 const hidl_vec<uint8_t>& value) override;
91     Return<void> getParameter(const hidl_vec<uint8_t>& parameter, uint32_t valueMaxSize,
92                               getParameter_cb _hidl_cb) override;
93     Return<void> getSupportedConfigsForFeature(uint32_t featureId, uint32_t maxConfigs,
94                                                uint32_t configSize,
95                                                getSupportedConfigsForFeature_cb _hidl_cb) override;
96     Return<void> getCurrentConfigForFeature(uint32_t featureId, uint32_t configSize,
97                                             getCurrentConfigForFeature_cb _hidl_cb) override;
98     Return<Result> setCurrentConfigForFeature(uint32_t featureId,
99                                               const hidl_vec<uint8_t>& configData) override;
100     Return<Result> close() override;
101     Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;
102 
103     // Methods from ::android::hardware::audio::effect::CPP_VERSION::IVirtualizerEffect
104     // follow.
105     Return<bool> isStrengthSupported() override;
106     Return<Result> setStrength(uint16_t strength) override;
107     Return<void> getStrength(getStrength_cb _hidl_cb) override;
108     Return<void> getVirtualizationMode(getVirtualizationMode_cb _hidl_cb) override;
109 #if MAJOR_VERSION <= 6
110     Return<void> getVirtualSpeakerAngles(AudioChannelBitfield mask, AudioDevice device,
111                                          getVirtualSpeakerAngles_cb _hidl_cb) override;
112     Return<Result> forceVirtualizationMode(AudioDevice device) override;
113 #else
114     Return<void> getVirtualSpeakerAngles(const AudioChannelMask& mask, const DeviceAddress& device,
115                                          getVirtualSpeakerAngles_cb _hidl_cb) override;
116     Return<Result> forceVirtualizationMode(const DeviceAddress& device) override;
117 #endif
118 
119   private:
120     sp<Effect> mEffect;
121 
122     virtual ~VirtualizerEffect() = default;
123 
124 #if MAJOR_VERSION <= 6
125     using SpeakerAngles = hidl_vec<SpeakerAngle>;
126 #endif
127     static status_t speakerAnglesFromHal(const int32_t* halAngles, uint32_t channelCount,
128                                          SpeakerAngles& speakerAngles);
129 };
130 
131 }  // namespace implementation
132 }  // namespace CPP_VERSION
133 }  // namespace effect
134 }  // namespace audio
135 }  // namespace hardware
136 }  // namespace android
137 
138 #endif  // ANDROID_HARDWARE_AUDIO_EFFECT_VIRTUALIZEREFFECT_H
139