Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 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 <cstddef> |
| 20 | #include <map> |
| 21 | #include <memory> |
| 22 | #include <utils/Errors.h> |
| 23 | |
| 24 | #include <aidl/android/hardware/audio/effect/IEffect.h> |
| 25 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 26 | #include <system/audio_effect.h> |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 27 | #include <system/audio_effects/audio_effects_utils.h> |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 28 | |
| 29 | namespace android { |
| 30 | namespace effect { |
| 31 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 32 | class EffectConversionHelperAidl { |
| 33 | protected: |
| 34 | EffectConversionHelperAidl( |
| 35 | std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> effect, |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 36 | int32_t sessionId, int32_t ioId, |
| 37 | const ::aidl::android::hardware::audio::effect::Descriptor& desc); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 38 | |
| 39 | status_t handleCommand(uint32_t cmdCode, uint32_t cmdSize, void* pCmdData, uint32_t* replySize, |
| 40 | void* pReplyData); |
| 41 | |
| 42 | private: |
| 43 | const int32_t mSessionId; |
| 44 | const int32_t mIoId; |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 45 | const ::aidl::android::hardware::audio::effect::Descriptor mDesc; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 46 | ::aidl::android::media::audio::common::AudioUuid mTypeUuid; |
| 47 | const std::shared_ptr<::aidl::android::hardware::audio::effect::IEffect> mEffect; |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 48 | ::aidl::android::hardware::audio::effect::IEffect::OpenEffectReturn mOpenReturn; |
| 49 | ::aidl::android::hardware::audio::effect::Parameter::Common mCommon; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 50 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 51 | const aidl::android::media::audio::common::AudioFormatDescription kDefaultFormatDescription = { |
| 52 | .type = aidl::android::media::audio::common::AudioFormatType::PCM, |
| 53 | .pcm = aidl::android::media::audio::common::PcmType::FLOAT_32_BIT}; |
| 54 | |
| 55 | static constexpr int kDefaultframeCount = 0x100; |
| 56 | |
| 57 | using AudioChannelLayout = aidl::android::media::audio::common::AudioChannelLayout; |
| 58 | const aidl::android::media::audio::common::AudioConfig kDefaultAudioConfig = { |
| 59 | .base = {.sampleRate = 44100, |
| 60 | .channelMask = AudioChannelLayout::make<AudioChannelLayout::layoutMask>( |
| 61 | AudioChannelLayout::LAYOUT_STEREO), |
| 62 | .format = kDefaultFormatDescription}, |
| 63 | .frameCount = kDefaultframeCount}; |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 64 | // command handler map |
| 65 | typedef status_t (EffectConversionHelperAidl::*CommandHandler)(uint32_t /* cmdSize */, |
| 66 | const void* /* pCmdData */, |
| 67 | uint32_t* /* replySize */, |
| 68 | void* /* pReplyData */); |
| 69 | static const std::map<uint32_t /* effect_command_e */, CommandHandler> mCommandHandlerMap; |
| 70 | |
| 71 | // parameter set/get handler map |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 72 | typedef status_t (EffectConversionHelperAidl::*SetParameter)( |
| 73 | android::effect::utils::EffectParamReader& param); |
| 74 | typedef status_t (EffectConversionHelperAidl::*GetParameter)( |
| 75 | android::effect::utils::EffectParamWriter& param); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 76 | static const std::map<::aidl::android::media::audio::common::AudioUuid /* TypeUUID */, |
| 77 | std::pair<SetParameter, GetParameter>> |
| 78 | mParameterHandlerMap; |
| 79 | |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 80 | status_t handleInit(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 81 | void* pReplyData); |
| 82 | status_t handleSetParameter(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 83 | void* pReplyData); |
| 84 | status_t handleGetParameter(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 85 | void* pReplyData); |
| 86 | status_t handleSetConfig(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 87 | void* pReplyData); |
| 88 | status_t handleGetConfig(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 89 | void* pReplyData); |
| 90 | status_t handleEnable(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 91 | void* pReplyData); |
| 92 | status_t handleDisable(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 93 | void* pReplyData); |
| 94 | status_t handleReset(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 95 | void* pReplyData); |
| 96 | status_t handleSetDevice(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 97 | void* pReplyData); |
| 98 | status_t handleSetVolume(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 99 | void* pReplyData); |
| 100 | status_t handleSetOffload(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 101 | void* pReplyData); |
| 102 | status_t handleFirstPriority(uint32_t cmdSize, const void* pCmdData, uint32_t* replySize, |
| 103 | void* pReplyData); |
| 104 | |
Shunkai Yao | 44bdbad | 2023-01-14 05:11:58 +0000 | [diff] [blame] | 105 | // set/get parameter handler |
| 106 | status_t setAecParameter(android::effect::utils::EffectParamReader& param); |
| 107 | status_t getAecParameter(android::effect::utils::EffectParamWriter& param); |
| 108 | status_t setAgcParameter(android::effect::utils::EffectParamReader& param); |
| 109 | status_t getAgcParameter(android::effect::utils::EffectParamWriter& param); |
| 110 | status_t setBassBoostParameter(android::effect::utils::EffectParamReader& param); |
| 111 | status_t getBassBoostParameter(android::effect::utils::EffectParamWriter& param); |
| 112 | status_t setDownmixParameter(android::effect::utils::EffectParamReader& param); |
| 113 | status_t getDownmixParameter(android::effect::utils::EffectParamWriter& param); |
Shunkai Yao | 284bb0d | 2023-01-10 00:42:36 +0000 | [diff] [blame] | 114 | }; |
| 115 | |
| 116 | } // namespace effect |
| 117 | } // namespace android |