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" |
| 28 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 29 | using aidl::android::hardware::audio::core::Config; |
| 30 | using aidl::android::hardware::audio::core::Module; |
| 31 | |
| 32 | int main() { |
Mikhail Naganov | 4f5d3f1 | 2022-07-22 23:23:25 +0000 | [diff] [blame] | 33 | // Random values are used in the implementation. |
| 34 | std::srand(std::time(nullptr)); |
| 35 | |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 36 | // This is a debug implementation, always enable debug logging. |
| 37 | android::base::SetMinimumLogSeverity(::android::base::DEBUG); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 38 | ABinderProcess_setThreadPoolMaxThreadCount(16); |
| 39 | |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 40 | // Make the default config service |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 41 | auto config = ndk::SharedRefBase::make<Config>(); |
| 42 | const std::string configName = std::string() + Config::descriptor + "/default"; |
| 43 | binder_status_t status = |
| 44 | AServiceManager_addService(config->asBinder().get(), configName.c_str()); |
Mikhail Naganov | 16db9b7 | 2022-06-17 21:36:18 +0000 | [diff] [blame] | 45 | CHECK_EQ(STATUS_OK, status); |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 46 | |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 47 | // Make modules |
Mikhail Naganov | df5feba | 2022-12-15 00:11:14 +0000 | [diff] [blame] | 48 | auto createModule = [](Module::Type type, const std::string& instance) { |
| 49 | auto module = ndk::SharedRefBase::make<Module>(type); |
| 50 | ndk::SpAIBinder moduleBinder = module->asBinder(); |
| 51 | const std::string moduleName = std::string(Module::descriptor).append("/").append(instance); |
| 52 | AIBinder_setMinSchedulerPolicy(moduleBinder.get(), SCHED_NORMAL, ANDROID_PRIORITY_AUDIO); |
| 53 | binder_status_t status = AServiceManager_addService(moduleBinder.get(), moduleName.c_str()); |
| 54 | CHECK_EQ(STATUS_OK, status); |
| 55 | return std::make_pair(module, moduleBinder); |
| 56 | }; |
| 57 | auto modules = {createModule(Module::Type::DEFAULT, "default"), |
jiabin | b309d8d | 2023-01-20 19:07:15 +0000 | [diff] [blame] | 58 | createModule(Module::Type::R_SUBMIX, "r_submix"), |
| 59 | createModule(Module::Type::USB, "usb")}; |
Mikhail Naganov | c8e4312 | 2022-12-09 00:33:47 +0000 | [diff] [blame] | 60 | |
Mikhail Naganov | df5adfd | 2021-11-11 22:09:22 +0000 | [diff] [blame] | 61 | ABinderProcess_joinThreadPool(); |
| 62 | return EXIT_FAILURE; // should not reach |
| 63 | } |