Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +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 | |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 17 | #include <cstdlib> |
| 18 | #include <ctime> |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 19 | #include <utility> |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 20 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 21 | #include <android-base/logging.h> |
Shunkai Yao | 39bf2c3 | 2022-12-06 03:25:59 +0000 | [diff] [blame] | 22 | #include <android/binder_ibinder_platform.h> |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 23 | #include <android/binder_manager.h> |
| 24 | #include <android/binder_process.h> |
| 25 | |
Lorena Torres-Huerta | bc585bd | 2022-10-23 20:41:35 +0000 | [diff] [blame] | 26 | #include "core-impl/Config.h" |
| 27 | #include "core-impl/Module.h" |
jiabin | 253bd32 | 2023-01-25 23:57:31 +0000 | [diff] [blame] | 28 | #include "core-impl/ModuleUsb.h" |
Lorena Torres-Huerta | bc585bd | 2022-10-23 20:41:35 +0000 | [diff] [blame] | 29 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 30 | using aidl::android::hardware::audio::core::Config; |
| 31 | using aidl::android::hardware::audio::core::Module; |
jiabin | 253bd32 | 2023-01-25 23:57:31 +0000 | [diff] [blame] | 32 | using aidl::android::hardware::audio::core::ModuleUsb; |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 33 | |
| 34 | int main() { |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 35 | // Random values are used in the implementation. |
| 36 | std::srand(std::time(nullptr)); |
| 37 | |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 38 | // This is a debug implementation, always enable debug logging. |
| 39 | android::base::SetMinimumLogSeverity(::android::base::DEBUG); |
Mikhail Naganov | 1f72fd4 | 2023-02-02 15:26:04 -0800 | [diff] [blame] | 40 | // For more logs, use VERBOSE, however this may hinder performance. |
| 41 | // android::base::SetMinimumLogSeverity(::android::base::VERBOSE); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 42 | ABinderProcess_setThreadPoolMaxThreadCount(16); |
| 43 | |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 44 | // Make the default config service |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 45 | 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 Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 49 | CHECK_EQ(STATUS_OK, status); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 50 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 51 | // Make modules |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 52 | auto createModule = [](Module::Type type, const std::string& instance) { |
jiabin | 253bd32 | 2023-01-25 23:57:31 +0000 | [diff] [blame] | 53 | auto module = Module::createInstance(type); |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 54 | 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"), |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 62 | createModule(Module::Type::R_SUBMIX, "r_submix"), |
| 63 | createModule(Module::Type::USB, "usb")}; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 64 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 65 | ABinderProcess_joinThreadPool(); |
| 66 | return EXIT_FAILURE; // should not reach |
| 67 | } |