• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "input/camera_input.h"
17 
18 #include <cinttypes>
19 #include <mutex>
20 #include <securec.h>
21 #include "camera_device.h"
22 #include "camera_device_ability_items.h"
23 #include "camera_log.h"
24 #include "camera_manager.h"
25 #include "camera_util.h"
26 #include "hcamera_device_callback_stub.h"
27 #include "icamera_util.h"
28 #include "metadata_utils.h"
29 #include "metadata_common_utils.h"
30 #include "output/metadata_output.h"
31 #include "session/capture_session.h"
32 
33 namespace OHOS {
34 namespace CameraStandard {
35 using OHOS::HDI::Camera::V1_3::OperationMode;
OnError(const int32_t errorType,const int32_t errorMsg)36 int32_t CameraDeviceServiceCallback::OnError(const int32_t errorType, const int32_t errorMsg)
37 {
38     std::lock_guard<std::mutex> lock(deviceCallbackMutex_);
39     auto camInputSptr = camInput_.promote();
40     MEDIA_ERR_LOG("CameraDeviceServiceCallback::OnError() is called!, errorType: %{public}d, errorMsg: %{public}d",
41                   errorType, errorMsg);
42     if (camInputSptr != nullptr && camInputSptr->GetErrorCallback() != nullptr) {
43         int32_t serviceErrorType = ServiceToCameraError(errorType);
44         camInputSptr->GetErrorCallback()->OnError(serviceErrorType, errorMsg);
45     } else {
46         MEDIA_INFO_LOG("CameraDeviceServiceCallback::ErrorCallback not set!, Discarding callback");
47     }
48     return CAMERA_OK;
49 }
50 
OnResult(const uint64_t timestamp,const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)51 int32_t CameraDeviceServiceCallback::OnResult(const uint64_t timestamp,
52                                               const std::shared_ptr<OHOS::Camera::CameraMetadata> &result)
53 {
54     CHECK_ERROR_RETURN_RET_LOG(result == nullptr, CAMERA_INVALID_ARG, "OnResult get null meta from server");
55     std::lock_guard<std::mutex> lock(deviceCallbackMutex_);
56     auto camInputSptr = camInput_.promote();
57     CHECK_ERROR_RETURN_RET_LOG(camInputSptr == nullptr, CAMERA_OK,
58         "CameraDeviceServiceCallback::OnResult() camInput_ is null!");
59     auto cameraObject = camInputSptr->GetCameraDeviceInfo();
60     if (cameraObject == nullptr) {
61         MEDIA_ERR_LOG("CameraDeviceServiceCallback::OnResult() camInput_->GetCameraDeviceInfo() is null!");
62     } else {
63         MEDIA_DEBUG_LOG("CameraDeviceServiceCallback::OnResult()"
64                         "is called!, cameraId: %{public}s, timestamp: %{public}"
65                         PRIu64, cameraObject->GetID().c_str(), timestamp);
66     }
67     if (camInputSptr->GetResultCallback() != nullptr) {
68         camInputSptr->GetResultCallback()->OnResult(timestamp, result);
69     }
70 
71     auto pfnOcclusionDetectCallback = camInputSptr->GetOcclusionDetectCallback();
72     if (pfnOcclusionDetectCallback != nullptr) {
73         camera_metadata_item itemOcclusion;
74         int32_t retOcclusion = OHOS::Camera::FindCameraMetadataItem(result->get(),
75             OHOS_STATUS_CAMERA_OCCLUSION_DETECTION, &itemOcclusion);
76         bool foundOcclusion = (retOcclusion == CAM_META_SUCCESS && itemOcclusion.count != 0);
77         uint8_t occlusion = foundOcclusion ? static_cast<uint8_t>(itemOcclusion.data.i32[0]) : 0;
78 
79         camera_metadata_item itemLensDirty;
80         int32_t retLensDirty = OHOS::Camera::FindCameraMetadataItem(result->get(),
81             OHOS_STATUS_CAMERA_LENS_DIRTY_DETECTION, &itemLensDirty);
82         bool foundLensDirty = (retLensDirty == CAM_META_SUCCESS && itemLensDirty.count != 0);
83         uint8_t lensDirty = foundLensDirty ? itemLensDirty.data.u8[0] : 0;
84 
85         if (foundOcclusion || foundLensDirty) {
86             MEDIA_DEBUG_LOG("occlusion found:%{public}d val:%{public}u; lensDirty found:%{public}d val:%{public}u",
87                 foundOcclusion, occlusion, foundLensDirty, lensDirty);
88             pfnOcclusionDetectCallback->OnCameraOcclusionDetected(occlusion, lensDirty);
89         }
90     }
91 
92     camInputSptr->ProcessCallbackUpdates(timestamp, result);
93     return CAMERA_OK;
94 }
95 
CameraInput(sptr<ICameraDeviceService> & deviceObj,sptr<CameraDevice> & cameraObj)96 CameraInput::CameraInput(sptr<ICameraDeviceService> &deviceObj,
97                          sptr<CameraDevice> &cameraObj) : deviceObj_(deviceObj), cameraObj_(cameraObj)
98 {
99     MEDIA_INFO_LOG("CameraInput::CameraInput Contructor!");
100     InitCameraInput();
101 }
102 
InitCameraInput()103 void CameraInput::InitCameraInput()
104 {
105     auto cameraObj = GetCameraDeviceInfo();
106     auto deviceObj = GetCameraDevice();
107     if (cameraObj) {
108         MEDIA_INFO_LOG("CameraInput::CameraInput Contructor Camera: %{public}s", cameraObj->GetID().c_str());
109     }
110     CameraDeviceSvcCallback_ = new(std::nothrow) CameraDeviceServiceCallback(this);
111     CHECK_ERROR_RETURN_LOG(CameraDeviceSvcCallback_ == nullptr, "Failed to new CameraDeviceSvcCallback_!");
112     CHECK_ERROR_RETURN_LOG(!deviceObj, "CameraInput::CameraInput() deviceObj is nullptr");
113     deviceObj->SetCallback(CameraDeviceSvcCallback_);
114     sptr<IRemoteObject> object = deviceObj->AsObject();
115     CHECK_ERROR_RETURN(object == nullptr);
116     pid_t pid = 0;
117     deathRecipient_ = new(std::nothrow) CameraDeathRecipient(pid);
118     CHECK_AND_RETURN_LOG(deathRecipient_ != nullptr, "failed to new CameraDeathRecipient.");
119     auto thisPtr = wptr<CameraInput>(this);
120     deathRecipient_->SetNotifyCb([thisPtr](pid_t pid) {
121         auto ptr = thisPtr.promote();
122         if (ptr != nullptr) {
123             ptr->CameraServerDied(pid);
124         }
125     });
126     bool result = object->AddDeathRecipient(deathRecipient_);
127     CHECK_ERROR_RETURN_LOG(!result, "CameraInput::CameraInput failed to add deathRecipient");
128 }
129 
CameraServerDied(pid_t pid)130 void CameraInput::CameraServerDied(pid_t pid)
131 {
132     MEDIA_ERR_LOG("camera server has died, pid:%{public}d!", pid);
133     {
134         std::lock_guard<std::mutex> errLock(errorCallbackMutex_);
135         if (errorCallback_ != nullptr) {
136             MEDIA_DEBUG_LOG("appCallback not nullptr");
137             int32_t serviceErrorType = ServiceToCameraError(CAMERA_INVALID_STATE);
138             int32_t serviceErrorMsg = 0;
139             MEDIA_DEBUG_LOG("serviceErrorType:%{public}d!, serviceErrorMsg:%{public}d!", serviceErrorType,
140                             serviceErrorMsg);
141             errorCallback_->OnError(serviceErrorType, serviceErrorMsg);
142         }
143     }
144     std::lock_guard<std::mutex> interfaceLock(interfaceMutex_);
145     InputRemoveDeathRecipient();
146 }
147 
InputRemoveDeathRecipient()148 void CameraInput::InputRemoveDeathRecipient()
149 {
150     auto deviceObj = GetCameraDevice();
151     if (deviceObj != nullptr) {
152         (void)deviceObj->AsObject()->RemoveDeathRecipient(deathRecipient_);
153         SetCameraDevice(nullptr);
154     }
155     deathRecipient_ = nullptr;
156 }
157 
~CameraInput()158 CameraInput::~CameraInput()
159 {
160     MEDIA_INFO_LOG("CameraInput::CameraInput Destructor!");
161     std::lock_guard<std::mutex> lock(interfaceMutex_);
162     if (cameraObj_) {
163         MEDIA_INFO_LOG("CameraInput::CameraInput Destructor Camera: %{public}s", cameraObj_->GetID().c_str());
164     }
165     InputRemoveDeathRecipient();
166 }
167 
Open()168 int CameraInput::Open()
169 {
170     std::lock_guard<std::mutex> lock(interfaceMutex_);
171     MEDIA_DEBUG_LOG("Enter Into CameraInput::Open");
172     int32_t retCode = CAMERA_UNKNOWN_ERROR;
173     auto deviceObj = GetCameraDevice();
174     if (deviceObj) {
175         retCode = deviceObj->Open();
176         CHECK_ERROR_PRINT_LOG(retCode != CAMERA_OK, "Failed to open Camera Input, retCode: %{public}d", retCode);
177     } else {
178         MEDIA_ERR_LOG("CameraInput::Open() deviceObj is nullptr");
179     }
180     return ServiceToCameraError(retCode);
181 }
182 
Open(bool isEnableSecureCamera,uint64_t * secureSeqId)183 int CameraInput::Open(bool isEnableSecureCamera, uint64_t* secureSeqId)
184 {
185     std::lock_guard<std::mutex> lock(interfaceMutex_);
186     MEDIA_DEBUG_LOG("Enter Into CameraInput::OpenSecureCamera");
187     int32_t retCode = CAMERA_UNKNOWN_ERROR;
188     bool isSupportSecCamera = false;
189     auto cameraObject = GetCameraDeviceInfo();
190     if (isEnableSecureCamera && cameraObject) {
191         std::shared_ptr<OHOS::Camera::CameraMetadata> baseMetadata = cameraObject->GetMetadata();
192         CHECK_ERROR_RETURN_RET_LOG(baseMetadata == nullptr, retCode,
193             "CameraInput::GetMetaSetting Failed to find baseMetadata");
194         camera_metadata_item_t item;
195         retCode = OHOS::Camera::FindCameraMetadataItem(baseMetadata->get(), OHOS_ABILITY_CAMERA_MODES, &item);
196         CHECK_ERROR_RETURN_RET_LOG(retCode != CAM_META_SUCCESS || item.count == 0, retCode,
197             "CaptureSession::GetSupportedModes Failed with return code %{public}d", retCode);
198         for (uint32_t i = 0; i < item.count; i++) {
199             if (item.data.u8[i] == SECURE) {
200                 isSupportSecCamera = true;
201             }
202         }
203     }
204 
205     auto deviceObj = GetCameraDevice();
206     if (deviceObj) {
207         retCode = isSupportSecCamera ? (deviceObj->OpenSecureCamera(secureSeqId)) : (deviceObj->Open());
208         CHECK_ERROR_PRINT_LOG(retCode != CAMERA_OK,
209             "Failed to open Camera Input, retCode: %{public}d, isSupportSecCamera is %{public}d",
210             retCode, isSupportSecCamera);
211     } else {
212         MEDIA_ERR_LOG("CameraInput::OpenSecureCamera() deviceObj is nullptr");
213     }
214     MEDIA_INFO_LOG("Enter Into CameraInput::OpenSecureCamera secureSeqId = %{public}" PRIu64, *secureSeqId);
215     return ServiceToCameraError(retCode);
216 }
217 
Close()218 int CameraInput::Close()
219 {
220     std::lock_guard<std::mutex> lock(interfaceMutex_);
221     MEDIA_DEBUG_LOG("Enter Into CameraInput::Close");
222     int32_t retCode = CAMERA_UNKNOWN_ERROR;
223     auto deviceObj = GetCameraDevice();
224     if (deviceObj) {
225         retCode = deviceObj->Close();
226         CHECK_ERROR_PRINT_LOG(retCode != CAMERA_OK, "Failed to close Camera Input, retCode: %{public}d", retCode);
227     } else {
228         MEDIA_ERR_LOG("CameraInput::Close() deviceObj is nullptr");
229     }
230     SetCameraDeviceInfo(nullptr);
231     InputRemoveDeathRecipient();
232     CameraDeviceSvcCallback_ = nullptr;
233     return ServiceToCameraError(retCode);
234 }
235 
Release()236 int CameraInput::Release()
237 {
238     std::lock_guard<std::mutex> lock(interfaceMutex_);
239     MEDIA_DEBUG_LOG("Enter Into CameraInput::Release");
240     int32_t retCode = CAMERA_UNKNOWN_ERROR;
241     auto deviceObj = GetCameraDevice();
242     if (deviceObj) {
243         retCode = deviceObj->Release();
244         CHECK_ERROR_PRINT_LOG(retCode != CAMERA_OK, "Failed to release Camera Input, retCode: %{public}d", retCode);
245     } else {
246         MEDIA_ERR_LOG("CameraInput::Release() deviceObj is nullptr");
247     }
248     SetCameraDeviceInfo(nullptr);
249     InputRemoveDeathRecipient();
250     CameraDeviceSvcCallback_ = nullptr;
251     return ServiceToCameraError(retCode);
252 }
253 
SetErrorCallback(std::shared_ptr<ErrorCallback> errorCallback)254 void CameraInput::SetErrorCallback(std::shared_ptr<ErrorCallback> errorCallback)
255 {
256     CHECK_ERROR_PRINT_LOG(errorCallback == nullptr, "SetErrorCallback: Unregistering error callback");
257     std::lock_guard<std::mutex> lock(errorCallbackMutex_);
258     errorCallback_ = errorCallback;
259     return;
260 }
261 
SetResultCallback(std::shared_ptr<ResultCallback> resultCallback)262 void CameraInput::SetResultCallback(std::shared_ptr<ResultCallback> resultCallback)
263 {
264     CHECK_ERROR_PRINT_LOG(resultCallback == nullptr, "SetResultCallback: Unregistering error resultCallback");
265     MEDIA_DEBUG_LOG("CameraInput::setresult callback");
266     std::lock_guard<std::mutex> lock(resultCallbackMutex_);
267     resultCallback_ = resultCallback;
268     return;
269 }
270 
SetCameraDeviceInfo(sptr<CameraDevice> cameraObj)271 void CameraInput::SetCameraDeviceInfo(sptr<CameraDevice> cameraObj)
272 {
273     MEDIA_ERR_LOG("CameraInput::SetCameraDeviceInfo");
274     std::lock_guard<std::mutex> lock(cameraDeviceInfoMutex_);
275     cameraObj_ = cameraObj;
276     return;
277 }
278 
createPositionMapping()279 std::map<CameraPosition, camera_position_enum> createPositionMapping()
280 {
281     std::map<CameraPosition, camera_position_enum> enumMapping;
282     enumMapping[CameraPosition::CAMERA_POSITION_UNSPECIFIED] = camera_position_enum::OHOS_CAMERA_POSITION_OTHER;
283     enumMapping[CameraPosition::CAMERA_POSITION_BACK] = camera_position_enum::OHOS_CAMERA_POSITION_BACK;
284     enumMapping[CameraPosition::CAMERA_POSITION_FRONT] = camera_position_enum::OHOS_CAMERA_POSITION_FRONT;
285     return enumMapping;
286 }
287 
SetInputUsedAsPosition(CameraPosition usedAsPosition)288 void CameraInput::SetInputUsedAsPosition(CameraPosition usedAsPosition)
289 {
290     MEDIA_INFO_LOG("CameraInput::SetInputUsedAsPosition params: %{public}u", usedAsPosition);
291     std::lock_guard<std::mutex> lock(cameraDeviceInfoMutex_);
292     uint8_t translatePos = OHOS_CAMERA_POSITION_OTHER;
293     if (positionMapping.empty()) {
294         positionMapping = createPositionMapping();
295     }
296     translatePos = positionMapping[usedAsPosition];
297 
298     auto metadata = std::make_shared<Camera::CameraMetadata>(1, 1);
299     MEDIA_INFO_LOG("CameraInput::SetInputUsedAsPosition fr: %{public}u, to: %{public}u", usedAsPosition, translatePos);
300     if (!AddOrUpdateMetadata(metadata, OHOS_CONTROL_CAMERA_USED_AS_POSITION, &translatePos, 1)) {
301         MEDIA_INFO_LOG("CameraInput::SetInputUsedAsPosition Failed to set metadata");
302     }
303     deviceObj_->SetUsedAsPosition(translatePos);
304     deviceObj_->UpdateSetting(metadata);
305     cameraObj_->SetCameraDeviceUsedAsPosition(usedAsPosition);
306 }
307 
SetOcclusionDetectCallback(std::shared_ptr<CameraOcclusionDetectCallback> cameraOcclusionDetectCallback)308 void CameraInput::SetOcclusionDetectCallback(
309     std::shared_ptr<CameraOcclusionDetectCallback> cameraOcclusionDetectCallback)
310 {
311     if (cameraOcclusionDetectCallback == nullptr) {
312         MEDIA_ERR_LOG("SetOcclusionDetectCallback:SetOcclusionDetectCallback error cameraOcclusionDetectCallback");
313     }
314     MEDIA_DEBUG_LOG("CameraInput::SetOcclusionDetectCallback callback");
315     std::lock_guard<std::mutex> lock(occlusionCallbackMutex_);
316     cameraOcclusionDetectCallback_ = cameraOcclusionDetectCallback;
317     return;
318 }
319 
GetCameraId()320 std::string CameraInput::GetCameraId()
321 {
322     auto cameraObject = GetCameraDeviceInfo();
323     CHECK_ERROR_RETURN_RET_LOG(cameraObject == nullptr, nullptr, "CameraInput::GetCameraId cameraObject is null");
324 
325     return cameraObject->GetID();
326 }
327 
GetCameraDevice()328 sptr<ICameraDeviceService> CameraInput::GetCameraDevice()
329 {
330     std::lock_guard<std::mutex> lock(deviceObjMutex_);
331     return deviceObj_;
332 }
333 
SetCameraDevice(sptr<ICameraDeviceService> deviceObj)334 void CameraInput::SetCameraDevice(sptr<ICameraDeviceService> deviceObj)
335 {
336     std::lock_guard<std::mutex> lock(deviceObjMutex_);
337     deviceObj_ = deviceObj;
338     return;
339 }
340 
GetErrorCallback()341 std::shared_ptr<ErrorCallback> CameraInput::GetErrorCallback()
342 {
343     std::lock_guard<std::mutex> lock(errorCallbackMutex_);
344     return errorCallback_;
345 }
346 
GetResultCallback()347 std::shared_ptr<ResultCallback> CameraInput::GetResultCallback()
348 {
349     std::lock_guard<std::mutex> lock(resultCallbackMutex_);
350     MEDIA_DEBUG_LOG("CameraDeviceServiceCallback::GetResultCallback");
351     return resultCallback_;
352 }
353 
GetOcclusionDetectCallback()354 std::shared_ptr<CameraOcclusionDetectCallback> CameraInput::GetOcclusionDetectCallback()
355 {
356     std::lock_guard<std::mutex> lock(occlusionCallbackMutex_);
357     return cameraOcclusionDetectCallback_;
358 }
359 
GetCameraDeviceInfo()360 sptr<CameraDevice> CameraInput::GetCameraDeviceInfo()
361 {
362     std::lock_guard<std::mutex> lock(cameraDeviceInfoMutex_);
363     return cameraObj_;
364 }
365 
ProcessCallbackUpdates(const uint64_t timestamp,const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)366 void CameraInput::ProcessCallbackUpdates(
367     const uint64_t timestamp, const std::shared_ptr<OHOS::Camera::CameraMetadata>& result)
368 {
369     auto metadataResultProcessor = GetMetadataResultProcessor();
370     CHECK_ERROR_RETURN(metadataResultProcessor == nullptr);
371     metadataResultProcessor->ProcessCallbacks(timestamp, result);
372 }
373 
UpdateSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata)374 int32_t CameraInput::UpdateSetting(std::shared_ptr<OHOS::Camera::CameraMetadata> changedMetadata)
375 {
376     CAMERA_SYNC_TRACE;
377     CHECK_ERROR_RETURN_RET(changedMetadata == nullptr, CAMERA_INVALID_ARG);
378     CHECK_ERROR_RETURN_RET_LOG(!OHOS::Camera::GetCameraMetadataItemCount(changedMetadata->get()), CAMERA_OK,
379         "CameraInput::UpdateSetting No configuration to update");
380 
381     std::lock_guard<std::mutex> lock(interfaceMutex_);
382     auto deviceObj = GetCameraDevice();
383     CHECK_ERROR_RETURN_RET_LOG(!deviceObj, ServiceToCameraError(CAMERA_INVALID_ARG),
384         "CameraInput::UpdateSetting() deviceObj is nullptr");
385     int32_t ret = deviceObj->UpdateSetting(changedMetadata);
386     CHECK_ERROR_RETURN_RET_LOG(ret != CAMERA_OK, ret, "CameraInput::UpdateSetting Failed to update settings");
387 
388     auto cameraObject = GetCameraDeviceInfo();
389     CHECK_ERROR_RETURN_RET_LOG(cameraObject == nullptr, CAMERA_INVALID_ARG,
390         "CameraInput::UpdateSetting cameraObject is null");
391     std::shared_ptr<OHOS::Camera::CameraMetadata> baseMetadata = cameraObject->GetMetadata();
392     bool mergeResult = MergeMetadata(changedMetadata, baseMetadata);
393     CHECK_ERROR_RETURN_RET_LOG(!mergeResult, CAMERA_INVALID_ARG,
394         "CameraInput::UpdateSetting() baseMetadata or itemEntry is nullptr");
395     return CAMERA_OK;
396 }
397 
MergeMetadata(const std::shared_ptr<OHOS::Camera::CameraMetadata> srcMetadata,std::shared_ptr<OHOS::Camera::CameraMetadata> dstMetadata)398 bool CameraInput::MergeMetadata(const std::shared_ptr<OHOS::Camera::CameraMetadata> srcMetadata,
399     std::shared_ptr<OHOS::Camera::CameraMetadata> dstMetadata)
400 {
401     CHECK_ERROR_RETURN_RET(srcMetadata == nullptr || dstMetadata == nullptr, false);
402     auto srcHeader = srcMetadata->get();
403     CHECK_ERROR_RETURN_RET(srcHeader == nullptr, false);
404     auto dstHeader = dstMetadata->get();
405     CHECK_ERROR_RETURN_RET(dstHeader == nullptr, false);
406 
407     auto srcItemCount = srcHeader->item_count;
408     camera_metadata_item_t srcItem;
409     for (uint32_t index = 0; index < srcItemCount; index++) {
410         int ret = OHOS::Camera::GetCameraMetadataItem(srcHeader, index, &srcItem);
411         CHECK_ERROR_RETURN_RET_LOG(ret != CAM_META_SUCCESS, false,
412             "Failed to get metadata item at index: %{public}d", index);
413         bool status = false;
414         uint32_t currentIndex;
415         ret = OHOS::Camera::FindCameraMetadataItemIndex(dstHeader, srcItem.item, &currentIndex);
416         if (ret == CAM_META_ITEM_NOT_FOUND) {
417             status = dstMetadata->addEntry(srcItem.item, srcItem.data.u8, srcItem.count);
418         } else if (ret == CAM_META_SUCCESS) {
419             status = dstMetadata->updateEntry(srcItem.item, srcItem.data.u8, srcItem.count);
420         }
421         CHECK_ERROR_RETURN_RET_LOG(!status, false, "Failed to update metadata item: %{public}d", srcItem.item);
422     }
423     return true;
424 }
425 
GetCameraSettings()426 std::string CameraInput::GetCameraSettings()
427 {
428     auto cameraObject = GetCameraDeviceInfo();
429     CHECK_ERROR_RETURN_RET_LOG(cameraObject == nullptr, nullptr, "GetCameraSettings cameraObject is null");
430     return OHOS::Camera::MetadataUtils::EncodeToString(cameraObject->GetMetadata());
431 }
432 
SetCameraSettings(std::string setting)433 int32_t CameraInput::SetCameraSettings(std::string setting)
434 {
435     std::shared_ptr<OHOS::Camera::CameraMetadata> metadata = OHOS::Camera::MetadataUtils::DecodeFromString(setting);
436     CHECK_ERROR_RETURN_RET_LOG(metadata == nullptr, CAMERA_INVALID_ARG,
437         "CameraInput::SetCameraSettings Failed to decode metadata setting from string");
438     return UpdateSetting(metadata);
439 }
440 
GetMetaSetting(uint32_t metaTag)441 std::shared_ptr<camera_metadata_item_t> CameraInput::GetMetaSetting(uint32_t metaTag)
442 {
443     CHECK_ERROR_RETURN_RET_LOG(cameraObj_ == nullptr, nullptr,
444         "CameraInput::GetMetaSetting cameraObj has release!");
445     std::shared_ptr<OHOS::Camera::CameraMetadata> baseMetadata = cameraObj_->GetMetadata();
446     CHECK_ERROR_RETURN_RET_LOG(baseMetadata == nullptr, nullptr,
447         "CameraInput::GetMetaSetting Failed to find baseMetadata");
448     std::shared_ptr<camera_metadata_item_t> item = MetadataCommonUtils::GetCapabilityEntry(baseMetadata, metaTag);
449     CHECK_ERROR_RETURN_RET_LOG(item == nullptr || item->count == 0, nullptr,
450         "CameraInput::GetMetaSetting  Failed to find meta item: metaTag = %{public}u", metaTag);
451     return item;
452 }
453 
GetCameraAllVendorTags(std::vector<vendorTag_t> & infos)454 int32_t CameraInput::GetCameraAllVendorTags(std::vector<vendorTag_t> &infos) __attribute__((no_sanitize("cfi")))
455 {
456     infos.clear();
457     MEDIA_INFO_LOG("CameraInput::GetCameraAllVendorTags called!");
458     int32_t ret = OHOS::Camera::GetAllVendorTags(infos);
459     CHECK_ERROR_RETURN_RET_LOG(ret != CAM_META_SUCCESS, CAMERA_UNKNOWN_ERROR,
460         "CameraInput::GetCameraAllVendorTags failed! because of hdi error, ret = %{public}d", ret);
461     MEDIA_INFO_LOG("CameraInput::GetCameraAllVendorTags success! vendors size = %{public}zu!", infos.size());
462     MEDIA_INFO_LOG("CameraInput::GetCameraAllVendorTags end!");
463     return CAMERA_OK;
464 }
465 
SwitchCameraDevice(sptr<ICameraDeviceService> & deviceObj,sptr<CameraDevice> & cameraObj)466 void CameraInput::SwitchCameraDevice(sptr<ICameraDeviceService> &deviceObj, sptr<CameraDevice> &cameraObj)
467 {
468     SetCameraDeviceInfo(cameraObj);
469     SetCameraDevice(deviceObj);
470     InitCameraInput();
471 }
472 } // namespace CameraStandard
473 } // namespace OHOS
474