blob: 07745dbdb0ef066bff5eeed368eb05e6fd7b2e4d [file] [log] [blame]
Kevin Rocardd4de2882018-02-28 14:33:38 -08001/*
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 Rocarddf9b4202018-05-10 19:56:08 -070017#ifndef ANDROID_HARDWARE_EFFECT_HAL_HIDL_H
18#define ANDROID_HARDWARE_EFFECT_HAL_HIDL_H
Kevin Rocardd4de2882018-02-28 14:33:38 -080019
Kevin Rocard95213bf2018-11-08 17:16:57 -080020#include PATH(android/hardware/audio/effect/FILE_VERSION/IEffect.h)
Kevin Rocardd4de2882018-02-28 14:33:38 -080021#include <media/audiohal/EffectHalInterface.h>
22#include <fmq/EventFlag.h>
23#include <fmq/MessageQueue.h>
24#include <system/audio_effect.h>
25
Kevin Rocardd4de2882018-02-28 14:33:38 -080026using ::android::hardware::EventFlag;
27using ::android::hardware::MessageQueue;
28
29namespace android {
Mikhail Naganov595caa32018-12-13 11:08:28 -080030namespace effect {
Kevin Rocardd4de2882018-02-28 14:33:38 -080031
Mikhail Naganov595caa32018-12-13 11:08:28 -080032using namespace ::android::hardware::audio::effect::CPP_VERSION;
33
Kevin Rocardd4de2882018-02-28 14:33:38 -080034class EffectHalHidl : public EffectHalInterface
35{
36 public:
37 // Set the input buffer.
38 virtual status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer);
39
40 // Set the output buffer.
41 virtual status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer);
42
43 // Effect process function.
44 virtual status_t process();
45
46 // Process reverse stream function. This function is used to pass
47 // a reference stream to the effect engine.
48 virtual status_t processReverse();
49
50 // Send a command and receive a response to/from effect engine.
51 virtual status_t command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
52 uint32_t *replySize, void *pReplyData);
53
54 // Returns the effect descriptor.
55 virtual status_t getDescriptor(effect_descriptor_t *pDescriptor);
56
57 // Free resources on the remote side.
58 virtual status_t close();
59
60 // Whether it's a local implementation.
61 virtual bool isLocal() const { return false; }
62
Mikhail Naganov4d547672019-02-22 14:19:19 -080063 virtual status_t dump(int fd);
64
Mikhail Naganov6718c392022-01-27 22:17:21 +000065 virtual uint64_t effectId() const { return mEffectId; }
Kevin Rocardd4de2882018-02-28 14:33:38 -080066
Kevin Rocardd4de2882018-02-28 14:33:38 -080067 private:
68 friend class EffectsFactoryHalHidl;
Mikhail Naganov595caa32018-12-13 11:08:28 -080069 typedef MessageQueue<Result, hardware::kSynchronizedReadWrite> StatusMQ;
Kevin Rocardd4de2882018-02-28 14:33:38 -080070
71 sp<IEffect> mEffect;
72 const uint64_t mEffectId;
73 sp<EffectBufferHalInterface> mInBuffer;
74 sp<EffectBufferHalInterface> mOutBuffer;
75 bool mBuffersChanged;
76 std::unique_ptr<StatusMQ> mStatusMQ;
77 EventFlag* mEfGroup;
Mikhail Naganov247b5f92021-01-15 19:16:12 +000078 bool mIsInput = false;
Kevin Rocardd4de2882018-02-28 14:33:38 -080079
Mikhail Naganov595caa32018-12-13 11:08:28 -080080 static status_t analyzeResult(const Result& result);
Kevin Rocardd4de2882018-02-28 14:33:38 -080081
82 // Can not be constructed directly by clients.
83 EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId);
84
85 // The destructor automatically releases the effect.
86 virtual ~EffectHalHidl();
87
88 status_t getConfigImpl(uint32_t cmdCode, uint32_t *replySize, void *pReplyData);
89 status_t prepareForProcessing();
90 bool needToResetBuffers();
91 status_t processImpl(uint32_t mqFlag);
92 status_t setConfigImpl(
93 uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
94 uint32_t *replySize, void *pReplyData);
95 status_t setProcessBuffers();
96};
97
Mikhail Naganov595caa32018-12-13 11:08:28 -080098} // namespace effect
Kevin Rocardd4de2882018-02-28 14:33:38 -080099} // namespace android
100
Kevin Rocarddf9b4202018-05-10 19:56:08 -0700101#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H