1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8
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 "hcs_deal.h"
18 #include <stdlib.h>
19 #include <vector>
20 #include "hcs_dm_parser.h"
21 #include "metadata_enum_map.h"
22 #define STRTOL_BASE 10
23
24 namespace OHOS::Camera {
HcsDeal(const std::string & pathName)25 HcsDeal::HcsDeal(const std::string &pathName) : sPathName(pathName), pDevResIns(nullptr), pRootNode(nullptr) {}
26
~HcsDeal()27 HcsDeal::~HcsDeal()
28 {
29 ReleaseHcsTree();
30 pDevResIns = nullptr;
31 pRootNode = nullptr;
32 }
33
SetHcsPathName(const std::string & pathName)34 void HcsDeal::SetHcsPathName(const std::string &pathName)
35 {
36 sPathName = pathName;
37 }
38
Init()39 RetCode HcsDeal::Init()
40 {
41 ReleaseHcsTree();
42 pDevResIns = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
43 if (pDevResIns == nullptr) {
44 CAMERA_LOGE("get hcs interface failed.");
45 return RC_ERROR;
46 }
47
48 CAMERA_LOGD("pathname = %{public}s", sPathName.c_str());
49 SetHcsBlobPath(sPathName.c_str());
50 pRootNode = pDevResIns->GetRootNode();
51 if (pRootNode == nullptr) {
52 CAMERA_LOGE("GetRootNode failed");
53 return RC_ERROR;
54 }
55 if (pRootNode->name != nullptr) {
56 CAMERA_LOGI("pRootNode = %{public}s", pRootNode->name);
57 }
58
59 DealHcsData();
60
61 return RC_OK;
62 }
63
DealHcsData()64 RetCode HcsDeal::DealHcsData()
65 {
66 const struct DeviceResourceNode *cameraHostConfig = pDevResIns->GetChildNode(pRootNode, "camera_host_config");
67 if (cameraHostConfig == nullptr) {
68 return RC_ERROR;
69 }
70 if (pRootNode->name != nullptr) {
71 CAMERA_LOGI("pRootNode = %{public}s", pRootNode->name);
72 }
73 if (cameraHostConfig->name == nullptr) {
74 CAMERA_LOGW("cameraHostConfig->name is null");
75 return RC_ERROR;
76 }
77 CAMERA_LOGD("cameraHostConfig = %{public}s", cameraHostConfig->name);
78
79 const struct DeviceResourceNode *childNodeTmp = nullptr;
80 DEV_RES_NODE_FOR_EACH_CHILD_NODE(cameraHostConfig, childNodeTmp)
81 {
82 if (childNodeTmp != nullptr && childNodeTmp->name != nullptr) {
83 std::string nodeName = std::string(childNodeTmp->name);
84 CAMERA_LOGI("cameraHostConfig subnode name = %{public}s", nodeName.c_str());
85 if (nodeName.find(std::string("ability"), 0) != std::string::npos) {
86 DealCameraAbility(*childNodeTmp);
87 }
88 }
89 }
90
91 return RC_OK;
92 }
93
DealCameraAbility(const struct DeviceResourceNode & node)94 RetCode HcsDeal::DealCameraAbility(const struct DeviceResourceNode &node)
95 {
96 CAMERA_LOGI("nodeName = %{public}s", node.name);
97
98 const char *cameraId = nullptr;
99 int32_t ret = pDevResIns->GetString(&node, "logicCameraId", &cameraId, nullptr);
100 if (ret != 0) {
101 CAMERA_LOGW("get logic cameraid failed");
102 return RC_ERROR;
103 }
104 CAMERA_LOGD("logic cameraid is %{public}s", cameraId);
105
106 std::vector<std::string> phyCameraIds;
107 (void)DealPhysicsCameraId(node, phyCameraIds);
108 if (!phyCameraIds.empty() && cameraId != nullptr) {
109 cameraIdMap_.insert(std::make_pair(std::string(cameraId), phyCameraIds));
110 }
111
112 const struct DeviceResourceNode *metadataNode = pDevResIns->GetChildNode(&node, "metadata");
113 if (metadataNode == nullptr || cameraId == nullptr) {
114 CAMERA_LOGW("metadataNode is null or cameraId is null");
115 return RC_ERROR;
116 }
117 RetCode rc = DealMetadata(cameraId, *metadataNode);
118 if (rc != RC_OK) {
119 CAMERA_LOGW("deal metadata failed");
120 return RC_ERROR;
121 }
122
123 for (CameraIdMap::iterator itr = cameraIdMap_.begin(); itr != cameraIdMap_.end(); ++itr) {
124 CAMERA_LOGD("cameraId = %{public}s", itr->first.c_str());
125 for (auto &str : itr->second) {
126 CAMERA_LOGD("phyCameraId = %{public}s", str.c_str());
127 }
128 }
129
130 return RC_OK;
131 }
132
DealPhysicsCameraId(const struct DeviceResourceNode & node,std::vector<std::string> & cameraIds)133 RetCode HcsDeal::DealPhysicsCameraId(const struct DeviceResourceNode &node, std::vector<std::string> &cameraIds)
134 {
135 const char *nodeValue = nullptr;
136 int32_t elemNum = pDevResIns->GetElemNum(&node, "physicsCameraIds");
137 for (int i = 0; i < elemNum; i++) {
138 pDevResIns->GetStringArrayElem(&node, "physicsCameraIds", i, &nodeValue, nullptr);
139 cameraIds.push_back(std::string(nodeValue));
140 }
141
142 return RC_OK;
143 }
144
DealMetadata(const std::string & cameraId,const struct DeviceResourceNode & node)145 RetCode HcsDeal::DealMetadata(const std::string &cameraId, const struct DeviceResourceNode &node)
146 {
147 struct DeviceResourceAttr *drAttr = nullptr;
148 DEV_RES_NODE_FOR_EACH_ATTR(&node, drAttr) {}
149
150 CAMERA_LOGD("metadata = %{public}s", node.name);
151 const int ENTRY_CAPACITY = 30;
152 const int DATA_CAPACITY = 2000;
153 std::shared_ptr<CameraMetadata> metadata = std::make_shared<CameraMetadata>(ENTRY_CAPACITY, DATA_CAPACITY);
154 if (metadata == nullptr) {
155 CAMERA_LOGE("metadata is nullptr cameraId: %{public}s, nodeName: %{public}s",
156 cameraId.c_str(), node.name);
157 return RC_ERROR;
158 }
159 DealAeAvailableAntiBandingModes(node, metadata);
160 DealAeAvailableModes(node, metadata);
161 DealAvailableFpsRange(node, metadata);
162 DealCameraPosition(node, metadata);
163 DealCameraType(node, metadata);
164 DealCameraConnectionType(node, metadata);
165 DealCameraMemoryType(node, metadata);
166 DealCameraFaceDetectMaxNum(node, metadata);
167 DealAeCompensationRange(node, metadata);
168 DealAeCompensationSteps(node, metadata);
169 DealAvailableAwbModes(node, metadata);
170 DealSensitivityRange(node, metadata);
171 DealFaceDetectMode(node, metadata);
172 DealFocalLength(node, metadata);
173 DealAvailableFocusModes(node, metadata);
174 DealAvailableExposureModes(node, metadata);
175 DealAvailableMetereModes(node, metadata);
176 DealAvalialbleFlashModes(node, metadata);
177 DealMirrorSupported(node, metadata);
178 DealAvaliableBasicConfigurations(node, metadata);
179 DealSensorOrientation(node, metadata);
180 DealAvalialbleVideoStabilizationModes(node, metadata);
181 DealAvalialbleFlash(node, metadata);
182 DealAvalialbleAutoFocus(node, metadata);
183 DealZoomRationRange(node, metadata);
184 DealJpegOrientation(node, metadata);
185 DealAvaliableExtendConfigurations(node, metadata);
186 DealJpegQuality(node, metadata);
187 cameraMetadataMap_.insert(std::make_pair(cameraId, metadata));
188
189 return RC_OK;
190 }
191
DealAeAvailableAntiBandingModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)192 RetCode HcsDeal::DealAeAvailableAntiBandingModes(
193 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
194 {
195 const char *nodeValue = nullptr;
196 std::vector<uint8_t> aeAvailableAntiBandingModeUint8s;
197 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "aeAvailableAntiBandingModes");
198 for (int i = 0; i < elemNum; i++) {
199 pDevResIns->GetStringArrayElem(&metadataNode, "aeAvailableAntiBandingModes", i, &nodeValue, nullptr);
200 aeAvailableAntiBandingModeUint8s.push_back(AeAntibandingModeMap[std::string(nodeValue)]);
201 CAMERA_LOGD("aeAvailableAntiBandingModes = %{public}s", nodeValue);
202 }
203 bool ret = metadata->addEntry(OHOS_CONTROL_AE_AVAILABLE_ANTIBANDING_MODES, aeAvailableAntiBandingModeUint8s.data(),
204 aeAvailableAntiBandingModeUint8s.size());
205 if (!ret) {
206 CAMERA_LOGE("aeAvailableAntiBandingModes add failed");
207 return RC_ERROR;
208 }
209 CAMERA_LOGD("aeAvailableAntiBandingModes add success");
210 return RC_OK;
211 }
212
DealAeAvailableModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)213 RetCode HcsDeal::DealAeAvailableModes(
214 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
215 {
216 int32_t hcbRet = -1;
217 const char *nodeValue = nullptr;
218 std::vector<uint8_t> aeAvailableModesU8;
219 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "aeAvailableModes");
220 for (int i = 0; i < elemNum; i++) {
221 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "aeAvailableModes", i, &nodeValue, nullptr);
222 if (hcbRet != 0) {
223 CAMERA_LOGD("get aeAvailableModes failed");
224 continue;
225 }
226 aeAvailableModesU8.push_back(AeModeMap[std::string(nodeValue)]);
227 CAMERA_LOGD("aeAvailableModes = %{public}s", nodeValue);
228 }
229 bool ret =
230 metadata->addEntry(OHOS_CONTROL_AE_AVAILABLE_MODES, aeAvailableModesU8.data(), aeAvailableModesU8.size());
231 if (!ret) {
232 CAMERA_LOGE("aeAvailableModes add failed");
233 return RC_ERROR;
234 }
235 CAMERA_LOGD("aeAvailableModes add success");
236 return RC_OK;
237 }
238
DealAvailableFpsRange(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)239 RetCode HcsDeal::DealAvailableFpsRange(
240 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
241 {
242 int32_t hcbRet = -1;
243 uint32_t nodeValue;
244 std::vector<int32_t> availableFpsRange;
245 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "availableFpsRange");
246 constexpr uint32_t groupLen = 2;
247
248 if (elemNum != groupLen) {
249 CAMERA_LOGE("availableFpsRange hcs file configuration error");
250 return RC_ERROR;
251 }
252
253 for (int i = 0; i < elemNum; i++) {
254 hcbRet = pDevResIns->GetUint32ArrayElem(&metadataNode, "availableFpsRange", i, &nodeValue, -1);
255 if (hcbRet != 0) {
256 CAMERA_LOGD("get availableFpsRange failed");
257 continue;
258 }
259 availableFpsRange.push_back(static_cast<int32_t>(nodeValue));
260 CAMERA_LOGD("get availableFpsRange:%{public}d", nodeValue);
261 }
262 bool ret = metadata->addEntry(OHOS_ABILITY_FPS_RANGES, availableFpsRange.data(), availableFpsRange.size());
263 if (!ret) {
264 CAMERA_LOGE("availableFpsRange add failed");
265 return RC_ERROR;
266 }
267 CAMERA_LOGD("availableFpsRange add success");
268 return RC_OK;
269 }
270
DealCameraPosition(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)271 RetCode HcsDeal::DealCameraPosition(
272 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
273 {
274 CAMERA_LOGD("cameraPosition in...");
275 const char *nodeValue = nullptr;
276 uint8_t cameraPosition = 0;
277
278 int32_t rc = pDevResIns->GetString(&metadataNode, "cameraPosition", &nodeValue, nullptr);
279 if (rc != 0 || (nodeValue == nullptr)) {
280 CAMERA_LOGE("get cameraPosition failed");
281 return RC_ERROR;
282 }
283
284 cameraPosition = CameraPositionMap[std::string(nodeValue)];
285 CAMERA_LOGD("cameraPosition = %{public}d", cameraPosition);
286
287 bool ret = metadata->addEntry(
288 OHOS_ABILITY_CAMERA_POSITION, static_cast<const void *>(&cameraPosition), sizeof(cameraPosition));
289 if (!ret) {
290 CAMERA_LOGE("cameraPosition add failed");
291 return RC_ERROR;
292 }
293 CAMERA_LOGD("cameraPosition add success");
294 return RC_OK;
295 }
296
DealCameraType(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)297 RetCode HcsDeal::DealCameraType(
298 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
299 {
300 CAMERA_LOGD("cameraType in...");
301 const char *nodeValue = nullptr;
302 uint8_t cameraType = 0;
303
304 int32_t rc = pDevResIns->GetString(&metadataNode, "cameraType", &nodeValue, nullptr);
305 if (rc != 0 || (nodeValue == nullptr)) {
306 CAMERA_LOGE("get cameraType failed");
307 return RC_ERROR;
308 }
309
310 cameraType = CameraTypeMap[std::string(nodeValue)];
311 CAMERA_LOGD("cameraType = %{public}d", cameraType);
312
313 bool ret = metadata->addEntry(OHOS_ABILITY_CAMERA_TYPE, static_cast<const void *>(&cameraType), sizeof(cameraType));
314 if (!ret) {
315 CAMERA_LOGE("cameraType add failed");
316 return RC_ERROR;
317 }
318 CAMERA_LOGD("cameraType add success");
319 return RC_OK;
320 }
321
DealCameraConnectionType(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)322 RetCode HcsDeal::DealCameraConnectionType(
323 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
324 {
325 CAMERA_LOGD("cameraConnectionType in...");
326 const char *nodeValue = nullptr;
327 uint8_t cameraConnectionType = 0;
328
329 int32_t rc = pDevResIns->GetString(&metadataNode, "cameraConnectionType", &nodeValue, nullptr);
330 if (rc != 0 || (nodeValue == nullptr)) {
331 CAMERA_LOGE("get cameraConnectionType failed");
332 return RC_ERROR;
333 }
334
335 cameraConnectionType = cameraConnectionTypeMap[std::string(nodeValue)];
336 CAMERA_LOGD("cameraConnectionType = %{public}d", cameraConnectionType);
337
338 bool ret = metadata->addEntry(OHOS_ABILITY_CAMERA_CONNECTION_TYPE, static_cast<const void *>(&cameraConnectionType),
339 sizeof(cameraConnectionType));
340 if (!ret) {
341 CAMERA_LOGE("cameraConnectionType add failed");
342 return RC_ERROR;
343 }
344 CAMERA_LOGD("cameraConnectionType add success");
345 return RC_OK;
346 }
347
DealCameraMemoryType(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)348 RetCode HcsDeal::DealCameraMemoryType(
349 const struct DeviceResourceNode &metadataNode,
350 std::shared_ptr<CameraMetadata> &metadata)
351 {
352 CAMERA_LOGD("cameraMemoryType in...");
353 const char *nodeValue = nullptr;
354 uint8_t cameraMemoryType = 0;
355 int32_t rc = pDevResIns->GetString(&metadataNode, "cameraMemoryType", &nodeValue, nullptr);
356 if (rc != 0 || (nodeValue == nullptr)) {
357 CAMERA_LOGE("get cameraMemoryType failed");
358 return RC_ERROR;
359 }
360 auto findIf = CameraMemoryTypeMap.find(std::string(nodeValue));
361 if (findIf == CameraMemoryTypeMap.end()) {
362 CAMERA_LOGE("value of cameraMemoryType err.[%{public}s]", nodeValue);
363 return RC_ERROR;
364 }
365 cameraMemoryType = CameraMemoryTypeMap[std::string(nodeValue)];
366 CAMERA_LOGD("cameraMemoryType = %{public}d", cameraMemoryType);
367 bool ret = metadata->addEntry(OHOS_ABILITY_MEMORY_TYPE,
368 static_cast<const void*>(&cameraMemoryType), sizeof(cameraMemoryType));
369 if (!ret) {
370 CAMERA_LOGE("cameraMemoryType add failed");
371 return RC_ERROR;
372 }
373 CAMERA_LOGD("cameraMemoryType add success");
374 return RC_OK;
375 }
376
DealCameraFaceDetectMaxNum(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)377 RetCode HcsDeal::DealCameraFaceDetectMaxNum(
378 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
379 {
380 const char *pNodeValue = nullptr;
381 uint8_t faceDetectMaxNum;
382
383 int32_t rc = pDevResIns->GetString(&metadataNode, "faceDetectMaxNum", &pNodeValue, nullptr);
384 if (rc != 0 || (pNodeValue == nullptr)) {
385 CAMERA_LOGE("get faceDetectMaxNum failed");
386 return RC_ERROR;
387 }
388
389 faceDetectMaxNum = (uint8_t)strtol(pNodeValue, NULL, STRTOL_BASE);
390 CAMERA_LOGD("faceDetectMaxNum = %{public}f", faceDetectMaxNum);
391
392 bool ret = metadata->addEntry(OHOS_STATISTICS_FACE_DETECT_MAX_NUM, static_cast<const void *>(&faceDetectMaxNum), 1);
393 if (!ret) {
394 CAMERA_LOGE("faceDetectMaxNum add failed");
395 return RC_ERROR;
396 }
397 CAMERA_LOGD("faceDetectMaxNum add success");
398 return RC_OK;
399 }
400
DealAeCompensationRange(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)401 RetCode HcsDeal::DealAeCompensationRange(
402 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
403 {
404 std::vector<int32_t> aeCompensationRange;
405 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "aeCompensationRange");
406 uint32_t nodeValue;
407 for (int i = 0; i < elemNum; i++) {
408 pDevResIns->GetUint32ArrayElem(&metadataNode, "aeCompensationRange", i, &nodeValue, -1);
409 aeCompensationRange.push_back(static_cast<int32_t>(nodeValue));
410 }
411
412 bool ret =
413 metadata->addEntry(OHOS_ABILITY_AE_COMPENSATION_RANGE, aeCompensationRange.data(), aeCompensationRange.size());
414 if (!ret) {
415 CAMERA_LOGD("aeCompensationRange add failed");
416 return RC_ERROR;
417 }
418 CAMERA_LOGI("aeCompensationRange add success");
419 return RC_OK;
420 }
421
DealAeCompensationSteps(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)422 RetCode HcsDeal::DealAeCompensationSteps(
423 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
424 {
425 constexpr const char *AE_COMPENSATION_STEPS = "aeCompensationSteps";
426 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, AE_COMPENSATION_STEPS);
427 uint32_t nodeValue;
428 camera_rational_t aeCompensationStep;
429 constexpr uint32_t groupLen = 2;
430
431 if (elemNum != groupLen) {
432 CAMERA_LOGE("aeCompensationSteps hcs file configuration error");
433 return RC_ERROR;
434 }
435
436 pDevResIns->GetUint32ArrayElem(&metadataNode, AE_COMPENSATION_STEPS, 0, &nodeValue, -1);
437 aeCompensationStep.numerator = (int32_t)nodeValue;
438 pDevResIns->GetUint32ArrayElem(&metadataNode, AE_COMPENSATION_STEPS, 1, &nodeValue, -1);
439 aeCompensationStep.denominator = (int32_t)nodeValue;
440
441 bool ret = metadata->addEntry(OHOS_ABILITY_AE_COMPENSATION_STEP, &aeCompensationStep, 1);
442 if (!ret) {
443 CAMERA_LOGE("aeCompensationSteps add failed");
444 return RC_ERROR;
445 }
446 CAMERA_LOGD("aeCompensationSteps add success");
447 return RC_OK;
448 }
449
DealAvailableAwbModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)450 RetCode HcsDeal::DealAvailableAwbModes(
451 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
452 {
453 int32_t hcbRet = -1;
454 const char *nodeValue = nullptr;
455 std::vector<uint8_t> availableAwbModes;
456 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "availableAwbModes");
457 for (int i = 0; i < elemNum; i++) {
458 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "availableAwbModes", i, &nodeValue, nullptr);
459 if (hcbRet != 0) {
460 CAMERA_LOGD("get availableAwbModes failed");
461 continue;
462 }
463 availableAwbModes.push_back(AwbModeMap[std::string(nodeValue)]);
464 }
465 bool ret = metadata->addEntry(OHOS_CONTROL_AWB_AVAILABLE_MODES, availableAwbModes.data(), availableAwbModes.size());
466 if (!ret) {
467 CAMERA_LOGE("availableAwbModes add failed");
468 return RC_ERROR;
469 }
470 CAMERA_LOGD("availableAwbModes add success");
471 return RC_OK;
472 }
473
DealSensitivityRange(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)474 RetCode HcsDeal::DealSensitivityRange(
475 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
476 {
477 std::vector<int32_t> sensitivityRange;
478 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "sensitivityRange");
479 CAMERA_LOGD("sensitivityRange elemNum = %{public}d", elemNum);
480 uint32_t nodeValue;
481 for (int i = 0; i < elemNum; i++) {
482 pDevResIns->GetUint32ArrayElem(&metadataNode, "sensitivityRange", i, &nodeValue, -1);
483 sensitivityRange.push_back(static_cast<int32_t>(nodeValue));
484 }
485
486 bool ret = metadata->addEntry(OHOS_SENSOR_INFO_SENSITIVITY_RANGE, sensitivityRange.data(), sensitivityRange.size());
487 if (!ret) {
488 CAMERA_LOGI("sensitivityRange add failed");
489 return RC_ERROR;
490 }
491 CAMERA_LOGD("sensitivityRange add success");
492 return RC_OK;
493 }
494
DealFaceDetectMode(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)495 RetCode HcsDeal::DealFaceDetectMode(
496 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
497 {
498 const char *pNodeValue = nullptr;
499 int32_t rc = pDevResIns->GetString(&metadataNode, "faceDetectMode", &pNodeValue, nullptr);
500 if (rc != 0) {
501 CAMERA_LOGI("get faceDetectMode failed");
502 return RC_ERROR;
503 }
504
505 bool ret = metadata->addEntry(OHOS_STATISTICS_FACE_DETECT_MODE, &(FaceDetectModeMap[std::string(pNodeValue)]), 1);
506 if (!ret) {
507 CAMERA_LOGI("faceDetectMode add failed");
508 return RC_ERROR;
509 }
510 CAMERA_LOGD("faceDetectMode add success");
511 return RC_OK;
512 }
513
DealAvailableResultKeys(const struct DeviceResourceNode & metadataNode,std::shared_ptr<CameraMetadata> & metadata)514 RetCode HcsDeal::DealAvailableResultKeys(
515 const struct DeviceResourceNode &metadataNode, std::shared_ptr<CameraMetadata> &metadata)
516 {
517 int32_t hcbRet = -1;
518 const char *nodeValue = nullptr;
519 std::vector<int32_t> availableResultKeys;
520 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "availableResultKeys");
521 for (int i = 0; i < elemNum; i++) {
522 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "availableResultKeys", i, &nodeValue, nullptr);
523 if (hcbRet != 0) {
524 CAMERA_LOGI("get availableResultKeys failed");
525 continue;
526 }
527 availableResultKeys.push_back(MetadataTagMap[std::string(nodeValue)]);
528 }
529 bool ret = metadata->addEntry(
530 OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, availableResultKeys.data(), availableResultKeys.size());
531 if (!ret) {
532 CAMERA_LOGI("availableResultKeys add failed");
533 return RC_ERROR;
534 }
535 CAMERA_LOGD("availableResultKeys add success");
536 return RC_OK;
537 }
538
DealFocalLength(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)539 RetCode HcsDeal::DealFocalLength(
540 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
541 {
542 const char *pNodeValue = nullptr;
543 float focalLength;
544
545 int32_t rc = pDevResIns->GetString(&metadataNode, "focalLength", &pNodeValue, nullptr);
546 if (rc != 0 || (pNodeValue == nullptr)) {
547 CAMERA_LOGE("get focalLength failed");
548 return RC_ERROR;
549 }
550
551 focalLength = (float)strtol(pNodeValue, NULL, STRTOL_BASE);
552 CAMERA_LOGD("focalLength = %{public}f", focalLength);
553
554 bool ret = metadata->addEntry(OHOS_ABILITY_FOCAL_LENGTH, static_cast<const void *>(&focalLength), 1);
555 if (!ret) {
556 CAMERA_LOGE("focalLength add failed");
557 return RC_ERROR;
558 }
559 CAMERA_LOGD("focalLength add success");
560 return RC_OK;
561 }
562
DealAvailableFocusModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)563 RetCode HcsDeal::DealAvailableFocusModes(
564 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
565 {
566 uint8_t hcbRet = 0;
567 const char *nodeValue = nullptr;
568 std::vector<uint8_t> focusAvailableModes;
569
570 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "focusAvailableModes");
571 CAMERA_LOGD("elemNum = %{public}d", elemNum);
572
573 for (int i = 0; i < elemNum; i++) {
574 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "focusAvailableModes", i, &nodeValue, nullptr);
575 if (hcbRet != 0) {
576 CAMERA_LOGE("get focusAvailableModes failed");
577 continue;
578 }
579 CAMERA_LOGD("nodeValue = %{public}s", nodeValue);
580 focusAvailableModes.push_back(FocusModeMap[std::string(nodeValue)]);
581 }
582 bool ret = metadata->addEntry(OHOS_ABILITY_FOCUS_MODES, focusAvailableModes.data(), focusAvailableModes.size());
583 if (!ret) {
584 CAMERA_LOGE("focusAvailableModes add failed");
585 return RC_ERROR;
586 }
587 CAMERA_LOGD("focusAvailableModes add success");
588 return RC_OK;
589 }
590
DealAvailableExposureModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)591 RetCode HcsDeal::DealAvailableExposureModes(
592 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
593 {
594 uint8_t hcbRet = 0;
595 const char *nodeValue = nullptr;
596 std::vector<uint8_t> exposureModeResult;
597
598 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "exposureAvailableModes");
599 CAMERA_LOGD("elemNum = %{public}d", elemNum);
600
601 for (int i = 0; i < elemNum; i++) {
602 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "exposureAvailableModes", i, &nodeValue, nullptr);
603 if (hcbRet != 0) {
604 CAMERA_LOGE("get exposureModeResult failed");
605 continue;
606 }
607 CAMERA_LOGD("nodeValue = %{public}s", nodeValue);
608 exposureModeResult.push_back(ExposureModeMap[std::string(nodeValue)]);
609 }
610 bool ret = metadata->addEntry(OHOS_ABILITY_EXPOSURE_MODES, exposureModeResult.data(), exposureModeResult.size());
611 if (!ret) {
612 CAMERA_LOGE("exposureModeResult add failed");
613 return RC_ERROR;
614 }
615 CAMERA_LOGD("exposureModeResult add success");
616 return RC_OK;
617 }
618
DealAvailableMetereModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)619 RetCode HcsDeal::DealAvailableMetereModes(
620 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
621 {
622 uint8_t hcbRet = 0;
623 const char *nodeValue = nullptr;
624 std::vector<uint8_t> meterModeResult;
625
626 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "meterAvailableModes");
627 CAMERA_LOGD("elemNum = %{public}d", elemNum);
628
629 for (int i = 0; i < elemNum; i++) {
630 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "meterAvailableModes", i, &nodeValue, nullptr);
631 if (hcbRet != 0) {
632 CAMERA_LOGE("get meterModeResult failed");
633 continue;
634 }
635 CAMERA_LOGD("nodeValue = %{public}s", nodeValue);
636 meterModeResult.push_back(meterModeMap[std::string(nodeValue)]);
637 }
638 bool ret = metadata->addEntry(OHOS_ABILITY_METER_MODES, meterModeResult.data(), meterModeResult.size());
639 if (!ret) {
640 CAMERA_LOGE("meterModeResult add failed");
641 return RC_ERROR;
642 }
643 CAMERA_LOGD("meterModeResult add success");
644 return RC_OK;
645 }
646
DealAvalialbleFlashModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)647 RetCode HcsDeal::DealAvalialbleFlashModes(
648 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
649 {
650 uint8_t hcbRet = 0;
651 const char *nodeValue = nullptr;
652 std::vector<uint8_t> flashAvailableModeUint8s;
653
654 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "flashAvailableModes");
655 CAMERA_LOGD("elemNum = %{public}d", elemNum);
656
657 for (int i = 0; i < elemNum; i++) {
658 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "flashAvailableModes", i, &nodeValue, nullptr);
659 if (hcbRet != 0) {
660 CAMERA_LOGE("get flashAvailableModes failed");
661 continue;
662 }
663 CAMERA_LOGD("nodeValue = %{public}s", nodeValue);
664 flashAvailableModeUint8s.push_back(FlashModeMap[std::string(nodeValue)]);
665 }
666 bool ret =
667 metadata->addEntry(OHOS_ABILITY_FLASH_MODES, flashAvailableModeUint8s.data(), flashAvailableModeUint8s.size());
668 if (!ret) {
669 CAMERA_LOGE("flashAvailableModes add failed");
670 return RC_ERROR;
671 }
672 CAMERA_LOGD("flashAvailableModes add success");
673 return RC_OK;
674 }
675
DealMirrorSupported(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)676 RetCode HcsDeal::DealMirrorSupported(
677 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
678 {
679 const char *nodeValue = nullptr;
680 uint8_t mirrorSupportU8;
681
682 int32_t rc = pDevResIns->GetString(&metadataNode, "mirrorSupported", &nodeValue, nullptr);
683 if (rc != 0 || (nodeValue == nullptr)) {
684 CAMERA_LOGE("get mirrorSupported failed");
685 return RC_ERROR;
686 }
687
688 mirrorSupportU8 = mirrorMap[std::string(nodeValue)];
689 CAMERA_LOGD("mirrorSupportU8 = %{public}d", mirrorSupportU8);
690
691 bool ret =
692 metadata->addEntry(OHOS_CONTROL_CAPTURE_MIRROR_SUPPORTED, static_cast<const void *>(&mirrorSupportU8), 1);
693 if (!ret) {
694 CAMERA_LOGE("mirrorSupported add failed");
695 return RC_ERROR;
696 }
697 CAMERA_LOGD("mirrorSupported add success");
698 return RC_OK;
699 }
700
DealAvaliableBasicConfigurations(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)701 RetCode HcsDeal::DealAvaliableBasicConfigurations(
702 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
703 {
704 uint32_t nodeValue;
705 std::vector<int32_t> basicConfigAvaliableInt32s;
706
707 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "basicAvailableConfigurations");
708 CAMERA_LOGD("elemNum = %{public}d", elemNum);
709
710 constexpr int STREAM_INFO_ITEM_LENGTH = 3;
711 for (int i = 0; i < elemNum; i++) {
712 pDevResIns->GetUint32ArrayElem(&metadataNode, "basicAvailableConfigurations", i, &nodeValue, -1);
713 CAMERA_LOGD("nodeValue = %{public}d", nodeValue);
714
715 if (i % STREAM_INFO_ITEM_LENGTH == 0) {
716 basicConfigAvaliableInt32s.push_back(formatArray[static_cast<int32_t>(nodeValue) - 1]);
717 } else {
718 basicConfigAvaliableInt32s.push_back(static_cast<int32_t>(nodeValue));
719 }
720 }
721
722 bool ret = metadata->addEntry(OHOS_ABILITY_STREAM_AVAILABLE_BASIC_CONFIGURATIONS, basicConfigAvaliableInt32s.data(),
723 basicConfigAvaliableInt32s.size());
724 if (!ret) {
725 CAMERA_LOGD("basicAvailableConfigurations add failed");
726 return RC_ERROR;
727 }
728 CAMERA_LOGI("basicAvailableConfigurations add success");
729 return RC_OK;
730 }
731
DealSensorOrientation(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)732 RetCode HcsDeal::DealSensorOrientation(
733 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
734 {
735 const char *nodeValue = nullptr;
736 int32_t sensorOrientation;
737
738 int32_t rc = pDevResIns->GetString(&metadataNode, "sensorOrientationSupported", &nodeValue, nullptr);
739 if (rc != 0 || (nodeValue == nullptr)) {
740 CAMERA_LOGE("get sensorOrientationSupported failed");
741 return RC_ERROR;
742 }
743
744 sensorOrientation = (int32_t)strtol(nodeValue, NULL, STRTOL_BASE);
745 CAMERA_LOGI("sensorOrientation = %{public}d", sensorOrientation);
746
747 constexpr uint32_t DATA_COUNT = 1;
748 bool ret = metadata->addEntry(OHOS_SENSOR_ORIENTATION, static_cast<const void *>(&sensorOrientation), DATA_COUNT);
749 if (!ret) {
750 CAMERA_LOGE("sensorOrientationSupported add failed");
751 return RC_ERROR;
752 }
753 CAMERA_LOGI("sensorOrientationSupported add success");
754 return RC_OK;
755 }
756
DealAvalialbleVideoStabilizationModes(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)757 RetCode HcsDeal::DealAvalialbleVideoStabilizationModes(
758 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
759 {
760 uint8_t hcbRet = 0;
761 const char *nodeValue = nullptr;
762 std::vector<uint8_t> videoStabilizationAvailableModes;
763
764 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "videoStabilizationAvailableModes");
765 CAMERA_LOGI("elemNum = %{public}d", elemNum);
766 for (int i = 0; i < elemNum; i++) {
767 hcbRet =
768 pDevResIns->GetStringArrayElem(&metadataNode, "videoStabilizationAvailableModes", i, &nodeValue, nullptr);
769 if (hcbRet != 0) {
770 CAMERA_LOGE("get videoStabilizationAvailableModes failed");
771 continue;
772 }
773 CAMERA_LOGI("nodeValue = %{public}s", nodeValue);
774 videoStabilizationAvailableModes.push_back(videoStabilizationMap[std::string(nodeValue)]);
775 }
776 bool ret = metadata->addEntry(OHOS_ABILITY_VIDEO_STABILIZATION_MODES, videoStabilizationAvailableModes.data(),
777 videoStabilizationAvailableModes.size());
778 if (!ret) {
779 CAMERA_LOGE("videoStabilizationAvailableModes add failed");
780 return RC_ERROR;
781 }
782 CAMERA_LOGI("videoStabilizationAvailableModes add success");
783 return RC_OK;
784 }
785
DealAvalialbleFlash(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)786 RetCode HcsDeal::DealAvalialbleFlash(
787 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
788 {
789 const char *nodeValue = nullptr;
790 uint8_t flashAvailable;
791
792 int32_t rc = pDevResIns->GetString(&metadataNode, "flashAvailable", &nodeValue, nullptr);
793 if (rc != 0 || (nodeValue == nullptr)) {
794 CAMERA_LOGE("get flashAvailable failed");
795 return RC_ERROR;
796 }
797
798 if (flashAvailableMap.count(std::string(nodeValue)) == 0) {
799 CAMERA_LOGE("flashAvailable invalid argument");
800 return RC_ERROR;
801 }
802 flashAvailable = flashAvailableMap[std::string(nodeValue)];
803 CAMERA_LOGI("flashAvailable = %{public}d", flashAvailable);
804
805 constexpr uint32_t DATA_COUNT = 1;
806 bool ret = metadata->addEntry(OHOS_ABILITY_FLASH_AVAILABLE, static_cast<const void *>(&flashAvailable), DATA_COUNT);
807 if (!ret) {
808 CAMERA_LOGE("flashAvailable add failed");
809 return RC_ERROR;
810 }
811 CAMERA_LOGI("flashAvailable add success");
812 return RC_OK;
813 }
814
DealAvalialbleAutoFocus(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)815 RetCode HcsDeal::DealAvalialbleAutoFocus(
816 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
817 {
818 uint8_t hcbRet = 0;
819 const char *nodeValue = nullptr;
820 std::vector<uint8_t> afAvailable;
821
822 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "afAvailable");
823 CAMERA_LOGI("elemNum = %{public}d", elemNum);
824 for (int i = 0; i < elemNum; i++) {
825 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "afAvailable", i, &nodeValue, nullptr);
826 if (hcbRet != 0) {
827 CAMERA_LOGE("get afAvailable failed");
828 continue;
829 }
830 CAMERA_LOGI("nodeValue = %{public}s", nodeValue);
831 if (AfModeMap.count(std::string(nodeValue)) == 0) {
832 CAMERA_LOGE("afAvailable invalid argument");
833 return RC_ERROR;
834 }
835 afAvailable.push_back(AfModeMap[std::string(nodeValue)]);
836 }
837 bool ret = metadata->addEntry(OHOS_CONTROL_AF_AVAILABLE_MODES, afAvailable.data(), afAvailable.size());
838 if (!ret) {
839 CAMERA_LOGE("afAvailable add failed");
840 return RC_ERROR;
841 }
842 CAMERA_LOGI("afAvailable add success");
843 return RC_OK;
844 }
845
DealZoomRationRange(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)846 RetCode HcsDeal::DealZoomRationRange(
847 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
848 {
849 uint8_t hcbRet = 0;
850 const char *nodeValue = nullptr;
851 std::vector<float> zoomRatioRange;
852
853 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "zoomRatioRange");
854 CAMERA_LOGI("elemNum = %{public}d", elemNum);
855
856 constexpr uint32_t GROUP_LEN = 2;
857 if (elemNum % GROUP_LEN != 0) {
858 CAMERA_LOGE("zoomRatioRange hcs file configuration error");
859 return RC_ERROR;
860 }
861
862 for (int i = 0; i < elemNum; i++) {
863 hcbRet = pDevResIns->GetStringArrayElem(&metadataNode, "zoomRatioRange", i, &nodeValue, nullptr);
864 if (hcbRet != 0) {
865 CAMERA_LOGE("get zoomRatioRange failed");
866 continue;
867 }
868 CAMERA_LOGI("nodeValue = %{public}s", nodeValue);
869 zoomRatioRange.push_back((float)strtol(nodeValue, NULL, STRTOL_BASE));
870 }
871
872 for (int i = 0; i < elemNum - 1;) {
873 if (zoomRatioRange[i + 1] < zoomRatioRange[i]) {
874 CAMERA_LOGE("zoomRatioRange invalid argument");
875 return RC_ERROR;
876 }
877 constexpr uint32_t INDEX_INTERVAL = 2;
878 i = i + INDEX_INTERVAL;
879 }
880
881 bool ret = metadata->addEntry(OHOS_ABILITY_ZOOM_RATIO_RANGE, zoomRatioRange.data(), zoomRatioRange.size());
882 if (!ret) {
883 CAMERA_LOGE("zoomRatioRange add failed");
884 return RC_ERROR;
885 }
886 CAMERA_LOGI("zoomRatioRange add success");
887 return RC_OK;
888 }
889
DealJpegOrientation(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)890 RetCode HcsDeal::DealJpegOrientation(
891 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
892 {
893 const char *nodeValue = nullptr;
894 int32_t jpegOrientation;
895
896 int32_t rc = pDevResIns->GetString(&metadataNode, "jpegOrientation", &nodeValue, nullptr);
897 if (rc != 0 || (nodeValue == nullptr)) {
898 CAMERA_LOGE("get jpegOrientation failed");
899 return RC_ERROR;
900 }
901
902 jpegOrientation = (int32_t)strtol(nodeValue, NULL, STRTOL_BASE);
903 CAMERA_LOGI("jpegOrientation = %{public}d", jpegOrientation);
904
905 if (jpegOrientation != OHOS_CAMERA_JPEG_ROTATION_0 && jpegOrientation != OHOS_CAMERA_JPEG_ROTATION_90 &&
906 jpegOrientation != OHOS_CAMERA_JPEG_ROTATION_180 && jpegOrientation != OHOS_CAMERA_JPEG_ROTATION_270) {
907 CAMERA_LOGE("jpegOrientation invalid argument");
908 return RC_ERROR;
909 }
910
911 constexpr uint32_t DATA_COUNT = 1;
912 bool ret = metadata->addEntry(OHOS_JPEG_ORIENTATION, static_cast<const void *>(&jpegOrientation), DATA_COUNT);
913 if (!ret) {
914 CAMERA_LOGE("jpegOrientation add failed");
915 return RC_ERROR;
916 }
917 CAMERA_LOGI("jpegOrientation add success");
918 return RC_OK;
919 }
920
DealJpegQuality(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)921 RetCode HcsDeal::DealJpegQuality(
922 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
923 {
924 const char *nodeValue = nullptr;
925 int32_t jpegQuality;
926
927 int32_t rc = pDevResIns->GetString(&metadataNode, "jpegQuality", &nodeValue, nullptr);
928 if (rc != 0 || (nodeValue == nullptr)) {
929 CAMERA_LOGE("get jpegQuality failed");
930 return RC_ERROR;
931 }
932
933 jpegQuality = (int32_t)strtol(nodeValue, NULL, STRTOL_BASE);
934 CAMERA_LOGI("jpegQuality = %{public}d", jpegQuality);
935
936 if (jpegQuality != OHOS_CAMERA_JPEG_LEVEL_LOW && jpegQuality != OHOS_CAMERA_JPEG_LEVEL_MIDDLE &&
937 jpegQuality != OHOS_CAMERA_JPEG_LEVEL_HIGH) {
938 CAMERA_LOGE("jpegQuality invalid argument");
939 return RC_ERROR;
940 }
941
942 constexpr uint32_t DATA_COUNT = 1;
943 bool ret = metadata->addEntry(OHOS_JPEG_QUALITY, static_cast<const void *>(&jpegQuality), DATA_COUNT);
944 if (!ret) {
945 CAMERA_LOGE("jpegQuality add failed");
946 return RC_ERROR;
947 }
948 CAMERA_LOGI("jpegQuality add success");
949 return RC_OK;
950 }
951
GetMetadata(CameraMetadataMap & metadataMap) const952 RetCode HcsDeal::GetMetadata(CameraMetadataMap &metadataMap) const
953 {
954 metadataMap = cameraMetadataMap_;
955 return RC_OK;
956 }
957
GetCameraId(CameraIdMap & cameraIdMap) const958 RetCode HcsDeal::GetCameraId(CameraIdMap &cameraIdMap) const
959 {
960 cameraIdMap = cameraIdMap_;
961 return RC_OK;
962 }
963
DealAvaliableExtendConfigurations(const struct DeviceResourceNode & metadataNode,std::shared_ptr<Camera::CameraMetadata> & metadata)964 RetCode HcsDeal::DealAvaliableExtendConfigurations(
965 const struct DeviceResourceNode &metadataNode, std::shared_ptr<Camera::CameraMetadata> &metadata)
966 {
967 int32_t elemNum = pDevResIns->GetElemNum(&metadataNode, "extendAvailableConfigurations");
968 CAMERA_LOGD("elemNum = %{public}d", elemNum);
969 if (elemNum <= 0) {
970 CAMERA_LOGD("elemNum <= 0");
971 return RC_ERROR;
972 }
973
974 int hcbRet;
975 uint32_t nodeValue;
976 std::vector<int32_t> extendConfigAvaliableInt32s;
977
978 for (int i = 0; i < elemNum; i++) {
979 hcbRet = pDevResIns->GetUint32ArrayElem(&metadataNode, "extendAvailableConfigurations", i, &nodeValue, -1);
980 if (hcbRet != 0 && nodeValue != UINT32_MAX) {
981 CAMERA_LOGE("get extendAvailableConfigurations failed");
982 continue;
983 }
984 extendConfigAvaliableInt32s.push_back(static_cast<int32_t>(nodeValue));
985 CAMERA_LOGD("nodeValue = %{public}u", nodeValue);
986 }
987
988 bool ret = metadata->addEntry(OHOS_ABILITY_STREAM_AVAILABLE_EXTEND_CONFIGURATIONS,
989 extendConfigAvaliableInt32s.data(), extendConfigAvaliableInt32s.size());
990 if (!ret) {
991 CAMERA_LOGD("extendAvailableConfigurations add failed");
992 return RC_ERROR;
993 }
994 CAMERA_LOGI("extendAvailableConfigurations add success");
995 return RC_OK;
996 }
997 } // namespace OHOS::Camera
998