Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8a0ae543 authored by Shunkai Yao's avatar Shunkai Yao
Browse files

AIDL effect: Minimal example implementation

Add effect factory placeholder implementation.
Update android.hardware.audio.service-aidl.example to include effects.

Bug: 238913361
Test: atest VtsHalAudioEffectTargetTest

Change-Id: I88266b509a03ee336e22be460580c5b22123659e
parent d56bc22d
Loading
Loading
Loading
Loading
+42 −0
Original line number Original line Diff line number Diff line
@@ -51,3 +51,45 @@ cc_binary {
    ],
    ],
    srcs: ["main.cpp"],
    srcs: ["main.cpp"],
}
}

cc_library_static {
    name: "libaudioeffectserviceexampleimpl",
    vendor: true,
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "android.media.audio.common.types-V1-ndk",
        "android.hardware.audio.effect-V1-ndk",
    ],
    export_include_dirs: ["include"],
    srcs: [
        "EffectFactory.cpp",
    ],
    visibility: [
        ":__subpackages__",
    ],
}

cc_binary {
    name: "android.hardware.audio.effect.service-aidl.example",
    relative_install_path: "hw",
    init_rc: ["android.hardware.audio.effect.service-aidl.example.rc"],
    vintf_fragments: ["android.hardware.audio.effect.service-aidl.xml"],
    vendor: true,
    shared_libs: [
        "libbase",
        "libbinder_ndk",
        "android.media.audio.common.types-V1-ndk",
        "android.hardware.audio.effect-V1-ndk",
    ],
    static_libs: [
        "libaudioeffectserviceexampleimpl",
    ],
    cflags: [
        "-Wall",
        "-Wextra",
        "-Werror",
        "-Wthread-safety",
    ],
    srcs: ["EffectMain.cpp"],
}
+59 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#define LOG_TAG "AHAL_EffectFactory"
#include <android-base/logging.h>

#include "effectFactory-impl/EffectFactory.h"
#include "equalizer-impl/Equalizer.h"
#include "visualizer-impl/Visualizer.h"

using aidl::android::media::audio::common::AudioUuid;

namespace aidl::android::hardware::audio::effect {

Factory::Factory() {
    // TODO: implement this with xml parser on audio_effect.xml, and filter with optional
    // parameters.
    Descriptor::Identity id;
    id.type = {static_cast<int32_t>(0x0bed4300),
               0xddd6,
               0x11db,
               0x8f34,
               {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
    id.uuid = EqualizerUUID;
    mIdentityList.push_back(id);
    id.type = {static_cast<int32_t>(0xd3467faa),
               0xacc7,
               0x4d34,
               0xacaf,
               {0x00, 0x02, 0xa5, 0xd5, 0xc5, 0x1b}};
    id.uuid = VisualizerUUID;
    mIdentityList.push_back(id);
}

ndk::ScopedAStatus Factory::queryEffects(const std::optional<AudioUuid>& in_type,
                                         const std::optional<AudioUuid>& in_instance,
                                         std::vector<Descriptor::Identity>* _aidl_return) {
    std::copy_if(mIdentityList.begin(), mIdentityList.end(), std::back_inserter(*_aidl_return),
                 [&](auto& desc) {
                     return (!in_type.has_value() || in_type.value() == desc.type) &&
                            (!in_instance.has_value() || in_instance.value() == desc.uuid);
                 });
    return ndk::ScopedAStatus::ok();
}

}  // namespace aidl::android::hardware::audio::effect
+38 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "effectFactory-impl/EffectFactory.h"

#include <android-base/logging.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>

int main() {
    // This is a debug implementation, always enable debug logging.
    android::base::SetMinimumLogSeverity(::android::base::DEBUG);
    ABinderProcess_setThreadPoolMaxThreadCount(16);

    auto effectFactory =
            ndk::SharedRefBase::make<aidl::android::hardware::audio::effect::Factory>();
    std::string serviceName = std::string() + effectFactory->descriptor + "/default";
    binder_status_t status =
            AServiceManager_addService(effectFactory->asBinder().get(), serviceName.c_str());
    CHECK_EQ(STATUS_OK, status);
    LOG(DEBUG) << __func__ << ": effectFactoryName:" << serviceName;

    ABinderProcess_joinThreadPool();
    return EXIT_FAILURE;  // should not reach
}
+9 −0
Original line number Original line Diff line number Diff line
service vendor.audio-effect-hal-aidl /vendor/bin/hw/android.hardware.audio.effect.service-aidl.example
    class hal
    user audioserver
    # media gid needed for /dev/fm (radio) and for /data/misc/media (tee)
    group audio camera drmrpc inet media mediadrm net_bt net_bt_admin net_bw_acct wakelock context_hub
    capabilities BLOCK_SUSPEND
    ioprio rt 4
    task_profiles ProcessCapacityHigh HighPerformance
    onrestart restart audioserver
+7 −0
Original line number Original line Diff line number Diff line
<manifest version="1.0" type="device">
  <hal format="aidl">
    <name>android.hardware.audio.effect</name>
    <version>1</version>
    <fqname>IFactory/default</fqname>
  </hal>
</manifest>
Loading