From 8cf929268cdb2cede142ebca0932fa4ac59d0f60 Mon Sep 17 00:00:00 2001 From: Jayant Chowdhary Date: Mon, 19 Nov 2018 15:45:17 -0800 Subject: [PATCH] cameraserver: Allow cameraserver HIDL interface to get provider ids with VendorTagSections. Bug: 110364143 Test: mm -j64 Test: AImageReaderVendorTest (sanity) Test: GCA (sanity) Change-Id: Iddcd5c1edb6cbe4b83968f01e46056a30c720219 Signed-off-by: Jayant Chowdhary --- camera/VendorTagDescriptor.cpp | 5 ++ camera/include/camera/VendorTagDescriptor.h | 3 + .../hidl/HidlCameraService.cpp | 77 +++++++++++-------- 3 files changed, 53 insertions(+), 32 deletions(-) diff --git a/camera/VendorTagDescriptor.cpp b/camera/VendorTagDescriptor.cpp index 38ff37f51a..d713d2dd86 100644 --- a/camera/VendorTagDescriptor.cpp +++ b/camera/VendorTagDescriptor.cpp @@ -411,6 +411,11 @@ status_t VendorTagDescriptorCache::readFromParcel(const Parcel* parcel) { return res; } +const std::unordered_map> & + VendorTagDescriptorCache::getVendorIdsAndTagDescriptors() { + return mVendorMap; +} + int VendorTagDescriptorCache::getTagCount(metadata_vendor_id_t id) const { int ret = 0; auto desc = mVendorMap.find(id); diff --git a/camera/include/camera/VendorTagDescriptor.h b/camera/include/camera/VendorTagDescriptor.h index c718c93aba..6f55890149 100644 --- a/camera/include/camera/VendorTagDescriptor.h +++ b/camera/include/camera/VendorTagDescriptor.h @@ -211,6 +211,9 @@ class VendorTagDescriptorCache : public Parcelable { */ void dump(int fd, int verbosity, int indentation) const; + const std::unordered_map> & + getVendorIdsAndTagDescriptors(); + protected: std::unordered_map> mVendorMap; struct vendor_tag_cache_ops mVendorCacheOps; diff --git a/services/camera/libcameraservice/hidl/HidlCameraService.cpp b/services/camera/libcameraservice/hidl/HidlCameraService.cpp index 31bdf6de20..48f1d374bf 100644 --- a/services/camera/libcameraservice/hidl/HidlCameraService.cpp +++ b/services/camera/libcameraservice/hidl/HidlCameraService.cpp @@ -40,9 +40,11 @@ using hardware::Void; using device::V2_0::implementation::H2BCameraDeviceCallbacks; using device::V2_0::implementation::HidlCameraDeviceUser; using service::V2_0::implementation::H2BCameraServiceListener; -using HCameraMetadataType = android::frameworks::cameraservice::common::V2_0::CameraMetadataType; -using HVendorTag = android::frameworks::cameraservice::common::V2_0::VendorTag; -using HVendorTagSection = android::frameworks::cameraservice::common::V2_0::VendorTagSection; +using HCameraMetadataType = frameworks::cameraservice::common::V2_0::CameraMetadataType; +using HVendorTag = frameworks::cameraservice::common::V2_0::VendorTag; +using HVendorTagSection = frameworks::cameraservice::common::V2_0::VendorTagSection; +using HProviderIdAndVendorTagSections = + frameworks::cameraservice::common::V2_0::ProviderIdAndVendorTagSections; sp gHidlCameraService; @@ -215,39 +217,50 @@ Return HidlCameraService::removeListener(const sp HidlCameraService::getCameraVendorTagSections(getCameraVendorTagSections_cb _hidl_cb) { - hidl_vec hVendorTagSections; - // TODO: Could this be just created on the stack since we don't set it to - // global cache or anything ? - HStatus hStatus = HStatus::NO_ERROR; - sp desc = new VendorTagDescriptor(); - binder::Status serviceRet = mAidlICameraService->getCameraVendorTagDescriptor(desc.get()); - - if (!serviceRet.isOk()) { - ALOGE("%s: Failed to get VendorTagDescriptor", __FUNCTION__); - _hidl_cb(B2HStatus(serviceRet), hVendorTagSections); + sp gCache = VendorTagDescriptorCache::getGlobalVendorTagCache(); + if (gCache == nullptr) { + _hidl_cb(HStatus::UNKNOWN_ERROR, {}); return Void(); } - - const SortedVector* sectionNames = desc->getAllSectionNames(); - size_t numSections = sectionNames->size(); - std::vector> tagsBySection(numSections); - int tagCount = desc->getTagCount(); - std::vector tags(tagCount); - desc->getTagArray(tags.data()); - for (int i = 0; i < tagCount; i++) { - HVendorTag vt; - vt.tagId = tags[i]; - vt.tagName = desc->getTagName(tags[i]); - vt.tagType = (HCameraMetadataType) desc->getTagType(tags[i]); - ssize_t sectionIdx = desc->getSectionIndex(tags[i]); - tagsBySection[sectionIdx].push_back(vt); + const std::unordered_map> + &vendorIdsAndTagDescs = gCache->getVendorIdsAndTagDescriptors(); + if (vendorIdsAndTagDescs.size() == 0) { + _hidl_cb(HStatus::UNKNOWN_ERROR, {}); + return Void(); } - hVendorTagSections.resize(numSections); - for (size_t s = 0; s < numSections; s++) { - hVendorTagSections[s].sectionName = (*sectionNames)[s].string(); - hVendorTagSections[s].tags = tagsBySection[s]; + + hidl_vec hTagIdsAndVendorTagSections; + hTagIdsAndVendorTagSections.resize(vendorIdsAndTagDescs.size()); + size_t j = 0; + for (auto &vendorIdAndTagDescs : vendorIdsAndTagDescs) { + hidl_vec hVendorTagSections; + sp desc = vendorIdAndTagDescs.second; + const SortedVector* sectionNames = desc->getAllSectionNames(); + size_t numSections = sectionNames->size(); + std::vector> tagsBySection(numSections); + int tagCount = desc->getTagCount(); + std::vector tags(tagCount); + desc->getTagArray(tags.data()); + for (int i = 0; i < tagCount; i++) { + HVendorTag vt; + vt.tagId = tags[i]; + vt.tagName = desc->getTagName(tags[i]); + vt.tagType = (HCameraMetadataType) desc->getTagType(tags[i]); + ssize_t sectionIdx = desc->getSectionIndex(tags[i]); + tagsBySection[sectionIdx].push_back(vt); + } + hVendorTagSections.resize(numSections); + for (size_t s = 0; s < numSections; s++) { + hVendorTagSections[s].sectionName = (*sectionNames)[s].string(); + hVendorTagSections[s].tags = tagsBySection[s]; + } + HProviderIdAndVendorTagSections &hProviderIdAndVendorTagSections = + hTagIdsAndVendorTagSections[j]; + hProviderIdAndVendorTagSections.providerId = vendorIdAndTagDescs.first; + hProviderIdAndVendorTagSections.vendorTagSections = std::move(hVendorTagSections); + j++; } - _hidl_cb(hStatus, hVendorTagSections); + _hidl_cb(HStatus::NO_ERROR, hTagIdsAndVendorTagSections); return Void(); }