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