blob: 981f431469f3531105c66f6330fbb0ecd0301b10 [file] [log] [blame]
Jayant Chowdharybe543d42018-08-15 13:16:14 -07001/*
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
17#include <hidl/Convert.h>
18
19#include <hidl/HidlCameraService.h>
20
21#include <hidl/HidlTransportSupport.h>
22
23namespace android {
24namespace frameworks {
25namespace cameraservice {
26namespace service {
27namespace V2_0 {
28namespace implementation {
29
30using frameworks::cameraservice::service::V2_0::implementation::HidlCameraService;
31using hardware::hidl_vec;
32using hardware::cameraservice::utils::conversion::convertToHidl;
33using hardware::cameraservice::utils::conversion::B2HStatus;
34using hardware::Void;
35
36using HCameraMetadataType = android::frameworks::cameraservice::common::V2_0::CameraMetadataType;
37using HVendorTag = android::frameworks::cameraservice::common::V2_0::VendorTag;
38using HVendorTagSection = android::frameworks::cameraservice::common::V2_0::VendorTagSection;
39
40sp<HidlCameraService> gHidlCameraService;
41
42sp<HidlCameraService> HidlCameraService::getInstance(android::CameraService *cs) {
43 gHidlCameraService = new HidlCameraService(cs);
44 return gHidlCameraService;
45}
46
47Return<void>
48HidlCameraService::getCameraCharacteristics(const hidl_string& cameraId,
49 getCameraCharacteristics_cb _hidl_cb) {
50 android::CameraMetadata cameraMetadata;
51 HStatus status = HStatus::NO_ERROR;
52 binder::Status serviceRet =
53 mAidlICameraService->getCameraCharacteristics(String16(cameraId.c_str()), &cameraMetadata);
54 HCameraMetadata hidlMetadata;
55 if (!serviceRet.isOk()) {
56 switch(serviceRet.serviceSpecificErrorCode()) {
57 // No ERROR_CAMERA_DISCONNECTED since we're in the same process.
58 case hardware::ICameraService::ERROR_ILLEGAL_ARGUMENT:
59 ALOGE("%s: Camera ID %s does not exist!", __FUNCTION__, cameraId.c_str());
60 status = HStatus::ILLEGAL_ARGUMENT;
61 break;
62 default:
63 ALOGE("Get camera characteristics from camera service failed: %s",
64 serviceRet.toString8().string());
65 status = B2HStatus(serviceRet);
66 }
67 _hidl_cb(status, hidlMetadata);
68 return Void();
69 }
70 const camera_metadata_t *rawMetadata = cameraMetadata.getAndLock();
71 convertToHidl(rawMetadata, &hidlMetadata);
72 _hidl_cb(status, hidlMetadata);
73 cameraMetadata.unlock(rawMetadata);
74 return Void();
75}
76
77Return<void> HidlCameraService::connectDevice(const sp<HCameraDeviceCallback>& hCallback,
78 const hidl_string& cameraId,
79 connectDevice_cb _hidl_cb) {
80 // To silence Wunused-parameter.
81 (void)hCallback;
82 (void)cameraId;
83 (void)_hidl_cb;
84
85 return Void();
86}
87
88Return<void> HidlCameraService::addListener(const sp<HCameraServiceListener>& hCsListener,
89 addListener_cb _hidl_cb) {
90 // To silence Wunused-parameter.
91 (void)hCsListener;
92 (void)_hidl_cb;
93
94 return Void();
95}
96
97Return<HStatus> HidlCameraService::removeListener(const sp<HCameraServiceListener>& hCsListener) {
98 if (hCsListener == nullptr) {
99 ALOGE("%s listener must not be NULL", __FUNCTION__);
100 return HStatus::ILLEGAL_ARGUMENT;
101 }
102 return HStatus::NO_ERROR;
103}
104
105Return<void> HidlCameraService::getCameraVendorTagSections(getCameraVendorTagSections_cb _hidl_cb) {
106 hidl_vec<HVendorTagSection> hVendorTagSections;
107 // TODO: Could this be just created on the stack since we don't set it to
108 // global cache or anything ?
109 HStatus hStatus = HStatus::NO_ERROR;
110 sp<VendorTagDescriptor> desc = new VendorTagDescriptor();
111 binder::Status serviceRet = mAidlICameraService->getCameraVendorTagDescriptor(desc.get());
112
113 if (!serviceRet.isOk()) {
114 ALOGE("%s: Failed to get VendorTagDescriptor", __FUNCTION__);
115 _hidl_cb(B2HStatus(serviceRet), hVendorTagSections);
116 return Void();
117 }
118
119 const SortedVector<String8>* sectionNames = desc->getAllSectionNames();
120 size_t numSections = sectionNames->size();
121 std::vector<std::vector<HVendorTag>> tagsBySection(numSections);
122 int tagCount = desc->getTagCount();
123 std::vector<uint32_t> tags(tagCount);
124 desc->getTagArray(tags.data());
125 for (int i = 0; i < tagCount; i++) {
126 HVendorTag vt;
127 vt.tagId = tags[i];
128 vt.tagName = desc->getTagName(tags[i]);
129 vt.tagType = (HCameraMetadataType) desc->getTagType(tags[i]);
130 ssize_t sectionIdx = desc->getSectionIndex(tags[i]);
131 tagsBySection[sectionIdx].push_back(vt);
132 }
133 hVendorTagSections.resize(numSections);
134 for (size_t s = 0; s < numSections; s++) {
135 hVendorTagSections[s].sectionName = (*sectionNames)[s].string();
136 hVendorTagSections[s].tags = tagsBySection[s];
137 }
138 _hidl_cb(hStatus, hVendorTagSections);
139 return Void();
140}
141
142} // implementation
143} // V2_0
144} // service
145} // cameraservice
146} // frameworks
147} // android
148