blob: 6fd405e779a37961317f9aa154c4e34b5774a9cb [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
Mikhail Naganovf508bd42017-02-16 13:51:20 -080026using ::android::hardware::audio::effect::V2_0::EffectBufferConfig;
27using ::android::hardware::audio::effect::V2_0::EffectConfig;
Mikhail Naganovf558e022016-11-14 17:45:17 -080028using ::android::hardware::audio::effect::V2_0::EffectDescriptor;
29using ::android::hardware::audio::effect::V2_0::IEffect;
Kevin Rocarddf9b4202018-05-10 19:56:08 -070030using EffectResult = ::android::hardware::audio::effect::V2_0::Result;
Mikhail Naganov022b9952017-01-04 16:36:51 -080031using ::android::hardware::EventFlag;
32using ::android::hardware::MessageQueue;
Mikhail Naganovf558e022016-11-14 17:45:17 -080033
34namespace android {
Kevin Rocarddf9b4202018-05-10 19:56:08 -070035namespace V2_0 {
Mikhail Naganovf558e022016-11-14 17:45:17 -080036
37class EffectHalHidl : public EffectHalInterface
38{
39 public:
Mikhail Naganov022b9952017-01-04 16:36:51 -080040 // Set the input buffer.
41 virtual status_t setInBuffer(const sp<EffectBufferHalInterface>& buffer);
42
43 // Set the output buffer.
44 virtual status_t setOutBuffer(const sp<EffectBufferHalInterface>& buffer);
45
46 // Effect process function.
47 virtual status_t process();
Mikhail Naganovf558e022016-11-14 17:45:17 -080048
49 // Process reverse stream function. This function is used to pass
50 // a reference stream to the effect engine.
Mikhail Naganov022b9952017-01-04 16:36:51 -080051 virtual status_t processReverse();
Mikhail Naganovf558e022016-11-14 17:45:17 -080052
53 // Send a command and receive a response to/from effect engine.
54 virtual status_t command(uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
55 uint32_t *replySize, void *pReplyData);
56
57 // Returns the effect descriptor.
58 virtual status_t getDescriptor(effect_descriptor_t *pDescriptor);
59
Mikhail Naganov022b9952017-01-04 16:36:51 -080060 // Free resources on the remote side.
61 virtual status_t close();
62
Mikhail Naganov6b111f32017-04-27 18:52:37 -070063 // Whether it's a local implementation.
64 virtual bool isLocal() const { return false; }
65
Mikhail Naganovf558e022016-11-14 17:45:17 -080066 uint64_t effectId() const { return mEffectId; }
67
68 static void effectDescriptorToHal(
69 const EffectDescriptor& descriptor, effect_descriptor_t* halDescriptor);
70
71 private:
72 friend class EffectsFactoryHalHidl;
Kevin Rocarddf9b4202018-05-10 19:56:08 -070073 typedef MessageQueue<EffectResult, hardware::kSynchronizedReadWrite> StatusMQ;
Mikhail Naganov022b9952017-01-04 16:36:51 -080074
Mikhail Naganovf558e022016-11-14 17:45:17 -080075 sp<IEffect> mEffect;
76 const uint64_t mEffectId;
Mikhail Naganov022b9952017-01-04 16:36:51 -080077 sp<EffectBufferHalInterface> mInBuffer;
78 sp<EffectBufferHalInterface> mOutBuffer;
79 bool mBuffersChanged;
80 std::unique_ptr<StatusMQ> mStatusMQ;
81 EventFlag* mEfGroup;
Mikhail Naganovf558e022016-11-14 17:45:17 -080082
Kevin Rocarddf9b4202018-05-10 19:56:08 -070083 static status_t analyzeResult(const EffectResult& result);
Mikhail Naganovf508bd42017-02-16 13:51:20 -080084 static void effectBufferConfigFromHal(
85 const buffer_config_t& halConfig, EffectBufferConfig* config);
Mikhail Naganoved01be52017-02-16 15:57:07 -080086 static void effectBufferConfigToHal(
87 const EffectBufferConfig& config, buffer_config_t* halConfig);
Mikhail Naganovf508bd42017-02-16 13:51:20 -080088 static void effectConfigFromHal(const effect_config_t& halConfig, EffectConfig* config);
Mikhail Naganoved01be52017-02-16 15:57:07 -080089 static void effectConfigToHal(const EffectConfig& config, effect_config_t* halConfig);
Mikhail Naganovf558e022016-11-14 17:45:17 -080090
91 // Can not be constructed directly by clients.
92 EffectHalHidl(const sp<IEffect>& effect, uint64_t effectId);
93
94 // The destructor automatically releases the effect.
95 virtual ~EffectHalHidl();
Mikhail Naganov022b9952017-01-04 16:36:51 -080096
Mikhail Naganoved01be52017-02-16 15:57:07 -080097 status_t getConfigImpl(uint32_t cmdCode, uint32_t *replySize, void *pReplyData);
Mikhail Naganov022b9952017-01-04 16:36:51 -080098 status_t prepareForProcessing();
Mikhail Naganov40be8a32017-04-26 17:22:00 -070099 bool needToResetBuffers();
Mikhail Naganov022b9952017-01-04 16:36:51 -0800100 status_t processImpl(uint32_t mqFlag);
Mikhail Naganovf508bd42017-02-16 13:51:20 -0800101 status_t setConfigImpl(
102 uint32_t cmdCode, uint32_t cmdSize, void *pCmdData,
103 uint32_t *replySize, void *pReplyData);
Mikhail Naganov022b9952017-01-04 16:36:51 -0800104 status_t setProcessBuffers();
Mikhail Naganovf558e022016-11-14 17:45:17 -0800105};
106
Kevin Rocarddf9b4202018-05-10 19:56:08 -0700107} // namespace V2_0
Mikhail Naganovf558e022016-11-14 17:45:17 -0800108} // namespace android
109
110#endif // ANDROID_HARDWARE_EFFECT_HAL_HIDL_H