Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_EFFECT_HAL_HIDL_H |
| 18 | #define ANDROID_HARDWARE_EFFECT_HAL_HIDL_H |
| 19 | |
| 20 | #include <android/hardware/audio/effect/2.0/IEffect.h> |
| 21 | #include <media/audiohal/EffectHalInterface.h> |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 22 | #include <fmq/EventFlag.h> |
| 23 | #include <fmq/MessageQueue.h> |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 24 | #include <system/audio_effect.h> |
| 25 | |
Mikhail Naganov | f508bd4 | 2017-02-16 13:51:20 -0800 | [diff] [blame] | 26 | using ::android::hardware::audio::effect::V2_0::EffectBufferConfig; |
| 27 | using ::android::hardware::audio::effect::V2_0::EffectConfig; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 28 | using ::android::hardware::audio::effect::V2_0::EffectDescriptor; |
| 29 | using ::android::hardware::audio::effect::V2_0::IEffect; |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 30 | using ::android::hardware::EventFlag; |
| 31 | using ::android::hardware::MessageQueue; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 32 | |
| 33 | namespace android { |
| 34 | |
| 35 | class EffectHalHidl : public EffectHalInterface |
| 36 | { |
| 37 | public: |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 38 | // Set the input buffer. |
| 39 | virtual status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer); |
| 40 | |
| 41 | // Set the output buffer. |
| 42 | virtual status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer); |
| 43 | |
| 44 | // Effect process function. |
| 45 | virtual status_t process(); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 46 | |
| 47 | // Process reverse stream function. This function is used to pass |
| 48 | // a reference stream to the effect engine. |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 49 | virtual status_t processReverse(); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 50 | |
| 51 | // Send a command and receive a response to/from effect engine. |
| 52 | virtual status_t command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, |
| 53 | uint32_t *replySize, void *pReplyData); |
| 54 | |
| 55 | // Returns the effect descriptor. |
| 56 | virtual status_t getDescriptor(effect_descriptor_t *pDescriptor); |
| 57 | |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 58 | // Free resources on the remote side. |
| 59 | virtual status_t close(); |
| 60 | |
Mikhail Naganov | 6b111f3 | 2017-04-27 18:52:37 -0700 | [diff] [blame^] | 61 | // Whether it's a local implementation. |
| 62 | virtual bool isLocal() const { return false; } |
| 63 | |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 64 | uint64_t effectId() const { return mEffectId; } |
| 65 | |
| 66 | static void effectDescriptorToHal( |
| 67 | const EffectDescriptor& descriptor, effect_descriptor_t* halDescriptor); |
| 68 | |
| 69 | private: |
| 70 | friend class EffectsFactoryHalHidl; |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 71 | typedef MessageQueue< |
| 72 | hardware::audio::effect::V2_0::Result, hardware::kSynchronizedReadWrite> StatusMQ; |
| 73 | |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 74 | sp<IEffect> mEffect; |
| 75 | const uint64_t mEffectId; |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 76 | sp<EffectBufferHalInterface> mInBuffer; |
| 77 | sp<EffectBufferHalInterface> mOutBuffer; |
| 78 | bool mBuffersChanged; |
| 79 | std::unique_ptr<StatusMQ> mStatusMQ; |
| 80 | EventFlag* mEfGroup; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 81 | |
| 82 | static status_t analyzeResult(const hardware::audio::effect::V2_0::Result& result); |
Mikhail Naganov | f508bd4 | 2017-02-16 13:51:20 -0800 | [diff] [blame] | 83 | static void effectBufferConfigFromHal( |
| 84 | const buffer_config_t& halConfig, EffectBufferConfig* config); |
Mikhail Naganov | ed01be5 | 2017-02-16 15:57:07 -0800 | [diff] [blame] | 85 | static void effectBufferConfigToHal( |
| 86 | const EffectBufferConfig& config, buffer_config_t* halConfig); |
Mikhail Naganov | f508bd4 | 2017-02-16 13:51:20 -0800 | [diff] [blame] | 87 | static void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config); |
Mikhail Naganov | ed01be5 | 2017-02-16 15:57:07 -0800 | [diff] [blame] | 88 | static void effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 89 | |
| 90 | // Can not be constructed directly by clients. |
| 91 | EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId); |
| 92 | |
| 93 | // The destructor automatically releases the effect. |
| 94 | virtual ~EffectHalHidl(); |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 95 | |
Mikhail Naganov | ed01be5 | 2017-02-16 15:57:07 -0800 | [diff] [blame] | 96 | status_t getConfigImpl(uint32_t cmdCode, uint32_t *replySize, void *pReplyData); |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 97 | status_t prepareForProcessing(); |
Mikhail Naganov | 40be8a3 | 2017-04-26 17:22:00 -0700 | [diff] [blame] | 98 | bool needToResetBuffers(); |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 99 | status_t processImpl(uint32_t mqFlag); |
Mikhail Naganov | f508bd4 | 2017-02-16 13:51:20 -0800 | [diff] [blame] | 100 | status_t setConfigImpl( |
| 101 | uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, |
| 102 | uint32_t *replySize, void *pReplyData); |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 103 | status_t setProcessBuffers(); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | } // namespace android |
| 107 | |
| 108 | #endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H |