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