blob: 9d9f707c859a8fb9d8f380de1c8230b614b074b8 [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 Rocard070e7512018-05-22 09:29:13 -070031namespace CPP_VERSION {
Kevin Rocardd4de2882018-02-28 14:33:38 -080032
Mikhail Naganov595caa32018-12-13 11:08:28 -080033using namespace ::android::hardware::audio::effect::CPP_VERSION;
34
Kevin Rocardd4de2882018-02-28 14:33:38 -080035class EffectHalHidl : public EffectHalInterface
36{
37 public:
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();
46
47 // Process reverse stream function. This function is used to pass
48 // a reference stream to the effect engine.
49 virtual status_t processReverse();
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
58 // Free resources on the remote side.
59 virtual status_t close();
60
61 // Whether it's a local implementation.
62 virtual bool isLocal() const { return false; }
63
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 Naganov595caa32018-12-13 11:08:28 -080071 typedef MessageQueue<Result, hardware::kSynchronizedReadWrite> StatusMQ;
Kevin Rocardd4de2882018-02-28 14:33:38 -080072
73 sp<IEffect> mEffect;
74 const uint64_t mEffectId;
75 sp<EffectBufferHalInterface> mInBuffer;
76 sp<EffectBufferHalInterface> mOutBuffer;
77 bool mBuffersChanged;
78 std::unique_ptr<StatusMQ> mStatusMQ;
79 EventFlag* mEfGroup;
80
Mikhail Naganov595caa32018-12-13 11:08:28 -080081 static status_t analyzeResult(const Result& result);
Kevin Rocardd4de2882018-02-28 14:33:38 -080082 static void effectBufferConfigFromHal(
83 const buffer_config_t& halConfig, EffectBufferConfig* config);
84 static void effectBufferConfigToHal(
85 const EffectBufferConfig& config, buffer_config_t* halConfig);
86 static void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config);
87 static void effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig);
88
89 // Can not be constructed directly by clients.
90 EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId);
91
92 // The destructor automatically releases the effect.
93 virtual ~EffectHalHidl();
94
95 status_t getConfigImpl(uint32_t cmdCode, uint32_t *replySize, void *pReplyData);
96 status_t prepareForProcessing();
97 bool needToResetBuffers();
98 status_t processImpl(uint32_t mqFlag);
99 status_t setConfigImpl(
100 uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
101 uint32_t *replySize, void *pReplyData);
102 status_t setProcessBuffers();
103};
104
Kevin Rocard070e7512018-05-22 09:29:13 -0700105} // namespace CPP_VERSION
Mikhail Naganov595caa32018-12-13 11:08:28 -0800106} // namespace effect
Kevin Rocardd4de2882018-02-28 14:33:38 -0800107} // namespace android
108
Kevin Rocarddf9b4202018-05-10 19:56:08 -0700109#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H