blob: 04f40d36f8d3d9d38357992633cea62a5a0b4d19 [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 Rocard070e7512018-05-22 09:29:13 -070020#include <android/hardware/audio/effect/2.0/IEffect.h>
Kevin Rocard2390b5d2018-02-28 14:36:53 -080021#include <android/hardware/audio/effect/4.0/IEffect.h>
Kevin Rocardd4de2882018-02-28 14:33:38 -080022#include <media/audiohal/EffectHalInterface.h>
23#include <fmq/EventFlag.h>
24#include <fmq/MessageQueue.h>
25#include <system/audio_effect.h>
26
Kevin Rocard070e7512018-05-22 09:29:13 -070027using ::android::hardware::audio::effect::CPP_VERSION::EffectBufferConfig;
28using ::android::hardware::audio::effect::CPP_VERSION::EffectConfig;
29using ::android::hardware::audio::effect::CPP_VERSION::EffectDescriptor;
30using ::android::hardware::audio::effect::CPP_VERSION::IEffect;
31using EffectResult = ::android::hardware::audio::effect::CPP_VERSION::Result;
Kevin Rocardd4de2882018-02-28 14:33:38 -080032using ::android::hardware::EventFlag;
33using ::android::hardware::MessageQueue;
34
35namespace android {
Kevin Rocard070e7512018-05-22 09:29:13 -070036namespace CPP_VERSION {
Kevin Rocardd4de2882018-02-28 14:33:38 -080037
38class 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 Rocarddf9b4202018-05-10 19:56:08 -070074 typedef MessageQueue<EffectResult, hardware::kSynchronizedReadWrite> StatusMQ;
Kevin Rocardd4de2882018-02-28 14:33:38 -080075
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 Rocarddf9b4202018-05-10 19:56:08 -070084 static status_t analyzeResult(const EffectResult& result);
Kevin Rocardd4de2882018-02-28 14:33:38 -080085 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 Rocard070e7512018-05-22 09:29:13 -0700108} // namespace CPP_VERSION
Kevin Rocardd4de2882018-02-28 14:33:38 -0800109} // namespace android
110
Kevin Rocarddf9b4202018-05-10 19:56:08 -0700111#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H