Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019 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 | #include <android/hardware/automotive/evs/1.0/IEvsEnumerator.h> |
| 17 | #include <hidl/HidlTransportSupport.h> |
| 18 | #include <log/log.h> |
| 19 | |
| 20 | #include "ConfigManager.h" |
| 21 | #include "Utils.h" |
| 22 | |
| 23 | namespace android { |
| 24 | namespace automotive { |
| 25 | namespace evs { |
| 26 | namespace support { |
| 27 | |
| 28 | using namespace ::android::hardware::automotive::evs::V1_0; |
| 29 | using ::android::hardware::hidl_vec; |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 30 | |
Haoxiang Li | 30aa0bc | 2019-08-30 13:24:59 -0700 | [diff] [blame] | 31 | vector<string> Utils::sCameraIds; |
| 32 | |
| 33 | vector<string> Utils::getRearViewCameraIds() { |
| 34 | // If we already get the camera list, re-use it. |
| 35 | if (!sCameraIds.empty()) { |
| 36 | return sCameraIds; |
| 37 | } |
| 38 | |
Changyeon Jo | 3aa79a1 | 2020-02-05 17:09:36 -0800 | [diff] [blame] | 39 | const char* evsServiceName = "default"; |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 40 | |
| 41 | // Load our configuration information |
| 42 | ConfigManager config; |
| 43 | if (!config.initialize("/system/etc/automotive/evs_support_lib/camera_config.json")) { |
| 44 | ALOGE("Missing or improper configuration for the EVS application. Exiting."); |
Haoxiang Li | 30aa0bc | 2019-08-30 13:24:59 -0700 | [diff] [blame] | 45 | return vector<string>(); |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | ALOGI("Acquiring EVS Enumerator"); |
| 49 | sp<IEvsEnumerator> evs = IEvsEnumerator::getService(evsServiceName); |
| 50 | if (evs.get() == nullptr) { |
| 51 | ALOGE("getService(%s) returned NULL. Exiting.", evsServiceName); |
Haoxiang Li | 30aa0bc | 2019-08-30 13:24:59 -0700 | [diff] [blame] | 52 | return vector<string>(); |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Haoxiang Li | 30aa0bc | 2019-08-30 13:24:59 -0700 | [diff] [blame] | 55 | // static variable cannot be passed into capture, so we create a local |
| 56 | // variable instead. |
| 57 | vector<string> cameraIds; |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 58 | ALOGD("Requesting camera list"); |
Haoxiang Li | 30aa0bc | 2019-08-30 13:24:59 -0700 | [diff] [blame] | 59 | evs->getCameraList([&config, &cameraIds](hidl_vec<CameraDesc> cameraList) { |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 60 | ALOGI("Camera list callback received %zu cameras", cameraList.size()); |
| 61 | for (auto&& cam : cameraList) { |
| 62 | ALOGD("Found camera %s", cam.cameraId.c_str()); |
| 63 | |
| 64 | // If there are more than one rear-view cameras, return the first |
| 65 | // one. |
| 66 | for (auto&& info : config.getCameras()) { |
| 67 | if (cam.cameraId == info.cameraId) { |
| 68 | // We found a match! |
| 69 | if (info.function.find("reverse") != std::string::npos) { |
| 70 | ALOGD("Camera %s is matched with reverse state", |
| 71 | cam.cameraId.c_str()); |
Haoxiang Li | 30aa0bc | 2019-08-30 13:24:59 -0700 | [diff] [blame] | 72 | cameraIds.emplace_back(cam.cameraId); |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | }); |
Haoxiang Li | 30aa0bc | 2019-08-30 13:24:59 -0700 | [diff] [blame] | 78 | sCameraIds = cameraIds; |
| 79 | return sCameraIds; |
| 80 | } |
| 81 | |
| 82 | string Utils::getDefaultRearViewCameraId() { |
| 83 | auto list = getRearViewCameraIds(); |
| 84 | if (!list.empty()) { |
| 85 | return list[0]; |
| 86 | } else { |
| 87 | return string(); |
| 88 | } |
Haoxiang Li | d2454a5 | 2019-06-18 13:23:12 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | } // namespace support |
| 92 | } // namespace evs |
| 93 | } // namespace automotive |
| 94 | } // namespace android |