Avichal Rakesh | e1857f8 | 2022-06-08 17:47:23 -0700 | [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 | |
| 17 | #include <ExternalCameraProvider.h> |
| 18 | #include <android-base/logging.h> |
| 19 | #include <android/binder_manager.h> |
| 20 | #include <android/binder_process.h> |
| 21 | |
| 22 | using ::android::hardware::camera::provider::implementation::ExternalCameraProvider; |
| 23 | |
| 24 | namespace { |
| 25 | // Default recommended RPC thread count for camera provider implementations |
| 26 | const int HWBINDER_THREAD_COUNT = 6; |
| 27 | } // namespace |
| 28 | |
| 29 | int main() { |
| 30 | ALOGI("CameraProvider: external webcam service is starting."); |
| 31 | |
| 32 | ABinderProcess_setThreadPoolMaxThreadCount(HWBINDER_THREAD_COUNT); |
| 33 | |
| 34 | std::shared_ptr<ExternalCameraProvider> defaultProvider = |
| 35 | ndk::SharedRefBase::make<ExternalCameraProvider>(); |
| 36 | const std::string serviceName = std::string(ExternalCameraProvider::descriptor) + "/external/0"; |
| 37 | |
| 38 | #ifdef LAZY_SERVICE |
| 39 | binder_exception_t ret = AServiceManager_registerLazyService(defaultProvider->asBinder().get(), |
| 40 | serviceName.c_str()); |
| 41 | LOG_ALWAYS_FATAL_IF(ret != EX_NONE, |
| 42 | "Error while registering lazy ext camera provider service: %d", ret); |
| 43 | #else |
| 44 | binder_exception_t ret = |
| 45 | AServiceManager_addService(defaultProvider->asBinder().get(), serviceName.c_str()); |
| 46 | LOG_ALWAYS_FATAL_IF(ret != EX_NONE, "Error while registering ext camera provider service: %d", |
| 47 | ret); |
| 48 | #endif |
| 49 | |
| 50 | ABinderProcess_joinThreadPool(); |
| 51 | return EXIT_FAILURE; // should not reach |
| 52 | } |