Shunkai Yao | dca65ce | 2022-12-02 05:35:41 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2022 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 | #include <random> |
| 18 | #define LOG_TAG "EffectsFactoryHalAidl" |
| 19 | //#define LOG_NDEBUG 0 |
| 20 | |
| 21 | #include <aidl/android/hardware/audio/effect/IFactory.h> |
| 22 | #include <android/binder_manager.h> |
| 23 | #include <utils/Log.h> |
| 24 | |
| 25 | #include "EffectsFactoryHalAidl.h" |
| 26 | |
| 27 | using aidl::android::hardware::audio::effect::IFactory; |
| 28 | using android::detail::AudioHalVersionInfo; |
| 29 | |
| 30 | namespace android { |
| 31 | namespace effect { |
| 32 | |
| 33 | EffectsFactoryHalAidl::EffectsFactoryHalAidl(std::shared_ptr<IFactory> effectsFactory) { |
| 34 | ALOG_ASSERT(effectsFactory != nullptr, "Provided IEffectsFactory service is NULL"); |
| 35 | mEffectsFactory = effectsFactory; |
| 36 | } |
| 37 | |
| 38 | status_t EffectsFactoryHalAidl::queryNumberEffects(uint32_t *pNumEffects) { |
| 39 | if (pNumEffects == nullptr) { |
| 40 | return BAD_VALUE; |
| 41 | } |
| 42 | ALOGE("%s not implemented yet", __func__); |
| 43 | return INVALID_OPERATION; |
| 44 | } |
| 45 | |
| 46 | status_t EffectsFactoryHalAidl::getDescriptor(uint32_t index, effect_descriptor_t* pDescriptor) { |
| 47 | if (index < 0 || pDescriptor == nullptr) { |
| 48 | return BAD_VALUE; |
| 49 | } |
| 50 | ALOGE("%s not implemented yet", __func__); |
| 51 | return INVALID_OPERATION; |
| 52 | } |
| 53 | |
| 54 | status_t EffectsFactoryHalAidl::getDescriptor(const effect_uuid_t* pEffectUuid, |
| 55 | effect_descriptor_t* pDescriptor) { |
| 56 | if (pEffectUuid == nullptr || pDescriptor == nullptr) { |
| 57 | return BAD_VALUE; |
| 58 | } |
| 59 | ALOGE("%s not implemented yet", __func__); |
| 60 | return INVALID_OPERATION; |
| 61 | } |
| 62 | |
| 63 | status_t EffectsFactoryHalAidl::getDescriptors(const effect_uuid_t* pEffectType, |
| 64 | std::vector<effect_descriptor_t>* descriptors) { |
| 65 | if (pEffectType == nullptr || descriptors == nullptr) { |
| 66 | return BAD_VALUE; |
| 67 | } |
| 68 | ALOGE("%s not implemented yet", __func__); |
| 69 | return INVALID_OPERATION; |
| 70 | } |
| 71 | |
| 72 | status_t EffectsFactoryHalAidl::createEffect(const effect_uuid_t* pEffectUuid, int32_t sessionId, |
| 73 | int32_t ioId, int32_t deviceId __unused, |
| 74 | sp<EffectHalInterface>* effect) { |
| 75 | if (pEffectUuid == nullptr || effect == nullptr) { |
| 76 | return BAD_VALUE; |
| 77 | } |
| 78 | ALOGE("%s not implemented yet %d %d", __func__, sessionId, ioId); |
| 79 | return INVALID_OPERATION; |
| 80 | } |
| 81 | |
| 82 | status_t EffectsFactoryHalAidl::dumpEffects(int fd) { |
| 83 | ALOGE("%s not implemented yet, fd %d", __func__, fd); |
| 84 | return INVALID_OPERATION; |
| 85 | } |
| 86 | |
| 87 | status_t EffectsFactoryHalAidl::allocateBuffer(size_t size, sp<EffectBufferHalInterface>* buffer) { |
| 88 | if (size <= 0 || buffer == nullptr) { |
| 89 | return BAD_VALUE; |
| 90 | } |
| 91 | ALOGE("%s not implemented yet", __func__); |
| 92 | return INVALID_OPERATION; |
| 93 | } |
| 94 | |
| 95 | status_t EffectsFactoryHalAidl::mirrorBuffer(void* external, size_t size, |
| 96 | sp<EffectBufferHalInterface>* buffer) { |
| 97 | if (external == nullptr || size <= 0 || buffer == nullptr) { |
| 98 | return BAD_VALUE; |
| 99 | } |
| 100 | ALOGE("%s not implemented yet", __func__); |
| 101 | return INVALID_OPERATION; |
| 102 | } |
| 103 | |
| 104 | AudioHalVersionInfo EffectsFactoryHalAidl::getHalVersion() const { |
| 105 | int32_t versionNumber = 0; |
| 106 | if (mEffectsFactory) { |
| 107 | if (!mEffectsFactory->getInterfaceVersion(&versionNumber).isOk()) { |
| 108 | ALOGE("%s getInterfaceVersion failed", __func__); |
| 109 | } else { |
| 110 | ALOGI("%s getInterfaceVersion %d", __func__, versionNumber); |
| 111 | } |
| 112 | } |
| 113 | // AIDL does not have minor version, fill 0 for all versions |
| 114 | return AudioHalVersionInfo(AudioHalVersionInfo::Type::AIDL, versionNumber); |
| 115 | } |
| 116 | |
| 117 | } // namespace effect |
| 118 | |
| 119 | // When a shared library is built from a static library, even explicit |
| 120 | // exports from a static library are optimized out unless actually used by |
| 121 | // the shared library. See EffectsFactoryHalEntry.cpp. |
| 122 | extern "C" void* createIEffectsFactoryImpl() { |
| 123 | auto factory = IFactory::fromBinder( |
| 124 | ndk::SpAIBinder(AServiceManager_waitForService(IFactory::descriptor))); |
| 125 | return factory ? new effect::EffectsFactoryHalAidl(factory) : nullptr; |
| 126 | } |
| 127 | |
| 128 | } // namespace android |