• 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 "hcamera_device.h"
17 
18 #include "camera_util.h"
19 #include "camera_log.h"
20 #include "ipc_skeleton.h"
21 #include "metadata_utils.h"
22 
23 namespace OHOS {
24 namespace CameraStandard {
HCameraDevice(sptr<HCameraHostManager> & cameraHostManager,std::string cameraID,const uint32_t callingTokenId)25 HCameraDevice::HCameraDevice(sptr<HCameraHostManager> &cameraHostManager,
26                              std::string cameraID,
27                              const uint32_t callingTokenId)
28 {
29     cameraHostManager_ = cameraHostManager;
30     cameraID_ = cameraID;
31     streamOperator_ = nullptr;
32     isReleaseCameraDevice_ = false;
33     isOpenedCameraDevice_ = false;
34     callerToken_ = callingTokenId;
35 }
36 
~HCameraDevice()37 HCameraDevice::~HCameraDevice()
38 {
39     hdiCameraDevice_ = nullptr;
40     streamOperator_ = nullptr;
41     if (cameraHostManager_) {
42         cameraHostManager_->RemoveCameraDevice(cameraID_);
43         cameraHostManager_ = nullptr;
44     }
45     deviceHDICallback_ = nullptr;
46     deviceSvcCallback_ = nullptr;
47 }
48 
GetCameraId()49 std::string HCameraDevice::GetCameraId()
50 {
51     return cameraID_;
52 }
53 
SetReleaseCameraDevice(bool isRelease)54 int32_t HCameraDevice::SetReleaseCameraDevice(bool isRelease)
55 {
56     isReleaseCameraDevice_ = isRelease;
57     return CAMERA_OK;
58 }
59 
IsReleaseCameraDevice()60 bool HCameraDevice::IsReleaseCameraDevice()
61 {
62     return isReleaseCameraDevice_;
63 }
64 
IsOpenedCameraDevice()65 bool HCameraDevice::IsOpenedCameraDevice()
66 {
67     return isOpenedCameraDevice_;
68 }
69 
GetSettings()70 std::shared_ptr<OHOS::Camera::CameraMetadata> HCameraDevice::GetSettings()
71 {
72     int32_t errCode;
73     std::shared_ptr<OHOS::Camera::CameraMetadata> ability = nullptr;
74     errCode = cameraHostManager_->GetCameraAbility(cameraID_, ability);
75     if (errCode != CAMERA_OK) {
76         MEDIA_ERR_LOG("HCameraDevice::GetSettings Failed to get Camera Ability: %{public}d", errCode);
77         return nullptr;
78     }
79 
80     if (!videoFrameRateRange_.empty() && ability != nullptr) {
81         bool status = false;
82         camera_metadata_item_t item;
83         int ret = OHOS::Camera::FindCameraMetadataItem(ability->get(), OHOS_CONTROL_FPS_RANGES, &item);
84         if (ret == CAM_META_ITEM_NOT_FOUND) {
85             status = ability->addEntry(OHOS_CONTROL_FPS_RANGES,
86                 videoFrameRateRange_.data(), videoFrameRateRange_.size());
87         } else if (ret == CAM_META_SUCCESS) {
88             status = ability->updateEntry(OHOS_CONTROL_FPS_RANGES,
89                 videoFrameRateRange_.data(), videoFrameRateRange_.size());
90         }
91         if (!status) {
92             MEDIA_ERR_LOG("HCameraDevice::Set fps renges Failed");
93         }
94     }
95     return ability;
96 }
97 
Open()98 int32_t HCameraDevice::Open()
99 {
100     CAMERA_SYNC_TRACE;
101     int32_t errorCode;
102     if (isOpenedCameraDevice_) {
103         MEDIA_ERR_LOG("HCameraDevice::Open failed, camera is busy");
104     }
105     if (deviceHDICallback_ == nullptr) {
106         deviceHDICallback_ = new(std::nothrow) CameraDeviceCallback(this);
107         if (deviceHDICallback_ == nullptr) {
108             MEDIA_ERR_LOG("HCameraDevice::Open CameraDeviceCallback allocation failed");
109             return CAMERA_ALLOC_ERROR;
110         }
111     }
112     bool isAllowed = true;
113     if (IsValidTokenId(callerToken_)) {
114         isAllowed = Security::AccessToken::PrivacyKit::IsAllowedUsingPermission(callerToken_, ACCESS_CAMERA);
115     }
116     if (!isAllowed) {
117         MEDIA_ERR_LOG("HCameraDevice::Open IsAllowedUsingPermission failed");
118         return CAMERA_ALLOC_ERROR;
119     }
120 
121     auto conflictDevices = cameraHostManager_->CameraConflictDetection(cameraID_);
122     // Destory conflict devices
123     for (auto &i : conflictDevices) {
124         i->Close();
125     }
126     MEDIA_INFO_LOG("HCameraDevice::Open Opening camera device: %{public}s", cameraID_.c_str());
127     errorCode = cameraHostManager_->OpenCameraDevice(cameraID_, deviceHDICallback_, hdiCameraDevice_);
128     if (errorCode == CAMERA_OK) {
129         isOpenedCameraDevice_ = true;
130         if (updateSettings_ != nullptr && hdiCameraDevice_ != nullptr) {
131             std::vector<uint8_t> setting;
132             OHOS::Camera::MetadataUtils::ConvertMetadataToVec(updateSettings_, setting);
133             CamRetCode rc = (CamRetCode)(hdiCameraDevice_->UpdateSettings(setting));
134             if (rc != HDI::Camera::V1_0::NO_ERROR) {
135                 MEDIA_ERR_LOG("HCameraDevice::Open Update setting failed with error Code: %{public}d", rc);
136                 return HdiToServiceError(rc);
137             }
138             updateSettings_ = nullptr;
139             MEDIA_DEBUG_LOG("HCameraDevice::Open Updated device settings");
140         }
141         if (hdiCameraDevice_) {
142             errorCode = HdiToServiceError((CamRetCode)(hdiCameraDevice_->SetResultMode(ON_CHANGED)));
143             cameraHostManager_->AddCameraDevice(cameraID_, this);
144             (void)OnCameraStatus(cameraID_, CAMERA_STATUS_UNAVAILABLE);
145         }
146     } else {
147         MEDIA_ERR_LOG("HCameraDevice::Open Failed to open camera");
148     }
149     return errorCode;
150 }
151 
Close()152 int32_t HCameraDevice::Close()
153 {
154     CAMERA_SYNC_TRACE;
155     std::lock_guard<std::mutex> lock(deviceLock_);
156     if (hdiCameraDevice_ != nullptr) {
157         MEDIA_INFO_LOG("HCameraDevice::Close Closing camera device: %{public}s", cameraID_.c_str());
158         hdiCameraDevice_->Close();
159         (void)OnCameraStatus(cameraID_, CAMERA_STATUS_AVAILABLE);
160     }
161     isOpenedCameraDevice_ = false;
162     hdiCameraDevice_ = nullptr;
163     if (streamOperator_) {
164         streamOperator_ = nullptr;
165     }
166     cameraHostManager_->RemoveCameraDevice(cameraID_);
167     deviceHDICallback_ = nullptr;
168     deviceSvcCallback_ = nullptr;
169     return CAMERA_OK;
170 }
171 
Release()172 int32_t HCameraDevice::Release()
173 {
174     if (hdiCameraDevice_ != nullptr) {
175         Close();
176     }
177     return CAMERA_OK;
178 }
179 
GetEnabledResults(std::vector<int32_t> & results)180 int32_t HCameraDevice::GetEnabledResults(std::vector<int32_t> &results)
181 {
182     if (hdiCameraDevice_) {
183         CamRetCode rc = (CamRetCode)(hdiCameraDevice_->GetEnabledResults(results));
184         if (rc != HDI::Camera::V1_0::NO_ERROR) {
185             MEDIA_ERR_LOG("HCameraDevice::GetEnabledResults failed with error Code:%{public}d", rc);
186             return HdiToServiceError(rc);
187         }
188     } else {
189         MEDIA_ERR_LOG("HCameraDevice::GetEnabledResults GetEnabledResults hdiCameraDevice_ is nullptr");
190         return CAMERA_UNKNOWN_ERROR;
191     }
192     return CAMERA_OK;
193 }
194 
UpdateSetting(const std::shared_ptr<OHOS::Camera::CameraMetadata> & settings)195 int32_t HCameraDevice::UpdateSetting(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings)
196 {
197     CAMERA_SYNC_TRACE;
198     if (settings == nullptr) {
199         MEDIA_ERR_LOG("HCameraDevice::UpdateSetting settings is null");
200         return CAMERA_INVALID_ARG;
201     }
202 
203     uint32_t count = OHOS::Camera::GetCameraMetadataItemCount(settings->get());
204     if (!count) {
205         MEDIA_DEBUG_LOG("HCameraDevice::UpdateSetting Nothing to update");
206         return CAMERA_OK;
207     }
208     if (updateSettings_) {
209         camera_metadata_item_t metadataItem;
210         for (uint32_t index = 0; index < count; index++) {
211             int ret = OHOS::Camera::GetCameraMetadataItem(settings->get(), index, &metadataItem);
212             if (ret != CAM_META_SUCCESS) {
213                 MEDIA_ERR_LOG("HCameraDevice::UpdateSetting Failed to get metadata item at index: %{public}d", index);
214                 return CAMERA_INVALID_ARG;
215             }
216             bool status = false;
217             uint32_t currentIndex;
218             ret = OHOS::Camera::FindCameraMetadataItemIndex(updateSettings_->get(), metadataItem.item, &currentIndex);
219             if (ret == CAM_META_ITEM_NOT_FOUND) {
220                 status = updateSettings_->addEntry(metadataItem.item, metadataItem.data.u8, metadataItem.count);
221             } else if (ret == CAM_META_SUCCESS) {
222                 status = updateSettings_->updateEntry(metadataItem.item, metadataItem.data.u8, metadataItem.count);
223             }
224             if (!status) {
225                 MEDIA_ERR_LOG("HCameraDevice::UpdateSetting Failed to update metadata item: %{public}d",
226                               metadataItem.item);
227                 return CAMERA_UNKNOWN_ERROR;
228             }
229         }
230     } else {
231         updateSettings_ = settings;
232     }
233     if (hdiCameraDevice_ != nullptr) {
234         std::vector<uint8_t> setting;
235         OHOS::Camera::MetadataUtils::ConvertMetadataToVec(updateSettings_, setting);
236         ReportMetadataDebugLog(updateSettings_);
237         GetFrameRateSetting(updateSettings_);
238 
239         CamRetCode rc = (CamRetCode)(hdiCameraDevice_->UpdateSettings(setting));
240         if (rc != HDI::Camera::V1_0::NO_ERROR) {
241             MEDIA_ERR_LOG("HCameraDevice::UpdateSetting failed with error Code: %{public}d", rc);
242             return HdiToServiceError(rc);
243         }
244         ReportFlashEvent(updateSettings_);
245         updateSettings_ = nullptr;
246     }
247     MEDIA_DEBUG_LOG("HCameraDevice::UpdateSetting Updated device settings");
248     return CAMERA_OK;
249 }
250 
ReportMetadataDebugLog(const std::shared_ptr<OHOS::Camera::CameraMetadata> & settings)251 void HCameraDevice::ReportMetadataDebugLog(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings)
252 {
253     // debug log for focus mode
254     camera_metadata_item_t item;
255     int ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_FOCUS_MODE, &item);
256     if (ret != CAM_META_SUCCESS) {
257         MEDIA_DEBUG_LOG("HCameraDevice::Failed to find OHOS_CONTROL_FOCUS_MODE tag");
258     } else {
259         MEDIA_DEBUG_LOG("HCameraDevice::find OHOS_CONTROL_FOCUS_MODE value = %{public}d", item.data.u8[0]);
260     }
261 
262     // debug log for af regions
263     ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_AF_REGIONS, &item);
264     if (ret != CAM_META_SUCCESS) {
265         MEDIA_DEBUG_LOG("HCameraDevice::Failed to find OHOS_CONTROL_AF_REGIONS tag");
266     } else {
267         MEDIA_DEBUG_LOG("HCameraDevice::find OHOS_CONTROL_AF_REGIONS x = %{public}f, y = %{public}f",
268             item.data.f[0], item.data.f[1]);
269     }
270 
271     // debug log for af regions
272     ret = OHOS::Camera::FindCameraMetadataItem(settings->get(),
273         OHOS_CONTROL_VIDEO_STABILIZATION_MODE, &item);
274     if (ret != CAM_META_SUCCESS) {
275         MEDIA_DEBUG_LOG("HCameraDevice::Failed to find OHOS_CONTROL_VIDEO_STABILIZATION_MODE tag");
276     } else {
277         MEDIA_DEBUG_LOG("HCameraDevice::find OHOS_CONTROL_VIDEO_STABILIZATION_MODE value = %{public}d",
278             item.data.u8[0]);
279     }
280 
281     // debug log for exposure mode
282     ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_EXPOSURE_MODE, &item);
283     if (ret != CAM_META_SUCCESS) {
284         MEDIA_DEBUG_LOG("HCameraDevice::Failed to find OHOS_CONTROL_EXPOSURE_MODE tag");
285     } else {
286         MEDIA_DEBUG_LOG("HCameraDevice::find OHOS_CONTROL_EXPOSURE_MODE value = %{public}d", item.data.u8[0]);
287     }
288 
289     // debug log for ae regions
290     ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_AE_REGIONS, &item);
291     if (ret != CAM_META_SUCCESS) {
292         MEDIA_DEBUG_LOG("HCameraDevice::Failed to find OHOS_CONTROL_AE_REGIONS tag");
293     } else {
294         MEDIA_DEBUG_LOG("HCameraDevice::find OHOS_CONTROL_AE_REGIONS x = %{public}f, y = %{public}f",
295             item.data.f[0], item.data.f[1]);
296     }
297 
298     // debug log for ae exposure compensation
299     ret = OHOS::Camera::FindCameraMetadataItem(settings->get(),
300         OHOS_CONTROL_AE_EXPOSURE_COMPENSATION, &item);
301     if (ret != CAM_META_SUCCESS) {
302         MEDIA_DEBUG_LOG("HCameraDevice::Failed to find OHOS_CONTROL_AE_EXPOSURE_COMPENSATION tag");
303     } else {
304         MEDIA_DEBUG_LOG("HCameraDevice::find OHOS_CONTROL_AE_EXPOSURE_COMPENSATION value = %{public}d",
305             item.data.u8[0]);
306     }
307 }
308 
GetFrameRateSetting(const std::shared_ptr<OHOS::Camera::CameraMetadata> & settings)309 void HCameraDevice::GetFrameRateSetting(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings)
310 {
311     camera_metadata_item_t item;
312     int ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_FPS_RANGES, &item);
313     if (ret != CAM_META_SUCCESS) {
314         MEDIA_DEBUG_LOG("HCameraDevice::Failed to find OHOS_CONTROL_FPS_RANGES tag");
315     } else {
316         videoFrameRateRange_ = {item.data.i32[0], item.data.i32[1]};
317         MEDIA_DEBUG_LOG("HCameraDevice::find OHOS_CONTROL_FPS_RANGES min = %{public}d, max = %{public}d",
318             item.data.i32[0], item.data.i32[1]);
319     }
320 }
321 
ReportFlashEvent(const std::shared_ptr<OHOS::Camera::CameraMetadata> & settings)322 void HCameraDevice::ReportFlashEvent(const std::shared_ptr<OHOS::Camera::CameraMetadata> &settings)
323 {
324     camera_metadata_item_t item;
325     camera_flash_mode_enum_t flashMode = OHOS_CAMERA_FLASH_MODE_ALWAYS_OPEN;
326     int ret = OHOS::Camera::FindCameraMetadataItem(settings->get(), OHOS_CONTROL_FLASH_MODE, &item);
327     if (ret == CAM_META_SUCCESS) {
328         flashMode = static_cast<camera_flash_mode_enum_t>(item.data.u8[0]);
329     } else {
330         MEDIA_ERR_LOG("CameraInput::GetFlashMode Failed with return code %{public}d", ret);
331     }
332 
333     if (flashMode == OHOS_CAMERA_FLASH_MODE_CLOSE) {
334         POWERMGR_SYSEVENT_FLASH_OFF();
335     } else {
336         POWERMGR_SYSEVENT_FLASH_ON();
337     }
338 }
339 
EnableResult(std::vector<int32_t> & results)340 int32_t HCameraDevice::EnableResult(std::vector<int32_t> &results)
341 {
342     if (results.empty()) {
343         MEDIA_ERR_LOG("HCameraDevice::EnableResult results vector empty");
344         return CAMERA_INVALID_ARG;
345     }
346 
347     if (hdiCameraDevice_ == nullptr) {
348         MEDIA_ERR_LOG("HCameraDevice::hdiCameraDevice_ is null");
349         return CAMERA_UNKNOWN_ERROR;
350     }
351 
352     CamRetCode rc = (CamRetCode)(hdiCameraDevice_->EnableResult(results));
353     if (rc != HDI::Camera::V1_0::NO_ERROR) {
354         MEDIA_ERR_LOG("HCameraDevice::EnableResult failed with error Code:%{public}d", rc);
355         return HdiToServiceError(rc);
356     }
357 
358     return CAMERA_OK;
359 }
360 
DisableResult(std::vector<int32_t> & results)361 int32_t HCameraDevice::DisableResult(std::vector<int32_t> &results)
362 {
363     if (results.empty()) {
364         MEDIA_ERR_LOG("HCameraDevice::DisableResult results vector empty");
365         return CAMERA_INVALID_ARG;
366     }
367 
368     if (hdiCameraDevice_ == nullptr) {
369         MEDIA_ERR_LOG("HCameraDevice::hdiCameraDevice_ is null");
370         return CAMERA_UNKNOWN_ERROR;
371     }
372 
373     CamRetCode rc = (CamRetCode)(hdiCameraDevice_->DisableResult(results));
374     if (rc != HDI::Camera::V1_0::NO_ERROR) {
375         MEDIA_ERR_LOG("HCameraDevice::DisableResult failed with error Code:%{public}d", rc);
376         return HdiToServiceError(rc);
377     }
378     return CAMERA_OK;
379 }
380 
SetCallback(sptr<ICameraDeviceServiceCallback> & callback)381 int32_t HCameraDevice::SetCallback(sptr<ICameraDeviceServiceCallback> &callback)
382 {
383     if (callback == nullptr) {
384         MEDIA_ERR_LOG("HCameraDevice::SetCallback callback is null");
385         return CAMERA_INVALID_ARG;
386     }
387     deviceSvcCallback_ = callback;
388     return CAMERA_OK;
389 }
390 
SetStatusCallback(std::map<int32_t,sptr<ICameraServiceCallback>> & callbacks)391 int32_t HCameraDevice::SetStatusCallback(std::map<int32_t, sptr<ICameraServiceCallback>> &callbacks)
392 {
393     MEDIA_INFO_LOG("HCameraDevice::SetStatusCallback callbacks size = %{public}zu",
394                    callbacks.size());
395     if (!statusSvcCallbacks_.empty()) {
396         MEDIA_ERR_LOG("HCameraDevice::SetStatusCallback statusSvcCallbacks_ is not empty, reset it");
397         statusSvcCallbacks_.clear();
398     }
399     for (auto it : callbacks) {
400         statusSvcCallbacks_[it.first] = it.second;
401     }
402     MEDIA_INFO_LOG("HCameraDevice::SetStatusCallback statusSvcCallbacks_ size = %{public}zu",
403                    statusSvcCallbacks_.size());
404     return CAMERA_OK;
405 }
406 
GetStreamOperator(sptr<IStreamOperatorCallback> callback,sptr<IStreamOperator> & streamOperator)407 int32_t HCameraDevice::GetStreamOperator(sptr<IStreamOperatorCallback> callback,
408     sptr<IStreamOperator> &streamOperator)
409 {
410     if (callback == nullptr) {
411         MEDIA_ERR_LOG("HCameraDevice::GetStreamOperator callback is null");
412         return CAMERA_INVALID_ARG;
413     }
414 
415     if (hdiCameraDevice_ == nullptr) {
416         MEDIA_ERR_LOG("HCameraDevice::hdiCameraDevice_ is null");
417         return CAMERA_UNKNOWN_ERROR;
418     }
419 
420     CamRetCode rc = (CamRetCode)(hdiCameraDevice_->GetStreamOperator(callback, streamOperator));
421     if (rc != HDI::Camera::V1_0::NO_ERROR) {
422         MEDIA_ERR_LOG("HCameraDevice::GetStreamOperator failed with error Code:%{public}d", rc);
423         return HdiToServiceError(rc);
424     }
425     streamOperator_ = streamOperator;
426     return CAMERA_OK;
427 }
428 
GetStreamOperator()429 sptr<IStreamOperator> HCameraDevice::GetStreamOperator()
430 {
431     return streamOperator_;
432 }
433 
OnError(const ErrorType type,const int32_t errorMsg)434 int32_t HCameraDevice::OnError(const ErrorType type, const int32_t errorMsg)
435 {
436     if (deviceSvcCallback_ != nullptr) {
437         int32_t errorType;
438         if (type == REQUEST_TIMEOUT) {
439             errorType = CAMERA_DEVICE_REQUEST_TIMEOUT;
440         } else if (type == DEVICE_PREEMPT) {
441             errorType = CAMERA_DEVICE_PREEMPTED;
442         } else {
443             errorType = CAMERA_UNKNOWN_ERROR;
444         }
445         deviceSvcCallback_->OnError(errorType, errorMsg);
446         CAMERA_SYSEVENT_FAULT(CreateMsg("CameraDeviceServiceCallback::OnError() is called!, errorType: %d,"
447                                         "errorMsg: %d", errorType, errorMsg));
448     }
449     return CAMERA_OK;
450 }
451 
OnCameraStatus(const std::string & cameraId,CameraStatus status)452 int32_t HCameraDevice::OnCameraStatus(const std::string& cameraId, CameraStatus status)
453 {
454     MEDIA_INFO_LOG("HCameraDevice::OnCameraStatus statusSvcCallbacks_ size = %{public}zu",
455                    statusSvcCallbacks_.size());
456     std::string callbackPids = "[";
457     for (auto it : statusSvcCallbacks_) {
458         if (it.second) {
459             callbackPids += " " + std::to_string((int)it.first);
460         }
461     }
462     callbackPids += " ]";
463     MEDIA_INFO_LOG("HCameraDevice::OnCameraStatus OnCameraStatusChanged callbackPids = %{public}s, "
464                    "cameraId = %{public}s, cameraStatus = %{public}d",
465                    callbackPids.c_str(), cameraId.c_str(), status);
466     for (auto it : statusSvcCallbacks_) {
467         it.second->OnCameraStatusChanged(cameraId, status);
468     }
469     return CAMERA_OK;
470 }
471 
OnResult(const uint64_t timestamp,const std::shared_ptr<OHOS::Camera::CameraMetadata> & result)472 int32_t HCameraDevice::OnResult(const uint64_t timestamp,
473                                 const std::shared_ptr<OHOS::Camera::CameraMetadata> &result)
474 {
475     if (deviceSvcCallback_ != nullptr) {
476         deviceSvcCallback_->OnResult(timestamp, result);
477     }
478     camera_metadata_item_t item;
479     common_metadata_header_t* metadata = result->get();
480     int ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FLASH_MODE, &item);
481     if (ret == 0) {
482         MEDIA_INFO_LOG("CameraDeviceServiceCallback::OnResult() OHOS_CONTROL_FLASH_MODE is %{public}d",
483                        item.data.u8[0]);
484     }
485     ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FLASH_STATE, &item);
486     if (ret == 0) {
487         MEDIA_INFO_LOG("CameraDeviceServiceCallback::OnResult() OHOS_CONTROL_FLASH_STATE is %{public}d",
488                        item.data.u8[0]);
489     }
490 
491     ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_MODE, &item);
492     if (ret == CAM_META_SUCCESS) {
493         MEDIA_DEBUG_LOG("Focus mode: %{public}d", item.data.u8[0]);
494     }
495     ret = OHOS::Camera::FindCameraMetadataItem(metadata, OHOS_CONTROL_FOCUS_STATE, &item);
496     if (ret == CAM_META_SUCCESS) {
497         MEDIA_INFO_LOG("Focus state: %{public}d", item.data.u8[0]);
498     }
499     return CAMERA_OK;
500 }
501 
CameraDeviceCallback(sptr<HCameraDevice> hCameraDevice)502 CameraDeviceCallback::CameraDeviceCallback(sptr<HCameraDevice> hCameraDevice)
503 {
504     hCameraDevice_ = hCameraDevice;
505 }
506 
OnError(const ErrorType type,const int32_t errorCode)507 int32_t CameraDeviceCallback::OnError(const ErrorType type, const int32_t errorCode)
508 {
509     hCameraDevice_->OnError(type, errorCode);
510     return CAMERA_OK;
511 }
512 
OnResult(uint64_t timestamp,const std::vector<uint8_t> & result)513 int32_t CameraDeviceCallback::OnResult(uint64_t timestamp, const std::vector<uint8_t>& result)
514 {
515     std::shared_ptr<OHOS::Camera::CameraMetadata> cameraResult;
516     OHOS::Camera::MetadataUtils::ConvertVecToMetadata(result, cameraResult);
517     hCameraDevice_->OnResult(timestamp, cameraResult);
518     return CAMERA_OK;
519 }
520 } // namespace CameraStandard
521 } // namespace OHOS
522