blob: 1ed11532d2b003426a39d68f0c7589bba9777c6d [file] [log] [blame]
Mikhail Naganovf558e022016-11-14 17:45:17 -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
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 Naganov022b9952017-01-04 16:36:51 -080022#include <fmq/EventFlag.h>
23#include <fmq/MessageQueue.h>
Mikhail Naganovf558e022016-11-14 17:45:17 -080024#include <system/audio_effect.h>
25
26using ::android::hardware::audio::effect::V2_0::EffectDescriptor;
27using ::android::hardware::audio::effect::V2_0::IEffect;
Mikhail Naganov022b9952017-01-04 16:36:51 -080028using ::android::hardware::EventFlag;
29using ::android::hardware::MessageQueue;
Mikhail Naganovf558e022016-11-14 17:45:17 -080030
31namespace android {
32
33class EffectHalHidl : public EffectHalInterface
34{
35 public:
Mikhail Naganov022b9952017-01-04 16:36:51 -080036 // 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 Naganovf558e022016-11-14 17:45:17 -080044
45 // Process reverse stream function. This function is used to pass
46 // a reference stream to the effect engine.
Mikhail Naganov022b9952017-01-04 16:36:51 -080047 virtual status_t processReverse();
Mikhail Naganovf558e022016-11-14 17:45:17 -080048
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 Naganov022b9952017-01-04 16:36:51 -080056 // Free resources on the remote side.
57 virtual status_t close();
58
Mikhail Naganovf558e022016-11-14 17:45:17 -080059 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 Naganov022b9952017-01-04 16:36:51 -080066 typedef MessageQueue<
67 hardware::audio::effect::V2_0::Result, hardware::kSynchronizedReadWrite> StatusMQ;
68
Mikhail Naganovf558e022016-11-14 17:45:17 -080069 sp<IEffect> mEffect;
70 const uint64_t mEffectId;
Mikhail Naganov022b9952017-01-04 16:36:51 -080071 sp<EffectBufferHalInterface> mInBuffer;
72 sp<EffectBufferHalInterface> mOutBuffer;
73 bool mBuffersChanged;
74 std::unique_ptr<StatusMQ> mStatusMQ;
75 EventFlag* mEfGroup;
Mikhail Naganovf558e022016-11-14 17:45:17 -080076
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 Naganov022b9952017-01-04 16:36:51 -080084
85 status_t prepareForProcessing();
86 status_t processImpl(uint32_t mqFlag);
87 status_t setProcessBuffers();
Mikhail Naganovf558e022016-11-14 17:45:17 -080088};
89
90} // namespace android
91
92#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H