blob: a861f9db3916c17e40736cc5b30a4f86d6d19b39 [file] [log] [blame]
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +00001/*
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
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000017#include <cstdlib>
18#include <ctime>
Mikhail Naganovdf5feba2022-12-15 00:11:14 +000019#include <utility>
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000020
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000021#include <android-base/logging.h>
Shunkai Yao39bf2c32022-12-06 03:25:59 +000022#include <android/binder_ibinder_platform.h>
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000023#include <android/binder_manager.h>
24#include <android/binder_process.h>
25
Lorena Torres-Huertabc585bd2022-10-23 20:41:35 +000026#include "core-impl/Config.h"
27#include "core-impl/Module.h"
jiabin253bd322023-01-25 23:57:31 +000028#include "core-impl/ModuleUsb.h"
Lorena Torres-Huertabc585bd2022-10-23 20:41:35 +000029
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000030using aidl::android::hardware::audio::core::Config;
31using aidl::android::hardware::audio::core::Module;
jiabin253bd322023-01-25 23:57:31 +000032using aidl::android::hardware::audio::core::ModuleUsb;
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000033
34int main() {
Mikhail Naganov4f5d3f12022-07-22 23:23:25 +000035 // Random values are used in the implementation.
36 std::srand(std::time(nullptr));
37
Mikhail Naganov16db9b72022-06-17 21:36:18 +000038 // This is a debug implementation, always enable debug logging.
39 android::base::SetMinimumLogSeverity(::android::base::DEBUG);
Mikhail Naganov1f72fd42023-02-02 15:26:04 -080040 // For more logs, use VERBOSE, however this may hinder performance.
41 // android::base::SetMinimumLogSeverity(::android::base::VERBOSE);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000042 ABinderProcess_setThreadPoolMaxThreadCount(16);
43
Mikhail Naganov16db9b72022-06-17 21:36:18 +000044 // Make the default config service
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000045 auto config = ndk::SharedRefBase::make<Config>();
46 const std::string configName = std::string() + Config::descriptor + "/default";
47 binder_status_t status =
48 AServiceManager_addService(config->asBinder().get(), configName.c_str());
Mikhail Naganov16db9b72022-06-17 21:36:18 +000049 CHECK_EQ(STATUS_OK, status);
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000050
Mikhail Naganovc8e43122022-12-09 00:33:47 +000051 // Make modules
Mikhail Naganovdf5feba2022-12-15 00:11:14 +000052 auto createModule = [](Module::Type type, const std::string& instance) {
jiabin253bd322023-01-25 23:57:31 +000053 auto module = Module::createInstance(type);
Mikhail Naganovdf5feba2022-12-15 00:11:14 +000054 ndk::SpAIBinder moduleBinder = module->asBinder();
55 const std::string moduleName = std::string(Module::descriptor).append("/").append(instance);
56 AIBinder_setMinSchedulerPolicy(moduleBinder.get(), SCHED_NORMAL, ANDROID_PRIORITY_AUDIO);
57 binder_status_t status = AServiceManager_addService(moduleBinder.get(), moduleName.c_str());
58 CHECK_EQ(STATUS_OK, status);
59 return std::make_pair(module, moduleBinder);
60 };
61 auto modules = {createModule(Module::Type::DEFAULT, "default"),
jiabinb309d8d2023-01-20 19:07:15 +000062 createModule(Module::Type::R_SUBMIX, "r_submix"),
63 createModule(Module::Type::USB, "usb")};
Mikhail Naganovc8e43122022-12-09 00:33:47 +000064
Mikhail Naganovdf5adfd2021-11-11 22:09:22 +000065 ABinderProcess_joinThreadPool();
66 return EXIT_FAILURE; // should not reach
67}