blob: dda21ed2cfd03c81b9d0ac8eb7c55e4253f90c79 [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
Mikhail Naganov89c22e42023-06-14 15:49:59 -070020#include PATH(android/hardware/audio/effect/COMMON_TYPES_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
Mikhail Naganov288a3432022-03-25 00:29:56 +000026#include "EffectConversionHelperHidl.h"
27
Kevin Rocardd4de2882018-02-28 14:33:38 -080028using ::android::hardware::EventFlag;
29using ::android::hardware::MessageQueue;
30
31namespace android {
Mikhail Naganov595caa32018-12-13 11:08:28 -080032namespace effect {
Kevin Rocardd4de2882018-02-28 14:33:38 -080033
Mikhail Naganov89c22e42023-06-14 15:49:59 -070034using namespace ::android::hardware::audio::effect::COMMON_TYPES_CPP_VERSION;
Mikhail Naganov595caa32018-12-13 11:08:28 -080035
Mikhail Naganov288a3432022-03-25 00:29:56 +000036class EffectHalHidl : public EffectHalInterface, public EffectConversionHelperHidl
Kevin Rocardd4de2882018-02-28 14:33:38 -080037{
38 public:
39 // Set the input buffer.
40 virtual status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer);
41
42 // Set the output buffer.
43 virtual status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer);
44
45 // Effect process function.
46 virtual status_t process();
47
48 // Process reverse stream function. This function is used to pass
49 // a reference stream to the effect engine.
50 virtual status_t processReverse();
51
52 // Send a command and receive a response to/from effect engine.
53 virtual status_t command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
54 uint32_t *replySize, void *pReplyData);
55
56 // Returns the effect descriptor.
57 virtual status_t getDescriptor(effect_descriptor_t *pDescriptor);
58
59 // Free resources on the remote side.
60 virtual status_t close();
61
Mikhail Naganov4d547672019-02-22 14:19:19 -080062 virtual status_t dump(int fd);
63
Mikhail Naganov89c22e42023-06-14 15:49:59 -070064 uint64_t effectId() const { return mEffectId; }
Kevin Rocardd4de2882018-02-28 14:33:38 -080065
Kevin Rocardd4de2882018-02-28 14:33:38 -080066 private:
67 friend class EffectsFactoryHalHidl;
Mikhail Naganov595caa32018-12-13 11:08:28 -080068 typedef MessageQueue<Result, hardware::kSynchronizedReadWrite> StatusMQ;
Kevin Rocardd4de2882018-02-28 14:33:38 -080069
70 sp<IEffect> mEffect;
71 const uint64_t mEffectId;
72 sp<EffectBufferHalInterface> mInBuffer;
73 sp<EffectBufferHalInterface> mOutBuffer;
74 bool mBuffersChanged;
75 std::unique_ptr<StatusMQ> mStatusMQ;
76 EventFlag* mEfGroup;
Mikhail Naganov247b5f92021-01-15 19:16:12 +000077 bool mIsInput = false;
Andy Hung6e3a3502022-10-17 19:10:02 -070078 static constexpr int32_t kRTPriorityMin = 1;
79 static constexpr int32_t kRTPriorityMax = 3;
80 static constexpr int kRTPriorityDisabled = 0;
81 // Typical RealTime mHalThreadPriority ranges from 1 (low) to 3 (high).
82 int mHalThreadPriority = kRTPriorityDisabled;
Kevin Rocardd4de2882018-02-28 14:33:38 -080083
Kevin Rocardd4de2882018-02-28 14:33:38 -080084 // Can not be constructed directly by clients.
85 EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId);
86
87 // The destructor automatically releases the effect.
88 virtual ~EffectHalHidl();
89
90 status_t getConfigImpl(uint32_t cmdCode, uint32_t *replySize, void *pReplyData);
91 status_t prepareForProcessing();
92 bool needToResetBuffers();
93 status_t processImpl(uint32_t mqFlag);
94 status_t setConfigImpl(
95 uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
96 uint32_t *replySize, void *pReplyData);
97 status_t setProcessBuffers();
Andy Hung6e3a3502022-10-17 19:10:02 -070098 status_t getHalPid(pid_t *pid) const;
99 status_t getHalWorkerTid(pid_t *tid);
100 bool requestHalThreadPriority(pid_t threadPid, pid_t threadId);
101 status_t checkHalThreadPriority();
Kevin Rocardd4de2882018-02-28 14:33:38 -0800102};
103
Mikhail Naganov595caa32018-12-13 11:08:28 -0800104} // namespace effect
Kevin Rocardd4de2882018-02-28 14:33:38 -0800105} // namespace android
106
Kevin Rocarddf9b4202018-05-10 19:56:08 -0700107#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H