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