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 | |
| 26 | using ::android::hardware::audio::effect::V2_0::EffectDescriptor; |
| 27 | using ::android::hardware::audio::effect::V2_0::IEffect; |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 28 | using ::android::hardware::EventFlag; |
| 29 | using ::android::hardware::MessageQueue; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | class EffectHalHidl : public EffectHalInterface |
| 34 | { |
| 35 | public: |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 36 | // Set the input buffer. |
| 37 | virtual status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer); |
| 38 | |
| 39 | // Set the output buffer. |
| 40 | virtual status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer); |
| 41 | |
| 42 | // Effect process function. |
| 43 | virtual status_t process(); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 44 | |
| 45 | // Process reverse stream function. This function is used to pass |
| 46 | // a reference stream to the effect engine. |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 47 | virtual status_t processReverse(); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 48 | |
| 49 | // Send a command and receive a response to/from effect engine. |
| 50 | virtual status_t command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData, |
| 51 | uint32_t *replySize, void *pReplyData); |
| 52 | |
| 53 | // Returns the effect descriptor. |
| 54 | virtual status_t getDescriptor(effect_descriptor_t *pDescriptor); |
| 55 | |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 56 | // Free resources on the remote side. |
| 57 | virtual status_t close(); |
| 58 | |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 59 | uint64_t effectId() const { return mEffectId; } |
| 60 | |
| 61 | static void effectDescriptorToHal( |
| 62 | const EffectDescriptor& descriptor, effect_descriptor_t* halDescriptor); |
| 63 | |
| 64 | private: |
| 65 | friend class EffectsFactoryHalHidl; |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 66 | typedef MessageQueue< |
| 67 | hardware::audio::effect::V2_0::Result, hardware::kSynchronizedReadWrite> StatusMQ; |
| 68 | |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 69 | sp<IEffect> mEffect; |
| 70 | const uint64_t mEffectId; |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 71 | sp<EffectBufferHalInterface> mInBuffer; |
| 72 | sp<EffectBufferHalInterface> mOutBuffer; |
| 73 | bool mBuffersChanged; |
| 74 | std::unique_ptr<StatusMQ> mStatusMQ; |
| 75 | EventFlag* mEfGroup; |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 76 | |
| 77 | static status_t analyzeResult(const hardware::audio::effect::V2_0::Result& result); |
| 78 | |
| 79 | // Can not be constructed directly by clients. |
| 80 | EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId); |
| 81 | |
| 82 | // The destructor automatically releases the effect. |
| 83 | virtual ~EffectHalHidl(); |
Mikhail Naganov | 022b995 | 2017-01-04 16:36:51 -0800 | [diff] [blame] | 84 | |
| 85 | status_t prepareForProcessing(); |
| 86 | status_t processImpl(uint32_t mqFlag); |
| 87 | status_t setProcessBuffers(); |
Mikhail Naganov | f558e02 | 2016-11-14 17:45:17 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | } // namespace android |
| 91 | |
| 92 | #endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H |