blob: 3db9d9c8edd91ca306784d4b76795acd328e81b2 [file] [log] [blame]
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +01001/*
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
30using ::android::companion::virtualcamera::VirtualCameraProvider;
31using ::android::companion::virtualcamera::VirtualCameraService;
32
33namespace {
34// Default recommended RPC thread count for camera provider implementations
35const int HWBINDER_THREAD_COUNT = 6;
36
37constexpr char kVirtualCameraServiceName[] = "virtual_camera";
38} // namespace
39
40int main() {
Vadim Caen7e8d0472024-05-24 08:43:48 +000041 ALOGI("virtual_camera service is starting.");
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010042
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 Caen347a5ff2023-12-06 15:59:15 +010052 binder_exception_t ret = AServiceManager_registerLazyService(
53 aidlBinder.get(), serviceName.c_str());
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010054 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 Caen347a5ff2023-12-06 15:59:15 +010060 ret = AServiceManager_registerLazyService(
61 virtualCameraService->asBinder().get(), kVirtualCameraServiceName);
Jan Sebechlebsky5cb39962023-11-22 17:33:07 +010062 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}