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