Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 17 | #include <android-base/properties.h> |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 18 | |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 19 | #include <hidl/AidlCameraDeviceCallbacks.h> |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 20 | #include <hidl/AidlCameraServiceListener.h> |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 21 | #include <hidl/HidlCameraService.h> |
| 22 | #include <hidl/HidlCameraDeviceUser.h> |
| 23 | #include <hidl/Utils.h> |
Avichal Rakesh | fcb78cb | 2022-10-27 15:45:54 -0700 | [diff] [blame] | 24 | #include <aidl/AidlUtils.h> |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 25 | |
| 26 | #include <hidl/HidlTransportSupport.h> |
| 27 | |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 28 | #include <camera/CameraUtils.h> |
Avichal Rakesh | 74b5ae7 | 2023-12-27 16:56:45 -0800 | [diff] [blame] | 29 | #include <utils/Utils.h> |
| 30 | |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 31 | namespace android { |
| 32 | namespace frameworks { |
| 33 | namespace cameraservice { |
| 34 | namespace service { |
| 35 | namespace V2_0 { |
| 36 | namespace implementation { |
| 37 | |
| 38 | using frameworks::cameraservice::service::V2_0::implementation::HidlCameraService; |
| 39 | using hardware::hidl_vec; |
Jayant Chowdhary | 81d81b0 | 2024-02-15 19:13:39 +0000 | [diff] [blame^] | 40 | using hardware::BnCameraService::ROTATION_OVERRIDE_NONE; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 41 | using hardware::cameraservice::utils::conversion::convertToHidl; |
| 42 | using hardware::cameraservice::utils::conversion::B2HStatus; |
| 43 | using hardware::Void; |
Avichal Rakesh | fcb78cb | 2022-10-27 15:45:54 -0700 | [diff] [blame] | 44 | using hardware::cameraservice::utils::conversion::aidl::filterVndkKeys; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 45 | |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 46 | using device::V2_0::implementation::H2BCameraDeviceCallbacks; |
Shuzhen Wang | 316781a | 2020-08-18 18:11:01 -0700 | [diff] [blame] | 47 | using device::V2_1::implementation::HidlCameraDeviceUser; |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 48 | using service::V2_0::implementation::H2BCameraServiceListener; |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 49 | using HCameraMetadataType = frameworks::cameraservice::common::V2_0::CameraMetadataType; |
| 50 | using HVendorTag = frameworks::cameraservice::common::V2_0::VendorTag; |
| 51 | using HVendorTagSection = frameworks::cameraservice::common::V2_0::VendorTagSection; |
| 52 | using HProviderIdAndVendorTagSections = |
| 53 | frameworks::cameraservice::common::V2_0::ProviderIdAndVendorTagSections; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 54 | |
| 55 | sp<HidlCameraService> gHidlCameraService; |
| 56 | |
| 57 | sp<HidlCameraService> HidlCameraService::getInstance(android::CameraService *cs) { |
| 58 | gHidlCameraService = new HidlCameraService(cs); |
| 59 | return gHidlCameraService; |
| 60 | } |
| 61 | |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 62 | HidlCameraService::HidlCameraService(android::CameraService *cs) : mAidlICameraService(cs) { |
Avichal Rakesh | 74b5ae7 | 2023-12-27 16:56:45 -0800 | [diff] [blame] | 63 | mVndkVersion = getVNDKVersionFromProp(__ANDROID_API_FUTURE__); |
| 64 | } |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 65 | |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 66 | Return<void> |
| 67 | HidlCameraService::getCameraCharacteristics(const hidl_string& cameraId, |
| 68 | getCameraCharacteristics_cb _hidl_cb) { |
| 69 | android::CameraMetadata cameraMetadata; |
| 70 | HStatus status = HStatus::NO_ERROR; |
| 71 | binder::Status serviceRet = |
Austin Borger | 71d8f67 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 72 | mAidlICameraService->getCameraCharacteristics(cameraId, |
Jayant Chowdhary | 81d81b0 | 2024-02-15 19:13:39 +0000 | [diff] [blame^] | 73 | /*targetSdkVersion*/__ANDROID_API_FUTURE__, ROTATION_OVERRIDE_NONE, |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 74 | kDefaultDeviceId, 0, &cameraMetadata); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 75 | HCameraMetadata hidlMetadata; |
| 76 | if (!serviceRet.isOk()) { |
| 77 | switch(serviceRet.serviceSpecificErrorCode()) { |
| 78 | // No ERROR_CAMERA_DISCONNECTED since we're in the same process. |
| 79 | case hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT: |
| 80 | ALOGE("%s: Camera ID %s does not exist!", __FUNCTION__, cameraId.c_str()); |
| 81 | status = HStatus::ILLEGAL_ARGUMENT; |
| 82 | break; |
| 83 | default: |
| 84 | ALOGE("Get camera characteristics from camera service failed: %s", |
Tomasz Wasilczyk | 12b04a5 | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 85 | serviceRet.toString8().c_str()); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 86 | status = B2HStatus(serviceRet); |
| 87 | } |
| 88 | _hidl_cb(status, hidlMetadata); |
| 89 | return Void(); |
| 90 | } |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 91 | if (filterVndkKeys(mVndkVersion, cameraMetadata) != OK) { |
| 92 | ALOGE("%s: Unable to filter vndk metadata keys for version %d", __FUNCTION__, mVndkVersion); |
| 93 | _hidl_cb(HStatus::UNKNOWN_ERROR, hidlMetadata); |
| 94 | return Void(); |
| 95 | } |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 96 | const camera_metadata_t *rawMetadata = cameraMetadata.getAndLock(); |
| 97 | convertToHidl(rawMetadata, &hidlMetadata); |
| 98 | _hidl_cb(status, hidlMetadata); |
| 99 | cameraMetadata.unlock(rawMetadata); |
| 100 | return Void(); |
| 101 | } |
| 102 | |
| 103 | Return<void> HidlCameraService::connectDevice(const sp<HCameraDeviceCallback>& hCallback, |
| 104 | const hidl_string& cameraId, |
| 105 | connectDevice_cb _hidl_cb) { |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 106 | // Here, we first get ICameraDeviceUser from mAidlICameraService, then save |
| 107 | // that interface in the newly created HidlCameraDeviceUser impl class. |
| 108 | if (mAidlICameraService == nullptr) { |
| 109 | _hidl_cb(HStatus::UNKNOWN_ERROR, nullptr); |
| 110 | return Void(); |
| 111 | } |
| 112 | sp<hardware::camera2::ICameraDeviceUser> deviceRemote = nullptr; |
| 113 | // Create a hardware::camera2::ICameraDeviceCallback object which internally |
| 114 | // calls callback functions passed through hCallback. |
| 115 | sp<H2BCameraDeviceCallbacks> hybridCallbacks = new H2BCameraDeviceCallbacks(hCallback); |
Jayant Chowdhary | 2f68652 | 2022-05-09 14:52:16 +0000 | [diff] [blame] | 116 | if (!hybridCallbacks->initializeLooper(mVndkVersion)) { |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 117 | ALOGE("Unable to handle callbacks on device, cannot connect"); |
| 118 | _hidl_cb(HStatus::UNKNOWN_ERROR, nullptr); |
| 119 | return Void(); |
| 120 | } |
| 121 | sp<hardware::camera2::ICameraDeviceCallbacks> callbacks = hybridCallbacks; |
| 122 | binder::Status serviceRet = mAidlICameraService->connectDevice( |
Austin Borger | 71d8f67 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 123 | callbacks, cameraId, std::string(), {}, |
Shuzhen Wang | d4abdf7 | 2021-05-28 11:22:50 -0700 | [diff] [blame] | 124 | hardware::ICameraService::USE_CALLING_UID, 0/*oomScoreOffset*/, |
Jayant Chowdhary | 81d81b0 | 2024-02-15 19:13:39 +0000 | [diff] [blame^] | 125 | /*targetSdkVersion*/__ANDROID_API_FUTURE__, ROTATION_OVERRIDE_NONE, |
Biswarup Pal | 37a7518 | 2024-01-16 15:53:35 +0000 | [diff] [blame] | 126 | kDefaultDeviceId, /*devicePolicy*/0, /*out*/&deviceRemote); |
Jayant Chowdhary | 0c94727 | 2018-08-15 14:42:04 -0700 | [diff] [blame] | 127 | HStatus status = HStatus::NO_ERROR; |
| 128 | if (!serviceRet.isOk()) { |
| 129 | ALOGE("%s: Unable to connect to camera device", __FUNCTION__); |
| 130 | status = B2HStatus(serviceRet); |
| 131 | _hidl_cb(status, nullptr); |
| 132 | return Void(); |
| 133 | } |
| 134 | // Now we create a HidlCameraDeviceUser class, store the deviceRemote in it, |
| 135 | // and return that back. All calls on that interface will be forwarded to |
| 136 | // the AIDL interface. |
| 137 | sp<HidlCameraDeviceUser> hDeviceRemote = new HidlCameraDeviceUser(deviceRemote); |
| 138 | if (!hDeviceRemote->initStatus()) { |
| 139 | ALOGE("%s: Unable to initialize camera device HIDL wrapper", __FUNCTION__); |
| 140 | _hidl_cb(HStatus::UNKNOWN_ERROR, nullptr); |
| 141 | return Void(); |
| 142 | } |
| 143 | hybridCallbacks->setCaptureResultMetadataQueue(hDeviceRemote->getCaptureResultMetadataQueue()); |
| 144 | _hidl_cb(status, hDeviceRemote); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 145 | return Void(); |
| 146 | } |
| 147 | |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 148 | void HidlCameraService::addToListenerCacheLocked(sp<HCameraServiceListener> hListener, |
| 149 | sp<hardware::ICameraServiceListener> csListener) { |
| 150 | mListeners.emplace_back(std::make_pair(hListener, csListener)); |
| 151 | } |
| 152 | |
| 153 | sp<hardware::ICameraServiceListener> |
| 154 | HidlCameraService::searchListenerCacheLocked(sp<HCameraServiceListener> hListener, |
| 155 | bool shouldRemove) { |
| 156 | // Go through the mListeners list and compare the listener with the HIDL |
| 157 | // listener registered. |
| 158 | auto it = mListeners.begin(); |
| 159 | sp<ICameraServiceListener> csListener = nullptr; |
| 160 | for (;it != mListeners.end(); it++) { |
| 161 | if (hardware::interfacesEqual(it->first, hListener)) { |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | if (it != mListeners.end()) { |
| 166 | csListener = it->second; |
| 167 | if (shouldRemove) { |
| 168 | mListeners.erase(it); |
| 169 | } |
| 170 | } |
| 171 | return csListener; |
| 172 | } |
| 173 | |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 174 | Return<void> HidlCameraService::addListener(const sp<HCameraServiceListener>& hCsListener, |
| 175 | addListener_cb _hidl_cb) { |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 176 | std::vector<hardware::CameraStatus> cameraStatusAndIds{}; |
| 177 | HStatus status = addListenerInternal<HCameraServiceListener>( |
| 178 | hCsListener, &cameraStatusAndIds); |
| 179 | if (status != HStatus::NO_ERROR) { |
| 180 | _hidl_cb(status, {}); |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 181 | return Void(); |
| 182 | } |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 183 | |
| 184 | hidl_vec<HCameraStatusAndId> hCameraStatusAndIds; |
| 185 | //Convert cameraStatusAndIds to HIDL and call callback |
| 186 | convertToHidl(cameraStatusAndIds, &hCameraStatusAndIds); |
| 187 | _hidl_cb(status, hCameraStatusAndIds); |
| 188 | |
| 189 | return Void(); |
| 190 | } |
| 191 | |
| 192 | Return<void> HidlCameraService::addListener_2_1(const sp<HCameraServiceListener2_1>& hCsListener, |
| 193 | addListener_2_1_cb _hidl_cb) { |
| 194 | std::vector<hardware::CameraStatus> cameraStatusAndIds{}; |
| 195 | HStatus status = addListenerInternal<HCameraServiceListener2_1>( |
| 196 | hCsListener, &cameraStatusAndIds); |
| 197 | if (status != HStatus::NO_ERROR) { |
| 198 | _hidl_cb(status, {}); |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 199 | return Void(); |
| 200 | } |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 201 | |
| 202 | hidl_vec<frameworks::cameraservice::service::V2_1::CameraStatusAndId> hCameraStatusAndIds; |
| 203 | //Convert cameraStatusAndIds to HIDL and call callback |
| 204 | convertToHidl(cameraStatusAndIds, &hCameraStatusAndIds); |
| 205 | _hidl_cb(status, hCameraStatusAndIds); |
| 206 | |
| 207 | return Void(); |
| 208 | } |
| 209 | |
| 210 | template<class T> |
| 211 | HStatus HidlCameraService::addListenerInternal(const sp<T>& hCsListener, |
| 212 | std::vector<hardware::CameraStatus>* cameraStatusAndIds) { |
| 213 | if (mAidlICameraService == nullptr) { |
| 214 | return HStatus::UNKNOWN_ERROR; |
| 215 | } |
| 216 | if (hCsListener == nullptr || cameraStatusAndIds == nullptr) { |
| 217 | ALOGE("%s listener and cameraStatusAndIds must not be NULL", __FUNCTION__); |
| 218 | return HStatus::ILLEGAL_ARGUMENT; |
| 219 | } |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 220 | sp<hardware::ICameraServiceListener> csListener = nullptr; |
| 221 | // Check the cache for previously registered callbacks |
| 222 | { |
| 223 | Mutex::Autolock l(mListenerListLock); |
| 224 | csListener = searchListenerCacheLocked(hCsListener); |
| 225 | if (csListener == nullptr) { |
| 226 | // Wrap an hCsListener with AidlCameraServiceListener and pass it to |
| 227 | // CameraService. |
| 228 | csListener = new H2BCameraServiceListener(hCsListener); |
| 229 | // Add to cache |
| 230 | addToListenerCacheLocked(hCsListener, csListener); |
| 231 | } else { |
| 232 | ALOGE("%s: Trying to add a listener %p already registered", |
| 233 | __FUNCTION__, hCsListener.get()); |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 234 | return HStatus::ILLEGAL_ARGUMENT; |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
Jayant Chowdhary | f949ddd | 2019-01-29 14:34:11 -0800 | [diff] [blame] | 237 | binder::Status serviceRet = |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 238 | mAidlICameraService->addListenerHelper(csListener, cameraStatusAndIds, true); |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 239 | HStatus status = HStatus::NO_ERROR; |
| 240 | if (!serviceRet.isOk()) { |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 241 | ALOGE("%s: Unable to add camera device status listener", __FUNCTION__); |
| 242 | status = B2HStatus(serviceRet); |
| 243 | return status; |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 244 | } |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 245 | cameraStatusAndIds->erase(std::remove_if(cameraStatusAndIds->begin(), cameraStatusAndIds->end(), |
Jayant Chowdhary | 90e6369 | 2019-10-25 14:13:01 -0700 | [diff] [blame] | 246 | [this](const hardware::CameraStatus& s) { |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 247 | bool supportsHAL3 = false; |
| 248 | binder::Status sRet = |
Austin Borger | 71d8f67 | 2023-06-01 16:51:35 -0700 | [diff] [blame] | 249 | mAidlICameraService->supportsCameraApi(s.cameraId, |
Jayant Chowdhary | 90e6369 | 2019-10-25 14:13:01 -0700 | [diff] [blame] | 250 | hardware::ICameraService::API_VERSION_2, &supportsHAL3); |
Shuzhen Wang | 4fa28d2 | 2020-01-23 15:57:25 -0800 | [diff] [blame] | 251 | return !sRet.isOk() || !supportsHAL3; |
| 252 | }), cameraStatusAndIds->end()); |
| 253 | |
| 254 | return HStatus::NO_ERROR; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | Return<HStatus> HidlCameraService::removeListener(const sp<HCameraServiceListener>& hCsListener) { |
| 258 | if (hCsListener == nullptr) { |
| 259 | ALOGE("%s listener must not be NULL", __FUNCTION__); |
| 260 | return HStatus::ILLEGAL_ARGUMENT; |
| 261 | } |
Jayant Chowdhary | 94f79a9 | 2018-08-15 13:57:17 -0700 | [diff] [blame] | 262 | sp<ICameraServiceListener> csListener = nullptr; |
| 263 | { |
| 264 | Mutex::Autolock l(mListenerListLock); |
| 265 | csListener = searchListenerCacheLocked(hCsListener, /*removeIfFound*/true); |
| 266 | } |
| 267 | if (csListener != nullptr) { |
| 268 | mAidlICameraService->removeListener(csListener); |
| 269 | } else { |
| 270 | ALOGE("%s Removing unregistered listener %p", __FUNCTION__, hCsListener.get()); |
| 271 | return HStatus::ILLEGAL_ARGUMENT; |
| 272 | } |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 273 | return HStatus::NO_ERROR; |
| 274 | } |
| 275 | |
| 276 | Return<void> HidlCameraService::getCameraVendorTagSections(getCameraVendorTagSections_cb _hidl_cb) { |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 277 | sp<VendorTagDescriptorCache> gCache = VendorTagDescriptorCache::getGlobalVendorTagCache(); |
| 278 | if (gCache == nullptr) { |
| 279 | _hidl_cb(HStatus::UNKNOWN_ERROR, {}); |
| 280 | return Void(); |
| 281 | } |
| 282 | const std::unordered_map<metadata_vendor_id_t, sp<android::VendorTagDescriptor>> |
| 283 | &vendorIdsAndTagDescs = gCache->getVendorIdsAndTagDescriptors(); |
| 284 | if (vendorIdsAndTagDescs.size() == 0) { |
| 285 | _hidl_cb(HStatus::UNKNOWN_ERROR, {}); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 286 | return Void(); |
| 287 | } |
| 288 | |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 289 | hidl_vec<HProviderIdAndVendorTagSections> hTagIdsAndVendorTagSections; |
| 290 | hTagIdsAndVendorTagSections.resize(vendorIdsAndTagDescs.size()); |
| 291 | size_t j = 0; |
| 292 | for (auto &vendorIdAndTagDescs : vendorIdsAndTagDescs) { |
| 293 | hidl_vec<HVendorTagSection> hVendorTagSections; |
| 294 | sp<VendorTagDescriptor> desc = vendorIdAndTagDescs.second; |
| 295 | const SortedVector<String8>* sectionNames = desc->getAllSectionNames(); |
| 296 | size_t numSections = sectionNames->size(); |
| 297 | std::vector<std::vector<HVendorTag>> tagsBySection(numSections); |
| 298 | int tagCount = desc->getTagCount(); |
Jayant Chowdhary | 925a27f | 2021-09-13 16:25:07 -0700 | [diff] [blame] | 299 | if (tagCount <= 0) { |
| 300 | continue; |
| 301 | } |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 302 | std::vector<uint32_t> tags(tagCount); |
| 303 | desc->getTagArray(tags.data()); |
| 304 | for (int i = 0; i < tagCount; i++) { |
| 305 | HVendorTag vt; |
| 306 | vt.tagId = tags[i]; |
| 307 | vt.tagName = desc->getTagName(tags[i]); |
| 308 | vt.tagType = (HCameraMetadataType) desc->getTagType(tags[i]); |
| 309 | ssize_t sectionIdx = desc->getSectionIndex(tags[i]); |
| 310 | tagsBySection[sectionIdx].push_back(vt); |
| 311 | } |
| 312 | hVendorTagSections.resize(numSections); |
| 313 | for (size_t s = 0; s < numSections; s++) { |
Tomasz Wasilczyk | 12b04a5 | 2023-08-11 15:52:22 +0000 | [diff] [blame] | 314 | hVendorTagSections[s].sectionName = (*sectionNames)[s].c_str(); |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 315 | hVendorTagSections[s].tags = tagsBySection[s]; |
| 316 | } |
| 317 | HProviderIdAndVendorTagSections &hProviderIdAndVendorTagSections = |
| 318 | hTagIdsAndVendorTagSections[j]; |
| 319 | hProviderIdAndVendorTagSections.providerId = vendorIdAndTagDescs.first; |
| 320 | hProviderIdAndVendorTagSections.vendorTagSections = std::move(hVendorTagSections); |
| 321 | j++; |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 322 | } |
Jayant Chowdhary | 8cf9292 | 2018-11-19 15:45:17 -0800 | [diff] [blame] | 323 | _hidl_cb(HStatus::NO_ERROR, hTagIdsAndVendorTagSections); |
Jayant Chowdhary | be543d4 | 2018-08-15 13:16:14 -0700 | [diff] [blame] | 324 | return Void(); |
| 325 | } |
| 326 | |
| 327 | } // implementation |
| 328 | } // V2_0 |
| 329 | } // service |
| 330 | } // cameraservice |
| 331 | } // frameworks |
| 332 | } // android |
| 333 | |