• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 PATH(android/hardware/audio/effect/COMMON_TYPES_FILE_VERSION/IEffect.h)
21 #include <media/audiohal/EffectHalInterface.h>
22 #include <fmq/EventFlag.h>
23 #include <fmq/MessageQueue.h>
24 #include <system/audio_effect.h>
25 
26 #include "EffectConversionHelperHidl.h"
27 
28 using ::android::hardware::EventFlag;
29 using ::android::hardware::MessageQueue;
30 
31 namespace android {
32 namespace effect {
33 
34 using namespace ::android::hardware::audio::effect::COMMON_TYPES_CPP_VERSION;
35 
36 class EffectHalHidl : public EffectHalInterface, public EffectConversionHelperHidl
37 {
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 
62     virtual status_t dump(int fd);
63 
effectId()64     uint64_t effectId() const { return mEffectId; }
65 
66     // Not implemented in HIDL effect HAL
setDevices(const AudioDeviceTypeAddrVector &)67     status_t setDevices(const AudioDeviceTypeAddrVector&) { return INVALID_OPERATION; };
68 
69   private:
70     friend class EffectsFactoryHalHidl;
71     typedef MessageQueue<Result, hardware::kSynchronizedReadWrite> StatusMQ;
72 
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     bool mIsInput = false;
81     static constexpr int32_t kRTPriorityMin = 1;
82     static constexpr int32_t kRTPriorityMax = 3;
83     static constexpr int kRTPriorityDisabled = 0;
84     // Typical RealTime mHalThreadPriority ranges from 1 (low) to 3 (high).
85     int mHalThreadPriority = kRTPriorityDisabled;
86 
87     // Can not be constructed directly by clients.
88     EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId);
89 
90     // The destructor automatically releases the effect.
91     virtual ~EffectHalHidl();
92 
93     status_t getConfigImpl(uint32_t cmdCode, uint32_t *replySize, void *pReplyData);
94     status_t prepareForProcessing();
95     bool needToResetBuffers();
96     status_t processImpl(uint32_t mqFlag);
97     status_t setConfigImpl(
98             uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
99             uint32_t *replySize, void *pReplyData);
100     status_t setProcessBuffers();
101     status_t getHalPid(pid_t *pid) const;
102     status_t getHalWorkerTid(pid_t *tid);
103     bool requestHalThreadPriority(pid_t threadPid, pid_t threadId);
104     status_t checkHalThreadPriority();
105 };
106 
107 } // namespace effect
108 } // namespace android
109 
110 #endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H
111