EffectHalHidl.h revision 40be8a343e8ceb7ae087bfb8988247731fa5ae75
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 <android/hardware/audio/effect/2.0/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
26using ::android::hardware::audio::effect::V2_0::EffectBufferConfig;
27using ::android::hardware::audio::effect::V2_0::EffectConfig;
28using ::android::hardware::audio::effect::V2_0::EffectDescriptor;
29using ::android::hardware::audio::effect::V2_0::IEffect;
30using ::android::hardware::EventFlag;
31using ::android::hardware::MessageQueue;
32
33namespace android {
34
35class EffectHalHidl : public EffectHalInterface
36{
37  public:
38    // Set the input buffer.
39    virtual status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer);
40
41    // Set the output buffer.
42    virtual status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer);
43
44    // Effect process function.
45    virtual status_t process();
46
47    // Process reverse stream function. This function is used to pass
48    // a reference stream to the effect engine.
49    virtual status_t processReverse();
50
51    // Send a command and receive a response to/from effect engine.
52    virtual status_t command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
53            uint32_t *replySize, void *pReplyData);
54
55    // Returns the effect descriptor.
56    virtual status_t getDescriptor(effect_descriptor_t *pDescriptor);
57
58    // Free resources on the remote side.
59    virtual status_t close();
60
61    uint64_t effectId() const { return mEffectId; }
62
63    static void effectDescriptorToHal(
64            const EffectDescriptor& descriptor, effect_descriptor_t* halDescriptor);
65
66  private:
67    friend class EffectsFactoryHalHidl;
68    typedef MessageQueue<
69        hardware::audio::effect::V2_0::Result, hardware::kSynchronizedReadWrite> StatusMQ;
70
71    sp<IEffect> mEffect;
72    const uint64_t mEffectId;
73    sp<EffectBufferHalInterface> mInBuffer;
74    sp<EffectBufferHalInterface> mOutBuffer;
75    bool mBuffersChanged;
76    std::unique_ptr<StatusMQ> mStatusMQ;
77    EventFlag* mEfGroup;
78
79    static status_t analyzeResult(const hardware::audio::effect::V2_0::Result& result);
80    static void effectBufferConfigFromHal(
81            const buffer_config_t& halConfig, EffectBufferConfig* config);
82    static void effectBufferConfigToHal(
83            const EffectBufferConfig& config, buffer_config_t* halConfig);
84    static void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config);
85    static void effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig);
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};
102
103} // namespace android
104
105#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H
106