Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2023 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 | #define LOG_TAG "VirtualCamera" |
| 18 | |
| 19 | #include <android/binder_stability.h> |
| 20 | |
| 21 | #include <cstddef> |
| 22 | |
| 23 | #include "VirtualCameraProvider.h" |
| 24 | #include "VirtualCameraService.h" |
| 25 | #include "android-base/logging.h" |
| 26 | #include "android/binder_manager.h" |
| 27 | #include "android/binder_process.h" |
| 28 | #include "log/log.h" |
| 29 | |
| 30 | using ::android::companion::virtualcamera::VirtualCameraProvider; |
| 31 | using ::android::companion::virtualcamera::VirtualCameraService; |
| 32 | |
| 33 | namespace { |
| 34 | // Default recommended RPC thread count for camera provider implementations |
| 35 | const int HWBINDER_THREAD_COUNT = 6; |
| 36 | |
| 37 | constexpr char kVirtualCameraServiceName[] = "virtual_camera"; |
| 38 | } // namespace |
| 39 | |
| 40 | int main() { |
Vadim Caen | 7e8d047 | 2024-05-24 08:43:48 +0000 | [diff] [blame] | 41 | ALOGI("virtual_camera service is starting."); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 42 | |
| 43 | ABinderProcess_setThreadPoolMaxThreadCount(HWBINDER_THREAD_COUNT); |
| 44 | |
| 45 | std::shared_ptr<VirtualCameraProvider> defaultProvider = |
| 46 | ndk::SharedRefBase::make<VirtualCameraProvider>(); |
| 47 | const std::string serviceName = |
| 48 | std::string(VirtualCameraProvider::descriptor) + "/virtual/0"; |
| 49 | |
| 50 | auto aidlBinder = defaultProvider->asBinder(); |
| 51 | AIBinder_forceDowngradeToLocalStability(aidlBinder.get()); |
Vadim Caen | 347a5ff | 2023-12-06 15:59:15 +0100 | [diff] [blame] | 52 | binder_exception_t ret = AServiceManager_registerLazyService( |
| 53 | aidlBinder.get(), serviceName.c_str()); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 54 | LOG_ALWAYS_FATAL_IF( |
| 55 | ret != EX_NONE, |
| 56 | "Error while registering virtual camera provider service: %d", ret); |
| 57 | |
| 58 | std::shared_ptr<VirtualCameraService> virtualCameraService = |
| 59 | ndk::SharedRefBase::make<VirtualCameraService>(defaultProvider); |
Vadim Caen | 347a5ff | 2023-12-06 15:59:15 +0100 | [diff] [blame] | 60 | ret = AServiceManager_registerLazyService( |
| 61 | virtualCameraService->asBinder().get(), kVirtualCameraServiceName); |
Jan Sebechlebsky | 5cb3996 | 2023-11-22 17:33:07 +0100 | [diff] [blame] | 62 | LOG_ALWAYS_FATAL_IF(ret != EX_NONE, |
| 63 | "Error while registering virtual camera service: %d", ret); |
| 64 | |
| 65 | ABinderProcess_joinThreadPool(); |
| 66 | return EXIT_FAILURE; // should not reach |
| 67 | } |