• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2023 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 #pragma once
18 
19 #include <memory>
20 
21 #include <aidl/android/hardware/audio/effect/IEffect.h>
22 #include <aidl/android/hardware/audio/effect/IFactory.h>
23 #include <fmq/AidlMessageQueue.h>
24 #include <media/audiohal/EffectHalInterface.h>
25 #include <system/audio_effect.h>
26 #include <system/audio_effects/aidl_effects_utils.h>
27 
28 #include "EffectConversionHelperAidl.h"
29 
30 namespace android {
31 namespace effect {
32 
33 class EffectHalAidl : public EffectHalInterface {
34   public:
35 
36     // Set the input buffer.
37     status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer) override;
38 
39     // Set the output buffer.
40     status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer) override;
41 
42     // Effect process function.
43     status_t process() override;
44 
45     // Process reverse stream function. This function is used to pass
46     // a reference stream to the effect engine.
47     status_t processReverse() override;
48 
49     // Send a command and receive a response to/from effect engine.
50     status_t command(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize,
51                      void* pReplyData) override;
52 
53     // Returns the effect descriptor.
54     status_t getDescriptor(effect_descriptor_t *pDescriptor) override;
55 
56     // Free resources on the remote side.
57     status_t close() override;
58 
59     status_t dump(int fd) override;
60 
getIEffect()61     const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> getIEffect() const {
62         return mEffect;
63     }
64 
65     // for TIME_CHECK
getClassName()66     const std::string getClassName() const { return "EffectHalAidl"; }
67 
68   private:
69     friend class sp<EffectHalAidl>;
70 
71     const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory> mFactory;
72     const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect;
73     const int32_t mSessionId;
74     const int32_t mIoId;
75     const bool mIsProxyEffect;
76     bool mIsHapticGenerator = false;
77 
78     std::unique_ptr<EffectConversionHelperAidl> mConversion;
79 
80     sp<EffectBufferHalInterface> mInBuffer, mOutBuffer;
81 
82     status_t createAidlConversion(
83             std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect,
84             int32_t sessionId, int32_t ioId,
85             const ::aidl::android::hardware::audio::effect::Descriptor& desc);
86     // Can not be constructed directly by clients.
87     EffectHalAidl(
88             const std::shared_ptr<::aidl::android::hardware::audio::effect::IFactory>& factory,
89             const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect>& effect,
90             int32_t sessionId, int32_t ioId,
91             const ::aidl::android::hardware::audio::effect::Descriptor& desc,
92             bool isProxyEffect);
93     bool setEffectReverse(bool reverse);
94     bool needUpdateReturnParam(uint32_t cmdCode);
95 
96     // The destructor automatically releases the effect.
97     virtual ~EffectHalAidl();
98 };
99 
100 } // namespace effect
101 } // namespace android
102